Driver for Atmel's internal Full CAN controller. More...
Data Structures | |
| struct | _CANBuffer |
Defines | |
| #define | RX_MOB 8 |
| #define | ATCAN_RX_BUF_SIZE 64 |
Typedefs | |
| typedef struct _CANBuffer | CANBuffer |
Functions | |
| int8_t | AtCanGetBusState (void) |
| int8_t | AtCanGetFreeMob (void) |
| int8_t | AtCanEnableMsgObj (uint8_t mob, uint32_t id, int8_t idIsExt, int8_t idRemTag, uint32_t mask, int8_t maskIsExt, int8_t maskRemTag) |
| int8_t | AtCanEnableRx (uint8_t noOfMsgObjs, uint32_t id, int8_t idIsExt, int8_t idRemTag, uint32_t mask, int8_t maskIsExt, int8_t maskRemTag) |
| int8_t | AtCanSendMsg (CANFRAME *frame) |
| uint8_t | AtCanRxAvail (NUTDEVICE *dev) |
| uint8_t | AtCanTxFree (NUTDEVICE *dev) |
| void | AtCanOutput (NUTDEVICE *dev, CANFRAME *frame) |
| uint8_t | AtCanInput (NUTDEVICE *dev, CANFRAME *frame) |
| void | AtCanSetAccCode (NUTDEVICE *dev, uint8_t *ac) |
| void | AtCanSetAccMask (NUTDEVICE *dev, uint8_t *am) |
| uint8_t | AtCanSetBaudrate (NUTDEVICE *dev, uint32_t baudrate) |
| int | AtCanInit (NUTDEVICE *dev) |
Variables | |
| NUTDEVICE | devAtCan |
| CANINFO | dcb_atcan |
| IFCAN | ifc_atcan |
| NUTDEVICE | devAtCan |
Driver for Atmel's internal Full CAN controller.
| #define RX_MOB 8 |
Referenced by AtCanInit(), AtCanSetAccCode(), and AtCanSetAccMask().
| #define ATCAN_RX_BUF_SIZE 64 |
Referenced by AtCanInit().
| typedef struct _CANBuffer CANBuffer |
| int8_t AtCanGetBusState | ( | void | ) |
Returns the state of this CAN node. Refer to state diagram in AT90CAN128 dataheet chapter 20.7 "Error Management"
| CAN_SUCCESS | if CAN node is in ACTIVE state |
| CAN_PASSIVE | if CAN node is in PASSIVE state |
| CAN_BUS_OFF | if CAN node is in BUS OFF state |
References _BV, CAN_BUS_OFF, CAN_PASSIVE, and CAN_SUCCESS.
| int8_t AtCanGetFreeMob | ( | void | ) |
References _BV, and bit_is_set.
Referenced by AtCanSendMsg(), and AtCanTxFree().
| int8_t AtCanEnableMsgObj | ( | uint8_t | mob, |
| uint32_t | id, | ||
| int8_t | idIsExt, | ||
| int8_t | idRemTag, | ||
| uint32_t | mask, | ||
| int8_t | maskIsExt, | ||
| int8_t | maskRemTag | ||
| ) |
Configure a single message object for receiption.
All 15 MOBS can be set up for reception, not only RX_MOB MOBs
| mob | Message object index (0-14) |
| id | Acceptance code |
| idIsExt | Flag if acceptance code is extended (0 = standard, 1 = extended) |
| idRemTag | Id's remote tag (0 or 1) |
| mask | Acceptance mask |
| maskIsExt | Flag if acceptance mask is extended (0 = standard, 1 = extended) |
| maskRemTag | Mask's remote tag (0 or 1) |
References _BV, CAN_ILLEGAL_MOB, and CAN_SUCCESS.
Referenced by AtCanEnableRx().
| int8_t AtCanEnableRx | ( | uint8_t | noOfMsgObjs, |
| uint32_t | id, | ||
| int8_t | idIsExt, | ||
| int8_t | idRemTag, | ||
| uint32_t | mask, | ||
| int8_t | maskIsExt, | ||
| int8_t | maskRemTag | ||
| ) |
Configure message objects for receiption.
| noOfMsgObjs | Number of message objects used for receiption (1-14). Message objects not configured for receiption are used for transmission. The same acceptance filter and mask is applied to the message objects. If it is required to set-up more complex filtering mechanisms use canEnableMsgObj() instead, which allows setting filters on a per message object basis. |
| id | Acceptance code |
| idIsExt | Flag if acceptance code is extended (0 = standard, 1 = extended) |
| idRemTag | Id's remote tag (0 or 1) |
| mask | Acceptance mask |
| maskIsExt | Flag if acceptance mask is extended (0 = standard, 1 = extended) |
| maskRemTag | Mask's remote tag (0 or 1) |
References AtCanEnableMsgObj(), and CAN_SUCCESS.
Referenced by AtCanInit(), AtCanSetAccCode(), and AtCanSetAccMask().
Send a CAN message
| frame | Container for CAN message to be sent |
References _BV, AtCanGetFreeMob(), _CANFRAME::byte, CAN_SUCCESS, CAN_TXBUF_FULL, _CANFRAME::ext, _CANFRAME::id, _CANFRAME::len, and _CANFRAME::rtr.
Referenced by AtCanOutput().
Checks if data is available in input buffer
| dev | Pointer to the device structure |
References _CANBuffer::datalength.
Checks if there's still space in output buffer
| dev | Pointer to the device structure |
References AtCanGetFreeMob().
Write a frame from to output buffer
This function writes a frame to the output buffer. If the output buffer is full the function will block until frames are send.
| dev | Pointer to the device structure |
| frame | Pointer to the receive frame |
References AtCanSendMsg(), _CANINFO::can_tx_rdy, CAN_TXBUF_FULL, _NUTDEVICE::dev_dcb, NUT_WAIT_INFINITE, and NutEventWait().
Reads a frame from input buffer
This function reads a frame from the input buffer. If the input buffer is empty the function will block unitl new frames are received, or the timeout is reached.
| dev | Pointer to the device structure |
| frame | Pointer to the receive frame |
References _CANINFO::can_rx_rdy, _CANBuffer::dataindex, _CANBuffer::datalength, _CANBuffer::dataptr, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, NutEnterCritical, NutEventWait(), NutExitCritical, and _CANBuffer::size.
Sets the acceptance code
| dev | Pointer to the device structure |
| ac | 4 byte char array with the acceptance code |
References AtCanEnableRx(), _NUTDEVICE::dev_icb, memcpy(), and RX_MOB.
Sets the acceptance mask
| dev | Pointer to the device structure |
| am | 4 byte char array with the acceptance mask |
References AtCanEnableRx(), _NUTDEVICE::dev_icb, memcpy(), and RX_MOB.
Sets the CAN baud rate
| dev | Pointer to the device structure |
| baudrate | Baud rate (One of the defined baud rates. See AtCan.h) |
References CAN_SPEED_100K, CAN_SPEED_10K, CAN_SPEED_125K, CAN_SPEED_1M, CAN_SPEED_20K, CAN_SPEED_250K, CAN_SPEED_500K, CAN_SPEED_50K, CAN_SPEED_800K, CAN_SPEED_CUSTOM, and _NUTDEVICE::dev_icb.
Referenced by AtCanInit().
| int AtCanInit | ( | NUTDEVICE * | dev | ) |
Initialize CAN interface.
Applications typically do not use this function, but call NutRegisterDevice().
| dev | Identifies the device to initialize. The structure must be properly set. |
References _BV, ATCAN_RX_BUF_SIZE, AtCanEnableRx(), AtCanSetBaudrate(), ifcan::can_baudrate, _CANBuffer::dataindex, _CANBuffer::datalength, _CANBuffer::dataptr, _NUTDEVICE::dev_dcb, loop_until_bit_is_set, memset(), NutHeapAlloc, NutRegisterIrqHandler(), RX_MOB, and _CANBuffer::size.
{
0,
{'a', 't', 'c', 'a', 'n', '0', 0, 0, 0},
IFTYP_CAN,
0,
0,
&ifc_atcan,
&dcb_atcan,
AtCanInit,
0,
0,
0,
0,
0,
0,
0
}
Device information structure.
Applications must pass this structure to NutRegisterDevice() to bind this CAN device driver to the Nut/OS kernel.
{
CAN_IF_2B,
CAN_SPEED_125K,
{0xFF, 0xFF, 0xFF, 0xFF},
{0x00, 0x00, 0x00, 0x00},
NUT_WAIT_INFINITE,
AtCanRxAvail,
AtCanTxFree,
AtCanInput,
AtCanOutput,
AtCanSetAccCode,
AtCanSetAccMask,
AtCanSetBaudrate,
}
Interface information structure.
This structure stores some interface parameters like bit rate, acceptance mask, acceptance code and callback handlers.