ChibiOS/RT Architecture - Reference Manual - Guides |
Generic CAN Driver. More...
Generic CAN Driver.
This module implements a generic ADC driver. The driver implements a state machine internally:
Modules | |
CAN Low Level Driver | |
CAN Driver low level driver template. | |
Defines | |
#define | CAN_LIMIT_WARNING 1 |
Errors rate warning. | |
#define | CAN_LIMIT_ERROR 2 |
Errors rate error. | |
#define | CAN_BUS_OFF_ERROR 4 |
Bus off condition reached. | |
#define | CAN_FRAMING_ERROR 8 |
Framing error of some kind on the CAN bus. | |
#define | CAN_OVERFLOW_ERROR 16 |
Overflow in receive queue. | |
#define | CAN_USE_SLEEP_MODE TRUE |
Sleep mode related APIs inclusion switch. | |
#define | canAddFlagsI(canp, mask) ((canp)->cd_status |= (mask)) |
Adds some flags to the CAN status mask. | |
Enumerations | |
enum | canstate_t { CAN_UNINIT = 0, CAN_STOP = 1, CAN_STARTING = 2, CAN_READY = 3, CAN_SLEEP = 4 } |
Driver state machine possible states. More... | |
Functions | |
void | canInit (void) |
CAN Driver initialization. | |
void | canObjectInit (CANDriver *canp) |
Initializes the standard part of a CANDriver structure. | |
void | canStart (CANDriver *canp, const CANConfig *config) |
Configures and activates the CAN peripheral. | |
void | canStop (CANDriver *canp) |
Deactivates the CAN peripheral. | |
msg_t | canTransmit (CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) |
Can frame transmission. | |
msg_t | canReceive (CANDriver *canp, CANRxFrame *crfp, systime_t timeout) |
Can frame receive. | |
canstatus_t | canGetAndClearFlags (CANDriver *canp) |
Returns the current status mask and clears it. | |
void | canSleep (CANDriver *canp) |
Enters the sleep mode. | |
void | canWakeup (CANDriver *canp) |
Enforces leaving the sleep mode. |
#define CAN_FRAMING_ERROR 8 |
#define CAN_USE_SLEEP_MODE TRUE |
#define canAddFlagsI | ( | canp, | |||
mask | ) | ((canp)->cd_status |= (mask)) |
enum canstate_t |
void canInit | ( | void | ) |
CAN Driver initialization.
Definition at line 59 of file can.c.
References can_lld_init().
Referenced by halInit().
void canObjectInit | ( | CANDriver * | canp | ) |
Initializes the standard part of a CANDriver
structure.
[in] | canp | pointer to the CANDriver object |
Definition at line 69 of file can.c.
References CAN_STOP, CANDriver::cd_config, CANDriver::cd_error_event, CANDriver::cd_rxfull_event, CANDriver::cd_rxsem, CANDriver::cd_sleep_event, CANDriver::cd_state, CANDriver::cd_status, CANDriver::cd_txempty_event, CANDriver::cd_txsem, CANDriver::cd_wakeup_event, chEvtInit, and chSemInit().
Configures and activates the CAN peripheral.
Definition at line 91 of file can.c.
References can_lld_start(), CAN_READY, CAN_STARTING, CAN_STOP, CANDriver::cd_config, CANDriver::cd_state, chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, and chThdSleepS.
void canStop | ( | CANDriver * | canp | ) |
Deactivates the CAN peripheral.
[in] | canp | pointer to the CANDriver object |
Definition at line 116 of file can.c.
References can_lld_stop(), CAN_READY, CAN_STOP, CANDriver::cd_rxsem, CANDriver::cd_state, CANDriver::cd_status, CANDriver::cd_txsem, chDbgAssert, chDbgCheck, chSchRescheduleS(), chSemResetI(), chSysLock, and chSysUnlock.
msg_t canTransmit | ( | CANDriver * | canp, | |
const CANTxFrame * | ctfp, | |||
systime_t | timeout | |||
) |
Can frame transmission.
The specified frame is queued for transmission, if the hardware queue is full then the invoking thread is queued.
[in] | canp | pointer to the CANDriver object |
[in] | ctfp | pointer to the CAN frame to be transmitted |
[in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
RDY_OK | the frame has been queued for transmission. | |
RDY_TIMEOUT | operation not finished within the specified time. | |
RDY_RESET | driver stopped while waiting. |
Definition at line 151 of file can.c.
References can_lld_can_transmit(), can_lld_transmit(), CAN_READY, CAN_SLEEP, CANDriver::cd_state, CANDriver::cd_txsem, chDbgAssert, chDbgCheck, chSemWaitTimeoutS(), chSysLock, chSysUnlock, and RDY_OK.
msg_t canReceive | ( | CANDriver * | canp, | |
CANRxFrame * | crfp, | |||
systime_t | timeout | |||
) |
Can frame receive.
The function waits until a frame is received.
[in] | canp | pointer to the CANDriver object |
[out] | crfp | pointer to the buffer where the CAN frame is copied |
[in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
RDY_OK | a frame has been received and placed in the buffer. | |
RDY_TIMEOUT | operation not finished within the specified time or frame not immediately available if invoked using TIME_IMMEDIATE . | |
RDY_RESET | driver stopped while waiting. |
Definition at line 192 of file can.c.
References can_lld_can_receive(), can_lld_receive(), CAN_READY, CAN_SLEEP, CANDriver::cd_rxsem, CANDriver::cd_state, chDbgAssert, chDbgCheck, chSemWaitTimeoutS(), chSysLock, chSysUnlock, and RDY_OK.
canstatus_t canGetAndClearFlags | ( | CANDriver * | canp | ) |
Returns the current status mask and clears it.
[in] | canp | pointer to the CANDriver object |
Definition at line 218 of file can.c.
References CANDriver::cd_status, chSysLock, and chSysUnlock.
void canSleep | ( | CANDriver * | canp | ) |
Enters the sleep mode.
[in] | canp | pointer to the CANDriver object |
Definition at line 234 of file can.c.
References can_lld_sleep(), CAN_READY, CAN_SLEEP, CANDriver::cd_sleep_event, CANDriver::cd_state, chDbgAssert, chDbgCheck, chEvtBroadcastI(), chSchRescheduleS(), chSysLock, and chSysUnlock.
void canWakeup | ( | CANDriver * | canp | ) |
Enforces leaving the sleep mode.
[in] | canp | pointer to the CANDriver object |
Definition at line 258 of file can.c.
References can_lld_wakeup(), CAN_READY, CAN_SLEEP, CANDriver::cd_state, CANDriver::cd_wakeup_event, chDbgAssert, chDbgCheck, chEvtBroadcastI(), chSchRescheduleS(), chSysLock, and chSysUnlock.