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
MACROS
Typedefs
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.