Remove unused directories and files in video_in_hal
[staging/basesystem.git] / hal / positioning_hal / src / GpsCommon / MDev_Gps_TimerCtrl.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17 * @file MDev_Gps_TimerCtrl.cpp
18 */
19
20 /*---------------------------------------------------------------------------*/
21 // Include files
22
23 #include  "MDev_Gps_TimerCtrl.h"
24
25 // #include  "MDev_Gps_Main.h"
26 // #include  "MDev_GpsRecv.h"
27
28 /*---------------------------------------------------------------------------*/
29 // Global values
30
31 static GPS_TIM_MNG          g_st_tim_mng;
32
33 /** Timer setting information table */
34 static const GPS_TIM_INFO   kTimInfo[TIM_NUM] = {
35   /* GSP related */
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                   */
46   /* Sensor related */
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           */
50 };
51
52 /*---------------------------------------------------------------------------*/
53 // Functions
54
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 */
58
59   pst_tim_mng = &g_st_tim_mng;
60
61   /*------------------------------------------------------------------------*/
62   /* Definition of Sequence Number                                                   */
63   /* |-------------------  Sequence number(2Byte)  -----------------------|  */
64   /* 15                             8 7                                  0  */
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);
75
76   return seq_no;
77 }
78
79 static BOOL VehicleUtilitySetTimer(GPS_TIM_KIND tim_kind) {
80   GPS_TIM_MNG*            pst_tim_mng = NULL;
81   const uint32_t *        p_time_val;
82   const PNO*              p_pno;
83   RET_API                 api_ret = RET_NORMAL;
84   u_int16                 seq_no = 0;
85   BOOL                    ret = TRUE;
86
87   // Initialize
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 */
91
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     /*-----------------------------------------------------------------------*/
97     ret = FALSE;
98   } else {
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;
107     } else {
108       /*-----------------------------------------------------------------------*/
109       /* If the count has not reached the maximum, it is counted up.              */
110       /*-----------------------------------------------------------------------*/
111       pst_tim_mng->sts[tim_kind].cnt++;
112     }
113
114     /*-----------------------------------------------------------------------*/
115     /* Creating timer sequence numbers                                            */
116     /*-----------------------------------------------------------------------*/
117     seq_no = TimeMakSeqNo(tim_kind);
118
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) {
124       ret = FALSE;
125     } else {
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;
131     }
132   }
133
134   return ret;
135 }
136
137 static BOOL VehicleUtilityStopTimer(GPS_TIM_KIND tim_kind) {
138   GPS_TIM_MNG*            pst_tim_mng = NULL;
139   const PNO*              p_pno;
140   BOOL                    ret = TRUE;
141   RET_API                 api_ret = RET_NORMAL;
142   u_int16                 seq_no = 0;
143
144   // Initialize
145   pst_tim_mng = &g_st_tim_mng;
146   p_pno = &(kTimInfo[tim_kind].pno); /* Notify party PNO */
147
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.  */
151     ret = FALSE;
152   } else {
153     /*-----------------------------------------------------------------------*/
154     /* Creating timer sequence numbers                                            */
155     /*-----------------------------------------------------------------------*/
156     seq_no = TimeMakSeqNo(tim_kind);
157
158     /*-----------------------------------------------------------------------*/
159     /* Set the corresponding timer to stop                                          */
160     /*-----------------------------------------------------------------------*/
161     api_ret = _pb_TimerStop(*p_pno, seq_no, TIMER_TYPE_USN);
162
163     if (api_ret != RET_NORMAL) {
164       ret = FALSE;
165     }
166
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;
172   }
173
174   return ret;
175 }
176
177 static BOOL VehicleUtilityTimeJdgKnd(uint16_t seqno) {
178   GPS_TIM_MNG*            pst_tim_mng = NULL;
179   BOOL                    ret = FALSE;
180   u_int8                  timekind = 0;
181   u_int8                  count = 0;
182
183   // Initialize
184   pst_tim_mng = &g_st_tim_mng;
185
186   timekind = (u_int8)((seqno & 0xff00) >> 8);
187   count = (u_int8)(seqno & 0x00ff);
188
189   /* Timer type is unexpected        */
190   if (timekind >= TIM_NUM) {
191     ret = FALSE;
192   } else {
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".      */
195       ret = TRUE;
196     } else {
197       /* Not applicable due to differences                                  */
198       ret = FALSE;
199     }
200   }
201
202   return ret;
203 }
204
205 /*******************************************************************************
206  * MODULE  : DEV_Gps_Tim_Init
207  * ABSTRACT  : Timer function initialization processing
208  * FUNCTION  : Initialize the timer function 
209  * ARGUMENT  : None
210  * NOTE    :  1.Initialize timer management table
211  * RETURN  : None
212  ******************************************************************************/
213 void  DevGpsTimInit(void) {
214   GPS_TIM_MNG*            pst_tim_mng = NULL;
215   u_int32                 i = 0;
216
217   // Initialie
218   pst_tim_mng = &g_st_tim_mng;
219
220   /* Initialize timer management table */
221   memset(pst_tim_mng, 0x00, sizeof(GPS_TIM_MNG));
222
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;
226   }
227
228   return;
229 }
230
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
239  *             4.Timer start
240  * RETURN   : TRUE : Normal completion
241  *          : FALSE : ABENDs
242  ******************************************************************************/
243 BOOL  DevGpsTimeSet(GPS_TIM_KIND tim_kind) {
244   BOOL ret = TRUE;
245
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)) {
255     return ret;
256   }
257   ret = VehicleUtilitySetTimer(tim_kind);
258   return ret;
259 }
260
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
267  *         2.Timer stop
268  * RETURN  : TRUE : Normal completion
269  *      : FALSE : ABENDs
270  ******************************************************************************/
271 BOOL  DevGpsTimeStop(GPS_TIM_KIND tim_kind) {
272     BOOL ret = TRUE;
273     ret = VehicleUtilityStopTimer(tim_kind);
274     return ret;
275 }
276
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
282  * NOTE        :
283  * RETURN      : TRUE : Normal completion(No problem)
284  *             : FALSE : ABENDs(Unusual number)
285  ********************************************************************************/
286 BOOL DevGpsTimeJdgKind(u_int16 seqno) {
287     BOOL ret;
288     ret = VehicleUtilityTimeJdgKnd(seqno);
289     return ret;
290 }
291
292 /*---------------------------------------------------------------------------*/
293 /*EOF*/