|
NetBurner 3.5.7
PDF Version |
MCAN Module Class. More...
#include <mcan.h>
Public Member Functions | |
| mcan_module (Mcan *phw, uint32_t baud) | |
| Create a MCAN module instance. | |
| void | init (Mcan *phw, struct mcan_config *config, uint32_t baud) |
| Initialize a MCAN module. | |
| void | send_message (uint32_t id_value, uint8_t *data, uint32_t data_length, OS_SEM *pSem=0) |
| Send a MCAN message. | |
| bool | blocking_send_message (uint32_t id_value, uint8_t *data, uint32_t data_length, uint32_t TimeOut) |
| Send a MCAN message and block until sent. | |
| int | RegisterRxFifo (uint32_t composite_id, OS_FIFO *pFifo, int channel=-1) |
| Register a FIFO to receive CAN messages. | |
| int | RegisterRxFifoMask (uint32_t composite_id, uint32_t mask, OS_FIFO *pFifo, int channel=-1) |
| Register a FIFO to receive messages as specified by the address bit mask. A value of 1 = match, a value of 0 = does not match. | |
| int | RegisterRxFifoRange (uint32_t composite_id_low, uint32_t composite_id_hi, OS_FIFO *pFifo, int channel=-1) |
| Register a FIFO to receive messages in the specified numeric range of addresses from low to high. | |
| int | UnRegisterFifo (int channel) |
| Unregister the FIFO for the specified CAN channel. | |
| int | MultiCanSetRTRMessage (uint32_t id, uint8_t *data, uint8_t len, int channel=-1) |
| Enable an auto-reply to a CAN RTR message for the specified CAN ID. The reply message is specified by the data parameter. | |
| int | MultiCanReplaceRTRMessage (int channel, uint8_t *data, uint8_t len) |
| Modifies/updates the response for the RTR message registered wotj MultiCanSetRTRMessage(). | |
| int | MultiCanStopRTRMessage (int channel) |
| Unregister the RTR message for the specified channel. | |
| uint32_t | read_error_count () |
| Read the raw value of the MCAN Error Count Register (MCAN_ECR). | |
| uint32_t | read_protocol_status () |
| Read the raw value of the MCAN Protocol Status Register (MCAN_PSR). | |
| void | start () |
| Take the MCAN controller out of initialization mode and place it on the bus. | |
| void | stop () |
| Halt the MCAN controller and place it in initialization mode. | |
MCAN Module Class.
Class to control a MCAN modules (peripherals) on the MODM7AE70
| mcanMODM7AE70::mcan_module::mcan_module | ( | Mcan * | phw, |
| uint32_t | baud ) |
Create a MCAN module instance.
| phw | MCAN hardware peripheral, MCAN0 or MCAN 1 |
| baud | MCAN baud rate. For example, 500000 |
| bool mcanMODM7AE70::mcan_module::blocking_send_message | ( | uint32_t | id_value, |
| uint8_t * | data, | ||
| uint32_t | data_length, | ||
| uint32_t | TimeOut ) |
Send a MCAN message and block until sent.
| id_value | CAN ID, 11-bit standard or 29-bit extended |
| data | Pointer to message data |
| data_length | Length of data in bytes |
| TimeOut | Time out value in system time ticks. For example, TICKS_PER_SECOND * 1 |
| void mcanMODM7AE70::mcan_module::init | ( | Mcan * | phw, |
| struct mcan_config * | config, | ||
| uint32_t | baud ) |
Initialize a MCAN module.
| phw | MCAN hardware peripheral, MCAN0 or MCAN 1 |
| config | Pointer to a mcan_config object, initialized with appropriate values. |
| baud | MCAN baud rate. For example, 500000 |
| int mcanMODM7AE70::mcan_module::MultiCanReplaceRTRMessage | ( | int | channel, |
| uint8_t * | data, | ||
| uint8_t | len ) |
Modifies/updates the response for the RTR message registered wotj MultiCanSetRTRMessage().
| int mcanMODM7AE70::mcan_module::MultiCanSetRTRMessage | ( | uint32_t | id, |
| uint8_t * | data, | ||
| uint8_t | len, | ||
| int | channel = -1 ) |
Enable an auto-reply to a CAN RTR message for the specified CAN ID. The reply message is specified by the data parameter.
The response message can be modified with MultiCanReplaceRTRMessage().
| id | CAN ID, 11-bit standard or 29-bit extended |
| data | Pointer to message data |
| len | Length of message |
| channel | Optional CAN channel |
| int mcanMODM7AE70::mcan_module::MultiCanStopRTRMessage | ( | int | channel | ) |
Unregister the RTR message for the specified channel.
| channel | CAN channel number |
|
inline |
Read the raw value of the MCAN Error Count Register (MCAN_ECR).
Bit fields can be extracted with the macros from component/mcan.h:
MCAN_ECR_TEC_Msk / MCAN_ECR_TEC_Pos – Transmit Error Counter (bits 7:0)MCAN_ECR_REC_Msk / MCAN_ECR_REC_Pos – Receive Error Counter (bits 14:8)MCAN_ECR_RP – Receive Error Passive flagMCAN_ECR_CEL_Msk / MCAN_ECR_CEL_Pos – CAN Error Logging counterNote: a non-zero TEC alone does not imply a problem on a healthy bus – a single missed acknowledge will increment it. For state-level decisions, prefer read_protocol_status().
|
inline |
Read the raw value of the MCAN Protocol Status Register (MCAN_PSR).
Bit fields can be extracted with the macros from component/mcan.h:
MCAN_PSR_BO – Bus_Off Status (controller cannot transmit until restarted)MCAN_PSR_EP – Error PassiveMCAN_PSR_EW – Error Warning (TEC or REC >= 96)MCAN_PSR_ACT_Msk – Node activity (idle, receiver, transmitter)| int mcanMODM7AE70::mcan_module::RegisterRxFifo | ( | uint32_t | composite_id, |
| OS_FIFO * | pFifo, | ||
| int | channel = -1 ) |
Register a FIFO to receive CAN messages.
| composite_id | CAN ID, 11-bit standard or 29-bit extended |
| pFifo | Pointer to OS_FIFO for received data |
| channel | Optional CAN channel |
| int mcanMODM7AE70::mcan_module::RegisterRxFifoMask | ( | uint32_t | composite_id, |
| uint32_t | mask, | ||
| OS_FIFO * | pFifo, | ||
| int | channel = -1 ) |
Register a FIFO to receive messages as specified by the address bit mask. A value of 1 = match, a value of 0 = does not match.
| composite_id | CAN ID, 11-bit standard or 29-bit extended |
| mask | Id mask |
| pFifo | Pointer to OS_FIFO for received data |
| channel | Optional CAN channel |
| int mcanMODM7AE70::mcan_module::RegisterRxFifoRange | ( | uint32_t | composite_id_low, |
| uint32_t | composite_id_hi, | ||
| OS_FIFO * | pFifo, | ||
| int | channel = -1 ) |
Register a FIFO to receive messages in the specified numeric range of addresses from low to high.
| composite_id_low | Composite ID low value |
| composite_id_hi | Composite ID high value |
| pFifo | Pointer to OS_FIFO for received data |
| channel | Optional CAN channel |
| void mcanMODM7AE70::mcan_module::send_message | ( | uint32_t | id_value, |
| uint8_t * | data, | ||
| uint32_t | data_length, | ||
| OS_SEM * | pSem = 0 ) |
Send a MCAN message.
| id_value | CAN ID, 11-bit standard or 29-bit extended |
| data | Pointer to message data |
| data_length | Length of data in bytes |
| pSem | Optional pointer to semaphore to post to, default is no post |
| void mcanMODM7AE70::mcan_module::start | ( | ) |
Take the MCAN controller out of initialization mode and place it on the bus.
Clears the CCCR.INIT bit and waits for the controller to leave init mode. Used in tandem with stop() to perform a software reset of the peripheral after a bus-off event or other error condition.
| void mcanMODM7AE70::mcan_module::stop | ( | ) |
Halt the MCAN controller and place it in initialization mode.
Sets the CCCR.INIT bit and waits for the controller to enter init mode. While in this state the peripheral does not transmit or receive on the bus. Pair with start() to recover the controller from a bus-off condition.
| int mcanMODM7AE70::mcan_module::UnRegisterFifo | ( | int | channel | ) |
Unregister the FIFO for the specified CAN channel.
| channel | CAN channel number |