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