Part 1 of this series covered EthSwt’s state machine and its place in the
architecture. This part shows the concrete API — and clears up a common
simplification along the way: EthSwt_Init does not synchronously
initialize the entire switch hardware. According to the SWS (chapter
8.3.1), that can take too long to be called from EcuM or BswM — the
actual hardware configuration is handled by a separate background task.
The init sequence in detail
EthSwt_Init(CfgPtr)
│
├─ Stores a pointer to the configuration structure
├─ State: ETHSWT_STATE_UNINIT → ETHSWT_STATE_INIT
├─ All EthSwtPorts → ETH_MODE_DOWN
└─ Unconfigured hardware ports are switched off
(and stay off for the entire runtime)
... repeated calls ...
EthSwt_BackgroundTask() ◄── call "as often as possible"
│ whenever no other task runs
├─ Takes over switch/port initialization if
│ EthSwt_Init would take too long for it
├─ Checks register access (otherwise: ETHSWT_E_ACCESS)
├─ Activates any configured port mirroring
│ (SWS_EthSwt_00421/00422)
└─ State: ETHSWT_STATE_INIT → ETHSWT_STATE_PORTINIT_COMPLETED
... afterwards, depending on EthSwtLowPowerModeSupport ...
├─ TRUE → switch initially stays in a low-power/inactive state
└─ FALSE → switch goes directly into an active state
EthSwt_SetSwitchPortMode(SwitchIdx, PortIdx, ETH_MODE_ACTIVE)
│ ◄── call explicitly per port
├─ If EthSwtPort references an EthTrcv:
│ additional call to EthTrcv_SetTransceiverMode
│ (via the EthIf API abstraction)
└─ State: ETHSWT_STATE_PORTINIT_COMPLETED → ETHSWT_STATE_ACTIVEThe simple ordering assumed in the original planning issue —
“EthSwt_Init` → |
Key APIs at a glance
| API | Purpose |
|---|---|
| State and pointer initialization; sets all ports to |
| Takes over the actual switch/port hardware initialization if needed |
| Switch a port to |
| Read the current port mode |
| Query a port’s link state |
| Read a port’s MAC address |
| Called cyclically by the BSW scheduler, supports asynchronous API
behavior (e.g. delayed |
Port modes in detail
EthSwt_SetSwitchPortMode expects one of three Eth_ModeType values:
| Mode | Meaning |
|---|---|
| Disable the port — per spec, as directly as possible to reduce power consumption |
| Enable the port |
| Enable the port and trigger a wake-up on the network — per SWS relevant e.g. for hardware compatible with OPEN Alliance TC10 |
If an |
Link state: with and without EthTrcv
EthSwt_GetLinkState behaves differently depending on whether the port
references an EthTrcv:
With an EthTrcv reference — the link state comes from
EthTrcv_GetLinkState(via EthIf), exactly as in a plain transceiver setupWithout an EthTrcv reference (e.g. an internal port to an embedded PHY that the switch chip manages itself) — the state comes from the port’s MAC interface; if the hardware can’t provide that, it’s derived from the current port mode:
ETH_MODE_ACTIVE→ link active,ETH_MODE_DOWN→ link down
If the port mode and the PHY mode don’t match, EthSwt_GetSwitchPortMode
reports the extended production error ETHSWT_E_SYNCPORT2PHY and returns
E_NOT_OK — a useful signal when debugging a case where the switch and the
transceiver report different states for different reasons.
Error handling & determinism
Per the SWS, every API covered in this post first checks register access to
the switch hardware; if that fails, the extended production error
ETHSWT_E_ACCESS is raised and E_NOT_OK is returned. Additionally, every
API returns E_NOT_OK if called in state ETHSWT_STATE_UNINIT or
ETHSWT_STATE_INIT (i.e. before port initialization has completed).
Practical consequence: calling |
Minimal example: init call sequence for a 4-port switch
EthSwt_Init(&EthSwtConfig_0);
// ... run background task cycles until PORTINIT_COMPLETED ...
EthSwt_BackgroundTask(); // possibly multiple times, depending on scheduling
for (portIdx = 0; portIdx < 4; portIdx++) {
EthSwt_SetSwitchPortMode(0, portIdx, ETH_MODE_ACTIVE);
}
// Cyclic operation:
EthSwt_MainFunction(); // called regularly by the BSW schedulerSeries
| Part | Topic | Status |
|---|---|---|
1 | Fundamentals, SWS & architecture | done |
2 | API & initialization | this post |
3 | ARXML configuration | upcoming |
4 | VLAN management, mirroring & diagnostics | upcoming |
Next in the EthSwt series: EthSwt Part 3 — ARXML Configuration in Practice