mokomoking2501/MoonECAT/hal does not have a README file

    Clock

    pub(open) trait Clock {
    fn now(Self) -> Timestamp
    fn sleep(Self, Duration) -> Unit
    }

    Clock provides monotonic timing primitives.

    DiagnosticSink

    pub(open) trait DiagnosticSink {
    fn emit(Self, DiagnosticEvent) -> Unit
    }

    DiagnosticSink receives diagnostic events from the stack.

    FileAccess

    pub(open) trait FileAccess {
    fn read_file(Self, String) -> Bytes raise EcError
    fn write_file(Self, String, Bytes) -> Unit raise EcError
    }

    FileAccess provides basic file I/O for configuration and diagnostics.

    Nic

    pub(open) trait Nic {
    fn open_(String) -> Self raise EcError
    fn send(Self, Bytes) -> Int raise EcError
    fn recv(Self, timeout~ : Duration) -> Bytes raise EcError
    fn close(Self) -> Unit
    }

    Nic defines the minimal network interface contract. All platform backends must implement this trait.

    ZeroCopyNic

    pub(open) trait ZeroCopyNic {
    fn open_(String, FramePool) -> Self raise EcError
    fn acquire_tx(Self) -> FrameRef raise EcError
    fn tx_buffer(Self, FrameRef) -> FixedArray[Byte]
    fn submit(Self, FrameRef, length~ : Int) -> Unit raise EcError
    fn recv(Self, timeout~ : Duration) -> FrameRef raise EcError
    fn rx_buffer(Self, FrameRef) -> FixedArray[Byte]
    fn rx_length(Self, FrameRef) -> Int
    fn release(Self, FrameRef) -> Unit
    fn close(Self) -> Unit
    }

    ZeroCopyNic defines the zero-allocation network interface contract.

    Unlike Nic which allocates Bytes on every recv, ZeroCopyNic operates on pre-allocated FramePool slots. The hot path has zero GC allocations.

    Platform backends:
    • Windows Npcap: FramePool in MoonBit heap, pcap_sendpacket via #borrow
    • Linux Raw Socket: FramePool in MoonBit heap, send/recv via #borrow
    • Linux AF_XDP: FramePool backed by UMEM shared memory
    • Embedded MCU: FramePool mapped to DMA descriptor ring in .DMA_SRAM

    EcError

    pub(all) suberror EcError {
    LinkDown
    SendFailed(String)
    RecvTimeout
    RecvFailed(String)
    InvalidFrame(String)
    InvalidPdu(String)
    UnexpectedWkc(expected~ : Int, actual~ : Int)
    EsmTransitionFailed(from~ : String, to~ : String)
    EsmStateError(String)
    MailboxTimeout
    MailboxProtocol(String)
    SdoAbort(UInt)
    SiiReadFailed(String)
    EsiParseFailed(String)
    ConfigMismatch(String)
    NotSupported(String)
    Internal(String)
    } derive(
    Debug
    )

    EcError represents all error conditions in the MoonECAT stack. Errors are grouped by layer to keep diagnostics clear.

    DiagnosticEvent

    pub(all) struct DiagnosticEvent {
    timestamp : Timestamp
    severity : Severity
    source : String
    message : String
    } derive(
    Debug
    )

    DiagnosticEvent represents a structured event emitted during operation.

    DiagnosticEvent::new

    fn DiagnosticEvent::new(timestamp : Timestamp, severity : Severity, source : String, message : String) -> DiagnosticEvent

    Duration

    pub(all) enum Duration {
    Duration(Int64)
    } derive(Compare, Eq,
    Debug
    )

    Duration represents a span of time, in nanoseconds.

    FramePool

    pub(all) struct FramePool {
    id : Int
    frames : FixedArray[FixedArray[Byte]]
    states : FixedArray[FrameState]
    lengths : FixedArray[Int]
    capacity : Int
    frame_size : Int
    next_scan : Int
    }

    FramePool provides pre-allocated frame buffers that eliminate per-cycle heap allocation in the PDO hot path.

    Inspired by EtherCrab's PduStorage (atomic frame pool) and CherryECAT's DMA descriptor ring (static buffer reuse).

    FramePool::acquire

    fn FramePool::acquire(self : FramePool) -> FrameRef raise EcError

    Acquire a free frame slot from the pool. Scans from the last allocation point (round-robin) for O(1) amortized. Returns EcError if no free slots are available.

    FramePool::acquire_rx

    fn FramePool::acquire_rx(self : FramePool) -> FrameRef raise EcError

    Acquire a slot for receiving into.

    FramePool::buffer

    fn FramePool::buffer(self : FramePool, fref : FrameRef) -> FixedArray[Byte]

    Get the writable buffer for an acquired frame slot. The caller fills this buffer with frame data, then calls mark_filled.

    FramePool::data_length

    fn FramePool::data_length(self : FramePool, fref : FrameRef) -> Int

    Get the effective data length for a frame slot.

    FramePool::free_count

    fn FramePool::free_count(self : FramePool) -> Int

    Count the number of free slots available.

    FramePool::mark_filled

    fn FramePool::mark_filled(self : FramePool, fref : FrameRef, length : Int) -> FrameRef

    Mark a frame as filled with the given data length.

    FramePool::mark_received

    fn FramePool::mark_received(self : FramePool, fref : FrameRef, length : Int) -> FrameRef

    Mark a receive slot as having received data.

    FramePool::mark_sending

    fn FramePool::mark_sending(self : FramePool, fref : FrameRef) -> Unit

    Mark a frame as being sent by the platform backend.

    FramePool::mark_sent

    fn FramePool::mark_sent(self : FramePool, fref : FrameRef) -> Unit

    Mark a frame as sent (transmission complete).

    FramePool::new

    fn FramePool::new(capacity? : Int, frame_size? : Int, id? : Int) -> FramePool

    Create a new FramePool with the given capacity and frame size. All buffers are pre-allocated; no further allocation occurs during operation.

    FramePool::read_byte

    fn FramePool::read_byte(self : FramePool, fref : FrameRef, offset : Int) -> Byte

    Read a single byte from a frame buffer at the given offset.

    FramePool::read_bytes

    fn FramePool::read_bytes(self : FramePool, fref : FrameRef, offset : Int, dst : FixedArray[Byte], dst_offset : Int, count : Int) -> Unit

    Copy data from a frame buffer into a FixedArray at the given offset.

    FramePool::read_u16_le

    fn FramePool::read_u16_le(self : FramePool, fref : FrameRef, offset : Int) -> Int

    Read a 16-bit little-endian value from a frame buffer.

    FramePool::read_u32_le

    fn FramePool::read_u32_le(self : FramePool, fref : FrameRef, offset : Int) -> Int

    Read a 32-bit little-endian value from a frame buffer.

    FramePool::release

    fn FramePool::release(self : FramePool, fref : FrameRef) -> Unit

    Release a frame slot back to the pool for reuse.

    FramePool::reset

    fn FramePool::reset(self : FramePool) -> Unit

    Reset all slots to Free state. Used for pool reinitialization.

    FramePool::state

    fn FramePool::state(self : FramePool, fref : FrameRef) -> FrameState

    Get the current state of a frame slot.

    FramePool::write_byte

    fn FramePool::write_byte(self : FramePool, fref : FrameRef, offset : Int, value : Byte) -> Unit

    Write a single byte into a frame buffer at the given offset.

    FramePool::write_bytes

    fn FramePool::write_bytes(self : FramePool, fref : FrameRef, offset : Int, src : FixedArray[Byte], src_offset : Int, count : Int) -> Unit

    Copy data from a FixedArray into a frame buffer at the given offset.

    FramePool::write_u16_le

    fn FramePool::write_u16_le(self : FramePool, fref : FrameRef, offset : Int, value : Int) -> Unit

    Write a 16-bit little-endian value into a frame buffer.

    FramePool::write_u32_le

    fn FramePool::write_u32_le(self : FramePool, fref : FrameRef, offset : Int, value : Int) -> Unit

    Write a 32-bit little-endian value into a frame buffer.

    FrameRef

    pub(all) struct FrameRef {
    pool_id : Int
    slot : Int
    offset : Int
    length : Int
    } derive(Eq,
    Debug
    )

    FrameRef is a lightweight value-type reference to a frame slot. No heap allocation 鈥?just 4 integers identifying the slice of data.

    FrameState

    pub(all) enum FrameState {
    Free
    Acquired
    Filled
    Sending
    Sent
    Receiving
    Received
    } derive(Eq,
    Debug
    )

    FrameState tracks the lifecycle of a frame slot in the pool. Transitions: Free 鈫?Acquired 鈫?Filled 鈫?Sending 鈫?Sent 鈫?Free Free 鈫?Receiving 鈫?Received 鈫?Free

    MasterConfig

    pub(all) struct MasterConfig {
    interface_name : String
    cycle_period_ns : Int64
    recv_timeout_ns : Int64
    max_retries : Int
    dc_enabled : Bool
    } derive(Eq,
    Debug
    )

    MasterConfig holds global master parameters.

    MasterConfig::default

    fn MasterConfig::default() -> MasterConfig

    MutableProcessImage

    pub(all) struct MutableProcessImage {
    outputs : FixedArray[Byte]
    inputs : FixedArray[Byte]
    output_size : Int
    input_size : Int
    } derive(
    Debug
    )

    MutableProcessImage uses FixedArray[Byte] for in-place read/write, eliminating per-cycle Bytes allocation in the PDO hot path.

    MutableProcessImage::clear_inputs

    fn MutableProcessImage::clear_inputs(self : MutableProcessImage) -> Unit

    Zero out inputs buffer (called before receiving new PDO data).

    MutableProcessImage::new

    fn MutableProcessImage::new(output_size : Int, input_size : Int) -> MutableProcessImage

    Create a new MutableProcessImage with pre-allocated buffers.

    NicHandle

    pub(all) struct NicHandle {
    id : Int
    } derive(Eq,
    Debug
    )

    NicHandle is an opaque network interface handle provided by the HAL backend.

    Severity

    pub(all) enum Severity {
    Debug
    Info
    Warn
    Error
    } derive(Eq,
    Debug
    )

    Severity level for diagnostic events.

    SlaveConfig

    pub(all) struct SlaveConfig {
    position : UInt
    expected_identity : SlaveIdentity?
    expected_identification : UInt?
    expected_alias_address : UInt?
    configured_address : UInt
    presence : SlavePresence
    } derive(Eq,
    Debug
    )

    SlaveConfig holds per-slave configuration parameters.

    SlaveIdentity

    pub(all) struct SlaveIdentity {
    vendor_id : UInt
    product_code : UInt
    revision : UInt
    serial : UInt
    } derive(Eq,
    Debug
    )

    SlaveIdentity holds the vendor/product identity read from SII.

    SlavePresence

    pub(all) enum SlavePresence {
    Mandatory
    Optional(group_id~ : UInt?)
    } derive(Eq,
    Debug
    )

    Timestamp

    pub(all) enum Timestamp {
    Timestamp(Int64)
    } derive(Compare, Eq,
    Debug
    )

    Timestamp represents a monotonic point in time, in nanoseconds.

    default_pool_capacity

    let default_pool_capacity : Int

    Default number of frame slots in a pool.

    ethercat_ethertype

    let ethercat_ethertype : Int

    The EtherCAT EtherType constant (0x88A4).

    max_frame_size

    let max_frame_size : Int

    The maximum size of an EtherCAT frame payload (Ethernet MTU).