Nut/OS  5.0.5
API Reference
CAN Devices
Collaboration diagram for CAN Devices:

Data Structures

struct  _CANFRAME
 CAN frame structure. More...
struct  _CANINFO
 CAN controller information structure. This is installed in heap at initializaton of a bus. More...
struct  ifcan
 CAN interface structure. More...
struct  _CANFILTER
 CAN message filter structure. More...

Defines

#define CAN_IF_2A   0x01
#define CAN_IF_2B   0x02
#define CAN_SPEED_10K   0
 10 kbit/s, max. cable length 5000 m
#define CAN_SPEED_20K   1
 20 kbit/s, max. cable length 2500 m
#define CAN_SPEED_50K   2
 50 kbit/s, max. cable length 1000 m
#define CAN_SPEED_100K   3
 100 kbit/s, max. cable length 600 m
#define CAN_SPEED_125K   4
 125 kbit/s, max. cable length 500 m
#define CAN_SPEED_250K   5
 250 kbit/s, max. cable length 250 m
#define CAN_SPEED_500K   6
 500 kbit/s, max. cable length 100 m
#define CAN_SPEED_800K   7
 800 kbit/s, max. cable length 50 m
#define CAN_SPEED_1M   8
 1 Mbit/s, max. cable length 25 m
#define CAN_SPEED_CUSTOM   255
#define CAN_SPEED_10K   0
 CAN Baud rate constants.
#define CAN_SPEED_20K   1
 20 kbit/s, max. cable length 2500 m
#define CAN_SPEED_50K   2
 50 kbit/s, max. cable length 1000 m
#define CAN_SPEED_100K   3
 100 kbit/s, max. cable length 600 m
#define CAN_SPEED_125K   4
 125 kbit/s, max. cable length 500 m
#define CAN_SPEED_250K   5
 250 kbit/s, max. cable length 250 m
#define CAN_SPEED_500K   6
 500 kbit/s, max. cable length 100 m
#define CAN_SPEED_800K   7
 800 kbit/s, max. cable length 50 m
#define CAN_SPEED_1M   8
 1 Mbit/s, max. cable length 25 m
#define CAN_SPEED_CUSTOM   255
#define CAN_TTCM   0x0001
#define CAN_ABOM   0x0002
#define CAN_AWUM   0x0004
#define CAN_NART   0x0008
#define CAN_RFLM   0x0010
#define CAN_TXFP   0x0020
#define FILTER_EXPLICIT   0xffffffff

Typedefs

typedef struct _CANFRAME CANFRAME
 CAN frame type.
typedef struct _CANINFO CANINFO
 CAN controller information type.
typedef struct ifcan IFCAN
 Canbus interface type.
typedef struct _NUTCANBUS NUTCANBUS
 CAN bus structure, defined by device.
typedef struct _CANBUSINFO CANBUSINFO
 CAN bus info structure, defined by device.
typedef struct _CANBUFFER CANBUFFER
 CAN BUFFER structure, defined by device.
typedef struct _CANFRAME CANFRAME
 CAN frame type.
typedef struct _CANFILTER CANFILTER
 CAN message filter type.

Enumerations

enum  CAN_RESULT {
  CAN_SUCCESS = 0, CAN_ERROR = -1, CAN_TXBUF_FULL = -2, CAN_RXBUF_EMPTY = -3,
  CAN_ILLEGAL_MOB = -4, CAN_INVALID_SPEED = -5, CAN_PASSIVE = -6, CAN_BUS_OFF = -7,
  CAN_NO_COMPANION = -8, CAN_IS_COMPANION = -9
}
 CAN error codes. More...
enum  CAN_COUNTERS {
  CAN_RX_FRAMES = 0, CAN_TX_FRAMES = 1, CAN_INTERRUPTS = 2, CAN_RX_INTERRUPTS = 3,
  CAN_TX_INTERRUPTS = 4, CAN_SCE_INTERRUPTS = 5, CAN_OVERRUNS = 6, CAN_ERRORS = 7,
  CAN_NO_COUNTERS = 8
}
 CAN event counters. More...

Functions

uint8_t CAN_SetSpeed (NUTDEVICE *dev, uint32_t baudrate)
void CAN_SetFilter (NUTDEVICE *dev, uint8_t *ac, uint8_t *am)
void CAN_TxFrame (NUTDEVICE *dev, CANFRAME *frame)
uint8_t CAN_TryTxFrame (NUTDEVICE *dev, CANFRAME *frame)
uint8_t CAN_TxFree (NUTDEVICE *dev)
uint8_t CAN_RxFrame (NUTDEVICE *dev, CANFRAME *frame)
uint8_t CAN_TryRxFrame (NUTDEVICE *dev, CANFRAME *frame)
uint8_t CAN_RxAvail (NUTDEVICE *dev)
void CAN_SetRxTimeout (NUTDEVICE *dev, uint32_t timeout)
int NutRegisterCanBus (NUTCANBUS *bus, int8_t ln2_size)
 _NUTCANBUS
int CanAddFilter (NUTCANBUS *bus, CANFILTER *filter)
int CanSetBaud (NUTCANBUS *bus, uint8_t baud, uint32_t alt_btr)
void CANSetRxTimeout (NUTCANBUS *bus, uint32_t timeout)
void CanEnableRx (NUTCANBUS *bus)
int CanRxAvail (NUTCANBUS *bus)
int CanInput (NUTCANBUS *bus, CANFRAME *output)
int CanTxFree (NUTCANBUS *can)
int CanOutput (NUTCANBUS *bus, CANFRAME *output)
int CanGetCounter (NUTCANBUS *bus, enum CAN_COUNTERS index)

Variables

uint32_t _CANFRAME::id
uint8_t _CANFRAME::byte [8]
uint8_t _CANFRAME::len
uint8_t _CANFRAME::ext
uint8_t _CANFRAME::rtr
uint32_t _CANFILTER::id
 Identifier.
uint32_t _CANFILTER::mask
 Mask, use 0xffffffff for ecavt match.
uint8_t _CANFILTER::id_ext
 Boolean, extended frame.
uint8_t _CANFILTER::id_rtr
 Boolean, remote transmition bit.
uint8_t _CANFILTER::mask_ext
 Boolean, match id_ext.
uint8_t _CANFILTER::mask_rtr
 Boolean, match id_rtr.

Define Documentation

#define CAN_IF_2A   0x01
#define CAN_IF_2B   0x02
#define CAN_SPEED_10K   0

10 kbit/s, max. cable length 5000 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_20K   1

20 kbit/s, max. cable length 2500 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_50K   2

50 kbit/s, max. cable length 1000 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_100K   3

100 kbit/s, max. cable length 600 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_125K   4

125 kbit/s, max. cable length 500 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_250K   5

250 kbit/s, max. cable length 250 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_500K   6

500 kbit/s, max. cable length 100 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_800K   7

800 kbit/s, max. cable length 50 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_1M   8

1 Mbit/s, max. cable length 25 m

Referenced by AtCanSetBaudrate(), CanSetBaud(), SJAInit(), and SJASetBaudrate().

#define CAN_SPEED_CUSTOM   255

Referenced by AtCanSetBaudrate(), and CanSetBaud().

#define CAN_SPEED_10K   0

CAN Baud rate constants.

10 kbit/s, max. cable length 5000 m

#define CAN_SPEED_20K   1

20 kbit/s, max. cable length 2500 m

#define CAN_SPEED_50K   2

50 kbit/s, max. cable length 1000 m

#define CAN_SPEED_100K   3

100 kbit/s, max. cable length 600 m

#define CAN_SPEED_125K   4

125 kbit/s, max. cable length 500 m

#define CAN_SPEED_250K   5

250 kbit/s, max. cable length 250 m

#define CAN_SPEED_500K   6

500 kbit/s, max. cable length 100 m

#define CAN_SPEED_800K   7

800 kbit/s, max. cable length 50 m

#define CAN_SPEED_1M   8

1 Mbit/s, max. cable length 25 m

#define CAN_SPEED_CUSTOM   255
#define CAN_TTCM   0x0001

Referenced by CanGetFeatures(), and CanSetFeatures().

#define CAN_ABOM   0x0002

Referenced by CanGetFeatures(), and CanSetFeatures().

#define CAN_AWUM   0x0004

Referenced by CanGetFeatures(), and CanSetFeatures().

#define CAN_NART   0x0008

Referenced by CanGetFeatures(), and CanSetFeatures().

#define CAN_RFLM   0x0010

Referenced by CanGetFeatures(), and CanSetFeatures().

#define CAN_TXFP   0x0020

Referenced by CanGetFeatures(), and CanSetFeatures().

#define FILTER_EXPLICIT   0xffffffff

Referenced by CanAddFilter().


Typedef Documentation

typedef struct _CANFRAME CANFRAME

CAN frame type.

typedef struct _CANINFO CANINFO

CAN controller information type.

typedef struct ifcan IFCAN

Canbus interface type.

typedef struct _NUTCANBUS NUTCANBUS

CAN bus structure, defined by device.

typedef struct _CANBUSINFO CANBUSINFO

CAN bus info structure, defined by device.

typedef struct _CANBUFFER CANBUFFER

CAN BUFFER structure, defined by device.

typedef struct _CANFRAME CANFRAME

CAN frame type.

typedef struct _CANFILTER CANFILTER

CAN message filter type.


Enumeration Type Documentation

enum CAN_RESULT

CAN error codes.

Enumerator:
CAN_SUCCESS 

Successful operation.

CAN_ERROR 

Unspecified error.

CAN_TXBUF_FULL 

All TX message objects busy.

CAN_RXBUF_EMPTY 

All RX message objects busy.

CAN_ILLEGAL_MOB 

Message object index out of range.

CAN_INVALID_SPEED 

Invalid baud rate parameter.

CAN_PASSIVE 

Bus is in passive state.

CAN_BUS_OFF 

Bus is bus-off.

CAN_NO_COMPANION 

FIFO2 needs FIFO1 active.

CAN_IS_COMPANION 

FIFO2 can only set Filters.

CAN event counters.

Enumerator:
CAN_RX_FRAMES 

Number of packets received.

CAN_TX_FRAMES 

Number of packets sent.

CAN_INTERRUPTS 

Number of interrupts.

CAN_RX_INTERRUPTS 

Number of RX interrupts.

CAN_TX_INTERRUPTS 

Number of TX interrupts.

CAN_SCE_INTERRUPTS 

Number of ERROR interrupts.

CAN_OVERRUNS 

Number of packet overruns.

CAN_ERRORS 

Number of frame errors.

CAN_NO_COUNTERS 

Function Documentation

uint8_t CAN_SetSpeed ( NUTDEVICE dev,
uint32_t  baudrate 
)

References _NUTDEVICE::dev_icb.

void CAN_SetFilter ( NUTDEVICE dev,
uint8_t ac,
uint8_t am 
)

References _NUTDEVICE::dev_icb.

void CAN_TxFrame ( NUTDEVICE dev,
CANFRAME frame 
)

References _NUTDEVICE::dev_icb.

uint8_t CAN_TryTxFrame ( NUTDEVICE dev,
CANFRAME frame 
)

References _NUTDEVICE::dev_icb.

uint8_t CAN_TxFree ( NUTDEVICE dev)

References _NUTDEVICE::dev_icb.

uint8_t CAN_RxFrame ( NUTDEVICE dev,
CANFRAME frame 
)

References _NUTDEVICE::dev_icb.

uint8_t CAN_TryRxFrame ( NUTDEVICE dev,
CANFRAME frame 
)

References _NUTDEVICE::dev_icb.

uint8_t CAN_RxAvail ( NUTDEVICE dev)

References _NUTDEVICE::dev_icb.

void CAN_SetRxTimeout ( NUTDEVICE dev,
uint32_t  timeout 
)

Sets the CAN receive timeout

Parameters:
devPointer to the device structure
timeoutTimeout in milliseconds, NUT_WAIT_INFINITE = no time-out
Warning:
Timeout values are given in milliseconds and are limited to the granularity of the system timer. To disable timeout, set the parameter to NUT_WAIT_INFINITE.

References _NUTDEVICE::dev_icb.

int NutRegisterCanBus ( NUTCANBUS bus,
int8_t  ln2_size 
)

_NUTCANBUS

_NUTCANBUS

Parameters:
baudBaudrate to set. CAN_SPEED_CUSTOM will use alt_btr
alt_btrCustom setting for the Baud Rate Registers, Device dependant.

Here we set up the Hardware, baudrate and special setting

References _BI32, _NUTCANBUS::bus_ci, CAN_DEF_RX_ENTRIES, CAN_ERROR, _CANBUSINFO::can_rx_timeout, _CANBUSINFO::can_RxBuf, _CANBUFFER::dataindex, _CANBUFFER::datalength, _CANBUFFER::dataptr, memset(), NULL, NUT_WAIT_INFINITE, NutHeapAlloc, NutHeapFree, NutIrqEnable(), NutIrqSetPriority(), NutRegisterIrqHandler(), rc, _NUTCANBUS::sig_rx_irq, _NUTCANBUS::sig_sce_irq, _NUTCANBUS::sig_tx_irq, and _CANBUFFER::size.

Here is the call graph for this function:

int CanSetBaud ( NUTCANBUS bus,
uint8_t  baud,
uint32_t  alt_btr 
)

Set the baudrate

Parameters:
busIdentifies the CANBUS
baudSymbolic value for the Baudrate
alt_btrUse given value with CAN_SPEED_CUSTOM

For STM32, alt_btr may be used for setting silent/loopback silent+loopback mode

Returns:
0 if baudrate can be delivered or -1 else

References CAN_TypeDef::BTR, _NUTCANBUS::bus_base, CAN_BUS_OFF, CAN_ERROR, CAN_IS_COMPANION, 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 _NUTCANBUS::sig_tx_irq.

void CANSetRxTimeout ( NUTCANBUS bus,
uint32_t  timeout 
)
int CanRxAvail ( NUTCANBUS bus)
int CanInput ( NUTCANBUS bus,
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

References __IO, __MAY_ALIAS, _BI32, _NUTCANBUS::bb_base, _NUTCANBUS::bus_ci, _CANFRAME::byte, CAN_IER_FMPIE0, CAN_IER_FMPIE1, CAN_RI0R_IDE, CAN_RI0R_RTR, _CANBUSINFO::can_rx_rdy, _CANBUSINFO::can_rx_timeout, _CANBUSINFO::can_RxBuf, CM3BB_OFFSET, _CANBUFFER::dataindex, _CANBUFFER::datalength, _CANBUFFER::dataptr, _CANFRAME::ext, _CANFRAME::id, IER, _CANFRAME::len, NutEnterCritical, NutEventWait(), NutExitCritical, CAN_FIFOMailBox_TypeDef::RDHR, CAN_FIFOMailBox_TypeDef::RDLR, CAN_FIFOMailBox_TypeDef::RDTR, CAN_FIFOMailBox_TypeDef::RIR, _CANFRAME::rtr, _NUTCANBUS::sig_tx_irq, and _CANBUFFER::size.

Here is the call graph for this function:

int CanTxFree ( NUTCANBUS bus)

Checks if there's still space in output buffer

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

References _NUTCANBUS::sig_tx_irq.

int CanOutput ( NUTCANBUS bus,
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:
busPointer to the device structure
framePointer to the receive frame

References _NUTCANBUS::bus_ci, CAN_IS_COMPANION, _CANBUSINFO::can_tx_frames, _CANBUSINFO::can_tx_rdy, CAN_TXBUF_FULL, NUT_WAIT_INFINITE, NutEventWait(), rc, and _NUTCANBUS::sig_tx_irq.

Here is the call graph for this function:

int CanGetCounter ( NUTCANBUS bus,
enum CAN_COUNTERS  index 
)

Report the counter values

This function writes a frame to the output buffer. If the output buffer is full the function will block until frames are send.

Parameters:
busPointer to the device structure
indexNumber of pointer to receive
Returns:
-1 if counter not available, counter value otherwise

References _NUTCANBUS::bus_ci, _CANBUSINFO::can_errors, CAN_ERRORS, CAN_INTERRUPTS, _CANBUSINFO::can_overruns, CAN_OVERRUNS, _CANBUSINFO::can_rx_frames, CAN_RX_FRAMES, _CANBUSINFO::can_rx_interrupts, CAN_RX_INTERRUPTS, _CANBUSINFO::can_sce_interrupts, CAN_SCE_INTERRUPTS, _CANBUSINFO::can_tx_frames, CAN_TX_FRAMES, _CANBUSINFO::can_tx_interrupts, and CAN_TX_INTERRUPTS.


Variable Documentation

Identifier.

Referenced by CanAddFilter().

Mask, use 0xffffffff for ecavt match.

Referenced by CanAddFilter().

Boolean, extended frame.

Referenced by CanAddFilter().

Boolean, remote transmition bit.

Referenced by CanAddFilter().

Boolean, match id_ext.

Referenced by CanAddFilter().

Boolean, match id_rtr.

Referenced by CanAddFilter().