1 /*
2 * Copyright (c) 2020-2022 Huawei Device 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
16 #include "example.h"
17 #include <stdint.h>
18 #include <feature.h>
19 #include <securec.h>
20 #include <ohos_init.h>
21 #include <samgr_lite.h>
22 #include <cmsis_os.h>
23 #include "time_adapter.h"
24
25 static const char *GetName(Service *service);
26 static BOOL Initialize(Service *service, Identity identity);
27 static BOOL MessageHandle(Service *service, Request *msg);
28 static TaskConfig GetTaskConfig(Service *service);
29 static Service g_example[] = {
30 {GetName, Initialize, MessageHandle, GetTaskConfig},
31 {GetName, Initialize, MessageHandle, GetTaskConfig},
32 {GetName, Initialize, MessageHandle, GetTaskConfig},
33 {GetName, Initialize, MessageHandle, GetTaskConfig}
34 };
35 static int g_initIndex = 0;
36
GetName(Service * service)37 static const char *GetName(Service *service)
38 {
39 // test cases demo 0
40 if (service == &g_example[0]) {
41 return TASK_SERVICE1;
42 }
43 // test cases demo 1
44 if (service == &g_example[1]) {
45 return TASK_SERVICE2;
46 }
47 // test cases demo 2
48 if (service == &g_example[2]) {
49 return TASK_SERVICE3;
50 }
51 // test cases demo 3
52 if (service == &g_example[3]) {
53 return TASK_SERVICE4;
54 }
55 return NULL;
56 }
57
Initialize(Service * service,Identity identity)58 static BOOL Initialize(Service *service, Identity identity)
59 {
60 (void)identity;
61 printf("[Task Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
62 (int)osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
63 return TRUE;
64 }
65
MessageHandle(Service * service,Request * msg)66 static BOOL MessageHandle(Service *service, Request *msg)
67 {
68 printf("[Task Test][TaskID:%u][Step:%u][S:%s] msgId<%d> \n",
69 (int)osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
70 return FALSE;
71 }
72
GetTaskConfig(Service * service)73 static TaskConfig GetTaskConfig(Service *service)
74 {
75 TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
76 0x800, 5, SHARED_TASK};
77 // test cases demo 0
78 if (service == &g_example[0]) {
79 config.taskFlags = SINGLE_TASK;
80 }
81 // test cases demo 3
82 if (service == &g_example[3]) {
83 config.priority = PRI_ABOVE_NORMAL;
84 }
85 return config;
86 }
87
SInit(Service * demo)88 static void SInit(Service *demo)
89 {
90 SAMGR_GetInstance()->RegisterService(demo);
91
92 printf("[Task Test][TaskID:%u][Step:%u][SYSEX Reg S:%s]Time: %llu!\n",
93 (int)osThreadGetId(), g_initIndex++, demo->GetName(demo), SAMGR_GetProcessTime());
94 }
95
S1Init(void)96 static void S1Init(void)
97 {
98 // test cases demo 0
99 SInit(&g_example[0]);
100 }
101
S2Init(void)102 static void S2Init(void)
103 {
104 // test cases demo 1
105 SInit(&g_example[1]);
106 }
107
S3Init(void)108 static void S3Init(void)
109 {
110 // test cases demo 2
111 SInit(&g_example[2]);
112 }
113
S4Init(void)114 static void S4Init(void)
115 {
116 // test cases demo 3
117 SInit(&g_example[3]);
118 }
119
120 SYSEX_SERVICE_INIT(S1Init);
121 SYSEX_SERVICE_INIT(S2Init);
122 SYSEX_SERVICE_INIT(S3Init);
123 SYSEX_SERVICE_INIT(S4Init);
124