dev_can.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-05-14 aubrcool@qq.com first version
  9. * 2015-07-06 Bernard remove RT_CAN_USING_LED.
  10. * 2022-05-08 hpmicro add CANFD support, fixed typos
  11. */
  12. #ifndef __DEV_CAN_H_
  13. #define __DEV_CAN_H_
  14. #include <rtthread.h>
  15. #ifndef RT_CANMSG_BOX_SZ
  16. #define RT_CANMSG_BOX_SZ 16
  17. #endif
  18. #ifndef RT_CANSND_BOX_NUM
  19. #define RT_CANSND_BOX_NUM 1
  20. #endif
  21. #ifndef RT_CANSND_MSG_TIMEOUT
  22. #define RT_CANSND_MSG_TIMEOUT 100
  23. #endif
  24. enum CAN_DLC
  25. {
  26. CAN_MSG_0BYTE = 0,
  27. CAN_MSG_1BYTE,
  28. CAN_MSG_2BYTES,
  29. CAN_MSG_3BYTES,
  30. CAN_MSG_4BYTES,
  31. CAN_MSG_5BYTES,
  32. CAN_MSG_6BYTES,
  33. CAN_MSG_7BYTES,
  34. CAN_MSG_8BYTES,
  35. CAN_MSG_12BYTES,
  36. CAN_MSG_16BYTES,
  37. CAN_MSG_20BYTES,
  38. CAN_MSG_24BYTES,
  39. CAN_MSG_32BYTES,
  40. CAN_MSG_48BYTES,
  41. CAN_MSG_64BYTES,
  42. };
  43. enum CANBAUD
  44. {
  45. CAN1MBaud = 1000UL * 1000,/* 1 MBit/sec */
  46. CAN800kBaud = 1000UL * 800, /* 800 kBit/sec */
  47. CAN500kBaud = 1000UL * 500, /* 500 kBit/sec */
  48. CAN250kBaud = 1000UL * 250, /* 250 kBit/sec */
  49. CAN125kBaud = 1000UL * 125, /* 125 kBit/sec */
  50. CAN100kBaud = 1000UL * 100, /* 100 kBit/sec */
  51. CAN50kBaud = 1000UL * 50, /* 50 kBit/sec */
  52. CAN20kBaud = 1000UL * 20, /* 20 kBit/sec */
  53. CAN10kBaud = 1000UL * 10 /* 10 kBit/sec */
  54. };
  55. #define RT_CAN_MODE_NORMAL 0
  56. #define RT_CAN_MODE_LISTEN 1
  57. #define RT_CAN_MODE_LOOPBACK 2
  58. #define RT_CAN_MODE_LOOPBACKANLISTEN 3
  59. #define RT_CAN_MODE_PRIV 0x01
  60. #define RT_CAN_MODE_NOPRIV 0x00
  61. /**
  62. * @defgroup group_drivers_can CAN Driver
  63. * @brief CAN driver api
  64. * @ingroup group_device_driver
  65. *
  66. * <b>Example</b>
  67. * @code {.c}
  68. * #include <rtthread.h>
  69. * #include "rtdevice.h"
  70. *
  71. * #define CAN_DEV_NAME "can1" // CAN 设备名称
  72. *
  73. * static struct rt_semaphore rx_sem; // 用于接收消息的信号量
  74. * static rt_device_t can_dev; // CAN 设备句柄
  75. *
  76. * // 接收数据回调函数
  77. * static rt_err_t can_rx_call(rt_device_t dev, rt_size_t size)
  78. * {
  79. * // CAN 接收到数据后产生中断,调用此回调函数,然后发送接收信号量
  80. * rt_sem_release(&rx_sem);
  81. *
  82. * return RT_EOK;
  83. * }
  84. *
  85. * static void can_rx_thread(void *parameter)
  86. * {
  87. * int i;
  88. * rt_err_t res;
  89. * struct rt_can_msg rxmsg = {0};
  90. *
  91. * // 设置接收回调函数
  92. * rt_device_set_rx_indicate(can_dev, can_rx_call);
  93. *
  94. * #ifdef RT_CAN_USING_HDR
  95. * struct rt_can_filter_item items[5] =
  96. * {
  97. * RT_CAN_FILTER_ITEM_INIT(0x100, 0, 0, 0, 0x700, RT_NULL, RT_NULL), // std,match ID:0x100~0x1ff,hdr 为 - 1,设置默认过滤表
  98. * RT_CAN_FILTER_ITEM_INIT(0x300, 0, 0, 0, 0x700, RT_NULL, RT_NULL), // std,match ID:0x300~0x3ff,hdr 为 - 1
  99. * RT_CAN_FILTER_ITEM_INIT(0x211, 0, 0, 0, 0x7ff, RT_NULL, RT_NULL), // std,match ID:0x211,hdr 为 - 1
  100. * RT_CAN_FILTER_STD_INIT(0x486, RT_NULL, RT_NULL), // std,match ID:0x486,hdr 为 - 1
  101. * {0x555, 0, 0, 0, 0x7ff, 7,} // std,match ID:0x555,hdr 为 7,指定设置 7 号过滤表
  102. * };
  103. * struct rt_can_filter_config cfg = {5, 1, items}; // 一共有 5 个过滤表
  104. * // 设置硬件过滤表
  105. * res = rt_device_control(can_dev, RT_CAN_CMD_SET_FILTER, &cfg);
  106. * RT_ASSERT(res == RT_EOK);
  107. * #endif
  108. * res = RT_TRUE;
  109. * res = rt_device_control(can_dev, RT_CAN_CMD_START, &res);
  110. * while (1)
  111. * {
  112. * // hdr 值为 - 1,表示直接从 uselist 链表读取数据
  113. * rxmsg.hdr = -1;
  114. * // 阻塞等待接收信号量
  115. * rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
  116. * // 从 CAN 读取一帧数据
  117. * rt_device_read(can_dev, 0, &rxmsg, sizeof(rxmsg));
  118. * // 打印数据 ID 及内容
  119. * rt_kprintf("ID:%x", rxmsg.id);
  120. * for (i = 0; i < 8; i++)
  121. * {
  122. * rt_kprintf("%2x", rxmsg.data[i]);
  123. * }
  124. *
  125. * rt_kprintf("\n");
  126. * }
  127. * }
  128. *
  129. * int can_sample(int argc, char *argv[])
  130. * {
  131. * struct rt_can_msg msg = {0};
  132. * rt_err_t res;
  133. * rt_size_t size;
  134. * rt_thread_t thread;
  135. * char can_name[RT_NAME_MAX];
  136. *
  137. * if (argc == 2)
  138. * {
  139. * rt_strncpy(can_name, argv[1], RT_NAME_MAX);
  140. * }
  141. * else
  142. * {
  143. * rt_strncpy(can_name, CAN_DEV_NAME, RT_NAME_MAX);
  144. * }
  145. * // 查找 CAN 设备
  146. * can_dev = rt_device_find(can_name);
  147. * if (!can_dev)
  148. * {
  149. * rt_kprintf("find %s failed!\n", can_name);
  150. * return -RT_ERROR;
  151. * }
  152. *
  153. * // 初始化 CAN 接收信号量
  154. * rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
  155. *
  156. * // 以中断接收及发送方式打开 CAN 设备
  157. * res = rt_device_open(can_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);
  158. * RT_ASSERT(res == RT_EOK);
  159. * // 创建数据接收线程
  160. * thread = rt_thread_create("can_rx", can_rx_thread, RT_NULL, 1024, 25, 10);
  161. * if (thread != RT_NULL)
  162. * {
  163. * rt_thread_startup(thread);
  164. * }
  165. * else
  166. * {
  167. * rt_kprintf("create can_rx thread failed!\n");
  168. * }
  169. *
  170. * msg.id = 0x78; // ID 为 0x78
  171. * msg.ide = RT_CAN_STDID; // 标准格式
  172. * msg.rtr = RT_CAN_DTR; // 数据帧
  173. * msg.len = 8; // 数据长度为 8
  174. * // 待发送的 8 字节数据
  175. * msg.data[0] = 0x00;
  176. * msg.data[1] = 0x11;
  177. * msg.data[2] = 0x22;
  178. * msg.data[3] = 0x33;
  179. * msg.data[4] = 0x44;
  180. * msg.data[5] = 0x55;
  181. * msg.data[6] = 0x66;
  182. * msg.data[7] = 0x77;
  183. * // 发送一帧 CAN 数据
  184. * size = rt_device_write(can_dev, 0, &msg, sizeof(msg));
  185. * if (size == 0)
  186. * {
  187. * rt_kprintf("can dev write data failed!\n");
  188. * }
  189. *
  190. * return res;
  191. * }
  192. * // 导出到 msh 命令列表中
  193. * MSH_CMD_EXPORT(can_sample, can device sample);
  194. * @endcode
  195. */
  196. /*!
  197. * @addtogroup group_drivers_can
  198. * @{
  199. */
  200. #define CAN_RX_FIFO0 (0x00000000U) /*!< CAN receive FIFO 0 */
  201. #define CAN_RX_FIFO1 (0x00000001U) /*!< CAN receive FIFO 1 */
  202. /**
  203. * @brief CAN filter item
  204. */
  205. struct rt_can_filter_item
  206. {
  207. rt_uint32_t id : 29;
  208. rt_uint32_t ide : 1;
  209. rt_uint32_t rtr : 1;
  210. rt_uint32_t mode : 1;
  211. rt_uint32_t mask;
  212. rt_int32_t hdr_bank;/*Should be defined as:rx.FilterBank,which should be changed to rt_int32_t hdr_bank*/
  213. rt_uint32_t rxfifo;/*Add a configuration item that CAN_RX_FIFO0/CAN_RX_FIFO1*/
  214. #ifdef RT_CAN_USING_HDR
  215. rt_err_t (*ind)(rt_device_t dev, void *args , rt_int32_t hdr, rt_size_t size);
  216. void *args;
  217. #endif /*RT_CAN_USING_HDR*/
  218. };
  219. #ifdef RT_CAN_USING_HDR
  220. #define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask,ind,args) \
  221. {(id), (ide), (rtr), (mode),(mask), -1, CAN_RX_FIFO0,(ind), (args)}/*0:CAN_RX_FIFO0*/
  222. #define RT_CAN_FILTER_STD_INIT(id,ind,args) \
  223. RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF,ind,args)
  224. #define RT_CAN_FILTER_EXT_INIT(id,ind,args) \
  225. RT_CAN_FILTER_ITEM_INIT(id,1,0,0,0xFFFFFFFF,ind,args)
  226. #define RT_CAN_STD_RMT_FILTER_INIT(id,ind,args) \
  227. RT_CAN_FILTER_ITEM_INIT(id,0,1,0,0xFFFFFFFF,ind,args)
  228. #define RT_CAN_EXT_RMT_FILTER_INIT(id,ind,args) \
  229. RT_CAN_FILTER_ITEM_INIT(id,1,1,0,0xFFFFFFFF,ind,args)
  230. #define RT_CAN_STD_RMT_DATA_FILTER_INIT(id,ind,args) \
  231. RT_CAN_FILTER_ITEM_INIT(id,0,0,1,0xFFFFFFFF,ind,args)
  232. #define RT_CAN_EXT_RMT_DATA_FILTER_INIT(id,ind,args) \
  233. RT_CAN_FILTER_ITEM_INIT(id,1,0,1,0xFFFFFFFF,ind,args)
  234. #else
  235. #define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask) \
  236. {(id), (ide), (rtr), (mode), (mask), -1, CAN_RX_FIFO0 }/*0:CAN_RX_FIFO0*/
  237. #define RT_CAN_FILTER_STD_INIT(id) \
  238. RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF)
  239. #define RT_CAN_FILTER_EXT_INIT(id) \
  240. RT_CAN_FILTER_ITEM_INIT(id,1,0,0,0xFFFFFFFF)
  241. #define RT_CAN_STD_RMT_FILTER_INIT(id) \
  242. RT_CAN_FILTER_ITEM_INIT(id,0,1,0,0xFFFFFFFF)
  243. #define RT_CAN_EXT_RMT_FILTER_INIT(id) \
  244. RT_CAN_FILTER_ITEM_INIT(id,1,1,0,0xFFFFFFFF)
  245. #define RT_CAN_STD_RMT_DATA_FILTER_INIT(id) \
  246. RT_CAN_FILTER_ITEM_INIT(id,0,0,1,0xFFFFFFFF)
  247. #define RT_CAN_EXT_RMT_DATA_FILTER_INIT(id) \
  248. RT_CAN_FILTER_ITEM_INIT(id,1,0,1,0xFFFFFFFF)
  249. #endif
  250. /**
  251. * @brief CAN filter configuration
  252. */
  253. struct rt_can_filter_config
  254. {
  255. rt_uint32_t count;
  256. rt_uint32_t actived;
  257. struct rt_can_filter_item *items;
  258. };
  259. /**
  260. * @brief CAN timing configuration
  261. */
  262. struct rt_can_bit_timing
  263. {
  264. rt_uint16_t prescaler; /* Pre-scaler */
  265. rt_uint16_t num_seg1; /* Bit Timing Segment 1, in terms of Tq */
  266. rt_uint16_t num_seg2; /* Bit Timing Segment 2, in terms of Tq */
  267. rt_uint8_t num_sjw; /* Synchronization Jump Width, in terms of Tq */
  268. rt_uint8_t num_sspoff; /* Secondary Sample Point Offset, in terms of Tq */
  269. };
  270. /**
  271. * @brief CAN bit timing configuration list
  272. * @note
  273. * items[0] always for CAN2.0/CANFD Arbitration Phase
  274. * items[1] always for CANFD (if it exists)
  275. */
  276. struct rt_can_bit_timing_config
  277. {
  278. rt_uint32_t count;
  279. struct rt_can_bit_timing *items;
  280. };
  281. /**
  282. * @brief CAN configuration
  283. */
  284. struct can_configure
  285. {
  286. rt_uint32_t baud_rate;
  287. rt_uint32_t msgboxsz;
  288. rt_uint32_t sndboxnumber;
  289. rt_uint32_t mode : 8;
  290. rt_uint32_t privmode : 8;
  291. rt_uint32_t reserved : 16;
  292. rt_uint32_t ticks;
  293. #ifdef RT_CAN_USING_HDR
  294. rt_uint32_t maxhdr;
  295. #endif
  296. #ifdef RT_CAN_USING_CANFD
  297. rt_uint32_t baud_rate_fd; /* CANFD data bit rate*/
  298. rt_uint32_t use_bit_timing: 8; /* Use the bit timing for CAN timing configuration */
  299. rt_uint32_t enable_canfd : 8; /* Enable CAN-FD mode */
  300. rt_uint32_t reserved1 : 16;
  301. /* The below fields take effect only if use_bit_timing is non-zero */
  302. struct rt_can_bit_timing can_timing; /* CAN bit-timing /CANFD bit-timing for arbitration phase */
  303. struct rt_can_bit_timing canfd_timing; /* CANFD bit-timing for datat phase */
  304. #endif
  305. };
  306. #define CANDEFAULTCONFIG \
  307. {\
  308. CAN1MBaud,\
  309. RT_CANMSG_BOX_SZ,\
  310. RT_CANSND_BOX_NUM,\
  311. RT_CAN_MODE_NORMAL,\
  312. };
  313. struct rt_can_ops;
  314. #define RT_CAN_CMD_SET_FILTER 0x13
  315. #define RT_CAN_CMD_SET_BAUD 0x14
  316. #define RT_CAN_CMD_SET_MODE 0x15
  317. #define RT_CAN_CMD_SET_PRIV 0x16
  318. #define RT_CAN_CMD_GET_STATUS 0x17
  319. #define RT_CAN_CMD_SET_STATUS_IND 0x18
  320. #define RT_CAN_CMD_SET_BUS_HOOK 0x19
  321. #define RT_CAN_CMD_SET_CANFD 0x1A
  322. #define RT_CAN_CMD_SET_BAUD_FD 0x1B
  323. #define RT_CAN_CMD_SET_BITTIMING 0x1C
  324. #define RT_CAN_CMD_START 0x1D
  325. #define RT_DEVICE_CAN_INT_ERR 0x1000
  326. enum RT_CAN_STATUS_MODE
  327. {
  328. NORMAL = 0,
  329. ERRWARNING = 1,
  330. ERRPASSIVE = 2,
  331. BUSOFF = 4,
  332. };
  333. enum RT_CAN_BUS_ERR
  334. {
  335. RT_CAN_BUS_NO_ERR = 0,
  336. RT_CAN_BUS_BIT_PAD_ERR = 1,
  337. RT_CAN_BUS_FORMAT_ERR = 2,
  338. RT_CAN_BUS_ACK_ERR = 3,
  339. RT_CAN_BUS_IMPLICIT_BIT_ERR = 4,
  340. RT_CAN_BUS_EXPLICIT_BIT_ERR = 5,
  341. RT_CAN_BUS_CRC_ERR = 6,
  342. };
  343. /**
  344. * @brief CAN status
  345. */
  346. struct rt_can_status
  347. {
  348. rt_uint32_t rcverrcnt;
  349. rt_uint32_t snderrcnt;
  350. rt_uint32_t errcode;
  351. rt_uint32_t rcvpkg;
  352. rt_uint32_t dropedrcvpkg;
  353. rt_uint32_t sndpkg;
  354. rt_uint32_t dropedsndpkg;
  355. rt_uint32_t bitpaderrcnt;
  356. rt_uint32_t formaterrcnt;
  357. rt_uint32_t ackerrcnt;
  358. rt_uint32_t biterrcnt;
  359. rt_uint32_t crcerrcnt;
  360. rt_uint32_t rcvchange;
  361. rt_uint32_t sndchange;
  362. rt_uint32_t lasterrtype;
  363. };
  364. #ifdef RT_CAN_USING_HDR
  365. struct rt_can_hdr
  366. {
  367. rt_uint32_t connected;
  368. rt_uint32_t msgs;
  369. struct rt_can_filter_item filter;
  370. struct rt_list_node list;
  371. };
  372. #endif
  373. struct rt_can_device;
  374. typedef rt_err_t (*rt_canstatus_ind)(struct rt_can_device *, void *);
  375. typedef struct rt_can_status_ind_type
  376. {
  377. rt_canstatus_ind ind;
  378. void *args;
  379. } *rt_can_status_ind_type_t;
  380. typedef void (*rt_can_bus_hook)(struct rt_can_device *);
  381. struct rt_can_device
  382. {
  383. struct rt_device parent;
  384. const struct rt_can_ops *ops;
  385. struct can_configure config;
  386. struct rt_can_status status;
  387. rt_uint32_t timerinitflag;
  388. struct rt_timer timer;
  389. struct rt_can_status_ind_type status_indicate;
  390. #ifdef RT_CAN_USING_HDR
  391. struct rt_can_hdr *hdr;
  392. #endif
  393. #ifdef RT_CAN_USING_BUS_HOOK
  394. rt_can_bus_hook bus_hook;
  395. #endif /*RT_CAN_USING_BUS_HOOK*/
  396. struct rt_mutex lock;
  397. void *can_rx;
  398. void *can_tx;
  399. };
  400. typedef struct rt_can_device *rt_can_t;
  401. #define RT_CAN_STDID 0
  402. #define RT_CAN_EXTID 1
  403. #define RT_CAN_DTR 0
  404. #define RT_CAN_RTR 1
  405. typedef struct rt_can_status *rt_can_status_t;
  406. struct rt_can_msg
  407. {
  408. rt_uint32_t id : 29;
  409. rt_uint32_t ide : 1;
  410. rt_uint32_t rtr : 1;
  411. rt_uint32_t rsv : 1;
  412. rt_uint32_t len : 8;
  413. rt_uint32_t priv : 8;
  414. rt_int32_t hdr_index : 8;/*Should be defined as:rx.FilterMatchIndex,which should be changed to rt_int32_t hdr_index : 8*/
  415. #ifdef RT_CAN_USING_CANFD
  416. rt_uint32_t fd_frame : 1;
  417. rt_uint32_t brs : 1;
  418. rt_uint32_t rxfifo : 2;/*Redefined to return :CAN RX FIFO0/CAN RX FIFO1*/
  419. rt_uint32_t reserved : 4;
  420. #else
  421. rt_uint32_t rxfifo : 2;/*Redefined to return :CAN RX FIFO0/CAN RX FIFO1*/
  422. rt_uint32_t reserved : 6;
  423. #endif
  424. #ifdef RT_CAN_USING_CANFD
  425. rt_uint8_t data[64];
  426. #else
  427. rt_uint8_t data[8];
  428. #endif
  429. };
  430. typedef struct rt_can_msg *rt_can_msg_t;
  431. struct rt_can_msg_list
  432. {
  433. struct rt_list_node list;
  434. #ifdef RT_CAN_USING_HDR
  435. struct rt_list_node hdrlist;
  436. struct rt_can_hdr *owner;
  437. #endif
  438. struct rt_can_msg data;
  439. };
  440. struct rt_can_rx_fifo
  441. {
  442. /* software fifo */
  443. struct rt_can_msg_list *buffer;
  444. rt_uint32_t freenumbers;
  445. struct rt_list_node freelist;
  446. struct rt_list_node uselist;
  447. };
  448. #define RT_CAN_SND_RESULT_OK 0
  449. #define RT_CAN_SND_RESULT_ERR 1
  450. #define RT_CAN_SND_RESULT_WAIT 2
  451. #define RT_CAN_EVENT_RX_IND 0x01 /* Rx indication */
  452. #define RT_CAN_EVENT_TX_DONE 0x02 /* Tx complete */
  453. #define RT_CAN_EVENT_TX_FAIL 0x03 /* Tx fail */
  454. #define RT_CAN_EVENT_RX_TIMEOUT 0x05 /* Rx timeout */
  455. #define RT_CAN_EVENT_RXOF_IND 0x06 /* Rx overflow */
  456. struct rt_can_sndbxinx_list
  457. {
  458. struct rt_list_node list;
  459. struct rt_completion completion;
  460. rt_uint32_t result;
  461. };
  462. struct rt_can_tx_fifo
  463. {
  464. struct rt_can_sndbxinx_list *buffer;
  465. struct rt_semaphore sem;
  466. struct rt_list_node freelist;
  467. };
  468. /**
  469. * @brief CAN operators
  470. */
  471. struct rt_can_ops
  472. {
  473. rt_err_t (*configure)(struct rt_can_device *can, struct can_configure *cfg);
  474. rt_err_t (*control)(struct rt_can_device *can, int cmd, void *arg);
  475. rt_ssize_t (*sendmsg)(struct rt_can_device *can, const void *buf, rt_uint32_t boxno);
  476. rt_ssize_t (*recvmsg)(struct rt_can_device *can, void *buf, rt_uint32_t boxno);
  477. };
  478. /**
  479. * @brief Register a CAN device to device list
  480. *
  481. * @param can the CAN device object
  482. * @param name the name of CAN device
  483. * @param ops the CAN device operators
  484. * @param data the private data of CAN device
  485. *
  486. * @return the error code, RT_EOK on successfully
  487. */
  488. rt_err_t rt_hw_can_register(struct rt_can_device *can,
  489. const char *name,
  490. const struct rt_can_ops *ops,
  491. void *data);
  492. /**
  493. * @brief CAN interrupt service routine
  494. *
  495. * @param can the CAN device
  496. * @param event the event mask
  497. */
  498. void rt_hw_can_isr(struct rt_can_device *can, int event);
  499. /*! @}*/
  500. #endif /*__DEV_CAN_H*/