Skip to content

File syn_ethercat.h

FileList > proto > syn_ethercat.h

Go to the source code of this file

EtherCAT (IEEE 802.3 EtherType 0x88A4) Bare-Metal Protocol Stack. More...

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

Classes

Type Name
struct SYN_EcatCoEHeader
CoE (CANoverEtherCAT) Mailbox Header.
struct SYN_EcatDatagram
EtherCAT Datagram Header (10 bytes header + 2 bytes WKC = 12 bytes overhead)
struct SYN_EcatHeader
Raw EtherCAT Header (2 bytes)
struct SYN_EcatNode
EtherCAT Node Descriptor.

Public Types

Type Name
enum SYN_EcatCmd
enum SYN_EcatCoEType
enum SYN_EcatState

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.

Macros

Type Name
define SYN_ETHERCAT_ETHERTYPE 0x88A4
EtherCAT IEEE 802.3 Ethernet Frame Type.
define SYN_ETHERCAT_TYPE_DATAGRAM 1
EtherCAT Header Type (1 = EtherCAT Datagrams)

Detailed Description

Implements EtherCAT Frame packing, Datagram commands (APRD, APWR, APRW, FPRD, FPWR, FPRW, BRD, BWR, LRD, LWR, LRW), Working Counter (WKC) accounting, EtherCAT State Machine (ESM: INIT, PREOP, BOOT, SAFEOP, OP), and CoE (CAN application protocol over EtherCAT) Mailbox SDO & PDO handling.

Designed for zero heap allocation and direct L2 raw Ethernet frame processing.

Public Types Documentation

enum SYN_EcatCmd

enum SYN_EcatCmd {
    SYN_ECAT_CMD_NOP = 0,
    SYN_ECAT_CMD_APRD = 1,
    SYN_ECAT_CMD_APWR = 2,
    SYN_ECAT_CMD_APRW = 3,
    SYN_ECAT_CMD_FPRD = 4,
    SYN_ECAT_CMD_FPWR = 5,
    SYN_ECAT_CMD_FPRW = 6,
    SYN_ECAT_CMD_BRD = 7,
    SYN_ECAT_CMD_BWR = 8,
    SYN_ECAT_CMD_BRW = 9,
    SYN_ECAT_CMD_LRD = 10,
    SYN_ECAT_CMD_LWR = 11,
    SYN_ECAT_CMD_LRW = 12,
    SYN_ECAT_CMD_ARMW = 13,
    SYN_ECAT_CMD_FRMW = 14
};

enum SYN_EcatCoEType

enum SYN_EcatCoEType {
    SYN_ECAT_COE_TYPE_EMERGENCY = 1,
    SYN_ECAT_COE_TYPE_SDO_REQ = 2,
    SYN_ECAT_COE_TYPE_SDO_RESP = 3,
    SYN_ECAT_COE_TYPE_RXPDO = 4,
    SYN_ECAT_COE_TYPE_TXPDO = 5,
    SYN_ECAT_COE_TYPE_SDO_INFO = 6
};

enum SYN_EcatState

enum SYN_EcatState {
    SYN_ECAT_STATE_NONE = 0x00,
    SYN_ECAT_STATE_INIT = 0x01,
    SYN_ECAT_STATE_PREOP = 0x02,
    SYN_ECAT_STATE_BOOT = 0x03,
    SYN_ECAT_STATE_SAFEOP = 0x04,
    SYN_ECAT_STATE_OP = 0x08
};

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.

Macro Definition Documentation

define SYN_ETHERCAT_ETHERTYPE

EtherCAT IEEE 802.3 Ethernet Frame Type.

#define SYN_ETHERCAT_ETHERTYPE `0x88A4`


define SYN_ETHERCAT_TYPE_DATAGRAM

EtherCAT Header Type (1 = EtherCAT Datagrams)

#define SYN_ETHERCAT_TYPE_DATAGRAM `1`



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