EVE 1.0
can.h
Go to the documentation of this file.
1 #ifndef DRIVER_CAN_H
2 #define DRIVER_CAN_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2015-2016, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * \brief Driver for CAN MCP2562x in EVE.
36  *
37  * \author SE, Jetro AS
38  */ /******************************************************************/
39 
40 #include <dev/spi.h>
41 
42 /**
43  * \defgroup MCP2562x MCP2562x CAN chip driver
44  * \ingroup extdrv
45  * This CAN driver supports MCP2562x CAN chip connected with EVE SPI driver.
46  *
47  * Public functionality included:
48  * - Init, HW and SW reset, full range of MCP2562x operation modes selection.
49  * - Preconfigured setup of GPIO assignments, available interrupts and chip behavior.
50  * - Run-time setup of desired CAN bus speed and address filtering.
51  * - Transmission and reception of full CAN frames.
52  *
53  * \{
54  */
55 
56 /******************************************************************************
57  * CAN driver public constants
58  *****************************************************************************/
59 
60 /**
61  * @name MCP2562x "Read Status" command result bit masks
62  * @{
63  */
64 #define STAT_RX0IF (1 << 0) //!< Rx0 buffer interrupt flag (Rx0 is ready to be read)
65 #define STAT_RX1IF (1 << 1) //!< Rx1 buffer interrupt flag (Rx1 is ready to be read)
66 #define STAT_TX0REQ (1 << 2) //!< Tx0 RTS flag (Tx0 is pending)
67 #define STAT_TX0IF (1 << 3) //!< Tx0 buffer interrupt flag (Tx0 being sent)
68 #define STAT_TX1REQ (1 << 4) //!< Tx1 RTS flag (Tx1 is pending)
69 #define STAT_TX1IF (1 << 5) //!< Tx1 buffer interrupt flag (Tx1 being sent)
70 #define STAT_TX2REQ (1 << 6) //!< Tx2 RTS flag (Tx2 is pending)
71 #define STAT_TX2IF (1 << 7) //!< Tx2 buffer interrupt flag (Tx2 being sent)
72 /** @} */
73 
74 /**
75  * @name MCP2562x TXBnCTRL register (Transmit Buffer [n] Control) bit masks
76  * @{
77  */
78 #define TXB_TXP_MASK (3 << 0) //!< Transmit Buffer Priority mask
79 #define TXB_TXP0 (1 << 0) //!< Transmit Buffer Priority low bit
80 #define TXB_TXP1 (1 << 1) //!< Transmit Buffer Priority high bit
81 #define TXB_TXREQ (1 << 3) //!< Message Transmit Request
82 #define TXB_TXERR (1 << 4) //!< Transmission Error Detected
83 #define TXB_MLOA (1 << 5) //!< Message Lost Arbitration
84 #define TXB_ABTF (1 << 6) //!< Message Aborted Flag
85 /** @} */
86 
87 /**
88  * @name MCP2562x interrupt bit masks
89  * @{
90  */
91 #define INT_RX0IF (1 << 0) //!< Rx0 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
92 #define INT_RX1IF (1 << 1) //!< Rx1 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
93 #define INT_TX0IF (1 << 2) //!< Tx0 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
94 #define INT_TX1IF (1 << 3) //!< Tx1 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
95 #define INT_TX2IF (1 << 4) //!< Tx2 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
96 #define INT_ERRIF (1 << 5) //!< Error Interrupt Flag bit (multiple sources in the EFLG register) - must be cleared by MCU to reset interrupt condition
97 #define INT_WAKIF (1 << 6) //!< Wake-up Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
98 #define INT_MERRF (1 << 7) //!< Message Error Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
99 /** @} */
100 
101 
102 /******************************************************************************
103  * CAN driver public types
104  *****************************************************************************/
105 
106 /**
107  * @brief defines possible MCP2562x modes of operation for CanSetMode() function.\n
108  * NB: values correspond to REQOP bits in CANCTRL register (except CAN_MODE_RESET and CAN_MODE_SPI_BUSY)
109  */
111 {
112  CAN_MODE_NORMAL = 0x00, //!< Switch to normal operational mode
113  CAN_MODE_SLEEP = 0x01, //!< Switch to sleep mode
114  CAN_MODE_LOOPBACK = 0x02, //!< Switch to loopback mode
115  CAN_MODE_LISTENONLY = 0x03, //!< Switch to listen-only mode
116  CAN_MODE_CONFIGURE = 0x04, //!< Switch to configuration mode
117  CAN_MODE_RESET = 0x0F, //!< Perform SW reset; after that MCP is in configuration mode
118  CAN_MODE_SPI_BUSY = 0xFF //!< SPI failed to communicate with MCP
119 };
120 
121 /**
122  * @brief defines MCP2562x TX/RX buffers for data transmission/reception.
123  */
125 {
126  CAN_TX0 = 0, //!< Write data to / get status of TX0
127  CAN_TX1, //!< Write data to / get status of TX1
128  CAN_TX2, //!< Write data to / get status of TX2
129  CAN_RX0, //!< Read data from / get status of RX0
130  CAN_RX1, //!< Read data from / get status of RX1
131  CAN_FIFO //!< Write data to the first available TX / Read data from the RX which came first
132 };
133 
134 /**
135  * @brief defines MCP2562x Rx filter Ids and Masks.
136  */
138 {
139  CAN_RXF0 = 0, //!< Identifier of filter #0 for RX0
140  CAN_RXF1, //!< Identifier of filter #1 for RX0
141  CAN_RXF2, //!< Identifier of filter #0 for RX1
142  CAN_RXF3, //!< Identifier of filter #1 for RX1
143  CAN_RXF4, //!< Identifier of filter #2 for RX1
144  CAN_RXF5, //!< Identifier of filter #3 for RX1
145  CAN_RXM0, //!< Mask of filter for RX0
146  CAN_RXM1 //!< Mask of filter for RX1
147 };
148 
149 /**
150  * @brief defines possible outgoing CAN frame priorities as in MCP2562x TXBnCTRL register.
151  */
153 {
154  CAN_PRIORITY_LOW = 0,
155  CAN_PRIORITY_MEDIUM = 1,
156  CAN_PRIORITY_HIGH = 2,
157  CAN_PRIORITY_HIGHEST = 3
158 };
159 
160 struct can_t;
161 
162 /**
163  * @brief The callback is called on CAN frame reception
164  * @param Can CAN driver descriptor
165  * @param BufNum Buffer with received data (Rx0/Rx1)
166  */
167 typedef void
168  (*can_rx_callback_t)(const struct can_t* Can, enum can_xbuffer_t BufNum);
169 
170 /**
171  * @brief The callback is called at CAN transmission ready and transmission error
172  * @param Can CAN driver descriptor
173  * @param BufNum Buffer transmitted (Tx0/Tx1/Tx2)
174  * @param TXBnCTRL MCP2562x Transmit buffer control register
175  * Masks:
176  * TXB_TXP0 - Transmit Buffer Priority low bit
177  * TXB_TXP1 - Transmit Buffer Priority high bit
178  * TXB_TXREQ - Message Transmit Request
179  * TXB_TXERR - Transmission Error Detected
180  * TXB_MLOA - Message Lost Arbitration
181  * TXB_ABTF - Message Aborted Flag
182  */
183 typedef void (*can_tx_callback_t)(const struct can_t* Can,
184  enum can_xbuffer_t BufNum,
185  uint8_t TXBnCTRL);
186 
187 /**
188  * @brief The callback is called at CAN chip wakeup
189  * @param Can CAN driver descriptor
190  */
191 typedef void (*can_wake_callback_t)(const struct can_t* Can);
192 
193 /**
194  * @brief The callback is called at CAN chip error
195  * @param Can CAN handling structure
196  * @param EREG MCP2562x EREG register
197  */
198 typedef void (*can_err_callback_t)(const struct can_t* Can, uint8_t EREG);
199 
200 /**
201  * @brief CAN driver descriptor: static structure for configuration of driver instance.
202  */
203 struct can_t
204 {
205  const struct spi_t* Spi; //!< Pointer to the SPI interface instance
206  const struct spi_cs_t SpiCs; //!< SPI CS settings
207  uint32_t SpiBaudrate; //!< SPI speed
208  struct can_state_t* State; //!< Pointer to the CAN state
209  uint8_t PinReset; //!< Pin number for MCP2562x HW RESET
210  union {
211  struct {
212  uint8_t CanCfgCLKPRE :2; //!< CLKOUT Pin Prescaler bits
213  uint8_t CanCfgCLKEN :1; //!< 1 : CLKOUT pin is enabled
214  uint8_t CanCfgOSM :1; //!< 1 : one-shot mode is on
215  uint8_t CANCTRLx :4; //!< Not used in configuration
216  };
217  uint8_t CanCfgCANCTRL; //!< CANCTRL register content
218  };
219  union {
220  struct {
221  uint8_t CanCfgRX0IE :1; //!< Rx0 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
222  uint8_t CanCfgRX1IE :1; //!< Rx1 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
223  uint8_t CanCfgTX0IE :1; //!< Tx0 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
224  uint8_t CanCfgTX1IE :1; //!< Tx1 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
225  uint8_t CanCfgTX2IE :1; //!< Tx2 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
226  uint8_t CanCfgERRIE :1; //!< Error Interrupt Flag bit (multiple sources in the EFLG register) - must be cleared by MCU to reset interrupt condition
227  uint8_t CanCfgWAKIE :1; //!< Wake-up Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
228  uint8_t CanCfgMERRE :1; //!< Message Error Interrupt Flag bit - must be cleared by MCU to reset interrupt condition
229  };
230  uint8_t CanCfgCANINTE; //!< CANINTE register content
231  };
232  union {
233  struct {
234  uint8_t CanCfgB0BFM :1; //!< RX0BF Pin Operation mode bit: 1 = Rx0 interrupt, 0 = Digital Output mode
235  uint8_t CanCfgB1BFM :1; //!< RX1BF Pin Operation mode bit: 1 = Rx1 interrupt, 0 = Digital Output mode
236  uint8_t CanCfgB0BFE :1; //!< RX0BF Pin Function Enable bit: 1 = Pin function enabled, operation mode determined by B0BFM bit
237  uint8_t CanCfgB1BFE :1; //!< RX1BF Pin Function Enable bit: 1 = Pin function enabled, operation mode determined by B1BFM bit
238  uint8_t BFPCTRLx :4; //!< Not used in configuration
239  };
240  uint8_t CanCfgBFPCTRL;
241  };
242  union {
243  struct {
244  uint8_t CanCfgB0RTSM :1; //!< TX0RTS Pin mode bit: 1 = RTS of Tx0 on falling edge, 0 = Digital input
245  uint8_t CanCfgB1RTSM :1; //!< TX1RTS Pin mode bit: 1 = RTS of Tx1 on falling edge, 0 = Digital input
246  uint8_t CanCfgB2RTSM :1; //!< TX2RTS Pin mode bit: 1 = RTS of Tx2 on falling edge, 0 = Digital input
247  uint8_t TXRTSCTRLx :5; //!< Not used in configuration
248  };
249  uint8_t CanCfgTXRTSCTRL;
250  };
251  union {
252  struct {
253  uint8_t CNF3x :6; //!< Not used in configuration
254  uint8_t CanCfgWAKFIL :1; //!< 1 : Wake-up filter enabled
255  uint8_t CanCfgSOF :1; //!< Start-of-Frame Signal bit (!!!only if CLKOUT pin is enabled!!!)
256  };
257  uint8_t CanCfgCNF3;
258  };
259  union {
260  struct {
261  uint8_t RXB0CTRLx1 :6; //!< Not used in configuration
262  uint8_t CanCfgBUKT :1; //!< Rollover Enable bit: 1 = Rx0 message will rollover to Rx1 if Rx0 is full
263  uint8_t RXB0CTRLx2 :2; //!< Not used in configuration
264  };
265  uint8_t CanCfgRXB0CTRL;
266  };
267 
268  can_rx_callback_t CanRxReadyCb[2]; //!< Rx0/Rx1 interrupt handlers
269  can_wake_callback_t CanWakeCb; //!< CAN wakeup interrupt handler
270  can_err_callback_t CanErrorCb; //!< CAN error interrupt handler
271 };
272 
273 /**
274  * @brief holds current CAN instance state variables.
275  */
277 {
278  can_tx_callback_t CanTxReadyCb[3]; //!< Tx ready callbacks for TX0/TX1/TX2
279 };
280 
281 /**
282  * @brief holds CAN frame and is used in driver's API to transfer
283  * frames between the driver and an application
284  */
286 {
287  union {
288  struct {
289  uint32_t ID :29; //!< Device ID (11 or 29 bit)
290  uint32_t ERR : 1; //!< error message frame flag
291  uint32_t RTR : 1; //!< remote transmission request flag
292  uint32_t EXT : 1; //!< 29bit Id flag
293  };
294  uint32_t IDFull;
295  };
296  uint8_t Data[8]; //!< CAN frame payload (0 to 8 bytes)
297  uint8_t Length; //!< actual frame data length (0-8)
298 };
299 
300 /**
301  * @brief CAN timing initialisation structure definition
302  */
304 {
305  uint8_t BRP; //!< Baud Rate Prescaler (5 bit). TQ = 2*(BRP+1)/Freq
306  uint8_t SJW; //!< Synchronisation Jump Width Length = (SJW+1)*TQ (0-3)
307  uint8_t PRSEG; //!< Propagation Segment Length bits = (PRSEG+1)*TQ (0-7)
308  uint8_t PHSEG1; //!< Phase Segment 1 Length bits = (PHSEG1+1)*TQ (0-7)
309  uint8_t PHSEG2; //!< Phase Segment 2 Length bits = (PHSEG2+1)*TQ (1-7)
310  uint8_t BTLMODE; //!< PS2 mode (0: PS2=max(PS1,2*TQ) ; 1: PS2 determined by PHSEG2).
311  uint8_t SAM; //!< Sample Point Configuration bit (0: 1 sample ; 1: 3 samples).
312 };
313 
314 
315 /******************************************************************************
316  * CAN driver public functions
317  *****************************************************************************/
318 
319 /**
320  * @brief Driver's HW interrupt callback to be exposed to EVE config
321  * @param Can Pointer to CAN instance structure
322  */
323 void CanInterruptCb(const struct can_t* Can);
324 
325 /**
326  * @brief Initialises CAN instance structure, connects it to SPI.\n
327  * Powers up MCP2562x if supported
328  * @param Can CAN driver descriptor
329  */
330 extern bool CanInit(const struct can_t* Can);
331 
332 /**
333  * @brief Disables interrupts from MCP2562x and releases SPI.\n
334  * Powers down MCP2562x if supported by product HW.
335  * @param Can CAN driver descriptor
336  */
337 extern bool CanDisable(const struct can_t* Can);
338 
339 /**
340  * @brief Performs MCP2562x HW reset. MCP2562x switches to configuration mode after reset.\n
341  * NB! It should be verified that MCP2562x is in configuration mode with
342  * CanGetMode() function after reset before any subsequent operation.
343  * @param Can CAN driver descriptor
344  */
345 extern void CanReset(const struct can_t* Can);
346 
347 /**
348  * @brief Sets up MCP2562x registers according to preconfigured parameters.\n
349  * NB! MCP2562x should be in configuration mode.
350  * @param Can CAN driver descriptor
351  */
352 extern bool CanSetup(const struct can_t* Can);
353 
354 /**
355  * @brief Sets up MCP2562x CAN timing parameters.\n
356  * NB! MCP2562x should be in configuration mode.
357  * @param Can CAN driver descriptor
358  * @param BitTime Pointer to can_bittime_t structure containing the configuration information.
359  */
360 extern bool CanSetBitTime(const struct can_t* Can,
361  struct can_bittime_t* BitTime);
362 
363 /**
364  * @brief Sets up MCP2562x acceptance filters.\n
365  * NB! MCP2562x should be in configuration mode.
366  * @param Can CAN driver descriptor
367  * @param Id Filter identification number / mask number (11 or 29 bit)
368  * @param Filter RX filter Id or Mask
369  */
370 extern bool CanSetFilter(const struct can_t* Can,
371  uint32_t Id,
372  enum can_filter_t Filter);
373 
374 /**
375  * @brief Reads current MCP2562x mode of operation.
376  * @param Can CAN driver descriptor
377  * @return Current mode of operation..
378  */
379 extern enum can_mode_t CanGetMode(const struct can_t* Can);
380 
381 /**
382  * @brief Sets current MCP2562x mode of operation.\n
383  * NB! After setting new mode it should be verified that MCP2562x is in
384  * desired mode (in configuration mode after SW reset) with CanGetMode()
385  * function before any subsequent operation.
386  * @param Can CAN driver descriptor
387  * @param Mode Mode of operation to set.
388  */
389 extern bool CanSetMode(const struct can_t* Can, enum can_mode_t Mode);
390 
391 /**
392  * @brief Loads 1 full CAN frame to MCP2562x TX register.
393  * @param Can CAN driver descriptor
394  * @param Frame Structure holding the data to send.
395  * @param Buffer MCP2562x TX buffer to use.
396  * @return TX buffer actually used for transmission.\n
397  * CAN_FIFO is returned on busy TX buffer / busy SPI
398  */
399 extern enum can_xbuffer_t CanUploadFrame(const struct can_t* Can,
400  struct can_frame_t* Frame,
401  enum can_xbuffer_t Buffer);
402 
403 /**
404  * @brief Sets priority and RTS flag to one of MCP2562x TX registers initiating transfer.
405  * @param Can CAN driver descriptor
406  * @param Buffer MCP2562x TX buffer to use
407  * @param Priority Message priority
408  * @param TransmitReadyCb Callback to call when transmission is done
409  * @return false on error
410  */
411 extern bool CanSendFrame(const struct can_t* Can,
412  enum can_xbuffer_t Buffer,
413  enum can_priority_t Priority,
414  can_tx_callback_t TransmitReadyCb);
415 
416 /**
417  * @brief Receives 1 full CAN frame from MCP2562x after Rx1/Rx2 is ready.
418  * @param Can CAN driver descriptor
419  * @param Frame Structure to copy received data to
420  * @param Buffer MCP2562x RX buffer to read from
421  * @return RX buffer actually been read.\n
422  * CAN_FIFO is returned on RX buffer not ready / busy SPI
423  */
424 extern enum can_xbuffer_t CanDownloadFrame(const struct can_t* Can,
425  struct can_frame_t* Frame,
426  enum can_xbuffer_t Buffer);
427 
428 /**
429  * @brief Gets MCP2562x TX/RX buffers status (IF/RTS).
430  * @param Can CAN driver descriptor
431  * @param Status Pointer to result: TX/RX buffers status as returned by MCP2562x "READ STATUS" command.\n
432  * Masks:\n
433  * STAT_TX2IF - Tx2 buffer interrupt flag (Tx2 was sent)\n
434  * STAT_TX2REQ - Tx2 RTS flag (Tx2 is pending)\n
435  * STAT_TX1IF - Tx1 buffer interrupt flag (Tx1 was sent)\n
436  * STAT_TX1REQ - Tx1 RTS flag (Tx1 is pending)\n
437  * STAT_TX0IF - Tx0 buffer interrupt flag (Tx0 was sent)\n
438  * STAT_TX0REQ - Tx0 RTS flag (Tx0 is pending)\n
439  * STAT_RX1IF - Rx1 buffer interrupt flag (Rx1 is ready to be read)\n
440  * STAT_RX0IF - Rx0 buffer interrupt flag (Rx0 is ready to be read)
441  * @return false on error.
442  */
443 extern bool CanReadStatus(const struct can_t* Can, uint8_t* Status);
444 
445 /**
446  * @brief Clear MCP2562x interrupt flag(s) by mask.
447  * @param Can CAN driver descriptor
448  * @param Mask MCP2562x interrupt register mask\n
449  * Masks:\n
450  * INT_RX0IF - Rx0 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
451  * INT_RX1IF - Rx1 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
452  * INT_TX0IF - Tx0 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
453  * INT_TX1IF - Tx1 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
454  * INT_TX2IF - Tx2 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
455  * INT_ERRIF - Error Interrupt Flag bit (multiple sources in the EFLG register) - must be cleared by MCU to reset interrupt condition\n
456  * INT_WAKIF - Wake-up Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
457  * INT_MERRF - Message Error Interrupt Flag bit - must be cleared by MCU to reset interrupt condition\n
458  * @return false on error.
459  */
460 extern bool CanClearIF(const struct can_t* Can, uint8_t Mask);
461 
462 /**
463  * @brief Sets/resets all the preconfigured interrupts.
464  * @param Can CAN driver descriptor
465  * @param Enable true - enable some (preconfigured) interrupts,
466  * false - disable all interrupts
467  * @return false on error
468  */
469 extern bool CanInterrupts(const struct can_t* Can, bool Enable);
470 
471 /** \} MCP2562x */
472 
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.
Definition: can.h:129
uint8_t CanCfgMERRE
Message Error Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
Definition: can.h:228
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.
Definition: can.h:152
uint8_t CanCfgB1BFM
RX1BF Pin Operation mode bit: 1 = Rx1 interrupt, 0 = Digital Output mode.
Definition: can.h:235
uint8_t BTLMODE
PS2 mode (0: PS2=max(PS1,2*TQ) ; 1: PS2 determined by PHSEG2).
Definition: can.h:310
holds current CAN instance state variables.
Definition: can.h:276
uint8_t BRP
Baud Rate Prescaler (5 bit). TQ = 2*(BRP+1)/Freq.
Definition: can.h:305
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.
Definition: can.h:246
can_err_callback_t CanErrorCb
CAN error interrupt handler.
Definition: can.h:270
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...
Definition: can.h:226
uint32_t SpiBaudrate
SPI speed.
Definition: can.h:207
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.
Definition: can.h:131
Identifier of filter #0 for RX0.
Definition: can.h:139
Mask of filter for RX1.
Definition: can.h:146
SPI failed to communicate with MCP.
Definition: can.h:118
bool CanInterrupts(const struct can_t *Can, bool Enable)
Sets/resets all the preconfigured interrupts.
uint8_t RXB0CTRLx2
Not used in configuration.
Definition: can.h:263
uint8_t CanCfgB0BFE
RX0BF Pin Function Enable bit: 1 = Pin function enabled, operation mode determined by B0BFM bit...
Definition: can.h:236
struct can_state_t * State
Pointer to the CAN state.
Definition: can.h:208
Definition: spi.h:113
Identifier of filter #1 for RX0.
Definition: can.h:140
Write data to / get status of TX2.
Definition: can.h:128
const struct spi_cs_t SpiCs
SPI CS settings.
Definition: can.h:206
void(* can_wake_callback_t)(const struct can_t *Can)
The callback is called at CAN chip wakeup.
Definition: can.h:191
Driver for the MCU&#39;s SPI blocks.
Switch to normal operational mode.
Definition: can.h:112
can_xbuffer_t
defines MCP2562x TX/RX buffers for data transmission/reception.
Definition: can.h:124
uint8_t CNF3x
Not used in configuration.
Definition: can.h:253
holds CAN frame and is used in driver&#39;s API to transfer frames between the driver and an application ...
Definition: can.h:285
uint8_t CanCfgTX1IE
Tx1 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
Definition: can.h:224
uint8_t TXRTSCTRLx
Not used in configuration.
Definition: can.h:247
uint8_t CanCfgCLKPRE
CLKOUT Pin Prescaler bits.
Definition: can.h:212
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.
Definition: can.h:116
can_rx_callback_t CanRxReadyCb[2]
Rx0/Rx1 interrupt handlers.
Definition: can.h:268
Write data to / get status of TX1.
Definition: can.h:127
void(* can_rx_callback_t)(const struct can_t *Can, enum can_xbuffer_t BufNum)
The callback is called on CAN frame reception.
Definition: can.h:168
Perform SW reset; after that MCP is in configuration mode.
Definition: can.h:117
uint8_t CanCfgRX1IE
Rx1 Full Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
Definition: can.h:222
uint8_t CanCfgWAKIE
Wake-up Interrupt Flag bit - must be cleared by MCU to reset interrupt condition. ...
Definition: can.h:227
void(* can_err_callback_t)(const struct can_t *Can, uint8_t EREG)
The callback is called at CAN chip error.
Definition: can.h:198
uint8_t SJW
Synchronisation Jump Width Length = (SJW+1)*TQ (0-3)
Definition: can.h:306
uint8_t CanCfgWAKFIL
1 : Wake-up filter enabled
Definition: can.h:254
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)
Definition: can.h:297
uint8_t CanCfgB0BFM
RX0BF Pin Operation mode bit: 1 = Rx0 interrupt, 0 = Digital Output mode.
Definition: can.h:234
uint8_t CanCfgCANINTE
CANINTE register content.
Definition: can.h:230
Identifier of filter #0 for RX1.
Definition: can.h:141
const struct spi_t * Spi
Pointer to the SPI interface instance.
Definition: can.h:205
void CanInterruptCb(const struct can_t *Can)
Driver&#39;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...
Definition: can.h:237
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.
Definition: can.h:183
uint8_t CanCfgOSM
1 : one-shot mode is on
Definition: can.h:214
uint8_t CanCfgSOF
Start-of-Frame Signal bit (!!!only if CLKOUT pin is enabled!!!)
Definition: can.h:255
Identifier of filter #1 for RX1.
Definition: can.h:142
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).
Definition: can.h:311
Mask of filter for RX0.
Definition: can.h:145
can_wake_callback_t CanWakeCb
CAN wakeup interrupt handler.
Definition: can.h:269
uint8_t PRSEG
Propagation Segment Length bits = (PRSEG+1)*TQ (0-7)
Definition: can.h:307
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.
Definition: can.h:209
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.
Definition: can.h:221
uint8_t CANCTRLx
Not used in configuration.
Definition: can.h:215
can_mode_t
defines possible MCP2562x modes of operation for CanSetMode() function. NB: values correspond to REQO...
Definition: can.h:110
uint8_t RXB0CTRLx1
Not used in configuration.
Definition: can.h:261
Identifier of filter #3 for RX1.
Definition: can.h:144
uint8_t PHSEG1
Phase Segment 1 Length bits = (PHSEG1+1)*TQ (0-7)
Definition: can.h:308
uint8_t CanCfgB0RTSM
TX0RTS Pin mode bit: 1 = RTS of Tx0 on falling edge, 0 = Digital input.
Definition: can.h:244
CAN driver descriptor: static structure for configuration of driver instance.
Definition: can.h:203
Switch to loopback mode.
Definition: can.h:114
uint8_t CanCfgCANCTRL
CANCTRL register content.
Definition: can.h:217
Switch to listen-only mode.
Definition: can.h:115
uint8_t CanCfgBUKT
Rollover Enable bit: 1 = Rx0 message will rollover to Rx1 if Rx0 is full.
Definition: can.h:262
uint8_t BFPCTRLx
Not used in configuration.
Definition: can.h:238
Write data to / get status of TX0.
Definition: can.h:126
uint8_t CanCfgTX0IE
Tx0 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
Definition: can.h:223
Read data from / get status of RX1.
Definition: can.h:130
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.
Definition: can.h:137
uint8_t CanCfgCLKEN
1 : CLKOUT pin is enabled
Definition: can.h:213
Switch to sleep mode.
Definition: can.h:113
uint8_t PHSEG2
Phase Segment 2 Length bits = (PHSEG2+1)*TQ (1-7)
Definition: can.h:309
Definition: spi.h:166
Identifier of filter #2 for RX1.
Definition: can.h:143
CAN timing initialisation structure definition.
Definition: can.h:303
uint8_t CanCfgTX2IE
Tx2 Empty Interrupt Flag bit - must be cleared by MCU to reset interrupt condition.
Definition: can.h:225
uint8_t CanCfgB1RTSM
TX1RTS Pin mode bit: 1 = RTS of Tx1 on falling edge, 0 = Digital input.
Definition: can.h:245
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...