Skip to content

File syn_canopen.c

FileList > proto > syn_canopen.c

Go to the source code of this file

CANopen DS301 Slave Protocol Engine implementation.

  • #include "syntropic/proto/syn_canopen.h"
  • #include "syntropic/util/syn_pack.h"
  • #include <string.h>

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).

Public Static Functions

Type Name
const SYN_CANOpenODEntry * canopen_find_od (const SYN_CANOpenNode * node, uint16_t index, uint8_t subindex)
Helper function to find an Object Dictionary entry.
void canopen_queue_tx (SYN_CANOpenNode * node, uint32_t cob_id, const uint8_t * data, uint8_t len)
Helper function to queue a CAN transmit frame.
void canopen_send_sdo_abort (SYN_CANOpenNode * node, uint16_t index, uint8_t subindex, uint32_t abort_code)
Send an SDO Abort frame.

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.


Public Static Functions Documentation

function canopen_find_od

Helper function to find an Object Dictionary entry.

static const SYN_CANOpenODEntry * canopen_find_od (
    const SYN_CANOpenNode * node,
    uint16_t index,
    uint8_t subindex
) 

Parameters:

  • node Pointer to node handle.
  • index 16-bit OD Index.
  • subindex 8-bit OD Subindex.

Returns:

Pointer to entry if found, NULL otherwise.


function canopen_queue_tx

Helper function to queue a CAN transmit frame.

static void canopen_queue_tx (
    SYN_CANOpenNode * node,
    uint32_t cob_id,
    const uint8_t * data,
    uint8_t len
) 

Parameters:

  • node Pointer to node handle.
  • cob_id 11-bit CAN COB-ID.
  • data Payload data pointer.
  • len Payload length.

function canopen_send_sdo_abort

Send an SDO Abort frame.

static void canopen_send_sdo_abort (
    SYN_CANOpenNode * node,
    uint16_t index,
    uint8_t subindex,
    uint32_t abort_code
) 

Parameters:

  • node Pointer to node handle.
  • index 16-bit OD Index.
  • subindex 8-bit OD Subindex.
  • abort_code 32-bit SDO Abort code.


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