EtherCAT.Slave.ESC.SII (ethercat v0.5.0)

Copy Markdown View Source

SII EEPROM interface for EtherCAT slaves.

Provides read, write, and reload operations against the slave EEPROM via ESC registers 0x0500–0x050F. All protocol details (busy-polling, error-bit clearing, missing-ACK retries) are handled internally.

Word addressing is used throughout — the EEPROM uses 16-bit words.

Examples

alias EtherCAT.Slave.ESC.SII

# Read vendor ID (words 0x08–0x09)
{:ok, <<vendor_id::32-little>>} = SII.read(bus, 0x1000, 0x08, 2)

# Write configured station alias (word 0x04)
:ok = SII.write(bus, 0x1000, 0x04, <<0x00, 0x10>>)

# Reload ESC configuration from EEPROM
:ok = SII.reload(bus, 0x1000)

Summary

Functions

Read the valid SII contents by walking the category structure.

Read word_count words from the EEPROM starting at word_address.

Read the identity fields from SII EEPROM words 0x08–0x0F.

Read the standard mailbox parameters from SII EEPROM words 0x18–0x1B.

Read TxPDO (0x0032) and RxPDO (0x0033) category data from SII EEPROM.

Read SyncManager configurations from SII category 0x0029.

Reload ESC configuration from EEPROM.

Write data to the EEPROM starting at word_address.

Types

pdo_config()

@type pdo_config() :: EtherCAT.Driver.PDO.t()

sm_entry()

@type sm_entry() ::
  {index :: non_neg_integer(), phys_start :: non_neg_integer(),
   length :: non_neg_integer(), ctrl :: non_neg_integer()}

Functions

dump(bus, station)

@spec dump(EtherCAT.Bus.server(), non_neg_integer()) ::
  {:ok, binary()} | {:error, atom()}

Read the valid SII contents by walking the category structure.

Reads the fixed header (words 0x00–0x3F), then follows category headers starting at word 0x40 until the end marker (type 0xFFFF).

Returns {:ok, binary} or {:error, reason}.

read(bus, station, word_address, word_count)

@spec read(EtherCAT.Bus.server(), non_neg_integer(), non_neg_integer(), pos_integer()) ::
  {:ok, binary()} | {:error, atom()}

Read word_count words from the EEPROM starting at word_address.

Returns {:ok, binary} with word_count * 2 bytes, or {:error, reason}.

read_identity(bus, station)

@spec read_identity(EtherCAT.Bus.server(), non_neg_integer()) ::
  {:ok,
   %{
     vendor_id: integer(),
     product_code: integer(),
     revision: integer(),
     serial_number: integer()
   }}
  | {:error, atom()}

Read the identity fields from SII EEPROM words 0x08–0x0F.

Returns {:ok, identity} where identity is a map with keys: :vendor_id, :product_code, :revision, :serial_number.

read_mailbox_config(bus, station)

@spec read_mailbox_config(EtherCAT.Bus.server(), non_neg_integer()) ::
  {:ok,
   %{
     recv_offset: integer(),
     recv_size: integer(),
     send_offset: integer(),
     send_size: integer()
   }}
  | {:error, atom()}

Read the standard mailbox parameters from SII EEPROM words 0x18–0x1B.

Returns {:ok, mailbox_config} where mailbox_config is a map with keys: :recv_offset, :recv_size, :send_offset, :send_size.

These are the PREOP/SAFEOP/OP mailbox parameters used for CoE, FoE, and EoE. See also the bootstrap mailbox at words 0x14–0x17 (BOOT state only).

read_pdo_configs(bus, station)

@spec read_pdo_configs(EtherCAT.Bus.server(), non_neg_integer()) ::
  {:ok, [pdo_config()]} | {:error, atom()}

Read TxPDO (0x0032) and RxPDO (0x0033) category data from SII EEPROM.

Returns {:ok, [pdo_config()]} where each entry describes one PDO object with its SM assignment, direction, total bit size, and cumulative bit offset within the SM.

Bit offsets are computed in EEPROM order within each SM group. Returns {:ok, []} if no PDO categories are present.

read_sm_configs(bus, station)

@spec read_sm_configs(EtherCAT.Bus.server(), non_neg_integer()) ::
  {:ok, [sm_entry()]} | {:error, atom()}

Read SyncManager configurations from SII category 0x0029.

Returns {:ok, entries} where each entry is {index, phys_start, length, ctrl}. Returns {:ok, []} if the slave has no SII SM category (uses ESC reset defaults).

Category 0x0029 entries are 8 bytes each — identical to the SM register layout. This is the authoritative source for SM physical addresses, sizes, and ctrl bytes, matching the DefaultSize and ControlRegister shown by ethercat pdos.

reload(bus, station)

@spec reload(EtherCAT.Bus.server(), non_neg_integer()) :: :ok | {:error, atom()}

Reload ESC configuration from EEPROM.

The slave re-reads configuration areas A (and B if present) and applies them to its registers. Note: configured station alias and enhanced link detection bits are only loaded at power-on, not on reload.

Returns :ok or {:error, reason}.

write(bus, station, word_address, data)

@spec write(EtherCAT.Bus.server(), non_neg_integer(), non_neg_integer(), binary()) ::
  :ok | {:error, atom()}

Write data to the EEPROM starting at word_address.

data must be a binary whose byte size is a multiple of 2 (whole words). Each word is written individually per the SII protocol.

Returns :ok or {:error, reason}.