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.
21 /*---------------------------------------------------------------------------------*
23 *---------------------------------------------------------------------------------*/
24 #include <native_service/frameworkunified_framework_if.h>
26 #include <native_service/ns_message_center_if.h>
28 #include <vehicle_service/positioning_base_library.h>
29 #include "TimerEntryDrv_If.h"
30 #include "DEV_TimerEntryDrv_if.h"
32 #include <native_service/ns_timer_if.h>
33 #include "WPF_STD_private.h"
36 /*---------------------------------------------------------------------------------*
38 *---------------------------------------------------------------------------------*/
39 #define MAX_CTRL_TIMER_NUM (8)
41 #define CID_TIMER_1 (0x1000)
42 #define CID_TIMER_2 (0x1001)
43 #define CID_TIMER_3 (0x1002)
44 #define CID_TIMER_4 (0x1003)
45 #define CID_TIMER_5 (0x1004)
46 #define CID_TIMER_6 (0x1005)
47 #define CID_TIMER_7 (0x1006)
48 #define CID_TIMER_8 (0x1007)
50 #define TIMER_MAKE_DEFAULT_MESSAGE(x) \
51 (x)->Header.signo = 0; \
52 (x)->Header.hdr.sndpno = 0; \
53 (x)->Header.hdr.respno = 0; \
54 (x)->Header.hdr.cid = CID_TIMER_TOUT; \
55 (x)->Header.hdr.msgbodysize = \
56 static_cast<uint16_t>(sizeof(TimerToutMsg) - sizeof(T_APIMSG_MSGBUF_HEADER)); \
57 (x)->Header.hdr.rid = 0; \
58 (x)->Header.hdr.reserve = 0; \
61 /*---------------------------------------------------------------------------------*
63 *---------------------------------------------------------------------------------*/
65 @brief Timer control information
68 CID cid; /**< Command ID */
69 HANDLE h_timer; /**< Timer handle */
70 TimerToutMsg msg_buf; /**< Message buffer */
71 uint16_t size; /**< Message size */
72 PNO pno; /**< Process number */
73 uint16_t seq_no; /**< Timer Sequence Number */
74 uint8_t type; /**< Timer type */
75 uint32_t time_out; /**< Timeout */
78 /*---------------------------------------------------------------------------------*
79 * Local Function Prototype *
80 *---------------------------------------------------------------------------------*/
81 /* Timer control table manipulation functions */
82 static void TimerSetCidOfCtrlTbl(u_int32 idx, CID cid); /* Set timer CID */
83 static CID TimerGetCidOfCtrlTbl(u_int32 idx); /* Get timer CID */
84 static void TimerSetPnoOfCtrlTbl(u_int32 idx, PNO pno); /* Set PNO */
85 static PNO TimerGetPnoOfCtrlTbl(u_int32 idx); /* Get PNO */
86 static void TimerSetSizeOfCtrlTbl(u_int32 idx, u_int16 size); /* Set message size */
87 static TimerToutMsg* TimerGetMsgBufOfCtrlTbl(u_int32 idx); /* Get message buffer */
88 static void TimerSetTimerHandleOfCtrlTbl(u_int32 idx, HANDLE handle); /* Set timer handle */
89 static HANDLE TimerGetTimerHandleOfCtrlTbl(u_int32 idx); /* Get timer handle */
90 static void TimerSetTypeOfCtrlTbl(u_int32 idx, u_int8 type); /* Set timer type */
91 static u_int8 TimerGetTypeOfCtrlTbl(u_int32 idx); /* Get timer type */
92 static void TimerSetSeqNoOfCtrlTbl(u_int32 idx, u_int16 seq_no); /* Set timer Sequence Number */
93 static u_int16 TimerGetSeqNoOfCtrlTbl(u_int32 idx); /* Get timer sequence number */
94 static void TimerSetTimeOutOfCtrlTbl(u_int32 idx, u_int32 time_out); /* Set timeout */
95 static u_int32 TimerGetTimeOutOfCtrlTbl(u_int32 idx); /* Get timeout */
96 static u_int32 TimerSearchEmptyOfCtrlTbl(void); /* Search unused area */
97 static u_int32 TimerSearchTimerOfCtrlTbl(PNO snd_pno, u_int16 timer_seq, u_int8 time_type); /* Search specified timer */
98 static void TimerClearSettingOfCtrlTbl(u_int32 idx); /* Clear timer information */
100 /* Mutex handling Functions for accessing Timer Control Table */
101 static void TimerCreateMutex(void); /* Create Mutex */
102 static void TimerDeleteMutex(void); /* Delete Mutex */
103 static void TimerLockMutex(void); /* Get Mutex */
104 static void TimerUnlockMutex(void); /* Release Mutex */
106 /* Callback function resources */
107 static EFrameworkunifiedStatus TimerCallback1(HANDLE h_app);
108 static EFrameworkunifiedStatus TimerCallback2(HANDLE h_app);
109 static EFrameworkunifiedStatus TimerCallback3(HANDLE h_app);
110 static EFrameworkunifiedStatus TimerCallback4(HANDLE h_app);
111 static EFrameworkunifiedStatus TimerCallback5(HANDLE h_app);
112 static EFrameworkunifiedStatus TimerCallback6(HANDLE h_app);
113 static EFrameworkunifiedStatus TimerCallback7(HANDLE h_app);
114 static EFrameworkunifiedStatus TimerCallback8(HANDLE h_app);
116 static void TimerCallbackComProc(const uint8_t id);
118 /*---------------------------------------------------------------------------------*
120 *---------------------------------------------------------------------------------*/
123 Note : Access to this instance shall be made through the operation module.
125 static TIMER_CTRL_INFO g_timer_ctrl_tbl[MAX_CTRL_TIMER_NUM]; // NOLINT(readability/nolint) global class instance
127 /** Timer control table lock Mutex handle */
128 static HANDLE g_h_mtx = NULL;
130 /** Timer event destination handle */
131 static HANDLE g_h_service;
134 /** Dispatcher Registration Callback Table */
135 static const FrameworkunifiedProtocolCallbackHandler kTimerPcbhs[] = {
136 {CID_TIMER_1, &TimerCallback1 },
137 {CID_TIMER_2, &TimerCallback2 },
138 {CID_TIMER_3, &TimerCallback3 },
139 {CID_TIMER_4, &TimerCallback4 },
140 {CID_TIMER_5, &TimerCallback5 },
141 {CID_TIMER_6, &TimerCallback6 },
142 {CID_TIMER_7, &TimerCallback7 },
143 {CID_TIMER_8, &TimerCallback8 },
144 }; // LCOV_EXCL_BR_LINE 11:unexpected branch
146 /*---------------------------------------------------------------------------------*
148 *---------------------------------------------------------------------------------*/
151 * Timer function initialization
153 * @return RET_NORMAL Normal completion
154 * @return RET_ERROR ABEND
156 RET_API TimerInit(HANDLE h_app) {
157 RET_API ret_api = RET_NORMAL;
160 EFrameworkunifiedStatus estatus;
161 NSTimerInfo timer_info;
162 HANDLE* p_h_service = &g_h_service;
164 if (h_app == NULL) { // LCOV_EXCL_BR_LINE 6: h_app cannot be Null
165 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR!! [h_app=%p]", h_app);
166 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
167 ret_api = RET_ERROR; // LCOV_EXCL_LINE 6: h_app cannot be Null
169 memset(&timer_info, 0x00, sizeof(timer_info));
172 TimerCreateMutex(); // LCOV_EXCL_BR_LINE 200: no branch
174 /* Register callback function for timer control */
175 // LCOV_EXCL_BR_LINE 4: nsfw error
176 estatus = FrameworkunifiedAttachCallbacksToDispatcher(h_app, "NS_ANY_SRC", kTimerPcbhs, _countof(kTimerPcbhs)); // LCOV_EXCL_BR_LINE 4: nsfw error // NOLINT(whitespace/line_length)
177 if (estatus != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: nsfw error
178 /* When registration fails */
179 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
180 "FrameworkunifiedAttachCallbacksToDispatcher ERROR [status:%d]", estatus);
181 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
182 ret_api = RET_ERROR; // LCOV_EXCL_LINE 4: nsfw error
185 /* Initialization of timer control table */
186 for (idx = 0; idx < MAX_CTRL_TIMER_NUM; idx++) {
187 TimerSetCidOfCtrlTbl(idx, static_cast<CID>(kTimerPcbhs[idx].iCmd)); /* Set timer control CID */ // LCOV_EXCL_BR_LINE 200: no branch // NOLINT(whitespace/line_length)
189 /* Initialize timeout */
190 TimerSetTimeOutOfCtrlTbl(idx, 0); // LCOV_EXCL_BR_LINE 200: no branch
192 *p_h_service = McOpenSender("Positioning"); /* Be intended for use only in Positioning */ // LCOV_EXCL_BR_LINE 4: nsfw error // NOLINT(whitespace/line_length)
194 /* Create Timer Resource */
195 timer_info.iCmd = TimerGetCidOfCtrlTbl(idx); /* Only CID needs to be set. */ // LCOV_EXCL_BR_LINE 200: no branch
196 h_timer = NS_TimerCreate(timer_info, CALLBACK_MESSAGE, (HANDLE)*p_h_service); // LCOV_EXCL_BR_LINE 4: nsfw error // NOLINT(whitespace/line_length)
197 if (h_timer == NULL) { // LCOV_EXCL_BR_LINE 4: nsfw error
198 // LCOV_EXCL_START 4: nsfw error
199 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
200 /* When an error occurs */
201 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
202 "NS_TimerCreate ERROR [h_timer:%p, hService:%p]", h_timer, *p_h_service);
207 /* Set Handle information */
208 TimerSetTimerHandleOfCtrlTbl(idx, h_timer); // LCOV_EXCL_BR_LINE 200: no branch
218 * Terminate timer function
220 * @return Normal completion
222 RET_API TimerTerm(void) { // LCOV_EXCL_START 8:dead code
223 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
224 RET_API ret_api = RET_NORMAL;
227 EFrameworkunifiedStatus estatus;
228 HANDLE* p_h_service = &g_h_service;
230 /* If a control Mutex has not been created, it is determined that the Timer function has not been initialized (non Positioning processes) and the process terminates with an error. */
231 if (g_h_mtx == NULL) {
232 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "g_h_mtx is NULL!!");
235 /* Delete timer control information */
236 for (idx = 0; idx < MAX_CTRL_TIMER_NUM; idx++) {
237 h_timer = TimerGetTimerHandleOfCtrlTbl(idx);
238 if (h_timer != NULL) {
240 estatus = NS_TimerDelete(h_timer);
241 if (estatus != eFrameworkunifiedStatusOK) {
242 /* When an error occurs */
243 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
244 "NS_TimerDelete ERROR [estatus:%d, h_timer:%p]", estatus, h_timer);
246 TimerSetTimerHandleOfCtrlTbl(idx, NULL);
249 TimerClearSettingOfCtrlTbl(idx);
256 /* Delete transmission handle */
257 estatus = McClose(*p_h_service);
258 if (estatus != eFrameworkunifiedStatusOK) {
259 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McClose ERROR [estatus:%d, hService:%p]", \
260 estatus, *p_h_service);
269 * Fixed period/asynchronous timer start instruction
271 * @param[in] snd_pno Requesting process number
272 * @param[in] timer_seq Timer sequence number
273 * @param[in] TimerType Timer type
274 * @param[in] time_out Timeout value [10ms]
276 * @return RET_NORMAL Normal completion<br>
277 * RET_ERROR Message transmission error<br>
278 * RET_ERRPARAM Parameter error
280 RET_API _pb_ReqTimerStart(PNO snd_pno, u_int16 timer_seq, // NOLINT(readability/nolint) WPF_SYSAPI.h API
281 u_int8 time_type, u_int32 time_out) {
282 RET_API ret_api = RET_NORMAL; /* Return value of this module */
285 EFrameworkunifiedStatus estatus;
287 NSTimerInfo timer_info;
289 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
291 /* If a control Mutex has not been created, it is determined that the Timer function has not been initialized (non Positioning processes) and the process terminates with an error. */
292 if (g_h_mtx == NULL) { // LCOV_EXCL_BR_LINE 6: g_h_mtx cannot be null
293 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "g_h_mtx is NULL!!");
294 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
295 ret_api = RET_ERROR; // LCOV_EXCL_LINE 6: g_h_mtx cannot be null
297 /* Parameter study */
298 if ((time_type != TIMER_TYPE_SYN) && (time_type != TIMER_TYPE_USN)) {
299 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [time_type:%d]", time_type);
300 ret_api = RET_ERRPARAM; /* Timer type error */
304 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [time_out:%d]", time_out);
305 ret_api = RET_ERRPARAM; /* Timer setting value error */
308 /* When a timer of the same process number, sequence number, or type is already registered, creation of the timer is not allowed. */
309 idx = TimerSearchTimerOfCtrlTbl(snd_pno, timer_seq, time_type);
310 if (idx != MAX_CTRL_TIMER_NUM) {
311 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TimerSearchTimerOfCtrlTbl ERROR!! " \
312 "[snd_pno:%d, timer_seq:%d, TimeType:%d]", snd_pno, timer_seq, time_type);
313 ret_api = RET_ERRPARAM; /* Invalid timer value */
316 /* Parameter normal */
317 if (ret_api == RET_NORMAL) {
318 TimerLockMutex(); /* Get Mutex */
320 /* Get free space in timer control table */
321 idx = TimerSearchEmptyOfCtrlTbl(); // LCOV_EXCL_BR_LINE 200: no branch
322 if (idx == MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 200: idx can not be MAX_CTRL_TIMER_NUM
323 // LCOV_EXCL_START 200: idx can not be MAX_CTRL_TIMER_NUM
324 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
325 /* When there is no free space */
326 /* Be impossible by design */
327 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TimerSearchEmptyCtrlTbl ERROR!! " \
330 /* don't arrive here. */
334 /* Get message buffer address */
335 p_msg = TimerGetMsgBufOfCtrlTbl(idx);
337 TIMER_MAKE_DEFAULT_MESSAGE(p_msg); /* Set message data to be send */
338 p_msg->TimerSeq = timer_seq; /* Timer sequence number */
340 /* Set callback function information in timer control table */
341 TimerSetPnoOfCtrlTbl(idx, snd_pno); // LCOV_EXCL_BR_LINE 200: no branch
342 TimerSetSizeOfCtrlTbl(idx, sizeof(TimerToutMsg)); // LCOV_EXCL_BR_LINE 200: no branch
343 TimerSetTypeOfCtrlTbl(idx, time_type); // LCOV_EXCL_BR_LINE 200: no branch
344 TimerSetSeqNoOfCtrlTbl(idx, timer_seq); // LCOV_EXCL_BR_LINE 200: no branch
345 TimerSetTimeOutOfCtrlTbl(idx, time_out); // LCOV_EXCL_BR_LINE 200: no branch
347 /* Set timer value */
348 timer_info.t_sec = (uint32_t)((10 * time_out) / 1000);
349 /* Coverity CID: 21979 compliant */
350 timer_info.t_nsec = ((10 * (uint64_t)time_out) - ((uint64_t)(timer_info.t_sec) * 1000)) * 1000 * 1000;
351 timer_info.iCmd = TimerGetCidOfCtrlTbl(idx);
352 timer_info.rpt_sec = 0;
353 timer_info.rpt_nsec = 0;
354 if (time_type == TIMER_TYPE_SYN) {
355 timer_info.rpt_sec = timer_info.t_sec;
356 timer_info.rpt_nsec = timer_info.t_nsec;
359 h_timer = TimerGetTimerHandleOfCtrlTbl(idx);
362 estatus = NS_TimerSetTime(h_timer, timer_info); // LCOV_EXCL_BR_LINE 4: nsfw error
363 if ((h_timer == NULL) || (estatus != eFrameworkunifiedStatusOK)) { // LCOV_EXCL_BR_LINE 4: nsfw error
364 // LCOV_EXCL_START 4: nsfw error
365 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
366 /* When an error occurs */
367 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NS_TimerSetTime ERROR " \
368 "[estatus:%d, h_timer:%p]", estatus, h_timer);
370 TimerClearSettingOfCtrlTbl(idx); /* Clear timer information */
375 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### TIMER TABLE INFORMATION # " \
376 "(++) idx:%d cid:%d h_timer:%p pno:%d seq_no:%d type:%d time_out:%d", \
377 idx, g_timer_ctrl_tbl[idx].cid, g_timer_ctrl_tbl[idx].h_timer, g_timer_ctrl_tbl[idx].pno, \
378 g_timer_ctrl_tbl[idx].seq_no, g_timer_ctrl_tbl[idx].type, g_timer_ctrl_tbl[idx].time_out);
381 TimerUnlockMutex(); /* Release Mutex */ // LCOV_EXCL_BR_LINE 200: no branch
385 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
392 * Timer stop instruction
394 * @param[in] snd_pno Requesting process number
395 * @param[in] timer_seq Timer sequence number
396 * @param[in] time_r_type Timer type<br>
397 * TIMER_TYPE_SYN Fixed-period timer<br>
398 * TIMER_TYPE_USN Asynchronous timer<br>
399 * TIMER_TYPE_ALM Alerm with specified time <br>
401 * @return RET_NORMAL Normal completion<br>
402 * RET_ERROR Message transmission error<br>
403 * RET_ERRPARAM Parameter error
405 RET_API _pb_TimerStop(PNO snd_pno, u_int16 timer_seq, // NOLINT(readability/nolint) WPF_SYSAPI.h API
407 RET_API ret_api = RET_NORMAL; /* Return value of this module */
409 EFrameworkunifiedStatus estatus;
411 const NSTimerInfo timer_info = {0};
413 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
415 /* If a control Mutex has not been created, it is determined that the Timer function has not been initialized (non Positioning processes) and the process terminates with an error. */
416 if (g_h_mtx == NULL) { // LCOV_EXCL_BR_LINE 6: g_h_mtx cannot be NULL
417 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "g_h_mtx is NULL!!");
418 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
419 ret_api = RET_ERROR; // LCOV_EXCL_LINE 6: g_h_mtx cannot be NULL
421 TimerLockMutex(); /* Get Mutex */ // LCOV_EXCL_BR_LINE 200: no branch
423 idx = TimerSearchTimerOfCtrlTbl(snd_pno, timer_seq, time_type);
424 if (idx == MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 200: idx can not be MAX_CTRL_TIMER_NUM
425 /* When the specified timer is not set */
428 h_timer = TimerGetTimerHandleOfCtrlTbl(idx);
431 estatus = NS_TimerSetTime(h_timer, timer_info); // LCOV_EXCL_BR_LINE 4: nsfw error
432 if (estatus != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: nsfw error
433 // LCOV_EXCL_START 4: nsfw error
434 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
435 /* When deletion fails */
436 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NS_TimerSetTime ERROR " \
437 "[estatus:%d, h_timer:%p]", estatus, h_timer);
442 /* Clear timer information */
443 TimerClearSettingOfCtrlTbl(idx); // LCOV_EXCL_BR_LINE 200: no branch
445 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### TIMER TABLE INFORMATION # " \
446 "(--) idx:%d cid:%d h_timer:%p pno:%d seq_no:%d type:%d time_out:%d", \
447 idx, g_timer_ctrl_tbl[idx].cid, g_timer_ctrl_tbl[idx].h_timer, g_timer_ctrl_tbl[idx].pno, \
448 g_timer_ctrl_tbl[idx].seq_no, g_timer_ctrl_tbl[idx].type, g_timer_ctrl_tbl[idx].time_out);
452 TimerUnlockMutex(); /* Release Mutex */ // LCOV_EXCL_BR_LINE 200: no branch
455 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
460 /*---------------------------------------------------------------------------------*
462 *---------------------------------------------------------------------------------*/
465 * Timer CID setting (Timer control table)
467 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
469 * @param[in] idx Control table accessor
470 * @param[in] cid Command ID
472 static void TimerSetCidOfCtrlTbl(u_int32 idx, CID cid) {
474 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
476 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
477 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
478 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
479 /* don't arrive here. */
481 g_timer_ctrl_tbl[idx].cid = cid;
489 * Timer CID acquisition (Timer control table)
491 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
493 * @param[in] idx Timer control table accessor
497 static CID TimerGetCidOfCtrlTbl(u_int32 idx) {
499 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
501 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
502 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
503 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
504 /* don't arrive here. */
507 return g_timer_ctrl_tbl[idx].cid;
512 * PNO setting (Timer control table)
514 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
516 * @param[in] idx Timer control table accessor
517 * @param[in] pno Process number
519 static void TimerSetPnoOfCtrlTbl(u_int32 idx, PNO pno) {
521 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
523 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR " \
524 "[idx:%d, pno:%d]", idx, pno);
525 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
526 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
527 /* don't arrive here. */
529 g_timer_ctrl_tbl[idx].pno = pno;
537 * PNO acquisition (Timer control table)
539 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
541 * @param[in] idx Timer control table accessor
543 * @return Process number
545 static PNO TimerGetPnoOfCtrlTbl(u_int32 idx) {
547 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
549 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
550 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
551 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
552 /* don't arrive here. */
555 return g_timer_ctrl_tbl[idx].pno;
560 * Message size setting (Timer control table)
562 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
564 * @param[in] idx Timer control table accessor
565 * @param[in] size Message size
567 static void TimerSetSizeOfCtrlTbl(u_int32 idx, u_int16 size) {
569 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
571 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR " \
572 "[idx:%d, size:%d]", idx, size);
573 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
574 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
575 /* don't arrive here. */
577 g_timer_ctrl_tbl[idx].size = size;
585 * Message buffer acquisition (Timer control table)
587 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
589 * @param[in] idx Timer control table accessor
591 * @return Pointer to message storage area
593 static TimerToutMsg* TimerGetMsgBufOfCtrlTbl(u_int32 idx) {
595 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
597 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
598 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
599 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
600 /* don't arrive here. */
603 return &(g_timer_ctrl_tbl[idx].msg_buf);
608 * Timer handle setting (Timer control table)
610 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
612 * @param[in] idx Timer control table accessor
613 * @param[in] handle Timer handle
615 static void TimerSetTimerHandleOfCtrlTbl(u_int32 idx, HANDLE handle) {
617 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
619 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR " \
620 "[idx:%d, handle:%p]", idx, handle);
621 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
622 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
623 /* don't arrive here. */
625 g_timer_ctrl_tbl[idx].h_timer = handle;
633 * Timer handle acquisition (Timer control table)
635 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
637 * @param[in] idx Timer control table accessor
639 * @return Timer handle
641 static HANDLE TimerGetTimerHandleOfCtrlTbl(u_int32 idx) {
643 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
645 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
646 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
647 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
648 /* don't arrive here. */
651 return g_timer_ctrl_tbl[idx].h_timer;
656 * Timer type setting (Timer control table)
658 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
660 * @param[in] idx Timer control table accessor
661 * @param[in] type Timer type
663 static void TimerSetTypeOfCtrlTbl(u_int32 idx, u_int8 type) {
665 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
667 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR " \
668 "[idx:%d, type:%d]", idx, type);
669 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
670 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
671 /* don't arrive here. */
673 g_timer_ctrl_tbl[idx].type = type;
681 * Timer type acquisition (Timer control table)
683 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
685 * @param[in] idx Timer control table accessor
687 * @return Timer handle
689 static u_int8 TimerGetTypeOfCtrlTbl(u_int32 idx) {
691 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
693 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
694 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
695 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
696 /* don't arrive here. */
699 return g_timer_ctrl_tbl[idx].type;
704 * Timer sequence number setting (Timer control table)
706 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
708 * @param[in] idx Timer control table accessor
709 * @param[in] seq_no Timer Sequence Number
711 static void TimerSetSeqNoOfCtrlTbl(u_int32 idx, u_int16 seq_no) {
713 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
715 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR " \
716 "[idx:%d, seq_no:%d]", idx, seq_no);
717 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
718 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
719 /* don't arrive here. */
721 g_timer_ctrl_tbl[idx].seq_no = seq_no;
729 * Timer sequence number acquisition (Timer control table)
731 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
733 * @param[in] idx Timer control table accessor
735 static u_int16 TimerGetSeqNoOfCtrlTbl(u_int32 idx) {
737 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
739 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
740 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
741 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
742 /* don't arrive here. */
745 return g_timer_ctrl_tbl[idx].seq_no;
750 * Timeout setting (Timer control table)
752 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
754 * @param[in] idx Timer control table access Index
755 * @param[in] time_out Timeout
757 static void TimerSetTimeOutOfCtrlTbl(u_int32 idx, u_int32 time_out) {
759 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
761 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d, " \
762 "time_out:%d]", idx, time_out);
763 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
764 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
765 /* don't arrive here. */
767 g_timer_ctrl_tbl[idx].time_out = time_out;
775 * Timeout acquisition (Timer control table)
777 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
779 * @param[in] idx Timer control table access Index
781 * @return Timeout value
783 static u_int32 TimerGetTimeOutOfCtrlTbl(u_int32 idx) {
785 if (idx >= MAX_CTRL_TIMER_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
787 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
788 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
789 _pb_Exit(); // LCOV_EXCL_LINE 6:idx cannot greater
790 /* don't arrive here. */
793 return g_timer_ctrl_tbl[idx].time_out;
798 * Retreaval of unused area in the timer control table (Timer control table)
800 * Return the lowest-numbered index for accessing unused space in the Timer control table.
801 * If the mutex is not registered, the maximum timer management value (MAX_CTRL_MUTEX_NUM)
804 * @return Table accessor
806 static u_int32 TimerSearchEmptyOfCtrlTbl(void) {
810 for (idx = 0; idx < MAX_CTRL_TIMER_NUM; idx++) {
811 time_out = TimerGetTimeOutOfCtrlTbl(idx);
813 /* For unused space */
824 * Retrieval of specified timer for in the timer control table (Timer control table)
826 * Retrieve whether the specified timer is already registered in the timer control table.
827 * If it is registered, the access index is returned. If it is not registered,
828 * Return the maximum value of timer management (MAX_CTRL_TIMER_NUM).
830 * @param[in] snd_pno Process number
831 * @param[in] TimerSeq Timer sequence number
832 * @param[in] TimeType Timer type
834 * @return Index for access(If it is registered)<br>
835 * Maximum mutex management value (Not registered)
837 static u_int32 TimerSearchTimerOfCtrlTbl(PNO snd_pno, u_int16 TimerSeq, u_int8 TimeType) {
843 for (idx = 0; idx < MAX_CTRL_TIMER_NUM; idx++) {
844 pno = TimerGetPnoOfCtrlTbl(idx);
845 seq_no = TimerGetSeqNoOfCtrlTbl(idx);
846 type = TimerGetTypeOfCtrlTbl(idx);
848 /* If there is a match */
849 if ((pno == snd_pno) && (seq_no == TimerSeq) && (type == TimeType)) {
859 * Clear timer setting information
861 * @param[in] idx Timer control table accessor
863 static void TimerClearSettingOfCtrlTbl(u_int32 idx) {
866 /* Delete timer information */
867 TimerSetPnoOfCtrlTbl(idx, 0);
868 TimerSetSizeOfCtrlTbl(idx, 0);
869 TimerSetTypeOfCtrlTbl(idx, 0);
870 TimerSetSeqNoOfCtrlTbl(idx, 0);
871 TimerSetTimeOutOfCtrlTbl(idx, 0);
872 p_msg = TimerGetMsgBufOfCtrlTbl(idx);
873 memset(p_msg, 0x00, sizeof(TimerToutMsg));
880 * Create Mutex for accessing the timer control table
882 static void TimerCreateMutex(void) {
883 g_h_mtx = _pb_CreateMutex(NULL, 0, "Timer_Mutex");
884 if (g_h_mtx == NULL) {
885 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_CreateMutex ERROR " \
886 "[g_h_mtx:%p]", g_h_mtx);
888 /* don't arrive here. */
896 * Delete Mutex for accessing timer control table
898 static void TimerDeleteMutex(void) { // LCOV_EXCL_START 8:dead code
899 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
902 ret = PbDeleteMutex(g_h_mtx);
903 if (ret != WAIT_OBJECT_0) {
904 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PbDeleteMutex ERROR " \
905 "[ret:%lu, g_h_mtx:%p]", ret, g_h_mtx);
907 /* don't arrive here. */
916 * Get Mutex for accessing timer control table
918 static void TimerLockMutex(void) {
921 ret = PbMutexLock(g_h_mtx, INFINITE); // LCOV_EXCL_BR_LINE 200: lock will not failed
922 if (ret != WAIT_OBJECT_0) { // LCOV_EXCL_BR_LINE 200: lock will not failed
923 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PbMutexLock ERROR " \
924 "[ret:%lu, g_h_mtx:%p]", ret, g_h_mtx);
925 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
926 _pb_Exit(); // LCOV_EXCL_LINE 200: lock will not failed
927 /* don't arrive here. */
935 * Release Mutex for accessing timer control table
937 static void TimerUnlockMutex(void) {
940 ret = PbMutexUnlock(g_h_mtx); // LCOV_EXCL_BR_LINE 200: unlock will not failed
941 if (ret != TRUE) { // LCOV_EXCL_BR_LINE 200: unlock will not failed
942 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PbMutexUnlock ERROR " \
943 "[ret:%d, g_h_mtx:%p]", ret, g_h_mtx);
944 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
945 _pb_Exit(); // LCOV_EXCL_LINE 200: unlock will not failed
946 /* don't arrive here. */
954 * Timer Expiration Callback Functions
956 * For setting the timer creation function (NS_TimerCreate)<br>
957 * TimerCallback1 ... TimerCallback8
959 * @param[in] h_app Application handle
961 * @return eFrameworkunifiedStatusOK Normal completion
963 static EFrameworkunifiedStatus TimerCallback1(HANDLE h_app) {
964 static const u_int8 ID = 0;
966 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
968 TimerCallbackComProc(ID);
970 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
972 return eFrameworkunifiedStatusOK;
975 static EFrameworkunifiedStatus TimerCallback2(HANDLE h_app) {
976 static const u_int8 ID = 1;
978 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
980 TimerCallbackComProc(ID);
982 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
984 return eFrameworkunifiedStatusOK;
987 static EFrameworkunifiedStatus TimerCallback3(HANDLE h_app) {
988 static const u_int8 ID = 2;
990 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
992 TimerCallbackComProc(ID);
994 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
996 return eFrameworkunifiedStatusOK;
999 static EFrameworkunifiedStatus TimerCallback4(HANDLE h_app) {
1000 static const u_int8 ID = 3;
1002 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
1004 TimerCallbackComProc(ID);
1006 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
1008 return eFrameworkunifiedStatusOK;
1011 static EFrameworkunifiedStatus TimerCallback5(HANDLE h_app) {
1012 static const u_int8 ID = 4;
1014 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
1016 TimerCallbackComProc(ID);
1018 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
1020 return eFrameworkunifiedStatusOK;
1023 static EFrameworkunifiedStatus TimerCallback6(HANDLE h_app) {
1024 static const u_int8 ID = 5;
1026 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
1028 TimerCallbackComProc(ID);
1030 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
1032 return eFrameworkunifiedStatusOK;
1035 static EFrameworkunifiedStatus TimerCallback7(HANDLE h_app) {
1036 static const u_int8 ID = 6;
1038 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
1040 TimerCallbackComProc(ID);
1042 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
1044 return eFrameworkunifiedStatusOK;
1047 static EFrameworkunifiedStatus TimerCallback8(HANDLE h_app) {
1048 static const u_int8 ID = 7;
1050 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "+");
1052 TimerCallbackComProc(ID);
1054 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "-");
1056 return eFrameworkunifiedStatusOK;
1059 static void TimerCallbackComProc(const uint8_t id) {
1062 TimerLockMutex(); /* Get Mutex */
1064 /* Message is sent to the thread specified when the timer is created. */
1065 (void)_pb_SndMsg(g_timer_ctrl_tbl[id].pno, g_timer_ctrl_tbl[id].size, &(g_timer_ctrl_tbl[id].msg_buf), 0);
1067 type = TimerGetTypeOfCtrlTbl(id);
1068 if (type == TIMER_TYPE_USN) {
1069 /* One-shot timer */
1070 /* Clear timer information */
1071 TimerClearSettingOfCtrlTbl(id);
1073 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### TIMER TABLE INFORMATION # " \
1074 "(--) idx:%d cid:%d h_timer:%p pno:%d seq_no:%d type:%d time_out:%d", \
1075 id, g_timer_ctrl_tbl[id].cid, g_timer_ctrl_tbl[id].h_timer, g_timer_ctrl_tbl[id].pno, \
1076 g_timer_ctrl_tbl[id].seq_no, g_timer_ctrl_tbl[id].type, g_timer_ctrl_tbl[id].time_out);
1079 TimerUnlockMutex(); /* Release Mutex */
1086 * Get dump information
1088 * @param[out] p_buf Dump info
1090 void _pb_GetDebugTimerMngTbl(void* p_buf) {
1091 static uint8_t buf[DEBUG_DUMP_MAX_SIZE];
1092 static uint8_t buf_tmp[256];
1095 if (p_buf != NULL) {
1096 memset(&buf, 0x00, sizeof(buf));
1097 snprintf(reinterpret_cast<char *>(&(buf)), sizeof(buf), "Timer");
1098 for (i = 0; i < MAX_CTRL_TIMER_NUM; i++) {
1099 memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
1100 snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
1101 "\n [%d] cid:%05d, hTim:%10p, sz:%05d, pno:0x%04x, seq:0x%04x, typ:%03d, tOut:%10d",
1103 g_timer_ctrl_tbl[i].cid,
1104 g_timer_ctrl_tbl[i].h_timer,
1105 g_timer_ctrl_tbl[i].size,
1106 g_timer_ctrl_tbl[i].pno,
1107 g_timer_ctrl_tbl[i].seq_no,
1108 g_timer_ctrl_tbl[i].type,
1109 g_timer_ctrl_tbl[i].time_out);
1110 strncat(reinterpret_cast<char *>(&buf[0]), reinterpret_cast<char *>(&buf_tmp[0]), \
1111 strlen(reinterpret_cast<char *>(&buf_tmp[0])));
1113 memcpy(p_buf, &buf[0], sizeof(buf));
1115 } // LCOV_EXCL_BR_LINE 10:The final line