2 * @copyright Copyright (c) 2019-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_Did_GyroYExt_l.cpp
19 * Subsystem name :Vehicle sensor process
20 * Program name :Vehicle sensor data master(POSHAL_DID_GYRO_EXT)
21 * Module configuration :VehicleSensInitGyroYExtl() Vehicle Sensor GYRO (Initial Delivery) Initialization Functions
22 * :VehicleSensSetGyroYExtlG() Vehicle Sensor GYRO (Initial Delivery) Set Functions
23 * :VehicleSensGetGyroYExtl() Vehicle Sensor GYRO (Initial Delivery) Get Functions
24 ******************************************************************************/
26 #include "VehicleSens_DataMaster.h"
28 #if CONFIG_SENSOR_EXT_VALID /* Initial Sensor Support */
29 /*************************************************/
31 /*************************************************/
32 static VEHICLESENS_DATA_MASTER_EXT gstGyroYExt_l; // NOLINT(readability/nolint)
34 /*******************************************************************************
35 * MODULE : VehicleSensInitGyroYExtl
36 * ABSTRACT : Vehicle Sensor GYRO_Y Initialization Functions(Initial delivery)
37 * FUNCTION : GYRO data master initialization process
41 ******************************************************************************/
42 void VehicleSensInitGyroYExtl(void) {
45 memset(&gstGyroYExt_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_EXT));
46 gstGyroYExt_l.ul_did = POSHAL_DID_GYRO_Y;
47 gstGyroYExt_l.us_size = VEHICLE_DSIZE_GYRO_EXT_INIT;
49 pus = reinterpret_cast<u_int16 *>(gstGyroYExt_l.uc_data);
50 memset(reinterpret_cast<void*>(pus), VEHICLE_DINIT_GYRO, VEHICLE_DSIZE_GYRO_EXT);
53 /*******************************************************************************
54 * MODULE : VehicleSensSetGyroYExtlG
55 * ABSTRACT : Vehicle Sensor GYRO_Y SET Functions(Initial delivery)
56 * FUNCTION : Update the GYRO data master
57 * ARGUMENT : *pst_data : Pointer to the message data received by the direct line
59 * RETURN : VEHICLESENS_EQ : No data change
60 * VEHICLESENS_NEQ : Data change
61 ******************************************************************************/
62 void VehicleSensSetGyroYExtlG(const LSDRV_LSDATA_G *pst_data) {
63 VEHICLESENS_DATA_MASTER_EXT *pst_master;
68 pst_master = &gstGyroYExt_l;
69 us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
71 /* Retrieve the location where the received one is stored */
72 us_start = gstPkgTempExt.start_point[GyroY];
74 /* Stored in data master(Order of reception)*/
75 if (us_start >= VEHICLE_DKEEP_MAX) {
76 /* Store the latest one at position 0 */
77 us_start = VEHICLE_DATA_POS_00;
78 /* If you are discarding old data,,Set a flag */
79 gstPkgTempExt.data_break = VEHICLE_SNS_BREAK;
81 pst_master->ul_did = pst_data->ul_did;
82 pst_master->uc_rcvflag = VEHICLE_RCVFLAG_ON;
83 for (us_cnt = 0; us_cnt < us_size; us_cnt++) {
84 pst_master->uc_data[us_start * us_size + us_cnt] = (u_int8)(pst_data->uc_data[us_cnt]);
87 /* Update next storage start position and latest data storage position */
89 gstPkgTempExt.start_point[GyroY] = us_start;
91 /* Update data master size */
92 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
93 /* Make the size of all extended data masters */
94 pst_master->us_size = VEHICLE_DSIZE_GYRO_EXT;
96 /* Add the size of one received data item */
97 pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
101 /*******************************************************************************
102 * MODULE : VehicleSensGetGyroYExtl
103 * ABSTRACT : Vehicle Sensor GYRO_Y GET Functions(Initial delivery)
104 * FUNCTION : Provide a GYRO data master
105 * ARGUMENT : *pst_data : Pointer to the data master acquisition destination
108 ******************************************************************************/
109 void VehicleSensGetGyroYExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
110 const VEHICLESENS_DATA_MASTER_EXT *pst_master;
111 uint16_t us_size = 0;
112 uint16_t us_data_cnt = 0; // Number of data contained
113 uint16_t us_loop_cnt = 0; // 64 over index
115 /* Store the data master in the specified destination. */
116 pst_master = &gstGyroYExt_l;
117 pst_data->ul_did = pst_master->ul_did;
118 pst_data->us_size = pst_master->us_size;
119 pst_data->uc_rcvflag = pst_master->uc_rcvflag;
121 us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
123 /* Checking whether the number of stored entries is looped */
124 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
125 us_data_cnt = VEHICLE_DKEEP_MAX;
127 us_data_cnt = gstPkgTempExt.start_point[GyroY];
130 /* Acquire data from the oldest data master */
131 for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
132 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
133 /* Get information before loop */
134 if (gstPkgTempExt.start_point[GyroY] + us_cnt < VEHICLE_DKEEP_MAX) {
135 memcpy(&pst_data->uc_data[us_cnt * us_size],
136 &pst_master->uc_data[(gstPkgTempExt.start_point[GyroY] + us_cnt) * us_size], us_size);
138 memcpy(&pst_data->uc_data[us_cnt * us_size],
139 &pst_master->uc_data[us_loop_cnt * us_size], us_size);
143 memcpy(&pst_data->uc_data[us_cnt * us_size],
144 &pst_master->uc_data[us_cnt * us_size], us_size);
148 #endif // CONFIG_SENSOR_EXT_VALID