AM64x MCU+ SDK  08.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 /* ========================================================================== */
37 /* Doxygen */
38 /* ========================================================================== */
39 
55 /* ========================================================================== */
56 /* Include Files */
57 /* ========================================================================== */
58 
59 #include "firmware/icss_pn_rtcx.h"
60 #include "PN_Handle.h"
61 
62 /* ========================================================================== */
63 /* Macros & Typedefs */
64 /* ========================================================================== */
65 
70 #define SHADOW_LIST 0
71 
75 #define ACTIVE_LIST 1
76 /* currently we support 8 PPM split into two blocks (NO_PPM/2)*/
77 #define HALFSIZE 4
78 
85 typedef enum
86 {
87  BUFF1 = 0,
90  NOBUFF
96 /* ========================================================================== */
97 /* Global Variables */
98 /* ========================================================================== */
99 uint32_t pRtcConfig;
100 uint32_t ocmcBaseAddress;
102 /* ========================================================================== */
103 /* Structure Declarations */
104 /* ========================================================================== */
125 typedef struct listIndex
126 {
127  uint8_t redP2;
128  uint8_t green;
129  uint8_t greenP2;
130  uint8_t end;
131 } t_listIndex;
132 
133 
138 typedef struct rtcMemBuff
139 {
140  uint8_t
141  *addr[3]; /*/< triple buffer start addresses - fixed after init - ARM view*/
142  uint16_t
143  regbase; /*/< 16 bit PRU base address of tripple buffer addresses - CPM only*/
144  uint8_t slotUsed; /*/< true if this slot is allocated*/
145 } t_rtcMemBuff;
146 
154 typedef struct ppmBlock
155 {
156  uint8_t
157  *blockStart; /*/< block start address (physical mem)*/
159  slots[HALFSIZE]; /*/< each buffer can have maximum of 4 slots*/
160 } t_ppmBlock;
161 
166 typedef struct cpmBlock
167 {
168  uint8_t
169  *blockStart; /*/< block start address (physical mem)*/
170  t_rtcMemBuff slots[NO_CPM]; /*/< single buffer takes all CPM*/
171 } t_cpmBlock;
172 
173 
177 typedef struct rtcPacket
178 {
179  uint32_t
180  frameOffset; /*/< frame send offset (0 indicates green PPM packet!)*/
181  t_rtcMemBuff *pBuffer; /*/< keep full buffer mem object pointer*/
182  uint16_t frameId; /*/< main identifier for all PPM/CPM*/
183  uint16_t length; /*/< length of packet (without space for CRC)*/
184  uint16_t reduRatio; /*/< reduction ratio (green or red)*/
185  uint16_t phase; /*/< assigned phase*/
186  uint8_t type; /*/< CPM or PPM packet*/
187  uint8_t port; /*/< where we want to sent to (PORT1 or PORT2)*/
188  uint8_t
189  crGroup; /*/< the group we belong too (1-8, 0 not defined)*/
190  uint8_t
191  lIndex; /*/< current index in descriptor list (0xFF = invalid)*/
192  uint8_t isActive; /*/< store activation state*/
193  uint8_t block; /*/< PPM only: store the buffer block number*/
194  uint8_t next; /*/< tripple buffer NEXT index*/
195  uint8_t last; /*/< tripple buffer LAST index*/
196  uint8_t validLast; /*/< new valid LAST buffer available (=1)*/
197  uint8_t
198  proc; /*/< tripple buffer PROC index -previously "buffIndex"*/
199  void *userRef; /*/< Reference for Application data"*/
200 } t_rtcPacket;
201 
206 typedef struct descList
207 {
208  uint32_t *pDescs[2];
209  uint8_t *rtc_index_ptr[2];
210  uint8_t
212  uint8_t
214  uint8_t *pEvent;
215  uint16_t redFID;
216  uint8_t size;
217  uint8_t shadow;
220  uint8_t mrpFlag;
221  uint8_t listToggleReq;
222 } t_descList;
223 
229 typedef struct cfgPN
230 {
232  cpmPkts[NO_CPM]; /*/< All CPM pkt config object internal to driver*/
234  ppmPkts[NO_PPM]; /*/< All PPM pkt config object internal to driver*/
235  uint16_t
236  maxCpmSize; /*/< maximum allowed data size for each CPM - incl overhead*/
237  uint16_t
238  maxPpmSize; /*/< maximum allowed data size for each PPM - incl overhead*/
239  uint8_t cfgAR; /*/< number of configured ARs*/
240 } t_cfgPN;
241 
242 /* ========================================================================== */
243 /* Function Declarations */
244 /* ========================================================================== */
245 
270 int32_t PN_cfgRtcMem(PN_Handle pnHandle, uint8_t ar, uint16_t size);
271 
277 int32_t PN_deCfgRtcMem(PN_Handle pnHandle);
278 
288 int32_t PN_initPacket(t_rtcPacket *pPkt, uint8_t type);
289 
301 int32_t PN_allocPkt(PN_Handle pnHandle, t_rtcPacket **pPkt, uint8_t type);
302 
311 int32_t PN_freePkt(t_rtcPacket *pPkt);
312 
327 int32_t PN_insPpmList(PN_Handle pnHandle, t_rtcPacket *ppmPkt, uint8_t legMode);
328 
341 int32_t PN_delPmList(PN_Handle pnHandle, t_rtcPacket *pmPkt);
342 
355 int32_t PN_insCpmList(PN_Handle pnHandle, t_rtcPacket *cpmPkt);
356 
369 int32_t PN_setCpmState(PN_Handle pnHandle, t_rtcPacket *pPkt, uint8_t val);
370 
382 int32_t PN_setPpmState(PRUICSS_HwAttrs const *pruicssHwAttrs,
383  t_rtcPacket *pPkt);
384 
394 int32_t PN_chgPpmBuffer(PN_Handle pnHandle, t_rtcPacket *ppmPkt);
395 
403 
411 typedef void (*pnCallBack_t)(void *arg, uint8_t arg2);
412 
425 int32_t PN_initRtcDrv(PN_Handle pnHandle);
426 
439 int32_t PN_getList(t_descList **pList, uint8_t dir);
440 
454 int32_t PN_clearList(PN_Handle pnHandle, uint8_t list);
455 
471 int32_t PN_resetARlink(PRUICSS_HwAttrs const *pruicssHwAttrs,
472  uint8_t ARgroup, uint8_t pmNum, uint8_t dir);
473 
497 int32_t PN_cpmBuffLock(PRUICSS_HwAttrs const *pruicssHwAttrs,
498  uint8_t pos, buffLocks buff);
499 
511 void PN_registerPpmCall(PN_Handle pnHandle, pnCallBack_t callBack);
512 
519 void PN_registerCpmCall(PN_Handle pnHandle, pnCallBack_t callBack);
520 
527 void PN_registerStatCall(PN_Handle pnHandle, pnCallBack_t callBack);
528 
534 typedef enum
535 {
539  ABORT
549 typedef void (*pnLegCallBack_t)(void *arg, void *arg2);
550 
562 
572 void PN_registerSetPkt(PN_Handle pnHandle, pnLegCallBack_t callBack);
584 void PN_clearPruIRQ(PRUICSS_HwAttrs const *pruicssHwAttrs,
585  uint8_t irq_num); /* event clearing*/
586 
587 
598 int32_t PN_setBaseClock(PN_Handle pnHandle, uint16_t factor);
599 
602 #endif /* IRTCDRV2_H_ */
t_cfgPN::maxPpmSize
uint16_t maxPpmSize
Definition: iRtcDrv2.h:238
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:214
t_rtcPacket::next
uint8_t next
Definition: iRtcDrv2.h:194
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)
size
uint16_t size
Definition: tisci_boardcfg.h:1
t_descList::size
uint8_t size
Definition: iRtcDrv2.h:216
PN_getConfig
t_cfgPN * PN_getConfig(void)
t_listIndex::redP2
uint8_t redP2
Definition: iRtcDrv2.h:127
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:191
pnLegCallBack_t
void(* pnLegCallBack_t)(void *arg, void *arg2)
Callback function for processing Profinet IRQs.
Definition: iRtcDrv2.h:549
PN_Handle
struct PN_Config_s * PN_Handle
Alias for Profinet Handle containing base addresses and modules.
Definition: PN_Handle.h:96
t_rtcPacket::proc
uint8_t proc
Definition: iRtcDrv2.h:198
BUFF2
@ BUFF2
Definition: iRtcDrv2.h:88
buffLocks
buffLocks
Enumerates the Buffer indexes of Triple buffers. Buffer lock needs to be aligned with firmware.
Definition: iRtcDrv2.h:86
NOINIT
@ NOINIT
Definition: iRtcDrv2.h:536
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:220
t_listIndex
Definition: iRtcDrv2.h:126
BUFF3
@ BUFF3
Definition: iRtcDrv2.h:89
t_ppmBlock
Definition: iRtcDrv2.h:155
t_cpmBlock::blockStart
uint8_t * blockStart
Definition: iRtcDrv2.h:169
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:239
SENDPPM
@ SENDPPM
Definition: iRtcDrv2.h:538
PN_registerPpmCall
void PN_registerPpmCall(PN_Handle pnHandle, pnCallBack_t callBack)
Registers callback function required for PPM processing.
type
uint16_t type
Definition: tisci_rm_core.h:1
t_listIndex::end
uint8_t end
Definition: iRtcDrv2.h:130
t_rtcMemBuff::regbase
uint16_t regbase
Definition: iRtcDrv2.h:143
t_descList
Definition: iRtcDrv2.h:207
t_descList::shadow
uint8_t shadow
Definition: iRtcDrv2.h:217
t_rtcPacket::frameId
uint16_t frameId
Definition: iRtcDrv2.h:182
t_descList::redFID
uint16_t redFID
Definition: iRtcDrv2.h:215
t_descList::lInitiate
t_rtcPacket * lInitiate
Definition: iRtcDrv2.h:219
t_rtcMemBuff
Definition: iRtcDrv2.h:139
NOBUFF
@ NOBUFF
Definition: iRtcDrv2.h:90
tLegStates
tLegStates
possible states for legacy suppport state machine
Definition: iRtcDrv2.h:535
t_cfgPN::maxCpmSize
uint16_t maxCpmSize
Definition: iRtcDrv2.h:236
addr
uint64_t addr
Definition: csl_udmap_tr.h:3
t_rtcMemBuff::slotUsed
uint8_t slotUsed
Definition: iRtcDrv2.h:144
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:60
PN_chgPpmBuffer
int32_t PN_chgPpmBuffer(PN_Handle pnHandle, t_rtcPacket *ppmPkt)
Update PPM descriptor to new buffer address (based on ARM buffer address)
t_listIndex::green
uint8_t green
Definition: iRtcDrv2.h:128
t_rtcPacket::isActive
uint8_t isActive
Definition: iRtcDrv2.h:192
READY
@ READY
Definition: iRtcDrv2.h:537
PRUICSS_HwAttrs
PRUICSS Hardware Attributes.
Definition: pruicss/g_v0/pruicss.h:334
t_rtcPacket::phase
uint16_t phase
Definition: iRtcDrv2.h:185
HALFSIZE
#define HALFSIZE
Definition: iRtcDrv2.h:77
t_rtcPacket::last
uint8_t last
Definition: iRtcDrv2.h:195
t_rtcPacket::validLast
uint8_t validLast
Definition: iRtcDrv2.h:196
PN_Handle.h
PN_getList
int32_t PN_getList(t_descList **pList, uint8_t dir)
t_rtcPacket::frameOffset
uint32_t frameOffset
Definition: iRtcDrv2.h:180
NO_CPM
#define NO_CPM
Definition: icss_pn_rtcx.h:61
PN_clearList
int32_t PN_clearList(PN_Handle pnHandle, uint8_t list)
t_rtcPacket::crGroup
uint8_t crGroup
Definition: iRtcDrv2.h:189
t_rtcPacket::type
uint8_t type
Definition: iRtcDrv2.h:186
t_descList::pStatus
uint8_t * pStatus
Definition: iRtcDrv2.h:213
PN_setCpmState
int32_t PN_setCpmState(PN_Handle pnHandle, t_rtcPacket *pPkt, uint8_t val)
ABORT
@ ABORT
Definition: iRtcDrv2.h:539
t_rtcPacket::block
uint8_t block
Definition: iRtcDrv2.h:193
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:184
t_listIndex::greenP2
uint8_t greenP2
Definition: iRtcDrv2.h:129
PN_clearPruIRQ
void PN_clearPruIRQ(PRUICSS_HwAttrs const *pruicssHwAttrs, uint8_t irq_num)
t_rtcPacket::port
uint8_t port
Definition: iRtcDrv2.h:187
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:178
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:157
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:221
t_cfgPN
Definition: iRtcDrv2.h:230
BUFF1
@ BUFF1
Definition: iRtcDrv2.h:87
ocmcBaseAddress
uint32_t ocmcBaseAddress
Definition: iRtcDrv2.h:100
t_rtcPacket::userRef
void * userRef
Definition: iRtcDrv2.h:199
pnCallBack_t
void(* pnCallBack_t)(void *arg, uint8_t arg2)
Callback function for processing Profinet IRQs.
Definition: iRtcDrv2.h:411
t_cpmBlock
Definition: iRtcDrv2.h:167
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:99
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:183
t_descList::pActive
uint8_t * pActive
Definition: iRtcDrv2.h:211
t_rtcPacket::pBuffer
t_rtcMemBuff * pBuffer
Definition: iRtcDrv2.h:181