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 * @file MDev_Gps_TimerCtrl.cpp
20 /*---------------------------------------------------------------------------*/
23 #include "MDev_Gps_TimerCtrl.h"
25 // #include "MDev_Gps_Main.h"
26 // #include "MDev_GpsRecv.h"
28 /*---------------------------------------------------------------------------*/
31 static GPS_TIM_MNG g_st_tim_mng;
33 /** Timer setting information table */
34 static const GPS_TIM_INFO kTimInfo[TIM_NUM] = {
36 {TIMVAL_GPS_STARTUP, PNO_NAVI_GPS_MAIN}, /* Start confirmation monitoring timer */
37 {TIMVAL_GPS_RCVCYCLDAT, PNO_NAVI_GPS_MAIN}, /* Periodic reception data monitoring timer */
38 {TIMVAL_GPS_RCVACK, PNO_NAVI_GPS_MAIN}, /* ACK reception monitoring timer */
39 {TIMVAL_GPS_NAVIFST, PNO_NAVI_GPS_MAIN}, /* Initial Navigation Monitoring Timer */
40 {TIMVAL_GPS_NAVICYCLE, PNO_NAVI_GPS_MAIN}, /* Navi monitoring timer */
41 {TIMVAL_GPS_NAVIDISRPT, PNO_NAVI_GPS_MAIN}, /* Navigation Monitoring Disruption Log Output Timer */
42 {TIMVAL_GPS_DIAGCLKGUARD, PNO_NAVI_GPS_MAIN}, /* Diagnosis provision time guard monitoring timer */
43 {TIMVAL_GPS_NMEADATAGUARD, PNO_NAVI_GPS_MAIN}, /* NMEA data providing guard monitoring timer */
44 {TIMVAL_GPS_RECOVERY, PNO_NAVI_GPS_MAIN}, /* GPS recovery timer */
45 {TIMVAL_GPS_RECEIVERERR, PNO_NAVI_GPS_MAIN}, /* GPS receiver anomaly detection timer */
47 {TIMVAL_SNS_RCVFSTDAT, PNO_VEHICLE_SENSOR}, /* Initial cyclic sensor data reception monitoring timer */
48 {TIMVAL_SNS_RCVCYCLDAT, PNO_VEHICLE_SENSOR}, /* Cyclic sensor data reception monitoring timer */
49 {TIMVAL_SNS_RCVDISRPT, PNO_VEHICLE_SENSOR}, /* Cyclic sensor data interruption log output timer */
52 /*---------------------------------------------------------------------------*/
55 static uint16_t TimeMakSeqNo(GPS_TIM_KIND tim_kind) {
56 GPS_TIM_MNG* pst_tim_mng = NULL;
57 u_int16 seq_no = 0; /* Timer sequence number */
59 pst_tim_mng = &g_st_tim_mng;
61 /*------------------------------------------------------------------------*/
62 /* Definition of Sequence Number */
63 /* |------------------- Sequence number(2Byte) -----------------------| */
65 /* +-------------------------------+-----------------------------------+ */
66 /* | Timer type(1Byte) | Counter(1Byte)(0x01 ? 0xFF) | */
67 /* +-------------------------------+-----------------------------------+ */
68 /* The timer type is 0x00. ? (Number of timers-1) */
69 /* counters is 0x01 ? 0xFF(Do not use 0x00) */
70 /* (Counters are counted up each time a timer is started. */
71 /* If the counter counts up when it is 0xFF, */
72 /* be counted up from the 0x01.) */
73 /*------------------------------------------------------------------------*/
74 seq_no = ((u_int16)tim_kind << 8) | (pst_tim_mng->sts[tim_kind].cnt);
79 static BOOL VehicleUtilitySetTimer(GPS_TIM_KIND tim_kind) {
80 GPS_TIM_MNG* pst_tim_mng = NULL;
81 const uint32_t * p_time_val;
83 RET_API api_ret = RET_NORMAL;
88 pst_tim_mng = &g_st_tim_mng;
89 p_time_val = &(kTimInfo[tim_kind].timer_val); /* Timer set value */
90 p_pno = &(kTimInfo[tim_kind].pno); /* Notify party PNO */
92 if (pst_tim_mng->sts[tim_kind].flag == TIMER_ON) {
93 /*-----------------------------------------------------------------------*/
94 /* When the same timer has already started, */
95 /* terminate without starting the timer because the timer is set multiple times. */
96 /*-----------------------------------------------------------------------*/
99 /*-----------------------------------------------------------------------*/
100 /* Count up the timer counter of the corresponding timer by 1. */
101 /*-----------------------------------------------------------------------*/
102 if (pst_tim_mng->sts[tim_kind].cnt >= TIM_CNTMAX) {
103 /*-----------------------------------------------------------------------*/
104 /* When the count reaches the maximum number, it counts again from 1. */
105 /*-----------------------------------------------------------------------*/
106 pst_tim_mng->sts[tim_kind].cnt = TIM_CNTMIN;
108 /*-----------------------------------------------------------------------*/
109 /* If the count has not reached the maximum, it is counted up. */
110 /*-----------------------------------------------------------------------*/
111 pst_tim_mng->sts[tim_kind].cnt++;
114 /*-----------------------------------------------------------------------*/
115 /* Creating timer sequence numbers */
116 /*-----------------------------------------------------------------------*/
117 seq_no = TimeMakSeqNo(tim_kind);
119 /*-----------------------------------------------------------------------*/
120 /* Start the timer */
121 /*-----------------------------------------------------------------------*/
122 api_ret = _pb_ReqTimerStart(*p_pno, seq_no, TIMER_TYPE_USN, static_cast<u_int32>(*p_time_val));
123 if (api_ret != RET_NORMAL) {
126 /*-----------------------------------------------------------------------*/
127 /* If successful timer start, */
128 /* set the start/stop flag of the corresponding timer to start (MCSUB_ON). */
129 /*-----------------------------------------------------------------------*/
130 pst_tim_mng->sts[tim_kind].flag = TIMER_ON;
137 static BOOL VehicleUtilityStopTimer(GPS_TIM_KIND tim_kind) {
138 GPS_TIM_MNG* pst_tim_mng = NULL;
141 RET_API api_ret = RET_NORMAL;
145 pst_tim_mng = &g_st_tim_mng;
146 p_pno = &(kTimInfo[tim_kind].pno); /* Notify party PNO */
148 /* Check timer start/stop flag */
149 if (pst_tim_mng->sts[tim_kind].flag == TIMER_OFF) {
150 /* If it is already stopped, do nothing. */
153 /*-----------------------------------------------------------------------*/
154 /* Creating timer sequence numbers */
155 /*-----------------------------------------------------------------------*/
156 seq_no = TimeMakSeqNo(tim_kind);
158 /*-----------------------------------------------------------------------*/
159 /* Set the corresponding timer to stop */
160 /*-----------------------------------------------------------------------*/
161 api_ret = _pb_TimerStop(*p_pno, seq_no, TIMER_TYPE_USN);
163 if (api_ret != RET_NORMAL) {
167 /*-----------------------------------------------------------------------*/
168 /* Set the start/stop flag of the corresponding timer to stop (MCSUB_OFF) */
169 /* Set the ID of the corresponding timer to invalid (DEV_TED_INVALID) */
170 /*-----------------------------------------------------------------------*/
171 pst_tim_mng->sts[tim_kind].flag = TIMER_OFF;
177 static BOOL VehicleUtilityTimeJdgKnd(uint16_t seqno) {
178 GPS_TIM_MNG* pst_tim_mng = NULL;
184 pst_tim_mng = &g_st_tim_mng;
186 timekind = (u_int8)((seqno & 0xff00) >> 8);
187 count = (u_int8)(seqno & 0x00ff);
189 /* Timer type is unexpected */
190 if (timekind >= TIM_NUM) {
193 if ((pst_tim_mng->sts[timekind].cnt == count) && (pst_tim_mng->sts[timekind].flag == TIMER_ON)) {
194 /* The counter matches and the counter start/stop flag is "Start". */
197 /* Not applicable due to differences */
205 /*******************************************************************************
206 * MODULE : DEV_Gps_Tim_Init
207 * ABSTRACT : Timer function initialization processing
208 * FUNCTION : Initialize the timer function
210 * NOTE : 1.Initialize timer management table
212 ******************************************************************************/
213 void DevGpsTimInit(void) {
214 GPS_TIM_MNG* pst_tim_mng = NULL;
218 pst_tim_mng = &g_st_tim_mng;
220 /* Initialize timer management table */
221 memset(pst_tim_mng, 0x00, sizeof(GPS_TIM_MNG));
223 for (i = 0; i < TIM_NUM; i++) {
224 pst_tim_mng->sts[i].flag = TIMER_OFF;
225 pst_tim_mng->sts[i].cnt = 0;
231 /*******************************************************************************
232 * MODULE : DevGpsTimeSet
233 * ABSTRACT : Timer start processing
234 * FUNCTION : Starts a timer of the specified type
235 * ARGUMENT : GPS_TIM_KIND tim_kind Timer type
236 * NOTE : 1.Increment total number of timer start
237 * 2.Timer Sequence Number Creation
238 * 3.Get timeout value
240 * RETURN : TRUE : Normal completion
242 ******************************************************************************/
243 BOOL DevGpsTimeSet(GPS_TIM_KIND tim_kind) {
246 /* Binding of unused timer */
247 if ((tim_kind != GPS_RECV_ACK_TIMER)
248 && (tim_kind != GPS_STARTUP_TIMER)
249 && (tim_kind != GPS_CYCL_TIMER)
250 && (tim_kind != GPS_NAVIFST_TIMER)
251 && (tim_kind != GPS_NAVICYCLE_TIMER)
252 && (tim_kind != GPS_NAVIDISRPT_TIMER)
253 && (tim_kind != GPS_RECOVERY_TIMER)
254 && (tim_kind != GPS_RECEIVERERR_TIMER)) {
257 ret = VehicleUtilitySetTimer(tim_kind);
261 /*******************************************************************************
262 * MODULE : DevGpsTimeStop
263 * ABSTRACT : Timer stop processing
264 * FUNCTION : Stops a timer of the specified type
265 * ARGUMENT : GPS_TIM_KIND tim_kind Timer type
266 * NOTE : 1.Get the sequence number of the specified type
268 * RETURN : TRUE : Normal completion
270 ******************************************************************************/
271 BOOL DevGpsTimeStop(GPS_TIM_KIND tim_kind) {
273 ret = VehicleUtilityStopTimer(tim_kind);
277 /********************************************************************************
278 * MODULE : DevGpsTimeJdgKind
279 * ABSTRACT : Timer Sequence Number Determination
280 * FUNCTION : Determine whether the timer sequence number corresponds to the one being managed
281 * ARGUMENT : Timer Sequence Number
283 * RETURN : TRUE : Normal completion(No problem)
284 * : FALSE : ABENDs(Unusual number)
285 ********************************************************************************/
286 BOOL DevGpsTimeJdgKind(u_int16 seqno) {
288 ret = VehicleUtilityTimeJdgKnd(seqno);
292 /*---------------------------------------------------------------------------*/