nros platform-cffi
Canonical C ABI for porting the nros platform abstraction
Loading...
Searching...
No Matches
platform_can.h
Go to the documentation of this file.
1#ifndef NROS_PLATFORM_CAN_H
2#define NROS_PLATFORM_CAN_H
3
4#include <stdint.h>
5#include <stddef.h>
6
7#include "nros/platform.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
55
56/* ---- Frame flags ---- */
57
59#define NROS_PLATFORM_CAN_FLAG_EXT 0x01u
62#define NROS_PLATFORM_CAN_FLAG_FD 0x02u
64#define NROS_PLATFORM_CAN_FLAG_BRS 0x04u
67#define NROS_PLATFORM_CAN_SEND_WAIT_TX 0x80u
68
70#define NROS_PLATFORM_CAN_FLAGS_KNOWN 0x87u
71
73#define NROS_PLATFORM_CAN_STD_ID_MAX 0x7FFu
74#define NROS_PLATFORM_CAN_EXT_ID_MAX 0x1FFFFFFFu
75
77#define NROS_PLATFORM_CAN_CLASSIC_MAX_LEN 8u
78#define NROS_PLATFORM_CAN_FD_MAX_LEN 64u
79
80/* ---- Return codes ---- */
81
83#define NROS_PLATFORM_CAN_OK 0
87#define NROS_PLATFORM_CAN_EINVAL (-1)
89#define NROS_PLATFORM_CAN_ENOTOPEN (-2)
93#define NROS_PLATFORM_CAN_ENOFD (-3)
95#define NROS_PLATFORM_CAN_EAGAIN (-4)
97#define NROS_PLATFORM_CAN_EBUSOFF (-5)
100#define NROS_PLATFORM_CAN_ENOTSUP (-6)
102#define NROS_PLATFORM_CAN_ENODEV (-7)
104#define NROS_PLATFORM_CAN_EIO (-8)
105
106/* ---- Types ---- */
107
111typedef struct {
113 uint32_t id;
115 uint8_t flags;
117 uint8_t len;
119 uint8_t data[64];
121
125#define NROS_PLATFORM_CAN_OPAQUE_U64S 16u
126
131
134#ifdef __cplusplus
135#define NROS_PLATFORM_CAN_STORAGE_FITS(type) \
136 static_assert(sizeof(type) <= sizeof(nros_platform_can_t) && \
137 alignof(type) <= alignof(nros_platform_can_t), \
138 "NROS_PLATFORM_CAN_OPAQUE_U64S too small for " #type)
139#else
140#define NROS_PLATFORM_CAN_STORAGE_FITS(type) \
141 _Static_assert(sizeof(type) <= sizeof(nros_platform_can_t) && \
142 _Alignof(type) <= _Alignof(nros_platform_can_t), \
143 "NROS_PLATFORM_CAN_OPAQUE_U64S too small for " #type)
144#endif
145
146/* ---- Calls ---- */
147
157int8_t nros_platform_can_open(nros_platform_can_t *can, const char *device, uint8_t want_fd);
158
162 uint32_t timeout_us);
163
167
172 uint32_t timeout_us);
173
176
177/* ---- The one frame check every backend applies ---- */
178
183static inline int8_t nros_platform_can_frame_check(const nros_platform_can_frame_t *frame, uint8_t fd_active) {
184 uint8_t flags;
185 uint8_t len;
186 if (frame == NULL) {
188 }
189 flags = frame->flags;
190 len = frame->len;
191 if ((flags & (uint8_t) ~NROS_PLATFORM_CAN_FLAGS_KNOWN) != 0u) {
193 }
197 }
198 if ((flags & NROS_PLATFORM_CAN_FLAG_FD) == 0u) {
201 }
203 }
204 if (fd_active == 0u) {
206 }
207 if (len <= 8u || len == 12u || len == 16u || len == 20u || len == 24u || len == 32u ||
208 len == 48u || len == 64u) {
210 }
212}
213
214#ifdef __cplusplus
215}
216#endif
217
218#endif /* NROS_PLATFORM_CAN_H */
Canonical C ABI for the nros platform abstraction.
size_t len
Definition platform.h:961
#define NROS_PLATFORM_CAN_EINVAL
Definition platform_can.h:87
#define NROS_PLATFORM_CAN_OPAQUE_U64S
Definition platform_can.h:125
#define NROS_PLATFORM_CAN_FLAG_BRS
Definition platform_can.h:64
void nros_platform_can_close(nros_platform_can_t *can)
#define NROS_PLATFORM_CAN_FLAG_FD
Definition platform_can.h:62
static int8_t nros_platform_can_frame_check(const nros_platform_can_frame_t *frame, uint8_t fd_active)
Definition platform_can.h:183
#define NROS_PLATFORM_CAN_OK
Definition platform_can.h:83
#define NROS_PLATFORM_CAN_FLAG_EXT
Definition platform_can.h:59
int8_t nros_platform_can_send(nros_platform_can_t *can, const nros_platform_can_frame_t *frame, uint32_t timeout_us)
int8_t nros_platform_can_open(nros_platform_can_t *can, const char *device, uint8_t want_fd)
#define NROS_PLATFORM_CAN_CLASSIC_MAX_LEN
Definition platform_can.h:77
#define NROS_PLATFORM_CAN_EXT_ID_MAX
Definition platform_can.h:74
int8_t nros_platform_can_recv(nros_platform_can_t *can, nros_platform_can_frame_t *frame, uint32_t timeout_us)
uint8_t nros_platform_can_fd_active(const nros_platform_can_t *can)
#define NROS_PLATFORM_CAN_STD_ID_MAX
Definition platform_can.h:73
#define NROS_PLATFORM_CAN_FLAGS_KNOWN
Definition platform_can.h:70
#define NROS_PLATFORM_CAN_ENOFD
Definition platform_can.h:93
Definition platform_can.h:111
uint32_t id
Definition platform_can.h:113
uint8_t flags
Definition platform_can.h:115
uint8_t len
Definition platform_can.h:117
uint8_t data[64]
Definition platform_can.h:119
Definition platform_can.h:128
uint64_t opaque[16u]
Definition platform_can.h:129