123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- #ifndef ZEPHYR_INCLUDE_ISOTP_H_
- #define ZEPHYR_INCLUDE_ISOTP_H_
- #include <drivers/can.h>
- #include <zephyr/types.h>
- #include <net/buf.h>
- #define ISOTP_N_OK 0
- #define ISOTP_N_TIMEOUT_A -1
- #define ISOTP_N_TIMEOUT_BS -2
- #define ISOTP_N_TIMEOUT_CR -3
- #define ISOTP_N_WRONG_SN -4
- #define ISOTP_N_INVALID_FS -5
- #define ISOTP_N_UNEXP_PDU -6
- #define ISOTP_N_WFT_OVRN -7
- #define ISOTP_N_BUFFER_OVERFLW -8
- #define ISOTP_N_ERROR -9
- #define ISOTP_NO_FREE_FILTER -10
- #define ISOTP_NO_NET_BUF_LEFT -11
- #define ISOTP_NO_BUF_DATA_LEFT -12
- #define ISOTP_NO_CTX_LEFT -13
- #define ISOTP_RECV_TIMEOUT -14
- #define ISOTP_FIXED_ADDR_SA_POS (0U)
- #define ISOTP_FIXED_ADDR_SA_MASK (0xFF << ISOTP_FIXED_ADDR_SA_POS)
- #define ISOTP_FIXED_ADDR_TA_POS (8U)
- #define ISOTP_FIXED_ADDR_TA_MASK (0xFF << ISOTP_FIXED_ADDR_TA_POS)
- #define ISOTP_FIXED_ADDR_PRIO_POS (26U)
- #define ISOTP_FIXED_ADDR_PRIO_MASK (0x7 << ISOTP_FIXED_ADDR_PRIO_POS)
- #define ISOTP_FIXED_ADDR_RX_MASK (0x03FFFF00)
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct isotp_msg_id {
-
- union {
- uint32_t std_id : 11;
- uint32_t ext_id : 29;
- };
-
- uint8_t ext_addr;
-
- uint8_t id_type : 1;
-
- uint8_t use_ext_addr : 1;
-
- uint8_t use_fixed_addr : 1;
- };
- struct isotp_fc_opts {
- uint8_t bs;
- uint8_t stmin;
- };
- typedef void (*isotp_tx_callback_t)(int error_nr, void *arg);
- struct isotp_send_ctx;
- struct isotp_recv_ctx;
- int isotp_bind(struct isotp_recv_ctx *ctx, const struct device *can_dev,
- const struct isotp_msg_id *rx_addr,
- const struct isotp_msg_id *tx_addr,
- const struct isotp_fc_opts *opts,
- k_timeout_t timeout);
- void isotp_unbind(struct isotp_recv_ctx *ctx);
- int isotp_recv(struct isotp_recv_ctx *ctx, uint8_t *data, size_t len,
- k_timeout_t timeout);
- int isotp_recv_net(struct isotp_recv_ctx *ctx, struct net_buf **buffer,
- k_timeout_t timeout);
- int isotp_send(struct isotp_send_ctx *ctx, const struct device *can_dev,
- const uint8_t *data, size_t len,
- const struct isotp_msg_id *tx_addr,
- const struct isotp_msg_id *rx_addr,
- isotp_tx_callback_t complete_cb, void *cb_arg);
- #ifdef CONFIG_ISOTP_ENABLE_CONTEXT_BUFFERS
- int isotp_send_ctx_buf(const struct device *can_dev,
- const uint8_t *data, size_t len,
- const struct isotp_msg_id *tx_addr,
- const struct isotp_msg_id *rx_addr,
- isotp_tx_callback_t complete_cb, void *cb_arg,
- k_timeout_t timeout);
- int isotp_send_net_ctx_buf(const struct device *can_dev,
- struct net_buf *data,
- const struct isotp_msg_id *tx_addr,
- const struct isotp_msg_id *rx_addr,
- isotp_tx_callback_t complete_cb, void *cb_arg,
- k_timeout_t timeout);
- #endif
- #if defined(CONFIG_ISOTP_USE_TX_BUF) && \
- defined(CONFIG_ISOTP_ENABLE_CONTEXT_BUFFERS)
- int isotp_send_buf(const struct device *can_dev,
- const uint8_t *data, size_t len,
- const struct isotp_msg_id *tx_addr,
- const struct isotp_msg_id *rx_addr,
- isotp_tx_callback_t complete_cb, void *cb_arg,
- k_timeout_t timeout);
- #endif
- struct isotp_callback {
- isotp_tx_callback_t cb;
- void *arg;
- };
- struct isotp_send_ctx {
- int filter_id;
- uint32_t error_nr;
- const struct device *can_dev;
- union {
- struct net_buf *buf;
- struct {
- const uint8_t *data;
- size_t len;
- };
- };
- struct k_work work;
- struct _timeout timeout;
- union {
- struct isotp_callback fin_cb;
- struct k_sem fin_sem;
- };
- struct isotp_fc_opts opts;
- uint8_t state;
- uint8_t tx_backlog;
- struct isotp_msg_id rx_addr;
- struct isotp_msg_id tx_addr;
- uint8_t wft;
- uint8_t bs;
- uint8_t sn : 4;
- uint8_t is_net_buf : 1;
- uint8_t is_ctx_slab : 1;
- uint8_t has_callback: 1;
- };
- struct isotp_recv_ctx {
- int filter_id;
- const struct device *can_dev;
- struct net_buf *buf;
- struct net_buf *act_frag;
- sys_snode_t alloc_node;
- uint32_t length;
- int error_nr;
- struct k_work work;
- struct _timeout timeout;
- struct k_fifo fifo;
- struct isotp_msg_id rx_addr;
- struct isotp_msg_id tx_addr;
- struct isotp_fc_opts opts;
- uint8_t state;
- uint8_t bs;
- uint8_t wft;
- uint8_t sn_expected : 4;
- };
- #ifdef __cplusplus
- }
- #endif
- #endif
|