Skip to content

File syn_canopen.h

FileList > proto > syn_canopen.h

Go to the source code of this file

CANopen DS301 Slave Protocol Engine. More...

  • #include "../common/syn_defs.h"
  • #include "../drivers/syn_can.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_CANOpenNode
CANopen Node State Handle.
struct SYN_CANOpenNodeConfig
CANopen Node Configuration.
struct SYN_CANOpenODEntry
Object Dictionary Entry Definition.
struct SYN_CANOpenPDOMap
PDO Mapping Configuration.
struct SYN_CANOpenSDOSession

Public Types

Type Name
enum SYN_CANOpenSDOState

Public Functions

Type Name
bool syn_canopen_get_tx (SYN_CANOpenNode * node, uint32_t * out_cob_id, uint8_t * out_data, uint8_t * out_len)
Retrieve pending transmit CAN frame.
SYN_Status syn_canopen_init (SYN_CANOpenNode * node, const SYN_CANOpenNodeConfig * cfg, const SYN_CANOpenODEntry * od_table, size_t od_count)
Initialize a CANopen DS301 Node.
SYN_Status syn_canopen_od_read (SYN_CANOpenNode * node, uint16_t index, uint8_t subindex, void * buf, size_t buf_size, size_t * out_len)
Directly read an entry from the Object Dictionary.
SYN_Status syn_canopen_od_write (SYN_CANOpenNode * node, uint16_t index, uint8_t subindex, const void * data, size_t len)
Directly write an entry to the Object Dictionary.
SYN_Status syn_canopen_process_rx (SYN_CANOpenNode * node, uint32_t cob_id, const uint8_t * data, uint8_t len)
Process an incoming CAN frame.
SYN_Status syn_canopen_send_emcy (SYN_CANOpenNode * node, uint16_t err_code, uint8_t err_reg)
Transmit an Emergency (EMCY) message.
SYN_Status syn_canopen_tpdo_trigger (SYN_CANOpenNode * node, uint8_t pdo_num)
Manually trigger transmission of a specific TPDO (1..4).
SYN_Status syn_canopen_update (SYN_CANOpenNode * node, uint32_t dt_ms)
Periodic timer update (call from tick thread or loop).

Macros

Type Name
define SYN_CANOPEN_ACCESS_RO 0x01U
OD Access Rights.
define SYN_CANOPEN_ACCESS_RW 0x03U
define SYN_CANOPEN_ACCESS_WO 0x02U
define SYN_CANOPEN_NMT_CMD_PREOP 0x80U
define SYN_CANOPEN_NMT_CMD_RESET_COMM 0x82U
define SYN_CANOPEN_NMT_CMD_RESET_NODE 0x81U
define SYN_CANOPEN_NMT_CMD_START 0x01U
CANopen NMT Command Specifiers.
define SYN_CANOPEN_NMT_CMD_STOP 0x02U
define SYN_CANOPEN_NMT_STATE_BOOTUP 0x00U
CANopen NMT States.
define SYN_CANOPEN_NMT_STATE_OPERATIONAL 0x05U
define SYN_CANOPEN_NMT_STATE_PREOP 0x7FU
define SYN_CANOPEN_NMT_STATE_STOPPED 0x04U
define SYN_CANOPEN_SDO_ABORT_NONE 0x00000000UL
SDO Abort Codes.
define SYN_CANOPEN_SDO_ABORT_NOT_EXIST 0x06020000UL
define SYN_CANOPEN_SDO_ABORT_READ_ONLY 0x06010002UL
define SYN_CANOPEN_SDO_ABORT_SUBINDEX_NOT_EXIST 0x06090011UL
define SYN_CANOPEN_SDO_ABORT_TOGGLE_BIT 0x05030000UL
define SYN_CANOPEN_SDO_ABORT_TYPE_MISMATCH 0x06070010UL
define SYN_CANOPEN_SDO_ABORT_UNSUPPORTED_ACCESS 0x06010000UL
define SYN_CANOPEN_SDO_ABORT_WRITE_ONLY 0x06010001UL
define SYN_CANOPEN_TYPE_I16 0x03U
define SYN_CANOPEN_TYPE_I32 0x04U
define SYN_CANOPEN_TYPE_I8 0x02U
OD Data Types.
define SYN_CANOPEN_TYPE_U16 0x06U
define SYN_CANOPEN_TYPE_U32 0x07U
define SYN_CANOPEN_TYPE_U8 0x05U

Detailed Description

Implements a lightweight, non-blocking, zero-malloc CANopen DS301 slave stack including Object Dictionary, SDO server, RPDO/TPDO engine, NMT state machine, Heartbeat producer, and Emergency (EMCY) alarms.

Public Types Documentation

enum SYN_CANOpenSDOState

enum SYN_CANOpenSDOState {
    SYN_CANOPEN_SDO_IDLE = 0,
    SYN_CANOPEN_SDO_SEG_DOWNLOAD,
    SYN_CANOPEN_SDO_SEG_UPLOAD
};

Public Functions Documentation

function syn_canopen_get_tx

Retrieve pending transmit CAN frame.

bool syn_canopen_get_tx (
    SYN_CANOpenNode * node,
    uint32_t * out_cob_id,
    uint8_t * out_data,
    uint8_t * out_len
) 

Parameters:

  • node Pointer to node handle.
  • out_cob_id Output COB-ID pointer.
  • out_data Output 8-byte buffer pointer.
  • out_len Output frame length pointer.

Returns:

true if a frame was popped, false if no frame pending.


function syn_canopen_init

Initialize a CANopen DS301 Node.

SYN_Status syn_canopen_init (
    SYN_CANOpenNode * node,
    const SYN_CANOpenNodeConfig * cfg,
    const SYN_CANOpenODEntry * od_table,
    size_t od_count
) 

Parameters:

  • node Pointer to node handle.
  • cfg Pointer to node configuration.
  • od_table Array of Object Dictionary entries.
  • od_count Number of entries in od_table.

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid inputs.


function syn_canopen_od_read

Directly read an entry from the Object Dictionary.

SYN_Status syn_canopen_od_read (
    SYN_CANOpenNode * node,
    uint16_t index,
    uint8_t subindex,
    void * buf,
    size_t buf_size,
    size_t * out_len
) 

Parameters:

  • node Pointer to node handle.
  • index 16-bit OD Index.
  • subindex 8-bit OD Subindex.
  • buf Output buffer pointer.
  • buf_size Maximum buffer capacity.
  • out_len Pointer to store read byte length.

Returns:

SYN_OK on success, error code if not found or unauthorized.


function syn_canopen_od_write

Directly write an entry to the Object Dictionary.

SYN_Status syn_canopen_od_write (
    SYN_CANOpenNode * node,
    uint16_t index,
    uint8_t subindex,
    const void * data,
    size_t len
) 

Parameters:

  • node Pointer to node handle.
  • index 16-bit OD Index.
  • subindex 8-bit OD Subindex.
  • data Input data pointer.
  • len Input data length in bytes.

Returns:

SYN_OK on success, error code if not found or unauthorized.


function syn_canopen_process_rx

Process an incoming CAN frame.

SYN_Status syn_canopen_process_rx (
    SYN_CANOpenNode * node,
    uint32_t cob_id,
    const uint8_t * data,
    uint8_t len
) 

Parameters:

  • node Pointer to node handle.
  • cob_id Received 11-bit CAN COB-ID.
  • data Payload buffer (up to 8 bytes).
  • len Payload length.

Returns:

SYN_OK on success, error code on failure.


function syn_canopen_send_emcy

Transmit an Emergency (EMCY) message.

SYN_Status syn_canopen_send_emcy (
    SYN_CANOpenNode * node,
    uint16_t err_code,
    uint8_t err_reg
) 

Parameters:

  • node Pointer to node handle.
  • err_code 16-bit CANopen Emergency Error Code.
  • err_reg 8-bit Error Register value (Index 0x1001).

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid parameters.


function syn_canopen_tpdo_trigger

Manually trigger transmission of a specific TPDO (1..4).

SYN_Status syn_canopen_tpdo_trigger (
    SYN_CANOpenNode * node,
    uint8_t pdo_num
) 

Parameters:

  • node Pointer to node handle.
  • pdo_num TPDO number (1..4).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if pdo_num invalid or unmapped.


function syn_canopen_update

Periodic timer update (call from tick thread or loop).

SYN_Status syn_canopen_update (
    SYN_CANOpenNode * node,
    uint32_t dt_ms
) 

Parameters:

  • node Pointer to node handle.
  • dt_ms Elapsed time since last update in milliseconds.

Returns:

SYN_OK on success.


Macro Definition Documentation

define SYN_CANOPEN_ACCESS_RO

OD Access Rights.

#define SYN_CANOPEN_ACCESS_RO `0x01U`

Read-Only access


define SYN_CANOPEN_ACCESS_RW

#define SYN_CANOPEN_ACCESS_RW `0x03U`

Read/Write access


define SYN_CANOPEN_ACCESS_WO

#define SYN_CANOPEN_ACCESS_WO `0x02U`

Write-Only access


define SYN_CANOPEN_NMT_CMD_PREOP

#define SYN_CANOPEN_NMT_CMD_PREOP `0x80U`

Enter Pre-Operational


define SYN_CANOPEN_NMT_CMD_RESET_COMM

#define SYN_CANOPEN_NMT_CMD_RESET_COMM `0x82U`

Reset Communication


define SYN_CANOPEN_NMT_CMD_RESET_NODE

#define SYN_CANOPEN_NMT_CMD_RESET_NODE `0x81U`

Reset Node


define SYN_CANOPEN_NMT_CMD_START

CANopen NMT Command Specifiers.

#define SYN_CANOPEN_NMT_CMD_START `0x01U`

Start Remote Node


define SYN_CANOPEN_NMT_CMD_STOP

#define SYN_CANOPEN_NMT_CMD_STOP `0x02U`

Stop Remote Node


define SYN_CANOPEN_NMT_STATE_BOOTUP

CANopen NMT States.

#define SYN_CANOPEN_NMT_STATE_BOOTUP `0x00U`

Bootup State


define SYN_CANOPEN_NMT_STATE_OPERATIONAL

#define SYN_CANOPEN_NMT_STATE_OPERATIONAL `0x05U`

Operational State


define SYN_CANOPEN_NMT_STATE_PREOP

#define SYN_CANOPEN_NMT_STATE_PREOP `0x7FU`

Pre-Operational State


define SYN_CANOPEN_NMT_STATE_STOPPED

#define SYN_CANOPEN_NMT_STATE_STOPPED `0x04U`

Stopped State


define SYN_CANOPEN_SDO_ABORT_NONE

SDO Abort Codes.

#define SYN_CANOPEN_SDO_ABORT_NONE `0x00000000UL`

No error


define SYN_CANOPEN_SDO_ABORT_NOT_EXIST

#define SYN_CANOPEN_SDO_ABORT_NOT_EXIST `0x06020000UL`

Object does not exist in dictionary


define SYN_CANOPEN_SDO_ABORT_READ_ONLY

#define SYN_CANOPEN_SDO_ABORT_READ_ONLY `0x06010002UL`

Attempt to write a read only object


define SYN_CANOPEN_SDO_ABORT_SUBINDEX_NOT_EXIST

#define SYN_CANOPEN_SDO_ABORT_SUBINDEX_NOT_EXIST `0x06090011UL`

Subindex does not exist


define SYN_CANOPEN_SDO_ABORT_TOGGLE_BIT

#define SYN_CANOPEN_SDO_ABORT_TOGGLE_BIT `0x05030000UL`

Toggle bit not altered


define SYN_CANOPEN_SDO_ABORT_TYPE_MISMATCH

#define SYN_CANOPEN_SDO_ABORT_TYPE_MISMATCH `0x06070010UL`

Data type mismatch, length mismatch \


define SYN_CANOPEN_SDO_ABORT_UNSUPPORTED_ACCESS

#define SYN_CANOPEN_SDO_ABORT_UNSUPPORTED_ACCESS `0x06010000UL`

Unsupported access to object


define SYN_CANOPEN_SDO_ABORT_WRITE_ONLY

#define SYN_CANOPEN_SDO_ABORT_WRITE_ONLY `0x06010001UL`

Attempt to read a write only object


define SYN_CANOPEN_TYPE_I16

#define SYN_CANOPEN_TYPE_I16 `0x03U`

Signed 16-bit integer


define SYN_CANOPEN_TYPE_I32

#define SYN_CANOPEN_TYPE_I32 `0x04U`

Signed 32-bit integer


define SYN_CANOPEN_TYPE_I8

OD Data Types.

#define SYN_CANOPEN_TYPE_I8 `0x02U`

Signed 8-bit integer


define SYN_CANOPEN_TYPE_U16

#define SYN_CANOPEN_TYPE_U16 `0x06U`

Unsigned 16-bit integer


define SYN_CANOPEN_TYPE_U32

#define SYN_CANOPEN_TYPE_U32 `0x07U`

Unsigned 32-bit integer


define SYN_CANOPEN_TYPE_U8

#define SYN_CANOPEN_TYPE_U8 `0x05U`

Unsigned 8-bit integer



The documentation for this class was generated from the following file src/syntropic/proto/syn_canopen.h