• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "prt_task.h"
32 #include "prt_config.h"
33 
34 #ifndef DRIVERS_HDF
35 #include "lwip/netif.h"
36 #include "lwip.h"
37 #endif
38 
39 #include "securec.h"
40 
41 #ifdef DRIVERS_HDF
42 #include "devmgr_service_start.h"
43 #endif
44 
45 #ifdef LOSCFG_DRIVERS_HDF_TESTS_ENABLE
46 #include "file_test.h"
47 #include "hdf_test_suit.h"
48 #include "osal_all_test.h"
49 #include "gpio_test.h"
50 #include "i2c_test.h"
51 #endif
52 
53 #define BAUDRATE        115200
54 #define DELAY_TIME      1000
55 
56 #ifndef DRIVERS_HDF
57 extern struct netif lwip_netif;
58 #endif
59 
60 extern unsigned long g_data_start;
61 extern unsigned long g_data_end;
62 extern unsigned long data_load_start;
63 
64 extern void SystemInit(void);
65 
66 #ifndef DRIVERS_HDF
67 extern u8 LwipInit(void);
68 #endif
69 
70 extern S32 LfsLowLevelInit(void);
71 extern void OHOS_SystemInit(void);
72 
73 #ifdef __cplusplus
74 #if __cplusplus
75 extern "C" {
76 #endif /* __cpluscplus */
77 #endif /* __cpluscplus */
78 
PRT_HardDrvInit(void)79 U32 PRT_HardDrvInit(void)
80 {
81     UartInit(BAUDRATE);
82     return OS_OK;
83 }
84 
PRT_HardBootInit(void)85 void PRT_HardBootInit(void)
86 {
87     int size = (unsigned long)&g_data_end - (unsigned long)&g_data_start;
88     (void)memcpy_s((void*)&g_data_start, size, (void*)&data_load_start, size);
89 
90     SystemInit();
91 }
92 
GetTaskStatusToStr(TskStatus status)93 static char *GetTaskStatusToStr(TskStatus status)
94 {
95     if (status & OS_TSK_RUNNING) {
96         return (char*)"Running";
97     } else if (status & OS_TSK_SUSPEND) {
98         return (char*)"Suspend";
99     } else if (status & OS_TSK_PEND) {
100         return (char*)"SemPend";
101     } else if (status & OS_TSK_QUEUE_PEND) {
102         return (char*)"QuePend";
103     } else if (status & OS_TSK_EVENT_PEND) {
104         return (char*)"EventPend";
105     } else if (status & OS_TSK_DELAY) {
106         return (char*)"Delay";
107     } else if (status & OS_TSK_READY) {
108         return (char*)"Ready";
109     }
110     return (char *)"Invalid";
111 }
112 
ShowTaskInfo(void)113 static void ShowTaskInfo(void)
114 {
115     struct TskInfo taskInfo;
116     printf(" TID Prio    Status               Name\n");
117     for (U32 id = 0; id < OS_TSK_MAX_SUPPORT_NUM; id++) {
118         memset_s(&taskInfo, sizeof(struct TskInfo), 0, sizeof(struct TskInfo));
119         U32 ret = PRT_TaskGetInfo(id, &taskInfo);
120         if (ret != OS_OK) {
121             continue;
122         }
123         printf("%4u%5u%10s%20s\n", id, taskInfo.taskPrio,
124                                    GetTaskStatusToStr(taskInfo.taskStatus),
125                                    taskInfo.name);
126     }
127 }
128 
OsTskUser1(void)129 static void OsTskUser1(void)
130 {
131     printf("OsTskUser:\n\r");
132 #ifdef LOSCFG_DRIVERS_HDF_TESTS_ENABLE
133     OsaTestBegin();
134     OsaTestEnd();
135     OsaTestALLResult();
136     HdfPlatformEntryTest();
137     HdfPlatformDeviceTest();
138     HdfPlatformDriverTest();
139     HdfPlatformManagerTest();
140     LfsTest();
141     HdfI2cTestAllEntry();
142     HdfGpioTestAllEntry();
143 #endif
144     while (TRUE) {
145         printf("OsTskUser1 loop\n\r");
146         printf("LWIP_DHCP = %d\n\r", LWIP_DHCP);
147 #if (LWIP_DHCP == 1)
148         U32 ip = lwip_netif.ip_addr.u_addr.ip4.addr;
149         U32 ip3 = (uint8_t)(ip >> 24);
150         U32 ip2 = (uint8_t)(ip >> 16);
151         U32 ip1 = (uint8_t)(ip >> 8);
152         U32 ip0 = (uint8_t)(ip);
153         printf("IP.......%d.%d.%d.%d\r\n", ip0, ip1, ip2, ip3);
154 #endif
155         PRT_TaskDelay(DELAY_TIME);
156     }
157 }
158 
OsTskUser2(void)159 static void OsTskUser2(void)
160 {
161     printf("OsTskUser:\n\r");
162 
163     while (TRUE) {
164         printf("    OsTskUser2 loop\n\r");
165         PRT_TaskDelay(DELAY_TIME / 2);  /* 2, delay */
166     }
167 }
168 
TestTask(void)169 void TestTask(void)
170 {
171     printf("TestTask!!!\n");
172 
173     U32 ret;
174     TskHandle taskId1;
175     TskHandle taskId2;
176     struct TskInitParam taskParam1 = {0};
177     struct TskInitParam taskParam2 = {0};
178 
179     taskParam1.taskEntry = (TskEntryFunc)OsTskUser1;
180     taskParam1.stackSize = 0x800;
181     taskParam1.name = "UserTask1";
182     taskParam1.taskPrio = OS_TSK_PRIORITY_05;
183     taskParam1.stackAddr = 0;
184 
185     taskParam2.taskEntry = (TskEntryFunc)OsTskUser2;
186     taskParam2.stackSize = 0x800;
187     taskParam2.name = "UserTask2";
188     taskParam2.taskPrio = OS_TSK_PRIORITY_05;
189     taskParam2.stackAddr = 0;
190 
191     ret = PRT_TaskCreate(&taskId1, &taskParam1);
192     if (ret != OS_OK) {
193         return ret;
194     }
195 
196     ret = PRT_TaskResume(taskId1);
197     if (ret != OS_OK) {
198         return ret;
199     }
200 
201     ret = PRT_TaskCreate(&taskId2, &taskParam2);
202     if (ret != OS_OK) {
203         return ret;
204     }
205 #ifndef DRIVERS_HDF
206     ret = PRT_TaskResume(taskId2);
207 #endif
208     if (ret != OS_OK) {
209         return ret;
210     }
211 }
212 
PRT_AppInit(void)213 U32 PRT_AppInit(void)
214 {
215     printf("PRT_AppInit!\n");
216 #ifdef DRIVERS_HDF
217     DeviceManagerStart();
218 #else
219     FsInit();
220 
221     LwipInit();
222 #endif
223     OHOS_SystemInit();
224     return OS_OK;
225 }
226 
227 #ifdef __cplusplus
228 #if __cplusplus
229 }
230 #endif /* __cpluscplus */
231 #endif /* __cpluscplus */
232