summaryrefslogtreecommitdiffstats
path: root/task_manager/server/src/tskm_wakeup.cpp
blob: b5c6e896eaf27f14a1276be4cec6e2f87fc12aac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "tskm_wakeup.h"
#include "tskm_debug.h"
#include "tskm_util.h"
#include "tskm_state.h"
#include "tskm_port_subsys.h"
#include "tskm_port_pf.h"

#include "tskm_gstep.h"


/*********************************************************
 *        Get gradual startup context
 *********************************************************/
TSKM_STATIC TSKM_GSTEP_CTX_t*
gstepGetWakeupCtx(TSKM_MAIN_CTX_t* p_main) {
  return &p_main->wakeup;
}

/***********************************************************************
 *        Startup completion process
 ***********************************************************************/
TSKM_STATIC void wakeupFinish(TSKM_MAIN_CTX_t* p_main) {
  return;
}

/*********************************************************
 *        Challenge for a transition to the next state
 *********************************************************/
TSKM_STATIC void tryTransNextState(TSKM_MAIN_CTX_t* p_main) {
  TSKM_GSTEP_CTX_t* p_wakeup;
  TSKM_GSTEP_t* p_current;

  p_wakeup = gstepGetWakeupCtx(p_main);
  p_current = gstepGetCurrent(p_wakeup);

  if (!p_current) {
    return;
  }

  // LCOV_EXCL_BR_START 8: Because the second condition in the if statement is never false
  if (tskm_svcsIsWaiting(&p_main->svcs) == TSKM_FALSE &&  // No waiting services
      ((p_wakeup->compState & p_current->nextTransCond)
          == p_current->nextTransCond)) {  // Event completion condition
    // LCOV_EXCL_BR_STOP
    if (gstepIsLast(p_wakeup)) {
      tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_RUNNING);
    } else {
      tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_WAKEUP);
    }
  }
}

/*********************************************************
 *        Gradual startup request issuance process
 *********************************************************/
TSKM_ERR_t tskm_entryWakeup_Req(TSKM_MAIN_CTX_t* p_main,
                                TSKM_GSTEP_t* p_current) {
  uint32_t ii;

  // Refer to the stepId and perform preprocessing if needed.
  if (p_current->gstepId == TSKM_GSTEP_BUPCHK) {
    TSKM_PRINTF(TSKM_LOG_STATE, "BUPCHK EXE");
    // When TaskManager is used as a system Launcher, system data is initialized here.
  }

  // Start process
  for (ii = 0; ii < p_current->execSvcNum; ii++) {
    TSKM_ERR_t tskmRet;
    TSKM_SVCID_t svcId = p_current->execSvcIdList[ii];
    TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, svcId);

    tskmRet = tskm_svcExec(p_svc);
    TSKM_ERR_CHK_DFT;
  }

  // Issue gradual startup request
  for (ii = 0; ii < p_current->reqNum; ii++) {
    TSKM_ERR_t tskmRet;
    TSKM_GSTEP_REQ_INFO_t* p_req = &p_current->reqList[ii];
    TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, p_req->svcId);

    // Queuing in the SVC layer even for services that are not started.
    tskmRet = tskm_svcWakeupRequest(p_svc, p_req);
    TSKM_ERR_CHK_DFT;  // LCOV_EXCL_BR_LINE 6: Because TSKM_ERR_CHK_DFT does not specify a condition for goto to ERROR
  }

  if (p_current->nextTransCond) {
    TSKM_PRINTF(TSKM_LOG_STATE, "WAIT COMP:%s(%llx)",
                tskm_convInitCompId2Str(p_current->nextTransCond),
                p_current->nextTransCond);
  }

  return TSKM_E_OK;

  // LCOV_EXCL_START 6: Checked in Death testing, but it is not reflected in the coverage and excluded
  ERROR:
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  return TSKM_E_NG;
  // LCOV_EXCL_STOP
}

/*********************************************************
 *        Gradual startup entry process
 *********************************************************/
TSKM_ERR_t tskm_entryWakeup(TSKM_MAIN_CTX_t* p_main) {
  TSKM_FUNC_IN();

  TSKM_GSTEP_CTX_t* p_wakeup;
  TSKM_GSTEP_t* p_current;

  p_main->state = TSKM_ST_WAKEUP;
  p_wakeup = gstepGetWakeupCtx(p_main);
  p_current = gstepGetCurrent(p_wakeup);

  if (p_current == NULL) {  // LCOV_EXCL_BR_LINE 8: Because condition false setting is not possible
    // LCOV_EXCL_START 8: Because condition false setting is not possible
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    TSKM_ASSERT(0);
    tskm_pf_exit(EXIT_FAILURE);
    // LCOV_EXCL_STOP
  }

  TSKM_PRINTF(TSKM_LOG_SVCSTATE, "WAKEUP GSTEP:%d", p_wakeup->gstepIdx);

  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)
    // LCOV_EXCL_START 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length)
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    tskm_pf_exit(EXIT_FAILURE);
    // LCOV_EXCL_STOP
  }

  TSKM_FUNC_OUT();
  return TSKM_E_OK;
}

/*********************************************************
 *        Gradual startup exit process
 *********************************************************/
TSKM_ERR_t tskm_exitWakeup(TSKM_MAIN_CTX_t* p_main) {
  TSKM_GSTEP_CTX_t* p_wakeup;

  TSKM_FUNC_IN();
  p_wakeup = gstepGetWakeupCtx(p_main);

  // Exit process at the end of the gradual startup
  if (gstepIsLast(p_wakeup)) {
    TSKM_PRINTF(TSKM_LOG_STATE, "WAKEUP FIN");
    wakeupFinish(p_main);
  }

  changeNextStep(p_wakeup);  // Transition to next step

  TSKM_FUNC_OUT();
  return TSKM_E_OK;
}

/*********************************************************
 *        Gradual startup handler
 *********************************************************/
TSKM_ERR_t tskm_handleWakeup(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) {
  TSKM_FUNC_IN();
  TSKM_ERR_t tskmRet = TSKM_E_OK;

  switch (p_ev->event) {
    case TSKM_EV_PRI_REP_WAKEUP_COMP:  // Event completion notification at startup
    {
      TSKM_PRINTF(TSKM_LOG_SVCSTATE, "INIT COMP :%s(%#llx) from:%d",
                  tskm_convInitCompId2Str(p_ev->prm.repWakeupComp.compId),
                  p_ev->prm.repWakeupComp.compId, p_ev->fromPid);
      TSKM_GSTEP_CTX_t* p_wakeup = gstepGetWakeupCtx(p_main);
      p_wakeup->compState |= p_ev->prm.repWakeupComp.compId;
      tryTransNextState(p_main);
    }
      break;
    case TSKM_EV_LCL_CHG_SVC_STATE:  // Service state change
      tryTransNextState(p_main);
      break;
    default:
      tskmRet = tskm_handleAccon(p_main, p_ev);
      break;
  }
  TSKM_FUNC_OUT();
  return tskmRet;
}  // LCOV_EXCL_BR_LINE 10: Final line