Nut/OS  4.10.3
API Reference
AT90CAN128 CAN device

Driver for Atmel's internal Full CAN controller. More...

Collaboration diagram for AT90CAN128 CAN device:

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

Detailed Description

Driver for Atmel's internal Full CAN controller.


Define Documentation

#define RX_MOB   8

Definition at line 100 of file atcan.c.

Referenced by AtCanInit(), AtCanSetAccCode(), and AtCanSetAccMask().

#define ATCAN_RX_BUF_SIZE   64

Definition at line 103 of file atcan.c.

Referenced by AtCanInit().


Typedef Documentation

typedef struct _CANBuffer CANBuffer

Definition at line 239 of file atcan.c.


Function Documentation

int8_t AtCanGetBusState ( void  )

Returns the state of this CAN node. Refer to state diagram in AT90CAN128 dataheet chapter 20.7 "Error Management"

Return values:
CAN_SUCCESSif CAN node is in ACTIVE state
CAN_PASSIVEif CAN node is in PASSIVE state
CAN_BUS_OFFif CAN node is in BUS OFF state

Definition at line 265 of file atcan.c.

References _BV, and CAN_BUS_OFF.

int8_t AtCanGetFreeMob ( void  )

Definition at line 280 of file atcan.c.

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

Parameters:
mobMessage object index (0-14)
idAcceptance code
idIsExtFlag if acceptance code is extended (0 = standard, 1 = extended)
idRemTagId's remote tag (0 or 1)
maskAcceptance mask
maskIsExtFlag if acceptance mask is extended (0 = standard, 1 = extended)
maskRemTagMask's remote tag (0 or 1)
Returns:
Result code. See CAN_RESULT

Definition at line 316 of file atcan.c.

References _BV.

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.

Parameters:
noOfMsgObjsNumber 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.
idAcceptance code
idIsExtFlag if acceptance code is extended (0 = standard, 1 = extended)
idRemTagId's remote tag (0 or 1)
maskAcceptance mask
maskIsExtFlag if acceptance mask is extended (0 = standard, 1 = extended)
maskRemTagMask's remote tag (0 or 1)
Returns:
Result code. See CAN_RESULT

Definition at line 384 of file atcan.c.

References AtCanEnableMsgObj().

Referenced by AtCanInit(), AtCanSetAccCode(), and AtCanSetAccMask().

Here is the call graph for this function:

int8_t AtCanSendMsg ( CANFRAME frame)

Send a CAN message

Parameters:
frameContainer for CAN message to be sent
Returns:
Result code. See CAN_RESULT

Definition at line 407 of file atcan.c.

References _BV, AtCanGetFreeMob(), _CANFRAME::byte, CAN_TXBUF_FULL, _CANFRAME::ext, _CANFRAME::id, _CANFRAME::len, and _CANFRAME::rtr.

Referenced by AtCanOutput().

Here is the call graph for this function:

uint8_t AtCanRxAvail ( NUTDEVICE dev)

Checks if data is available in input buffer

Parameters:
devPointer to the device structure
Returns:
Number of frames available

Definition at line 551 of file atcan.c.

References _CANBuffer::datalength.

uint8_t AtCanTxFree ( NUTDEVICE dev)

Checks if there's still space in output buffer

Parameters:
devPointer to the device structure
Returns:
1 if space is available

Definition at line 563 of file atcan.c.

References AtCanGetFreeMob().

Here is the call graph for this function:

void AtCanOutput ( NUTDEVICE dev,
CANFRAME frame 
)

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.

Parameters:
devPointer to the device structure
framePointer to the receive frame

Definition at line 578 of file atcan.c.

References AtCanSendMsg(), _CANINFO::can_tx_rdy, CAN_TXBUF_FULL, _NUTDEVICE::dev_dcb, NUT_WAIT_INFINITE, and NutEventWait().

Here is the call graph for this function:

uint8_t AtCanInput ( NUTDEVICE dev,
CANFRAME frame 
)

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.

Parameters:
devPointer to the device structure
framePointer to the receive frame
Returns:
1 if timeout, 0 otherwise

Definition at line 600 of file atcan.c.

References _CANINFO::can_rx_rdy, _CANBuffer::dataindex, _CANBuffer::datalength, _CANBuffer::dataptr, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, NutEnterCritical, NutEventWait(), NutExitCritical, and _CANBuffer::size.

Here is the call graph for this function:

void AtCanSetAccCode ( NUTDEVICE dev,
uint8_t ac 
)

Sets the acceptance code

Parameters:
devPointer to the device structure
ac4 byte char array with the acceptance code

Definition at line 631 of file atcan.c.

References AtCanEnableRx(), _NUTDEVICE::dev_icb, memcpy(), and RX_MOB.

Here is the call graph for this function:

void AtCanSetAccMask ( NUTDEVICE dev,
uint8_t am 
)

Sets the acceptance mask

Parameters:
devPointer to the device structure
am4 byte char array with the acceptance mask

Definition at line 644 of file atcan.c.

References AtCanEnableRx(), _NUTDEVICE::dev_icb, memcpy(), and RX_MOB.

Here is the call graph for this function:

uint8_t AtCanSetBaudrate ( NUTDEVICE dev,
uint32_t  baudrate 
)

Sets the CAN baud rate

Parameters:
devPointer to the device structure
baudrateBaud rate (One of the defined baud rates. See AtCan.h)
Returns:
0 for success

Definition at line 658 of file atcan.c.

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().

Parameters:
devIdentifies the device to initialize. The structure must be properly set.
Returns:
0 for successful initialisation or -1 in case init failed

Definition at line 732 of file atcan.c.

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.

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
    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.

Definition at line 820 of file atcan.c.

Definition at line 247 of file atcan.c.

Initial value:

Interface information structure.

This structure stores some interface parameters like bit rate, acceptance mask, acceptance code and callback handlers.

Definition at line 248 of file atcan.c.

Initial value:
 {
    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.

Definition at line 249 of file atcan.c.