How rtlabs-com/p-net works
Purpose and build boundary
P-Net is a C PROFINET Device protocol stack for resource-constrained embedded targets and Linux/RTOS deployments. This evaluation source is intentionally incomplete: it requires target-specific port sources before it can build. Public integration contracts are in include/pnet_api.h, include/pnal.h, and src/pf_driver.h.
Application-facing API and stack bootstrap
The application configures and drives a device through the public P-Net API, implemented by src/device/pnet_api.c. API calls enter device configuration, identification, IO, diagnosis, and alarm subsystems rather than exposing protocol internals directly. Platform abstraction (include/pnal.h) separates OS/network/clock primitives from stack logic.
Device configuration and connection state machines
The src/device layer implements PROFINET device behavior and its coordinated state machines:
• Device lifecycle and controller connection handling: src/device/pf_cmdev.c, src/device/pf_cmsm.c, src/device/pf_cmrpc.c.
• Configuration/parameter services and startup: src/device/pf_cmina.c, src/device/pf_cmpbe.c, src/device/pf_fspm.c.
• IO and record access handling: src/device/pf_cmio.c, src/device/pf_cmrdr.c, src/device/pf_cmwrr.c.
This is the boundary between protocol requests and application-visible device model/state.
RPC, discovery, and management protocols
Connection establishment and management traffic are handled through CM-RPC and endpoint mapping in src/device/pf_cmrpc.c and src/device/pf_cmrpc_epm.c. Common Ethernet-facing protocols provide discovery/configuration, topology advertisement, and management: src/common/pf_dcp.c, src/common/pf_lldp.c, and src/common/pf_snmp.c. Protocol block serialization is centralized in src/device/pf_block_reader.c and src/device/pf_block_writer.c.
Real-time cyclic IO and timing
Cyclic PROFINET traffic is split into consumer and provider paths: src/common/pf_cpm.c receives controller output data, while src/common/pf_ppm.c transmits device input data. Their software fallback drivers are src/common/pf_cpm_driver_sw.c and src/common/pf_ppm_driver_sw.c. Scheduling and synchronization are supplied by src/common/pf_scheduler.c and src/common/pf_ptcp.c; timing and deterministic packet handling are key platform/driver boundaries.
Network, alarms, diagnostics, and ports
Raw Ethernet and UDP transport adapters live in src/common/pf_eth.c and src/common/pf_udp.c. Alarm delivery and diagnostic state are maintained in src/common/pf_alarm.c and src/device/pf_diag.c. Physical-port and port-data behavior is modeled by src/device/pf_port.c, src/device/pf_pdport.c, and src/device/pf_plugsm.c, connecting network-interface events to PROFINET state.
Hardware/runtime integrations
The portable core expects OS/network/file implementations through PNAL and driver hooks. A specialized LAN9662 integration replaces software cyclic IO with hardware-oriented drivers in src/drivers/lan9662/src/pf_cpm_driver_lan9662.c and src/drivers/lan9662/src/pf_ppm_driver_lan9662.c, using MESA and UIO-backed resources (src/drivers/lan9662/src/pf_rte_uio.c). Supported deployment intent includes Linux and RTOSs such as rt-kernel and FreeRTOS; the missing port is the required infrastructure layer.
Main entry points: pnet_api.c API implementation · pf_cpm.c Cyclic IO consumer · pf_ppm.c Cyclic IO provider · pf_cpm_driver_lan9662.c LAN9662 cyclic drivers
Components 20
Integration boundary
- Device application · Configures and drives the P-Net device.
- P-Net public API
include/pnet_api.h - PNAL platform abstraction · Required target-specific runtime and network implementation.
include/pnal.h - Driver hooks
src/pf_driver.h
Device behavior
- API implementation
src/device/pnet_api.c - Connection state machines · Coordinates lifecycle and controller connections.
src/device/pf_cmdev.c - Configuration and startup
src/device/pf_cmina.c - IO and record services
src/device/pf_cmio.c - Diagnostics and alarms
src/device/pf_diag.c - Physical port behavior · Maps interface events into PROFINET port state.
src/device/pf_port.c
Protocols and cyclic IO
- RPC endpoint mapping
src/device/pf_cmrpc_epm.c - Protocol block codec
src/device/pf_block_reader.c - Discovery and management
src/common/pf_dcp.c - Cyclic IO consumer · Receives controller output data.
src/common/pf_cpm.c - Cyclic IO provider · Transmits device input data.
src/common/pf_ppm.c - Scheduling and sync
src/common/pf_scheduler.c - Ethernet and UDP transport
src/common/pf_eth.c
Runtime and hardware
- Software cyclic drivers
src/common/pf_cpm_driver_sw.c - LAN9662 cyclic drivers · Hardware-oriented replacement for software cyclic IO.
src/drivers/lan9662/src/pf_cpm_driver_lan9662.c - LAN9662 UIO resources
src/drivers/lan9662/src/pf_rte_uio.c
Connections 26
- Device application → P-Net public API: configures and drives
- P-Net public API → API implementation: implemented by
- API implementation → Connection state machines: device lifecycle
- API implementation → Configuration and startup: configuration
- API implementation → IO and record services: IO and records
- API implementation → Diagnostics and alarms: diagnosis and alarms
- Connection state machines → RPC endpoint mapping: establishes RPC
- Connection state machines → Configuration and startup: coordinates startup
- Configuration and startup → Protocol block codec: serializes services
- IO and record services → Cyclic IO consumer: controller outputs
- IO and record services → Cyclic IO provider: device inputs
- Diagnostics and alarms → Ethernet and UDP transport: delivers alarms
- Physical port behavior → Discovery and management: topology and port data
- Discovery and management → Ethernet and UDP transport: Ethernet management traffic
- RPC endpoint mapping → Ethernet and UDP transport: management transport
- Cyclic IO consumer → Scheduling and sync: scheduled receive
- Cyclic IO provider → Scheduling and sync: scheduled transmit
- Cyclic IO consumer → Software cyclic drivers: fallback driver
- Cyclic IO provider → Software cyclic drivers: fallback driver
- Cyclic IO consumer → LAN9662 cyclic drivers: hardware option
- Cyclic IO provider → LAN9662 cyclic drivers: hardware option
- LAN9662 cyclic drivers → LAN9662 UIO resources: uses
- Ethernet and UDP transport → PNAL platform abstraction: requires platform services
- Scheduling and sync → PNAL platform abstraction: requires clock and OS services
- Software cyclic drivers → Driver hooks: implements
- LAN9662 cyclic drivers → Driver hooks: implements