1 /* 2 * Copyright (c) 2022 Talkweb Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <stdio.h> 16 #include "los_task.h" 17 #include "los_compiler.h" 18 #include "cmsis_os2.h" 19 #include "samgr_lite.h" 20 #include "ohos_init.h" 21 #include "ohos_types.h" 22 #include "watch_dog.h" 23 24 #define TALKWEB_SERVICE_STACKSIZE (4096) 25 #define TALKWEB_SERVICE_TASK_PRIOR 26 26 #define TALKWEB_SERVICE_TASK_NAME "talkweb_sys_service" 27 #define TALKWEB_SERVICE_TASK_DELAY 1000 28 ohos_app_main(void)29__attribute__((weak)) void ohos_app_main(void) 30 { 31 printf("No application run, Maybe you should config your application in BUILD.gn!\n"); 32 return; 33 } 34 before_ohos_run(void)35__attribute__((weak)) void before_ohos_run(void) 36 { 37 return; 38 } 39 talkweb_sys_service(void)40static void talkweb_sys_service(void) 41 { 42 sys_service_config(); 43 44 ohos_app_main(); 45 46 while (1) { 47 feed_dog(); 48 LOS_TaskDelay(TALKWEB_SERVICE_TASK_DELAY); 49 } 50 } 51 OHOS_Main(void)52static void OHOS_Main(void) 53 { 54 UINT32 uwRet = -1; 55 UINT32 taskID = 0; 56 TSK_INIT_PARAM_S stTask = {0}; 57 stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)talkweb_sys_service; 58 stTask.uwStackSize = TALKWEB_SERVICE_STACKSIZE; 59 stTask.pcName = TALKWEB_SERVICE_TASK_NAME; 60 stTask.usTaskPrio = TALKWEB_SERVICE_TASK_PRIOR; /* Os task priority is 6 */ 61 uwRet = LOS_TaskCreate(&taskID, &stTask); 62 if (uwRet != LOS_OK) { 63 printf("Task1 create failed\n"); 64 } 65 } 66 67 /** 68 * @brief This is the ohos entry, and you could call this in your main funciton after the 69 * necessary hardware has been initialized. 70 */ OHOS_Boot(void)71void OHOS_Boot(void) 72 { 73 UINT32 ret; 74 75 before_ohos_run(); 76 77 ret = LOS_KernelInit(); 78 if (ret == LOS_OK) { 79 OHOS_SystemInit(); 80 LOS_Start(); 81 } 82 return; // and should never come here 83 } 84 85 SYS_RUN(OHOS_Main);