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 /*******************************************************************************
18 * File name :VehicleSens_SharedMemory.cpp
19 * System name :PastModel002
20 * Subsystem name :Vehicle sensor process
21 * Program name :Vehicle sensor shared memory management
22 ******************************************************************************/
24 #include <vehicle_service/positioning_base_library.h>
25 #include "VehicleSens_SharedMemory.h"
26 #include "Sensor_API.h"
27 #include "VehicleSens_DataMaster.h"
28 #include "Sensor_API_private.h"
29 #include "SensorLocation_API.h"
30 #include "SensorLocation_API_private.h"
32 /********************************************************************************
33 * prototype declalation *
34 ********************************************************************************/
35 static void VehicleSensLinkSharedMemory(char *shared_memory_name, void **p_share_addr);
36 static RET_API VehicleSensWriteDataGpsInterruptSignal(DID ul_did);
37 static RET_API VehicleSensWriteDataGyroConnectStatus(DID ul_did);
38 static RET_API VehicleSensWriteDataLocalTime(void);
39 static RET_API VehicleSensWriteDataLonLat(void);
41 /********************************************************************************
43 ********************************************************************************/
45 /*******************************************************************************
46 * MODULE : VehicleSensInitSharedMemory
47 * ABSTRACT : Shared Memory Initialization
48 * FUNCTION : Initialize shared memory
51 * RETURN : RET_NORMAL :Normal
52 * : RET_ERROR :Abnormality
53 ******************************************************************************/
54 RET_API VehicleSensInitSharedMemory(void) { // LCOV_EXCL_START 8 : dead code
55 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
56 RET_API l_ret; /* Return of the functions */
58 /* All shared memory initialization */
59 l_ret = VehicleSensWriteDataGpsInterruptSignal(VEHICLE_DID_MAIN_GPS_INTERRUPT_SIGNAL);
60 if (l_ret == RET_NORMAL) {
61 l_ret = VehicleSensWriteDataGpsInterruptSignal(VEHICLE_DID_SYS_GPS_INTERRUPT_SIGNAL);
63 if (l_ret == RET_NORMAL) {
64 l_ret = VehicleSensWriteDataGyroConnectStatus(VEHICLE_DID_GYRO_CONNECT_STATUS);
67 /* Initializes the effective ephemeris count when the shared memory is shut down. */
68 if (l_ret == RET_NORMAL) {
69 l_ret = VehicleSensWriteDataValidEphemerisNum(0); /* Initialized with effective ephemeris number 0 */
72 /* Writes the value read from the non-volatile memory to the shared memory. */
73 /* This process is executed only at startup.,After that, the shared memory will not be overwritten. */
74 if (l_ret == RET_NORMAL) {
75 l_ret = VehicleSensWriteDataLocalTime();
78 if (l_ret == RET_NORMAL) {
79 l_ret = VehicleSensWriteDataLonLat();
85 /*******************************************************************************
86 * MODULE : VehicleSensLinkSharedMemory
87 * ABSTRACT : Shared memory link
88 * FUNCTION : Link to shared memory
92 ******************************************************************************/
93 static void VehicleSensLinkSharedMemory(char *shared_memory_name, void **p_share_addr) {
94 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
96 void *pv_share_mem; /* Store Shared Memory Address */
97 u_int32 ul_share_mem_size; /* Size of the linked shared memory */
99 /* Link to the handle storage area */
100 ret_api = _pb_LinkShareData(shared_memory_name, &pv_share_mem, &ul_share_mem_size);
102 if (ret_api == RET_NORMAL) {
103 /* If the link is successful */
104 *p_share_addr = pv_share_mem; /* Set the address */
106 /* If the link fails */
107 *p_share_addr = NULL;
111 /*******************************************************************************
112 * MODULE : VehicleSensWriteDataGpsInterruptSignal
113 * ABSTRACT : Writing of data
114 * FUNCTION : Writing Data to Shared Memory
115 * ARGUMENT : DID : Data ID
117 * RETURN : RET_NORMAL :Normal
118 * : RET_ERROR :Abnormality
119 ******************************************************************************/
120 static RET_API VehicleSensWriteDataGpsInterruptSignal(DID ul_did) {
121 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
122 static GPS_INTERRUPT *gpsInterruptSharedAddr = NULL; /* Store Shared Memory Address */
123 static SemID sem_id = 0; /* ID of shared memory exclusive semaphore */
125 VEHICLESENS_DATA_MASTER_GPS_INTERRUPT_SIGNAL pst_data;
127 RET_API l_ret = RET_NORMAL; /* Return of the functions */
128 RET_API l_ret_api; /* Return of the functions */
131 /* Get Semaphore ID */
133 sem_id = _pb_CreateSemaphore(const_cast<char *>(GPS_INTERRUPT_SIGNAL_SEMAPHO_NAME));
137 /* Semaphore ID successfully acquired */
138 l_ret_api = _pb_SemLock(sem_id); /* Semaphore Lock */
140 if (l_ret_api == RET_NORMAL) {
141 /* Semaphore lock successful */
143 /* When the shared memory is not linked */
144 if (gpsInterruptSharedAddr == NULL) {
145 /* Link to shared memory */
146 /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */
147 VehicleSensLinkSharedMemory(const_cast<char *>(GPS_INTERRUPT_SIGNAL_SHARE_NAME),
148 reinterpret_cast<void **>(&gpsInterruptSharedAddr));
151 if (gpsInterruptSharedAddr != NULL) {
152 /* The link to shared memory is successful. */
154 case VEHICLE_DID_MAIN_GPS_INTERRUPT_SIGNAL:
156 /* Get data from data master */
157 VehicleSensGetDataMasterMainGpsInterruptSignal(ul_did, 0, &pst_data);
159 /* Writing Data to Shared Memory */
160 gpsInterruptSharedAddr->_CWORD102__interrupt = pst_data.uc_data;
163 case VEHICLE_DID_SYS_GPS_INTERRUPT_SIGNAL:
165 /* Get data from data master */
166 VehicleSensGetDataMasterSysGpsInterruptSignal(ul_did, 0, &pst_data);
168 /* Writing Data to Shared Memory */
169 gpsInterruptSharedAddr->_CWORD56__interrupt = pst_data.uc_data;
174 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "DID is unknown. \r\n");
180 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "gpsInterruptSharedAddr == NULL \r\n");
183 /* Semaphore unlock */
184 (void)_pb_SemUnlock(sem_id);
187 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemLock failed");
191 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "sem_id == 0");
197 /*******************************************************************************
198 * MODULE : VehicleSensWriteDataGyroConnectStatus
199 * ABSTRACT : Writing of data
200 * FUNCTION : Writing Data to Shared Memory
201 * ARGUMENT : DID : Data ID
203 * RETURN : RET_NORMAL :Normal
204 * : RET_ERROR :Abnormality
205 ******************************************************************************/
206 static RET_API VehicleSensWriteDataGyroConnectStatus(DID ul_did) {
207 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
208 static u_int8 *gyroConnectSharedAddr = NULL; /* Store Shared Memory Address */
209 static SemID sem_id = 0; /* ID of shared memory exclusive semaphore */
211 VEHICLESENS_DATA_MASTER_GYRO_CONNECT_STATUS pst_data;
213 RET_API l_ret = RET_NORMAL; /* Return of the functions */
214 RET_API l_ret_api; /* Return of the functions */
216 /* Get Semaphore ID */
218 sem_id = _pb_CreateSemaphore(const_cast<char *>(GYRO_CONNECT_STATUS_SEMAPHO_NAME));
222 /* Semaphore ID successfully acquired */
223 l_ret_api = _pb_SemLock(sem_id); /* Semaphore Lock */
225 if (l_ret_api == RET_NORMAL) {
226 /* Semaphore lock successful */
228 /* When the shared memory is not linked */
229 if (gyroConnectSharedAddr == NULL) {
230 /* Link to shared memory */
231 /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */
232 VehicleSensLinkSharedMemory(const_cast<char *>(GYRO_CONNECT_STATUS_SHARE_NAME),
233 reinterpret_cast<void **>(&gyroConnectSharedAddr));
236 if (gyroConnectSharedAddr != NULL) {
237 /* The link to shared memory is successful. */
239 /* Get data from data master */
240 VehicleSensGetDataMasterGyroConnectStatus(ul_did, 0, &pst_data);
242 /* Writing Data to Shared Memory */
243 *gyroConnectSharedAddr = pst_data.uc_data;
247 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
248 "gyroConnectSharedAddr == NULL \r\n");
251 /* Semaphore unlock */
252 (void)_pb_SemUnlock(sem_id);
255 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemLock failed");
259 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "sem_id == 0");
265 /*******************************************************************************
266 * MODULE : VehicleSensWriteDataValidEphemerisNum
267 * ABSTRACT : Write effective ephemeris number at shutdown
268 * FUNCTION : Write effective ephemeris number at shutdown to shared memory
269 * ARGUMENT : u_int8 valid_ephemer_isnum : Number of effective ephemeris written to shared memory during shutdown
271 * RETURN : RET_NORMAL :Normal
272 * : RET_ERROR :Abnormality
273 ******************************************************************************/
274 RET_API VehicleSensWriteDataValidEphemerisNum(u_int8 valid_ephemer_isnum) {
275 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
276 static u_int8 *shared_addr = NULL; /* Store Shared Memory Address */
277 static SemID sem_id = 0; /* ID of shared memory exclusive semaphore */
279 RET_API l_ret; /* Return of the functions */
280 RET_API l_ret_api; /* Return of the functions */
282 /* Get Semaphore ID */
284 sem_id = _pb_CreateSemaphore(const_cast<char *>(EPHEMERIS_NUM_SEMAPHO_NAME));
288 /* Semaphore ID successfully acquired */
289 l_ret_api = _pb_SemLock(sem_id); /* Semaphore Lock */
291 if (l_ret_api == RET_NORMAL) {
292 /* Semaphore lock successful */
294 /* When the shared memory is not linked */
295 if (shared_addr == NULL) {
296 /* Link to shared memory */
297 /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */
298 VehicleSensLinkSharedMemory(const_cast<char *>(EPHEMERIS_NUM_SHARE_NAME),
299 reinterpret_cast<void **>(&shared_addr));
302 if (shared_addr != NULL) {
303 *shared_addr = valid_ephemer_isnum;
308 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "shared_addr == NULL \r\n");
311 /* Semaphore unlock */
312 l_ret_api = _pb_SemUnlock(sem_id);
313 if (l_ret_api != RET_NORMAL) {
314 /* Semaphore unlock failure */
316 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemUnlock failed");
319 /* Semaphore ID acquisition failure */
321 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemLock failed");
325 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "sem_id == 0");
331 /*******************************************************************************
332 * MODULE : VehicleSensWriteDataLocalTime
333 * ABSTRACT : Writing Local Time at Shutdown
334 * FUNCTION : Write local time on shutdown to shared memory
337 * RETURN : RET_NORMAL :Acquisition normal
338 * : RET_ERROR :Acquisition anomaly
339 ******************************************************************************/
340 static RET_API VehicleSensWriteDataLocalTime(void) {
341 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
342 static LOCALTIME *shared_addr = NULL; /* Store Shared Memory Address */
343 static SemID sem_id = 0; /* ID of shared memory exclusive semaphore */
345 RET_API l_ret; /* Return of the functions */
346 RET_API l_ret_api; /* Return of the functions */
350 /* Get Semaphore ID */
352 sem_id = _pb_CreateSemaphore(const_cast<char *>(LOCALTIME_SEMAPHO_NAME));
356 /* Semaphore ID successfully acquired */
357 l_ret_api = _pb_SemLock(sem_id); /* Semaphore Lock */
359 if (l_ret_api == RET_NORMAL) {
360 /* Semaphore lock successful */
362 /* When the shared memory is not linked */
363 if (shared_addr == NULL) {
364 /* Link to shared memory */
365 /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */
366 VehicleSensLinkSharedMemory(const_cast<char *>(LOCALTIME_SHARE_NAME),
367 reinterpret_cast<void **>(&shared_addr));
370 if (shared_addr != NULL) {
371 /* The link to shared memory is successful. */
373 /* Acquires data from the non-volatile memory and writes it to the shared memory. */
374 l_ret_api = VehicleSensReadNVLocalTime(&LocalTime);
375 if (l_ret_api == RET_NORMAL) {
376 *shared_addr = LocalTime;
379 /* When data acquisition from non-volatile memory fails,Set an invalid value */
380 (*shared_addr).status = CLOCK_INVALID;
381 (*shared_addr).year = 0xFFFFU; /* invalid */
382 (*shared_addr).month = 255U; /* invalid */
383 (*shared_addr).day = 255U; /* invalid */
384 (*shared_addr).hour = 255U; /* invalid */
385 (*shared_addr).min = 255U; /* invalid */
386 (*shared_addr).sec = 255U; /* invalid */
392 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "shared_addr == NULL \r\n");
395 /* Semaphore unlock */
396 l_ret_api = _pb_SemUnlock(sem_id);
397 if (l_ret_api != RET_NORMAL) {
398 /* Semaphore unlock failure */
400 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemUnlock failed");
403 /* Semaphore ID acquisition failure */
405 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemLock failed");
409 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "sem_id == 0");
415 /*******************************************************************************
416 * MODULE : VehicleSensWriteDataLonLat
417 * ABSTRACT : Write position at shutdown
418 * FUNCTION : Write shutdown position to shared memory
421 * RETURN : RET_NORMAL :Successful acquisition
422 * : RET_ERROR :Failed to acquire
423 ******************************************************************************/
424 static RET_API VehicleSensWriteDataLonLat(void) {
425 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
426 static LONLAT *shared_addr = NULL; /* Store Shared Memory Address */
427 static SemID sem_id = 0; /* ID of shared memory exclusive semaphore */
429 RET_API l_ret; /* Return of the functions */
430 RET_API l_ret_api; /* Return of the functions */
432 LONLAT lonlat; /* Position */
434 /* Get Semaphore ID */
436 sem_id = _pb_CreateSemaphore(const_cast<char *>(LONLAT_SEMAPHO_NAME));
440 /* Semaphore ID successfully acquired */
441 l_ret_api = _pb_SemLock(sem_id); /* Semaphore Lock */
443 if (l_ret_api == RET_NORMAL) {
444 /* Semaphore lock successful */
446 /* When the shared memory is not linked */
447 if (shared_addr == NULL) {
448 /* Link to shared memory */
449 /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */
450 VehicleSensLinkSharedMemory(const_cast<char *>(LONLAT_SHARE_NAME),
451 reinterpret_cast<void **>(&shared_addr));
454 if (shared_addr != NULL) {
455 /* The link to shared memory is successful. */
457 /* Acquires data from the non-volatile memory and writes it to the shared memory. */
458 l_ret_api = VehicleSensReadNVLonLat(&lonlat);
459 if (l_ret_api == RET_NORMAL) {
460 *shared_addr = lonlat;
463 /* When data acquisition from non-volatile memory fails */
464 (*shared_addr).latitude = SENSORLOCATION_LATITUDE_INIT_VALUE;
465 (*shared_addr).longitude = SENSORLOCATION_LONGITUDE_INIT_VALUE;
471 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "shared_addr == NULL \r\n");
474 /* Semaphore unlock */
475 l_ret_api = _pb_SemUnlock(sem_id);
476 if (l_ret_api != RET_NORMAL) {
477 /* Semaphore unlock failure */
479 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemUnlock failed");
482 /* Semaphore ID acquisition failure */
484 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SemLock failed");
488 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "sem_id == 0");
494 /*******************************************************************************
495 * MODULE : VehicleSensWriteSharedMemory
496 * ABSTRACT : Write Shared Memory
497 * FUNCTION : Write Shared Memory
498 * ARGUMENT : DID : Data ID
501 ******************************************************************************/
502 void VehicleSensWriteSharedMemory(DID ul_did) {
503 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
505 case VEHICLE_DID_MAIN_GPS_INTERRUPT_SIGNAL:
506 case VEHICLE_DID_SYS_GPS_INTERRUPT_SIGNAL:
508 (void)VehicleSensWriteDataGpsInterruptSignal(ul_did);
511 case VEHICLE_DID_GYRO_CONNECT_STATUS:
513 (void)VehicleSensWriteDataGyroConnectStatus(ul_did);
517 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "DID is unknown. \r\n");