]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/emac/test/EmacLoopbackTest/main_am65xx.c
PDK-6489 : Enabling image generation and image naming convention
[processor-sdk/pdk.git] / packages / ti / drv / emac / test / EmacLoopbackTest / main_am65xx.c
1 /**
2  * @file   main_am65xx.c
3  *
4  * @brief  This file tests the EMAC driver APIs using loopback mode of operation
5  */
6 /*
7  * Copyright (c) 2018, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
39 #include <stdio.h>
40 #include <string.h>
43 /* XDCtools Header files */
44 #include <xdc/std.h>
45 #include <xdc/runtime/Error.h>
47 /* BIOS Header files */
48 #include <ti/sysbios/BIOS.h>
49 #include <ti/sysbios/knl/Task.h>
50 #include <ti/sysbios/family/arm/v8a/Mmu.h>
52 /* CSL Header files */
53 #include <ti/csl/soc.h>
55 /* OSAL Header files */
56 #include <ti/osal/osal.h>
58 /* BOARD Header files */
59 #include <ti/board/board.h>
61 /* UART Header files */
62 #include <ti/drv/uart/UART.h>
63 #include <ti/drv/uart/UART_stdio.h>
65 /* EMAC Driver Header File. */
66 #include <ti/drv/emac/emac_drv.h>
67 #include <ti/drv/emac/soc/emac_soc_v5.h>
69 extern uint32_t app_test_recv_port;
71 /* UDMA Driver Header File. */
72 #include <ti/drv/udma/udma.h>
73 /* Test application local header file */
74 #include "ti/drv/emac/test/EmacLoopbackTest/test_loc.h"
75 #include "ti/drv/emac/test/EmacLoopbackTest/test_utils.h"
78 extern void app_test_task_verify_ut_dual_mac_cpsw(UArg arg0, UArg arg1);
79 extern void app_test_task_benchmark(UArg arg0, UArg arg1);
80 extern void app_test_task_verify_ut_switch(UArg arg0, UArg arg1);
81 /*
82  *  ======== Globals========
83  */
85 const char* rxTaskName[7] =  {"rxPort0","rxPort1","rxPort2","rxPort3","rxPort4","rxPort5","rxPort6"};
86 const char* rxMgmtTaskName[7] =  {"rxMgmtPort0","rxMgmtPort1","rxMgmtPort2","rxMgmtPort3","rxMgmtPort4","rxMgmtPort5","rxMgmtPort6"};
88 #ifdef EMAC_TEST_APP_ICSSG_SWITCH
89 int32_t port_en[EMAC_PORT_CPSW + 1] = {1, 1, 1, 1, 0, 0, 0};
90 #else
91     #ifdef EMAC_TEST_APP_WITHOUT_DDR
92     int32_t port_en[EMAC_PORT_CPSW + 1] = {1, 1, 0, 0, 0, 0, 0};
93     #else
94         #ifdef EMAC_BENCHMARK
95             #ifdef EMAC_TEST_APP_ICSSG
96                 int32_t port_en[EMAC_PORT_CPSW + 1] = {0, 0, 0, 0, 1, 0, 0};
97             #else /* CPSW use case */
98                 int32_t port_en[EMAC_PORT_CPSW + 1] = {0, 0, 0, 0, 0, 0, 1};
99             #endif
100         #else
101             #ifdef EMAC_TEST_APP_ICSSG
102                 int32_t  port_en[EMAC_PORT_CPSW + 1] = {1, 1, 1, 1, 1, 1, 0};
103             #else /* CPSW use case */
104                 int32_t port_en[EMAC_PORT_CPSW + 1] = {0, 0, 0, 0, 0, 0, 1};
105             #endif
106         #endif
107     #endif
108 #endif
110 #ifdef EMAC_TEST_APP_CPSW
111 uint32_t portNum = EMAC_PORT_CPSW;
112 uint32_t endPort = EMAC_PORT_CPSW;
113 #else
114 /* ICSSG case */
115 #ifdef am65xx_idk
116 uint32_t portNum = EMAC_PORT_ICSS;
117 uint32_t endPort = EMAC_PORT_ICSS+5;
118 #else
119 uint32_t portNum = EMAC_PORT_ICSS + 4;
120 uint32_t endPort = EMAC_PORT_ICSS + 5;
121 #endif
122 #endif
123 #ifdef BUILD_MCU
124 uint32_t AsmReadActlr(void);
125 void AsmWriteActlr(uint32_t);
126 #endif
128 /*
129  *  ======== main ========
130  */
131 int main(void)
133     Task_Params     taskParams;
134     Error_Block eb;
135     Error_init(&eb);
137 #ifdef EMAC_TEST_APP_ICSSG_SWITCH
138 #ifndef EMAC_BENCHMARK
139         /* Create the  task start the unit test.*/
140         Task_Params_init(&taskParams);
141         taskParams.priority = 10;
142         taskParams.instance->name = "app_test_task_verify_ut_switch";
143         Task_create( app_test_task_verify_ut_switch, &taskParams, NULL);
144 #else
145         /* Create the  task to start BENCHMARK testing.*/
146         Task_Params_init(&taskParams);
147         taskParams.priority = 11;
148         taskParams.arg0 = EMAC_SWITCH_PORT1;
149         taskParams.instance->name = "app_test_task_benchmark";
150         Task_create( app_test_task_benchmark, &taskParams, NULL);
151 #endif
153 #ifndef EMAC_CHECK_LINK_STATUS
154     /* Create the  task to poll driver to rx pkts.*/
155     /* set the priority to 10 for both polling tasks */
156     taskParams.priority = 10;
158     taskParams.arg0 = EMAC_SWITCH_PORT1;
159     taskParams.instance->name = rxTaskName[0];
160     Task_create(app_test_task_poll_ctrl, &taskParams, NULL);
162     taskParams.arg0 = EMAC_SWITCH_PORT2;
163     taskParams.instance->name = rxTaskName[2];
164     Task_create(app_test_task_poll_ctrl, &taskParams, NULL);
165 #endif
166 #else
167 #ifndef EMAC_BENCHMARK
168     /* Create the  task start the unit test.*/
169     Task_Params_init(&taskParams);
170     taskParams.priority = 10;
171     taskParams.instance->name = "app_test_task_verify_ut_dual_mac_cpsw";
172     Task_create( app_test_task_verify_ut_dual_mac_cpsw, &taskParams, NULL);
173 #else
174     /* Create the  task to start BENCHMARK testing.*/
175     Task_Params_init(&taskParams);
176     taskParams.priority = 10;
177     taskParams.arg0 = EMAC_PORT_ICSS + 4;
178     taskParams.instance->name = "app_test_task_benchmark";
179     Task_create( app_test_task_benchmark, &taskParams, NULL);
180 #endif
182     int i;
183     for (i = portNum; i <=endPort; i++)
184     {
185         /* will poll on app_test_recv_port */
186 #ifdef EMAC_BENCHMARK
187         if ((!port_en[i]) || (i != app_test_recv_port))
188 #else
189         if (!port_en[i])
190 #endif
191             continue;
192             /* Create the  task to poll driver to rx packets driver.*/
193             Task_Params_init(&taskParams);
194             taskParams.arg0 = i;
195             taskParams.priority = 10;
196             taskParams.instance->name = rxTaskName[i];
197             Task_create(app_test_task_poll_pkt, &taskParams, NULL);
199 #ifndef EMAC_BENCHMARK
200             /* Create the  task to poll driver to rx cfg responses.*/
201             Task_Params_init(&taskParams);
202             taskParams.arg0 = i;
203             taskParams.priority = 10;
204             taskParams.instance->name = rxMgmtTaskName[i];
205             Task_create(app_test_task_poll_ctrl, &taskParams, NULL);
206 #endif
207     }
209 #endif
210     {
211 #ifdef BUILD_MCU
212         uint32_t actlrRegVal = AsmReadActlr();
213         actlrRegVal |= (1 << 13);
214         AsmWriteActlr(actlrRegVal);
215 #endif
216     }
217     /* Start BIOS */
218     BIOS_start();
219     return 0;
223 #if defined (__aarch64__)
224 struct MmuCfg_t {
225     uint64_t    vaddr;
226     uint64_t    paddr;
227     size_t      size;
228     int         attrInd;
229 } MmuCfgTbl[] = {
230     { 0x00100000, 0x00100000, 0x00900000, 0 }, /* Main MMR0     */
231     { 0x00400000, 0x00400000, 0x00001000, 0 }, /* PSC0          */
232     { 0x01800000, 0x01800000, 0x00100000, 0 }, /* gicv3         */
233     { 0x02400000, 0x02400000, 0x000c0000, 0 }, /* dmtimer       */
234     { 0x02800000, 0x02800000, 0x00001000, 0 }, /* uart          */
235     { 0x02000000, 0x02000000, 0x00100000, 0 }, /* I2C           */
236     { 0x02100000, 0x02100000, 0x00080000, 0 }, /* McSPI         */
237     { 0x40F00000, 0x40F00000, 0x00020000, 0 }, /* MCU MMR0      */
238     { 0x40d00000, 0x40d00000, 0x00002000, 0 }, /* PLL0          */
239     { 0x43000000, 0x43000000, 0x00020000, 0 }, /* WKUP MMR0     */
240     { 0x02C40000, 0x02C40000, 0x00100000, 0 }, /* pinmux ctrl   */
241     { 0x30800000, 0x30800000, 0x0C000000, 0 }, /* main navss    */
242     { 0x28380000, 0x28380000, 0x03880000, 0 }, /* mcu navss     */
243     { 0x30000000, 0x30000000, 0x0F000000, 0 }, /* ctrcontrol0   */
244     { CSL_MCU_CPSW0_NUSS_BASE, CSL_MCU_CPSW0_NUSS_BASE,
245         (CSL_MCU_CPSW0_NUSS_SIZE*2), 0 },      /* for CPSW      */
246     { 0x0b000000, 0x0b000000, 0x00100000, 0 }, /* ICSS-G 0      */
247     { 0x0b100000, 0x0b100000, 0x00100000, 0 }, /* ICSS-G 1      */
248     { 0x0b200000, 0x0b200000, 0x00100000, 0 }, /* ICSS-G 2      */
249     { 0x42000000, 0x42000000, 0x00001000, 0 }, /* PSC WKUP      */
250     { 0x03802000, 0x03802000, 0x00001000, 0 }, /* NB0_CFG_MMRS  */
251     { 0x70000000, 0x70000000, 0x04000000, 7 }, /* msmc          */
252     { 0x41C00000, 0x41C00000, 0x00080000, 7 }, /* ocmc          */
253     { 0x80000000, 0x80000000, 0x10000000, 7 }, /* ddr_0          */
254     { 0, 0, 0, 8 } /* attrInd = 8 -> end of table */
255 };
257 void InitMmu(void)
259     bool        retVal = FALSE;
260     uint32_t    j = 0;
261     Mmu_MapAttrs attrs;
262     Mmu_initMapAttrs(&attrs);
263     while (MmuCfgTbl[j].attrInd < 8) {
264         attrs.attrIndx = MmuCfgTbl[j].attrInd;
265         retVal = Mmu_map(MmuCfgTbl[j].vaddr, MmuCfgTbl[j].paddr, MmuCfgTbl[j].size, &attrs);
266         if(retVal == FALSE)
267             break;
268         j++;
269     }
271     if(retVal == FALSE) {
272         UART_printf("Mmu_map idx %d returned error %d", j, retVal);
273         while(1);
274     }
276 #endif