AM263Px INDUSTRIAL COMMUNICATIONS SDK  2026.00.00
iolfw.h
Go to the documentation of this file.
1 
59 #ifndef IOLFW_H_
60 #define IOLFW_H_
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /* ========================================================================== */
67 /* Include Files */
68 /* ========================================================================== */
69 
70 #include <stdarg.h>
71 #include <stdbool.h>
72 #include <stdint.h>
73 #include <stdlib.h>
74 
75 #include <drivers/pruicss.h>
76 
77 /* ========================================================================== */
78 /* Macros & Typedefs */
79 /* ========================================================================== */
80 
81 /* Default TA bit time */
82 #define IOLFW_TA_BIT_DEFAULT (11)
83 /* Maximum number of Process Data bytes */
84 #define IOLFW_MAX_PD_SIZE (32)
85 /* Maximum number of OD bytes per message */
86 #define IOLFW_MAX_OD_SIZE (32)
87 /* Default transmission rate : COM3 */
88 #define IOLFW_TR_DEF (3)
89 
90 /* Maximum possible response time between IO-Link Master Tx and Slave Rx UART
91  * frames in bits */
92 #define IOLFW_MAX_RESPONSE_TIME (85U)
93 /* Adapt if needed to ensure uniform packing across abstraction layers */
94 #define IOLFW_STRUCT_PACKED __attribute__((__packed__))
95 
96 /* ========================================================================== */
97 /* Error Codes */
98 /* ========================================================================== */
99 
100 #define IOLFW_ERR_SUCCESS (0)
101 #define IOLFW_ERR_BASE_CODE (-150)
102 
104 #define IOLFW_ERR_PRECONFIG (IOLFW_ERR_BASE_CODE - 1)
105 
106 #define IOLFW_ERR_EMPTY_ARG (IOLFW_ERR_BASE_CODE - 2)
107 
108 #define IOLFW_ERR_INST_INVALID (IOLFW_ERR_BASE_CODE - 4)
109 
110 #define IOLFW_ERR_INST_ALL_USED (IOLFW_ERR_BASE_CODE - 5)
111 
112 #define IOLFW_ERR_CB_PORT_CFG (IOLFW_ERR_BASE_CODE - 6)
113 
114 #define IOLFW_ERR_CB_SET_MODE (IOLFW_ERR_BASE_CODE - 7)
115 
116 #define IOLFW_ERR_CB_RX_ERR_EVT (IOLFW_ERR_BASE_CODE - 9)
117 
118 #define IOLFW_ERR_CB_TR_IND (IOLFW_ERR_BASE_CODE - 10)
119 
120 #define IOLFW_ERR_CB_START_COMP (IOLFW_ERR_BASE_CODE - 11)
121 
122 #define IOLFW_ERR_PRU_CLOCK (IOLFW_ERR_BASE_CODE - 12)
123 
124 #define IOLFW_ERR_IEP_CLOCK (IOLFW_ERR_BASE_CODE - 13)
125 
126 #define IOLFW_ERR_VAL_OUT_OF_RANGE (IOLFW_ERR_BASE_CODE - 14)
127 
128 #define IOLFW_ERR_NULL_PTR (IOLFW_ERR_BASE_CODE - 15)
129 
130 #define IOLFW_ERR_PORT_OUT_OF_RANGE (IOLFW_ERR_BASE_CODE - 16)
131 
132 #define IOLFW_ERR_INVALID_CYCLE_TIME (IOLFW_ERR_BASE_CODE - 17)
133 
134 /* Maximum number of IOLFW instances */
135 #define IOLFW_MAX_INST (1)
136 /* Maximum number of ports per instance */
137 #define IOLFW_MAX_PORTS (8)
138 
139 /* ========================================================================== */
140 /* Structure Declarations */
141 /* ========================================================================== */
142 
150 typedef enum IOLFW_ePortMode
151 {
156  IOLFW_ePortMode_Force32Bit = 0x7fffffff
158 
165 typedef struct IOLFW_PortInst
166 {
168  uint32_t txDataLength;
169  uint32_t rxDataLength;
170  uint8_t *pRxBuffer;
171  uint8_t awaitingRsp;
173  uint8_t errorReported;
176 
182 typedef enum IOLFW_eInstanceState
183 {
188 
189 typedef struct IOLFW_PruMem IOLFW_PruMem_t;
190 typedef struct IOLFW_PruMemTimer IOLFW_PruMemTimer_t;
191 
198 typedef struct IOLFW_Inst
199 {
201  void *pUserArg;
202  uint32_t pruIcssInst;
203  PRUICSS_Handle pruHandle;
206  volatile uint8_t *pruBase;
207  volatile uint8_t *pruIntc;
210 } IOLFW_Inst_t;
211 
219 typedef enum IOLFW_eBaudrate
220 {
226 
232 typedef enum IOLFW_eRxErrorEvents
233 {
236 
242 typedef enum IOLFW_eTransferStatus
243 {
249 
255 typedef enum IOLFW_eStartupStatus
256 {
260 
266 typedef struct IOLFW_GpioConfig
267 {
268  uint32_t gpioBase;
269  uint32_t gpioPin;
270  int16_t ctlRegOffset;
272 
279 typedef struct IOLFW_GpioPruConfig
280 {
282  uint32_t pruPin;
284 
291 typedef struct IOLFW_GpioEnConfig
292 {
294  uint32_t gpioPhysAddr;
295  uint32_t gpioPinMask;
297 
304 typedef struct IOLFW_PortConfig
305 {
311 
317 typedef struct IOLFW_Config
318 {
322 
323 /* ========================================================================== */
324 /* Callback Typedefs */
325 /* ========================================================================== */
326 
337 typedef void (*IOLFW_cbSetMode_t)(IOLFW_Inst_t *pFwInstance, uint8_t portNum, IOLFW_ePortMode_t mode);
338 
350 typedef const IOLFW_PortConfig_t *(*IOLFW_cbGetPortCfg_t)(IOLFW_Inst_t *pFwInstance, uint8_t portNum);
351 
361 typedef void (
362  *IOLFW_cbRxErrEvent_t)(IOLFW_Inst_t *pFwInstance, uint8_t port, IOLFW_eRxErrorEvents_t rxErr);
363 
374 typedef void (*IOLFW_cbTransferInd_t)(
375  IOLFW_Inst_t *pFwInstance,
376  uint8_t port,
377  uint8_t dataLen,
378  IOLFW_eTransferStatus_t eTrStatus);
379 
389 typedef void (
390  *IOLFW_cbStartupCmpl_t)(IOLFW_Inst_t *pFwInstance, uint8_t port, IOLFW_eStartupStatus_t eStrStatus);
391 
399 typedef IOLFW_Inst_t *(*IOLFW_cbGetInstCont_t)(uint8_t inst_p);
400 
407 typedef struct IOLFW_PlCallbacks
408 {
412 
418 typedef struct IOLFW_SpCallbacks
419 {
424 
425 /* ========================================================================== */
426 /* Function Declarations */
427 /* ========================================================================== */
428 
444 
455 
466 
477 
488 
518 int32_t IOLFW_init(IOLFW_Inst_t **pFwInstance, IOLFW_Config_t *pConfig);
519 
532 int32_t IOLFW_deInit(IOLFW_Inst_t *pFwInstance);
533 
555 int32_t IOLFW_setPortMode(IOLFW_Inst_t *pFwInstance, uint8_t port, IOLFW_ePortMode_t eTargetMode);
556 
568 
582 int32_t IOLFW_wakeUp(IOLFW_Inst_t *pFwInstance, uint8_t port);
583 
604  IOLFW_Inst_t *pFwInstance,
605  uint8_t port,
606  uint8_t *pData,
607  uint8_t dataLength,
608  uint8_t *pResponseData,
609  uint8_t responseLength);
610 
632 int32_t IOLFW_setMaxRespTime(IOLFW_Inst_t *pFwInstance, uint8_t port, uint8_t taRespTime);
633 
646 int32_t IOLFW_resetCycleTime(IOLFW_Inst_t *pFwInstance, uint8_t port);
647 
661 int32_t IOLFW_setCycleTime(IOLFW_Inst_t *pFwInstance, uint8_t port, uint32_t timeUs);
662 
677 int32_t IOLFW_enableCycleTimer(IOLFW_Inst_t *pFwInstance, uint8_t port, bool enable);
678 
700 int32_t IOLFW_configCycleTime(IOLFW_Inst_t *pFwInstance, uint8_t port, uint32_t timeUs);
701 
705 #ifdef __cplusplus
706 }
707 #endif
708 
709 #endif /* IOLFW_H_ */
IOLFW_PortInst_t::startupActive
bool startupActive
Definition: iolfw.h:174
IOLFW_eInstanceState_t
IOLFW_eInstanceState_t
IOLFW instance state.
Definition: iolfw.h:183
IOLFW_eBaudrate_Com3
@ IOLFW_eBaudrate_Com3
Definition: iolfw.h:224
IOLFW_Inst_t::pruDram1
volatile IOLFW_PruMemTimer_t * pruDram1
Definition: iolfw.h:205
IOLFW_GpioPruConfig_t
GPIO configuration with PRU pin mapping.
Definition: iolfw.h:280
IOLFW_Inst_t::pruBase
volatile uint8_t * pruBase
Definition: iolfw.h:206
IOLFW_SpCallbacks_t::cbRxErrEvent
IOLFW_cbRxErrEvent_t cbRxErrEvent
Definition: iolfw.h:421
IOLFW_setCycleTime
int32_t IOLFW_setCycleTime(IOLFW_Inst_t *pFwInstance, uint8_t port, uint32_t timeUs)
Set cycle time.
IOLFW_eStartupStatus_Ok
@ IOLFW_eStartupStatus_Ok
Definition: iolfw.h:257
IOLFW_Config_t::pruIcssInstanceNumber
uint32_t pruIcssInstanceNumber
Definition: iolfw.h:319
IOLFW_registerGetPortCfgCallback
void IOLFW_registerGetPortCfgCallback(IOLFW_cbGetPortCfg_t pCallback)
Register port configuration callback.
IOLFW_PortInst_t
IO-Link port instance data.
Definition: iolfw.h:166
IOLFW_GpioPruConfig_t::pruPin
uint32_t pruPin
Definition: iolfw.h:282
IOLFW_MAX_PORTS
#define IOLFW_MAX_PORTS
Definition: iolfw.h:137
IOLFW_SpCallbacks_t::cbTransferInd
IOLFW_cbTransferInd_t cbTransferInd
Definition: iolfw.h:422
IOLFW_transferPrepare
int32_t IOLFW_transferPrepare(IOLFW_Inst_t *pFwInstance, uint8_t port, uint8_t *pData, uint8_t dataLength, uint8_t *pResponseData, uint8_t responseLength)
Prepare data transfer.
IOLFW_eInstanceState_Running
@ IOLFW_eInstanceState_Running
Definition: iolfw.h:186
IOLFW_deInit
int32_t IOLFW_deInit(IOLFW_Inst_t *pFwInstance)
De-initialize IOLFW instance.
IOLFW_ePortMode_Force32Bit
@ IOLFW_ePortMode_Force32Bit
Definition: iolfw.h:156
IOLFW_registerTransferIndCallback
void IOLFW_registerTransferIndCallback(IOLFW_cbTransferInd_t pCallback)
Register transfer indication callback.
IOLFW_GpioConfig_t::ctlRegOffset
int16_t ctlRegOffset
Definition: iolfw.h:270
IOLFW_eTransferStatus_FramingError
@ IOLFW_eTransferStatus_FramingError
Definition: iolfw.h:246
IOLFW_eBaudrate_Com2
@ IOLFW_eBaudrate_Com2
Definition: iolfw.h:223
IOLFW_setPortMode
int32_t IOLFW_setPortMode(IOLFW_Inst_t *pFwInstance, uint8_t port, IOLFW_ePortMode_t eTargetMode)
Set port operating mode.
IOLFW_PortInst_t::txDataLength
uint32_t txDataLength
Definition: iolfw.h:168
IOLFW_eStartupStatus_t
IOLFW_eStartupStatus_t
Port startup/wake-up status codes.
Definition: iolfw.h:256
IOLFW_ePortMode_SioDO
@ IOLFW_ePortMode_SioDO
Definition: iolfw.h:155
IOLFW_configCycleTime
int32_t IOLFW_configCycleTime(IOLFW_Inst_t *pFwInstance, uint8_t port, uint32_t timeUs)
Configure and enable cycle time.
IOLFW_Inst_t::pUserArg
void * pUserArg
Definition: iolfw.h:201
IOLFW_PlCallbacks_t::cbSetMode
IOLFW_cbSetMode_t cbSetMode
Definition: iolfw.h:409
IOLFW_GpioEnConfig_t::gpioPinMask
uint32_t gpioPinMask
Definition: iolfw.h:295
IOLFW_ePortMode_t
IOLFW_ePortMode_t
IO-Link port operating mode.
Definition: iolfw.h:151
IOLFW_GpioEnConfig_t::gpio
IOLFW_GpioConfig_t gpio
Definition: iolfw.h:293
IOLFW_PortInst_t::rxDataLength
uint32_t rxDataLength
Definition: iolfw.h:169
IOLFW_eRxErrorEvents_t
IOLFW_eRxErrorEvents_t
RX error event types.
Definition: iolfw.h:233
IOLFW_PortConfig_t::txEn
IOLFW_GpioEnConfig_t txEn
Definition: iolfw.h:308
IOLFW_wakeUp
int32_t IOLFW_wakeUp(IOLFW_Inst_t *pFwInstance, uint8_t port)
Initiate IO-Link wake-up sequence.
IOLFW_PortConfig_t::tx
IOLFW_GpioPruConfig_t tx
Definition: iolfw.h:307
IOLFW_PortInst_t::errorReported
uint8_t errorReported
Definition: iolfw.h:173
IOLFW_Inst_t::pruHandle
PRUICSS_Handle pruHandle
Definition: iolfw.h:203
IOLFW_cbTransferInd_t
void(* IOLFW_cbTransferInd_t)(IOLFW_Inst_t *pFwInstance, uint8_t port, uint8_t dataLen, IOLFW_eTransferStatus_t eTrStatus)
Transfer indication callback.
Definition: iolfw.h:374
IOLFW_enableCycleTimer
int32_t IOLFW_enableCycleTimer(IOLFW_Inst_t *pFwInstance, uint8_t port, bool enable)
Enable or disable cycle timer.
IOLFW_ePortMode_SioDI
@ IOLFW_ePortMode_SioDI
Definition: iolfw.h:154
IOLFW_eBaudrate_Auto
@ IOLFW_eBaudrate_Auto
Definition: iolfw.h:221
IOLFW_PruMem_t
struct IOLFW_PruMem IOLFW_PruMem_t
Definition: iolfw.h:189
IOLFW_SpCallbacks_t::cbStartupCmpl
IOLFW_cbStartupCmpl_t cbStartupCmpl
Definition: iolfw.h:420
IOLFW_eTransferStatus_t
IOLFW_eTransferStatus_t
Data transfer status codes.
Definition: iolfw.h:243
IOLFW_GpioEnConfig_t
GPIO enable configuration with PRU direct access.
Definition: iolfw.h:292
IOLFW_Inst_t::pruIntc
volatile uint8_t * pruIntc
Definition: iolfw.h:207
IOLFW_PortConfig_t::pwrEn
IOLFW_GpioConfig_t pwrEn
Definition: iolfw.h:309
IOLFW_PortConfig_t
IO-Link port hardware configuration.
Definition: iolfw.h:305
IOLFW_Config_t
IOLFW initialization configuration.
Definition: iolfw.h:318
IOLFW_eRxErrorEvents_Rxol
@ IOLFW_eRxErrorEvents_Rxol
Definition: iolfw.h:234
IOLFW_ePortMode_SioInactive
@ IOLFW_ePortMode_SioInactive
Definition: iolfw.h:152
IOLFW_PlCallbacks_t
Physical Layer (PL) callbacks.
Definition: iolfw.h:408
IOLFW_cbStartupCmpl_t
void(* IOLFW_cbStartupCmpl_t)(IOLFW_Inst_t *pFwInstance, uint8_t port, IOLFW_eStartupStatus_t eStrStatus)
Startup/wake-up completion callback.
Definition: iolfw.h:390
IOLFW_cbRxErrEvent_t
void(* IOLFW_cbRxErrEvent_t)(IOLFW_Inst_t *pFwInstance, uint8_t port, IOLFW_eRxErrorEvents_t rxErr)
RX error event callback.
Definition: iolfw.h:362
IOLFW_Inst_t::pruIcssInst
uint32_t pruIcssInst
Definition: iolfw.h:202
IOLFW_cbSetMode_t
void(* IOLFW_cbSetMode_t)(IOLFW_Inst_t *pFwInstance, uint8_t portNum, IOLFW_ePortMode_t mode)
Port mode change callback.
Definition: iolfw.h:337
IOLFW_Config_t::isPru1FrameHandler
bool isPru1FrameHandler
Definition: iolfw.h:320
IOLFW_GpioPruConfig_t::gpio
IOLFW_GpioConfig_t gpio
Definition: iolfw.h:281
IOLFW_eTransferStatus_Overrun
@ IOLFW_eTransferStatus_Overrun
Definition: iolfw.h:247
IOLFW_eStartupStatus_NoResponse
@ IOLFW_eStartupStatus_NoResponse
Definition: iolfw.h:258
IOLFW_GpioEnConfig_t::gpioPhysAddr
uint32_t gpioPhysAddr
Definition: iolfw.h:294
IOLFW_cbGetPortCfg_t
const IOLFW_PortConfig_t *(* IOLFW_cbGetPortCfg_t)(IOLFW_Inst_t *pFwInstance, uint8_t portNum)
Get port configuration callback.
Definition: iolfw.h:350
IOLFW_resetCycleTime
int32_t IOLFW_resetCycleTime(IOLFW_Inst_t *pFwInstance, uint8_t port)
Reset cycle timer counter.
IOLFW_Inst_t::isPru1FrameHandler
bool isPru1FrameHandler
Definition: iolfw.h:209
IOLFW_registerSetModeCallback
void IOLFW_registerSetModeCallback(IOLFW_cbSetMode_t pCallback)
Register port mode change callback.
IOLFW_PortInst_t::pRxBuffer
uint8_t * pRxBuffer
Definition: iolfw.h:170
IOLFW_setMaxRespTime
int32_t IOLFW_setMaxRespTime(IOLFW_Inst_t *pFwInstance, uint8_t port, uint8_t taRespTime)
Set maximum response time.
IOLFW_eTransferStatus_ParityError
@ IOLFW_eTransferStatus_ParityError
Definition: iolfw.h:245
IOLFW_PortInst_t::mode
IOLFW_ePortMode_t mode
Definition: iolfw.h:167
IOLFW_eBaudrate_Com1
@ IOLFW_eBaudrate_Com1
Definition: iolfw.h:222
IOLFW_ePortMode_Sdci
@ IOLFW_ePortMode_Sdci
Definition: iolfw.h:153
IOLFW_PortInst_t::cycleTimerActive
bool cycleTimerActive
Definition: iolfw.h:172
IOLFW_GpioConfig_t
GPIO pin configuration.
Definition: iolfw.h:267
IOLFW_eInstanceState_Init
@ IOLFW_eInstanceState_Init
Definition: iolfw.h:185
IOLFW_Inst_t::state
IOLFW_eInstanceState_t state
Definition: iolfw.h:200
IOLFW_Inst_t::pruDram0
volatile IOLFW_PruMem_t * pruDram0
Definition: iolfw.h:204
IOLFW_eInstanceState_NotInitialized
@ IOLFW_eInstanceState_NotInitialized
Definition: iolfw.h:184
IOLFW_eBaudrate_t
IOLFW_eBaudrate_t
IO-Link transmission rate (baud rate)
Definition: iolfw.h:220
IOLFW_PortConfig_t::rx
IOLFW_GpioPruConfig_t rx
Definition: iolfw.h:306
IOLFW_SpCallbacks_t
Stack Porting Layer (SP) callbacks.
Definition: iolfw.h:419
IOLFW_registerRxErrEventCallback
void IOLFW_registerRxErrEventCallback(IOLFW_cbRxErrEvent_t pCallback)
Register RX error event callback.
IOLFW_GpioConfig_t::gpioBase
uint32_t gpioBase
Definition: iolfw.h:268
IOLFW_registerStartupCmplCallback
void IOLFW_registerStartupCmplCallback(IOLFW_cbStartupCmpl_t pCallback)
Register startup completion callback.
IOLFW_PortInst_t::awaitingRsp
uint8_t awaitingRsp
Definition: iolfw.h:171
IOLFW_init
int32_t IOLFW_init(IOLFW_Inst_t **pFwInstance, IOLFW_Config_t *pConfig)
Initialize IOLFW instance.
IOLFW_GpioConfig_t::gpioPin
uint32_t gpioPin
Definition: iolfw.h:269
IOLFW_eTransferStatus_Ok
@ IOLFW_eTransferStatus_Ok
Definition: iolfw.h:244
IOLFW_PruMemTimer_t
struct IOLFW_PruMemTimer IOLFW_PruMemTimer_t
Definition: iolfw.h:190
IOLFW_getBaudRate
IOLFW_eBaudrate_t IOLFW_getBaudRate(IOLFW_Inst_t *pFwInstance, uint8_t port)
Get current baud rate of port.
IOLFW_PlCallbacks_t::cbGetPortCfg
IOLFW_cbGetPortCfg_t cbGetPortCfg
Definition: iolfw.h:410
IOLFW_Inst_t
IOLFW instance handle.
Definition: iolfw.h:199
enable
@ enable
Definition: iPtcpDrv.h:69