]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/emac/example/cptsEventExample/src/cpts_event_test.c
emac-lld: add to PDK
[processor-sdk/pdk.git] / packages / ti / drv / emac / example / cptsEventExample / src / cpts_event_test.c
1 /**  
2  * @file cpts_event_test.c
3  *
4  *   @n This function performs IEEE1588 Event tests. It formats and sends IEEE1588
5  *      event packets to the CPSW and then receive the same packets since the CPSW
6  *      is in loopback mode. It also verifies the receive packets and displat both
7  *      Tx and Rx CPTS events.
8  *
9  *
10  * @brief 
11  *  Example to illustrate the usage of EMAC CPSW switch to send and receive IEEE1588 
12  *  event packets  and process CPTS events using CPPI, QMSS low level drivers and 
13  *  CSL.
14  *
15  *      This example application does the following:
16  *          (1) Initializes:
17  *                  (a) Queue Manager (QM) Subsystem 
18  *                  (b) Packet Accelerator (PA) CPPI DMA 
19  *                  (c) Ethernet Subsystem (Ethernet switch + CPTS + SGMII/RGMII + MDIO) 
20  *                  - (Note: Applicable only for NO_BOOT mode)
21  *
22  *          (2) Sets up the CPPI descriptors and Queues required for sending and
23  *              receiving data using Ethernet.
24  *                  (a) Uses Host descriptors
25  *
26  *          (3) Sends IEEE1588 event packets onto wire 
27  *          The packets sent by the application are sent onto wire and 
28  *          then be delivered to the same EMAC port through internal or 
29  *          external loopback.
30  *      
31  *      (4) Application receives the IEEE1588 event packet, pop and display 
32  *          the CPTS events.
33  *
34  *  \par
35  *  ============================================================================
36  *  @n   (C) Copyright 2015, Texas Instruments, Inc.
37  * 
38  *  Redistribution and use in source and binary forms, with or without 
39  *  modification, are permitted provided that the following conditions 
40  *  are met:
41  *
42  *    Redistributions of source code must retain the above copyright 
43  *    notice, this list of conditions and the following disclaimer.
44  *
45  *    Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the 
47  *    documentation and/or other materials provided with the   
48  *    distribution.
49  *
50  *    Neither the name of Texas Instruments Incorporated nor the names of
51  *    its contributors may be used to endorse or promote products derived
52  *    from this software without specific prior written permission.
53  *
54  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
55  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
56  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
58  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
59  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
60  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
63  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
64  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  *
66 */
67 #include <ti/drv/emac/example/cptsEventExample/src/cpts_event_test.h>
68 #include <stdio.h>
70 /**************************************************************
71 ************************** DEFINITIONS ************************
72 ***************************************************************/
73 /*
74  * Default test configuration for the silicon
75  *
76  * To run test at the CCS simulator
77  *    cpswSimTest = 1
78  *    cpswLpbkMode = CPSW_LOOPBACK_INTERNAL
79  */
80 #ifdef  SIMULATOR_SUPPORT
81 int cpswSimTest = 1;
82 int cpswLpbkMode = CPSW_LOOPBACK_INTERNAL;
83 #else
84 int cpswSimTest = 0;
85 int cpswLpbkMode = CPSW_LOOPBACK_INTERNAL;
86 #endif
88 #ifdef __LINUX_USER_SPACE
89 uint32_t no_bootMode = FALSE;
90 /* Linux Specific global variables per process */
91 sock_h                 rmClientSocket;
92 sem_t                  mutex;
93 #else
94 uint32_t no_bootMode = TRUE;
95 #endif
97 /* IEEE1588F packet 1
98  * Sync Message: Message Type = 0
99  * mac dest = 01:0b:19:00:00:00
100  */                         
101 //#pragma DATA_ALIGN(pkt1588F_1, 16);
102 uint8_t pkt1588F_1[] = {
103         0x01, 0x1b, 0x19, 0x00, 0x00, 0x00,               /* Dest MAC */
104         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
105         0x88, 0xf7,                                       /* Ethertype = IEEE1588 */
106         0x00,                                             /* transport specific | message type */
107         0x02,                                             /* reserved | PTP version */
108         0x00, 0x2c,                                       /* Length */
109         0x0F,                                             /* domain number */
110         0x00,                                             /* reserved */
111         0x02, 0x00,                                       /* flags 0x02: twoStep operation */
112         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
113         0x00, 0x00, 0x00, 0x00,                           /* reserved */
114         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
115         0x00, 0x00,                                       /* soure port ID */
116         0x00, 0x01,                                       /* sequenceId */
117         0x00,                                             /* controlField */
118         0x00,                                             /* logMessageInterval */
119         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* originTimestamp */
120         0x00, 0x00, 
121         0x00, 0x00                                        /* padding */ 
122         };    
123         
124         
125 /* IEEE1588F packet 2
126  * Path Delay Request Message: Message Type = 2
127  * mac dest = 01:80:C2:00:00:0E
128  */                         
129 uint8_t pkt1588F_2[] = {
130         0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E,               /* Dest MAC */
131         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
132         0x81, 0x00, 0x08, 0x88,                           /* VLAN: 0x0888 */
133         0x88, 0xf7,                                       /* Ethertype = IEEE1588 */
134         0x02,                                             /* transport specific | message type */
135         0x02,                                             /* reserved | PTP version */
136         0x00, 0x36,                                       /* Length */
137         0x0F,                                             /* domain number */
138         0x00,                                             /* reserved */
139         0x02, 0x00,                                       /* flags 0x02: twoStep operation */
140         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
141         0x00, 0x00, 0x00, 0x00,                           /* reserved */
142         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
143         0x00, 0x00,                                       /* soure port ID */
144         0x00, 0x02,                                       /* sequenceId */
145         0x05,                                             /* controlField */
146         0x0f,                                             /* logMessageInterval */
147         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* requestReceiptTimestamp */
148         0x00, 0x00, 
149         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* requestingPortIdentity */
150         0x00, 0x00, 
151         };  
152         
153 /* IEEE1588F packet 3
154  * Announce Message: Message Type = 11 (0x0b)
155  * mac dest = 01:0b:19:00:00:00
156  */                         
157 uint8_t pkt1588F_3[] = {
158         0x01, 0x1b, 0x19, 0x00, 0x00, 0x00,               /* Dest MAC */
159         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
160         0x88, 0xa8, 0x07, 0x77,                           /* STag: 0x0777 */
161         0x81, 0x00, 0x08, 0x88,                           /* VLAN: 0x0888 */
162         0x88, 0xf7,                                       /* Ethertype = IEEE1588 */
163         0x0b,                                             /* transport specific | message type */
164         0x02,                                             /* reserved | PTP version */
165         0x00, 0x40,                                       /* Length */
166         0x0F,                                             /* domain number */
167         0x00,                                             /* reserved */
168         0x00, 0x0c,                                       /* flags: ptpTimescale and currentUtcOffsetValid */
169         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
170         0x00, 0x00, 0x00, 0x00,                           /* reserved */
171         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
172         0x00, 0x00,                                       /* soure port ID */
173         0x00, 0x03,                                       /* sequenceId */
174         0x05,                                             /* controlField */
175         0x01,                                             /* logMessageInterval */
176         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* originTimestamp */
177         0x00, 0x00,                                       
178         0x00, 0x00,                                       /* currentUtcOffset */
179         0x00,                                             /* reserved */
180         0x60,                                             /* grandmasterPriority1 */
181         0x00, 0x00, 0x00, 0x80,                           /* grandmasterClockQuality */
182         0x63,                                             /* grandmasterPriority2 */
183         0xff, 0xff, 0x00, 0x09, 0xba, 0xf8, 0x21, 0x00,   /* grandmasterIdentity */
184         0x00, 0x80,                                       /* stepsRemoved */
185         0x80,                                             /* timeSource */
186         };                        
187         
188         
189 /* IEEE1588E packet 1
190  * Sync Message: Message Type = 0
191  * mac dest = 01:00:5e:00:01:81
192  * ip dest = FF0E:0:0:0:0:0:0:181
193  */                         
194 uint8_t pkt1588E_1[] = {
195         0x01, 0x00, 0x5e, 0x00, 0x01, 0x81,               /* Dest MAC */
196         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
197         0x86, 0xdd,                                       /* Ethertype = IPv6 */
198             0x60, 0x01, 0x01, 0x01,                           /* Iv6 header */
199             0x00, 0x34, 0x11, 0x01, 
200             0x20, 0x02, 0x9e, 0xda, 
201             0x6d, 0x30, 0x00, 0x00, 
202             0x00, 0x00, 0x00, 0x00, 
203             0x00, 0x00, 0x00, 0x04, 
204             0xFF, 0x0E, 0x00, 0x00, 
205             0x00, 0x00, 0x00, 0x00, 
206             0x00, 0x00, 0x00, 0x00, 
207             0x00, 0x00, 0x01, 0x81, 
208         0x01, 0x3f, 0x01, 0x3f, 0x00, 0x34, 0x00, 0x00,   /* UDP header */
209         0x10,                                             /* transport specific | message type */
210         0x02,                                             /* reserved | PTP version */
211         0x00, 0x2c,                                       /* Length */
212         0x0E,                                             /* domain number */
213         0x00,                                             /* reserved */
214         0x02, 0x00,                                       /* flags 0x02: twoStep operation */
215         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
216         0x00, 0x00, 0x00, 0x00,                           /* reserved */
217         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
218         0x00, 0x00,                                       /* soure port ID */
219         0x00, 0x04,                                       /* sequenceId */
220         0x00,                                             /* controlField */
221         0x00,                                             /* logMessageInterval */
222         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* originTimestamp */
223         0x00, 0x00, 
224         0x00, 0x00                                        /* padding */ 
225         };    
226                                 
227                                                       
228 /* IEEE1588D packet 2
229  * Path Delay Request Message: Message Type = 2
230  * mac dest = 01:00:5e:00:00:6b
231  * ip dest = FF02:0:0:0:0:0:0:6B
232  */                         
233 uint8_t pkt1588E_2[] = {
234         0x01, 0x00, 0x5e, 0x00, 0x00, 0x6b,               /* Dest MAC */
235         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
236         0x86, 0xdd,                                       /* Ethertype = IPv6 */
237             0x60, 0x01, 0x01, 0x01,                           /* Iv6 header */
238             0x00, 0x3e, 0x11, 0x01, 
239             0x20, 0x02, 0x9e, 0xda, 
240             0x6d, 0x30, 0x00, 0x00, 
241             0x00, 0x00, 0x00, 0x00, 
242             0x00, 0x00, 0x00, 0x04, 
243             0xFF, 0x02, 0x00, 0x00, 
244             0x00, 0x00, 0x00, 0x00, 
245             0x00, 0x00, 0x00, 0x00, 
246             0x00, 0x00, 0x00, 0x6B, 
247         0x01, 0x3f, 0x01, 0x3f, 0x00, 0x3e, 0x00, 0x00,   /* UDP header */
248         0x12,                                             /* transport specific | message type */
249         0x02,                                             /* reserved | PTP version */
250         0x00, 0x36,                                       /* Length */
251         0x0E,                                             /* domain number */
252         0x00,                                             /* reserved */
253         0x02, 0x00,                                       /* flags 0x02: twoStep operation */
254         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
255         0x00, 0x00, 0x00, 0x00,                           /* reserved */
256         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
257         0x00, 0x00,                                       /* soure port ID */
258         0x00, 0x05,                                       /* sequenceId */
259         0x05,                                             /* controlField */
260         0x0f,                                             /* logMessageInterval */
261         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* requestReceiptTimestamp */
262         0x00, 0x00, 
263         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* requestingPortIdentity */
264         0x00, 0x00, 
265         };  
266         
267 /* IEEE1588D packet 3
268  * Announce Message: Message Type = 11 (0x0b)
269  * mac dest = 01:00:5e:00:01:81
270  * ip dest = FF0X:0:0:0:0:0:0:181
271  */                         
272 uint8_t pkt1588E_3[] = {
273         0x01, 0x00, 0x5e, 0x00, 0x01, 0x81,               /* Dest MAC */
274         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
275         0x86, 0xdd,                                       /* Ethertype = IPv6 */
276             0x60, 0x01, 0x01, 0x01,                           /* Iv6 header */
277             0x00, 0x48, 0x11, 0x01, 
278             0x20, 0x02, 0x9e, 0xda, 
279             0x6d, 0x30, 0x00, 0x00, 
280             0x00, 0x00, 0x00, 0x00, 
281             0x00, 0x00, 0x00, 0x04, 
282             0xFF, 0x0E, 0x00, 0x00, 
283             0x00, 0x00, 0x00, 0x00, 
284             0x00, 0x00, 0x00, 0x00, 
285             0x00, 0x00, 0x01, 0x81, 
286         0x01, 0x40, 0x01, 0x40, 0x00, 0x48, 0x00, 0x00,   /* UDP header */
287         0x1b,                                             /* transport specific | message type */
288         0x02,                                             /* reserved | PTP version */
289         0x00, 0x40,                                       /* Length */
290         0x0E,                                             /* domain number */
291         0x00,                                             /* reserved */
292         0x00, 0x0c,                                       /* flags: ptpTimescale and currentUtcOffsetValid */
293         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
294         0x00, 0x00, 0x00, 0x00,                           /* reserved */
295         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
296         0x00, 0x00,                                       /* soure port ID */
297         0x00, 0x06,                                       /* sequenceId */
298         0x05,                                             /* controlField */
299         0x01,                                             /* logMessageInterval */
300         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* originTimestamp */
301         0x00, 0x00,                                       
302         0x00, 0x00,                                       /* currentUtcOffset */
303         0x00,                                             /* reserved */
304         0x60,                                             /* grandmasterPriority1 */
305         0x00, 0x00, 0x00, 0x80,                           /* grandmasterClockQuality */
306         0x63,                                             /* grandmasterPriority2 */
307         0xff, 0xff, 0x00, 0x09, 0xba, 0xf8, 0x21, 0x00,   /* grandmasterIdentity */
308         0x00, 0x80,                                       /* stepsRemoved */
309         0x80,                                             /* timeSource */
310         };   
311         
312 /* IEEE1588D packet 1
313  * Sync Message: Message Type = 0
314  * mac dest = 01:00:5e:00:01:81
315  * ip dest = 224.0.1.129
316  */                         
317 uint8_t pkt1588D_1[] = {
318         0x01, 0x00, 0x5e, 0x00, 0x01, 0x81,               /* Dest MAC */
319         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
320         0x08, 0x00,                                       /* Ethertype = IPv4 */
321         0x45, 0x00, 0x00, 0x48, 0x45, 0xa9, 0x00, 0x00,   /* IPv4 header */
322         0x01, 0x11, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0x06,
323         0xe0, 0x00, 0x01, 0x81,
324         0x01, 0x3f, 0x01, 0x3f, 0x00, 0x34, 0x00, 0x00,   /* UDP header */
325         0x10,                                             /* transport specific | message type */
326         0x02,                                             /* reserved | PTP version */
327         0x00, 0x2c,                                       /* Length */
328         0x0D,                                             /* domain number */
329         0x00,                                             /* reserved */
330         0x02, 0x00,                                       /* flags 0x02: twoStep operation */
331         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
332         0x00, 0x00, 0x00, 0x00,                           /* reserved */
333         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
334         0x00, 0x00,                                       /* soure port ID */
335         0x00, 0x07,                                       /* sequenceId */
336         0x00,                                             /* controlField */
337         0x00,                                             /* logMessageInterval */
338         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* originTimestamp */
339         0x00, 0x00, 
340         0x00, 0x00                                        /* padding */ 
341         };    
342                                 
343                                                       
344 /* IEEE1588D packet 2
345  * Path Delay Request Message: Message Type = 2
346  * mac dest = 01:00:5e:00:00:6b
347  * ip dest = 224.0.0.107
348  */                         
349 uint8_t pkt1588D_2[] = {
350         0x01, 0x00, 0x5e, 0x00, 0x00, 0x6b,               /* Dest MAC */
351         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
352         0x08, 0x00,                                       /* Ethertype = IPv4 */
353         0x45, 0x00, 0x00, 0x52, 0x45, 0xaa, 0x00, 0x00,   /* IPv4 header */
354         0x01, 0x11, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0x06,
355         0xe0, 0x00, 0x00, 0x6b,
356         0x01, 0x3f, 0x01, 0x3f, 0x00, 0x3e, 0x00, 0x00,   /* UDP header */
357         0x12,                                             /* transport specific | message type */
358         0x02,                                             /* reserved | PTP version */
359         0x00, 0x36,                                       /* Length */
360         0x0D,                                             /* domain number */
361         0x00,                                             /* reserved */
362         0x02, 0x00,                                       /* flags 0x02: twoStep operation */
363         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
364         0x00, 0x00, 0x00, 0x00,                           /* reserved */
365         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
366         0x00, 0x00,                                       /* soure port ID */
367         0x00, 0x08,                                       /* sequenceId */
368         0x05,                                             /* controlField */
369         0x0f,                                             /* logMessageInterval */
370         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* requestReceiptTimestamp */
371         0x00, 0x00, 
372         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* requestingPortIdentity */
373         0x00, 0x00, 
374         };  
375         
376 /* IEEE1588D packet 3
377  * Announce Message: Message Type = 11 (0x0b)
378  * mac dest = 01:00:5e:00:01:81
379  * ip dest = 224.0.1.129
380  */                         
381 uint8_t pkt1588D_3[] = {
382         0x01, 0x00, 0x5e, 0x00, 0x01, 0x81,               /* Dest MAC */
383         0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,               /* Src MAC  */
384         0x08, 0x00,                                       /* Ethertype = IPv4 */
385         0x45, 0x00, 0x00, 0x5c, 0x45, 0xac, 0x00, 0x00,   /* IPv4 header */
386         0x01, 0x11, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0x06,
387         0xe0, 0x00, 0x01, 0x81,
388         0x01, 0x40, 0x01, 0x40, 0x00, 0x48, 0x00, 0x00,   /* UDP header */
389         0x1b,                                             /* transport specific | message type */
390         0x02,                                             /* reserved | PTP version */
391         0x00, 0x40,                                       /* Length */
392         0x0D,                                             /* domain number */
393         0x00,                                             /* reserved */
394         0x00, 0x0c,                                       /* flags: ptpTimescale and currentUtcOffsetValid */
395         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* correction Fields */
396         0x00, 0x00, 0x00, 0x00,                           /* reserved */
397         0x00, 0xe0, 0xa6, 0xff, 0xfe, 0x66, 0x57, 0x04,   /* sourcePortIdentity */
398         0x00, 0x00,                                       /* soure port ID */
399         0x00, 0x09,                                       /* sequenceId */
400         0x05,                                             /* controlField */
401         0x01,                                             /* logMessageInterval */
402         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* originTimestamp */
403         0x00, 0x00,                                       
404         0x00, 0x00,                                       /* currentUtcOffset */
405         0x00,                                             /* reserved */
406         0x60,                                             /* grandmasterPriority1 */
407         0x00, 0x00, 0x00, 0x80,                           /* grandmasterClockQuality */
408         0x63,                                             /* grandmasterPriority2 */
409         0xff, 0xff, 0x00, 0x09, 0xba, 0xf8, 0x21, 0x00,   /* grandmasterIdentity */
410         0x00, 0x80,                                       /* stepsRemoved */
411         0x80,                                             /* timeSource */
412         };                        
413         
414         
415 /* Goose packet 1
416  * Ltype = 0x88b8
417  * mac dest = 01:a0:f4:08:2f:77
418  */                         
419 char pktGoose_1[] = {                                     
420         0x01, 0xa0, 0xf4, 0x08, 0x2f, 0x77,               /* Dest MAC */
421         0x00, 0xa0, 0xf4, 0x08, 0x2f, 0x77,               /* Src MAC  */
422         0x88, 0xb8,                                       /* Ethertype = Goose */
423         0x00, 0x01, 0x00, 0x91, 0x11, 0x00, 0x00, 0x00, 
424         0x61, 0x81, 0x86, 0x80, 0x1a, 0x47, 0x45, 0x44, 
425         0x65, 0x76, 0x69, 0x63, 0x65, 0x46, 0x36, 0x35, 
426         0x30, 0x2f, 0x4c, 0x4c, 0x4e, 0x30, 0x00, 0x0A, 
427         0x4f, 0x24, 0x67, 0x63, 0x62, 0x30, 0x31, 0x81, 
428         0x03, 0x00, 0x9c, 0x40, 0x82, 0x18, 0x47, 0x45, 
429         0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x46, 0x36, 
430         0x35, 0x30, 0x2f, 0x4c, 0x4c, 0x4e, 0x30, 0x24, 
431         0x47, 0x4f, 0x4f, 0x53, 0x45, 0x31, 0x83, 0x0b, 
432         0x46, 0x36, 0x35, 0x30, 0x5f, 0x47, 0x4f, 0x4f, 
433         0x53, 0x45, 0x31, 0x84, 0x08, 0x38, 0x6e, 0xbb, 
434         0xf3, 0x42, 0x17, 0x28, 0x0a, 0x85, 0x01, 0x01, 
435         0x86, 0x01, 0x0a, 0x87, 0x01, 0x00, 0x88, 0x01, 
436         0x01, 0x89, 0x01, 0x00, 0x8a, 0x01, 0x08, 0xab, 
437         0x20, 0x83, 0x01, 0x00, 0x84, 0x03, 0x03, 0x00, 
438         0x00, 0x83, 0x01, 0x00, 0x84, 0x03, 0x03, 0x00, 
439         0x00, 0x83, 0x01, 0x00, 0x84, 0x03, 0x03, 0x00, 
440         0x00, 0x83, 0x01, 0x00, 0x84, 0x03, 0x03, 0x00, 
441         0x00 
442         };
443         
444 typedef struct cptsEvtPkts_s {
445     char *name;
446         uint8_t *data;
447         int size;
448 } cptsEvtPkts_t;
450 cptsEvtPkts_t cptsEvtPkts[] = {
452     /* IEEE1588 Annex F Packet 1 */
453     {
454         "IEEE1588 Annex F Sync Message",
455         pkt1588F_1,
456         sizeof(pkt1588F_1)
457     },
458     
459     /* IEEE1588 Annex F Packet 2 */
460     {
461         "IEEE1588 Annex F Path Delay Request Message",
462         pkt1588F_2,
463         sizeof(pkt1588F_2)
464     },
465     
466     /* IEEE1588 Annex F Packet 3 */
467     {
468         "IEEE1588 Annex F Announce Message",
469         pkt1588F_3,
470         sizeof(pkt1588F_3)
471     },
472     
473     /* IEEE1588 Annex E Packet 1 */
474     {
475         "IEEE1588 Annex E Sync Message",
476         pkt1588E_1,
477         sizeof(pkt1588E_1)
478     },
479     
480     /* IEEE1588 Annex E Packet 2 */
481     {
482         "IEEE1588 Annex E Path Delay Request Message",
483         pkt1588E_2,
484         sizeof(pkt1588E_2)
485     },
486     
487     /* IEEE1588 Annex E Packet 3 */
488     {
489         "IEEE1588 Annex E Announce Message",
490         pkt1588E_3,
491         sizeof(pkt1588E_3)
492     },
493     
494     /* IEEE1588 Annex D Packet 1 */
495     {
496         "IEEE1588 Annex D Sync Message",
497         pkt1588D_1,
498         sizeof(pkt1588D_1)
499     },
500     
501     /* IEEE1588 Annex D Packet 2 */
502     {
503         "IEEE1588 Annex D Path Delay Request Message",
504         pkt1588D_2,
505         sizeof(pkt1588D_2)
506     },
507     
508     /* IEEE1588 Annex D Packet 3 */
509     {
510         "IEEE1588 Annex D Announce Message",
511         pkt1588D_3,
512         sizeof(pkt1588D_3)
513     },
514     
515     /* Goose Packet 1 */
516     {
517         "Goose",
518         pktGoose_1,
519         sizeof(pktGoose_1)
520     },
521     
522 };
524 /** ============================================================================
525  *   @n@b Send1588Packet
526  *
527  *   @b Description
528  *   @n This API is called to actually send out an IEEE1588 test packet data onto 
529  *      wire using ethernet.
530  *
531  *   @param[in]
532  *   @n None
533  *
534  *   @return    int32_t
535  *              -1      -   Error
536  *              0       -   Success
537  * =============================================================================
538  */
539 static int32_t Send1588Packet (cptsEvtPkts_t *pPkt)
541     Cppi_Desc*      pCppiDesc;
542     uint32_t        dataBufferSize;
543     char            psFlags = EMAC_PORT_0;
544     Cppi_DescTag    tag;
545     
546     /* Get a free descriptor from the global free queue we setup
547      * during initialization.
548      */
549     if ((pCppiDesc = Qmss_queuePop (gTxFreeQHnd)) == NULL)
550     {
551         System_printf ("No Tx free descriptor. Cant run send/rcv test \n");
552         return -1;
553     }
555     /* The descriptor address returned from the hardware has the
556      * descriptor size appended to the address in the last 4 bits.
557      *
558      * To get the true descriptor size, always mask off the last
559      * 4 bits of the address.
560      */
561     pCppiDesc = (Ptr) ((uint32_t) pCppiDesc & 0xFFFFFFF0);
563     dataBufferSize  = pPkt->size;
564     Cppi_setData (  Cppi_DescType_HOST,
565                     (Cppi_Desc *) pCppiDesc,
566                     (uint8_t *) Convert_CoreLocal2GlobalAddr((uint32_t)pPkt->data),
567                     dataBufferSize
568                  );
569     Cppi_setPacketLen (Cppi_DescType_HOST, (Cppi_Desc *)pCppiDesc, dataBufferSize);
570         
571     tag.srcTagHi  = 0;
572     tag.srcTagLo  = 0;
573     tag.destTagHi = 0;
574     tag.destTagLo = psFlags;
575     Cppi_setTag(Cppi_DescType_HOST, (Cppi_Desc *)pCppiDesc, (Cppi_DescTag *)&tag); 
576     
577     /* Clear PS Data */
578     Cppi_setPSLen (Cppi_DescType_HOST, (Cppi_Desc *)pCppiDesc, 0);
579     
580         /* Send the packet out the mac. */
581     Qmss_queuePush (gPaTxQHnd[NSS_CPSW_QUEUE_ETH_INDEX_LITE], pCppiDesc, dataBufferSize, SIZE_HOST_DESC, Qmss_Location_TAIL);
582     
583     /* Give some time for the CPSW to process the packet */
584     CycleDelay (1000);
586     return 0;
589 /** ============================================================================
590  *   @n@b Verify1588Packet
591  *
592  *   @b Description
593  *   @n This function verifies a 1588 packet received against the expected data and 
594  *      returns 0 to inidcate success and -1 to indicate a mismatch.
595  *
596  *   @param[in]  
597  *   @n pCppiDesc           Packet descriptor received.
598  * 
599  *   @return    int32_t
600  *              -1      -   Error
601  *              0       -   Success
602  * =============================================================================
603  */
604 static int32_t Verify1588Packet (cptsEvtPkts_t *pPkt, Cppi_Desc* pCppiDesc)
606         Cppi_HostDesc               *pHostDesc;
607         uint8_t                     *pDataBuffer;
608     uint8_t                     *pMsg;
609         int32_t                      i;
610     CSL_CPTS_EVENTINFO           cptsEventInfo;
611         
612     pHostDesc = (Cppi_HostDesc *)pCppiDesc;
613     
614     System_printf ("%s packet received: \n", pPkt->name);
615     
616     /* Verify the packet matches what we had sent */
617     pDataBuffer = (uint8_t *) pHostDesc->buffPtr;
618     pMsg = (uint8_t *) pPkt->data;
619     for (i = 0; i < pPkt->size; i++)  
620     {
621         if (pMsg[i] != pDataBuffer[i])  
622         {
623             System_printf ("Verify1588Packet: Byte %d expected 0x%02x, found 0x%02x\n", i, pMsg[i], pDataBuffer[i]);
624             System_flush();
626             /* Free the packet back to the Rx FDQ */
627             pHostDesc->buffLen = pHostDesc->origBufferLen;
628             Qmss_queuePush (gRxFreeQHnd, (Ptr)pHostDesc, pHostDesc->buffLen, SIZE_HOST_DESC, Qmss_Location_TAIL);
629             return -1;
630         }
631     }
632     
633     /* Extract Tx Timestamp from CPTS event */
634     CSL_CPTS_getEventInfo(&cptsEventInfo);
635     CSL_CPTS_popEvent(); 
636     System_printf ("CPTS Tx event (0x%x): Message Type 0x%x, Domain 0x%02x, SeqId 0x%04x, Tx timestamp 0x%08x%08x\n", 
637                    cptsEventInfo.eventType, cptsEventInfo.msgType, cptsEventInfo.domain, cptsEventInfo.seqId, 
638                    cptsEventInfo.timeStampHi, cptsEventInfo.timeStamp);
639     CSL_CPTS_getEventInfo(&cptsEventInfo);
640     CSL_CPTS_popEvent(); 
641     System_printf ("CPTS Rx event (0x%x): Message Type 0x%x, Domain 0x%02x, SeqId 0x%04x, Rx timestamp 0x%08x%08x\n", 
642                    cptsEventInfo.eventType, cptsEventInfo.msgType, cptsEventInfo.domain, cptsEventInfo.seqId, 
643                    cptsEventInfo.timeStampHi, cptsEventInfo.timeStamp);
644         
645     /* Reset the buffer lenght and put the descriptor back on the free queue */    
646     pHostDesc->buffLen = pHostDesc->origBufferLen;
647     Qmss_queuePush (gRxFreeQHnd, (Ptr)pHostDesc, pHostDesc->buffLen, SIZE_HOST_DESC, Qmss_Location_TAIL);
649     /* Verify packet done. Return success. */
650         return 0;
653 /**************************************************************
654 **************** EXAMPLE APP FUNCTIONS ************************
655 ***************************************************************/
658 /** ============================================================================
659  *   @n@b Cpts_EventTestApp
660  *
661  *   @b Description
662  *   @n Example application that sets up the application, sends, receives
663  *      data.
664  *
665  *   @param[in]  
666  *   @n None
667  * 
668  *   @return
669  *   @n None
670  *
671  * =============================================================================
672  */
673 extern Qmss_QueueHnd gRxQHnd;
674 static CSL_CPSW_STATS  stats [CSL_CPSW_NUMSTATBLOCKS];
676 #ifdef __LINUX_USER_SPACE
677 void* Cpts_EventTestApp (void *args)
678 #else
679 void Cpts_EventTestApp (void)
680 #endif
682         extern void view_ale_table(void);
683         int32_t                 i, numPkts;
684     int             fPass = 1;
686     System_printf ("**************************************************\n");
687     System_printf ("************* CPTS Event Test Starts *************\n");
688     System_printf ("**************************************************\n");
689     System_flush();
691 #if RM
692     if (setupRm ())
693     {
694       System_printf ("Function setupRm failed\n");
695       System_flush();
696       return;
697     }
698 #endif
699     /* Initialize the components required to run the example:
700      *  (1) QMSS
701      *  (2) CPPI
702      *  (3) Ethernet switch subsystem + MDIO + SGMII
703      */
704     
705     /* Initialize QMSS */
706     if (Init_Qmss () != 0)
707     {
708         System_printf ("QMSS init failed \n");
709         System_flush();
710         APP_exit (-1);
711     }
712     else
713     {
714         System_printf ("QMSS successfully initialized \n");
715         System_flush();
716     }
718     /* Initialize CPPI */
719     if (Init_Cppi () != 0)
720     {
721         System_printf ("CPPI init failed \n");
722         System_flush();
723         APP_exit (-1);
724     }
725     else
726     {
727         System_printf ("CPPI successfully initialized \n");
728         System_flush();
729     }
730  
731 #ifndef __LINUX_USER_SPACE
732     if (no_bootMode == TRUE)
733     {
734         /* Initialize the CPSW switch */
735         if (Init_Cpsw () != 0)
736         {
737             System_printf ("Ethernet subsystem init failed \n");
738             System_flush();
739             APP_exit (-1);
740         }
741         else
742         {
743             System_printf ("Ethernet subsystem successfully initialized \n");
744             System_flush();
745         }
746     }
747 #endif
749     /* Setup Tx */
750     if (Setup_Tx () != 0)
751     {
752         System_printf ("Tx setup failed \n");
753         System_flush();
754         APP_exit (-1);
755     }
756     else
757     {
758         System_printf ("Tx setup successfully done \n");
759         System_flush();
760     }
762     /* Setup Rx */
763     if (Setup_Rx () != 0)
764     {
765         System_printf ("Rx setup failed \n");
766         System_flush();
767         APP_exit (-1);
768     }
769     else
770     {
771         System_printf ("Rx setup successfully done \n");
772         System_flush();
773     }
775 #if 0
776 #ifndef __LINUX_USER_SPACE
777     System_printf ("CSL_CPSW_getStats before Packet Transmission ...\n");
778     memset(stats, 0, sizeof(stats));
779     cpsw_getStats(stats, 0);
780     System_flush();
781 #endif
782 #endif
783     
784     /* Run all types of CPTS event packets through */
785     numPkts = sizeof(cptsEvtPkts)/sizeof(cptsEvtPkts_t);
786     
787     for ( i = 0; i < numPkts; i++)
788     {
789         int j;
790             Cppi_Desc           *hd;
791         
792         if (Send1588Packet(&cptsEvtPkts[i]))
793         {
794             System_printf ("%s pkt: send error!\n", cptsEvtPkts[i].name);
795             break;
796         }
797         
798             /* Wait for a data packet from PA */
799         for (j = 0; j < 100; j++)  
800         {
801             CycleDelay (1000);
802             if (Qmss_getQueueEntryCount (gRxQHnd) > 0)   
803             {
804                 hd = (Cppi_Desc *)(((uint32_t)Qmss_queuePop (gRxQHnd)) & ~0xf);
805                 break;
806             }
807         } 
808         
809         if (j == 100)
810         {
811             System_printf ("%s pkt: receive timeout !\n", cptsEvtPkts[i].name);
812             break;
813         }
814         
815         if (Verify1588Packet(&cptsEvtPkts[i], hd) != 0)
816         {
817             System_printf ("%s pkt: receive error!\n", cptsEvtPkts[i].name);
818             break;
819         }
820     }
821     
822     if (i < numPkts)
823     {
824             System_printf("IEEE1588 event test failed!\n");
825         fPass = 0;
826     }
828 #if 0
829 #ifndef __LINUX_USER_SPACE
830     System_printf ("CSL_CPSW_getStats after Packet Transmission ...\n");
831     cpsw_getStats(stats, 1);
832 #endif
833 #endif
834     if(fPass)
835         System_printf("All tests have passed!\n");
836     System_printf ("**************************************************\n");
837     System_printf ("************** CPTS Event Test Ends **************\n");
838     System_printf ("**************************************************\n");
839     System_flush();
841     /* Clear framework */
842         if (clearFramework() < 0) 
843         {
844         System_printf ("Failed to Clean the example application \n");
845         System_flush();
846         }
848 #if (RM) && !defined(__LINUX_USER_SPACE)
849     {
850         int32_t rmResult;
852         if ((rmResult = Rm_resourceStatus(rmHandle, FALSE)) != 0)
853         {
854             System_printf ("Error : Number of unfreed resources : %d\n", rmResult);
855             System_flush();
856         }
857         else
858         {
859             System_printf ("All resources freed successfully\n");
860             System_flush();
861         }
862     }
863 #endif
864     /* Example application done. Return success */
865     APP_exit (0);
866     
869 /* Nothing past this point */