2015-01-14 07:09:08 -08:00
|
|
|
#ifndef _CAN_H
|
|
|
|
#define _CAN_H
|
|
|
|
|
|
|
|
enum can_bitrate {
|
2020-03-05 16:57:22 -08:00
|
|
|
CAN_BITRATE_10K = 0,
|
2015-05-15 11:20:10 -07:00
|
|
|
CAN_BITRATE_20K,
|
2015-05-14 14:41:28 -07:00
|
|
|
CAN_BITRATE_50K,
|
2015-05-15 11:20:10 -07:00
|
|
|
CAN_BITRATE_100K,
|
|
|
|
CAN_BITRATE_125K,
|
|
|
|
CAN_BITRATE_250K,
|
|
|
|
CAN_BITRATE_500K,
|
|
|
|
CAN_BITRATE_750K,
|
|
|
|
CAN_BITRATE_1000K,
|
2020-03-05 16:57:22 -08:00
|
|
|
|
|
|
|
CAN_BITRATE_INVALID,
|
2015-01-14 07:09:08 -08:00
|
|
|
};
|
|
|
|
|
2021-02-21 10:03:27 -08:00
|
|
|
typedef enum can_bus_state {
|
|
|
|
OFF_BUS = 0,
|
|
|
|
ON_BUS = 1,
|
|
|
|
} can_bus_state_t;
|
|
|
|
|
|
|
|
|
|
|
|
// CAN transmit buffering
|
|
|
|
#define TXQUEUE_LEN 28 // Number of buffers allocated
|
|
|
|
#define TXQUEUE_DATALEN 8 // CAN DLC length of data buffers
|
|
|
|
|
|
|
|
typedef struct cantxbuf_
|
|
|
|
{
|
|
|
|
uint8_t data[TXQUEUE_LEN][TXQUEUE_DATALEN]; // Data buffer
|
|
|
|
CAN_TxHeaderTypeDef header[TXQUEUE_LEN]; // Header buffer
|
|
|
|
uint8_t head; // Head pointer
|
|
|
|
uint8_t tail; // Tail pointer
|
|
|
|
uint8_t full; // TODO: Set this when we are full, clear when the tail moves one.
|
|
|
|
} can_txbuf_t;
|
|
|
|
|
2015-01-14 07:09:08 -08:00
|
|
|
|
2021-02-21 10:03:27 -08:00
|
|
|
// Prototypes
|
2015-01-14 07:09:08 -08:00
|
|
|
void can_init(void);
|
|
|
|
void can_enable(void);
|
|
|
|
void can_disable(void);
|
|
|
|
void can_set_bitrate(enum can_bitrate bitrate);
|
2016-01-25 11:16:45 -08:00
|
|
|
void can_set_silent(uint8_t silent);
|
2018-12-31 11:24:46 -08:00
|
|
|
void can_set_autoretransmit(uint8_t autoretransmit);
|
2020-03-05 16:57:22 -08:00
|
|
|
uint32_t can_tx(CAN_TxHeaderTypeDef *tx_msg_header, uint8_t *tx_msg_data);
|
|
|
|
uint32_t can_rx(CAN_RxHeaderTypeDef *rx_msg_header, uint8_t *rx_msg_data);
|
|
|
|
|
2016-08-16 19:15:20 -07:00
|
|
|
|
|
|
|
void can_process(void);
|
|
|
|
|
2016-01-25 11:16:45 -08:00
|
|
|
uint8_t is_can_msg_pending(uint8_t fifo);
|
2016-08-13 11:22:24 -07:00
|
|
|
CAN_HandleTypeDef* can_gethandle(void);
|
2015-01-14 07:09:08 -08:00
|
|
|
|
|
|
|
#endif // _CAN_H
|