AT90CAN128 CAN device
[Device Drivers]

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

Collaboration diagram for AT90CAN128 CAN device:

Defines

#define RX_MOB   8
#define ATCAN_RX_BUF_SIZE   64

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


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_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

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:
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)
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:
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)
Returns:
Result code. See CAN_RESULT
Examples:
canbus/candemo.c.

Definition at line 384 of file atcan.c.

References AtCanEnableMsgObj().

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

int8_t AtCanSendMsg ( CANFRAME *  frame  ) 

Send a CAN message

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

Definition at line 407 of file atcan.c.

References _BV, AtCanGetFreeMob(), and CAN_TXBUF_FULL.

Referenced by AtCanOutput().

uint8_t AtCanRxAvail ( NUTDEVICE *  dev  ) 

Checks if data is available in input buffer

Parameters:
dev Pointer to the device structure
Returns:
Number of frames available

Definition at line 551 of file atcan.c.

uint8_t AtCanTxFree ( NUTDEVICE *  dev  ) 

Checks if there's still space in output buffer

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

Definition at line 563 of file atcan.c.

References AtCanGetFreeMob().

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:
dev Pointer to the device structure
frame Pointer to the receive frame

Definition at line 578 of file atcan.c.

References AtCanSendMsg(), CAN_TXBUF_FULL, NUT_WAIT_INFINITE, and NutEventWait().

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:
dev Pointer to the device structure
frame Pointer to the receive frame
Returns:
1 if timeout, 0 otherwise

Definition at line 600 of file atcan.c.

References NutEnterCritical, NutEventWait(), and NutExitCritical.

void AtCanSetAccCode ( NUTDEVICE *  dev,
uint8_t ac 
)

Sets the acceptance code

Parameters:
dev Pointer to the device structure
ac 4 byte char array with the acceptance code

Definition at line 631 of file atcan.c.

References AtCanEnableRx(), memcpy(), and RX_MOB.

void AtCanSetAccMask ( NUTDEVICE *  dev,
uint8_t am 
)

Sets the acceptance mask

Parameters:
dev Pointer to the device structure
am 4 byte char array with the acceptance mask

Definition at line 644 of file atcan.c.

References AtCanEnableRx(), memcpy(), and RX_MOB.

uint8_t AtCanSetBaudrate ( NUTDEVICE *  dev,
uint32_t  baudrate 
)

Sets the CAN baud rate

Parameters:
dev Pointer to the device structure
baudrate Baud 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, and CAN_SPEED_CUSTOM.

Referenced by AtCanInit().

int AtCanInit ( NUTDEVICE *  dev  ) 

Initialize CAN interface.

Applications typically do not use this function, but call NutRegisterDevice().

Parameters:
dev Identifies 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(), ifc_atcan, loop_until_bit_is_set, memset(), NutHeapAlloc, NutRegisterIrqHandler(), and RX_MOB.


Variable Documentation

NUTDEVICE devAtCan

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.

CANINFO dcb_atcan

Definition at line 247 of file atcan.c.

IFCAN ifc_atcan

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.

Referenced by AtCanInit().

NUTDEVICE devAtCan

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.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/