1 #pragma once 2 3 #include <lk/compiler.h> 4 #include <stdbool.h> 5 #include <stdint.h> 6 7 #include <sys/types.h> 8 9 typedef struct { 10 unsigned id:11; // Standard CAN identifier. 11 unsigned id_ex:18; // Extended CAN identifier. 12 unsigned rtr:1; // Remote transmit request. 13 unsigned ide:1; // Identifier extension. 14 unsigned pad:1; 15 16 uint8_t dlc; // Data length. 17 uint8_t data[8]; 18 } __PACKED can_msg_t; 19 20 /** 21 * can_init 22 * 23 * Initialize the CAN peripheral. 24 * 25 * @param[in] loopback If true, puts the can interface in loopback mode. 26 */ 27 void can_init(bool loopback); 28 29 /** 30 * can_send 31 * 32 * Queues a can message to be sent. Does not block if there is no space 33 * in the CAN mailboxes. 34 * 35 * @param[in] msg Message to send. 36 * 37 * @return Negative error code on error, size of data queued on success. 38 */ 39 ssize_t can_send(const can_msg_t *msg); 40 41 /** 42 * can_recv 43 * 44 * @param[out] msg Received message 45 * @param[in] block If true, can_recv() will block until a message is received. 46 * 47 * @return Negative error code on error, size of data received on success. 48 */ 49 ssize_t can_recv(can_msg_t *msg, bool block); 50 51