CAN Interface

File: csp/interfaces/csp_if_can.h

Description: CAN interface

CAN frames contains at most 8 bytes of data, so in order to transmit CSP packets larger than this, a fragmentation protocol is required. The CAN Fragmentation Protocol (CFP) is based on CAN2.0B, using all 29 bits of the identifier. The CAN identifier is divided into these fields:

  • Source: 5 bits

  • Destination: 5 bits

  • Type: 1 bit

  • Remain: 8 bits

  • Identifier: 10 bits

The Source and Destination fields must match the source and destiantion addressses in the CSP packet. The Type field is used to distinguish the first and subsequent frames in a fragmented CSP packet. Type is BEGIN (0) for the first fragment and MORE (1) for all other fragments. The Remain field indicates number of remaining fragments, and must be decremented by one for each fragment sent. The identifier field serves the same purpose as in the Internet Protocol, and should be an auto incrementing integer to uniquely separate sessions.

For networks configured as CSP version 2, the CAN identifier is divided into:

  • Priority: 2 bits

  • Destination: 14 bits

  • Sender id: 6 bits

  • Packet count: 2 bits

  • Frame count: 3 bits

  • Begin flag: 1 bit

  • End flag: 1 bit

The b Priority represents the CSP prio field. Placing this as the first bits in the transmission ensure that packets with high priority is priotized on the bus due to the nature of CAN arbitration. The b Destination field represents the CSP node of the receiving node The b Sender holds the least significant bits of the transmitting interface, i.e. the local address when a packet is forwarded by a routing instance. The b Packet b count is an incrementing value for every CSP packet The b Frame b count represents the frame fragment index for the particular packet The b Begin b flag is set for the first CAN frame in a CSP packet The b End b flag is set for the last CAN frame in a CSP packet

In addition to the 29 bit extended CAN header, CSP utilize four bytes in the first CAN fragment in every CSP packet as:

  • Source: 14 bits

  • Dest port: 6 bits

  • Source port: 6 bits

  • CSP flags: 6 bits

The b Source holds the CSP node address of the origin of the CSP packet. The b Dest and Source b port represents the port numbers for the transmission. The b CSP b flags holds the CSP_HEADER_FLAGS.

Other CAN communication using a standard 11 bit identifier, can co-exist on the wire.

Defines

CFP_HOST_SIZE
[source]

Host - source/destination address.

CFP_TYPE_SIZE
[source]

Type - begin fragment or more fragments.

CFP_REMAIN_SIZE
[source]

Remaining fragments

CFP_ID_SIZE
[source]

CFP identification.

CFP_ID_CONN_MASK
[source]

Mask to uniquely separate connections

CFP2_ID_CONN_MASK
[source]

Fields used to uniquely define a CSP packet within each fragment header

CSP_IF_CAN_DEFAULT_NAME
[source]

Default interface name.

MACROS

CFP_FIELD(id, rsiz, fsiz)
[source]

Helper macro

CFP_SRC(id)
[source]

Extract source address

CFP_DST(id)
[source]

Extract destination address

CFP_TYPE(id)
[source]

Extract type (begin or more)

CFP_REMAIN(id)
[source]

Extract remaining fragments

CFP_ID(id)
[source]

Extract CFP identification

CFP_MAKE_FIELD(id, fsiz, rsiz)
[source]

Helper macro

CFP_MAKE_SRC(id)
[source]

Make source

CFP_MAKE_DST(id)
[source]

Make destination

CFP_MAKE_TYPE(id)
[source]

Make type

CFP_MAKE_REMAIN(id)
[source]

Make remaining fragments

CFP_MAKE_ID(id)
[source]

Make CFP id

Typedefs

type csp_can_interface_data_t
[source]

Interface data (state information).

uint32_t cfp_packet_counter
[source]

CFP Identification number - same number on all fragments from same CSP packet.

csp_packet_t *pbufs
[source]

PBUF queue

csp_can_driver_tx_t tx_func
[source]

Tx function

Interface Functions

int csp_can_add_interface(csp_iface_t *iface)
[source]

Add interface.

Parameters:
  • iface – CSP interface, initialized with name and inteface_data pointing to a valid #csp_can_interface_data_t structure.

Returns:

#CSP_ERR_NONE on success, otherwise an error code.

int csp_can_tx(csp_iface_t *iface, uint16_t via, csp_packet_t *packet)
[source]

Send CSP packet over CAN (nexthop).

This function will split the CSP packet into several fragments and call csp_can_tx_fram() for sending each fragment.

Parameters:
  • iface – CSP interface

  • via

  • packet – CSP packet

Returns:

#CSP_ERR_NONE on success, otherwise an error code.

int csp_can_rx(csp_iface_t *iface, uint32_t id, const uint8_t *data, uint8_t dlc, int *pxTaskWoken)
[source]

Process received CAN frame.

Called from driver when a single CAN frame (up to 8 bytes) has been received. The function will gather the fragments into a single CSP packet and route it on when complete.

Parameters:
  • iface – incoming interface.

  • id – received CAN message identifier.

  • data – received CAN data.

  • dlc – length of received data.

  • pxTaskWoken – Valid reference if called from ISR, otherwise NULL!

Returns:

#CSP_ERR_NONE on success, otherwise an error code.