2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "tskm_wakeup.h"
18 #include "tskm_debug.h"
19 #include "tskm_util.h"
20 #include "tskm_state.h"
21 #include "tskm_port_subsys.h"
22 #include "tskm_port_pf.h"
24 #include "tskm_gstep.h"
27 /*********************************************************
28 * Get gradual startup context
29 *********************************************************/
30 TSKM_STATIC TSKM_GSTEP_CTX_t*
31 gstepGetWakeupCtx(TSKM_MAIN_CTX_t* p_main) {
32 return &p_main->wakeup;
35 /***********************************************************************
36 * Startup completion process
37 ***********************************************************************/
38 TSKM_STATIC void wakeupFinish(TSKM_MAIN_CTX_t* p_main) {
42 /*********************************************************
43 * Challenge for a transition to the next state
44 *********************************************************/
45 TSKM_STATIC void tryTransNextState(TSKM_MAIN_CTX_t* p_main) {
46 TSKM_GSTEP_CTX_t* p_wakeup;
47 TSKM_GSTEP_t* p_current;
49 p_wakeup = gstepGetWakeupCtx(p_main);
50 p_current = gstepGetCurrent(p_wakeup);
56 // LCOV_EXCL_BR_START 8: Because the second condition in the if statement is never false
57 if (tskm_svcsIsWaiting(&p_main->svcs) == TSKM_FALSE && // No waiting services
58 ((p_wakeup->compState & p_current->nextTransCond)
59 == p_current->nextTransCond)) { // Event completion condition
61 if (gstepIsLast(p_wakeup)) {
62 tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_RUNNING);
64 tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_WAKEUP);
69 /*********************************************************
70 * Gradual startup request issuance process
71 *********************************************************/
72 TSKM_ERR_t tskm_entryWakeup_Req(TSKM_MAIN_CTX_t* p_main,
73 TSKM_GSTEP_t* p_current) {
76 // Refer to the stepId and perform preprocessing if needed.
77 if (p_current->gstepId == TSKM_GSTEP_BUPCHK) {
78 TSKM_PRINTF(TSKM_LOG_STATE, "BUPCHK EXE");
79 // When TaskManager is used as a system Launcher, system data is initialized here.
83 for (ii = 0; ii < p_current->execSvcNum; ii++) {
85 TSKM_SVCID_t svcId = p_current->execSvcIdList[ii];
86 TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, svcId);
88 tskmRet = tskm_svcExec(p_svc);
92 // Issue gradual startup request
93 for (ii = 0; ii < p_current->reqNum; ii++) {
95 TSKM_GSTEP_REQ_INFO_t* p_req = &p_current->reqList[ii];
96 TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, p_req->svcId);
98 // Queuing in the SVC layer even for services that are not started.
99 tskmRet = tskm_svcWakeupRequest(p_svc, p_req);
100 TSKM_ERR_CHK_DFT; // LCOV_EXCL_BR_LINE 6: Because TSKM_ERR_CHK_DFT does not specify a condition for goto to ERROR
103 if (p_current->nextTransCond) {
104 TSKM_PRINTF(TSKM_LOG_STATE, "WAIT COMP:%s(%llx)",
105 tskm_convInitCompId2Str(p_current->nextTransCond),
106 p_current->nextTransCond);
111 // LCOV_EXCL_START 6: Checked in Death testing, but it is not reflected in the coverage and excluded
113 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
118 /*********************************************************
119 * Gradual startup entry process
120 *********************************************************/
121 TSKM_ERR_t tskm_entryWakeup(TSKM_MAIN_CTX_t* p_main) {
124 TSKM_GSTEP_CTX_t* p_wakeup;
125 TSKM_GSTEP_t* p_current;
127 p_main->state = TSKM_ST_WAKEUP;
128 p_wakeup = gstepGetWakeupCtx(p_main);
129 p_current = gstepGetCurrent(p_wakeup);
131 if (p_current == NULL) { // LCOV_EXCL_BR_LINE 8: Because condition false setting is not possible
132 // LCOV_EXCL_START 8: Because condition false setting is not possible
133 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
135 tskm_pf_exit(EXIT_FAILURE);
139 TSKM_PRINTF(TSKM_LOG_SVCSTATE, "WAKEUP GSTEP:%d", p_wakeup->gstepIdx);
141 if (tskm_entryWakeup_Req(p_main, p_current) == TSKM_E_NG) { // LCOV_EXCL_BR_LINE 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length)
142 // LCOV_EXCL_START 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length)
143 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
144 tskm_pf_exit(EXIT_FAILURE);
152 /*********************************************************
153 * Gradual startup exit process
154 *********************************************************/
155 TSKM_ERR_t tskm_exitWakeup(TSKM_MAIN_CTX_t* p_main) {
156 TSKM_GSTEP_CTX_t* p_wakeup;
159 p_wakeup = gstepGetWakeupCtx(p_main);
161 // Exit process at the end of the gradual startup
162 if (gstepIsLast(p_wakeup)) {
163 TSKM_PRINTF(TSKM_LOG_STATE, "WAKEUP FIN");
164 wakeupFinish(p_main);
167 changeNextStep(p_wakeup); // Transition to next step
173 /*********************************************************
174 * Gradual startup handler
175 *********************************************************/
176 TSKM_ERR_t tskm_handleWakeup(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) {
178 TSKM_ERR_t tskmRet = TSKM_E_OK;
180 switch (p_ev->event) {
181 case TSKM_EV_PRI_REP_WAKEUP_COMP: // Event completion notification at startup
183 TSKM_PRINTF(TSKM_LOG_SVCSTATE, "INIT COMP :%s(%#llx) from:%d",
184 tskm_convInitCompId2Str(p_ev->prm.repWakeupComp.compId),
185 p_ev->prm.repWakeupComp.compId, p_ev->fromPid);
186 TSKM_GSTEP_CTX_t* p_wakeup = gstepGetWakeupCtx(p_main);
187 p_wakeup->compState |= p_ev->prm.repWakeupComp.compId;
188 tryTransNextState(p_main);
191 case TSKM_EV_LCL_CHG_SVC_STATE: // Service state change
192 tryTransNextState(p_main);
195 tskmRet = tskm_handleAccon(p_main, p_ev);
200 } // LCOV_EXCL_BR_LINE 10: Final line