common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / positioning_hal / src / LineSensDrv / LineSensDrv_Api.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 LineSensDrv_Api.cpp
18 */
19
20 /*---------------------------------------------------------------------------*/
21 // Include files
22
23 #include "LineSensDrv_Api.h"
24 #include "positioning_def.h"
25
26 /*---------------------------------------------------------------------------*/
27 // Macro definitions
28
29 #define LSDRV_GPS_DATA_TOP_TH           5       // Threshold for determining the beginning of GPS data
30 #define LSDRV_SENS_DATA_RCV_WAIT_TIME   400     // Sensor data wait time of GPS reception flag ON(Total)
31 #define LSDRV_SENS_DATA_RCV_WAIT_TERM   50      // Sensor data wait time of GPS reception flag ON(1 time)
32
33 #define LSDRV_EST_GPS_CNT_ARRAY_NUM     3U      // Number of arrays for holding estimated GPS counter
34 #define LSDRV_EST_GPS_CNT_ENABLE_TH     5U      // Estimated GPS counter enable/disable determination threshold
35 #define LSDRV_EST_GPS_CNT_ADD_VALUE     10U     // Estimated GPS counter update addition value
36
37 // GPS data reception cycle:1sec sensor counters: 100ms
38
39 // for debug
40 #define LINE_SENS_DRV_API_DEBUG_SWITCH  0       // 0:OFF 1:ON
41
42 /*---------------------------------------------------------------------------*/
43 // Global variable
44
45 static HANDLE  g_gps_irq_mutex          = NULL;             // GPS received flag Mutex handles
46 static BOOL    g_rcv_pps_int            = FALSE;            // PPS interrupt reception flag  (GPS->_CWORD102_)
47 static BOOL    g_rcv_gps_irq            = FALSE;            // GPS reception flag    (GPS->_CWORD56_)
48 static u_int8  g_rcv_gps_sens_cnt_tmp   = 0;                // Sensor counter when GPS reception flag is ON(for retention)
49 static u_int8  g_rcv_gps_sens_cnt       = 0;                // Sensor counter when GPS reception flag is ON
50 static u_int8  g_gps_sens_cnt_top       = 0;                // Sensor counter when first GPS data is received
51 static u_int8  g_est_gps_cnt[LSDRV_EST_GPS_CNT_ARRAY_NUM];  // Array for storing estimated GPS counter values
52 static BOOL    g_est_gps_cnt_available  = FALSE;            // Estimated GPS counter value enable/disable judgment
53
54 typedef struct VehicleSensDataMaster {
55   DID     ul_did;           // Data ID
56   u_int16 us_size;          // Size of the data
57   u_int8  uc_rcv_flag;      // Receive flag
58   u_int8  uc_sns_cnt;       // Sensor counter
59   u_int8  uc_data[132];     // Vehicle sensor data
60 } VEHICLESENS_DATA_MASTER;
61
62
63 /*******************************************************************************
64  * MODULE    : DeliveryLineSensorDataPositioning
65  * ABSTRACT  : LineSensor vehicle signaling notification messages sending process
66  * FUNCTION  : Send LineSensor vehicle signalling notification messages
67  * ARGUMENT  : *pstSendBuf:Transmitted data
68  *           : uc_data_num  :Number of sent data
69  * NOTE      :
70  * RETURN    : None
71  ******************************************************************************/
72 void DeliveryLineSensorDataPositioning(LSDRV_MSG_LSDATA_G* pst_send_buf, u_int8 uc_data_num) {
73   if (pst_send_buf != NULL) {
74     /* Initializing sent messages */
75     memset(reinterpret_cast<void *>(&(pst_send_buf->st_head)), 0, sizeof(T_APIMSG_MSGBUF_HEADER));
76
77     /* Message Header Settings */
78     pst_send_buf->st_head.hdr.sndpno      = PNO_LINE_SENS_DRV;                /* Source process number */
79     pst_send_buf->st_head.hdr.cid         = CID_LINESENS_VEHICLE_DATA_G;      /* Command ID */
80     pst_send_buf->st_head.hdr.msgbodysize = sizeof(LSDRV_MSG_LSDATA_DAT_G);   /* Message data body length */
81
82     /* Message data is already set */
83     pst_send_buf->st_para.uc_data_num       = uc_data_num;
84
85     /* Send messages */
86     (void)_pb_ZcSndMsg(PNO_VEHICLE_SENSOR, sizeof( LSDRV_MSG_LSDATA_G ), 0);
87   }
88 }
89
90 /*******************************************************************************
91  * MODULE    : LineSensDrvApi_Initialize
92  * ABSTRACT  : LineSensDrvApi initialization process
93  * FUNCTION  : LineSensDrvApi initialization process
94  * ARGUMENT  : -
95  * NOTE      :
96  * RETURN    : -
97  ******************************************************************************/
98 BOOL LineSensDrvApiInitialize(void) {
99   BOOL ret = TRUE;
100
101   g_gps_irq_mutex = _pb_CreateMutex(NULL, FALSE, MUTEX_GPS_IRQ_FLG);
102
103   if (g_gps_irq_mutex == 0) {
104     ret = FALSE;
105   } else {
106     g_rcv_gps_irq = FALSE;
107     g_rcv_gps_sens_cnt_tmp = 0;
108     LineSensDrvApiInitEstGpsCnt();
109     ret = TRUE;
110   }
111
112   return (ret);
113 }
114
115 /*******************************************************************************
116  * MODULE    : LineSensDrvApi_InitEstGpsCnt
117  * ABSTRACT  : Estimated GPS counter related parameter initialization processing
118  * FUNCTION  : Estimated GPS counter related parameter initialization processing
119  * ARGUMENT  : -
120  * NOTE      :
121  * RETURN    : -
122  ******************************************************************************/
123 void LineSensDrvApiInitEstGpsCnt(void) {
124   /* Initializing process */
125   g_rcv_pps_int = FALSE;
126   g_rcv_gps_sens_cnt = 0;
127   g_gps_sens_cnt_top = 0;
128
129   (void)memset(reinterpret_cast<void *>(&g_est_gps_cnt[0]), 0, sizeof(g_est_gps_cnt));
130   g_est_gps_cnt_available  = FALSE;
131
132   return;
133 }
134
135 /*---------------------------------------------------------------------------*/
136 /*EOF*/