AM243x INDUSTRIAL COMMUNICATIONS SDK  09.02.00
iRtcDrv2.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef IRTCDRV2_H_
34 #define IRTCDRV2_H_
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 
42 /* ========================================================================== */
43 /* Doxygen */
44 /* ========================================================================== */
45 
61 /* ========================================================================== */
62 /* Include Files */
63 /* ========================================================================== */
64 
65 #include "firmware/icss_pn_rtcx.h"
66 #include "PN_Handle.h"
67 
68 /* ========================================================================== */
69 /* Macros & Typedefs */
70 /* ========================================================================== */
71 
76 #define SHADOW_LIST 0
77 
81 #define ACTIVE_LIST 1
82 /* currently we support 8 PPM split into two blocks (NO_PPM/2)*/
83 #define HALFSIZE 4
84 
91 typedef enum
92 {
93  BUFF1 = 0,
96  NOBUFF
102 /* ========================================================================== */
103 /* Global Variables */
104 /* ========================================================================== */
105 uint32_t pRtcConfig;
106 uint32_t ocmcBaseAddress;
108 /* ========================================================================== */
109 /* Structure Declarations */
110 /* ========================================================================== */
131 typedef struct listIndex
132 {
133  uint8_t redP2;
134  uint8_t green;
135  uint8_t greenP2;
136  uint8_t end;
137 } t_listIndex;
138 
139 
144 typedef struct rtcMemBuff
145 {
146  uint8_t
147  *addr[3]; /*/< triple buffer start addresses - fixed after init - ARM view*/
148  uint16_t
149  regbase; /*/< 16 bit PRU base address of tripple buffer addresses - CPM only*/
150  uint8_t slotUsed; /*/< true if this slot is allocated*/
151 } t_rtcMemBuff;
152 
160 typedef struct ppmBlock
161 {
162  uint8_t
163  *blockStart; /*/< block start address (physical mem)*/
165  slots[HALFSIZE]; /*/< each buffer can have maximum of 4 slots*/
166 } t_ppmBlock;
167 
172 typedef struct cpmBlock
173 {
174  uint8_t
175  *blockStart; /*/< block start address (physical mem)*/
176  t_rtcMemBuff slots[NO_CPM]; /*/< single buffer takes all CPM*/
177 } t_cpmBlock;
178 
179 
183 typedef struct rtcPacket
184 {
185  uint32_t
186  frameOffset; /*/< frame send offset (0 indicates green PPM packet!)*/
187  t_rtcMemBuff *pBuffer; /*/< keep full buffer mem object pointer*/
188  uint16_t frameId; /*/< main identifier for all PPM/CPM*/
189  uint16_t length; /*/< length of packet (without space for CRC)*/
190  uint16_t reduRatio; /*/< reduction ratio (green or red)*/
191  uint16_t phase; /*/< assigned phase*/
192  uint8_t type; /*/< CPM or PPM packet*/
193  uint8_t port; /*/< where we want to sent to (PORT1 or PORT2)*/
194  uint8_t
195  crGroup; /*/< the group we belong too (1-8, 0 not defined)*/
196  uint8_t
197  lIndex; /*/< current index in descriptor list (0xFF = invalid)*/
198  uint8_t isActive; /*/< store activation state*/
199  uint8_t block; /*/< PPM only: store the buffer block number*/
200  uint8_t next; /*/< tripple buffer NEXT index*/
201  uint8_t last; /*/< tripple buffer LAST index*/
202  uint8_t validLast; /*/< new valid LAST buffer available (=1)*/
203  uint8_t
204  proc; /*/< tripple buffer PROC index -previously "buffIndex"*/
205  void *userRef; /*/< Reference for Application data"*/
206 } t_rtcPacket;
207 
212 typedef struct descList
213 {
214  uint32_t *pDescs[2];
215  uint8_t *rtc_index_ptr[2];
216  uint8_t
218  uint8_t
220  uint8_t *pEvent;
221  uint16_t redFID;
222  uint8_t size;
223  uint8_t shadow;
226  uint8_t mrpFlag;
227  uint8_t listToggleReq;
228 } t_descList;
229 
235 typedef struct cfgPN
236 {
238  cpmPkts[NO_CPM]; /*/< All CPM pkt config object internal to driver*/
240  ppmPkts[NO_PPM]; /*/< All PPM pkt config object internal to driver*/
241  uint16_t
242  maxCpmSize; /*/< maximum allowed data size for each CPM - incl overhead*/
243  uint16_t
244  maxPpmSize; /*/< maximum allowed data size for each PPM - incl overhead*/
245  uint8_t cfgAR; /*/< number of configured ARs*/
246 } t_cfgPN;
247 
248 /* ========================================================================== */
249 /* Function Declarations */
250 /* ========================================================================== */
251 
276 int32_t PN_cfgRtcMem(PN_Handle pnHandle, uint8_t ar, uint16_t size);
277 
283 int32_t PN_deCfgRtcMem(PN_Handle pnHandle);
284 
294 int32_t PN_initPacket(t_rtcPacket *pPkt, uint8_t type);
295 
307 int32_t PN_allocPkt(PN_Handle pnHandle, t_rtcPacket **pPkt, uint8_t type);
308 
317 int32_t PN_freePkt(t_rtcPacket *pPkt);
318 
333 int32_t PN_insPpmList(PN_Handle pnHandle, t_rtcPacket *ppmPkt, uint8_t legMode);
334 
347 int32_t PN_delPmList(PN_Handle pnHandle, t_rtcPacket *pmPkt);
348 
361 int32_t PN_insCpmList(PN_Handle pnHandle, t_rtcPacket *cpmPkt);
362 
375 int32_t PN_setCpmState(PN_Handle pnHandle, t_rtcPacket *pPkt, uint8_t val);
376 
388 int32_t PN_setPpmState(PRUICSS_HwAttrs const *pruicssHwAttrs,
389  t_rtcPacket *pPkt);
390 
400 int32_t PN_chgPpmBuffer(PN_Handle pnHandle, t_rtcPacket *ppmPkt);
401 
409 
417 typedef void (*pnCallBack_t)(void *arg, uint8_t arg2);
418 
431 int32_t PN_initRtcDrv(PN_Handle pnHandle);
432 
445 int32_t PN_getList(t_descList **pList, uint8_t dir);
446 
460 int32_t PN_clearList(PN_Handle pnHandle, uint8_t list);
461 
477 int32_t PN_resetARlink(PRUICSS_HwAttrs const *pruicssHwAttrs,
478  uint8_t ARgroup, uint8_t pmNum, uint8_t dir);
479 
503 int32_t PN_cpmBuffLock(PRUICSS_HwAttrs const *pruicssHwAttrs,
504  uint8_t pos, buffLocks buff);
505 
517 void PN_registerPpmCall(PN_Handle pnHandle, pnCallBack_t callBack);
518 
525 void PN_registerCpmCall(PN_Handle pnHandle, pnCallBack_t callBack);
526 
533 void PN_registerStatCall(PN_Handle pnHandle, pnCallBack_t callBack);
534 
540 typedef enum
541 {
545  ABORT
555 typedef void (*pnLegCallBack_t)(void *arg, void *arg2);
556 
557 typedef void (*pnDrvThreadSafe_t)(void);
558 
559 
571 
581 void PN_registerSetPkt(PN_Handle pnHandle, pnLegCallBack_t callBack);
594 
595 
602 void PN_clearPruIRQ(PRUICSS_HwAttrs const *pruicssHwAttrs,
603  uint8_t irq_num); /* event clearing*/
604 
605 
616 int32_t PN_setBaseClock(PN_Handle pnHandle, uint16_t factor);
617 
626 void PN_setFSODeviationComp(PRUICSS_HwAttrs const *pruicssHwAttrs, uint16_t fso_comp_val);
627 
628 
629 #ifdef __cplusplus
630 }
631 #endif
632 
633 #endif /* IRTCDRV2_H_ */
t_cfgPN::maxPpmSize
uint16_t maxPpmSize
Definition: iRtcDrv2.h:244
PN_freePkt
int32_t PN_freePkt(t_rtcPacket *pPkt)
Free a packet object for re-use Utility API for stack. Doesn't update anything in driver.
PN_allocPkt
int32_t PN_allocPkt(PN_Handle pnHandle, t_rtcPacket **pPkt, uint8_t type)
Allocate a packet object from internal array Initializes pPkt with PN_initPacket Find the next freesl...
t_descList::pEvent
uint8_t * pEvent
Definition: iRtcDrv2.h:220
t_rtcPacket::next
uint8_t next
Definition: iRtcDrv2.h:200
PN_setBaseClock
int32_t PN_setBaseClock(PN_Handle pnHandle, uint16_t factor)
Sets Profinet base clock in multiples of 31.25us.
PN_resetARlink
int32_t PN_resetARlink(PRUICSS_HwAttrs const *pruicssHwAttrs, uint8_t ARgroup, uint8_t pmNum, uint8_t dir)
t_descList::size
uint8_t size
Definition: iRtcDrv2.h:222
PN_getConfig
t_cfgPN * PN_getConfig(void)
t_listIndex::redP2
uint8_t redP2
Definition: iRtcDrv2.h:133
PN_insPpmList
int32_t PN_insPpmList(PN_Handle pnHandle, t_rtcPacket *ppmPkt, uint8_t legMode)
Inserts PPM descriptor data into the lists.
t_rtcPacket::lIndex
uint8_t lIndex
Definition: iRtcDrv2.h:197
pnLegCallBack_t
void(* pnLegCallBack_t)(void *arg, void *arg2)
Callback function for processing Profinet IRQs.
Definition: iRtcDrv2.h:555
PN_Handle
struct PN_Config_s * PN_Handle
Alias for Profinet Handle containing base addresses and modules.
Definition: PN_Handle.h:102
t_rtcPacket::proc
uint8_t proc
Definition: iRtcDrv2.h:204
BUFF2
@ BUFF2
Definition: iRtcDrv2.h:94
buffLocks
buffLocks
Enumerates the Buffer indexes of Triple buffers. Buffer lock needs to be aligned with firmware.
Definition: iRtcDrv2.h:92
pnDrvThreadSafe_t
void(* pnDrvThreadSafe_t)(void)
Definition: iRtcDrv2.h:557
NOINIT
@ NOINIT
Definition: iRtcDrv2.h:542
PN_registerStatCall
void PN_registerStatCall(PN_Handle pnHandle, pnCallBack_t callBack)
Registers callback function required for Stat processing.
t_descList::mrpFlag
uint8_t mrpFlag
Definition: iRtcDrv2.h:226
t_listIndex
Definition: iRtcDrv2.h:132
BUFF3
@ BUFF3
Definition: iRtcDrv2.h:95
t_ppmBlock
Definition: iRtcDrv2.h:161
t_cpmBlock::blockStart
uint8_t * blockStart
Definition: iRtcDrv2.h:175
PN_cpmBuffLock
int32_t PN_cpmBuffLock(PRUICSS_HwAttrs const *pruicssHwAttrs, uint8_t pos, buffLocks buff)
Locks CPM Buffer indicating that ARM is consuming the particular buffer. PRU cannot write to this buf...
t_cfgPN::cfgAR
uint8_t cfgAR
Definition: iRtcDrv2.h:245
SENDPPM
@ SENDPPM
Definition: iRtcDrv2.h:544
PN_registerPpmCall
void PN_registerPpmCall(PN_Handle pnHandle, pnCallBack_t callBack)
Registers callback function required for PPM processing.
t_listIndex::end
uint8_t end
Definition: iRtcDrv2.h:136
t_rtcMemBuff::regbase
uint16_t regbase
Definition: iRtcDrv2.h:149
t_descList
Definition: iRtcDrv2.h:213
t_descList::shadow
uint8_t shadow
Definition: iRtcDrv2.h:223
t_rtcPacket::frameId
uint16_t frameId
Definition: iRtcDrv2.h:188
t_descList::redFID
uint16_t redFID
Definition: iRtcDrv2.h:221
t_descList::lInitiate
t_rtcPacket * lInitiate
Definition: iRtcDrv2.h:225
t_rtcMemBuff
Definition: iRtcDrv2.h:145
NOBUFF
@ NOBUFF
Definition: iRtcDrv2.h:96
tLegStates
tLegStates
possible states for legacy suppport state machine
Definition: iRtcDrv2.h:541
t_cfgPN::maxCpmSize
uint16_t maxCpmSize
Definition: iRtcDrv2.h:242
t_rtcMemBuff::slotUsed
uint8_t slotUsed
Definition: iRtcDrv2.h:150
PN_registerCpmCall
void PN_registerCpmCall(PN_Handle pnHandle, pnCallBack_t callBack)
Registers callback function required for CPM processing.
NO_PPM
#define NO_PPM
Definition: icss_pn_rtcx.h:66
PN_chgPpmBuffer
int32_t PN_chgPpmBuffer(PN_Handle pnHandle, t_rtcPacket *ppmPkt)
Update PPM descriptor to new buffer address (based on ARM buffer address)
PN_setFSODeviationComp
void PN_setFSODeviationComp(PRUICSS_HwAttrs const *pruicssHwAttrs, uint16_t fso_comp_val)
Sets FSO deviation compensation value for propogation delays inside ICSS.
t_listIndex::green
uint8_t green
Definition: iRtcDrv2.h:134
t_rtcPacket::isActive
uint8_t isActive
Definition: iRtcDrv2.h:198
READY
@ READY
Definition: iRtcDrv2.h:543
t_rtcPacket::phase
uint16_t phase
Definition: iRtcDrv2.h:191
HALFSIZE
#define HALFSIZE
Definition: iRtcDrv2.h:83
t_rtcPacket::last
uint8_t last
Definition: iRtcDrv2.h:201
t_rtcPacket::validLast
uint8_t validLast
Definition: iRtcDrv2.h:202
PN_Handle.h
PN_getList
int32_t PN_getList(t_descList **pList, uint8_t dir)
t_rtcPacket::frameOffset
uint32_t frameOffset
Definition: iRtcDrv2.h:186
NO_CPM
#define NO_CPM
Definition: icss_pn_rtcx.h:67
PN_clearList
int32_t PN_clearList(PN_Handle pnHandle, uint8_t list)
t_rtcPacket::crGroup
uint8_t crGroup
Definition: iRtcDrv2.h:195
t_rtcPacket::type
uint8_t type
Definition: iRtcDrv2.h:192
t_descList::pStatus
uint8_t * pStatus
Definition: iRtcDrv2.h:219
PN_setCpmState
int32_t PN_setCpmState(PN_Handle pnHandle, t_rtcPacket *pPkt, uint8_t val)
ABORT
@ ABORT
Definition: iRtcDrv2.h:545
t_rtcPacket::block
uint8_t block
Definition: iRtcDrv2.h:199
PN_initPacket
int32_t PN_initPacket(t_rtcPacket *pPkt, uint8_t type)
Initialize packet according to type Utility API for stack. Doesn't update anything in driver.
t_rtcPacket::reduRatio
uint16_t reduRatio
Definition: iRtcDrv2.h:190
PN_registerThreadsafeFunc
void PN_registerThreadsafeFunc(PN_Handle pnHandle, pnDrvThreadSafe_t callBackEnt, pnDrvThreadSafe_t callBackExt)
Registers callback function for thread safety functionality. This callback is used in a critical sect...
t_listIndex::greenP2
uint8_t greenP2
Definition: iRtcDrv2.h:135
PN_clearPruIRQ
void PN_clearPruIRQ(PRUICSS_HwAttrs const *pruicssHwAttrs, uint8_t irq_num)
t_rtcPacket::port
uint8_t port
Definition: iRtcDrv2.h:193
icss_pn_rtcx.h
PN_deCfgRtcMem
int32_t PN_deCfgRtcMem(PN_Handle pnHandle)
De-configures the driver memory.
t_rtcPacket
real-time packet structure
Definition: iRtcDrv2.h:184
PN_delPmList
int32_t PN_delPmList(PN_Handle pnHandle, t_rtcPacket *pmPkt)
Deletes a descriptor from PPM or CPM list.
t_ppmBlock::blockStart
uint8_t * blockStart
Definition: iRtcDrv2.h:163
PN_registerSetState
void PN_registerSetState(PN_Handle pnHandle, pnLegCallBack_t callBack)
Registers callback function for legacy state This callback is used to change the Legacy state machine...
t_descList::listToggleReq
uint8_t listToggleReq
Definition: iRtcDrv2.h:227
t_cfgPN
Definition: iRtcDrv2.h:236
BUFF1
@ BUFF1
Definition: iRtcDrv2.h:93
ocmcBaseAddress
uint32_t ocmcBaseAddress
Definition: iRtcDrv2.h:106
t_rtcPacket::userRef
void * userRef
Definition: iRtcDrv2.h:205
pnCallBack_t
void(* pnCallBack_t)(void *arg, uint8_t arg2)
Callback function for processing Profinet IRQs.
Definition: iRtcDrv2.h:417
t_cpmBlock
Definition: iRtcDrv2.h:173
PN_insCpmList
int32_t PN_insCpmList(PN_Handle pnHandle, t_rtcPacket *cpmPkt)
Insert a packet into descriptor list and lock this buffer, indicating that ARM is consuming this buff...
pRtcConfig
uint32_t pRtcConfig
Definition: iRtcDrv2.h:105
PN_initRtcDrv
int32_t PN_initRtcDrv(PN_Handle pnHandle)
Initializes RTC driver.
PN_cfgRtcMem
int32_t PN_cfgRtcMem(PN_Handle pnHandle, uint8_t ar, uint16_t size)
Configures the driver memory.
PN_registerSetPkt
void PN_registerSetPkt(PN_Handle pnHandle, pnLegCallBack_t callBack)
Registers callback function for packet pointer This callback is used to configure the packet send by ...
PN_setPpmState
int32_t PN_setPpmState(PRUICSS_HwAttrs const *pruicssHwAttrs, t_rtcPacket *pPkt)
t_rtcPacket::length
uint16_t length
Definition: iRtcDrv2.h:189
t_descList::pActive
uint8_t * pActive
Definition: iRtcDrv2.h:217
t_rtcPacket::pBuffer
t_rtcMemBuff * pBuffer
Definition: iRtcDrv2.h:187