# saga0619/rtnet_soem architecture

> Architecture diagram of the GitHub repository saga0619/rtnet_soem, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saga0619/rtnet_soem
- Repository: https://github.com/saga0619/rtnet_soem

## Overview

RTNE-SOEM is a C EtherCAT master library, patched for RTnet use. Its documented workflow is to initialize with `ec_init` or `ec_init_redundant` on the main thread, then perform EtherCAT communication from a real-time thread; the README also describes redundant links and a humanoid-robot stability test. The graph separates the master runtime, protocol capabilities, platform I/O, and OS timing/thread support. Several protocol modules are present in the tree but were not sampled, so their nodes are shown without speculative call arrows.

Main entry points: [`soem/ethercatmain.c`](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatmain.c) (Master core), [`osal/osal.h`](https://github.com/saga0619/rtnet_soem/blob/main/osal/osal.h) (OS abstraction), [`oshw/rtk/nicdrv.c`](https://github.com/saga0619/rtnet_soem/blob/main/oshw/rtk/nicdrv.c) (RTK NIC driver), [`soem/ethercatcoe.c`](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatcoe.c) (CoE)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_master["Master runtime"]
  node_master_core["Master core<br/>[ethercatmain.c]"]
  node_wire_types["Wire types<br/>[ethercattype.h]"]
end

subgraph group_protocol["EtherCAT protocols"]
  node_base["Base datagrams<br/>[ethercatbase.c]"]
  node_configuration["Slave configuration<br/>[ethercatconfig.c]"]
  node_coe["CoE<br/>[ethercatcoe.c]"]
  node_eoe["EoE<br/>[ethercateoe.c]"]
  node_foe["FoE<br/>[ethercatfoe.c]"]
  node_soe["SoE<br/>[ethercatsoe.c]"]
  node_dc["Distributed clocks<br/>[ethercatdc.c]"]
  node_diagnostics["Protocol printing<br/>[ethercatprint.c]"]
end

subgraph group_io["Platform I/O"]
  node_linux_nic["Linux NIC driver<br/>[nicdrv.c]"]
  node_rtk_nic["RTK NIC driver<br/>[nicdrv.c]"]
  node_rtk_mac["RTK MAC support<br/>[lw_emac.c]"]
end

subgraph group_osal["OS services"]
  node_osal_api["OS abstraction<br/>[osal.h]"]
  node_linux_osal["Linux OS services<br/>[osal.c]"]
  node_rtk_osal["RTK OS services<br/>[osal.c]"]
end

node_application(("Application"))
node_ethercat_slaves(("EtherCAT slaves"))

node_application -->|"initializes and communicates"| node_master_core
node_master_core -->|"uses definitions"| node_wire_types
node_master_core -.->|"selects platform interface"| node_rtk_nic
node_master_core -.->|"exchanges datagrams"| node_ethercat_slaves
node_linux_nic -->|"sends and receives frames"| node_ethercat_slaves
node_rtk_nic -->|"initializes MAC"| node_rtk_mac
node_rtk_nic -.->|"sends and receives frames"| node_ethercat_slaves
node_master_core -->|"uses timing services"| node_osal_api
node_coe -->|"uses timing services"| node_osal_api
node_osal_api -.->|"platform implementation"| node_linux_osal
node_osal_api -.->|"platform implementation"| node_rtk_osal

click node_master_core "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatmain.c"
click node_wire_types "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercattype.h"
click node_base "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatbase.c"
click node_configuration "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatconfig.c"
click node_coe "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatcoe.c"
click node_eoe "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercateoe.c"
click node_foe "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatfoe.c"
click node_soe "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatsoe.c"
click node_dc "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatdc.c"
click node_diagnostics "https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatprint.c"
click node_linux_nic "https://github.com/saga0619/rtnet_soem/blob/main/oshw/linux/nicdrv.c"
click node_rtk_nic "https://github.com/saga0619/rtnet_soem/blob/main/oshw/rtk/nicdrv.c"
click node_rtk_mac "https://github.com/saga0619/rtnet_soem/blob/main/oshw/rtk/lw_mac/lw_emac.c"
click node_osal_api "https://github.com/saga0619/rtnet_soem/blob/main/osal/osal.h"
click node_linux_osal "https://github.com/saga0619/rtnet_soem/blob/main/osal/linux/osal.c"
click node_rtk_osal "https://github.com/saga0619/rtnet_soem/blob/main/osal/rtk/osal.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_master_core,node_wire_types toneBlue
class node_base,node_configuration,node_coe,node_eoe,node_foe,node_soe,node_dc,node_diagnostics toneAmber
class node_linux_nic,node_rtk_nic,node_rtk_mac toneMint
class node_osal_api,node_linux_osal,node_rtk_osal toneRose
class node_application,node_ethercat_slaves toneIndigo
```

## Components

### Master runtime

- [Master core](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatmain.c): `soem/ethercatmain.c`
- [Wire types](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercattype.h): `soem/ethercattype.h`

### EtherCAT protocols

- [Base datagrams](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatbase.c): `soem/ethercatbase.c`
- [Slave configuration](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatconfig.c): `soem/ethercatconfig.c`
- [CoE](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatcoe.c): `soem/ethercatcoe.c`
- [EoE](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercateoe.c): `soem/ethercateoe.c`
- [FoE](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatfoe.c): `soem/ethercatfoe.c`
- [SoE](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatsoe.c): `soem/ethercatsoe.c`
- [Distributed clocks](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatdc.c): `soem/ethercatdc.c`
- [Protocol printing](https://github.com/saga0619/rtnet_soem/blob/main/soem/ethercatprint.c): `soem/ethercatprint.c`

### Platform I/O

- [Linux NIC driver](https://github.com/saga0619/rtnet_soem/blob/main/oshw/linux/nicdrv.c): `oshw/linux/nicdrv.c`
- [RTK NIC driver](https://github.com/saga0619/rtnet_soem/blob/main/oshw/rtk/nicdrv.c): `oshw/rtk/nicdrv.c`
- [RTK MAC support](https://github.com/saga0619/rtnet_soem/blob/main/oshw/rtk/lw_mac/lw_emac.c): `oshw/rtk/lw_mac/lw_emac.c`

### OS services

- [OS abstraction](https://github.com/saga0619/rtnet_soem/blob/main/osal/osal.h): `osal/osal.h`
- [Linux OS services](https://github.com/saga0619/rtnet_soem/blob/main/osal/linux/osal.c): `osal/linux/osal.c`
- [RTK OS services](https://github.com/saga0619/rtnet_soem/blob/main/osal/rtk/osal.c): `osal/rtk/osal.c`

### Other components

- **Application**
- **EtherCAT slaves**

## Connections

- Application → Master core: initializes and communicates
- Master core → Wire types: uses definitions (evidence: `soem/ethercatmain.c`)
- Master core → RTK NIC driver: selects platform interface
- Master core → EtherCAT slaves: exchanges datagrams
- Linux NIC driver → EtherCAT slaves: sends and receives frames (evidence: `oshw/linux/nicdrv.c`)
- RTK NIC driver → RTK MAC support: initializes MAC (evidence: `oshw/rtk/nicdrv.c`)
- RTK NIC driver → EtherCAT slaves: sends and receives frames
- Master core → OS abstraction: uses timing services (evidence: `soem/ethercatmain.c`)
- CoE → OS abstraction: uses timing services (evidence: `soem/ethercatcoe.c`)
- OS abstraction → Linux OS services: platform implementation
- OS abstraction → RTK OS services: platform implementation (evidence: `osal/osal.h`)
