Skip to content

File syn_ethercat.c

FileList > proto > syn_ethercat.c

Go to the source code of this file

Bare-metal EtherCAT Protocol Engine implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_ethercat.h"
  • #include <string.h>

Public Functions

Type Name
size_t syn_ecat_build_datagram_frame (uint8_t * buf, size_t buf_len, const SYN_EcatDatagram * datagram, const uint8_t * data, uint16_t data_len)
Build an EtherCAT Frame containing one or more datagrams.
size_t syn_ecat_coe_encode_sdo_download (uint8_t * buf, size_t buf_len, uint16_t index, uint8_t subindex, const void * data, size_t data_len)
Encode a CoE SDO Download (Write) request into a mailbox buffer.
size_t syn_ecat_coe_encode_sdo_upload (uint8_t * buf, size_t buf_len, uint16_t index, uint8_t subindex)
Encode a CoE SDO Upload (Read) request into a mailbox buffer.
void syn_ecat_init (SYN_EcatNode * node, uint16_t station_addr, SYN_CANOpenNode * od)
Initialize an EtherCAT Node instance.
SYN_Status syn_ecat_parse_frame (SYN_EcatNode * node, const uint8_t * frame, size_t len, uint16_t * wkc)
Parse and process a received raw EtherCAT frame.
SYN_Status syn_ecat_set_state (SYN_EcatNode * node, SYN_EcatState new_state)
Request an EtherCAT State Machine (ESM) state transition.
void syn_ecat_update (SYN_EcatNode * node)
Run ESM state machine step.

Public Static Functions

Type Name
uint16_t load16_le (const uint8_t * p)
void store16_le (uint8_t * p, uint16_t val)
void store32_le (uint8_t * p, uint32_t val)

Public Functions Documentation

function syn_ecat_build_datagram_frame

Build an EtherCAT Frame containing one or more datagrams.

size_t syn_ecat_build_datagram_frame (
    uint8_t * buf,
    size_t buf_len,
    const SYN_EcatDatagram * datagram,
    const uint8_t * data,
    uint16_t data_len
) 

Parameters:

  • buf Output frame buffer (must include Ethernet header space if needed).
  • buf_len Capacity of output buffer.
  • datagram Datagram header descriptor.
  • data Payload bytes to write into datagram.
  • data_len Payload length.

Returns:

Total EtherCAT frame length in bytes, or 0 on error.


function syn_ecat_coe_encode_sdo_download

Encode a CoE SDO Download (Write) request into a mailbox buffer.

size_t syn_ecat_coe_encode_sdo_download (
    uint8_t * buf,
    size_t buf_len,
    uint16_t index,
    uint8_t subindex,
    const void * data,
    size_t data_len
) 

Parameters:

  • buf Output buffer.
  • buf_len Capacity of output buffer.
  • index Object Dictionary Index (0x0000 - 0xFFFF).
  • subindex Subindex (0x00 - 0xFF).
  • data Data bytes to write.
  • data_len Data length (1-4 bytes for expedited SDO).

Returns:

Encoded CoE Mailbox packet length in bytes, or 0 on error.


function syn_ecat_coe_encode_sdo_upload

Encode a CoE SDO Upload (Read) request into a mailbox buffer.

size_t syn_ecat_coe_encode_sdo_upload (
    uint8_t * buf,
    size_t buf_len,
    uint16_t index,
    uint8_t subindex
) 

Parameters:

  • buf Output buffer.
  • buf_len Capacity of output buffer.
  • index Object Dictionary Index (0x0000 - 0xFFFF).
  • subindex Subindex (0x00 - 0xFF).

Returns:

Encoded CoE Mailbox packet length in bytes, or 0 on error.


function syn_ecat_init

Initialize an EtherCAT Node instance.

void syn_ecat_init (
    SYN_EcatNode * node,
    uint16_t station_addr,
    SYN_CANOpenNode * od
) 

Parameters:

  • node EtherCAT node instance.
  • station_addr Configured station address.
  • od Optional CANopen Object Dictionary binding for CoE.

function syn_ecat_parse_frame

Parse and process a received raw EtherCAT frame.

SYN_Status syn_ecat_parse_frame (
    SYN_EcatNode * node,
    const uint8_t * frame,
    size_t len,
    uint16_t * wkc
) 

Parameters:

  • node EtherCAT node instance.
  • frame Raw received frame bytes (after Ethernet header).
  • len Frame length in bytes.
  • wkc [out] Extracted Working Counter sum.

Returns:

SYN_OK on successful parsing and WKC validation.


function syn_ecat_set_state

Request an EtherCAT State Machine (ESM) state transition.

SYN_Status syn_ecat_set_state (
    SYN_EcatNode * node,
    SYN_EcatState new_state
) 

Parameters:

  • node EtherCAT node instance.
  • new_state Requested state (INIT, PREOP, BOOT, SAFEOP, OP).

Returns:

SYN_OK if state transition request is valid.


function syn_ecat_update

Run ESM state machine step.

void syn_ecat_update (
    SYN_EcatNode * node
) 

Parameters:

  • node EtherCAT node instance.

Public Static Functions Documentation

function load16_le

static inline uint16_t load16_le (
    const uint8_t * p
) 

function store16_le

static inline void store16_le (
    uint8_t * p,
    uint16_t val
) 

function store32_le

static inline void store32_le (
    uint8_t * p,
    uint32_t val
) 


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