64 #define STAT_RX0IF (1 << 0) 65 #define STAT_RX1IF (1 << 1)
66 #define STAT_TX0REQ (1 << 2)
67 #define STAT_TX0IF (1 << 3)
68 #define STAT_TX1REQ (1 << 4)
69 #define STAT_TX1IF (1 << 5)
70 #define STAT_TX2REQ (1 << 6)
71 #define STAT_TX2IF (1 << 7)
78 #define TXB_TXP_MASK (3 << 0) 79 #define TXB_TXP0 (1 << 0)
80 #define TXB_TXP1 (1 << 1)
81 #define TXB_TXREQ (1 << 3)
82 #define TXB_TXERR (1 << 4)
83 #define TXB_MLOA (1 << 5)
84 #define TXB_ABTF (1 << 6)
91 #define INT_RX0IF (1 << 0) 92 #define INT_RX1IF (1 << 1)
93 #define INT_TX0IF (1 << 2)
94 #define INT_TX1IF (1 << 3)
95 #define INT_TX2IF (1 << 4)
96 #define INT_ERRIF (1 << 5)
97 #define INT_WAKIF (1 << 6)
98 #define INT_MERRF (1 << 7)
154 CAN_PRIORITY_LOW = 0,
155 CAN_PRIORITY_MEDIUM = 1,
156 CAN_PRIORITY_HIGH = 2,
157 CAN_PRIORITY_HIGHEST = 3
240 uint8_t CanCfgBFPCTRL;
249 uint8_t CanCfgTXRTSCTRL;
265 uint8_t CanCfgRXB0CTRL;
473 #endif // DRIVER_CAN_H bool CanSetBitTime(const struct can_t *Can, struct can_bittime_t *BitTime)
Sets up MCP2562x CAN timing parameters. NB! MCP2562x should be in configuration mode.
Read data from / get status of RX0.
uint8_t CanCfgMERRE
Message Error Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
enum can_xbuffer_t CanDownloadFrame(const struct can_t *Can, struct can_frame_t *Frame, enum can_xbuffer_t Buffer)
Receives 1 full CAN frame from MCP2562x after Rx1/Rx2 is ready.
can_priority_t
defines possible outgoing CAN frame priorities as in MCP2562x TXBnCTRL register.
uint8_t CanCfgB1BFM
RX1BF Pin Operation mode bit: 1 = Rx1 interrupt, 0 = Digital Output mode.
uint8_t BTLMODE
PS2 mode (0: PS2=max(PS1,2*TQ) ; 1: PS2 determined by PHSEG2).
holds current CAN instance state variables.
uint8_t BRP
Baud Rate Prescaler (5 bit). TQ = 2*(BRP+1)/Freq.
bool CanDisable(const struct can_t *Can)
Disables interrupts from MCP2562x and releases SPI. Powers down MCP2562x if supported by product HW...
uint8_t CanCfgB2RTSM
TX2RTS Pin mode bit: 1 = RTS of Tx2 on falling edge, 0 = Digital input.
can_err_callback_t CanErrorCb
CAN error interrupt handler.
void CanReset(const struct can_t *Can)
Performs MCP2562x HW reset. MCP2562x switches to configuration mode after reset. NB! It should be ver...
bool CanInit(const struct can_t *Can)
Initialises CAN instance structure, connects it to SPI. Powers up MCP2562x if supported.
uint8_t CanCfgERRIE
Error Interrupt Flag bit (multiple sources in the EFLG register) - must be cleared by MCU to reset in...
uint32_t SpiBaudrate
SPI speed.
enum can_xbuffer_t CanUploadFrame(const struct can_t *Can, struct can_frame_t *Frame, enum can_xbuffer_t Buffer)
Loads 1 full CAN frame to MCP2562x TX register.
Write data to the first available TX / Read data from the RX which came first.
Identifier of filter #0 for RX0.
SPI failed to communicate with MCP.
bool CanInterrupts(const struct can_t *Can, bool Enable)
Sets/resets all the preconfigured interrupts.
uint8_t RXB0CTRLx2
Not used in configuration.
uint8_t CanCfgB0BFE
RX0BF Pin Function Enable bit: 1 = Pin function enabled, operation mode determined by B0BFM bit...
struct can_state_t * State
Pointer to the CAN state.
Identifier of filter #1 for RX0.
Write data to / get status of TX2.
const struct spi_cs_t SpiCs
SPI CS settings.
void(* can_wake_callback_t)(const struct can_t *Can)
The callback is called at CAN chip wakeup.
Driver for the MCU's SPI blocks.
Switch to normal operational mode.
can_xbuffer_t
defines MCP2562x TX/RX buffers for data transmission/reception.
uint8_t CNF3x
Not used in configuration.
holds CAN frame and is used in driver's API to transfer frames between the driver and an application ...
uint8_t CanCfgTX1IE
Tx1 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
uint8_t TXRTSCTRLx
Not used in configuration.
uint8_t CanCfgCLKPRE
CLKOUT Pin Prescaler bits.
bool CanSetFilter(const struct can_t *Can, uint32_t Id, enum can_filter_t Filter)
Sets up MCP2562x acceptance filters. NB! MCP2562x should be in configuration mode.
Switch to configuration mode.
can_rx_callback_t CanRxReadyCb[2]
Rx0/Rx1 interrupt handlers.
Write data to / get status of TX1.
void(* can_rx_callback_t)(const struct can_t *Can, enum can_xbuffer_t BufNum)
The callback is called on CAN frame reception.
Perform SW reset; after that MCP is in configuration mode.
uint8_t CanCfgRX1IE
Rx1 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
uint8_t CanCfgWAKIE
Wake-up Interrupt Flag bit - must be cleared by MCU to reset interrupt condition. ...
void(* can_err_callback_t)(const struct can_t *Can, uint8_t EREG)
The callback is called at CAN chip error.
uint8_t SJW
Synchronisation Jump Width Length = (SJW+1)*TQ (0-3)
uint8_t CanCfgWAKFIL
1 : Wake-up filter enabled
bool CanClearIF(const struct can_t *Can, uint8_t Mask)
Clear MCP2562x interrupt flag(s) by mask.
uint8_t Length
actual frame data length (0-8)
uint8_t CanCfgB0BFM
RX0BF Pin Operation mode bit: 1 = Rx0 interrupt, 0 = Digital Output mode.
uint8_t CanCfgCANINTE
CANINTE register content.
Identifier of filter #0 for RX1.
const struct spi_t * Spi
Pointer to the SPI interface instance.
void CanInterruptCb(const struct can_t *Can)
Driver's HW interrupt callback to be exposed to EVE config.
uint8_t CanCfgB1BFE
RX1BF Pin Function Enable bit: 1 = Pin function enabled, operation mode determined by B1BFM bit...
void(* can_tx_callback_t)(const struct can_t *Can, enum can_xbuffer_t BufNum, uint8_t TXBnCTRL)
The callback is called at CAN transmission ready and transmission error.
uint8_t CanCfgOSM
1 : one-shot mode is on
uint8_t CanCfgSOF
Start-of-Frame Signal bit (!!!only if CLKOUT pin is enabled!!!)
Identifier of filter #1 for RX1.
bool CanReadStatus(const struct can_t *Can, uint8_t *Status)
Gets MCP2562x TX/RX buffers status (IF/RTS).
uint8_t SAM
Sample Point Configuration bit (0: 1 sample ; 1: 3 samples).
can_wake_callback_t CanWakeCb
CAN wakeup interrupt handler.
uint8_t PRSEG
Propagation Segment Length bits = (PRSEG+1)*TQ (0-7)
bool CanSendFrame(const struct can_t *Can, enum can_xbuffer_t Buffer, enum can_priority_t Priority, can_tx_callback_t TransmitReadyCb)
Sets priority and RTS flag to one of MCP2562x TX registers initiating transfer.
uint8_t PinReset
Pin number for MCP2562x HW RESET.
enum can_mode_t CanGetMode(const struct can_t *Can)
Reads current MCP2562x mode of operation.
uint8_t CanCfgRX0IE
Rx0 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
uint8_t CANCTRLx
Not used in configuration.
can_mode_t
defines possible MCP2562x modes of operation for CanSetMode() function. NB: values correspond to REQO...
uint8_t RXB0CTRLx1
Not used in configuration.
Identifier of filter #3 for RX1.
uint8_t PHSEG1
Phase Segment 1 Length bits = (PHSEG1+1)*TQ (0-7)
uint8_t CanCfgB0RTSM
TX0RTS Pin mode bit: 1 = RTS of Tx0 on falling edge, 0 = Digital input.
CAN driver descriptor: static structure for configuration of driver instance.
uint8_t CanCfgCANCTRL
CANCTRL register content.
Switch to listen-only mode.
uint8_t CanCfgBUKT
Rollover Enable bit: 1 = Rx0 message will rollover to Rx1 if Rx0 is full.
uint8_t BFPCTRLx
Not used in configuration.
Write data to / get status of TX0.
uint8_t CanCfgTX0IE
Tx0 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
Read data from / get status of RX1.
bool CanSetup(const struct can_t *Can)
Sets up MCP2562x registers according to preconfigured parameters. NB! MCP2562x should be in configura...
can_filter_t
defines MCP2562x Rx filter Ids and Masks.
uint8_t CanCfgCLKEN
1 : CLKOUT pin is enabled
uint8_t PHSEG2
Phase Segment 2 Length bits = (PHSEG2+1)*TQ (1-7)
Identifier of filter #2 for RX1.
CAN timing initialisation structure definition.
uint8_t CanCfgTX2IE
Tx2 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
uint8_t CanCfgB1RTSM
TX1RTS Pin mode bit: 1 = RTS of Tx1 on falling edge, 0 = Digital input.
bool CanSetMode(const struct can_t *Can, enum can_mode_t Mode)
Sets current MCP2562x mode of operation. NB! After setting new mode it should be verified that MCP256...