AT90CAN128 CAN device
[Device Drivers]

Collaboration diagram for AT90CAN128 CAN device:

Detailed Description

Driver for Atmel's internal Full CAN controller.


Defines

#define RX_MOB   8
#define CAN_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
IFCAN ifc_atcan
NUTDEVICE devAtCan


Define Documentation

#define RX_MOB   8

Definition at line 97 of file atcan.c.

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

#define CAN_BUF_SIZE   64

Definition at line 100 of file atcan.c.

Referenced by AtCanInit().


Typedef Documentation

typedef struct _CANBuffer CANBuffer

Definition at line 211 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_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 237 of file atcan.c.

References _BV, and CAN_BUS_OFF.

int8_t AtCanGetFreeMob ( void   ) 

Definition at line 252 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.

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 286 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 354 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 377 of file atcan.c.

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

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 521 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 533 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 548 of file atcan.c.

References AtCanSendMsg(), _CANINFO::can_tx_rdy, CAN_TXBUF_FULL, _NUTDEVICE::dev_dcb, 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 570 of file atcan.c.

References _CANINFO::can_rx_rdy, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, 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 601 of file atcan.c.

References AtCanEnableRx(), _NUTDEVICE::dev_icb, 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 614 of file atcan.c.

References AtCanEnableRx(), _NUTDEVICE::dev_icb, 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 628 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:
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 698 of file atcan.c.

References _BV, AtCanEnableRx(), AtCanSetBaudrate(), ifcan::can_baudrate, CAN_BUF_SIZE, _NUTDEVICE::dev_dcb, loop_until_bit_is_set, memset(), NutHeapAlloc(), NutRegisterIrqHandler(), and RX_MOB.


Variable Documentation

NUTDEVICE devAtCan

Device information structure.

Applications must pass this structure to NutRegisterDevice() to bind this CAN device driver to the Nut/OS kernel.

Definition at line 221 of file atcan.c.

CANINFO dcb_atcan

Definition at line 219 of file atcan.c.

IFCAN ifc_atcan

Definition at line 220 of file atcan.c.

NUTDEVICE devAtCan

Definition at line 221 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 764 of file atcan.c.

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 786 of file atcan.c.


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