AM64x MCU+ SDK  08.02.00
icss_pn_rtcx.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 //*****************************************************************************/
34 // file: icss_pn_rtcx.h
35 //
36 // brief: Definitions and mapping of Profinet cyclic data exchange for RT and IRT
37 // Includes:
38 // 1. Sendlist and Receivelist with shadow operation
39 // 2. Descriptors in lists for cyclic data exchange
40 // 3. Configuration for cyclic data exchange and start-up
41 // 4. Configuration for IRT phase management
42 // 5. Parameter exchange between host and PRU for time sync
43 // 6. Events for cyclic data exchange
44 //
45 
46 #ifndef __ICSS_PN_RTCX__
47 #define __ICSS_PN_RTCX__
48 
49 // Target switches: PRU / ARM
50 // Protocol switches: PROFINET , PN_IOD, PN_IOC
51 //
52 // Global settings
53 
54 #ifndef PN_IOD
55 #define PN_IOD
56 #endif
57 
58 // IOD Definitions
59 #ifdef PN_IOD
60  #define NO_PPM 8
61  #define NO_CPM 8
62  #define NO_PM 8 // FW driver uses this number for CPM/PPM size!
63  #define NO_AR 8
64 #else
65 // IOC definitions
66  #define NO_PPM 256
67  #define NO_CPM 256
68  #define NO_AR 256
69 #endif
70 
71 // CONSTANT ARE DEFINED HERE
72 // Yellow safety margin is 640 ns.
73 #define YELLOW_SAFETY_MARGIN 0x0280
74 #define DCP_IDENTREQ_FRAMEID 0xfefe
75 #define DCP_NAME_CMP_NO_OF_CHAR 8
76 // offset of the first character of dcp name in incoming dcp frame assuming it is in R2 register.
77 #define DCP_NAME_FRAME_PTR_OFFSET 0x8
78 // offset of the first character of the set of "last eight characters" of slave name assuming it is read in R10 register
79 #define DCP_NAME_SLAVE_PTR_OFFSET 0x28
80 
81 #define RTC_3125_CLK_CONST 0x7A12 // const for 31.25us cycle
82 
83 #define MAX_BRIDGE_DELAY 3020 // 2920 + 100ns
84 
85 #define RTC3_PPM_FIFO_PUSH_MARGIN 6720
86 
87 // Common scratch pad usage for CPM DHT in bank0
88 // r29.t0 indicates critical section of DHT updates in pn_rtc1_schedule
89 // when set to 1 indicates that DHT cannot be modified in pn_rtc1_receive
90 // when set to 0 indicates DHT can be overwritten. The critical section needs to consider
91 // latency of SBCO command which is like a 2-1-1-1 burst for 16 bytes of DHT update.
92 
93 #define PN_CRITICAL_DHT_REG R29.b0
94 #define PN_CRITICAL_DHT_FLAG t0
95 
96 // Sendlist (PPMs) and Receivelist (CPMs)
97 //
98 // Cyclic data is exchanged using separate lists for send and receive. For dynamic handling of connections there is a shadow
99 // list which can be prepared by host while active list is processed by PRU on send and receive. There is an index in
100 // RTC_CPM_INDEX and RTC_PPM_INDEX indicating which list is active.
101 // Each list is pre-sorted by period, port and time. The index for period and port is also given in index register.
102 // Index register: entries in this register are position in list (0-7) * 12 bytes. Simplifies PRU code as *12 is not easily done
103 // with shift.
104 //
105 
106 // RTC_CPM_INDEX_L1/2 / RTC_PPM_INDEX_L1/2
107 // Bit Name Description
108 //
109 
110 // 0..7 RTC_RED_PORT_IDX points to first port 2 descriptor in red period
111 // 8..15 RTC_GREEN_IDX points to first descriptor of green period,
112 // 16..23 RTC_GREEN_PORT_IDX points to first port 2 descriptor in green period
113 // 24..31 RTC_GREEN_END_IDX points to last descriptor of green period
114 
115 // RTC_LIST_INDEX_OFFSET
116 // Bit Name Description
117 // 0 RTC_CPM_IDX_PRU Index which CPM list is used. 0 = list 1, 1 = list 2
118 // 1 RTC_PPM_IDX_PRU
119 // 8 RTC_CPM_IDX_HOST Index which PPM list is used. 0 = list 1, 1 = list 2
120 // 9 RTC_PPM_IDX_HOST
121 
122 // All the following offsets are applied to RTC_CONFIG_OFFSET which is after PPM_LIST on PRU0 DMEM.
123 // 8 bytes for DHT expire source. Each CPM has one byte to indicate if it's DHT expired
124 
125 #define RTC_NOTIFY_DHT_EXPIRE_OFFSET 0x10 // 8 bytes
126 
127 #define RTC_PPM_INDEX_L1_OFFSET RTC_NOTIFY_DHT_EXPIRE_OFFSET +8
128 #define RTC_PPM_INDEX_L2_OFFSET RTC_PPM_INDEX_L1_OFFSET + 4
129 #define RTC_LIST_INDEX_OFFSET RTC_PPM_INDEX_L2_OFFSET + 4
130 
131 
132 #ifdef PRU
133 #define RTC_RED_PORT_IDX b0
134 #define RTC_GREEN_IDX b1
135 #define RTC_GREEN_PORT_IDX b2
136 #define RTC_GREEN_END_IDX b3
137 // there is only one pru writing to this field at different times - assumes CPM and PPM are on same port.
138 #define RTC_CPM_IDX_PRU t0 // host read, pru write
139 #define RTC_PPM_IDX_PRU t1 // host read, pru write
140 
141 #define RTC_CPM_IDX_HOST t8 // host write, pru read
142 #define RTC_PPM_IDX_HOST t9 // host write, pru read
143 #else
144 #define RTC_RED_PORT_IDX 0
145 #define RTC_GREEN_IDX 1 // byte offset to rtc_index_ptr
146 #define RTC_GREEN_PORT_IDX 2
147 #define RTC_GREEN_END_IDX 3
148 #endif
149 
150 // directions - make sure all lists are using this defines
151 #define CPM 0
152 #define PPM 1
153 
154 // CRITICAL mapping from 0x0012 to 0x0020 which allows for single PRU reads of CPM and PPM configuration
155 
156 // CPM monitoring has activation bit which needs to be set per CPM.
157 // PPM is removed on CPM failure. This function is also activated.
158 // when RTC_CPM_ACTIVE_x bit is set then monitoring of incoming packet is activated including DHT
159 // when RTC_PPM_ACTIVE_x bit is set then PPM is stopped on corresponding CPM error.
160 // This is for IOD only. IOC needs 256 bits per direction.
161 
162 #define RTC_CPM_ACTIVE_OFFSET RTC_LIST_INDEX_OFFSET + 2
163 
164 #ifdef PRU
165 #define RTC_CPM_ACTIVE_1 t0
166 #define RTC_CPM_ACTIVE_2 t1
167 #define RTC_CPM_ACTIVE_3 t2
168 #define RTC_CPM_ACTIVE_4 t3
169 #define RTC_CPM_ACTIVE_5 t4
170 #define RTC_CPM_ACTIVE_6 t5
171 #define RTC_CPM_ACTIVE_7 t6
172 #define RTC_CPM_ACTIVE_8 t7
173 #define RTC_PPM_ACTIVE_1 t0
174 #define RTC_PPM_ACTIVE_2 t1
175 #define RTC_PPM_ACTIVE_3 t2
176 #define RTC_PPM_ACTIVE_4 t3
177 #define RTC_PPM_ACTIVE_5 t4
178 #define RTC_PPM_ACTIVE_6 t5
179 #define RTC_PPM_ACTIVE_7 t6
180 #define RTC_PPM_ACTIVE_8 t7
181 #endif
182 
183 // CPM/PPM STATUS
184 // consumer and provider can be of status ERROR or OK/RUN. For this one bit per connection is reserved in
185 // Status register for CPM and PPM.
186 #define RTC_PPM_OK 1
187 #define RTC_PPM_ERROR 0
188 #define RTC_CPM_RUN 1
189 #define RTC_CPM_FAILURE 0
190 #define RTC_CPM_STATUS_OFFSET RTC_CPM_ACTIVE_OFFSET + 1
191 #define RTC_PPM_STATUS_OFFSET RTC_CPM_STATUS_OFFSET + 2
192 
193 #define RTC_EXECUTE_DHT_CODE RTC_PPM_STATUS_OFFSET + 2
194 
195 // PPM_SEND_STATUS is defined as
196 // 0 = PPM not sent
197 // 0xFF = PPM descriptor not yet read from PRU b
198 // 0x10 = PPM send active (PRU is transferring packet from PPM buffer to MII TX fifo)
199 // 0x20 = PPM send complete (PRU has pushed last bytes of packet into MII TX fifo)
200 // state transitions:
201 // 0 -> 1 : PRU sets to one at the beginning of PPM send, host does not write to PPM_SEND_STATUS when value is 0 or 1
202 // 1 -> 2 : PRU sets to two at the end of PPM send. host can now reset to 0
203 // 2 -> 0 : host received interrupt or polls state and sees a value of 2. Host then resets state to 0
204 // 2 -> 1 : in case host did not see last packet send complete and PRU needs to send another packet.
205 // all other transitions are not defined. Normal sequence is 0 -> 1 -> 2 -> 0.
206 
207 #define RTC_PPM_SEND_STATUS_OFFSET RTC_EXECUTE_DHT_CODE + 1 // 8 bytes ... 1 byte for each PPM
208 
209 // Buffer locked indication for CPM index indicated to consumer is locked, provider will not overwrite until cleared
210 // CPM: one byte per CPM set and cleared by host, 00 = buffer 1, 01 = buffer 2, 02 = buffer 3, 03 = no locked
211 
212 // moved to free space as it is now 1 byte per CPM.
213 #define RTC_CPM_BUFFER_LOCK_OFFSET 0x30 //RTC_PPM_SEND_STATUS_OFFSET + 8 // 8 bytes ... 1 byte for each CPM
214 
215 // Register to indicate fdb_flush mode - 1 byte. 0 = not active, 1 - fdb_flush mode active
216 #define RTC_MRP_FDB_FLUSH_OFFSET RTC_CPM_BUFFER_LOCK_OFFSET + 9
217 
218 // Base clock is used to schedule provider data in RT and IRT. For RT there is a min base clock of 250us.
219 // RTC_IRT_BASE_CLK: is multiplier of 31.25 us (default = 8 which corresponds to 250 us base clock)
220 // Base clock is given as a shift value as send_clock_factor is power of 2. E.g. value of 3 in this field
221 // means send_clock_Factor of 8 = 250 us base clock. Value of 5 provides 1 ms base clock.
222 
223 #define PRU0_PHASE_EVENT_OFFSET RTC_MRP_FDB_FLUSH_OFFSET + 1 // 8 bit to separate writes
224 #define PRU1_PHASE_EVENT_OFFSET PRU0_PHASE_EVENT_OFFSET + 1
225 
226 #define RTC_PHASE_COUNTER_OFFSET PRU1_PHASE_EVENT_OFFSET + 3 // 16 bit for phase counter
227 #define RTC_SEND_LIST_P1_OFFSET RTC_PHASE_COUNTER_OFFSET + 2
228 #define RTC_SEND_LIST_P2_OFFSET RTC_SEND_LIST_P1_OFFSET + 8
229 
230 // SCF = send clock factor is power of 2. Up to 4096 (128ms) with RTC1 and 32 (1ms)with RTC3
231 // RTC_SCF and RTC_CYLE_COUNTER need to be next to each other as used with single LBCO!!!
232 
233 #define RTC_SCF_OFFSET RTC_SEND_LIST_P2_OFFSET + 8
234 #define RTC_CYCLE_COUNTER_OFFSET RTC_SCF_OFFSET + 2
235 #define RTC_BASE_CLK_OFFSET RTC_CYCLE_COUNTER_OFFSET + 2
236 #define PTCP_ABS_COUNTER_OFFSET RTC_BASE_CLK_OFFSET + 4 // moved here for optimization
237 
238 // RTC3 frames need to check for valid FRAME ID range also called red guard
239 // FID is 16 bit
240 #define RTC3_SOF_RedFrameID_OFFSET 0x5c//PTCP_ABS_COUNTER_OFFSET + 4
241 #define RTC3_EOF_RedFrameID_OFFSET RTC3_SOF_RedFrameID_OFFSET + 2
242 
243 #define RTC_DEVICE_SYNC_STATUS_OFFSET RTC3_EOF_RedFrameID_OFFSET + 2
244 #define RTC_YELLOW_PERIOD_CONFIGURED_OFFSET RTC_DEVICE_SYNC_STATUS_OFFSET + 1
245 #define PORT1_STATUS_OFFSET RTC_YELLOW_PERIOD_CONFIGURED_OFFSET + 1
246 #define PORT2_STATUS_OFFSET PORT1_STATUS_OFFSET + 1
247 
248 #define MAXLINE_RXDELAY_P1_OFFSET PORT2_STATUS_OFFSET + 1
249 #define MAXLINE_RXDELAY_P2_OFFSET MAXLINE_RXDELAY_P1_OFFSET + 4
250 
251 // Bytes where PRU's store the index of active list using which send list has been prepared
252 // These are then used by the RTC Send code
253 #define PRU0_ACTIVE_LIST_INDEX_OFFSET MAXLINE_RXDELAY_P2_OFFSET + 4
254 #define PRU1_ACTIVE_LIST_INDEX_OFFSET PRU0_ACTIVE_LIST_INDEX_OFFSET + 1
255 
256 // Below registers are used by PRU firmware for internal usage
257 #define RTC_SCH_EXECUTED_HALF_PRU0_OFFSET PRU1_ACTIVE_LIST_INDEX_OFFSET + 1 // 2 bytes
258 #define RTC_SCH_EXECUTED_HALF_PRU1_OFFSET RTC_SCH_EXECUTED_HALF_PRU0_OFFSET + 2 // 2 bytes
259 
260 #define MRP_PORT1_STATE_OFFSET 0x72//RTC_SCH_EXECUTED_HALF_PRU1_OFFSET + 2
261 #define MRP_PORT2_STATE_OFFSET MRP_PORT1_STATE_OFFSET + 1
262 
263 #define RTC_YELLOW_PRD_START_TIME_OFFSET MRP_PORT2_STATE_OFFSET + 1 // 4 bytes
264 #define RTC_YELLOW_SAFETY_MARGIN_PRD_START_TIME_OFFSET RTC_YELLOW_PRD_START_TIME_OFFSET + 4 // 4 bytes
265 #define RTC_BASE_CLK_CHANGED_OFFSET RTC_YELLOW_SAFETY_MARGIN_PRD_START_TIME_OFFSET + 4 // 1 byte
266 // Free byte x006d
267 
268 #define RTC_SEND_EXECUTED_HALF_PRU0_OFFSET RTC_BASE_CLK_CHANGED_OFFSET + 2
269 #define RTC_SEND_EXECUTED_HALF_PRU1_OFFSET RTC_SEND_EXECUTED_HALF_PRU0_OFFSET + 1
270 
271 // Parameters for IRT relative forwarder
272 // There are 5 configurations for GreenPeriodBegin per port and direction. Max value is 0x7A120 equal to 500us.
273 // If 5 configurations then one is 0 which means no red period in this phase.
274 // Orange period is leagay and should be supported.
275 
276 #define RTC_GREEN_BEGIN_P1_1_RX_OFFSET 0x80//RTC_SEND_EXECUTED_HALF_PRU1_OFFSET + 1
277 #define RTC_GREEN_BEGIN_P1_1_TX_OFFSET RTC_GREEN_BEGIN_P1_1_RX_OFFSET + 4
278 #define RTC_GREEN_BEGIN_P1_2_RX_OFFSET RTC_GREEN_BEGIN_P1_1_TX_OFFSET + 4
279 #define RTC_GREEN_BEGIN_P1_2_TX_OFFSET RTC_GREEN_BEGIN_P1_2_RX_OFFSET + 4
280 #define RTC_GREEN_BEGIN_P1_3_RX_OFFSET RTC_GREEN_BEGIN_P1_2_TX_OFFSET + 4
281 #define RTC_GREEN_BEGIN_P1_3_TX_OFFSET RTC_GREEN_BEGIN_P1_3_RX_OFFSET + 4
282 #define RTC_GREEN_BEGIN_P1_4_RX_OFFSET RTC_GREEN_BEGIN_P1_3_TX_OFFSET + 4
283 #define RTC_GREEN_BEGIN_P1_4_TX_OFFSET RTC_GREEN_BEGIN_P1_4_RX_OFFSET + 4
284 #define RTC_GREEN_BEGIN_P1_5_RX_OFFSET RTC_GREEN_BEGIN_P1_4_TX_OFFSET + 4
285 #define RTC_GREEN_BEGIN_P1_5_TX_OFFSET RTC_GREEN_BEGIN_P1_5_RX_OFFSET + 4
286 
287 #define RTC_GREEN_BEGIN_P2_1_RX_OFFSET 0xA8//RTC_GREEN_BEGIN_P1_5_TX_OFFSET + 4
288 #define RTC_GREEN_BEGIN_P2_1_TX_OFFSET RTC_GREEN_BEGIN_P2_1_RX_OFFSET + 4
289 #define RTC_GREEN_BEGIN_P2_2_RX_OFFSET RTC_GREEN_BEGIN_P2_1_TX_OFFSET + 4
290 #define RTC_GREEN_BEGIN_P2_2_TX_OFFSET RTC_GREEN_BEGIN_P2_2_RX_OFFSET + 4
291 #define RTC_GREEN_BEGIN_P2_3_RX_OFFSET RTC_GREEN_BEGIN_P2_2_TX_OFFSET + 4
292 #define RTC_GREEN_BEGIN_P2_3_TX_OFFSET RTC_GREEN_BEGIN_P2_3_RX_OFFSET + 4
293 #define RTC_GREEN_BEGIN_P2_4_RX_OFFSET RTC_GREEN_BEGIN_P2_3_TX_OFFSET + 4
294 #define RTC_GREEN_BEGIN_P2_4_TX_OFFSET RTC_GREEN_BEGIN_P2_4_RX_OFFSET + 4
295 #define RTC_GREEN_BEGIN_P2_5_RX_OFFSET RTC_GREEN_BEGIN_P2_4_TX_OFFSET + 4
296 #define RTC_GREEN_BEGIN_P2_5_TX_OFFSET RTC_GREEN_BEGIN_P2_5_RX_OFFSET + 4
297 
298 // Each setting can be mapped to up to 16 phases. There are 3 bits required per mapping. Total 48 bits or 6 bytes
299 // bits 0..2 index of RTC_GREEN_BEGIN_Px_y_OFFSET for phase 1
300 // ...
301 // bits 45..47 index of RTC_GREEN_BEGIN_Px_y_OFFSET for phase 16
302 
303 #define RTC_PAHSE_MAPPING_OFFSET 0xD0//RTC_GREEN_BEGIN_P2_5_TX_OFFSET + 4
304 
305 // 4 bytes for each phase.. 64 bytes in total. Next data location is 0x100
306 
307 #define PN_DCPF_NAME_OFFSET RTC_PAHSE_MAPPING_OFFSET + 64 // 8 bytes
308 #define PN_DCPF_NAME_LENGTH_OFFSET PN_DCPF_NAME_OFFSET + 8 // 8 bit
309 
310 // Previous cycle counter per CPM is verified with current cycle counter. Not to remember previous
311 // counter per CPM. For 8 CPMs this is 8 * 16 bit = 16 bytes
312 #define CPM_PREV_CYCLE_COUNTER_OFFSET PN_DCPF_NAME_LENGTH_OFFSET + 4
313 
314 // Monitoring of incoming packets is done with DHT. Time-out value is specified by host in RTC mode
315 // default setting is 3 (sendcycles). Max value is 255. There is one DHT per CPM.
316 // todo: need 16 bit values and decouple from location from RTC_CPM_ACTIVE_OFFSET
317 // RTC_CPM_DHT_OFFSET is updated when CPM is active with every scf*31.25us
318 // RTC_CPM_DHT_TIME_OUT_OFFSET is fixed timeout set by host when new CPM is activated
319 // 16 bit timout/value * 8 CPM = 16 bytes each
320 
321 #define RTC_CPM_DHT_OFFSET CPM_PREV_CYCLE_COUNTER_OFFSET + 16
322 #define RTC_DHT_TIMEOUT_OFFSET RTC_CPM_DHT_OFFSET + 16
323 
324 // AR Group - PPM mapping- up to 8 groups. Each group can have up to 8 PPMs which are indicated in this inverted mask
325 // we use this mask and XOR with PPM active field
326 // byte 0 = AR Group 1
327 // ..
328 // byte 7 = AR Group 8
329 // bit 0 = 0 PPM 1 belongs to this group
330 // bit 0 = 1 PPM 1 does not belong to this group
331 // ...
332 // bit 7 = 1 PPM 7 belongs to this group
333 
334 #define RTC_AR_GROUP_PPM_OFFSET RTC_DHT_TIMEOUT_OFFSET + 16
335 
336 // for faster detection of AR group each CPM has one byte which gives the group number it belongs to
337 // byte 0 (CPM 1) = AR Group number 0..7 indicating group number 1..8
338 // ...
339 // byte 7 (CPM 8) = AR Group number 1..8
340 
341 #define RTC_CPM_AR_GROUP_OFFSET RTC_AR_GROUP_PPM_OFFSET + 8
342 
343 #define RTC_NOTIFY_DHT_EVENT_OFFSET RTC_CPM_AR_GROUP_OFFSET + 8 // signals the DHT event (see below)
344 #define RTC_NOTIFY_LIST_TOGGLE_EVENT_OFFSET RTC_NOTIFY_DHT_EVENT_OFFSET + 10 // signals the PPM List toggle event (see below)
345 #define RTC_NOTIFY_DHT_EXPIRE 0x01 // indicate DHT expire event
346 #define RTC_NOTIFY_CPM_CRC 0x02 // indicate CPM CRC
347 #define RTC_NOTIFY_CPM_SEQ 0x03 // CPM sequence counter error
348 #define RTC_NOTIFY_CPM_STAT 0x04 // CPM status error
349 #define RTC_NOTIFY_CPM_LIST_CHANGE 0x05 // CPM List changed
350 #define RTC_NOTIFY_PPM_LIST_CHANGE 0x06 // PPM List changed
351 #define RTC_NOTIFY_ALL_LIST_CHANGE 0x0B // spcial case: both lists changed
352 
353 // One byte for each PPM. This will allow to resolve a race condition where PPM Active is cleared when DHT expires
354 // and it is re-written when the list toggle happens.
355 #define RTC_PPM_ACTIVE_OFFSET 0x160//RTC_NOTIFY_LIST_TOGGLE_EVENT_OFFSET + 3
356 
357 // Free space - 0x00158 = 4 Bytes
358 #define RTC_PPM_ACTIVE_SHADOW_OFFSET RTC_PPM_ACTIVE_OFFSET + 8
359 
360 // Storage space for the CPM buffer addresses for CPM connections. Max 8 AR's -> 8*3 possible number of buffer addresses.
361 // Each CPM connection would have three buffers allocated. Since, actual CPM frame length may be smaller than statically allocated
362 // buffer size it is necessary to store the offset addresses of all the three buffers. Total space used = 24*2= 48 bytes.
363 #define RTC_CPM_BUFFER_ADDRESSES_OFFSET RTC_PPM_ACTIVE_SHADOW_OFFSET + 8 //0x0160
364 
365 #define ISOM_TIO_TIMEVAL1 0x190
366 #define ISOM_TIO_DURATION1 ISOM_TIO_TIMEVAL1 + 4
367 #define ISOM_TIO_TYPE1 ISOM_TIO_DURATION1 + 4
368 #define ISOM_TIO_ENABLE_OFFSET ISOM_TIO_TYPE1 + 1
369 #define ISOM_TIO_TIMEVAL2 ISOM_TIO_TYPE1 + 4
370 #define ISOM_TIO_DURATION2 ISOM_TIO_TIMEVAL2 + 4
371 #define ISOM_TIO_TYPE2 ISOM_TIO_DURATION2 + 4
372 // Free Space - From 0x01AC to 0x01CC
373 #define RTC_IRT_YELLOW_TIME_OFFSET 0x01D0
374 
375 #define RTC_AR_GROUP_PPM_SHADOW_OFFSET 0x01D4 // 8 Bytes
376 
377 // PRU clears the event and ARM sets it - 1 bit per PPM
378 // ARM clear the event and PRU sets it - 1 bit per CPM
379 #define RTC_CPM_BC_EVENT_OFFSET 0x01DC
380 
381 #define COMPENSATION_OFFSET 0x01E4
382 #define MAXBRIDGE_DELAY_OFFSET 0x01E8
383 
384 // Free space from 0x1EC to 0x200 is available for future registers
385 
386 #define EOF_RTC_CONFIG 0x0200
387 
388 // Event generation
389 // PRU issues an interrupt to ARM when packet is received or packet is transmitted. This is aligned with buffer complete flag.
390 
391 // Descriptor for CPM and PPM is as follows: total 16 bytes or 4 32 bit word.
392 
393 // CPM RTC descriptor for red and green period
394 // Bit Name Description
395 // 0..15 FrameReference 16 bit offset into start address pointer for triple buffer CPM (fixed address). Points into cpm triple buffer start addresses (RTC_CPM_BUFFER_ADDRESSES_OFFSET+ offset of current CPM first buffer)
396 // 16..31 FrameLength 11 bits of frame length including VLAN and FCS, set by host only. PRU may verify incoming frame on length which needs to be flexible in terms of stripped VLAN tag. Bit12.15 need to be zero.
397 // 0..15 FrameDataPointer 16 bit absolute address pointing to Profinet data of current index buffer. This pointer masks VLAN tag offset. Points to first byte after FID
398 // 16..23 FrameIndex Current index of data source which is host on PPM and PRU on CPM.
399 // CPM: Before first packet received idx indicated to host with FrameIndex is idx_2 whereas PRU is on idx_0 (not shown in register) . After first packet received by PRU FrameIndex changes to idx_0 and BufferComplete flag is reset by PRU. PRU advances to next index which is idx_1.
400 //24..31 FrameFlags1 CPM: Bit 0: 1 = VLAN TAG present
401 // CPM: Bit 1: 0 = CPM received on port 1 (PRU0), 1 = CPM received on port 2 (PRU1)
402 // Bit 1..7: reserved
403 // 24..31 Reserved
404 // 0..15 FrameID FrameID as provided by engineering. Set by host and used only for CPM. Not used for PPM. MRPD?
405 // 16..23 FrameFlags2 CPM: Bit 0: 0 = received in red, 1 = received in green
406 // Bit 1..7: reserved
407 // 24..31 Reserved
408 // 0..15 RR Reduction Ratio for red period which is max 16.
409 // Send in GREEN period: reduction ratio (max 512) set by host and used by PRU to find out whether current phase matches.
410 // 16..31 Phase CPM: used for DHT update
411 
412 // -----------------------------------------------
413 
414 // PPM RTC descriptor for red and green period
415 // Bit Name Description
416 // 0..15 FrameReference bytes address offset into RTCx - PPM buffer which has fixed base address.
417 // 16..31 FrameLength 11 bits of frame length, set by host only. PRU may verify incoming frame on length.
418 // 0..31 FrameSendOffset PPM: Send in RED period: FSO as provided by engineering and limited to 22 bits, i.e. 4.1ms. Set by host only.
419 // 0..15 FrameID FrameID as provided by engineering. Set by host and used only for CPM. Not used for PPM. MRPD?
420 // 16..23 FrameFlags1 PPM: Bit 0: 1 = RTC3 frame in red period, note: first RTC3 will come in green and is handled with additional descriptor for legacy start-up
421 // Bit 1..7: reserved
422 // 24..31 FrameIndex Current index of data source which is host on PPM and PRU on CPM.
423 // CPM: Before first packet received idx indicated to host with FrameIndex is idx_2 whereas PRU is on idx_0 (not shown in register) . After first packet received by PRU FrameIndex changes to idx_0 and BufferComplete flag is reset by PRU. PRU advances to next index which is idx_1.
424 // 0..15 RR Reduction Ratio for red period which is max 16.
425 // Send in GREEN period: reduction ratio (max 512) set by host and used by PRU to find out whether current phase matches.
426 // 16..31 Phase PPM: used for sendlist generation.
427 #ifdef PRU
428 .struct struct_rtc_cpm_desc
429  .u16 FrameReference
430  .u16 FrameLength
431  .u16 FrameDataPointer
432  .u8 FrameIndex
433  .u8 FrameFlags1
434  .u16 FrameID
435  .u8 FrameFlags2
436  .u8 Reserved
437  .u16 RR
438  .u16 Phase
439 .ends
440 
441 .struct struct_rtc_ppm_desc
442  .u16 FrameReference
443  .u16 FrameLength
444  .u32 FrameSendOffset
445  .u16 FrameID
446  .u8 Reserved
447  .u8 FrameIndex
448  .u16 RR
449  .u16 Phase
450 .ends
451 
452 // cpm FrameFlags
453 #define VLAN_TAG t0
454 // cpm/ppm FrameFlags
455 #define RED_GREEN_FLAG t0
456 // FW ARM descriptor structure hard coded in driver
457 #endif
458 
459 // CPM/PPM list size is 16 * 8 = 128 bytes
460 // each list has shadow list -> 192 bytes
461 
462 #define RTC_DESC_SIZE 16 // increased for IRT
463 #define RTC_CPM_LIST_SIZE RTC_DESC_SIZE * NO_CPM
464 #define RTC_PPM_LIST_SIZE RTC_DESC_SIZE * NO_PPM
465 
466 // ICSS PRU0 DMEM 8 kB
467 
468 // RTC descriptors
469 
470 // CPM/PPM descriptors have 16 bytes length. There is one descriptor per triple buffer.
471 // There is a second list for the host to prepare new connection in background.
472 
473 #define RTC_CPM_IDX0_OFFSET 0x200
474 #define RTC_PPM_IDX0_OFFSET RTC_CPM_IDX0_OFFSET + RTC_DESC_SIZE * NO_CPM
475 #define RTC_PPM_IDX1_OFFSET RTC_PPM_IDX0_OFFSET + RTC_DESC_SIZE * NO_PPM
476 #define EOF_PPM_LIST_OFFSET RTC_PPM_IDX1_OFFSET + RTC_DESC_SIZE * NO_PPM
477 
478 // Blocking tables for MRP. Each Port has it's own Blocking static multicast receive and forward table.
479 #define NO_ROWS 50
480 #define SIZE_OF_ROW 4
481 #define BLOCKING_STATIC_MAC_TABLE_RCV EOF_PPM_LIST_OFFSET
482 #define BLOCKING_STATIC_MAC_TABLE_FWD BLOCKING_STATIC_MAC_TABLE_RCV + NO_ROWS * SIZE_OF_ROW
483 
484 
485 #define DCP_IDENT_REQ_OFFSET 0x0600
486 
487 // ICSS PRU1 DMEM 8 kB
488 
489 // PPM buffer has 1440 bytes IO data which can be shared over 8 connections
490 // Each connection has a full packet with Ethernet header, FID, DATA, Status.
491 // Host prepares complete packet which may include VLAN tag. Although RTC
492 // packet will bypass send queues and has no effect on tags.
493 // Total size needed is:
494 // 8 * 26 bytes (header, FID, cycle counter, data status, transfer status)
495 // 1440 bytes IO data
496 // triple buffered: 3 * 1440 + 3 * 8 (26) = 4944 bytes = 0x1350
497 // absolute address is referenced by RTC descriptor FrameIndex
498 // organization on PPM buffer is managed by host. PRU only executes send list
499 // and fills in cycles counter and transfer status.
500 
501 #define PPM_IO_DATA_SIZE 1440 // FW driver uses this value also for CPM data size!
502 #define PPM_ETH_HEADER 12+4+2+2 // includes VLAN and FID
503 #define PPM_TRAILER 2+1+1 // cycle counter, data status, transfer status
504 // FW extended PPM buffer model requires two blocks in different Data RAMs
505 #define PPM_BUFFER_OFFSET0 0x0D00 // buffer block 0 Data RAM0
506 #define PPM_BUFFER_OFFSET1 0x10 // buffer block 1 Data RAM1. Inital 16 bytes used for Firmware version
507 
508 // Following two buffers are used to store a RTC3 frame which has to be forwarded
509 // PRU0
510 #define RTC3_SF_FSO_PRU0_OFFSET 0xBC00
511 #define RTC3_SF_LENGTH_PRU0_OFFSET RTC3_SF_FSO_PRU0_OFFSET + 4
512 #define RTC3_SF_BUFFER_PRU0_OFFSET RTC3_SF_LENGTH_PRU0_OFFSET + 4
513 // PRU1
514 #define RTC3_SF_FSO_PRU1_OFFSET 0xE814
515 #define RTC3_SF_LENGTH_PRU1_OFFSET RTC3_SF_FSO_PRU1_OFFSET + 4
516 #define RTC3_SF_BUFFER_PRU1_OFFSET RTC3_SF_LENGTH_PRU1_OFFSET + 4
517 
518 // now each block has max of 4 packets
519 #define EOF_PPM_BUFFER_OFFSET 0x1218 // 3 * (1440+4*26) = 0x1218 (each block...)
520 
521 // ICSS Shared RAM 12kB
522 
523 // L3 64KB Memory - switch buffer Pool and CPM buffer
524 
525 // CPM buffer is at end of L3 Memory. Extend to two CPM of 1440 max...
526 // 2-8 CPMs including header and CRC 3 * (2*1440 + 8*30) = 9360 = 0x2490
527 // Tagged frames have tag bit set in descriptor for host to simplify parsing.
528 // Incoming frames are verified in terms of FID, MAC, period, time, data hold time, status.
529 // In case there is a match and no error packet is put in the corresponding CPM buffer.
530 // Triple buffer management is managed through buffer complete flag and FrameIndex in RTC descriptor.
531 //
532 
533 #define CPM_IO_DATA_SIZE 1440
534 #define CPM_ETH_HEADER 12+4+2+2 // includes VLAN and FID
535 #define CPM_TRAILER 2+1+1+4 // cycle counter, data status, transfer status, CRC
536 
537 #define EOF_CPM_BUFFER_OFFSET 0xE690 // 0xC200+0x2490
538 #define CPM_BUFFER_OFFSET 0xC200
539 #define EOF_48K_BUFFER_OFFSET 0xC200
540 
541 //=====================================PTCP RELATED DATA=====================================//
542 #define P2_T2_ABS_TS_OFFSET 0x278
543 #define P1_T2_ABS_TS_OFFSET 0x274
544 
545 #define SYNC_CYCLE_COUNTER 0x0270
546 #define SYNC_SF_BUF_OFFSET_P2 PTCP_BASE_ADDR_OFFSET + 528 //94 bytes
547 
548 //these four offsets are only accessed from ARM
549 #define PORT2_DELAY_REQ_FRAME_OFFSET PTCP_BASE_ADDR_OFFSET + 452 //60-bytes
550 #define PORT1_DELAY_REQ_FRAME_OFFSET PTCP_BASE_ADDR_OFFSET + 392 //60-bytes
551 
552 #define PORT2_DELAY_RESP_FRAME_OFFSET PTCP_BASE_ADDR_OFFSET + 324 //66-bytes
553 #define PORT1_DELAY_RESP_FRAME_OFFSET PTCP_BASE_ADDR_OFFSET + 256 //66-bytes
554 
555 #define SYNC_INIT_FLAG_OFFSET PTCP_BASE_ADDR_OFFSET + 254 // 1 byte required
556 #define SYNC_MASTER_MAC_OFFSET PTCP_BASE_ADDR_OFFSET + 248 //6-bytes required
557 #define SYNC_UUID_OFFSET PTCP_BASE_ADDR_OFFSET + 232 //16-bytes
558 
559 
560 #define SYNC_SF_BUF_OFFSET_P1 PTCP_BASE_ADDR_OFFSET + 136 //94 bytes
561 #define SYNC_SBLOCK_OFFSET PTCP_BASE_ADDR_OFFSET + 104 //32 bytes // cut-through
562 #define SYNC_W_FUP_CTRL_BYTE_OFFSET PTCP_BASE_ADDR_OFFSET + 100 //1 byte
563 #define SYNC_CTRL_BYTE_OFFSET PTCP_BASE_ADDR_OFFSET + 96 //1 byte
564 #define SYNC_RCV_CYCLE_CTR_OFFSET PTCP_BASE_ADDR_OFFSET + 92 //2 bytes // not being used
565 
566 #define SYNC_TORG_TIME_OFFSET PTCP_BASE_ADDR_OFFSET + 84 // 8 bytes // cut-through
567 #define SYNC_FUP_DELAY_OFFSET PTCP_BASE_ADDR_OFFSET + 80
568 #define P2_DELAY_RESP_CTRL_OFFSET PTCP_BASE_ADDR_OFFSET + 78
569 #define P1_DELAY_RESP_CTRL_OFFSET PTCP_BASE_ADDR_OFFSET + 77
570 #define SYNC_FWD_ENABLED_OFFSET PTCP_BASE_ADDR_OFFSET + 76 // 1 byte required
571 #define SYNC_RX_SOF_OFFSET_P1 PTCP_BASE_ADDR_OFFSET + 72
572 #define SYNC_RX_SOF_OFFSET PTCP_BASE_ADDR_OFFSET + 68 // cut-through
573 #define SYNC_INDELAY_PLUS_LD_OFFSET PTCP_BASE_ADDR_OFFSET + 64 // cut-through
574 #define SYNC_RX_SOF_OFFSET_P2 PTCP_BASE_ADDR_OFFSET + 60
575 #define SYNC_SEQID_OFFSET PTCP_BASE_ADDR_OFFSET + 56
576 
577 #define PRU1_HANDSHAKE_OFFSET PTCP_BASE_ADDR_OFFSET + 52
578 #define P2_SMA_LINE_DELAY_OFFSET PTCP_BASE_ADDR_OFFSET + 48
579 #define P2_T2_TIME_STAMP_OFFSET PTCP_BASE_ADDR_OFFSET + 44
580 #define P2_T4_CYCLE_CTR_OFFSET PTCP_BASE_ADDR_OFFSET + 40
581 #define P2_T4_TIME_STAMP_OFFSET PTCP_BASE_ADDR_OFFSET + 36
582 #define P2_T1_CYCLE_CTR_OFFSET PTCP_BASE_ADDR_OFFSET + 32
583 #define P2_T1_TIME_STAMP_OFFSET PTCP_BASE_ADDR_OFFSET + 28
584 
585 #define PRU0_HANDSHAKE_OFFSET PTCP_BASE_ADDR_OFFSET + 24
586 #define P1_SMA_LINE_DELAY_OFFSET PTCP_BASE_ADDR_OFFSET + 20
587 #define P1_T2_TIME_STAMP_OFFSET PTCP_BASE_ADDR_OFFSET + 16
588 #define P1_T4_CYCLE_CTR_OFFSET PTCP_BASE_ADDR_OFFSET + 12
589 #define P1_T4_TIME_STAMP_OFFSET PTCP_BASE_ADDR_OFFSET + 8
590 #define P1_T1_CYCLE_CTR_OFFSET PTCP_BASE_ADDR_OFFSET + 4
591 #define P1_T1_TIME_STAMP_OFFSET PTCP_BASE_ADDR_OFFSET + 0
592 
593 #define PTCP_BASE_ADDR_OFFSET 0x0000
594 
595 //==========================================================================================//
596 
597 #define ECAP_CLR_CONFIG_OFFSET PTCP_L3_OCMC_BASE + 272 //4 bytes
598 #define IEP_CONFIG_ADJ_OFFSET PTCP_L3_OCMC_BASE + 260 //12 bytes
599 
600 #define P2_PTCP_CTRL_OFFSET PTCP_L3_OCMC_BASE + 257
601 #define P1_PTCP_CTRL_OFFSET PTCP_L3_OCMC_BASE + 256
602 #define P2_DLY_FUP_PACKET_OFFSET PTCP_L3_OCMC_BASE + 192
603 #define P1_DLY_FUP_PACKET_OFFSET PTCP_L3_OCMC_BASE + 128
604 #define P2_DLY_RSP_PACKET_OFFSET PTCP_L3_OCMC_BASE + 64
605 #define P1_DLY_RSP_PACKET_OFFSET PTCP_L3_OCMC_BASE
606 #define PTCP_L3_OCMC_BASE 0xE700 // moved to accomondate larger CPM buffer
607 
608 #define PTCP_PHASE_COUNTER_OFFSET RTC_PHASE_COUNTER_OFFSET
609 #define PTCP_BASE_CLK_OFFSET RTC_BASE_CLK_OFFSET
610 #define PTCP_PM_CYCLE_COUNTER_OFFSET RTC_CYCLE_COUNTER_OFFSET
611 #define PTCP_PM_PHASE_COUNTER_OFFSET RTC_PHASE_COUNTER_OFFSET
612 
613 #define P2_MAC_ADDR 0x1E50
614 #define P1_MAC_ADDR 0x1E48
615 
616 #define STATIC_MAC_TABLE_FWD_PORT2 STATIC_MAC_TABLE_RCV_PORT2 + 256
617 #define STATIC_MAC_TABLE_RCV_PORT2 STATIC_MAC_TABLE_FWD_PORT1 + 256
618 #define STATIC_MAC_TABLE_FWD_PORT1 STATIC_MAC_TABLE_RCV_PORT1 + 256
619 #define STATIC_MAC_TABLE_RCV_PORT1 0x2000
620 #endif //__ICSS_PN_RTCX__
621