summaryrefslogtreecommitdiffstats
path: root/hal
diff options
context:
space:
mode:
Diffstat (limited to 'hal')
-rwxr-xr-xhal/boot_hal/LICENSE177
-rwxr-xr-xhal/boot_hal/Makefile65
-rwxr-xr-xhal/boot_hal/hal_api/boot_hal.h228
-rwxr-xr-xhal/boot_hal/inc/boot_hal_boothallog.h76
-rwxr-xr-xhal/boot_hal/src/boot_hal.cpp313
-rwxr-xr-xhal/can_hal/LICENSE177
-rwxr-xr-xhal/can_hal/Makefile19
-rwxr-xr-xhal/can_hal/README.md3
-rwxr-xr-xhal/can_hal/can_hal.mk39
-rwxr-xr-xhal/can_hal/hal_api/can_hal.h303
-rwxr-xr-xhal/can_hal/src/Makefile52
-rwxr-xr-xhal/can_hal/src/can_hal_api.cpp166
-rwxr-xr-xhal/can_hal/src/can_hal_core.cpp372
-rwxr-xr-xhal/can_hal/src/can_hal_stm.cpp243
-rwxr-xr-xhal/can_hal/src/driver_can__CWORD31_.c472
-rwxr-xr-xhal/can_hal/src/inc/can_hal_core.h37
-rwxr-xr-xhal/can_hal/src/inc/can_hal_frameworkunifiedlog.h76
-rwxr-xr-xhal/can_hal/src/inc/can_hal_internal.h31
-rwxr-xr-xhal/can_hal/src/inc/can_hal_stm.h45
-rwxr-xr-xhal/can_hal/src/inc/can_mng_api.h120
-rwxr-xr-xhal/clock_hal/LICENSE177
-rwxr-xr-xhal/clock_hal/Makefile67
-rwxr-xr-xhal/clock_hal/README.md3
-rwxr-xr-xhal/clock_hal/hal_api/clock_hal.h67
-rwxr-xr-xhal/clock_hal/inc/clock_hal_clockhallog.h76
-rwxr-xr-xhal/clock_hal/src/clock_hal.cpp91
-rwxr-xr-xhal/deck_hal/LICENSE177
-rwxr-xr-xhal/deck_hal/Makefile67
-rwxr-xr-xhal/deck_hal/hal_api/deck_hal.h322
-rwxr-xr-xhal/deck_hal/inc/deck_hal_deckhallog.h76
-rwxr-xr-xhal/deck_hal/src/deck_hal.cpp159
-rwxr-xr-xhal/input_hal/LICENSE177
-rwxr-xr-xhal/input_hal/Makefile81
-rwxr-xr-xhal/input_hal/README.md3
-rwxr-xr-xhal/input_hal/hal_api/input_hal.h696
-rwxr-xr-xhal/input_hal/hal_api/peripheral_service/aglinput.h536
-rwxr-xr-xhal/input_hal/hal_api/peripheral_service/extinput.h27
-rwxr-xr-xhal/input_hal/inc/input_drm.h22
-rwxr-xr-xhal/input_hal/inc/input_hal_debug.h57
-rwxr-xr-xhal/input_hal/inc/input_hal_frameworkunifiedlog.h76
-rwxr-xr-xhal/input_hal/inc/input_hal_internal.h107
-rwxr-xr-xhal/input_hal/inc/input_touch_ilitek.h27
-rwxr-xr-xhal/input_hal/inc/input_udev_monitor.h40
-rwxr-xr-xhal/input_hal/inc/input_util.h46
-rwxr-xr-xhal/input_hal/src/input_drm.cpp128
-rwxr-xr-xhal/input_hal/src/input_hal.cpp267
-rwxr-xr-xhal/input_hal/src/input_touch_ilitek.cpp226
-rwxr-xr-xhal/input_hal/src/input_udev_monitor.cpp566
-rwxr-xr-xhal/input_hal/src/input_util.cpp77
-rwxr-xr-xhal/nv_hal/LICENSE177
-rwxr-xr-xhal/nv_hal/Makefile65
-rwxr-xr-xhal/nv_hal/hal_api/nv_hal.h245
-rwxr-xr-xhal/nv_hal/inc/nv_hal_nvhallog.h76
-rwxr-xr-xhal/nv_hal/src/nv_hal.cpp242
-rwxr-xr-xhal/positioning_hal/LICENSE177
-rwxr-xr-xhal/positioning_hal/Makefile91
-rwxr-xr-xhal/positioning_hal/README.md3
-rwxr-xr-xhal/positioning_hal/hal_api/gps_hal.h932
-rwxr-xr-xhal/positioning_hal/hal_api/positioning_hal.h872
-rwxr-xr-xhal/positioning_hal/inc/Common/LineSensDrv_Api.h44
-rwxr-xr-xhal/positioning_hal/inc/Common/MDev_Gps_API.h51
-rwxr-xr-xhal/positioning_hal/inc/Common/positioning_common.h63
-rwxr-xr-xhal/positioning_hal/inc/Common/positioning_def.h307
-rwxr-xr-xhal/positioning_hal/inc/Common/positioning_log.h43
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_GpsRecv.h170
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_GpsRollOver.h34
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_Gps_Common.h187
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_Gps_Main.h311
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_Gps_Mtrx.h90
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_Gps_Nmea.h313
-rwxr-xr-xhal/positioning_hal/inc/GpsCommon/MDev_Gps_TimerCtrl.h113
-rwxr-xr-xhal/positioning_hal/inc/LineSensDrv/LineSensDrv_Sensor.h183
-rwxr-xr-xhal/positioning_hal/inc/LineSensDrv/LineSensDrv_Thread.h66
-rwxr-xr-xhal/positioning_hal/src/Common/positioning_common.cpp388
-rwxr-xr-xhal/positioning_hal/src/Common/positioning_hal.cpp49
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_GpsRecv.cpp608
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_GpsRollOver.cpp275
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_Gps_API.cpp491
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_Gps_Common.cpp2105
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_Gps_Main.cpp362
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_Gps_Mtrx.cpp866
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_Gps_Nmea.cpp928
-rwxr-xr-xhal/positioning_hal/src/GpsCommon/MDev_Gps_TimerCtrl.cpp293
-rwxr-xr-xhal/positioning_hal/src/LineSensDrv/LineSensDrv_Api.cpp136
-rwxr-xr-xhal/positioning_hal/src/LineSensDrv/LineSensDrv_Sensor.cpp622
-rwxr-xr-xhal/positioning_hal/src/LineSensDrv/LineSensDrv_Thread.cpp125
-rwxr-xr-xhal/power_hal/LICENSE177
-rwxr-xr-xhal/power_hal/Makefile66
-rwxr-xr-xhal/power_hal/README.md3
-rwxr-xr-xhal/power_hal/hal_api/power_hal.h572
-rwxr-xr-xhal/power_hal/src/power_hal.cpp97
-rwxr-xr-xhal/security_hal/LICENSE177
-rwxr-xr-xhal/security_hal/Makefile67
-rwxr-xr-xhal/security_hal/hal_api/security_hal.h1131
-rwxr-xr-xhal/security_hal/inc/security_hal_securityhallog.h76
-rwxr-xr-xhal/security_hal/src/security_hal.cpp615
-rwxr-xr-xhal/soc_temperature_hal/LICENSE177
-rwxr-xr-xhal/soc_temperature_hal/Makefile66
-rwxr-xr-xhal/soc_temperature_hal/hal_api/soc_temperature_hal.h89
-rwxr-xr-xhal/soc_temperature_hal/inc/soc_temperature_hal_soctemperaturehallog.h75
-rwxr-xr-xhal/soc_temperature_hal/src/soc_temperature_hal.cpp106
-rwxr-xr-xhal/update_hal/LICENSE177
-rwxr-xr-xhal/update_hal/Makefile34
-rwxr-xr-xhal/update_hal/hal_api/update_hal.h165
-rwxr-xr-xhal/update_hal/include/update_hal.h165
-rwxr-xr-xhal/usb_hal/LICENSE177
-rwxr-xr-xhal/usb_hal/Makefile66
-rwxr-xr-xhal/usb_hal/hal_api/usb_hal.h379
-rwxr-xr-xhal/usb_hal/inc/usb_hal_debug.h31
-rwxr-xr-xhal/usb_hal/inc/usb_hal_internal.h165
-rwxr-xr-xhal/usb_hal/inc/usb_hal_usbhallog.h77
-rwxr-xr-xhal/usb_hal/src/usb_hal.cpp500
-rwxr-xr-xhal/vehicle_hal/LICENSE177
-rwxr-xr-xhal/vehicle_hal/Makefile69
-rwxr-xr-xhal/vehicle_hal/README.md3
-rwxr-xr-xhal/vehicle_hal/hal_api/vehicle_hal.h210
-rwxr-xr-xhal/vehicle_hal/inc/vehicle_hal_frameworkunifiedlog.h78
-rwxr-xr-xhal/vehicle_hal/src/vehicle_hal.cpp398
-rwxr-xr-xhal/video_in_hal/LICENSE177
-rwxr-xr-xhal/video_in_hal/Makefile61
-rwxr-xr-xhal/video_in_hal/README.md3
-rwxr-xr-xhal/video_in_hal/hal_api/video_in_hal.h567
-rwxr-xr-xhal/video_in_hal/src/video_in_hal.c50
123 files changed, 26781 insertions, 0 deletions
diff --git a/hal/boot_hal/LICENSE b/hal/boot_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/boot_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/boot_hal/Makefile b/hal/boot_hal/Makefile
new file mode 100755
index 0000000..d184316
--- /dev/null
+++ b/hal/boot_hal/Makefile
@@ -0,0 +1,65 @@
+#
+# @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libboot_hal.so
+
+HEADER := hal_api/boot_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+
+RPATH :=
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+######### source files ##########################
+VPATH := src
+OBJS := boot_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/boot_hal/hal_api/boot_hal.h b/hal/boot_hal/hal_api/boot_hal.h
new file mode 100755
index 0000000..783db97
--- /dev/null
+++ b/hal/boot_hal/hal_api/boot_hal.h
@@ -0,0 +1,228 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_BOOT_HAL_H_
+#define HAL_API_BOOT_HAL_H_
+
+#include <stdint.h>
+#include <native_service/frameworkunified_types.h>
+
+/**
+ * @file boot_hal.h
+ * @brief This file provides API for get boot info from boot device, set boot info to boot device,
+ * set next boot mode to coldstart and get current boot mode
+ */
+
+/** @addtogroup reproservice
+ * @{
+ */
+/** @addtogroup boot_hal
+ * @ingroup reprogramming_service
+ * @{
+ */
+
+/**
+ * \~english BootHalBootMode
+ */
+enum BootHalBootMode{
+ /**
+ * \~english cold start
+ */
+ COLD_START = 0,
+ /**
+ * \~english hot start
+ */
+ HOT_START = 1,
+};
+
+/**
+ * \~english BootHalUpTableID
+ */
+enum BootHalUpTableID{
+ /**
+ * \~english UBOOT
+ */
+ BOOTHAL_SIDE_IDX_UBOOT = 0,
+ /**
+ * \~english Secure loader
+ */
+ BOOTHAL_SIDE_IDX_SECURE = 1,
+ /**
+ * \~english MAIN software
+ */
+ BOOTHAL_SIDE_IDX_MAINSOFT = 2,
+ /**
+ * \~english Max num of modules(include reserves)
+ */
+ BOOTHAL_NUMTARGS = 20
+};
+
+/**
+ * \~english BootHalStatus
+ */
+typedef enum BootHalStatus {
+/**
+ * \~english Success
+ */
+ BOOTHAL_RET_SUCCESS = 0,
+/**
+ * \~english No permission to operate
+ */
+ BOOTHAL_RET_ERR_PERMISSION = 1,
+/**
+ * \~english Time out
+ */
+ BOOTHAL_RET_ERR_TIMEOUT = 2,
+/**
+ * \~english Status error
+ */
+ BOOTHAL_RET_ERR_STATUS = 3,
+/**
+ * \~english Write error
+ */
+ BOOTHAL_RET_ERR_WRITE = 4,
+/**
+ * \~english Paramater error
+ */
+ BOOTHAL_RET_ERR_PARAM = 5,
+/**
+ * \~english Internal IO error(open, read, write, strstr, close)
+ */
+ BOOTHAL_RET_ERR_FAIL = 6,
+} BootHalStatus;
+
+/**
+ * \~english Not rewrite.
+ */
+#define BOOTHAL_SIDE_NONE 0
+/**
+ * \~english Rewrites side A.
+ */
+#define BOOTHAL_SIDE_A 1
+/**
+ * \~english Rewrites side B.
+ */
+#define BOOTHAL_SIDE_B 2
+/**
+ * \~english Max parameter num
+ */
+#define BOOTHAL_NUMSIDE_MAX 3
+
+/**\ingroup setSide
+ * \~english @par Brief
+ * This API set boot info to boot device, the caller control this API not be called at the
+ * same time
+ * \~english @param [in] upTableID
+ * unsigned int - Boot info
+ * \~english @retval BOOTHAL_RET_SUCCESS OK
+ * \~english @retval BOOTHAL_RET_ERR_PARAM Parameter error
+ * \~english @retval BOOTHAL_RET_ERR_WRITE Write error
+ * \~english @retval BOOTHAL_RET_ERR_FAIL Internal IO error
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter upTableId is NULL. [BOOTHAL_RET_ERR_PARAM]
+ * - If write /dev/mmcblk0boot1 return -1. [BOOTHAL_RET_ERR_WRITE]
+ * - Internal IO error(open, read, lseek). [BOOTHAL_RET_ERR_FAIL]
+ * \~english @par Detail
+ * - This API set boot info.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see getSide
+ */
+BootHalStatus setSide(unsigned int upTableID[]);
+
+/**\ingroup getSide
+ * \~english @par Brief
+ * Get boot info from boot device
+ * \~english @param [out] upTableID
+ * unsigned int - boot info
+ * \~english @retval BOOTHAL_RET_SUCCESS OK
+ * \~english @retval BOOTHAL_RET_ERR_PARAM Parameter error
+ * \~english @retval BOOTHAL_RET_ERR_FAIL Internal IO error
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter upTableId is NULL. [BOOTHAL_RET_ERR_PARAM]
+ * - Internal IO error.[BOOTHAL_RET_ERR_FAIL]
+ * \~english @par Detail
+ * - This API get boot info from boot device.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see setSide
+ */
+BootHalStatus getSide(unsigned int upTableID[]);
+
+/**\ingroup setBootColdStart
+ * \~english @par Brief
+ * Set next boot to ColdStart mode.
+ * \~english @retval BOOTHAL_RET_SUCCESS OK
+ * \~english @retval BOOTHAL_RET_ERR_FAIL set next boot start mode failed
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error.[BOOTHAL_RET_ERR_FAIL]
+ * \~english @par Detail
+ * - This API Set next boot to ColdStart mode.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see getBootMode
+ */
+BootHalStatus setBootColdStart(void);
+
+/**\ingroup getBootMode
+ * \~english @par Brief
+ * Get boot mode.
+ * \~english @param [out] mode
+ * unsigned int - boot mode(COLD_START or HOT_START)
+ * \~english @retval BOOTHAL_RET_SUCCESS OK
+ * \~english @retval BOOTHAL_RET_ERR_PARAM Parameter error
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter mode is NULL. [BOOTHAL_RET_ERR_PARAM]
+ * \~english @par Detail
+ * - This API get boot mode.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see setBootColdStart
+ */
+BootHalStatus getBootMode(uint32_t *mode);
+
+/** @}*/ // end of boot_hal
+/** @}*/ // end of reprogramming_service
+
+#endif // HAL_API_BOOT_HAL_H_
diff --git a/hal/boot_hal/inc/boot_hal_boothallog.h b/hal/boot_hal/inc/boot_hal_boothallog.h
new file mode 100755
index 0000000..4a037ee
--- /dev/null
+++ b/hal/boot_hal/inc/boot_hal_boothallog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_BOOT_HAL_BOOTHALLOG_H_
+#define INC_BOOT_HAL_BOOTHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_BOOT_HAL_BOOTHALLOG_H_
diff --git a/hal/boot_hal/src/boot_hal.cpp b/hal/boot_hal/src/boot_hal.cpp
new file mode 100755
index 0000000..d4d5581
--- /dev/null
+++ b/hal/boot_hal/src/boot_hal.cpp
@@ -0,0 +1,313 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <boot_hal.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/vfs.h>
+
+#include <cstdio>
+#include <cerrno>
+#include <cstring>
+
+#include "boot_hal_boothallog.h"
+
+#define BOOT_PARTATION "/dev/mmcblk0boot1"
+#define BOOTINFO_FILEA "/repro/mmcblk0boot1-launch_a.bin"
+#define BOOTINFO_FILEB "/repro/mmcblk0boot1-launch_b.bin"
+
+#define MMCBLK0BOOT1_FORCE_RO "/sys/class/block/mmcblk0boot1/force_ro"
+#define MMCBLK0BOOT1_SIZE_PATH "/sys/class/block/mmcblk0boot1/size"
+#define MMCBLK0BOOT1_SIZE_DEF (0x1000000)
+#define BOOTINFO_SIZE (0x20000)
+#define SECTOR_SIZE (512)
+#define FILEPATH_MAX (256)
+
+#define BOOT_CMDLINE "/proc/cmdline"
+#define CMDLINE_MAX_SIZE (256)
+#define BOOT_ROOTFS_A "/dev/mmcblk0p1"
+#define BOOT_ROOTFS_B "/dev/mmcblk0p2"
+#define BOOTARGS_LST_ROOT "root="
+
+
+#define BOOT_COPYBUF_SIZE (64 * 1024)
+
+static int EnableMmcBlk(const char *path) {
+ int fd;
+ char enable[] = "0";
+
+ if ((fd = open(path, O_RDWR)) < 0) {
+ return -1;
+ }
+
+ if (write(fd, enable, sizeof(enable)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+ return 0;
+}
+
+static int GetMmcBlkCount(const char *path) {
+ int fd;
+ char block_size[16] = {0};
+
+ if ((fd = open(path, O_RDONLY)) < 0) {
+ return -1;
+ }
+
+ if (read(fd, block_size, sizeof(block_size)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+ return strtol(block_size, NULL, 10);
+}
+
+static ssize_t BootReadN(int fd, void *buffer, size_t n) {
+ size_t tot_read;
+ char *buf;
+
+ buf = reinterpret_cast<char *>(buffer);
+ for (tot_read = 0; tot_read < n;) {
+ ssize_t num_read;
+ num_read = read(fd, buf, n - tot_read);
+
+ if (num_read == 0) {
+ return tot_read;
+ }
+ if (num_read == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ return -1;
+ }
+ }
+ tot_read += num_read;
+ buf += num_read;
+ }
+ return tot_read;
+}
+
+static ssize_t BootWriteN(int fd, const void *buffer, size_t n) {
+ size_t tot_written;
+ const char *buf;
+
+ buf = (const char *)buffer;
+ for (tot_written = 0; tot_written < n;) {
+ ssize_t num_written;
+ num_written = write(fd, buf, n - tot_written);
+
+ if (num_written <= 0) {
+ if (num_written == -1 && errno == EINTR) {
+ continue;
+ } else {
+ return -1;
+ }
+ }
+ tot_written += num_written;
+ buf += num_written;
+ }
+ return tot_written;
+}
+
+BootHalStatus setSide(unsigned int upTableID[]) {
+ BootHalStatus ret = BOOTHAL_RET_ERR_FAIL;
+ int binfo_fd = -1;
+ int mmc_fd = -1;
+ int sector_count = 0;
+ char *buf = NULL;
+ char binfo_file[FILEPATH_MAX] = {0};
+ off_t mmc_offset;
+
+ if (NULL == upTableID) {
+ return BOOTHAL_RET_ERR_PARAM;
+ }
+
+ if (upTableID[BOOTHAL_SIDE_IDX_MAINSOFT] == BOOTHAL_SIDE_A) {
+ snprintf(binfo_file, FILEPATH_MAX, "%s", BOOTINFO_FILEA);
+ } else if (upTableID[BOOTHAL_SIDE_IDX_MAINSOFT] == BOOTHAL_SIDE_B) {
+ snprintf(binfo_file, FILEPATH_MAX, "%s", BOOTINFO_FILEB);
+ } else {
+ ret = BOOTHAL_RET_ERR_PARAM;
+ goto exit;
+ }
+
+ binfo_fd = open(binfo_file, O_RDONLY);
+ if (binfo_fd < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "open %s:%s", binfo_file, strerror(errno));
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ mmc_fd = open(BOOT_PARTATION, O_WRONLY);
+ if (mmc_fd < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "open %s:%s", BOOT_PARTATION, strerror(errno));
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ /*
+ * enable mmcblk0boot1 for write
+ */
+ if (EnableMmcBlk(MMCBLK0BOOT1_FORCE_RO) < 0) {
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ /*
+ * Get sector count of mmcblk0boot1 block from sys-file, every sector size is 512byte.
+ * The mmcblk0boot1 block default size is 16M.
+ */
+ if ((sector_count = GetMmcBlkCount(MMCBLK0BOOT1_SIZE_PATH)) < 0) {
+ mmc_offset = MMCBLK0BOOT1_SIZE_DEF - BOOTINFO_SIZE;
+ } else {
+ mmc_offset = sector_count * SECTOR_SIZE - BOOTINFO_SIZE;
+ }
+
+ /*
+ * The environment should be write to the latest 128K of mmcblk0boot1.
+ */
+ if (lseek(mmc_fd, mmc_offset, SEEK_SET) < 0) {
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ buf = reinterpret_cast<char *>(mmap(NULL, BOOT_COPYBUF_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0));
+ if (buf == MAP_FAILED) {
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ while (1) {
+ ssize_t rd, wr;
+
+ rd = BootReadN(binfo_fd, buf, BOOT_COPYBUF_SIZE);
+ if (!rd) {
+ // EOF
+ break;
+ }
+ if (rd < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "read:%s", strerror(errno));
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ wr = BootWriteN(mmc_fd, buf, rd);
+ if (wr < rd) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "write(%s):%s", BOOT_PARTATION, strerror(errno));
+ ret = BOOTHAL_RET_ERR_WRITE;
+ goto exit;
+ }
+ }
+
+ if (fsync(mmc_fd) < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "fsync:%s", strerror(errno));
+ }
+ ret = BOOTHAL_RET_SUCCESS;
+
+exit:
+ if (binfo_fd >= 0) {
+ if (close(binfo_fd) < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "close:%s", strerror(errno));
+ }
+ }
+
+ if (mmc_fd >= 0) {
+ if (close(mmc_fd) < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "close:%s", strerror(errno));
+ }
+ }
+
+ if (buf) {
+ munmap(buf, BOOT_COPYBUF_SIZE);
+ }
+
+ return ret;
+}
+
+BootHalStatus getSide(unsigned int upTableID[]) {
+ BootHalStatus ret = BOOTHAL_RET_SUCCESS;
+ int fd;
+ int rd_size;
+ char buf[CMDLINE_MAX_SIZE] = {0};
+ char *rootfs = NULL;
+
+ if (NULL == upTableID) {
+ return BOOTHAL_RET_ERR_PARAM;
+ }
+
+ if ((fd = open(BOOT_CMDLINE, O_RDONLY)) < 0) {
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ if ((rd_size = BootReadN(fd, buf, CMDLINE_MAX_SIZE)) < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "read %s error:%s", BOOT_CMDLINE, strerror(errno));
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ rootfs = strstr(buf, BOOTARGS_LST_ROOT);
+ if (!rootfs) {
+ ret = BOOTHAL_RET_ERR_FAIL;
+ goto exit;
+ }
+
+ rootfs += strlen(BOOTARGS_LST_ROOT);
+ if (strncmp(rootfs, BOOT_ROOTFS_A, strlen(BOOT_ROOTFS_A)) == 0 &&
+ (rootfs[strlen(BOOT_ROOTFS_A)] == ' ' || rootfs[strlen(BOOT_ROOTFS_A)] == '\0')) {
+ upTableID[BOOTHAL_SIDE_IDX_MAINSOFT] = BOOTHAL_SIDE_A;
+ } else if (strncmp(rootfs, BOOT_ROOTFS_B, strlen(BOOT_ROOTFS_B)) == 0 &&
+ (rootfs[strlen(BOOT_ROOTFS_B)] == ' ' || rootfs[strlen(BOOT_ROOTFS_B)] == '\0')) {
+ upTableID[BOOTHAL_SIDE_IDX_MAINSOFT] = BOOTHAL_SIDE_B;
+ } else {
+ ret = BOOTHAL_RET_ERR_FAIL;
+ }
+
+exit:
+ if (fd >= 0) {
+ if (close(fd) < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "close:%s", strerror(errno));
+ }
+ }
+
+ return ret;
+}
+
+BootHalStatus setBootColdStart(void) {
+ /*
+ * Note.
+ * This feature needs to be implemented by the vendor.
+ */
+ return BOOTHAL_RET_SUCCESS;
+}
+
+BootHalStatus getBootMode(uint32_t *mode) {
+ if (NULL == mode) {
+ return BOOTHAL_RET_ERR_PARAM;
+ }
+
+ *mode = COLD_START;
+ return BOOTHAL_RET_SUCCESS;
+}
diff --git a/hal/can_hal/LICENSE b/hal/can_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/can_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/can_hal/Makefile b/hal/can_hal/Makefile
new file mode 100755
index 0000000..61e5cc2
--- /dev/null
+++ b/hal/can_hal/Makefile
@@ -0,0 +1,19 @@
+#
+# @copyright Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+SUBDIRS := src
+
+include ./can_hal.mk
diff --git a/hal/can_hal/README.md b/hal/can_hal/README.md
new file mode 100755
index 0000000..e1a5e84
--- /dev/null
+++ b/hal/can_hal/README.md
@@ -0,0 +1,3 @@
+can_hal library
+==================
+CAN HAL implementation library for AGL Reference Board.
diff --git a/hal/can_hal/can_hal.mk b/hal/can_hal/can_hal.mk
new file mode 100755
index 0000000..19a824d
--- /dev/null
+++ b/hal/can_hal/can_hal.mk
@@ -0,0 +1,39 @@
+#
+# @copyright Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+CURRENT_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+
+#############################################################
+# COMPONENT_NAME must not be blank and be named snake_case
+
+COMPONENT_NAME ?= can_hal
+
+#############################################################
+
+#############################################################
+# You can add several flags and libraries.
+# When you add -I or -L path, DO NOT USE relative path.
+# Instead, use $(CURRENT_DIR) variable
+# that indicates the path this .mk file is stored.
+
+COMPONENT_CFLAGS :=
+COMPONENT_CXXFLAGS :=
+COMPONENT_LDLIBS :=
+COMPONENT_LDFLAGS :=
+
+##############################################################
+
+include $(SDKTARGETSYSROOT)/usr/agl/share/agl.mk
diff --git a/hal/can_hal/hal_api/can_hal.h b/hal/can_hal/hal_api/can_hal.h
new file mode 100755
index 0000000..5f3ef4f
--- /dev/null
+++ b/hal/can_hal/hal_api/can_hal.h
@@ -0,0 +1,303 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef HAL_API_CAN_HAL_H_
+#define HAL_API_CAN_HAL_H_
+/**
+ * @file can_hal.h
+ */
+
+/** @addtogroup communication
+ * @{
+ */
+/** @addtogroup can_hal
+ * @ingroup communication
+ * @{
+ */
+
+#include <native_service/frameworkunified_types.h>
+#include <string>
+
+/**
+ * \~english Max data length of nomarl can send
+ */
+#define CAN_NORMAL_MESSAGE_LEN (8)
+
+/**
+ * \~english Maximum data length
+ */
+#define CAN_MESSAGE_LEN (2048)
+
+/**
+ * \~english Maximum CAN_ID data length
+ */
+#define CAN_NUM_MAX (125)
+
+/**
+ * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_CAN_SEND_STATUS, CANHalSndStsProcess);
+ * @endcode
+ * \~english Command ID to send CAN data and get the send status
+ */
+#define CID_CANHAL_CMD_CAN_SEND_STATUS (0x0A03)
+
+/**
+ * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_CAN_RECV, CANHalRcvProcess);
+ * @endcode
+ * \~english Command ID to receive the CAN data
+ */
+#define CID_CANHAL_CMD_CAN_RECV (0x0A04)
+
+/**
+ * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_CAN_READY, AnyCallback);
+ * @endcode
+ * \~english Command ID to receive Global CAN is ready.
+ */
+#define CID_CANHAL_CMD_CAN_READY (0x0A0C)
+
+/**
+ * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_ERROR_NOTIFY, AnyCallback);
+ * @endcode
+ * \~english Command ID to receive can hal error.
+ */
+#define CID_CANHAL_CMD_ERROR_NOTIFY (0x0A10)
+
+/**
+ * \~english No target address
+ */
+#define CAN_NTA_NONE (0x00)
+
+/**
+ * \~english Size of error message.
+ */
+#define CANHAL_ERROR_MESSAGE_LEN (2048)
+
+/**
+ * \~english Return type of the API
+ */
+enum CANHAL_RET_API {
+ CANHAL_RET_NORMAL = 0, //!< \~english API Success
+ CANHAL_RET_ERR_ERR, //!< \~english API Failed
+ CANHAL_RET_ERR_PARAM, //!< \~english Parameter error
+ CANHAL_RET_ERR_STATE, //!< \~english Uninitialized(not called CanOpen)
+};
+
+/**
+ * \~english CAN type
+ */
+enum CanHalType {
+ CAN_HAL_TYPE_CAN = 0, //!< \~english CAN
+ NR_CAN_HAL_TYPES //!< \~english Number of CAN type
+};
+
+/**
+ * \~english device State
+ */
+enum DEVICE_STATE {
+ DEVICE_STATE_UNAVAILABLE, //!< \~english device unavailable
+ DEVICE_STATE_AVAILABLE, //!< \~english device available
+};
+
+/**
+ * \~english CAN Send Result
+ */
+enum CAN_SEND_RESULT {
+ CAN_SEND_RESULT_FAILURE = 0, //!< \~english Send failure
+ CAN_SEND_RESULT_SUCCESS, //!< \~english Send success
+};
+
+/**
+ * \~english structure of can data
+ */
+typedef struct CanMessageT {
+ uint32_t can_id; //!< \~english Target CAN ID
+ uint32_t dlc; //!< \~english Data length(1~2048)
+ uint8_t rid; //!< \~english Replay ID
+ uint8_t data[CAN_MESSAGE_LEN]; //!< \~english Data buffer
+} CanMessage;
+
+/**
+ * \~english structure of can send result
+ */
+typedef struct CanSendResultT {
+ uint32_t can_id; //!< \~english CAN ID
+ uint8_t rid; //!< \~english RID
+ CAN_SEND_RESULT result; //!< \~english Send result
+} CanSendResult;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \ingroup CanOpen
+ * \~english @par Brief
+ * API to start the can_hal service
+ * \~english @param [in] h_app
+ * HANDLE - Application handle
+ * \~english @param [in] type
+ * CanHalType - CAN type
+ * \~english @retval CANHAL_RET_NORMAL : API return OK
+ * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
+ * \~english @retval CANHAL_RET_ERR_ERR : Failed
+ * \~english @par Prerequisite
+ * None
+ * \~english @par Change of internal state
+ * - When calling of this API succeeds, the requested channel state is set to open.
+ * \~english @par Conditions of processing failure
+ * - Input paramter is invalid.
+ * - Internal processing failure.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Method
+ * \~english @par Detail
+ * - Perform device use preparation processing of the requested communication path.
+ * - Up to one process can use this library.
+ * \~english @see
+ * Nothing
+ */
+CANHAL_RET_API CanOpen(HANDLE h_app, CanHalType type);
+
+/**
+ * \ingroup CanClose
+ * \~english @par Brief
+ * API to stop the can_hal service
+ * \~english @param [in] h_app
+ * HANDLE - Application handle
+ * \~english @param [in] type
+ * CanHalType - CAN type
+ * \~english @retval CANHAL_RET_NORMAL : API return OK
+ * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
+ * \~english @retval CANHAL_RET_ERR_ERR : Failed
+ * \~english @retval CANHAL_RET_ERR_STATE : Failed because CanOpen is not called
+ * \~english @par Prerequisite
+ * Communication path status is open
+ * \~english @par Change of internal state
+ * - In the case of normal termination, the requested channel state is close.
+ * \~english @par Conditions of processing failure
+ * - CanOpen is not called.
+ * - Input paramter is invalid.
+ * - Internal processing failure.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Perform device use finalize processing of the requested communication path.
+ * - Up to one process can use this library.
+ * \~english @see
+ * None
+ */
+CANHAL_RET_API CanClose(HANDLE h_app, CanHalType type);
+
+/**
+ * \ingroup CanSend
+ * \~english @par Brief
+ * API to send the Can data
+ * \~english @param [in] h_app
+ * HANDLE - Application handle
+ * \~english @param [in] message
+ * const CanMessage * - Pointer to the structure of
+ * the data which is sent to the CAN
+ * \~english @param [in] type
+ * CanHalType - CAN type
+ * \~english @retval CANHAL_RET_NORMAL : API return OK
+ * \~english @retval CANHAL_RET_ERR_ERR : Failed
+ * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
+ * \~english @retval CANHAL_RET_ERR_STATE : Failed because CanOpen is not called
+ * \~english @par Prerequisite
+ * - can_hal start successfully
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Input paramter is invalid.
+ * - CanOpen is not called.
+ * - Send data to the sending thread failed.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Method
+ * \~english @par Detail
+ * - Check the sending data, if data is valid, then send the data
+ * to the sending thread; If data if invalid, then return error.
+ * - The API can only be used by 1 process.
+ * \~english @see
+ * \ref CanSendResult
+ */
+CANHAL_RET_API CanSend(HANDLE h_app, const CanMessage *message, CanHalType type);
+
+/**
+ * \ingroup CanGetVersion
+ * \~english @par Brief
+ * API to get the CAN micon version
+ * \~english @param [in] h_app
+ * HANDLE - Application handle
+ * \~english @param [out] p_version
+ * std::string * - Pointer to the version buffer
+ * \~english @retval CANHAL_RET_NORMAL : API return OK
+ * \~english @retval CANHAL_RET_ERR_STATE : Failed because CanOpen is not called
+ * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
+ * \~english @retval CANHAL_RET_ERR_ERR : Failed
+ * \~english @par Prerequisite
+ * - can_hal start successfully
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Input paramter is invalid.
+ * - CanOpen is not called.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - This API gets the CAN version.
+ * - The API can only be used by 1 process.
+ * - p_version detail\n
+ * Information on the following pink shaded part 4 BYTE in the version information \n
+ * of the CAN microcomputer is stored in string and returned.\n
+ * <table>
+ * <tr>
+ * <th></th><th>7bit-0bit</th>
+ * </tr>
+ * <tr>
+ * <td>1BYTE</td><td>7bit:M/S 6-0bit:Message kind</td>
+ * </tr>
+ * <tr>
+ * <td>2BYTE</td><td>7bit-0bit Operation Code</td>
+ * </tr>
+ * <tr>
+ * <td>3BYTE</td><td bgcolor="pink">7bit-0bit Software kind</td>
+ * </tr>
+ * <tr>
+ * <td>4BYTE</td><td bgcolor="pink">7bit-0bit version(Higher order)</td>
+ * </tr>
+ * <tr>
+ * <td>5BYTE</td><td bgcolor="pink">7bit-0bit version(middle order)</td>
+ * </tr>
+ * <tr>
+ * <td>6BYTE</td><td bgcolor="pink">7bit-0bit version(lower order)</td>
+ * </tr>
+ * </table>
+ * \~english @see
+ * None
+ */
+CANHAL_RET_API CanGetVersion(HANDLE h_app, std::string *p_version);
+
+/** @}*/ // end of can_hal
+/** @}*/ // end of communication
+#ifdef __cplusplus
+}
+#endif
+#endif // HAL_API_CAN_HAL_H_
diff --git a/hal/can_hal/src/Makefile b/hal/can_hal/src/Makefile
new file mode 100755
index 0000000..f34eb75
--- /dev/null
+++ b/hal/can_hal/src/Makefile
@@ -0,0 +1,52 @@
+#
+# @copyright Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed shared library(*.so) #############
+INST_SHLIBS = libcan_hal
+
+######### installed static library(*.a) #############
+
+######### install headers(*.h) #############
+INST_HEADERS = ../hal_api/can_hal.h
+
+######### compiled sources #############
+libcan_hal_SRCS = can_hal_core.cpp can_hal_stm.cpp can_hal_api.cpp
+libcan_hal_SRCS += driver_can__CWORD31_.c
+
+######### include paths/files ###################
+CPPFLAGS += -I./inc/
+CPPFLAGS += -I../hal_api/
+
+######### compile options #######################
+CPPFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--gc-sections
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH := /usr/lib:/usr/agl/lib
+
+######### linked library ########################
+LDLIBS += -Wl,-Bdynamic -lstdc++
+LDLIBS += -Wl,-Bdynamic -lpthread
+LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+COMPONENT_NAME =
+AGL_TOPDIR ?= $(DESTDIR)/usr
+include ../can_hal.mk
diff --git a/hal/can_hal/src/can_hal_api.cpp b/hal/can_hal/src/can_hal_api.cpp
new file mode 100755
index 0000000..86a0104
--- /dev/null
+++ b/hal/can_hal/src/can_hal_api.cpp
@@ -0,0 +1,166 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Information.
+ * This source code is a sample source code .
+ * Implementation of the function must be performed by the vendor.
+ */
+
+#include "can_hal_core.h"
+#include "can_hal_stm.h"
+#include <stdio.h>
+#include <pthread.h>
+#include <string.h>
+#include <assert.h>
+
+CANHAL_RET_API CanOpen(HANDLE h_app, CanHalType type) {
+ CANHAL_RET_API ret = CANHAL_RET_ERR_ERR;
+
+ if (!TypeIsValid(type)) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (!h_app) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (IsCanHalOpened(type)) {
+ return CANHAL_RET_NORMAL;
+ }
+
+ if (IsDeviceEnabled(type)) {
+ return CANHAL_RET_NORMAL;
+ }
+
+ ret = CanOpenCore(type);
+ if (CANHAL_RET_NORMAL != ret) {
+ return ret;
+ }
+
+ ret = CanHalCreateInternalThread(h_app, type);
+ if (CANHAL_RET_NORMAL != ret) {
+ CanCloseCore(type);
+ return ret;
+ }
+
+ SetDeviceStateEnable(type);
+ SetCanHalStateOpen(type);
+ InvokeStateCallback(type);
+ return ret;
+}
+
+CANHAL_RET_API CanClose(HANDLE h_app, CanHalType type) {
+ CANHAL_RET_API ret = CANHAL_RET_ERR_ERR;
+ if (!TypeIsValid(type)) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (!h_app) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (!IsCanHalOpened(type)) {
+ return CANHAL_RET_NORMAL;
+ }
+
+ if (IsDeviceEnabled(type)) {
+ ret = CanCloseCore(type);
+ if (CANHAL_RET_NORMAL != ret)
+ return ret;
+ }
+
+ ret = CanHalDestroyInternalThread(h_app, type);
+ if (CANHAL_RET_NORMAL != ret)
+ return ret;
+
+ SetDeviceStateDisable(type);
+ SetCanHalStateClose(type);
+ InvokeErrorCallback(h_app, type);
+
+ return ret;
+}
+
+static CANHAL_RET_API CanSendCommonCheck(const void *message,
+ enum CanHalType type) {
+ if (!TypeIsValid(type)) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (!message) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (!IsCanHalOpened(type)) {
+ return CANHAL_RET_ERR_STATE;
+ }
+
+ if (!IsDeviceEnabled(type)) {
+ return CANHAL_RET_ERR_STATE;
+ }
+
+ return CANHAL_RET_NORMAL;
+}
+
+CANHAL_RET_API CanSend(HANDLE h_app,
+ const CanMessage *message, enum CanHalType type) {
+ CANHAL_RET_API ret = CANHAL_RET_ERR_ERR;
+ void *_message = NULL;
+ ssize_t sz = 0;
+
+ ret = CanSendCommonCheck(message, type);
+ if (ret != CANHAL_RET_NORMAL)
+ return ret;
+
+ if (!h_app) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (CAN_NORMAL_MESSAGE_LEN < message->dlc) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ _message = CanHalPackMessage(h_app, (const void *)message,
+ sizeof(CanMessage), &sz);
+ if (!_message)
+ return CANHAL_RET_ERR_ERR;
+
+ ret = CanHalInternalSend(type, _message, sz);
+ CanHalDestroyPackedMessage(_message);
+ return ret;
+}
+
+CANHAL_RET_API CanGetVersion(HANDLE h_app, std::string *p_version) {
+ CanHalType type = CAN_HAL_TYPE_CAN;
+ if (!h_app) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ if (!IsCanHalOpened(type)) {
+ return CANHAL_RET_ERR_STATE;
+ }
+
+ if (!IsDeviceEnabled(type)) {
+ return CANHAL_RET_ERR_STATE;
+ }
+
+ if (NULL == p_version) {
+ return CANHAL_RET_ERR_PARAM;
+ }
+
+ *p_version = "FFFF";
+ return CANHAL_RET_NORMAL;
+}
diff --git a/hal/can_hal/src/can_hal_core.cpp b/hal/can_hal/src/can_hal_core.cpp
new file mode 100755
index 0000000..bdbdbbc
--- /dev/null
+++ b/hal/can_hal/src/can_hal_core.cpp
@@ -0,0 +1,372 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "can_hal.h"
+#include "can_hal_core.h"
+#include "can_hal_internal.h"
+#include "can_hal_frameworkunifiedlog.h"
+#include "can_hal_stm.h"
+extern "C" {
+ #include "can_mng_api.h"
+}
+#include <native_service/ns_message_center_if.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <native_service/frameworkunified_multithreading.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <string>
+
+static CanCtlApiObj g_driver_obj; // can driver handler
+
+typedef struct MessageWrapper {
+ HANDLE h_app;
+ void *message;
+} MessageWrapper;
+
+// define frame
+enum CANHAL_FRAME {
+ CANHAL_FRAME_SF = 0x00,
+ CANHAL_FRAME_FF,
+ CANHAL_FRAME_CF,
+ CANHAL_FRAME_NONE = 0xFF,
+};
+
+// Declaration of the local functions
+static EFrameworkunifiedStatus CanSendData(HANDLE h_app);
+static UINT8 PackageSendData(const CanMessage *send_msg,
+ UINT8 *send_cmd);
+static UINT8 PackageRecvData(const UINT8 *recv_data, CanMessage *message);
+static uint32_t GetCanId(const UINT8 *recv_data);
+
+#define CANHAL_VALID_NUM_INDEX 0x00
+#define CANHAL_CANID_HI_INDEX 0x00
+#define CANHAL_CANID_LO_INDEX 0x01
+#define CANHAL_DLC_INDEX 0x02
+#define CANHAL_DATA_START_INDEX 0x03
+
+#define CANHAL_RECV_DATA_LENGTH_INVALID 0xFF
+
+#define CANHAL_RECV_DATABLOCK_SIZE (0x0B)
+#define CANHAL_RECV_NTA_INDEX (0x03)
+
+// Register table for framework callback
+static const FrameworkunifiedProtocolCallbackHandler kCanHalPcbhs[] = {
+ { TX_INTERNAL, CanSendData },
+};
+
+void *CanHalPackMessage(HANDLE h_app, const void *msg, ssize_t msg_sz,
+ ssize_t *packed_sz) {
+ *packed_sz = msg_sz + sizeof(ssize_t) + sizeof(HANDLE);
+ void *p = malloc(*packed_sz);
+ if (p) {
+ char *_p = (char *)p;
+ // Set HANDLE to new buffer.
+ memcpy(_p, &h_app, sizeof(HANDLE));
+ // Set message size to new buffer
+ _p += sizeof(HANDLE);
+ *(ssize_t *)_p = msg_sz;
+ // Set message body to new buffer
+ _p += (sizeof(ssize_t));
+ memcpy(_p, msg, msg_sz);
+ }
+ return p;
+}
+
+void CanHalUnPackMessage(void *packed, HANDLE *h_app, void **msg,
+ ssize_t *msg_sz) {
+ char *_p = (char *)packed;
+ *h_app = *(HANDLE *)_p;
+ _p += sizeof(HANDLE);
+ *msg_sz = *((ssize_t *)_p);
+ _p += sizeof(ssize_t);
+ *msg = _p;
+}
+
+void CanHalDestroyPackedMessage(void *packed) {
+ free(packed);
+}
+
+// Start function of the receive thread
+void *CanRecvRun(void *arg) {
+ UINT8 data_start_index = 0;
+ UINT8 loop_num = 0;
+ UINT32 ret = 0;
+ CanCtlApiCmd recv_cmd;
+ memset(&recv_cmd, 0x00, sizeof(CanCtlApiCmd));
+ CanMessage recv_data_can;
+ memset(&recv_data_can, 0x00, sizeof(recv_data_can));
+ enum CanHalType *type = (enum CanHalType *)arg;
+
+ while (1) {
+ // call driver API to receive the can data
+ ret = CanCtlApiRcvCmd(&g_driver_obj, &recv_cmd);
+ if (CAN_CTL_RET_SUCCESS != ret) {
+ continue;
+ }
+
+ /**
+ * Receive data in the following structure:
+ * -----------------
+ * BYTE 01 | num of can data |
+ * -----------------
+ * BYTE 02 | CAN ID (Hi) |
+ * -----------------
+ * BYTE 03 | CAN ID (Lo) |
+ * -----------------
+ * BYTE 04 | DLC |
+ * -----------------
+ * BYTE 05 | DATA #1 |
+ * -----------------
+ * | ... |
+ * -----------------
+ * BYTE 12 | DATA #8 |
+ * -----------------
+ * BYTE 13 | CAN ID (Hi) |
+ * -----------------
+ * BYTE 14 | CAN ID (Lo) |
+ * -----------------
+ * BYTE 15 | DLC |
+ * -----------------
+ * BYTE 16 | DATA #1 |
+ * -----------------
+ * | ... |
+ * -----------------
+ * BYTE 23 | DATA #8 |
+ * -----------------
+ * | ... |
+ * -----------------
+ * BYTE 255 | |
+ * -----------------
+ *
+ * BYTE 0 for the invalid number of the can data
+ * CAN ID (Hi) and (Lo) combine for the CAN ID
+ * CAN ID (Hi) byte's low 7 bits is the high 7 bits of the CAN ID
+ * CAN ID (Lo) byte's high 4 bits is the low 4 bits of the CAN ID
+ * DLC for the length of the following data
+ * DATA #1 ~ #8 for the receive data, its actual length changes
+ * according to the previous DLC byte
+ */
+ UINT8 total_data_num = recv_cmd.data[CANHAL_VALID_NUM_INDEX];
+ data_start_index = 1;
+
+ for (loop_num = 0; loop_num < total_data_num; loop_num++) {
+ uint32_t can_id;
+ can_id = GetCanId(&(recv_cmd.data[data_start_index]));
+
+ // normal can
+ // Return value of the PackageRecvData is the total length
+ // of one can data package, so add to the data_start_index
+ // for the next can data package.
+ ret = PackageRecvData(&(recv_cmd.data[data_start_index]),
+ &recv_data_can);
+ if (CANHAL_RECV_DATA_LENGTH_INVALID == ret) {
+ continue;
+ }
+ data_start_index += ret;
+ CanHalReceiveNotify(*type, &(recv_data_can), sizeof(recv_data_can));
+ }
+
+ // reset buffer
+ memset(&recv_cmd, 0x00, sizeof(CanCtlApiCmd));
+ usleep(1000);
+ }
+
+ return NULL;
+}
+
+// get can id from recive buffer
+static uint32_t GetCanId(const UINT8 *recv_data) {
+ uint32_t can_id;
+ can_id = (recv_data[CANHAL_CANID_HI_INDEX] & 0x7F);
+ can_id <<= 4;
+ can_id |= ((recv_data[CANHAL_CANID_LO_INDEX] & 0xF0) >> 4);
+ return can_id;
+}
+
+static CANHAL_RET_API CanOpenCoreCAN(void) {
+ CanCtlRcvId recv_can_id;
+ memset(recv_can_id.id, 0xFF, sizeof(recv_can_id.id));
+ if (CAN_CTL_RET_SUCCESS != CanCtlApiOpen(&g_driver_obj))
+ return CANHAL_RET_ERR_ERR;
+
+ if (CAN_CTL_RET_SUCCESS != CanCtlApiSetRcvId(&g_driver_obj, &recv_can_id)) {
+ return CANHAL_RET_ERR_ERR;
+ }
+
+ return CANHAL_RET_NORMAL;
+}
+
+CANHAL_RET_API CanOpenCore(CanHalType type) {
+ CANHAL_RET_API ret = CANHAL_RET_ERR_ERR;
+ switch (type) {
+ case CAN_HAL_TYPE_CAN:
+ ret = CanOpenCoreCAN();
+ break;
+ default:
+ // Do nothing
+ break;
+ }
+ return ret;
+}
+
+// Initialize the sending thread
+EFrameworkunifiedStatus CanSendThreadStart(HANDLE h_app) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ intptr_t ptr;
+ e_status = FrameworkunifiedAttachCallbacksToDispatcher(h_app,
+ FRAMEWORKUNIFIED_ANY_SOURCE,
+ kCanHalPcbhs,
+ _countof(kCanHalPcbhs));
+ if (e_status != eFrameworkunifiedStatusOK)
+ goto finish;
+
+ e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &ptr, sizeof(ptr));
+ if (e_status != eFrameworkunifiedStatusOK)
+ goto finish;
+
+ *((HANDLE *)ptr) = FrameworkunifiedMcOpenSender(h_app, FrameworkunifiedGetAppName(h_app));
+ if (!(*(HANDLE *)ptr))
+ e_status = eFrameworkunifiedStatusFail;
+
+finish:
+ return e_status;
+}
+
+// Clean the sending thread
+EFrameworkunifiedStatus CanSendThreadStop(HANDLE h_app) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ intptr_t ptr;
+ e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &ptr, sizeof(ptr));
+ if (e_status != eFrameworkunifiedStatusOK)
+ goto finish;
+
+ FrameworkunifiedMcClose(*((HANDLE*)ptr));
+finish:
+ return e_status;
+}
+
+static CANHAL_RET_API CanCloseCoreCAN(void) {
+ CanCtlApiClose(&g_driver_obj);
+ return CANHAL_RET_NORMAL;
+}
+
+// Stop the can hal
+CANHAL_RET_API CanCloseCore(CanHalType type) {
+ CANHAL_RET_API ret = CANHAL_RET_NORMAL;
+ switch (type) {
+ case CAN_HAL_TYPE_CAN:
+ ret = CanCloseCoreCAN();
+ if (ret != CANHAL_RET_NORMAL)
+ goto finish;
+ break;
+ default:
+ goto finish;
+ break;
+ }
+finish:
+ return ret;
+}
+
+// Callback for the sending thread to send the can data
+static EFrameworkunifiedStatus CanSendData(HANDLE h_app) {
+ UINT8 ret = 0;
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ HANDLE hb = NULL;
+ CanMessage mb;
+ ssize_t sz = 0;
+ void *send_msg = NULL;
+ HANDLE unpacked_h_app;
+ CanMessage *unpacked_msg;
+ ssize_t unpacked_sz;
+
+ send_msg = CanHalPackMessage(hb, (const void *)&mb, sizeof(mb), &sz);
+ if (!send_msg)
+ return eFrameworkunifiedStatusFail;
+
+ e_status = FrameworkunifiedGetMsgDataOfSize(h_app, send_msg, sz, eSMRRelease);
+ if (eFrameworkunifiedStatusOK != e_status) {
+ if (eFrameworkunifiedStatusInvldBufSize == e_status) {
+ FrameworkunifiedClearMsgData(h_app);
+ }
+ return eFrameworkunifiedStatusFail;
+ }
+
+ CanHalUnPackMessage(send_msg, &unpacked_h_app,
+ (void **)&unpacked_msg, &unpacked_sz);
+
+ CanCtlApiCmd send_can_data;
+ memset(&send_can_data, 0, sizeof(CanCtlApiCmd));
+ send_can_data.data[CANHAL_VALID_NUM_INDEX] = 1;
+ ret = PackageSendData(unpacked_msg, &(send_can_data.data[1]));
+ send_can_data.len = ret + 1;
+ CanSendResult send_result;
+ send_result.can_id = unpacked_msg->can_id;
+ send_result.rid = unpacked_msg->rid;
+
+ if (CAN_CTL_RET_SUCCESS == CanCtlApiSndCmd(&g_driver_obj, &send_can_data)) {
+ send_result.result = CAN_SEND_RESULT_SUCCESS;
+ } else {
+ send_result.result = CAN_SEND_RESULT_FAILURE;
+ }
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Send status is %d.", send_result.result);
+
+ if (CANHAL_RET_NORMAL != CanHalSendStatus(CAN_HAL_TYPE_CAN,
+ unpacked_h_app, &send_result, sizeof(send_result))) {
+ CanHalDestroyPackedMessage(send_msg);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ CanHalDestroyPackedMessage(send_msg);
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * param [in] send_msg
+ * param [out] send_can_data
+ */
+static UINT8 PackageSendData(const CanMessage *send_msg,
+ UINT8 *send_can_data) {
+ // package according to the rule of the data structure,
+ // refer to the line 108 and 109
+ send_can_data[CANHAL_CANID_HI_INDEX] = (send_msg->can_id & 0x7F0) >> 4;
+ send_can_data[CANHAL_CANID_LO_INDEX] = (send_msg->can_id & 0x0F) << 4;
+ send_can_data[CANHAL_DLC_INDEX] = send_msg->dlc;
+ memcpy(&(send_can_data[CANHAL_DATA_START_INDEX]),
+ send_msg->data,
+ send_msg->dlc);
+ return (send_msg->dlc + CANHAL_DATA_START_INDEX);
+}
+
+/**
+ * param [in] recv_data
+ * param [out] message
+ */
+static UINT8 PackageRecvData(const UINT8 *recv_data, CanMessage *message) {
+ if (CAN_NORMAL_MESSAGE_LEN < recv_data[CANHAL_DLC_INDEX]) {
+ // receive data's length is invalid
+ return CANHAL_RECV_DATA_LENGTH_INVALID;
+ }
+ // package according to the rule of the data structure,
+ // refer to the line 108 and 109
+ message->can_id = recv_data[CANHAL_CANID_HI_INDEX] & 0x7F;
+ message->can_id <<= 4;
+ message->can_id |= (recv_data[CANHAL_CANID_LO_INDEX] & 0xF0) >> 4;
+ message->dlc = recv_data[CANHAL_DLC_INDEX];
+ memcpy(message->data, &(recv_data[CANHAL_DATA_START_INDEX]), CAN_NORMAL_MESSAGE_LEN);
+
+ return CANHAL_RECV_DATABLOCK_SIZE;
+}
+
diff --git a/hal/can_hal/src/can_hal_stm.cpp b/hal/can_hal/src/can_hal_stm.cpp
new file mode 100755
index 0000000..fc24964
--- /dev/null
+++ b/hal/can_hal/src/can_hal_stm.cpp
@@ -0,0 +1,243 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "can_hal_stm.h"
+#include "can_hal_core.h"
+#include "can_hal_internal.h"
+#include <native_service/ns_message_center_if.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <native_service/frameworkunified_multithreading.h>
+#include <string>
+#include <stdbool.h>
+#include <stdint.h>
+#include <assert.h>
+#include <pthread.h>
+
+// BSS section would be initialized to all 0.
+struct CanHalStateMachine {
+ CanHalType type;
+ HANDLE h_app;
+ bool can_hal_is_opened;
+ bool device_is_enabled;
+ struct {
+ HANDLE tx;
+ HANDLE tx_sender;
+ uint32_t tx_cmd;
+ const char *tx_name;
+ bool rx_initialized;
+ pthread_t rx;
+ pthread_attr_t rx_attr;
+ } internal;
+} can_hal_stm[NR_CAN_HAL_TYPES];
+
+bool TypeIsValid(enum CanHalType type) {
+ if (CAN_HAL_TYPE_CAN == type)
+ return true;
+
+ return false;
+}
+
+bool IsCanHalOpened(enum CanHalType type) {
+ return can_hal_stm[type].can_hal_is_opened;
+}
+
+void SetCanHalStateOpen(enum CanHalType type) {
+ can_hal_stm[type].can_hal_is_opened = true;
+}
+
+void SetCanHalStateClose(enum CanHalType type) {
+ can_hal_stm[type].can_hal_is_opened = false;
+}
+
+bool IsDeviceEnabled(enum CanHalType type) {
+ return can_hal_stm[type].device_is_enabled;
+}
+
+void SetDeviceStateEnable(enum CanHalType type) {
+ can_hal_stm[type].device_is_enabled = true;
+}
+
+void SetDeviceStateDisable(enum CanHalType type) {
+ can_hal_stm[type].device_is_enabled = false;
+}
+
+CANHAL_RET_API CanHalDestroyInternalThread(HANDLE h_app, enum CanHalType type) {
+ intptr_t ptr = (intptr_t)&(can_hal_stm[type].internal.tx_sender);
+
+ if (can_hal_stm[type].internal.tx) {
+ FrameworkunifiedStopChildThread(h_app, can_hal_stm[type].internal.tx, sizeof(ptr), &ptr);
+ FrameworkunifiedDestroyChildThread(h_app, can_hal_stm[type].internal.tx);
+ can_hal_stm[type].internal.tx = NULL;
+ }
+
+ if (can_hal_stm[type].internal.rx_initialized) {
+ pthread_cancel(can_hal_stm[type].internal.rx);
+ pthread_join(can_hal_stm[type].internal.rx, NULL);
+ can_hal_stm[type].internal.rx_initialized = false;
+ }
+ can_hal_stm[type].h_app = NULL;
+ return CANHAL_RET_NORMAL;
+}
+
+CANHAL_RET_API CanHalCreateInternalThread(HANDLE h_app, enum CanHalType type) {
+ enum CANHAL_RET_API ret = CANHAL_RET_ERR_PARAM;
+ EFrameworkunifiedStatus err = eFrameworkunifiedStatusOK;
+ intptr_t ptr = (intptr_t)&(can_hal_stm[type].internal.tx_sender);
+
+ can_hal_stm[type].h_app = h_app;
+ can_hal_stm[type].internal.tx_name = CANHAL_CAN_SEND_THREAD;
+ can_hal_stm[type].internal.tx = FrameworkunifiedCreateChildThread(h_app,
+ can_hal_stm[type].internal.tx_name,
+ CanSendThreadStart, CanSendThreadStop);
+ if (!can_hal_stm[type].internal.tx)
+ goto cleanup;
+
+ err = FrameworkunifiedStartChildThread(h_app,
+ can_hal_stm[type].internal.tx,
+ sizeof(ptr), &ptr);
+ if (err != eFrameworkunifiedStatusOK)
+ goto cleanup;
+
+ if (0 != pthread_attr_init(&(can_hal_stm[type].internal.rx_attr)))
+ goto cleanup;
+
+ if (0 != pthread_create(&(can_hal_stm[type].internal.rx),
+ &(can_hal_stm[type].internal.rx_attr), CanRecvRun,
+ (void *)&(can_hal_stm[type].type)))
+ goto cleanup;
+
+ can_hal_stm[type].internal.rx_initialized = true;
+ ret = CANHAL_RET_NORMAL;
+ return ret;
+cleanup:
+ if (can_hal_stm[type].internal.tx) {
+ FrameworkunifiedStopChildThread(h_app, can_hal_stm[type].internal.tx, sizeof(ptr), &ptr);
+ FrameworkunifiedDestroyChildThread(h_app, can_hal_stm[type].internal.tx);
+ can_hal_stm[type].internal.tx = NULL;
+ }
+
+ return ret;
+}
+
+CANHAL_RET_API CanHalInternalSend_CWORD118_(enum CanHalType type,
+ const void *msg, ssize_t sz) {
+ EFrameworkunifiedStatus e_status = FrameworkunifiedSendMsg(can_hal_stm[type].internal.tx_sender,
+ TX_INTERNAL__CWORD118_, sz, msg);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ return CANHAL_RET_ERR_ERR;
+ }
+ return CANHAL_RET_NORMAL;
+}
+
+static EFrameworkunifiedStatus FrameworkunifiedSendMsgOneshot(HANDLE h_app, UI_32 cmd,
+ UI_32 l, PCVOID d) {
+ HANDLE h_client = NULL;
+ EFrameworkunifiedStatus err = eFrameworkunifiedStatusFail;
+
+ h_client = FrameworkunifiedMcOpenSender(h_app, FrameworkunifiedGetAppName(h_app));
+ if (!h_client)
+ return err;
+
+ err = FrameworkunifiedSendMsg(h_client, cmd, l, d);
+ FrameworkunifiedMcClose(h_client);
+ return err;
+}
+
+CANHAL_RET_API CanHalInternalSend(enum CanHalType type,
+ const void *msg, ssize_t sz) {
+ EFrameworkunifiedStatus e_status = FrameworkunifiedSendMsg(can_hal_stm[type].internal.tx_sender,
+ TX_INTERNAL, sz, msg);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ return CANHAL_RET_ERR_ERR;
+ }
+ return CANHAL_RET_NORMAL;
+}
+
+
+CANHAL_RET_API InvokeStateCallback(enum CanHalType type) {
+ HANDLE sender = can_hal_stm[type].h_app;
+ uint32_t cmd = 0;
+ EFrameworkunifiedStatus err = eFrameworkunifiedStatusOK;
+ bool send = true;
+
+ switch (type) {
+ case CAN_HAL_TYPE_CAN:
+ cmd = CID_CANHAL_CMD_CAN_READY;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ err = FrameworkunifiedSendMsgOneshot(sender, cmd, sizeof(send), &send);
+ if (err != eFrameworkunifiedStatusOK)
+ return CANHAL_RET_ERR_ERR;
+ return CANHAL_RET_NORMAL;
+}
+
+CANHAL_RET_API InvokeErrorCallback(HANDLE h_app, enum CanHalType type) {
+ HANDLE sender = h_app;
+ uint32_t cmd = CID_CANHAL_CMD_ERROR_NOTIFY;
+ char msg[CANHAL_ERROR_MESSAGE_LEN] = {0};
+ ssize_t sz = sizeof(msg);
+ EFrameworkunifiedStatus err = eFrameworkunifiedStatusOK;
+
+ switch (type) {
+ case CAN_HAL_TYPE_CAN:
+ sprintf(msg, "Global CAN Stop");
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ err = FrameworkunifiedSendMsgOneshot(sender, cmd, sz, msg);
+ if (err != eFrameworkunifiedStatusOK)
+ return CANHAL_RET_ERR_ERR;
+ return CANHAL_RET_NORMAL;
+}
+
+CANHAL_RET_API CanHalSendStatus(enum CanHalType type, HANDLE h_app,
+ const void *msg, ssize_t sz) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ e_status = FrameworkunifiedSendMsgOneshot(h_app, CID_CANHAL_CMD_CAN_SEND_STATUS, sz, msg);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ return CANHAL_RET_ERR_ERR;
+ }
+ return CANHAL_RET_NORMAL;
+}
+
+CANHAL_RET_API CanHalReceiveNotify(enum CanHalType type,
+ const void *msg, ssize_t sz) {
+ EFrameworkunifiedStatus e_status;
+ uint32_t cmd = 0;
+
+ switch (type) {
+ case CAN_HAL_TYPE_CAN:
+ cmd = CID_CANHAL_CMD_CAN_RECV;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ e_status = FrameworkunifiedSendMsgOneshot(can_hal_stm[type].h_app, cmd, sz, msg);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ return CANHAL_RET_ERR_ERR;
+ }
+
+ return CANHAL_RET_NORMAL;
+}
diff --git a/hal/can_hal/src/driver_can__CWORD31_.c b/hal/can_hal/src/driver_can__CWORD31_.c
new file mode 100755
index 0000000..bd9cb29
--- /dev/null
+++ b/hal/can_hal/src/driver_can__CWORD31_.c
@@ -0,0 +1,472 @@
+/*
+ * @copyright Copyright (c) 2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include "can_mng_api.h"
+
+#include <poll.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <linux/can/raw.h>
+#include <net/if.h>
+
+
+#define DUMP_DIR "/nv/driver-can"
+#define DUMP_RCVID "/nv/driver-can/dump_rcvid"
+#define CAN_DATA_SIZE (sizeof(CanData))
+
+static int fd_can = -1;
+static struct sockaddr_can tx_address;
+static CanCtlRcvId RcvId;
+const char* device_name = "vcan0";
+
+static UINT32 getData(CanCtlRcvId*, CanCtlApiCmd*);
+static UINT32 getCanData(unsigned char*);
+static UINT32 copyEnableCandata(UINT16* , unsigned char*, unsigned char*);
+static UINT32 isOpendDriver(void);
+
+UINT32 CanCtlApiOpen(CanCtlApiObj* pClientObj)
+{
+ int err_no;
+ int ret;
+
+ CAN_MNG_API_LOGT("FUNC IN");
+
+ /*----------------------------------------------------------------------*/
+ /* Clear Object */
+ /*----------------------------------------------------------------------*/
+ if (pClientObj != NULL) {
+ memset(pClientObj, 0, sizeof(*pClientObj));
+ }
+
+ if (fd_can != -1) {
+ CAN_MNG_API_LOGT("Already Opened");
+ CAN_MNG_API_LOGT("FUNC OUT");
+ return CAN_CTL_RET_SUCCESS;
+ }
+
+ // open socket
+ CAN_MNG_API_LOGT("open socket start");
+ struct ifreq ifr = {0};
+ fd_can = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+ err_no = errno;
+ CAN_MNG_API_LOGT("open socket end");
+ if (fd_can == -1) {
+ CAN_MNG_API_LOGE("Socket Open Error.");
+ CAN_MNG_API_LOGE("(errno[%d]).", err_no);
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ // ioctl(SIOCGIFINDEX)
+ strcpy(ifr.ifr_name, device_name);
+ ret = ioctl(fd_can, SIOCGIFINDEX, &ifr);
+ err_no = errno;
+ if (ret < 0) {
+ CAN_MNG_API_LOGE("ioctl(SIOCGIFINDEX) Error.");
+ CAN_MNG_API_LOGE("(errno[%d]).", err_no);
+ (void)close(fd_can);
+ fd_can = -1;
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ // bind
+ tx_address.can_family = AF_CAN;
+ tx_address.can_ifindex = ifr.ifr_ifindex;
+
+ ret = bind(fd_can, (struct sockaddr *)&tx_address, sizeof(tx_address));
+ err_no = errno;
+ if (ret < 0) {
+ CAN_MNG_API_LOGE("Socket Bind Error.");
+ CAN_MNG_API_LOGE("(errno[%d]).", err_no);
+ (void)close(fd_can);
+ fd_can = -1;
+ return -1;
+ }
+
+ // Initialize RcvId Map
+ memset(&RcvId, 0, sizeof(RcvId));
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+
+ return CAN_CTL_RET_SUCCESS;
+}
+
+UINT32 CanCtlApiClose(CanCtlApiObj* pClientObj)
+{
+ /*----------------------------------------------------------------------*/
+ /* Clear Object */
+ /*----------------------------------------------------------------------*/
+ if (pClientObj != NULL) {
+ memset(pClientObj, 0, sizeof(*pClientObj));
+ }
+
+ if (fd_can != -1) {
+ (void)close(fd_can);
+ }
+
+ // Initialize fd info
+ fd_can = -1;
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+
+ return CAN_CTL_RET_SUCCESS;
+}
+
+UINT32 CanCtlApiSndCmd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pSndCmd)
+{
+ int i;
+ printf("%s: call_id=0x%x len=%d\n",
+ __func__, pClientObj->call_id, pSndCmd->len);
+ for (i = 0; i < pSndCmd->len; i++) {
+ printf("[%d]0x%x ", i, pSndCmd->data[i]);
+ if ((i != 0) && ((i % 7) == 0))
+ printf("\n");
+ }
+ printf("\n");
+
+
+ int ret;
+ int err_no;
+
+ CAN_MNG_API_LOGT("FUNC IN");
+ /*----------------------------------------------------------------------*/
+ /* Check Input Value */
+ /*----------------------------------------------------------------------*/
+ if (NULL == pSndCmd)
+ {
+ CAN_MNG_API_LOGE("%s(%p) invalid parameter.", __func__, pSndCmd);
+ return CAN_CTL_RET_ERR_PARAM;
+ }
+
+ ret = isOpendDriver();
+ if (ret != CAN_CTL_RET_SUCCESS) {
+ CAN_MNG_API_LOGE("Not Open Driver.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ struct can_frame frame = {0};
+
+ frame.can_id = pSndCmd->data[1] & 0x7F;
+ frame.can_id <<= 4;
+ frame.can_id |= (pSndCmd->data[2] & 0xF0) >> 4;
+ frame.can_dlc = pSndCmd->data[3];
+ frame.data[0] = pSndCmd->data[4];
+ frame.data[1] = pSndCmd->data[5];
+ frame.data[2] = pSndCmd->data[6];
+ frame.data[3] = pSndCmd->data[7];
+ frame.data[4] = pSndCmd->data[8];
+ frame.data[5] = pSndCmd->data[9];
+ frame.data[6] = pSndCmd->data[10];
+ frame.data[7] = pSndCmd->data[11];
+
+ CAN_MNG_API_LOGT("write() CanDataExtSendNotif start size = %d", (int)sizeof(frame));
+ ret = write(fd_can, &frame, sizeof(frame));
+ err_no = errno;
+ CAN_MNG_API_LOGE("write() ret = %d).", ret);
+
+ CAN_MNG_API_LOGT("write() CanDataExtSendNotif end");
+ if (ret == -1) {
+ CAN_MNG_API_LOGE("write() error(errno[%d]).", err_no);
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+
+ return CAN_CTL_RET_SUCCESS;
+}
+
+UINT32 CanCtlApiSetRcvId(CanCtlApiObj* pClientObj, CanCtlRcvId* pRcvId)
+{
+ FILE* fp;
+ size_t nmemb;
+
+ CAN_MNG_API_LOGT("FUNC IN");
+ /*----------------------------------------------------------------------*/
+ /* Check Input Value */
+ /*----------------------------------------------------------------------*/
+ if (NULL == pRcvId)
+ {
+ CAN_MNG_API_LOGE("%s(%p) invalid parameter.", __func__, pRcvId);
+ return CAN_CTL_RET_ERR_PARAM;
+ }
+
+ struct stat st;
+ int ret = 0;
+ if (stat(DUMP_DIR, &st) != 0) {
+ ret = mkdir(DUMP_DIR, 0755);
+ }
+ if (ret != 0) {
+ CAN_MNG_API_LOGE("Can not Created RcvId Dump dir.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+ CAN_MNG_API_LOGT("fopen(DUMP_RCVID) start");
+ fp = fopen(DUMP_RCVID, "wb");
+ CAN_MNG_API_LOGT("fopen(DUMP_RCVID) end");
+ if (fp == NULL) {
+ CAN_MNG_API_LOGE("Can not Opened RcvId Dump file.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("fwrite(pRcvId) start");
+ nmemb = fwrite(pRcvId, sizeof(CanCtlRcvId), 1, fp);
+ CAN_MNG_API_LOGT("fwrite(pRcvId) end");
+ if (nmemb != 1) {
+ CAN_MNG_API_LOGE("RcvId Dump file write error.");
+ (void)fclose(fp);
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("fclose() start");
+ (void)fclose(fp);
+ CAN_MNG_API_LOGT("fclose() end");
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+
+ return CAN_CTL_RET_SUCCESS;
+}
+
+UINT32 CanCtlApiRcvCmd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pRcvCmd)
+{
+ int ret;
+ int enable_ret;
+
+ CanCtlRcvId InitialRcvId;
+ CanCtlRcvId RcvId;
+ FILE* fp;
+ size_t nmemb;
+
+ CAN_MNG_API_LOGT("FUNC IN");
+ /*----------------------------------------------------------------------*/
+ /* Check Input Value */
+ /*----------------------------------------------------------------------*/
+ if (NULL == pRcvCmd)
+ {
+ CAN_MNG_API_LOGE("%s(%p) invalid parameter.", __func__, pRcvCmd);
+ return CAN_CTL_RET_ERR_PARAM;
+ }
+
+ ret = isOpendDriver();
+ if (ret != CAN_CTL_RET_SUCCESS) {
+ CAN_MNG_API_LOGE("Not Open Driver.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ // Restore RcvId
+ CAN_MNG_API_LOGT("fopen(DUMP_RCVID) start");
+ fp = fopen(DUMP_RCVID, "rb");
+ CAN_MNG_API_LOGT("fopen(DUMP_RCVID) end");
+ if (fp == NULL) {
+ CAN_MNG_API_LOGE("Can not Opened RcvId Dump file.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("fread(RcvId) start");
+ nmemb = fread(&RcvId, sizeof(CanCtlRcvId), 1, fp);
+ CAN_MNG_API_LOGT("fread(RcvId) end");
+ if (nmemb != 1) {
+ CAN_MNG_API_LOGE("RcvId Dump file read error.");
+ (void)fclose(fp);
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("fclose() start");
+ (void)fclose(fp);
+ CAN_MNG_API_LOGT("fclose() end");
+
+ memset(&InitialRcvId.id, 0, sizeof(InitialRcvId.id));
+
+ if (memcmp(InitialRcvId.id, RcvId.id, sizeof(RcvId.id)) == 0) {
+ CAN_MNG_API_LOGE("No RecvId Maps.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ enable_ret = getData(&RcvId, pRcvCmd);
+
+ if (enable_ret != CAN_CTL_RET_SUCCESS) {
+ CAN_MNG_API_LOGE("No data founds.");
+ return enable_ret;
+ }
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+
+ return CAN_CTL_RET_SUCCESS;
+}
+
+static UINT32 getData(CanCtlRcvId* pRcvId, CanCtlApiCmd* pRcvCmd) {
+ int ret;
+ int total_cnt = 0;
+ int copy_cnt = 0;
+ int i;
+ unsigned char can_data[CAN_CTL_CMD_LEN_MAX+1];
+ unsigned char enable_can_data[CAN_CTL_CMD_LEN_MAX];
+ unsigned char store_can_data[CAN_CTL_CMD_LEN_MAX];
+ unsigned char* scd;
+
+
+ UINT16 id_map[CAN_CTL_CMD_ID_HI_NUM];
+
+ CAN_MNG_API_LOGT("FUNC IN");
+
+ memcpy(id_map, pRcvId->id, sizeof(id_map));
+
+ memset(store_can_data, 0, sizeof(store_can_data));
+ scd = store_can_data;
+
+ while(1) {
+ memset(can_data, 0, sizeof(can_data));
+ memset(enable_can_data, 0, sizeof(enable_can_data));
+ ret = getCanData(can_data);
+ if (ret != CAN_CTL_RET_SUCCESS) {
+ // In case of error, read next data
+ CAN_MNG_API_LOGE("getCanData error.");
+ continue;
+ }
+
+ // Extract data of "CAN data extended reception notification 4"
+ copy_cnt = copyEnableCandata(id_map, can_data, enable_can_data);
+ if( copy_cnt == 0 ){
+ continue;
+ }
+
+ // Store in work buffer
+ for (i = 0; i < copy_cnt; i++) {
+ if (total_cnt >= CAN_CTL_MAX_RCV_CAN_SIZE) {
+ CAN_MNG_API_LOGE("buffer over");
+ break;
+ }
+ memcpy(scd, &enable_can_data[CAN_DATA_SIZE * i], CAN_DATA_SIZE);
+ scd = scd + CAN_DATA_SIZE;
+ total_cnt++;
+ }
+
+ // Check work buffer overflow
+ if (total_cnt >= CAN_CTL_MAX_RCV_CAN_SIZE) {
+ CAN_MNG_API_LOGE("buffer over");
+ break;
+ }
+ }
+
+ // If data exists, set and return
+ if (total_cnt != 0) {
+ pRcvCmd->len = 1 + (total_cnt * CAN_DATA_SIZE);
+ pRcvCmd->data[0] = total_cnt;
+ memcpy( &(pRcvCmd->data[1]), store_can_data, (total_cnt * CAN_DATA_SIZE));
+ } else {
+ // If there is no data, return with length 0
+ pRcvCmd->len = 0;
+ memset( &(pRcvCmd->data[0]), 0, sizeof(UINT8) * CAN_DAT_LEN_MAX );
+ CAN_MNG_API_LOGE("data not found");
+ }
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+
+ return CAN_CTL_RET_SUCCESS;
+}
+
+static UINT32 getCanData(unsigned char *can_data) {
+ int err_no;
+ int i;
+
+ CAN_MNG_API_LOGT("FUNC IN");
+
+ CAN_MNG_API_LOGE("recvfrom start");
+
+ int nbytes = 0;
+ struct can_frame frame = {0};
+ socklen_t addrlen = sizeof(struct sockaddr_can);
+ nbytes = recvfrom(fd_can, &frame, sizeof(frame), 0, (struct sockaddr*)&tx_address, &addrlen);
+ err_no = errno;
+ CAN_MNG_API_LOGE("recvfrom end ret = %d",nbytes);
+ if (nbytes == -1) {
+ CAN_MNG_API_LOGE("Not Read CAN Driver(errno[%d]).", err_no);
+ return CAN_CTL_RET_ERR_ERR;
+ } else if (nbytes != CAN_MTU) {
+ CAN_MNG_API_LOGE("Receive Error size: %d.", nbytes);
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("Recvfrom CAN Data(start)");
+ can_data[0] = (frame.can_id & 0x7F0) >> 4;
+ can_data[1] = (frame.can_id & 0x0F) << 4;
+ can_data[2] = frame.can_dlc;
+ for (i = 0; i < frame.can_dlc; i++) {
+ can_data[3+i] = frame.data[i];
+ CAN_MNG_API_LOGE(" 0x%02x", frame.data[i]);
+ }
+ CAN_MNG_API_LOGT("");
+ CAN_MNG_API_LOGT("Recvfrom Data(end)");
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+ return CAN_CTL_RET_SUCCESS;
+}
+
+static UINT32 copyEnableCandata(UINT16* id_map, unsigned char* can_data, unsigned char* enable_can_data) {
+ int id;
+ UINT16 val;
+ unsigned char* ecd = enable_can_data;
+ UINT32 count = 0;
+
+ CAN_MNG_API_LOGT("FUNC IN");
+ // Search data of "CAN data extended reception notification 4"
+ id = can_data[0];
+ val = can_data[1] >> 4; // Shift right 4 bits and determine search position
+
+ CAN_MNG_API_LOGE("data id =%x", id);
+ CAN_MNG_API_LOGE("data val=%x", val);
+ CAN_MNG_API_LOGE("file val=%x", id_map[id]);
+
+ // If the target data is found (If the bit is on ?)
+ if ((id_map[id] & (0x01 << val)) != 0) {
+ CAN_MNG_API_LOGT("matched.");
+ CAN_MNG_API_LOGE("id_map[%u]", id_map[id]);
+
+ // Store data in work buffer
+ memcpy(ecd, &can_data[0], CAN_DATA_SIZE);
+ count++;
+ }
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+ return count;
+}
+
+UINT32 CanCtlApiRcvSpd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pRcvCmd)
+{
+ // Note.
+ // If vendor needs the special implementation about receiving the vehicle speed,
+ // it should be implemented by vendor.
+ return CAN_CTL_RET_SUCCESS;
+}
+
+static UINT32 isOpendDriver() {
+ CAN_MNG_API_LOGT("FUNC IN");
+
+ if (fd_can == -1) {
+ CAN_MNG_API_LOGE("Not Open CAN Driver.");
+ return CAN_CTL_RET_ERR_ERR;
+ }
+
+ CAN_MNG_API_LOGT("FUNC OUT");
+ return CAN_CTL_RET_SUCCESS;
+}
diff --git a/hal/can_hal/src/inc/can_hal_core.h b/hal/can_hal/src/inc/can_hal_core.h
new file mode 100755
index 0000000..57a9c9d
--- /dev/null
+++ b/hal/can_hal/src/inc/can_hal_core.h
@@ -0,0 +1,37 @@
+/*
+ * @copyright Copyright (c) 2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CAN_HAL_CORE_H_
+#define _CAN_HAL_CORE_H_
+#include <stdint.h>
+#include "can_hal.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+CANHAL_RET_API CanOpenCore(CanHalType type);
+CANHAL_RET_API CanCloseCore(CanHalType type);
+EFrameworkunifiedStatus CanSendThreadStart(HANDLE h_app);
+EFrameworkunifiedStatus CanSendThreadStop(HANDLE h_app);
+void *CanRecvRun(void *arg);
+void *CanHalPackMessage(HANDLE h_app, const void *msg, ssize_t msg_sz,
+ ssize_t *packed_sz);
+void CanHalUnPackMessage(void *packed, HANDLE *h_app, void **msg,
+ ssize_t *msg_sz);
+void CanHalDestroyPackedMessage(void *packed);
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/hal/can_hal/src/inc/can_hal_frameworkunifiedlog.h b/hal/can_hal/src/inc/can_hal_frameworkunifiedlog.h
new file mode 100755
index 0000000..f3a5f50
--- /dev/null
+++ b/hal/can_hal/src/inc/can_hal_frameworkunifiedlog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_CAN_HAL_FRAMEWORKUNIFIEDLOG_H_
+#define INC_CAN_HAL_FRAMEWORKUNIFIEDLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+#endif // INC_CAN_HAL_FRAMEWORKUNIFIEDLOG_H_
diff --git a/hal/can_hal/src/inc/can_hal_internal.h b/hal/can_hal/src/inc/can_hal_internal.h
new file mode 100755
index 0000000..f42a73f
--- /dev/null
+++ b/hal/can_hal/src/inc/can_hal_internal.h
@@ -0,0 +1,31 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_CAN_HAL_INTERNAL_H_
+#define INC_CAN_HAL_INTERNAL_H_
+
+/**
+ * \~english Name of the CAN send thread
+ */
+#define CANHAL_CAN_SEND_THREAD "HalCANSend"
+
+enum CanHalInternalCmd {
+ INVALID_CMD = 0,
+ TX_INTERNAL,
+ TX_INTERNAL__CWORD118_
+};
+
+#endif // INC_CAN_HAL_INTERNAL_H_
diff --git a/hal/can_hal/src/inc/can_hal_stm.h b/hal/can_hal/src/inc/can_hal_stm.h
new file mode 100755
index 0000000..cd07814
--- /dev/null
+++ b/hal/can_hal/src/inc/can_hal_stm.h
@@ -0,0 +1,45 @@
+/*
+ * @copyright Copyright (c) 2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CAN_HAL_STM_H_
+#define _CAN_HAL_STM_H_
+#include "can_hal.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+bool TypeIsValid(enum CanHalType type);
+bool IsCanHalOpened(enum CanHalType type);
+void SetCanHalStateOpen(enum CanHalType type);
+void SetCanHalStateClose(enum CanHalType type);
+bool IsDeviceEnabled(enum CanHalType type);
+void SetDeviceStateEnable(enum CanHalType type);
+void SetDeviceStateDisable(enum CanHalType type);
+CANHAL_RET_API InvokeStateCallback(enum CanHalType type);
+CANHAL_RET_API InvokeErrorCallback(HANDLE h_app, enum CanHalType type);
+CANHAL_RET_API CanHalInternalSend(enum CanHalType type,
+ const void *msg, ssize_t sz);
+CANHAL_RET_API CanHalInternalSend_CWORD118_(enum CanHalType type,
+ const void *msg, ssize_t sz);
+CANHAL_RET_API CanHalSendStatus(enum CanHalType type, HANDLE h_app,
+ const void *msg, ssize_t sz);
+CANHAL_RET_API CanHalReceiveNotify(enum CanHalType type,
+ const void *msg, ssize_t sz);
+CANHAL_RET_API CanHalCreateInternalThread(HANDLE h_app, enum CanHalType type);
+CANHAL_RET_API CanHalDestroyInternalThread(HANDLE h_app, enum CanHalType type);
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/hal/can_hal/src/inc/can_mng_api.h b/hal/can_hal/src/inc/can_mng_api.h
new file mode 100755
index 0000000..ef03750
--- /dev/null
+++ b/hal/can_hal/src/inc/can_mng_api.h
@@ -0,0 +1,120 @@
+/*
+ * @copyright Copyright (c) 2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CAN_MNG_API_H__
+#define __CAN_MNG_API_H__
+
+/** @includes
+ *
+ */
+
+/** @define
+ *
+ */
+#ifndef UINT8
+#define UINT8 unsigned char
+#endif
+#ifndef UINT16
+#define UINT16 unsigned short
+#endif
+#ifndef INT32
+#define INT32 int
+#endif
+#ifndef UINT32
+#define UINT32 unsigned int
+#endif
+
+/*------------------------------------------*/
+/* Log */
+/*------------------------------------------*/
+#if defined(CAN_MNG_API_FORCE_DEBUG)
+ #define CAN_MNG_API_LOGT(fmt,...) fprintf(stderr, "[T][CAN_API] %s(%s)(%d):" fmt "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__)
+ #define CAN_MNG_API_LOGD(fmt,...) fprintf(stderr, "[D][CAN_API] %s(%s)(%d):" fmt "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__)
+ #define CAN_MNG_API_LOGE(fmt,...) fprintf(stderr, "[E][CAN_API] %s(%s)(%d):" fmt "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__)
+#else
+ #define CAN_MNG_API_LOGT(fmt,...)
+ #define CAN_MNG_API_LOGD(fmt,...)
+ #define CAN_MNG_API_LOGE(fmt,...)
+#endif
+/*------------------------------------------*/
+/* API return value */
+/*------------------------------------------*/
+#define CAN_CTL_RET_SUCCESS 0 /* Normal end */
+#define CAN_CTL_RET_ERR_PARAM -1 /* Parameter error */
+#define CAN_CTL_RET_ERR_NOSVC -2 /* Service not open error */
+#define CAN_CTL_RET_ERR_ERR -3 /* Other error */
+
+/*------------------------------------------*/
+/* Received command information */
+/*------------------------------------------*/
+#define CAN_CTL_CMD_LEN_MAX 255 /* Maximum data length */
+#define CAN_DAT_LEN_MAX CAN_CTL_CMD_LEN_MAX /* Maximum data length */
+#define CAN_CTL_CMD_ID_HI_NUM 128 /* Number of higher CAN-ID(8bit) (00 to 7F) */
+
+#define CAN_CTL_MAX_RCV_CAN_SIZE 23
+
+/** @typedefs
+ *
+ */
+/* Object for CAN communication control API */
+typedef struct _CanCtlApiObj {
+ /* ID assigned to the command reception notification callback */
+ INT32 call_id;
+} CanCtlApiObj ;
+
+/* CAN command structure */
+typedef struct _CanCtlApiCmd {
+ UINT8 len; /* Data length */
+ UINT8 data[CAN_DAT_LEN_MAX]; /* Data */
+} CanCtlApiCmd;
+
+/* Received ID MAP information */
+typedef struct _CanCtlRcvId {
+ UINT16 id[CAN_CTL_CMD_ID_HI_NUM]; /* CAN ID MAP(000~7FF) */
+} CanCtlRcvId;
+
+
+/* CAN Frame structure */
+typedef union {
+ UINT8 Data[2];
+} CanId;
+
+#define LCN_SRV_MSB_FRAME_DAT_SIZE (8) /* MSB send/receive frame data size */
+
+typedef struct _CanData {
+ CanId id; /* CAN Frame structure */
+ UINT8 dlc; /* Valid bytes of DATA#1~#8. DLC is 1 to 8. */
+ UINT8 Data[LCN_SRV_MSB_FRAME_DAT_SIZE]; /* Receive data */
+ /* Data of DLC size is valid, otherwise set to 0 as invalid value. */
+} CanData;
+
+/** @forward declarations
+ *
+ */
+/* API prototype */
+#ifdef __cplusplus
+extern "C" {
+#endif
+UINT32 CanCtlApiOpen(CanCtlApiObj* pClientObj);
+UINT32 CanCtlApiClose(CanCtlApiObj* pClientObj);
+UINT32 CanCtlApiSndCmd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pSndCmd);
+UINT32 CanCtlApiSetRcvId(CanCtlApiObj* pClientObj, CanCtlRcvId* pRcvId);
+UINT32 CanCtlApiRcvCmd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pRcvCmd);
+UINT32 CanCtlApiRcvSpd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pRcvCmd);
+#ifdef __cplusplus
+}
+#endif
+#endif /* __CAN_MNG_API_H__ */
diff --git a/hal/clock_hal/LICENSE b/hal/clock_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/clock_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/clock_hal/Makefile b/hal/clock_hal/Makefile
new file mode 100755
index 0000000..e417a15
--- /dev/null
+++ b/hal/clock_hal/Makefile
@@ -0,0 +1,67 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libclock_hal.so
+
+HEADER := hal_api/clock_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+CXXFLAGS += -DAGL_REFHW
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH :=
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+######### source files ##########################
+VPATH := src
+OBJS := clock_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/clock_hal/README.md b/hal/clock_hal/README.md
new file mode 100755
index 0000000..0443f95
--- /dev/null
+++ b/hal/clock_hal/README.md
@@ -0,0 +1,3 @@
+clock_hal library
+==================
+Clock HAL implementation library for AGL Reference Board.
diff --git a/hal/clock_hal/hal_api/clock_hal.h b/hal/clock_hal/hal_api/clock_hal.h
new file mode 100755
index 0000000..8006b32
--- /dev/null
+++ b/hal/clock_hal/hal_api/clock_hal.h
@@ -0,0 +1,67 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef HAL_API_CLOCK_HAL_H_
+#define HAL_API_CLOCK_HAL_H_
+/**
+ * @file clock_hal.h
+ */
+#include <time.h>
+
+#include <native_service/frameworkunified_types.h>
+/** @addtogroup clock
+ * @{
+ */
+/** @addtogroup clock_hal
+ * @ingroup clock
+ * @{
+ */
+/**
+ * \ingroup SetHardwareClock
+ * \~english @par Brief
+ * API to set the RTC.
+ * \~english @param [in] h_app
+ * HANDLE - Handle for Application
+ * \~english @param [in] l_tm
+ * const struct tm * - pointer to the time will be set
+ * \~english @retval eFrameworkunifiedStatusOK : Ok
+ * \~english @retval eFrameworkunifiedStatusFail : Failed
+ * \~english @retval eFrameworkunifiedStatusInvldHandle : parameter "h_app" is NULL
+ * \~english @retval eFrameworkunifiedStatusNullPointer : parameter "l_tm" is NULL
+ * \~english @par Prerequisite
+ * - /dev/rtc node is exist, rtc driver is availability.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Set time to RTC failed. [eFrameworkunifiedStatusFail]
+ * - The parameter "l_tm" is NULL. [eFrameworkunifiedStatusNullPointer]
+ * - The parameter "h_app" is NULL. [eFrameworkunifiedStatusInvldHandle]
+ * \~english @par Detail
+ * - Set time to RTC.
+ * - The API can be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+EFrameworkunifiedStatus SetHardwareClock(HANDLE h_app, const struct tm *l_tm);
+
+
+/**@}*/ // end of clock_hal
+/**@}*/ // end of clock
+
+#endif // HAL_API_CLOCK_HAL_H_
diff --git a/hal/clock_hal/inc/clock_hal_clockhallog.h b/hal/clock_hal/inc/clock_hal_clockhallog.h
new file mode 100755
index 0000000..6ed5de5
--- /dev/null
+++ b/hal/clock_hal/inc/clock_hal_clockhallog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_CLOCK_HAL_CLOCKHALLOG_H_
+#define INC_CLOCK_HAL_CLOCKHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_CLOCK_HAL_CLOCKHALLOG_H_
diff --git a/hal/clock_hal/src/clock_hal.cpp b/hal/clock_hal/src/clock_hal.cpp
new file mode 100755
index 0000000..cccbd5b
--- /dev/null
+++ b/hal/clock_hal/src/clock_hal.cpp
@@ -0,0 +1,91 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "clock_hal.h"
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/rtc.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "clock_hal_clockhallog.h"
+
+#define RTC_NODE_PATH_DEPTH 64
+#define RTC_NODE_PERANT_PATH "/dev"
+
+// set time to hardware
+EFrameworkunifiedStatus SetHardwareClock(HANDLE h_app, const struct tm *l_tm) {
+ if (NULL == h_app) {
+ return eFrameworkunifiedStatusInvldHandle;
+ }
+ if (NULL == l_tm) {
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ struct rtc_time hal_rtc_time;
+ hal_rtc_time.tm_year = l_tm->tm_year;
+ hal_rtc_time.tm_mon = l_tm->tm_mon;
+ hal_rtc_time.tm_mday = l_tm->tm_mday;
+ hal_rtc_time.tm_hour = l_tm->tm_hour;
+ hal_rtc_time.tm_min = l_tm->tm_min;
+ hal_rtc_time.tm_sec = l_tm->tm_sec;
+ hal_rtc_time.tm_wday = l_tm->tm_wday;
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
+ "setting time : %d-%02d/%02d %02d:%02d:%02d\n",
+ 1900 + l_tm->tm_year, l_tm->tm_mon + 1, l_tm->tm_mday,
+ l_tm->tm_hour, l_tm->tm_min, l_tm->tm_sec);
+
+ // Search RTC node
+ DIR *dir = ::opendir(RTC_NODE_PERANT_PATH);
+ char rtc_path[RTC_NODE_PATH_DEPTH] = { '\0' };
+ for (struct dirent *dp = readdir(dir); dp != NULL; dp = readdir(dir)) {
+ if (strstr(dp->d_name, "rtc") != NULL) {
+ snprintf(rtc_path, sizeof(rtc_path), "/dev/%s", dp->d_name);
+ break;
+ }
+ }
+ closedir(dir);
+ if (strlen(rtc_path) == 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "/dev/rtcX not found.\n");
+ e_status = eFrameworkunifiedStatusFail;
+ return e_status;
+ }
+
+ // Set time to /dev/rtcX
+ int fd = ::open(rtc_path, O_WRONLY);
+ if (-1 == fd) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Error open(/dev/rtc)=[%d] errno=%d\n",
+ fd, errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ int ret = ::ioctl(fd, RTC_SET_TIME, &hal_rtc_time);
+ if (0 != ret) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
+ "Error ioctl(fd, RTC_SET_TIME, hal_rtc_time)=[%d] errno=%d\n",
+ ret, errno);
+ e_status = eFrameworkunifiedStatusFail;
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
+ "Success ioctl(fd, RTC_SET_TIME, hal_rtc_time)=[%d]\n", ret);
+ }
+ ::close(fd);
+ return e_status;
+}
diff --git a/hal/deck_hal/LICENSE b/hal/deck_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/deck_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/deck_hal/Makefile b/hal/deck_hal/Makefile
new file mode 100755
index 0000000..fbe4ddf
--- /dev/null
+++ b/hal/deck_hal/Makefile
@@ -0,0 +1,67 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libdeck_hal.so
+
+HEADER := hal_api/deck_hal.h
+
+######### include paths/files ###################
+CXXFLAGS += -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH := /usr/lib
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+
+######### source files ##########################
+VPATH += src
+OBJS := deck_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=:$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/deck_hal/hal_api/deck_hal.h b/hal/deck_hal/hal_api/deck_hal.h
new file mode 100755
index 0000000..74aa19a
--- /dev/null
+++ b/hal/deck_hal/hal_api/deck_hal.h
@@ -0,0 +1,322 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*!-----------------------------------------------------------------------------
+ * @file deck_hal.h
+ * @~english
+ * @brief deck_hal API head
+ *
+ */
+
+#ifndef HAL_API_DECK_HAL_H_
+#define HAL_API_DECK_HAL_H_
+
+#include <native_service/frameworkunified_types.h>
+
+/**
+ * @file deck_hal.h
+ */
+
+/** @addtogroup interface_unified
+ * @{
+ */
+/** @addtogroup deck_hal
+ * @ingroup interface_unified
+ * @{
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /*__cplusplus*/
+
+/*! @~english Maximum length of command data division */
+#define DECK_CMD_SIZE_CMDDATA_MAX 252
+/*! @~english Maximum length of notification destination */
+#define NOTIFY_NAME_MAX_SIZE 15
+
+// CID_DECK_SYS_DELIVERY is for deck_hal to report correspinding message to vehicle,
+// the value 0x40 can be changed in the future
+/**
+ * \~english @brief DECK SYS Command-Delivery Notification
+ * \~english @brief If you want to receive this DECK SYS command-delivery notification, use the NSFW IF as follows:
+ * \~english @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, DECKHAL_THREAD, CID_DECK_SYS_DELIVERY, LineSensDrvRcvDeckHal);
+ * @endcode
+ */
+#define CID_DECK_SYS_DELIVERY 0x40
+
+/*!
+ * @~english
+ * @brief Disc eject mode
+*/
+typedef enum {
+ /*! @~english normal eject */
+ DECK_EJECT_NORMAL,
+ /*! @~english forced eject */
+ DECK_EJECT_FORCED
+} DeckEjectMode;
+
+/*!
+ * @~english
+ * @brief Disc mode
+*/
+typedef enum {
+ /*! @~english CD */
+ DECK_KIND_CD,
+ /*! @~english DVD */
+ DECK_KIND_DVD,
+ /*! @~english Blue-lay disc */
+ DECK_KIND_BD
+} DeckKind;
+
+/*------------------------------------------------------------------------------
+ * typedefs
+ *----------------------------------------------------------------------------*/
+/**
+ * \~english Deck-Sys command header structure
+ */
+typedef struct {
+ /*! @~english Source logical address */
+ uint8_t lgadr_from;
+ /*! @~english Forwarding destination logical address */
+ uint8_t lgadr_to;
+ /*! @~english OP code */
+ uint8_t opc;
+ /*! @~english Reserve */
+ uint8_t reserve;
+} DeckCmdhdr;
+
+/**
+ * \~english Deck-Sys command body structure
+ */
+typedef struct DeckCmd {
+ /*! @~english Deck-Sys command header */
+ DeckCmdhdr cmdhdr;
+ /*! @~english Data length */
+ uint16_t data_length;
+ /*! @~english Reserve */
+ uint16_t reserve;
+ /*! @~english Command data */
+ uint8_t data[DECK_CMD_SIZE_CMDDATA_MAX];
+} DeckCmd;
+
+/*!
+ * @~english
+ * @brief Structure for message header
+ */
+typedef struct {
+ uint16_t replyid; //!< \~english Send Result ID
+ uint16_t sndpno; //!< \~english Send process No
+ uint16_t respno; //!< \~english Response No
+ uint16_t cid; //!< \~english Command ID
+ uint16_t msgbodysize; //!< \~english Message body size
+ uint8_t rid; //!< \~english Resource ID
+ uint8_t reserve; //!< \~english Reserve
+ uint8_t filler[2]; //!< \~english filler
+} DECK_HEADER_COMM;
+
+/*!
+ * @~english
+ * @brief Structure for buffer message header
+ */
+typedef struct {
+ uint32_t signo; //!< \~english Signal No
+ DECK_HEADER_COMM hdr; //!< \~english Message Header
+} DECK_MSGBUF_HEADER_COMM;
+
+/**
+ * \~english Delivery message structure
+ */
+typedef struct {
+ /*! @~english Header part */
+ DECK_MSGBUF_HEADER_COMM hdr;
+ /*! @~english Physical address */
+ uint16_t phyadr_from;
+ /*! @~english Communication type */
+ uint8_t service_type;
+ /*! @~english Reserve */
+ uint8_t reserve;
+ /*! @~english Data section */
+ DeckCmd cmd;
+} DECK_MSG_DELIVERY;
+
+/*!
+ * @~english
+ * @brief Structure for send command data
+ */
+typedef struct {
+ /*! @~english Physical address */
+ uint16_t phyadr_from;
+ /*! @~english Communication type */
+ uint8_t service_type;
+ /*! @~english Forwarding former logic address */
+ uint8_t lgadr_from;
+ /*! @~english Forwarding site logic address */
+ uint8_t lgadr_to;
+ /*! @~english Operation code */
+ uint8_t opc;
+ /*! @~english Data length (size in command data */
+ uint8_t d_length;
+ /*! @~english Command data */
+ uint8_t data[DECK_CMD_SIZE_CMDDATA_MAX];
+ /*! @~english reserve */
+ uint8_t reserve;
+} DECK_CMD_DATA;
+
+/*!
+ * @~english
+ * @brief Structure for send command
+ */
+typedef struct {
+ /*! @~english Command information */
+ DECK_CMD_DATA cmd_data;
+} DECK_CMD;
+
+/*------------------------------------------------------------------------------
+ * function declaration
+ *----------------------------------------------------------------------------*/
+////////////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup StopDiscRotation
+/// \~english @par Brief
+/// Stop disc rotation
+/// \~english @param [in] -
+/// \~english @param [out] -
+/// \~english @retval eFrameworkunifiedStatusOK OK
+/// \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+/// \~english @par Prerequisite
+/// - Disc was inserted
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur.
+/// \~english @par Conditions of processing failure
+/// - Error occurs when call open or ioctl function.[eFrameworkunifiedStatusFail]
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - Stop disc rotation
+/// - Whatever disc is rotating or stoped, return successed.
+/// - The API can be used by multi-process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////////////////
+
+EFrameworkunifiedStatus StopDiscRotation();
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup EjectDisc
+/// \~english @par Brief
+/// Eject disc
+/// \~english @param [in] kind
+/// DeckKind - kind of deck.
+/// \~english @param [in] mode
+/// DeckEjectMode - eject mode(normal/forcedly)
+/// \~english @param [out] -
+/// \~english @retval eFrameworkunifiedStatusOK OK
+/// \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur.
+/// \~english @par Conditions of processing failure
+/// - Error occurs when call open or ioctl function.[eFrameworkunifiedStatusFail]
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - Eject disc
+/// - Whatever disc is Ejecting or Unejected, return successed.
+/// - The API can be used by multi-process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus EjectDisc(DeckKind kind, DeckEjectMode mode);
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup DeckHalSysSend
+/// \~english @par Brief
+/// Send Disc Sys-Command to MICON
+/// \~english @param [in] h_app
+/// HANDLE - Handle of caller (Handle to get in Dispatcher generation
+/// (FrameworkunifiedCreateDispatcherWithoutLoop etc.))
+/// \~english @param [in] name
+/// PCSTR - Name to notification of send result destination thread name
+/// \~english @param [in] cmd
+/// DECK_CMD - Send command pointer
+/// \~english @param [in] req_id
+/// uint8_t - Resource ID
+/// \~english @param [out] -
+/// \~english @retval eFrameworkunifiedStatusOK Normal termination
+/// \~english @retval eFrameworkunifiedStatusInvldParam Abnormal parameter
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur.
+/// \~english @par Conditions of processing failure
+/// - h_app is NULL.[eFrameworkunifiedStatusInvldParam]
+/// - name is NULL or the length of name is longer than 15 bytes.
+/// [eFrameworkunifiedStatusInvldParam]
+/// - Send command pointer(cmd) is null.[eFrameworkunifiedStatusInvldParam]
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - Send SYS command to MICON
+/// - Now only usb disc exists,MICON disc is stub now.
+/// - The API can only be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus DeckHalSysSend(HANDLE h_app, PCSTR name, const DECK_CMD* cmd, uint8_t req_id);
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup DeckHalRegister
+/// \~english @par Brief
+/// Register the deck_hal command to receive from MICON
+/// \~english @param [in] h_app
+/// HANDLE - Handle of caller (Handle to get in Dispatcher generation
+/// (FrameworkunifiedCreateDispatcherWithoutLoop etc.))
+/// \~english @param [in] notify_name
+/// PCSTR - Name to notification destination thread name
+/// \~english @param [out] -
+/// \~english @retval eFrameworkunifiedStatusOK Normal termination
+/// \~english @retval eFrameworkunifiedStatusInvldParam Abnormal parameter
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur.
+/// \~english @par Conditions of processing failure
+/// - h_app is NULL.[eFrameworkunifiedStatusInvldParam]
+/// - notify_name is NULL or the length of notify_name is longer than 15 bytes.
+/// [eFrameworkunifiedStatusInvldParam]
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - After call this API, the user can received dech_hal command from MICON.
+/// - Now MICON is stub,so that deck_hal won't register to MICON.
+/// - The API can only be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus DeckHalRegister(HANDLE h_app, PCSTR notify_name);
+
+#ifdef __cplusplus
+}
+#endif /*__cplusplus */
+
+/** @}*/ // end of deck_hal
+/** @}*/ // end of interface_unified
+
+#endif // HAL_API_DECK_HAL_H_
diff --git a/hal/deck_hal/inc/deck_hal_deckhallog.h b/hal/deck_hal/inc/deck_hal_deckhallog.h
new file mode 100755
index 0000000..9aa4624
--- /dev/null
+++ b/hal/deck_hal/inc/deck_hal_deckhallog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_DECK_HAL_DECKHALLOG_H_
+#define INC_DECK_HAL_DECKHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_DECK_HAL_DECKHALLOG_H_
diff --git a/hal/deck_hal/src/deck_hal.cpp b/hal/deck_hal/src/deck_hal.cpp
new file mode 100755
index 0000000..a116e6c
--- /dev/null
+++ b/hal/deck_hal/src/deck_hal.cpp
@@ -0,0 +1,159 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/cdrom.h>
+#include <sys/ioctl.h>
+#include <deck_hal.h>
+#include <native_service/frameworkunified_types.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <stdio.h>
+#include <string.h>
+#include "deck_hal_deckhallog.h"
+
+#define DECKHAL_THREAD "DeckHal"
+#define DISC_PATH "/dev/sr0"
+// static variables
+static char g_notify_name[NOTIFY_NAME_MAX_SIZE + 1] = {0};
+static bool g_register_status = false; // deck_hal register status
+
+// functions
+EFrameworkunifiedStatus DeckNotifyInfo(const DECK_MSG_DELIVERY &DeliveryData);
+
+EFrameworkunifiedStatus StopDiscRotation() {
+ int fd;
+ int ret;
+ fd = open(DISC_PATH, O_RDONLY);
+ if (fd < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "open failed.");
+ return eFrameworkunifiedStatusFail;
+ }
+ ret = ioctl(fd, CDROMSTOP);
+ close(fd);
+ if (ret != 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "ioctl failed.");
+ return eFrameworkunifiedStatusFail;
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus EjectDisc(DeckKind kind, DeckEjectMode mode) {
+ int fd;
+ int ret;
+ fd = open(DISC_PATH, O_RDONLY);
+ if (fd < 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "open failed.");
+ return eFrameworkunifiedStatusFail;
+ }
+ ret = ioctl(fd, CDROM_LOCKDOOR);
+ if (ret != 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "unlock disc failed.");
+ close(fd);
+ return eFrameworkunifiedStatusFail;
+ }
+ ret = ioctl(fd, CDROMEJECT);
+ close(fd);
+ if (ret != 0) {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "eject disc failed.");
+ return eFrameworkunifiedStatusFail;
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus DeckHalSysSend(HANDLE h_app, PCSTR name, const DECK_CMD* cmd, uint8_t req_id) {
+ EFrameworkunifiedStatus ret = eFrameworkunifiedStatusOK;
+
+ if (NULL == h_app || NULL == name || NULL == cmd) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input param is NULL\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ if (NOTIFY_NAME_MAX_SIZE < strlen(name)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input name length is overlapped\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ // DeckHalSysSend aims to send command to micon,
+ // since micon is stub now,so DeckHalSysSend is stub either.
+
+ // deck_hal should notify chande mode status after received mode change info
+ // from micon,since now micon is stub,notify change mode status to vehicle
+ // immediately.
+ // the data notify to vehile is just a example.
+ DECK_MSG_DELIVERY data;
+ data.cmd.cmdhdr.lgadr_from = 0x44; // vehile:LSDRV_ADR_DVD_P
+ data.cmd.cmdhdr.lgadr_to = 0xC8; // vehicle:LSDRV_OPC_DRV_M_CH_A_DVD
+ data.cmd.cmdhdr.opc = 0xC8; // vehicle:LSDRV_OPC_DRV_M_CH_A_DVD
+ DeckNotifyInfo(data);
+
+ return ret;
+}
+
+EFrameworkunifiedStatus DeckHalRegister(HANDLE h_app, PCSTR notify_name) {
+ if (NULL == h_app) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input h_app is NULL\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ if (NULL == notify_name) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input notify_name is NULL\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ if (strlen(notify_name) > NOTIFY_NAME_MAX_SIZE) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input notify_name length is overlapped\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ strncpy(g_notify_name, notify_name, NOTIFY_NAME_MAX_SIZE);
+
+ // now micon is stub,in the future,should register to micon
+
+ g_register_status = true;
+
+ return eFrameworkunifiedStatusOK;
+}
+
+// DeckNotifyInfo aims to send deck infos to vehicle
+// if micon is not stub in the future,after received meesage from micon
+// or any other ways triggered by micon,deck_hal should call this function
+// with different input data to send these data to vehicle.
+EFrameworkunifiedStatus DeckNotifyInfo(const DECK_MSG_DELIVERY &DeliveryData) {
+ EFrameworkunifiedStatus ret = eFrameworkunifiedStatusOK;
+ HANDLE send_handle = NULL;
+
+ if (g_register_status == true) {
+ send_handle = McOpenSender(g_notify_name);
+ if (send_handle == NULL) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedMcOpenSender to _CWORD121_Shadow Failed.");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ ret = McSend(send_handle, DECKHAL_THREAD, CID_DECK_SYS_DELIVERY,
+ sizeof(DECK_MSG_DELIVERY), &DeliveryData);
+
+ if (eFrameworkunifiedStatusOK != ret) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Failed to send CID_DECK_SYS_DELIVERY.");
+ ret = eFrameworkunifiedStatusFail;
+ }
+
+ if (send_handle != NULL) {
+ McClose(send_handle);
+ send_handle = NULL;
+ }
+ }
+
+ return ret;
+}
diff --git a/hal/input_hal/LICENSE b/hal/input_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/input_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/input_hal/Makefile b/hal/input_hal/Makefile
new file mode 100755
index 0000000..35dfefd
--- /dev/null
+++ b/hal/input_hal/Makefile
@@ -0,0 +1,81 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+COMPONENT_NAME := peripheral_service
+
+######### installed program/file ################
+TARGET := libinput_hal.so
+
+HEADER := ./hal_api/input_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/include/libdrm
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+CXXFLAGS += -D_USE_DRM
+
+######### link options ##########################
+LDFLAGS := -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+######### linked library ########################
+LIBS := -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+LIBS += -Wl,-Bdynamic -ludev
+LIBS += -Wl,-Bdynamic -lpthread
+LIBS += -Wl,-Bdynamic -ldrm
+
+######### source files ##########################
+VPATH := src
+OBJS := input_hal.o
+OBJS += input_touch_ilitek.o
+OBJS += input_util.o
+OBJS += input_udev_monitor.o
+OBJS += input_drm.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install: install-input
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
+
+install-input:
+ install -m 0755 -d $(DESTDIR)/usr/agl/include/$(COMPONENT_NAME)/
+ install -m 0644 ./hal_api/$(COMPONENT_NAME)/aglinput.h $(DESTDIR)/usr/agl/include/$(COMPONENT_NAME)/
+ install -m 0644 ./hal_api/$(COMPONENT_NAME)/extinput.h $(DESTDIR)/usr/agl/include/$(COMPONENT_NAME)/
diff --git a/hal/input_hal/README.md b/hal/input_hal/README.md
new file mode 100755
index 0000000..4a69113
--- /dev/null
+++ b/hal/input_hal/README.md
@@ -0,0 +1,3 @@
+input_hal library
+==================
+Input HAL implementation library for AGL Reference Board.
diff --git a/hal/input_hal/hal_api/input_hal.h b/hal/input_hal/hal_api/input_hal.h
new file mode 100755
index 0000000..bfc9d59
--- /dev/null
+++ b/hal/input_hal/hal_api/input_hal.h
@@ -0,0 +1,696 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_INPUT_HAL_H_
+#define HAL_API_INPUT_HAL_H_
+
+#include <native_service/frameworkunified_types.h>
+
+#include "peripheral_service/aglinput.h"
+
+/**
+ * @file input_hal.h
+ */
+
+/** @addtogroup switchhandler
+ * @{
+ */
+/** @addtogroup input_hal
+ * @ingroup switchhandler
+ * @{
+ */
+
+/************************************************************************
+* Macro definitions *
+************************************************************************/
+/**
+ * \~english Return value type
+ */
+enum HalInputRetType {
+ /**
+ * \~english Success
+ */
+ HAL_INPUT_RET_NORMAL = 0,
+ /**
+ * \~english Process abnormality
+ */
+ HAL_INPUT_RET_ERROR,
+ /**
+ * \~english Not support
+ */
+ HAL_INPUT_RET_NOT_SUPPORT,
+};
+/**
+ * \~english Touch panel IC type
+ */
+enum HalInputTouchDeviceType {
+ /**
+ * \~english Touch panel IC is invalid
+ */
+ HAL_INPUT_TOUCH_DEVICE_INVALID = 0,
+ /**
+ * \~english Touch panel IC is ILITEK
+ */
+ HAL_INPUT_TOUCH_DEVICE_ILITEK,
+};
+
+/**
+ * \~english Radio band type
+ */
+enum HalInputBandType {
+ /**
+ * \~english Radio band is AM
+ */
+ HAL_INPUT_BAND_TYPE_AM = 0,
+ /**
+ * \~english Radio band isn't AM
+ */
+ HAL_INPUT_BAND_TYPE_NOT_AM,
+};
+
+/**
+ * \~english Radio reception status
+ */
+enum HalInputTuneStatus {
+ /**
+ * \~english Radio is in normal state
+ */
+ HAL_INPUT_TUNE_STATUS_NORMAL = 0,
+ /**
+ * \~english Radio is in search state
+ */
+ HAL_INPUT_TUNE_STATUS_SERACH,
+};
+
+/**
+ * \~english Sensitivity Level
+ */
+enum HalInputTouchSensitivityLevel {
+ /**
+ * \~english Sensitivity level low
+ */
+ HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_LOW = 1,
+ /**
+ * \~english Sensitivity level middle
+ */
+ HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_MIDDLE,
+ /**
+ * \~english Sensitivity level high
+ */
+ HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_HIGH,
+ /**
+ * \~english Sensitivity level none
+ */
+ HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_NONE,
+};
+
+/**
+ * \~english input device type
+ */
+enum HalInputDeviceType {
+ /**
+ * \~english The device type invalid
+ */
+ HAL_INPUT_DEVICE_INVALID,
+ /**
+ * \~english The device is keyboard
+ */
+ HAL_INPUT_DEVICE_KEYBOARD,
+ /**
+ * \~english The device is touch
+ */
+ HAL_INPUT_DEVICE_TOUCH,
+ /**
+ * \~english The device is ESC-KEY
+ */
+ HAL_INPUT_DEVICE_TOUCH_ESCKEY,
+ /**
+ * \~english The device is steering SW
+ */
+ HAL_INPUT_DEVICE_STEERING,
+ /**
+ * \~english The device is tablet finger
+ */
+ HAL_INPUT_DEVICE_TABLET_FINGER,
+ /**
+ * \~english The device is rotary key
+ */
+ HAL_INPUT_DEVICE_ROTARY_KEY,
+};
+
+/**
+ * \~english Don't need to config touch panel
+ */
+#define HAL_INPUT_TOUCH_CONFIG_OFF (0)
+/**
+ * \~english Touch panel configed
+ */
+#define HAL_INPUT_TOUCH_CONFIG_ON (1)
+
+/**
+ * \~english Touch panel touch press
+ */
+#define HAL_INPUT_TOUCH_PRESS (0)
+/**
+ * \~english Touch panel touch release
+ */
+#define HAL_INPUT_TOUCH_RELEASE (1)
+
+/**
+ * \~english Don't report touch panel's touch event
+ */
+#define HAL_INPUT_TOUCH_UNREPORT (0)
+/**
+ * \~english Report touch panel's touch event
+ */
+#define HAL_INPUT_TOUCH_REPORT (1)
+
+/**
+ * \~english Test all case
+ */
+#define HAL_INPUT_TOUCH_SELFTEST_ID_ALL (0xFE)
+/**
+ * \~english Selftest data length
+ */
+#define HAL_INPUT_TOUCH_SELFTEST_DATA_LEN (5)
+/**
+ * \~english Selftest mode not support
+ */
+#define HAL_INPUT_TOUCH_SELFTEST_NOT_SUPPORT (0xEE)
+
+/**
+ * \~english max number of input_event per package.
+ */
+#define HAL_INPUT_EVENT_COUNT 64
+
+/**
+ * \~english Thread name defined
+ */
+#define HAL_INPUT_SOURCE_NAME "input_hal_mon"
+
+/**
+ * \~english Notify input event from touch panel,
+ * The data of the notification please refer the following two type.\n
+ * @ref HAL_INPUT_TOUCH_PRESS \n
+ * @ref HAL_INPUT_TOUCH_RELEASE \n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_TOUCH, fpOnCmd);
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_TOUCH 100
+/**
+ * \~english Notify input event from touch panel ESC-KEY,
+ * The data format of the notification please refer to @ref EventsPackageInput.\n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_ESC_KEY, fpOnCmd)
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_ESC_KEY 101
+/**
+ * \~english Notify input event from key board,
+ * The data format of the notification please refer to @ref EventsPackageInput.\n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_KEY_BOARD, fpOnCmd)
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_KEY_BOARD 102
+/**
+ * \~english Notify input event from steering,
+ * The data format of the notification please refer to @ref EventsPackageInput.\n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_STEERING, fpOnCmd)
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_STEERING 104
+/**
+ * \~english Notify input event from tablet finger,
+ * The data format of the notification please refer to @ref EventsPackageInput.\n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_TABLET_FINGER, fpOnCmd)
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_TABLET_FINGER 105
+/**
+ * \~english Notify input event from rotary-key,
+ * The data format of the notification please refer to @ref EventsPackageInput.\n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_ROTARY_KEY, fpOnCmd)
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_ROTARY_KEY 106
+
+/**
+ * \~english Initialzing touch result notify,
+ * The data format of the notification please refer to @ref TouchInitFinishInput.\n
+ * Please use IF of NSFW as follows to receive this event.
+ * \~ @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(happ, HAL_INPUT_SOURCE_NAME, HAL_INPUT_NOTIFY_TOUCH_INIT_FINISH, fpOnCmd)
+ * @endcode
+ * \~english note:FrameworkunifiedAttachCallbacksToDispatcher is available, too.
+ */
+#define HAL_INPUT_NOTIFY_TOUCH_INIT_FINISH 120
+
+/**
+ * @struct RadioInfoTouch
+ * \~english @par Brief
+ * Radio information
+ */
+struct RadioInfoTouch {
+ /**
+ * \~english Radio band type
+ * \~english Please ref to @ref HalInputBandType
+ */
+ int16_t band;
+ /**
+ * \~english Frequency of the tuner[kHz]
+ * (Use only at the time of AM reception)
+ */
+ uint16_t freq;
+ /**
+ * \~english Reception status (Use only at the time of AM reception)
+ * \~english Please refer to @ref HalInputBandType
+ */
+ int32_t status;
+};
+
+/**
+ * @struct SelftestTouch
+ * \~english @par Brief
+ * Touch panel selftest mode result
+ */
+struct SelftestTouch {
+ /**
+ * \~english Touch panel selftest mode result
+ */
+ unsigned char r_code;
+ /**
+ * \~english Touch panel selftest mode data.
+ * The datail info is depend on hardware spec.
+ */
+ unsigned char r_data[HAL_INPUT_TOUCH_SELFTEST_DATA_LEN];
+};
+
+/**
+ * @struct EventsPackageInput
+ * \~english @par Brief
+ * Input event package defined
+ */
+struct EventsPackageInput {
+ /**
+ * \~english device type
+ */
+ int device_type;
+ /**
+ * \~english event count
+ */
+ int count;
+ /**
+ * \~english input event data.
+ */
+ struct input_event event[HAL_INPUT_EVENT_COUNT];
+};
+
+/**
+ * @struct TouchInitFinishInput
+ * \~english @par Brief
+ * The result of initializing touch
+ */
+struct TouchInitFinishInput {
+ /**
+ * \~english If initializing the touch successful, the result was set HAL_INPUT_RET_NORMAL.
+ * If an error occurred, the result was set HAL_INPUT_RET_ERROR.
+ */
+ int result;
+};
+/************************************************************************
+* Function prototype *
+************************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// initializing input_hal.
+/// \~english @param [in] app_name
+/// const char* - the app name for receive input event.
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - None
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - Listen input devices and send input event.
+/// - After initializing touch panel, the event(@ref HAL_INPUT_NOTIFY_TOUCH_INIT_FINISH) will be sent.
+/// - The API can be used by 1 process.
+/// \~english @see None.
+////////////////////////////////////////////////////////////////////////////////
+int InitInput(const char* app_name);
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// finalize input_hal
+/// \~english @param none
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - None
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to finalize input_hal.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int DeInitInput();
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Init those operating function of touch panel driver
+/// \~english @param none
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @par Prerequisite
+/// - Touch panel function exist
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - None
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - The API is a block I/F which initializes those operating functions of touch panel driver.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int InitTouch();
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Make touch panel start work
+/// \~english @param none
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to prepare touch panel and make it start work.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int StartTouch();
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Execute touch panel self test
+/// \~english @param [in] id
+/// int - selftest id(Pass HAL_INPUT_TOUCH_SELFTEST_ID_ALL :
+/// Execute all test(disconnection check))
+/// \~english @param [out] result
+/// void* - Touch panel selftest mode check result
+/// \~english @note Result struct SelftestTouch depend on hardware spec
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @retval HAL_INPUT_RET_NOT_SUPPORT : Not support
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Not support this function
+/// - @ref HAL_INPUT_RET_NOT_SUPPORT
+/// - Param result is NULL
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to execute touch panel self test and get test result.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int SelfTestTouch(int id, void *result);
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Set whether the driver sends touch panel data or not.
+/// \~english @param [in] status
+/// int - Touch panel whether report/unreport event\n
+/// HAL_INPUT_TOUCH_REPORT : Report touch panel's touch event\n
+/// HAL_INPUT_TOUCH_UNREPORT : Don't report touch panel's touch event\n
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @retval HAL_INPUT_RET_NOT_SUPPORT : Not support
+/// \~english @note It means this API isn't support when return
+/// @ref HAL_INPUT_RET_NOT_SUPPORT.
+/// The user need to implement it
+/// if don't need to report touch event.
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Not support this function
+/// - @ref HAL_INPUT_RET_NOT_SUPPORT
+/// - Status is none of @ref HAL_INPUT_TOUCH_REPORT /
+/// @ref HAL_INPUT_TOUCH_UNREPORT
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to set whether the driver sends touch panel data or not.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int LockTouch(int status);
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Suspend touch panel
+/// \~english @param none
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @retval HAL_INPUT_RET_NOT_SUPPORT : Not support
+/// \~english @note It means this API isn't support when return
+/// @ref HAL_INPUT_RET_NOT_SUPPORT.
+/// The user need to implement it
+/// if don't need to report touch event.
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Not support this function
+/// - @ref HAL_INPUT_RET_NOT_SUPPORT
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to suspend touch panel.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int SuspendTouch();
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Set touch panel sensitivity level
+/// \~english @param [in] level
+/// int - Sensitivity level.
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @retval HAL_INPUT_RET_NOT_SUPPORT : Not support
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Not support this function
+/// - @ref HAL_INPUT_RET_NOT_SUPPORT
+/// - Sensitivity level is none of @ref HalInputTouchSensitivityLevel
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to set touch panel sensitivity level.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int SetSensitivityLevelTouch(int level);
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Get touch panel sensitivity level
+/// \~english @param [out] level
+/// int* - Sensitivity level.
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @retval HAL_INPUT_RET_NOT_SUPPORT : Not support
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Not support this function
+/// - @ref HAL_INPUT_RET_NOT_SUPPORT
+/// - Param level is NULL
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to get touch panel sensitivity level.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int GetSensitivityLevelTouch(int *level);
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Notify radio scan frequency
+/// \~english @param [in] info
+/// RadioInfoTouch* - SCAN frequence info
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @retval HAL_INPUT_RET_NOT_SUPPORT : Not support
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Haven't called @ref InitTouch()
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Not support this function
+/// - @ref HAL_INPUT_RET_NOT_SUPPORT
+/// - Param info is NULL
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to notify radio scan frequency.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int NotifyRadioScanFreqTouch(struct RadioInfoTouch *info);
+
+////////////////////////////////////////////////////////////////////////////////
+/// \ingroup input_hal
+/// \~english @par Brief
+/// Get panel resolution
+/// \~english @param [in] reso_h
+/// int* - horizontal resolution
+/// \~english @param [in] reso_v
+/// int* - vertical resolution
+/// \~english @retval HAL_INPUT_RET_NORMAL : Success
+/// \~english @retval HAL_INPUT_RET_ERROR : Process abnormality
+/// \~english @par Prerequisite
+/// - Have called @ref InitTouch()
+/// \~english @par Change of internal state
+/// - Change of internal state according to the API does not occur
+/// \~english @par Conditions of processing failure
+/// - Param reso_h or reso_v is NULL
+/// - @ref HAL_INPUT_RET_ERROR
+/// - Inner io error
+/// - @ref HAL_INPUT_RET_ERROR
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @par Detail
+/// - This API is to get horizontal and vertical resolution.
+/// - The API can be used by 1 process.
+/// \~english @see None
+////////////////////////////////////////////////////////////////////////////////
+int GetPanelSpecResolutionInput(int *reso_h, int *reso_v);
+
+/** @}*/ // end of input_hal
+/** @}*/ // end of switchhandler
+
+#endif // HAL_API_INPUT_HAL_H_
diff --git a/hal/input_hal/hal_api/peripheral_service/aglinput.h b/hal/input_hal/hal_api/peripheral_service/aglinput.h
new file mode 100755
index 0000000..aa5f6ed
--- /dev/null
+++ b/hal/input_hal/hal_api/peripheral_service/aglinput.h
@@ -0,0 +1,536 @@
+/*
+ * @copyright Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef HAL_API_PERIPHERAL_SERVICE_AGLINPUT_H_
+#define HAL_API_PERIPHERAL_SERVICE_AGLINPUT_H_
+
+#include <peripheral_service/extinput.h>
+
+/*
+ * Extended Area for AGL
+ * In this file the Key definition based on the specification
+ * Redefine with '#undef/#define
+ */
+enum{
+ /**
+ * FP Switch : 0x0001 - 0x0064
+ * */
+ KEY_FP_TOP = 0x001,
+ KEY_FP_SW1 = KEY_FP_TOP,
+ KEY_FP_SW2 ,
+ KEY_FP_SW3 ,
+ KEY_FP_SW4 ,
+ KEY_FP_SW5 ,
+ KEY_FP_SW6 ,
+ KEY_FP_SW7 ,
+ KEY_FP_SW8 ,
+ KEY_FP_SW9 ,
+ KEY_FP_SW10 ,
+ KEY_FP_SW11 ,
+ KEY_FP_SW12 ,
+ KEY_FP_SW13 ,
+ KEY_FP_SW14 ,
+ KEY_FP_SW15 ,
+ KEY_FP_SW16 ,
+ KEY_FP_SW17 ,
+ KEY_FP_SW18 ,
+ KEY_FP_SW19 ,
+ KEY_FP_SW20 ,
+ KEY_FP_SW21 ,
+ KEY_FP_SW22 ,
+ KEY_FP_SW23 ,
+ KEY_FP_SW24 ,
+ KEY_FP_SW25 ,
+ KEY_FP_SW26 ,
+ KEY_FP_SW27 ,
+ KEY_FP_SW28 ,
+ KEY_FP_SW29 ,
+ KEY_FP_SW30 ,
+ KEY_FP_SW31 ,
+ KEY_FP_SW32 ,
+ KEY_FP_SW33 ,
+ KEY_FP_SW34 ,
+ KEY_FP_SW35 ,
+ KEY_FP_SW36 ,
+ KEY_FP_SW37 ,
+ KEY_FP_SW38 ,
+ KEY_FP_SW39 ,
+ KEY_FP_SW40 ,
+ KEY_FP_SW41 ,
+ KEY_FP_SW42 ,
+ KEY_FP_SW43 ,
+ KEY_FP_SW44 ,
+ KEY_FP_SW45 ,
+ KEY_FP_SW46 ,
+ KEY_FP_SW47 ,
+ KEY_FP_SW48 ,
+ KEY_FP_SW49 ,
+ KEY_FP_SW50 ,
+ KEY_FP_SW51 ,
+ KEY_FP_SW52 ,
+ KEY_FP_SW53 ,
+ KEY_FP_SW54 ,
+ KEY_FP_SW55 ,
+ KEY_FP_SW56 ,
+ KEY_FP_SW57 ,
+ KEY_FP_SW58 ,
+ KEY_FP_SW59 ,
+ KEY_FP_SW60 ,
+ KEY_FP_SW61 ,
+ KEY_FP_SW62 ,
+ KEY_FP_SW63 ,
+ KEY_FP_SW64 ,
+ KEY_FP_SW65 ,
+ KEY_FP_SW66 ,
+ KEY_FP_SW67 ,
+ KEY_FP_SW68 ,
+ KEY_FP_SW69 ,
+ KEY_FP_SW70 ,
+ KEY_FP_SW71 ,
+ KEY_FP_SW72 ,
+ KEY_FP_SW73 ,
+ KEY_FP_SW74 ,
+ KEY_FP_SW75 ,
+ KEY_FP_SW76 ,
+ KEY_FP_SW77 ,
+ KEY_FP_SW78 ,
+ KEY_FP_SW79 ,
+ KEY_FP_SW80 ,
+ KEY_FP_SW81 ,
+ KEY_FP_SW82 ,
+ KEY_FP_SW83 ,
+ KEY_FP_SW84 ,
+ KEY_FP_SW85 ,
+ KEY_FP_SW86 ,
+ KEY_FP_SW87 ,
+ KEY_FP_SW88 ,
+ KEY_FP_SW89 ,
+ KEY_FP_SW90 ,
+ KEY_FP_SW91 ,
+ KEY_FP_SW92 ,
+ KEY_FP_SW93 ,
+ KEY_FP_SW94 ,
+ KEY_FP_SW95 ,
+ KEY_FP_SW96 ,
+ KEY_FP_SW97 ,
+ KEY_FP_SW98 ,
+ KEY_FP_SW99 ,
+ KEY_FP_SW100 ,
+ KEY_FP_BOTTOM = KEY_FP_SW100,
+
+ /**
+ * RC Switch : 0x065 - 0x094
+ * */
+ KEY_RC_TOP = 0x0065,
+ KEY_RC_SW1 = KEY_RC_TOP,
+ KEY_RC_SW2 ,
+ KEY_RC_SW3 ,
+ KEY_RC_SW4 ,
+ KEY_RC_SW5 ,
+ KEY_RC_SW6 ,
+ KEY_RC_SW7 ,
+ KEY_RC_SW8 ,
+ KEY_RC_SW9 ,
+ KEY_RC_SW10 ,
+ KEY_RC_SW11 ,
+ KEY_RC_SW12 ,
+ KEY_RC_SW13 ,
+ KEY_RC_SW14 ,
+ KEY_RC_SW15 ,
+ KEY_RC_SW16 ,
+ KEY_RC_SW17 ,
+ KEY_RC_SW18 ,
+ KEY_RC_SW19 ,
+ KEY_RC_SW20 ,
+ KEY_RC_SW21 ,
+ KEY_RC_SW22 ,
+ KEY_RC_SW23 ,
+ KEY_RC_SW24 ,
+ KEY_RC_SW25 ,
+ KEY_RC_SW26 ,
+ KEY_RC_SW27 ,
+ KEY_RC_SW28 ,
+ KEY_RC_SW29 ,
+ KEY_RC_SW30 ,
+ KEY_RC_SW31 ,
+ KEY_RC_SW32 ,
+ KEY_RC_SW33 ,
+ KEY_RC_SW34 ,
+ KEY_RC_SW35 ,
+ KEY_RC_SW36 ,
+ KEY_RC_SW37 ,
+ KEY_RC_SW38 ,
+ KEY_RC_SW39 ,
+ KEY_RC_SW40 ,
+ KEY_RC_SW41 ,
+ KEY_RC_SW42 ,
+ KEY_RC_SW43 ,
+ KEY_RC_SW44 ,
+ KEY_RC_SW45 ,
+ KEY_RC_SW46 ,
+ KEY_RC_SW47 ,
+ KEY_RC_SW48 ,
+ KEY_RC_BOTTOM = KEY_RC_SW48,
+
+ /**
+ * R Switch : 0x0095 - 0x0096
+ * */
+ KEY_ROT_TOP = 0x0095,
+ KEY_ROT_SW1 = KEY_ROT_TOP,
+ KEY_ROT_SW2 ,
+ KEY_ROT_BOTTOM = KEY_ROT_SW2,
+
+ /**
+ * FSAC Switch : 0x0097 - 0x00D2
+ * */
+ KEY_FSAC_TOP = 0x0097,
+ KEY_FSAC_SW1 = KEY_FSAC_TOP,
+ KEY_FSAC_SW2 ,
+ KEY_FSAC_SW3 ,
+ KEY_FSAC_SW4 ,
+ KEY_FSAC_SW5 ,
+ KEY_FSAC_SW6 ,
+ KEY_FSAC_SW7 ,
+ KEY_FSAC_SW8 ,
+ KEY_FSAC_SW9 ,
+ KEY_FSAC_SW10 ,
+ KEY_FSAC_SW11 ,
+ KEY_FSAC_SW12 ,
+ KEY_FSAC_SW13 ,
+ KEY_FSAC_SW14 ,
+ KEY_FSAC_SW15 ,
+ KEY_FSAC_SW16 ,
+ KEY_FSAC_SW17 ,
+ KEY_FSAC_SW18 ,
+ KEY_FSAC_SW19 ,
+ KEY_FSAC_SW20 ,
+ KEY_FSAC_SW21 ,
+ KEY_FSAC_SW22 ,
+ KEY_FSAC_SW23 ,
+ KEY_FSAC_SW24 ,
+ KEY_FSAC_SW25 ,
+ KEY_FSAC_SW26 ,
+ KEY_FSAC_SW27 ,
+ KEY_FSAC_SW28 ,
+ KEY_FSAC_SW29 ,
+ KEY_FSAC_SW30 ,
+ KEY_FSAC_SW31 ,
+ KEY_FSAC_SW32 ,
+ KEY_FSAC_SW33 ,
+ KEY_FSAC_SW34 ,
+ KEY_FSAC_SW35 ,
+ KEY_FSAC_SW36 ,
+ KEY_FSAC_SW37 ,
+ KEY_FSAC_SW38 ,
+ KEY_FSAC_SW39 ,
+ KEY_FSAC_SW40 ,
+ KEY_FSAC_SW41 ,
+ KEY_FSAC_SW42 ,
+ KEY_FSAC_SW43 ,
+ KEY_FSAC_SW44 ,
+ KEY_FSAC_SW45 ,
+ KEY_FSAC_SW46 ,
+ KEY_FSAC_SW47 ,
+ KEY_FSAC_SW48 ,
+ KEY_FSAC_SW49 ,
+ KEY_FSAC_SW50 ,
+ KEY_FSAC_SW51 ,
+ KEY_FSAC_SW52 ,
+ KEY_FSAC_SW53 ,
+ KEY_FSAC_SW54 ,
+ KEY_FSAC_SW55 ,
+ KEY_FSAC_SW56 ,
+ KEY_FSAC_SW57 ,
+ KEY_FSAC_SW58 ,
+ KEY_FSAC_SW59 ,
+ KEY_FSAC_BOTTOM = KEY_FSAC_SW59,
+
+ /**
+ * Ste Switch : 0x00D3 - 0x00E6
+ * */
+ KEY_STE_TOP = 0x00D3,
+ KEY_STE_SW1 = KEY_STE_TOP,
+ KEY_STE_SW2 ,
+ KEY_STE_SW3 ,
+ KEY_STE_SW4 ,
+ KEY_STE_SW5 ,
+ KEY_STE_SW6 ,
+ KEY_STE_SW7 ,
+ KEY_STE_SW8 ,
+ KEY_STE_SW9 ,
+ KEY_STE_SW10 ,
+ KEY_STE_SW11 ,
+ KEY_STE_SW12 ,
+ KEY_STE_SW13 ,
+ KEY_STE_SW14 ,
+ KEY_STE_SW15 ,
+ KEY_STE_SW16 ,
+ KEY_STE_SW18 ,
+ KEY_STE_SW19 ,
+ KEY_STE_BOTTOM = KEY_STE_SW19,
+
+ /**
+ * RCP Switch : 0x00F0 - 0x00F8
+ * */
+ KEY_RCP_TOP = 0x00F0,
+ KEY_RCP_SW1 = KEY_RCP_TOP,
+ KEY_RCP_SW2 ,
+ KEY_RCP_SW3 ,
+ KEY_RCP_SW4 ,
+ KEY_RCP_SW5 ,
+ KEY_RCP_SW6 ,
+ KEY_RCP_SW7 ,
+ KEY_RCP_SW8 ,
+ KEY_RCP_BOTTOM = KEY_RCP_SW8,
+
+ /**
+ * RSE_RC Switch : 0x0160 - 0x01CF
+ * */
+ KEY_RSE_RC_TOP = 0x0160,
+ KEY_RSE_RC_SW1 = KEY_RSE_RC_TOP,
+ KEY_RSE_RC_SW2 ,
+ KEY_RSE_RC_SW3 ,
+ KEY_RSE_RC_SW4 ,
+ KEY_RSE_RC_SW5 ,
+ KEY_RSE_RC_SW6 ,
+ KEY_RSE_RC_SW7 ,
+ KEY_RSE_RC_SW8 ,
+ KEY_RSE_RC_SW9 ,
+ KEY_RSE_RC_SW10 ,
+ KEY_RSE_RC_SW11 ,
+ KEY_RSE_RC_SW12 ,
+ KEY_RSE_RC_SW13 ,
+ KEY_RSE_RC_SW14 ,
+ KEY_RSE_RC_SW15 ,
+ KEY_RSE_RC_SW16 ,
+ KEY_RSE_RC_SW17 ,
+ KEY_RSE_RC_SW18 ,
+ KEY_RSE_RC_SW19 ,
+ KEY_RSE_RC_SW20 ,
+ KEY_RSE_RC_SW21 ,
+ KEY_RSE_RC_SW22 ,
+ KEY_RSE_RC_SW23 ,
+ KEY_RSE_RC_SW24 ,
+ KEY_RSE_RC_SW25 ,
+ KEY_RSE_RC_SW26 ,
+ KEY_RSE_RC_SW27 ,
+ KEY_RSE_RC_SW28 ,
+ KEY_RSE_RC_SW29 ,
+ KEY_RSE_RC_SW30 ,
+ KEY_RSE_RC_SW31 ,
+ KEY_RSE_RC_SW32 ,
+ KEY_RSE_RC_SW33 ,
+ KEY_RSE_RC_SW34 ,
+ KEY_RSE_RC_SW35 ,
+ KEY_RSE_RC_SW36 ,
+ KEY_RSE_RC_SW37 ,
+ KEY_RSE_RC_SW38 ,
+ KEY_RSE_RC_SW39 ,
+ KEY_RSE_RC_SW40 ,
+ KEY_RSE_RC_SW41 ,
+ KEY_RSE_RC_SW42 ,
+ KEY_RSE_RC_SW43 ,
+ KEY_RSE_RC_SW44 ,
+ KEY_RSE_RC_SW45 ,
+ KEY_RSE_RC_SW46 ,
+ KEY_RSE_RC_SW47 ,
+ KEY_RSE_RC_SW48 ,
+ KEY_RSE_RC_SW49 ,
+ KEY_RSE_RC_SW50 ,
+ KEY_RSE_RC_SW51 ,
+ KEY_RSE_RC_SW52 ,
+ KEY_RSE_RC_SW53 ,
+ KEY_RSE_RC_SW54 ,
+ KEY_RSE_RC_SW55 ,
+ KEY_RSE_RC_SW56 ,
+ KEY_RSE_RC_SW57 ,
+ KEY_RSE_RC_SW58 ,
+ KEY_RSE_RC_SW59 ,
+ KEY_RSE_RC_SW60 ,
+ KEY_RSE_RC_SW61 ,
+ KEY_RSE_RC_SW65 ,
+ KEY_RSE_RC_SW66 ,
+ KEY_RSE_RC_SW67 ,
+ KEY_RSE_RC_SW68 ,
+ KEY_RSE_RC_SW69 ,
+ KEY_RSE_RC_SW70 ,
+ KEY_RSE_RC_SW71 ,
+ KEY_RSE_RC_SW72 ,
+ KEY_RSE_RC_SW73 ,
+ KEY_RSE_RC_SW74 ,
+ KEY_RSE_RC_SW75 ,
+ KEY_RSE_RC_SW76 ,
+ KEY_RSE_RC_SW77 ,
+ KEY_RSE_RC_SW78 ,
+ KEY_RSE_RC_SW79 ,
+ KEY_RSE_RC_SW80 ,
+ KEY_RSE_RC_SW81 ,
+ KEY_RSE_RC_SW82 ,
+ KEY_RSE_RC_SW83 ,
+ KEY_RSE_RC_SW84 ,
+ KEY_RSE_RC_SW85 ,
+ KEY_RSE_RC_SW86 ,
+ KEY_RSE_RC_SW87 ,
+ KEY_RSE_RC_SW88 ,
+ KEY_RSE_RC_SW89 ,
+ KEY_RSE_RC_SW90 ,
+ KEY_RSE_RC_SW91 ,
+ KEY_RSE_RC_SW92 ,
+ KEY_RSE_RC_SW93 ,
+ KEY_RSE_RC_SW94 ,
+ KEY_RSE_RC_SW95 ,
+ KEY_RSE_RC_SW96 ,
+ KEY_RSE_RC_SW97 ,
+ KEY_RSE_RC_SW98 ,
+ KEY_RSE_RC_SW99 ,
+ KEY_RSE_RC_SW100 ,
+ KEY_RSE_RC_SW101 ,
+ KEY_RSE_RC_SW102 ,
+ KEY_RSE_RC_SW62 ,
+ KEY_RSE_RC_SW63 ,
+ KEY_RSE_RC_SW64 ,
+ KEY_RSE_RC_SW103 ,
+ KEY_RSE_RC_SW104 ,
+ KEY_RSE_RC_SW105 ,
+ KEY_RSE_RC_SW106 ,
+ KEY_RSE_RC_SW107 ,
+ KEY_RSE_RC_SW108 ,
+ KEY_RSE_RC_SW109 ,
+ KEY_RSE_RC_SW110 ,
+ KEY_RSE_RC_SW111 ,
+ KEY_RSE_RC_SW112 ,
+ KEY_RSE_RC_BOTTOM = KEY_RSE_RC_SW112,
+
+ /**
+ * RTP Switch : 0x01D6 - 0x01DE
+ * */
+ KEY_RTP_TOP = 0x01D6,
+ KEY_RTP_SW1 = KEY_RTP_TOP,
+ KEY_RTP_SW2 ,
+ KEY_RTP_SW3 ,
+ KEY_RTP_SW4 ,
+ KEY_RTP_SW5 ,
+ KEY_RTP_SW6 ,
+ KEY_RTP_SW7 ,
+ KEY_RTP_SW8 ,
+ KEY_RTP_SW9 ,
+ KEY_RTP_BOTTOM = KEY_RTP_SW9,
+
+ /**
+ * RSP Switch : 0x01E0 - 0x0208
+ * */
+ KEY_RSP_TOP = 0x01E0,
+ KEY_RSP_SW1 = KEY_RSP_TOP,
+ KEY_RSP_SW2 ,
+ KEY_RSP_SW3 ,
+ KEY_RSP_SW4 ,
+ KEY_RSP_SW5 ,
+ KEY_RSP_SW6 ,
+ KEY_RSP_SW7 ,
+ KEY_RSP_SW8 ,
+ KEY_RSP_SW9 ,
+ KEY_RSP_SW10 ,
+ KEY_RSP_SW11 ,
+ KEY_RSP_SW12 ,
+ KEY_RSP_SW13 ,
+ KEY_RSP_SW14 ,
+ KEY_RSP_SW15 ,
+ KEY_RSP_SW16 ,
+ KEY_RSP_SW17 ,
+ KEY_RSP_SW18 ,
+ KEY_RSP_SW19 ,
+ KEY_RSP_SW20 ,
+ KEY_RSP_SW21 ,
+ KEY_RSP_SW22 ,
+ KEY_RSP_SW23 ,
+ KEY_RSP_SW24 ,
+ KEY_RSP_SW25 ,
+ KEY_RSP_SW26 ,
+ KEY_RSP_SW27 ,
+ KEY_RSP_SW28 ,
+ KEY_RSP_SW29 ,
+ KEY_RSP_SW30 ,
+ KEY_RSP_SW31 ,
+ KEY_RSP_SW32 ,
+ KEY_RSP_SW33 ,
+ KEY_RSP_SW34 ,
+ KEY_RSP_SW35 ,
+ KEY_RSP_SW36 ,
+ KEY_RSP_SW37 ,
+ KEY_RSP_SW38 ,
+ KEY_RSP_SW39 ,
+ KEY_RSP_SW40 ,
+ KEY_RSP_SW41 ,
+ KEY_RSP_BOTTOM = KEY_RSP_SW41,
+
+ /**
+ * Original Define : 0x02A0 - 0x02CF
+ * */
+ KEY_INPUTHAL_TOP = 0x02A0,
+ KEY_INPUTHAL_SW1 = KEY_INPUTHAL_TOP,
+ KEY_INPUTHAL_BTN_RIGHT,
+ KEY_INPUTHAL_BTN_MIDDLE,
+ KEY_INPUTHAL_BTN_SIDE,
+ KEY_INPUTHAL_BTN_EXTRA,
+ KEY_INPUTHAL_BTN_FORWARD,
+ KEY_INPUTHAL_BTN_BACK,
+ KEY_INPUTHAL_BTN_TASK,
+ KEY_INPUTHAL_SW9,
+ KEY_INPUTHAL_SW10,
+ KEY_INPUTHAL_BTN_JOYSTICK,
+ KEY_INPUTHAL_TOUCH,
+ KEY_INPUTHAL_SINGLE_TAP_UP,
+ KEY_INPUTHAL_DOUBLE_TOUCH_DOWN,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY1,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY2,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY3,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY4,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY5,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY6,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY7,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY8,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY9,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY10,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY11,
+ KEY_INPUTHAL_TOUCHPAD_DUMMY12,
+ KEY_INPUTHAL_TOUCH_POINT_3,
+ KEY_INPUTHAL_TOUCH_POINT_2,
+ KEY_INPUTHAL_PUSH,
+ KEY_INPUTHAL_TAP_SINGLE,
+ KEY_INPUTHAL_TAP_DOUBLE,
+ KEY_INPUTHAL_SW16,
+ KEY_INPUTHAL_NAVI,
+ KEY_INPUTHAL_HOME,
+ KEY_INPUTHAL_MEM1,
+ KEY_INPUTHAL_MEM2,
+ KEY_INPUTHAL_RECENT_JP,
+ KEY_INPUTHAL_WEB,
+ KEY_INPUTHAL_DEST_ERACE,
+ KEY_INPUTHAL_MENU_SEARCH,
+ KEY_INPUTHAL_MENU_GO_HOME,
+ KEY_INPUTHAL_MENU_RECENT_NA,
+ KEY_INPUTHAL_MENU_FAVORITE,
+ KEY_INPUTHAL_MENU_CONTACT,
+ KEY_INPUTHAL_MENU_OTHERS,
+ KEY_INPUTHAL_MENU_SUBSCREEN_NAVI,
+ KEY_INPUTHAL_INVALID_SW ,
+ KEY_INPUTHAL_BOTTOM = KEY_INPUTHAL_INVALID_SW,
+};
+
+#define BTN_TAP_DOUBLE KEY_INPUTHAL_SW10
+
+#define REL_PINCH 0x0a
+
+#endif // HAL_API_PERIPHERAL_SERVICE_AGLINPUT_H_
diff --git a/hal/input_hal/hal_api/peripheral_service/extinput.h b/hal/input_hal/hal_api/peripheral_service/extinput.h
new file mode 100755
index 0000000..0265a2d
--- /dev/null
+++ b/hal/input_hal/hal_api/peripheral_service/extinput.h
@@ -0,0 +1,27 @@
+/*
+ * @copyright Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef HAL_API_PERIPHERAL_SERVICE_EXTINPUT_H_
+#define HAL_API_PERIPHERAL_SERVICE_EXTINPUT_H_
+
+#include <linux/input.h>
+
+/*
+ * Extended fields for each supplier
+ * If you want to modify the key definition at the supplier,
+ * redefine with '#undef/#define in this file.
+ */
+
+#endif // HAL_API_PERIPHERAL_SERVICE_EXTINPUT_H_
diff --git a/hal/input_hal/inc/input_drm.h b/hal/input_hal/inc/input_drm.h
new file mode 100755
index 0000000..11ffc32
--- /dev/null
+++ b/hal/input_hal/inc/input_drm.h
@@ -0,0 +1,22 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_INPUT_DRM_H_
+#define INC_INPUT_DRM_H_
+
+int GetPanelSpecResolutionInput(int *reso_h, int *reso_v);
+
+#endif // INC_INPUT_DRM_H_
diff --git a/hal/input_hal/inc/input_hal_debug.h b/hal/input_hal/inc/input_hal_debug.h
new file mode 100755
index 0000000..2fb7d86
--- /dev/null
+++ b/hal/input_hal/inc/input_hal_debug.h
@@ -0,0 +1,57 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_INPUT_HAL_DEBUG_H_
+#define INC_INPUT_HAL_DEBUG_H_
+
+#include "input_hal_frameworkunifiedlog.h"
+
+// #define INPUT_DEBUG
+
+#ifdef INPUT_DEBUG
+#define INPUT_DBG_LOG(zone_index, fmt, ...) \
+ FRAMEWORKUNIFIEDLOG(zone_index, __FUNCTION__, fmt, ## __VA_ARGS__);
+#else
+#define INPUT_DBG_LOG(zone_index, fmt, ...)
+#endif
+
+/* Log output control flag */
+#define INPUT_LOG_ENABLE_TRACE /* Normal log(Trace) */
+#define INPUT_LOG_ENABLE_ERROR /* Error log */
+#define INPUT_LOG_ENABLE_RETAIL /* Debug log */
+
+#ifdef INPUT_LOG_ENABLE_TRACE
+#define INPUT_LOG_TRACE(fmt, ...) \
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, fmt, ## __VA_ARGS__);
+#else
+#define INPUT_LOG_TRACE(fmt, ...)
+#endif
+
+#ifdef INPUT_LOG_ENABLE_ERROR
+#define INPUT_ERROR_LOG(fmt, ...) \
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, fmt, ## __VA_ARGS__);
+#else
+#define INPUT_ERROR_LOG(fmt, ...)
+#endif
+
+#ifdef INPUT_LOG_ENABLE_RETAIL
+#define INPUT_RETAIL_LOG(fmt, ...) \
+ FRAMEWORKUNIFIEDLOG(ZONE_HMI_DBG, __FUNCTION__, fmt, ## __VA_ARGS__);
+#else
+#define INPUT_RETAIL_LOG(fmt, ...)
+#endif
+
+#endif // INC_INPUT_HAL_DEBUG_H_
diff --git a/hal/input_hal/inc/input_hal_frameworkunifiedlog.h b/hal/input_hal/inc/input_hal_frameworkunifiedlog.h
new file mode 100755
index 0000000..c54f16a
--- /dev/null
+++ b/hal/input_hal/inc/input_hal_frameworkunifiedlog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_INPUT_HAL_FRAMEWORKUNIFIEDLOG_H_
+#define INC_INPUT_HAL_FRAMEWORKUNIFIEDLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_INPUT_HAL_FRAMEWORKUNIFIEDLOG_H_
diff --git a/hal/input_hal/inc/input_hal_internal.h b/hal/input_hal/inc/input_hal_internal.h
new file mode 100755
index 0000000..4e57aed
--- /dev/null
+++ b/hal/input_hal/inc/input_hal_internal.h
@@ -0,0 +1,107 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_INPUT_HAL_INTERNAL_H_
+#define INC_INPUT_HAL_INTERNAL_H_
+
+/*
+ * Touch panel operation function info
+ */
+struct TouchHal {
+ /**
+ * \~english Make touch panel start work.
+ */
+ int (* start)(void);
+ /**
+ * \~english Get touch panel device horizontal resolution.
+ */
+ int (* get_reso_h)(int *);
+ /**
+ * \~english Get touch panel device vertical resolution.
+ */
+ int (* get_reso_v)(int *);
+ /**
+ * \~english Get whether X axis is inversion.
+ */
+ int (* get_reverse_axis_x)(bool *);
+ /**
+ * \~english Get whether Y axis is inversion.
+ */
+ int (* get_reverse_axis_y)(bool *);
+ /**
+ * \~english Config touch panel.
+ */
+ int (* config)(const char *, int, int);
+ /**
+ * \~english Get touch panel device name.
+ */
+ int (* get_touch_devicename)(char*, size_t);
+ /**
+ * \~english Get touch panel key device name.
+ */
+ int (* get_key_devicename)(char*, size_t);
+ /**
+ * \~english Execute touch panel self test.
+ */
+ int (* selftest)(int, void *);
+ /**
+ * \~english Get touch panel config status.
+ */
+ int (* get_config_status)(int *);
+ /**
+ * \~english Set whether the driver sends touch panel data or not.
+ */
+ int (* set_touch_lock)(int);
+ /**
+ * \~english Request touch panel touch suspend.
+ */
+ int (* set_touch_suspend)(void);
+ /**
+ * \~english Set touch panel sensitivity level.
+ */
+ int (* set_sensitivity_level)(int);
+ /**
+ * \~english Get touch panel sensitivity level.
+ */
+ int (* get_sensitivity_level)(int *);
+ /**
+ * \~english Notify radio scan frequency.
+ */
+ int (* notify_radio_scan_frequency)(struct RadioInfoTouch *);
+};
+
+
+/**
+ * Config touch panel
+ */
+int ConfigTouch(const char *path , int resolution_h, int resolution_v);
+
+/**
+ * Get touch panel device name
+ */
+int GetPanelNameTouch(char* name, size_t buf_length);
+
+/**
+ * Get touch panel key device name
+ */
+int GetKeyNameTouch(char* name, size_t buf_length);
+
+/**
+ * Get touch panel config status
+ */
+int GetConfigStatusTouch(int *status);
+
+#endif // INC_INPUT_HAL_INTERNAL_H_
diff --git a/hal/input_hal/inc/input_touch_ilitek.h b/hal/input_hal/inc/input_touch_ilitek.h
new file mode 100755
index 0000000..6d76d83
--- /dev/null
+++ b/hal/input_hal/inc/input_touch_ilitek.h
@@ -0,0 +1,27 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_INPUT_TOUCH_ILITEK_H_
+#define INC_INPUT_TOUCH_ILITEK_H_
+
+#include "input_hal_internal.h"
+
+/*
+ * Init ilitek touch panel operation function
+ */
+int InputTouchIlitekInit(struct TouchHal *touch);
+
+#endif // INC_INPUT_TOUCH_ILITEK_H_
diff --git a/hal/input_hal/inc/input_udev_monitor.h b/hal/input_hal/inc/input_udev_monitor.h
new file mode 100755
index 0000000..0391f6f
--- /dev/null
+++ b/hal/input_hal/inc/input_udev_monitor.h
@@ -0,0 +1,40 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_INPUT_UDEV_MONITOR_H_
+#define INC_INPUT_UDEV_MONITOR_H_
+
+#include <peripheral_service/aglinput.h>
+
+#include "input_util.h"
+
+#define INPUT_DEVICE_NODE_LENGTH_MAX (32)
+
+struct InputInputDeviceList{
+ int fd;
+ int device_assort;
+ char device_node[INPUT_DEVICE_NODE_LENGTH_MAX];
+ struct InputUtilList list;
+};
+
+struct InputUdevMonitorInfo {
+ struct udev *udev;
+ struct udev_monitor *monitor;
+ struct InputInputDeviceList dev_list;
+};
+
+int32_t InputUdevMonitorThreadCreate(void);
+
+#endif // INC_INPUT_UDEV_MONITOR_H_
diff --git a/hal/input_hal/inc/input_util.h b/hal/input_hal/inc/input_util.h
new file mode 100755
index 0000000..6d6a400
--- /dev/null
+++ b/hal/input_hal/inc/input_util.h
@@ -0,0 +1,46 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_INPUT_UTIL_H_
+#define INC_INPUT_UTIL_H_
+
+#include <native_service/frameworkunified_types.h>
+
+struct InputUtilList {
+ struct InputUtilList *next;
+ struct InputUtilList *prev;
+};
+
+#define INPUT_INIT_LIST_HEAD(ptr) \
+ (ptr)->next = (ptr); (ptr)->prev = (ptr);
+
+#define input_list_entry(ptr, type, member) \
+ (reinterpret_cast<type *>( \
+ reinterpret_cast<char *>(ptr) - (size_t)(&(reinterpret_cast<type *>(0))->member)))
+
+#define input_list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); pos = pos->next)
+
+#define input_list_for_each_safe(pos, n, head) \
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
+
+void InputUtilListAdd(struct InputUtilList *node_new, struct InputUtilList *node_head);
+void InputUtilListDelete(struct InputUtilList *node);
+int InputUtilMCSend(HANDLE h_message, PCSTR source, UI_32 cmd, UI_32 length, PCVOID data);
+int InputUtilSleep(int usec);
+
+#endif // INC_INPUT_UTIL_H_
diff --git a/hal/input_hal/src/input_drm.cpp b/hal/input_hal/src/input_drm.cpp
new file mode 100755
index 0000000..20adf79
--- /dev/null
+++ b/hal/input_hal/src/input_drm.cpp
@@ -0,0 +1,128 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "input_drm.h"
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#if defined(_USE_DRM)
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#endif
+
+#include "input_hal.h"
+#include "input_hal_debug.h"
+
+#define DIR_PATH "/dev/dri/card0"
+#define DEFAULT_RESOLUTION_HORIZONTAL 1280 /* Horizontal resolution default value */
+#define DEFAULT_RESOLUTION_VERTICAL 800 /* Vertical resolution default value */
+/**
+ * Panel resolution acquisition / GetPanelSpecResolutionInput
+ */
+int GetPanelSpecResolutionInput(int *reso_h, int *reso_v) {
+ if ((NULL == reso_h) || (NULL == reso_v)) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+#if defined(_USE_DRM)
+ int fd;
+ drmModeRes *resources = NULL;
+ drmModeConnector *connector = NULL;
+ drmModeEncoder *encoder = NULL;
+ drmModeCrtc *crtc = NULL;
+
+ fd = open(DIR_PATH, O_RDWR);
+ if (fd < 0) {
+ INPUT_ERROR_LOG("DRI Open Error=%s\n", DIR_PATH);
+ goto err_rtn;
+ }
+
+ resources = drmModeGetResources(fd);
+ if (!resources) {
+ INPUT_ERROR_LOG("No resources\n");
+ goto err_rtn;
+ }
+ if (2 > resources->count_connectors) {
+ INPUT_ERROR_LOG("DRI Connect Num Error connectors=%d\n",
+ resources->count_connectors);
+ goto err_rtn;
+ }
+
+ connector = drmModeGetConnector(fd, resources->connectors[1]);
+ if (!connector) {
+ INPUT_ERROR_LOG("No Connector\n");
+ goto err_rtn;
+ }
+
+ if ((DRM_MODE_CONNECTED == connector->connection) &&(connector->count_modes > 0)) {
+ } else {
+ INPUT_ERROR_LOG("Not found connected connector\n");
+ goto err_rtn;
+ }
+
+ encoder = drmModeGetEncoder(fd, connector->encoder_id);
+ if (!encoder) {
+ INPUT_ERROR_LOG("drmModeGetEncoder null\n");
+ goto err_rtn;
+ }
+
+ crtc = drmModeGetCrtc(fd, encoder->crtc_id);
+ if (!crtc) {
+ INPUT_ERROR_LOG("drmModeGetCrtc null\n");
+ goto err_rtn;
+ }
+
+ *reso_h = crtc->mode.hdisplay;
+ *reso_v = crtc->mode.vdisplay;
+
+ drmModeFreeCrtc(crtc);
+ drmModeFreeEncoder(encoder);
+ drmModeFreeConnector(connector);
+ drmModeFreeResources(resources);
+ close(fd);
+
+ INPUT_LOG_TRACE("width=%d height=%d\n", *reso_h, *reso_v);
+ return HAL_INPUT_RET_NORMAL;
+
+err_rtn:
+
+ if (encoder) {
+ drmModeFreeEncoder(encoder);
+ }
+ if (connector) {
+ drmModeFreeConnector(connector);
+ }
+ if (resources) {
+ drmModeFreeResources(resources);
+ }
+ if (fd >= 0) {
+ close(fd);
+ }
+
+ INPUT_ERROR_LOG("Use Default Resolution\n");
+ *reso_h = DEFAULT_RESOLUTION_HORIZONTAL;
+ *reso_v = DEFAULT_RESOLUTION_VERTICAL;
+
+ return HAL_INPUT_RET_ERROR;
+#else
+ *reso_h = DEFAULT_RESOLUTION_HORIZONTAL;
+ *reso_v = DEFAULT_RESOLUTION_VERTICAL;
+
+ return HAL_INPUT_RET_NORMAL;
+#endif
+}
diff --git a/hal/input_hal/src/input_hal.cpp b/hal/input_hal/src/input_hal.cpp
new file mode 100755
index 0000000..b5f4916
--- /dev/null
+++ b/hal/input_hal/src/input_hal.cpp
@@ -0,0 +1,267 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "input_hal.h"
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "input_hal_debug.h"
+#include "input_hal_internal.h"
+#include "input_touch_ilitek.h"
+#include "input_udev_monitor.h"
+
+// Touch panel operation function info
+static struct TouchHal g_input_touch_info = { 0 };
+
+char* g_app_name = NULL;
+static bool g_touch_inited = false;
+static bool g_input_inited = false;
+
+extern bool g_break_from_watch;
+extern pthread_t g_udev_monitor_thread;
+
+// Environment key name
+#define HAL_INPUT_TARGET_BOARD "TARGET_BOARD"
+// Reference board environment value of HAL_INPUT_TARGET_BOARD
+#define HAL_INPUT_REF_BOARD_NAME "agl_reference"
+// Invalid status of report touch panel's touch event
+#define HAL_INPUT_TOUCH_REPORT_INVALID (-1)
+
+/*
+ * Input device init.
+ */
+int InitInput(const char* app_name) {
+ if (NULL == app_name) {
+ INPUT_ERROR_LOG("param is error");
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ if (!g_touch_inited) {
+ INPUT_ERROR_LOG("call InitTouch first.");
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ if (g_input_inited) {
+ INPUT_ERROR_LOG("input inited.");
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ g_break_from_watch = false;
+ if (NULL != g_app_name) {
+ delete[] g_app_name;
+ }
+
+ g_app_name = new char[strlen(app_name) + 1];
+ snprintf(g_app_name, strlen(app_name) + 1, "%s", app_name);
+ if (HAL_INPUT_RET_ERROR == InputUdevMonitorThreadCreate()) {
+ delete[] g_app_name;
+ g_app_name = NULL;
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ g_input_inited = true;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Deinit input device
+ */
+int DeInitInput() {
+ g_break_from_watch = true;
+ void* ret_val = NULL;
+ if (NULL != g_app_name) {
+ delete[] g_app_name;
+ g_app_name = NULL;
+ }
+ if (g_udev_monitor_thread != static_cast<pthread_t>(-1)) {
+ pthread_join(g_udev_monitor_thread, &ret_val);
+ }
+ g_input_inited = false;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Init those operating function of touch panel driver
+ */
+int InitTouch() {
+ int ret = InputTouchIlitekInit(&g_input_touch_info);
+ g_touch_inited = true;
+ return ret;
+}
+
+/*
+ * Make touch panel start work
+ */
+int StartTouch() {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.start) {
+ ret = g_input_touch_info.start();
+ }
+
+ return ret;
+}
+
+/*
+ * Config touch panel
+ */
+int ConfigTouch(const char *path , int reso_h, int reso_v) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.config) {
+ ret = g_input_touch_info.config(path, reso_h, reso_v);
+ }
+
+ return ret;
+}
+
+/*
+ * Get touch panel device name
+ */
+int GetPanelNameTouch(char* name, size_t buf_length) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.get_touch_devicename) {
+ ret = g_input_touch_info.get_touch_devicename(name, buf_length);
+ }
+
+ return ret;
+}
+
+/*
+ * Get touch panel key device name
+ */
+int GetKeyNameTouch(char* name, size_t buf_length) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.get_key_devicename) {
+ ret = g_input_touch_info.get_key_devicename(name, buf_length);
+ }
+
+ return ret;
+}
+
+/*
+ * Execute touch panel self test
+ */
+int SelfTestTouch(int id, void *result) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.selftest) {
+ ret = g_input_touch_info.selftest(id, result);
+ }
+
+ return ret;
+}
+
+/*
+ * Get touch panel config status
+ */
+int GetConfigStatusTouch(int *status) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.get_config_status) {
+ ret = g_input_touch_info.get_config_status(status);
+ }
+
+ return ret;
+}
+
+/*
+ * Set whether the driver sends touch panel data or not
+ */
+int LockTouch(int status) {
+ static int input_touch_lock_status = HAL_INPUT_TOUCH_REPORT_INVALID;
+
+ if (input_touch_lock_status == status) {
+ return HAL_INPUT_RET_NORMAL;
+ }
+
+ int ret = HAL_INPUT_RET_ERROR;
+ if (NULL != g_input_touch_info.set_touch_lock) {
+ ret = g_input_touch_info.set_touch_lock(status);
+ if (HAL_INPUT_RET_NORMAL == ret) {
+ input_touch_lock_status = status;
+ }
+ }
+
+ return ret;
+}
+
+/*
+ * Suspend touch panel
+ */
+int SuspendTouch() {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.set_touch_suspend) {
+ ret = g_input_touch_info.set_touch_suspend();
+ }
+
+ return ret;
+}
+
+/*
+ * Set touch panel sensitivity level
+ */
+int SetSensitivityLevelTouch(int level) {
+ int cur = HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_NONE;
+
+ int ret = GetSensitivityLevelTouch(&cur);
+ if (HAL_INPUT_RET_NORMAL == ret) {
+ if (cur == level) {
+ // Don't need to update sensitivity level
+ INPUT_LOG_TRACE("already set level=%d", level);
+ } else {
+ if (NULL != g_input_touch_info.set_sensitivity_level) {
+ ret = g_input_touch_info.set_sensitivity_level(level);
+ } else {
+ ret = HAL_INPUT_RET_ERROR;
+ }
+ }
+ }
+
+ return ret;
+}
+
+/*
+ * Get touch panel sensitivity level
+ */
+int GetSensitivityLevelTouch(int *level) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.get_sensitivity_level) {
+ ret = g_input_touch_info.get_sensitivity_level(level);
+ }
+
+ return ret;
+}
+
+/*
+ * Notify radio scan frequency
+ */
+int NotifyRadioScanFreqTouch(struct RadioInfoTouch *info) {
+ int ret = HAL_INPUT_RET_ERROR;
+
+ if (NULL != g_input_touch_info.notify_radio_scan_frequency) {
+ ret = g_input_touch_info.notify_radio_scan_frequency(info);
+ }
+
+ return ret;
+}
diff --git a/hal/input_hal/src/input_touch_ilitek.cpp b/hal/input_hal/src/input_touch_ilitek.cpp
new file mode 100755
index 0000000..9d1822a
--- /dev/null
+++ b/hal/input_hal/src/input_touch_ilitek.cpp
@@ -0,0 +1,226 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "input_touch_ilitek.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "input_hal.h"
+
+// Touch panel device name
+#define HAL_INPUT_ILITEK_TOUCH_DEVICE_NAME "ILITEK ILITEK Multi-Touch"
+// Touch panel key device name
+#define HAL_INPUT_ILITEK_KEY_DEVICE_NAME ""
+
+// Touch panel horizontal resolution value
+#define HAL_INPUT_TOUCH_RESOLUTION_HORIZONTAL 4816
+
+// Touch panel vertical resolution value
+#define HAL_INPUT_TOUCH_RESOLUTION_VERTICAL 2992
+
+/*
+ * Make touch panel start work
+ */
+static int InputTouchStart() {
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Config touch panel
+ */
+static int InputTouchConfig(const char *path,
+ int resolution_h, int resolution_v) {
+ if (NULL == path) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ if (-1 == ::access(path, F_OK)) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Get touch panel device name
+ */
+static int InputTouchGetDeviceName(char* name, size_t buf_length) {
+ if (NULL == name) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ if (buf_length < (strlen(HAL_INPUT_ILITEK_TOUCH_DEVICE_NAME) + 1)) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ snprintf(name, buf_length, "%s", HAL_INPUT_ILITEK_TOUCH_DEVICE_NAME);
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Get touch panel key device name
+ */
+static int InputTouchGetKeyName(char* name, size_t buf_length) {
+ if (NULL == name) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ if (buf_length < (strlen(HAL_INPUT_ILITEK_KEY_DEVICE_NAME) + 1)) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ snprintf(name, buf_length, "%s", HAL_INPUT_ILITEK_KEY_DEVICE_NAME);
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Get touch panel device horizontal resolution
+ */
+static int InputTouchGetDeviceHResolution(int *resolution) {
+ if (NULL == resolution) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ *resolution = HAL_INPUT_TOUCH_RESOLUTION_HORIZONTAL;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Get touch panel device vertical resolution
+ */
+static int InputTouchGetDeviceVResolution(int *resolution) {
+ if (NULL == resolution) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ *resolution = HAL_INPUT_TOUCH_RESOLUTION_VERTICAL;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Get whether X axis is inversion
+ */
+static int InputTouchGetXAxisReverse(bool* is_reverse) {
+ if (NULL == is_reverse) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ *is_reverse = false;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Get whether Y axis is inversion
+ */
+static int InputTouchGetYAxisReverse(bool* is_reverse) {
+ if (NULL == is_reverse) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ *is_reverse = false;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Execute touch panel self test
+ */
+static int InputTouchSelftest(int id, void *result) {
+ if (NULL == result) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ return HAL_INPUT_RET_NOT_SUPPORT;
+}
+
+/*
+ * Get touch panel config status
+ */
+static int InputTouchGetConfigStatus(int *status) {
+ if (NULL == status) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ *status = HAL_INPUT_TOUCH_CONFIG_OFF;
+ return HAL_INPUT_RET_NORMAL;
+}
+
+/*
+ * Set whether the driver sends touch panel data or not
+ */
+static int InputTouchSetTouchLock(int lock) {
+ if ((HAL_INPUT_TOUCH_UNREPORT == lock) ||
+ (HAL_INPUT_TOUCH_REPORT == lock)) {
+ return HAL_INPUT_RET_NOT_SUPPORT;
+ }
+ return HAL_INPUT_RET_ERROR;
+}
+
+/*
+ * Suspend touch panel
+ */
+static int InputTouchSetTouchSuspend() {
+ return HAL_INPUT_RET_NOT_SUPPORT;
+}
+
+/*
+ * Set touch panel sensitivity level
+ */
+static int InputTouchSetSensitivityLevel(int level) {
+ if ((HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_LOW == level) ||
+ (HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_MIDDLE == level) ||
+ (HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_HIGH == level) ||
+ (HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_NONE == level) ) {
+ return HAL_INPUT_RET_NOT_SUPPORT;
+ }
+ return HAL_INPUT_RET_ERROR;
+}
+
+/*
+ * Get touch panel sensitivity level
+ */
+static int InputTouchGetSensitivityLevel(int *level) {
+ if (NULL == level) {
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ return HAL_INPUT_RET_NOT_SUPPORT;
+}
+
+/*
+ * Notify radio scan frequency
+ */
+static int InputTouchNotifyRadioScanFrequency(struct RadioInfoTouch *info) {
+ if (NULL == info) {
+ return HAL_INPUT_RET_ERROR;
+ }
+ return HAL_INPUT_RET_NOT_SUPPORT;
+}
+
+/*
+ * Init touch panel operation function
+ */
+int InputTouchIlitekInit(struct TouchHal *touch) {
+ touch->start = InputTouchStart;
+ touch->config = InputTouchConfig;
+ touch->get_touch_devicename = InputTouchGetDeviceName;
+ touch->get_key_devicename = InputTouchGetKeyName;
+ touch->get_reso_h = InputTouchGetDeviceHResolution;
+ touch->get_reso_v = InputTouchGetDeviceVResolution;
+ touch->get_reverse_axis_x = InputTouchGetXAxisReverse;
+ touch->get_reverse_axis_y = InputTouchGetYAxisReverse;
+ touch->selftest = InputTouchSelftest;
+ touch->get_config_status = InputTouchGetConfigStatus;
+ touch->set_touch_lock = InputTouchSetTouchLock;
+ touch->set_touch_suspend = InputTouchSetTouchSuspend;
+ touch->set_sensitivity_level = InputTouchSetSensitivityLevel;
+ touch->get_sensitivity_level = InputTouchGetSensitivityLevel;
+ touch->notify_radio_scan_frequency = InputTouchNotifyRadioScanFrequency;
+ return HAL_INPUT_RET_NORMAL;
+}
diff --git a/hal/input_hal/src/input_udev_monitor.cpp b/hal/input_hal/src/input_udev_monitor.cpp
new file mode 100755
index 0000000..5d8cc6b
--- /dev/null
+++ b/hal/input_hal/src/input_udev_monitor.cpp
@@ -0,0 +1,566 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/prctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <libudev.h>
+#include <native_service/ns_message_center_if.h>
+
+#include "input_hal.h"
+#include "input_hal_debug.h"
+#include "input_hal_internal.h"
+#include "input_drm.h"
+#include "input_udev_monitor.h"
+
+#define HAL_INPUT_UDEVMONITOR_THREADNAME "input_hal_udevm"
+#define max_value(x, y) ((x) > (y) ? (x) : (y))
+
+#define INPUT_VIRTUAL_INPUTDEVICE_NAME "/devices/virtual" /* Virtual device name created by SwitchManager */
+
+// Enough name length to contain node name
+#define INPUT_NODE_NAME_LENGTH 256
+
+#define TRACKING_ID_NONE -1
+
+static struct InputUdevMonitorInfo g_input_udevmonitor_info;
+static HANDLE g_sender_handle;
+static bool g_input_touch_init_notify = false;
+extern char* g_app_name; /* app name */
+bool g_break_from_watch = false; /* watch thread loop break flag */
+pthread_t g_udev_monitor_thread = -1; /* udev monitor thread */
+
+static void InputUdevMonitorTouchInitFinEventSend(int result) {
+ struct TouchInitFinishInput msg;
+
+ if (g_input_touch_init_notify) {
+ return;
+ }
+
+ if (NULL == g_sender_handle) {
+ g_sender_handle = McOpenSender(g_app_name);
+ }
+ msg.result = result;
+
+ InputUtilMCSend(
+ g_sender_handle, HAL_INPUT_SOURCE_NAME,
+ HAL_INPUT_NOTIFY_TOUCH_INIT_FINISH, sizeof(msg), &msg);
+ g_input_touch_init_notify = true;
+}
+
+static void InputUdevMonitorInputEventHandle(int fd, int device_type, int notify_id) {
+ ssize_t read_size;
+ struct EventsPackageInput events = {0};
+
+ read_size = read(fd, events.event, sizeof(events.event));
+ if (read_size > 0) {
+ events.count = read_size / sizeof(struct input_event);
+ events.device_type = device_type;
+
+ if (NULL == g_sender_handle) {
+ g_sender_handle = McOpenSender(g_app_name);
+ }
+
+ InputUtilMCSend(
+ g_sender_handle, HAL_INPUT_SOURCE_NAME,
+ notify_id, sizeof(events), &events);
+ }
+}
+
+static void InputUdevMonitorTouchEventHandle(int fd, int notify_id) {
+ ssize_t read_size;
+ struct input_event event[HAL_INPUT_EVENT_COUNT] = {0};
+ int touch_status;
+
+ read_size = read(fd, event, sizeof(event));
+
+ if (read_size > 0) {
+ if (NULL == g_sender_handle) {
+ g_sender_handle = McOpenSender(g_app_name);
+ }
+
+ int event_num = read_size / sizeof(struct input_event);
+
+ for (int index = 0; index < event_num; ++index) {
+ if (EV_ABS == event[index].type) {
+ if (event[index].code == ABS_MT_TRACKING_ID) {
+ if (TRACKING_ID_NONE == event[index].value) {
+ touch_status = HAL_INPUT_TOUCH_RELEASE;
+ } else {
+ touch_status = HAL_INPUT_TOUCH_PRESS;
+ }
+ InputUtilMCSend(
+ g_sender_handle, HAL_INPUT_SOURCE_NAME,
+ notify_id, sizeof(touch_status), &touch_status);
+ }
+ }
+ }
+ }
+}
+
+static int InputUdevMonitorDeviceAssort(struct udev_device *dev) {
+ const char *property;
+
+ char touch_key_device_name[INPUT_NODE_NAME_LENGTH] = { 0 };
+ GetKeyNameTouch(touch_key_device_name, sizeof(touch_key_device_name));
+ const char *sysattr_name = udev_device_get_sysattr_value(dev, "name");
+ if ((sysattr_name) &&
+ (0 == strcmp(touch_key_device_name, sysattr_name))) {
+ INPUT_LOG_TRACE("DeviceAssort : ESC_SW\n");
+ return HAL_INPUT_DEVICE_TOUCH_ESCKEY;
+ }
+
+ char touch_device_name[INPUT_NODE_NAME_LENGTH] = { 0 };
+ GetPanelNameTouch(touch_device_name, sizeof(touch_device_name));
+ sysattr_name = udev_device_get_sysattr_value(dev, "name");
+ if ((sysattr_name) &&
+ (0 == strcmp(touch_device_name, sysattr_name))) {
+ INPUT_LOG_TRACE("DeviceAssort : Touch\n");
+ return HAL_INPUT_DEVICE_TOUCH;
+ }
+
+ property = udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
+ if ((property) && (strcmp("1", property) == 0)) {
+ INPUT_LOG_TRACE("DeviceAssort : KeyBoard\n");
+ return HAL_INPUT_DEVICE_KEYBOARD;
+ }
+
+ property = udev_device_get_property_value(dev, "ID_INPUT_TABLET");
+ if ((property) && (strcmp("1", property) == 0)) {
+ INPUT_LOG_TRACE("DeviceAssort : Tablet\n");
+ return HAL_INPUT_DEVICE_INVALID;
+ }
+
+ property = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
+ if ((property) && (strcmp("1", property) == 0)) {
+ INPUT_LOG_TRACE("DeviceAssort : Touch pad\n");
+ return HAL_INPUT_DEVICE_TABLET_FINGER;
+ }
+
+ return HAL_INPUT_DEVICE_INVALID;
+}
+
+static void InputUdevMonitorDeviceListOutput(void) {
+ struct InputUtilList *p;
+
+ INPUT_LOG_TRACE("OutputList >> start ======================\n");
+ input_list_for_each(p, &g_input_udevmonitor_info.dev_list.list) {
+ struct InputInputDeviceList *entry = input_list_entry(p, struct InputInputDeviceList, list);
+ if (NULL != entry) {
+ INPUT_LOG_TRACE("FD: %d Device=%s Assort=%d\n",
+ entry->fd, entry->device_node, entry->device_assort);
+ }
+ }
+ INPUT_LOG_TRACE("OutputList << end ======================\n");
+}
+
+static void InputUdevMonitorDeviceListDelete(const char *node) {
+ struct InputUtilList *p;
+
+ input_list_for_each(p, &g_input_udevmonitor_info.dev_list.list) {
+ struct InputInputDeviceList *entry = input_list_entry(p, struct InputInputDeviceList, list);
+ if (strcmp(node, entry->device_node) == 0) {
+ close(entry->fd);
+ InputUtilListDelete(p);
+ free(entry);
+ break;
+ }
+ }
+ InputUdevMonitorDeviceListOutput();
+}
+
+static int InputUdevMonitorDeviceListAdd(int fd, int device_assort, const char *node) {
+ int ret = HAL_INPUT_RET_NORMAL;
+ struct InputInputDeviceList *p;
+
+ p = (struct InputInputDeviceList *) malloc(sizeof(struct InputInputDeviceList));
+ if (p) {
+ p->fd = fd;
+ p->device_assort = device_assort;
+
+ if (strlen(node) < INPUT_DEVICE_NODE_LENGTH_MAX) {
+ strncpy(p->device_node, node, sizeof(p->device_node) - 1);
+ InputUdevMonitorDeviceListDelete(node);
+ InputUtilListAdd(&p->list, &g_input_udevmonitor_info.dev_list.list);
+ } else {
+ ret = HAL_INPUT_RET_ERROR;
+ }
+ } else {
+ ret = HAL_INPUT_RET_ERROR;
+ }
+
+ InputUdevMonitorDeviceListOutput();
+
+ return ret;
+}
+
+static int InputUdevMonitorInputEventGrab(const char *node, struct udev_device *dev) {
+ int fd, rtn;
+
+ InputUdevMonitorDeviceListDelete(node);
+
+ fd = open(node, O_RDONLY);
+
+ if (fd < 0) {
+ INPUT_ERROR_LOG("ERR: open %s errno=%d \n", node, errno);
+ goto err_rtn;
+ }
+
+ rtn = ioctl(fd, EVIOCGRAB, 1);
+ if (rtn) {
+ INPUT_ERROR_LOG("ERR: ioctl grab %s \n", node);
+ goto err_rtn_close;
+ }
+ INPUT_LOG_TRACE("%s Grab \n", node);
+
+ /* Backup FD */
+ rtn = InputUdevMonitorDeviceListAdd(fd, InputUdevMonitorDeviceAssort(dev), node);
+ if (rtn) {
+ goto err_rtn_close;
+ }
+
+ return HAL_INPUT_RET_NORMAL;
+
+err_rtn_close:
+ close(fd);
+err_rtn:
+ INPUT_LOG_TRACE("%s Grab impossible \n", node);
+ return HAL_INPUT_RET_ERROR;
+}
+
+static void InputUdevMonitorFDSet(int *nfds, fd_set *fds) {
+ struct InputUtilList *p;
+
+ input_list_for_each(p, &g_input_udevmonitor_info.dev_list.list) {
+ struct InputInputDeviceList *entry = input_list_entry(p, struct InputInputDeviceList, list);
+
+ switch (entry->device_assort) {
+ case HAL_INPUT_DEVICE_TOUCH_ESCKEY:
+ case HAL_INPUT_DEVICE_TOUCH:
+ case HAL_INPUT_DEVICE_KEYBOARD:
+ case HAL_INPUT_DEVICE_TABLET_FINGER:
+ FD_SET(entry->fd, fds);
+ *nfds = max_value(*nfds, entry->fd);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static void InputUdevMonitorFDHandle(fd_set *fds) {
+ struct InputUtilList *p;
+
+ input_list_for_each(p, &g_input_udevmonitor_info.dev_list.list) {
+ struct InputInputDeviceList *entry = input_list_entry(p, struct InputInputDeviceList, list);
+ if (FD_ISSET(entry->fd, fds)) {
+ int notify_id = 0;
+ switch (entry->device_assort) {
+ case HAL_INPUT_DEVICE_TOUCH_ESCKEY:
+ notify_id = HAL_INPUT_NOTIFY_ESC_KEY;
+ break;
+ case HAL_INPUT_DEVICE_TOUCH:
+ notify_id = HAL_INPUT_NOTIFY_TOUCH;
+ break;
+ case HAL_INPUT_DEVICE_KEYBOARD:
+ notify_id = HAL_INPUT_NOTIFY_KEY_BOARD;
+ break;
+ case HAL_INPUT_DEVICE_TABLET_FINGER:
+ notify_id = HAL_INPUT_NOTIFY_TABLET_FINGER;
+ break;
+ default:
+ return;
+ }
+ if (notify_id == HAL_INPUT_NOTIFY_TOUCH) {
+ InputUdevMonitorTouchEventHandle(entry->fd, notify_id);
+ } else {
+ InputUdevMonitorInputEventHandle(entry->fd, entry->device_assort, notify_id);
+ }
+ }
+ }
+}
+
+static int InputUdevMonitorInit(void) {
+ g_input_udevmonitor_info.udev = udev_new();
+ if (NULL == g_input_udevmonitor_info.udev) {
+ INPUT_ERROR_LOG("ERR: udev_new ret=%d \n", errno);
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ // create the udev monitor
+ g_input_udevmonitor_info.monitor = udev_monitor_new_from_netlink(g_input_udevmonitor_info.udev, "udev");
+ udev_monitor_filter_add_match_subsystem_devtype(g_input_udevmonitor_info.monitor, "input", NULL);
+
+ // start receiving hotplug events
+ udev_monitor_enable_receiving(g_input_udevmonitor_info.monitor);
+
+ INPUT_INIT_LIST_HEAD(&g_input_udevmonitor_info.dev_list.list)
+
+ return HAL_INPUT_RET_NORMAL;
+}
+
+static void InputUdevMonitorDeinit(void) {
+ // destroy the udev monitor
+ udev_monitor_unref(g_input_udevmonitor_info.monitor);
+ // destroy the udev object
+ udev_unref(g_input_udevmonitor_info.udev);
+
+ if (g_sender_handle != NULL) {
+ McClose(g_sender_handle);
+ g_sender_handle = NULL;
+ }
+
+ g_input_touch_init_notify = false;
+}
+
+static int InputUdevMonitorDevicesGet(void) {
+ int ret;
+ struct udev_enumerate *enumerate;
+ struct udev_list_entry *devices, *dev_list_entry;
+ char touch_device_name[INPUT_NODE_NAME_LENGTH] = { 0};
+ const char* sysattr_name;
+ bool input_touch_device_found = false;
+
+ // Create a list of the devices in the 'usb_device' subsystem.
+ enumerate = udev_enumerate_new(g_input_udevmonitor_info.udev);
+ udev_enumerate_add_match_subsystem(enumerate, "input");
+ udev_enumerate_scan_devices(enumerate);
+ devices = udev_enumerate_get_list_entry(enumerate);
+ GetPanelNameTouch(touch_device_name, sizeof(touch_device_name));
+
+ // Enumerate device list
+ udev_list_entry_foreach(dev_list_entry, devices) {
+ const char *path, *node;
+
+ // Get the filename of the /sys entry for the device and create a udev_device object (dev) representing it
+ path = udev_list_entry_get_name(dev_list_entry);
+ struct udev_device* dev = udev_device_new_from_syspath(g_input_udevmonitor_info.udev, path);
+ if (NULL == dev) continue;
+
+ // usb_device_get_devnode() returns the path to the device node itself in /dev.
+ node = udev_device_get_devnode(dev);
+ if (!node) {
+ udev_device_unref(dev);
+ continue;
+ }
+
+ // Filter device name is eventX
+ if (strncmp("event", udev_device_get_sysname(dev), sizeof("event") -1) != 0) {
+ udev_device_unref(dev);
+ continue;
+ }
+
+ // virtual device
+ if (strncmp(INPUT_VIRTUAL_INPUTDEVICE_NAME, udev_device_get_devpath(dev),
+ sizeof(INPUT_VIRTUAL_INPUTDEVICE_NAME) - 1) == 0) {
+ INPUT_LOG_TRACE("Found Virtual Device : %s \n", node);
+ udev_device_unref(dev);
+ continue;
+ }
+
+ // check parent is input
+ struct udev_device* input_dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL);
+ if (NULL == input_dev) {
+ udev_device_unref(dev);
+ continue;
+ }
+
+ sysattr_name = udev_device_get_sysattr_value(input_dev, "name");
+ if (NULL == sysattr_name) {
+ INPUT_ERROR_LOG("ERR: Unable to find sysattr \n");
+ udev_device_unref(dev);
+ continue;
+ }
+
+ // touchpanel device
+ if (0 == strcmp(touch_device_name, sysattr_name)) {
+ INPUT_LOG_TRACE("Found %s : %s \n", touch_device_name, path);
+ int spec_reso_h;
+ int spec_reso_v;
+ GetPanelSpecResolutionInput(&spec_reso_h, &spec_reso_v);
+ ret = ConfigTouch(udev_device_get_syspath(input_dev),
+ spec_reso_h, spec_reso_v);
+
+ if (HAL_INPUT_RET_NORMAL == ret) {
+ int status;
+ ret = GetConfigStatusTouch(&status);
+ if (HAL_INPUT_RET_NORMAL == ret) {
+ if (HAL_INPUT_TOUCH_CONFIG_OFF == status) {
+ InputUdevMonitorTouchInitFinEventSend(HAL_INPUT_RET_NORMAL);
+ }
+ } else {
+ INPUT_ERROR_LOG("GetConfigStatusTouch fail\n");
+ InputUdevMonitorTouchInitFinEventSend(HAL_INPUT_RET_ERROR);
+ }
+ } else {
+ INPUT_ERROR_LOG("ConfigTouch fail\n");
+ InputUdevMonitorTouchInitFinEventSend(HAL_INPUT_RET_ERROR);
+ }
+
+ input_touch_device_found = true;
+ }
+
+ INPUT_LOG_TRACE("Found Device : %s \n", node);
+
+ /* Modified not to notify input events to other processes */
+ InputUdevMonitorInputEventGrab(node, input_dev);
+
+ udev_device_unref(dev);
+ } // end foreach
+
+ if (!input_touch_device_found) {
+ INPUT_ERROR_LOG("ERR: Dummy Device Create");
+ InputUdevMonitorTouchInitFinEventSend(HAL_INPUT_RET_NORMAL);
+ }
+
+ // Free the enumerator object
+ udev_enumerate_unref(enumerate);
+
+ return HAL_INPUT_RET_NORMAL;
+}
+
+static void InputUdevMonitorDeviceStatusChange(int fd, fd_set *fds) {
+ if (FD_ISSET(fd, fds)) {
+ // receive the relevant device
+ struct udev_device* dev = udev_monitor_receive_device(g_input_udevmonitor_info.monitor);
+ if (NULL == dev) return;
+
+ // input_udev_DevicesGet(udm);
+ const char* action = udev_device_get_action(dev);
+ const char* node = udev_device_get_devnode(dev);
+ if ((!action) || (!node)) {
+ udev_device_unref(dev);
+ return;
+ }
+
+ if (strncmp("event", udev_device_get_sysname(dev), sizeof("event") -1) != 0) {
+ INPUT_LOG_TRACE("not event device %s \n", udev_device_get_sysname(dev));
+ udev_device_unref(dev);
+ return;
+ }
+
+ if (strncmp(INPUT_VIRTUAL_INPUTDEVICE_NAME, udev_device_get_devpath(dev),
+ sizeof(INPUT_VIRTUAL_INPUTDEVICE_NAME) - 1) == 0) {
+ udev_device_unref(dev);
+ return;
+ }
+
+ if (strcmp(action, "remove") == 0) {
+ InputUdevMonitorDeviceListDelete(node);
+ }
+
+ struct udev_device* input_dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL);
+ if (NULL == input_dev) {
+ udev_device_unref(dev);
+ return;
+ }
+ char touch_device_name[INPUT_NODE_NAME_LENGTH] = { 0};
+ GetPanelNameTouch(touch_device_name, sizeof(touch_device_name));
+ const char *sysattr_name = udev_device_get_sysattr_value(input_dev, "name");
+ if (NULL == sysattr_name) {
+ INPUT_ERROR_LOG("ERR: Unable to find sysattr \n");
+ udev_device_unref(dev);
+ return;
+ }
+
+ if (0 == strcmp(touch_device_name, sysattr_name)) {
+ if (strcmp(action, "remove") == 0) {
+ } else {
+ INPUT_LOG_TRACE("Found %s \n", touch_device_name);
+ InputUdevMonitorTouchInitFinEventSend(HAL_INPUT_RET_NORMAL);
+ }
+ }
+
+ INPUT_LOG_TRACE("%s : %s \n", node, action);
+ if (strcmp(action, "remove") == 0) {
+ } else {
+ /* Modified not to notify input events to other processes */
+ InputUdevMonitorInputEventGrab(node, input_dev);
+ }
+ udev_device_unref(dev);
+ }
+}
+
+static void InputUdevMonitorWatch(void) {
+ fd_set fds;
+ int fd = udev_monitor_get_fd(g_input_udevmonitor_info.monitor);
+
+ if (fd != -1) {
+ while (!g_break_from_watch) {
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ int nfds = max_value(0, fd);
+
+ InputUdevMonitorFDSet(&nfds, &fds);
+
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100 * 1000;
+ int ret = select(nfds + 1, &fds, NULL, NULL, &timeout);
+ if (ret > 0) {
+ InputUdevMonitorDeviceStatusChange(fd, &fds);
+
+ InputUdevMonitorFDHandle(&fds);
+ }
+ }
+ } else {
+ INPUT_ERROR_LOG("ERR: udev_monitor_get_fd");
+ }
+}
+
+static void *InputUdevMonitorMain(void * arg) {
+ int rtn;
+ prctl(PR_SET_NAME, HAL_INPUT_UDEVMONITOR_THREADNAME);
+
+ rtn = InputUdevMonitorInit();
+ if (rtn != HAL_INPUT_RET_NORMAL) {
+ goto err_rtn;
+ }
+
+ /* Get input device */
+ InputUdevMonitorDevicesGet();
+
+ /* Input device monitoring (basically never get out from here) */
+ InputUdevMonitorWatch();
+
+ InputUdevMonitorDeinit();
+
+ return NULL;
+
+err_rtn:
+ INPUT_LOG_TRACE("pthread_detach\n");
+ return NULL;
+}
+
+int32_t InputUdevMonitorThreadCreate(void) {
+ int ret;
+
+ ret = pthread_create(&g_udev_monitor_thread, NULL, InputUdevMonitorMain, NULL);
+ if (ret != 0) {
+ INPUT_ERROR_LOG("ERR: pthread_create =%d\n", errno);
+ return HAL_INPUT_RET_ERROR;
+ }
+
+ return HAL_INPUT_RET_NORMAL;
+}
diff --git a/hal/input_hal/src/input_util.cpp b/hal/input_hal/src/input_util.cpp
new file mode 100755
index 0000000..bb349eb
--- /dev/null
+++ b/hal/input_hal/src/input_util.cpp
@@ -0,0 +1,77 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "input_util.h"
+
+#include <native_service/ns_message_center_if.h>
+#include <stdio.h>
+
+#include "input_hal.h"
+#include "input_hal_debug.h"
+
+#define INPUT_UTIL_MESSAGE_SEND_RETRY 3
+#define INPUT_UTIL_MESSAGE_SEND_WAIT 10000 /* RetryWait:10ms */
+/*
+ * InputUtilListAdd
+ */
+void InputUtilListAdd(struct InputUtilList *node_new, struct InputUtilList *node_head) {
+ node_new->prev = node_head;
+ node_new->next = node_head->next;
+ node_head->next = node_new;
+ node_new->next->prev = node_new;
+}
+
+/*
+ * InputUtilListDelete
+ */
+void InputUtilListDelete(struct InputUtilList *node) {
+ node->prev->next = node->next;
+ node->next->prev = node->prev;
+}
+
+/*
+ * InputUtilMCSend
+ */
+int InputUtilMCSend(HANDLE h_message, PCSTR source, UI_32 cmd, UI_32 length, PCVOID data) {
+ int i = 0;
+ EFrameworkunifiedStatus e_status; /* return value */
+
+ do {
+ e_status = McSend(h_message, source, cmd, length, data);
+ if (eFrameworkunifiedStatusOK == e_status) {
+ break;
+ }
+ InputUtilSleep(INPUT_UTIL_MESSAGE_SEND_WAIT);
+ } while (i++ < INPUT_UTIL_MESSAGE_SEND_RETRY);
+
+ if (e_status != eFrameworkunifiedStatusOK) {
+ INPUT_ERROR_LOG("ERR: MessageSend=%d \n", e_status);
+ }
+
+ return e_status;
+}
+
+/*
+ * InputUtilSleep
+ */
+int InputUtilSleep(int usec) {
+ struct timespec req;
+
+ req.tv_sec = 0;
+ req.tv_nsec = usec * 1000;
+ nanosleep(&req, NULL);
+
+ return HAL_INPUT_RET_NORMAL;
+}
diff --git a/hal/nv_hal/LICENSE b/hal/nv_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/nv_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/nv_hal/Makefile b/hal/nv_hal/Makefile
new file mode 100755
index 0000000..2f2d89f
--- /dev/null
+++ b/hal/nv_hal/Makefile
@@ -0,0 +1,65 @@
+#
+# @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libnv_hal.so
+
+HEADER := hal_api/nv_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+
+RPATH :=
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+######### source files ##########################
+VPATH := src
+OBJS := nv_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/nv_hal/hal_api/nv_hal.h b/hal/nv_hal/hal_api/nv_hal.h
new file mode 100755
index 0000000..2014754
--- /dev/null
+++ b/hal/nv_hal/hal_api/nv_hal.h
@@ -0,0 +1,245 @@
+/*
+ * @copyright Copyright(c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_NV_HAL_H_
+#define HAL_API_NV_HAL_H_
+
+#include <stdint.h>
+#include <native_service/frameworkunified_types.h>
+
+/**
+ * @file nv_hal.h
+ * @brief This file provides API for accessing storage device.
+ */
+
+/** @addtogroup backup_manager
+ * @{
+ */
+/** @addtogroup nv_hal
+ * @ingroup backup_manager
+ * @{
+ */
+
+/**
+ * \~english NvHalMedia
+ */
+enum NvHalMedia {
+ /**
+ * \~english CacheDram
+ */
+ NVHALMEDIA_CACHEDRAM = 0,
+ /**
+ * \~english BackupDram
+ */
+ NVHALMEDIA_BACKUPDRAM,
+ /**
+ * \~english nand
+ */
+ NVHALMEDIA_NAND,
+ /**
+ * \~english Max
+ */
+ NVHALMEDIA_MAX
+};
+
+/**\ingroup InitNv
+ * \~english @par Brief
+ * Initialize Nv hal library.
+ * \~english @retval eFrameworkunifiedStatusOK : succsess initialize.
+ * \~english @retval eFrameworkunifiedStatusFail : fail initialize
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Initialization processing failure.[eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Perform Nv_hal library initialization.
+ * - This process also performs deletion of temporary files accompanying system reset\n
+ * during write processing.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * - None
+ */
+EFrameworkunifiedStatus InitNv(void);
+
+/**\ingroup GetSizeNv
+ * \~english @par Brief
+ * This API get data size which is stored in storage device.
+ * \~english @param [in] media
+ * enum NvHalMedia - Media type
+ * \~english @param [in] filename
+ * const char* - file name(Concatenated[category name/item name])
+ * \~english @param [out] size
+ * uint32_t - Data size
+ * \~english @par
+ * - Get decrypted data size as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
+ * - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
+ * - Encryption data : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusFileLoadError File not exists
+ * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter media is less than NVHALMEDIA_CACHEDRAM or greater than\n
+ * NVHALMEDIA_NAND. [eFrameworkunifiedStatusInvldParam]
+ * - Parameter id is NULL. [eFrameworkunifiedStatusInvldParam]
+ * - Value of parameter size is 0. [eFrameworkunifiedStatusInvldParam]
+ * - Internal IO error(lstat).[eFrameworkunifiedStatusFileLoadError]
+ * \~english @par Detail
+ * - This API get the data size according to specified media and ID.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see WriteNv ReadNv
+ */
+EFrameworkunifiedStatus GetSizeNv(enum NvHalMedia media, const char *filename, uint32_t* size);
+
+
+
+/**\ingroup ReadNv
+ * \~english @par Brief
+ * Read data from storage device.
+ * \~english @param [in] media
+ * enum NvHalMedia - Media type
+ * \~english @param [in] filename
+ * const char* - file name(Concatenated[category name/item name])
+ * \~english @param [out] buffer
+ * uint8_t* - Buffer for storing read data
+ * \~english @param [in] size
+ * uint32_t - Data size
+ * \~english @par
+ * - Decrypt and read data as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
+ * - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
+ * - Encryption data : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
+ * \~english @retval eFrameworkunifiedStatusFail Read data failed
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter media is less than NVHALMEDIA_CACHEDRAM or greater than\n
+ * NVHALMEDIA_NAND. [eFrameworkunifiedStatusInvldParam]
+ * - Parameter id is NULL. [eFrameworkunifiedStatusInvldParam]
+ * - Parameter buffer is NULL. [eFrameworkunifiedStatusInvldParam]
+ * - Value of parameter size is 0. [eFrameworkunifiedStatusInvldParam]
+ * - Internal IO error(open, pread, lstat, close).[eFrameworkunifiedStatusFail]
+ * - The value of parameter size is not equal to the file size specified by id.
+ * [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - This API reads data according to specified media and ID.
+ * - ID is managed by backup_manager.For details, refer to "Details about XML file" in external specification of backup_manager.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see CheckNv WriteNv
+ */
+EFrameworkunifiedStatus ReadNv(enum NvHalMedia media, const char *filename, uint8_t *buffer, uint32_t size);
+
+/**\ingroup WriteNv
+ * \~english @par Brief
+ * Write data to storage device.
+ * \~english @param [in] media
+ * enum NvHalMedia - Media type
+ * \~english @param [in] filename
+ * const char* - filename(Concatenated[category name/item name])
+ * \~english @param [in] buffer
+ * uint8_t* - Buffer for storing written data
+ * \~english @param [in] size
+ * uint32_t - Data size
+ * \~english @par
+ * - Encrypt and write data as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
+ * - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
+ * - Encryption data : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
+ * \~english @retval eFrameworkunifiedStatusFail Write data failed
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter media is less than NVHALMEDIA_CACHEDRAM or greater than\n
+ * NVHALMEDIA_NAND. [eFrameworkunifiedStatusInvldParam]
+ * - Parameter id is NULL. [eFrameworkunifiedStatusInvldParam]
+ * - Parameter buffer is NULL. [eFrameworkunifiedStatusInvldParam]
+ * - Value of parameter size is 0. [eFrameworkunifiedStatusInvldParam]
+ * - Internal IO error(open, pwrite, close, mkdir).[eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - This API writes data according to specified media and ID.
+ * - filename is managed by backup_manager.For details, refer to "Details about XML file" in external specification of backup_manager.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see CheckNv ReadNv
+ */
+EFrameworkunifiedStatus WriteNv(enum NvHalMedia media, const char *filename, uint8_t *buffer, uint32_t size);
+
+/**\ingroup DeleteNv
+ * \~english @par Brief
+ * Delete data which is stored in storage device.
+ * \~english @param [in] media
+ * enum \ref NvHalMedia - Media type
+ * \~english @param [in] filename
+ * const char* - filename(Concatenated[category name/item name])
+ * \~english @par
+ * - Delete data as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
+ * - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
+ * - Encryption data : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
+ * \~english @retval eFrameworkunifiedStatusFail Delete data failed
+ * \~english @par Preconditions
+ * - There is no preconditions for this API.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter media is less than \ref NVHALMEDIA_CACHEDRAM or greater than\n
+ * \ref NVHALMEDIA_NAND . [eFrameworkunifiedStatusInvldParam]
+ * - Parameter filename (filename) is NULL. [eFrameworkunifiedStatusInvldParam]
+ * - Internal IO error.[eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - This API delete data according to specified media and filename.
+ * - This API delete encryption key if data is encrypted.
+ * - filename is managed by backup_manager.For details, refer to "Details about XML file" in external specification of backup_manager.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see GetSizeNv ReadNv WriteNv
+ */
+EFrameworkunifiedStatus DeleteNv(enum NvHalMedia media, const char *filename);
+
+/** @}*/ // end of nv_hal
+/** @}*/ // end of backup_manager
+
+#endif // HAL_API_NV_HAL_H_
diff --git a/hal/nv_hal/inc/nv_hal_nvhallog.h b/hal/nv_hal/inc/nv_hal_nvhallog.h
new file mode 100755
index 0000000..d62bd88
--- /dev/null
+++ b/hal/nv_hal/inc/nv_hal_nvhallog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_NV_HAL_NVHALLOG_H_
+#define INC_NV_HAL_NVHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_NV_HAL_NVHALLOG_H_
diff --git a/hal/nv_hal/src/nv_hal.cpp b/hal/nv_hal/src/nv_hal.cpp
new file mode 100755
index 0000000..d746ea0
--- /dev/null
+++ b/hal/nv_hal/src/nv_hal.cpp
@@ -0,0 +1,242 @@
+/*
+ * @copyright Copyright(c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "nv_hal.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <aglpath.h>
+#include <sys/syscall.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "nv_hal_nvhallog.h"
+
+/**
+ * Media type difine.
+ */
+const char *kMediaType[NVHALMEDIA_MAX] = {
+ "/tmp/bkup/",
+ "/ramd/BS/ns/backup_manager/rwdata/",
+ "/nv/BS/ns/backup_manager/rwdata/",
+};
+
+const int kMaxPath = 127; // Max length of path
+
+/**
+ * Initialize Nv hal
+ */
+EFrameworkunifiedStatus InitNv(void) {
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * Get data size.
+ */
+EFrameworkunifiedStatus GetSizeNv(enum NvHalMedia media, const char *filename, uint32_t *size) {
+ if ((media < NVHALMEDIA_CACHEDRAM) || (media > NVHALMEDIA_NAND)) { // Argument range checking
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "invalid media type:%d\n", media);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == filename) { // NULL checking of arguments
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "filename is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == size) { // NULL checking of arguments
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "size is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ char path[kMaxPath];
+ memset(path, '\0', kMaxPath);
+ snprintf(path, kMaxPath, "%s%s", kMediaType[media], filename);
+ // Geting the file size
+ struct stat file_stat;
+ if (0 > lstat(path, &file_stat)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "lstat() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFileLoadError;
+ }
+ *size = file_stat.st_size;
+ return eFrameworkunifiedStatusOK;
+}
+
+
+
+/**
+ * Reading data from memory device.
+ */
+EFrameworkunifiedStatus ReadNv(enum NvHalMedia media, const char *filename, uint8_t *buffer, uint32_t size) {
+ if ((media < NVHALMEDIA_CACHEDRAM) || (media > NVHALMEDIA_NAND)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "invalid media type:%d\n", media);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == filename) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "filename is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == buffer) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "buffer is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (0 == size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "invalid size:%d\n", size);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ char path[kMaxPath];
+ memset(path, '\0', kMaxPath);
+ snprintf(path, kMaxPath, "%s%s", kMediaType[media], filename);
+ struct stat file_stat;
+ if (0 > lstat(path, &file_stat)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "lstat() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ if (file_stat.st_size != size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "size error:%ld != %d\n", file_stat.st_size, size);
+ return eFrameworkunifiedStatusFail;
+ }
+ int fd = open(path, O_RDONLY);
+ if (-1 == fd) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open(%s) error, errno=%d\n", path, errno);
+ return eFrameworkunifiedStatusFail;
+ } else {
+ size_t tot_read;
+ // Read data by support EINTR
+ for (tot_read = 0; tot_read < static_cast<size_t>(size);) {
+ ssize_t read_size = pread(fd, &buffer[tot_read], static_cast<size_t>(size) - tot_read, tot_read);
+ if (-1 == read_size) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "pread() error, errno=%d\n", errno);
+ if (0 != close(fd)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "close() error, errno=%d\n", errno);
+ }
+ return eFrameworkunifiedStatusFail;
+ }
+ }
+ tot_read += read_size;
+ }
+ if (0 != close(fd)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "close() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * Writing data to memory device.
+ */
+EFrameworkunifiedStatus WriteNv(enum NvHalMedia media, const char *filename, uint8_t *buffer, uint32_t size) {
+ if ((media < NVHALMEDIA_CACHEDRAM) || (media > NVHALMEDIA_NAND)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "invalid media type:%d\n", media);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == filename) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "filename is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == buffer) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "buffer is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (0 == size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "invalid size:%d\n", size);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ char path[kMaxPath];
+ memset(path, '\0', kMaxPath);
+ snprintf(path, kMaxPath, "%s%s", kMediaType[media], filename);
+ struct stat file_stat;
+ // Check file exists or not, mkdir first if file no exists.
+ if (0 > lstat(path, &file_stat)) {
+ char *dir_point = path;
+ char dir_buff[kMaxPath];
+ dir_point++;
+ while ((dir_point = strchr(dir_point, '/'))) {
+ memset(dir_buff, '\0', kMaxPath);
+ memcpy(dir_buff, path, dir_point - path);
+ if (0 > mkdir(dir_buff, 0770)) {
+ if (EEXIST != errno) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "mkdir() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFail;
+ } else {
+ dir_point++;
+ continue;
+ }
+ }
+ dir_point++;
+ }
+ }
+ int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0660);
+ if (-1 == fd) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open(%s) error, errno=%d\n", path, errno);
+ return eFrameworkunifiedStatusFail;
+ } else {
+ size_t tot_written;
+ // Write data by support EINTR
+ for (tot_written = 0; tot_written < static_cast<size_t>(size);) {
+ ssize_t write_size = pwrite(fd, &buffer[tot_written], static_cast<size_t>(size) - tot_written, tot_written);
+ if (0 >= write_size) {
+ if (-1 == write_size && errno == EINTR) {
+ continue;
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "pwrite() error, errno=%d\n", errno);
+ if (0 != close(fd)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "close() error, errno=%d\n", errno);
+ }
+ return eFrameworkunifiedStatusFail;
+ }
+ }
+ tot_written += write_size;
+ }
+ if (0 != close(fd)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "close() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * Delete data.
+ */
+EFrameworkunifiedStatus DeleteNv(enum NvHalMedia media, const char *filename) {
+ if ((media < NVHALMEDIA_CACHEDRAM) || (media > NVHALMEDIA_NAND)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "invalid media type:%d\n", media);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == filename) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "filename is NULL.\n");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ char path[kMaxPath];
+ memset(path, '\0', kMaxPath);
+ snprintf(path, kMaxPath, "%s%s", kMediaType[media], filename);
+ struct stat file_stat;
+
+ if (0 > lstat(path, &file_stat)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "lstat() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ if (0 != unlink(path)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unlink() error, errno=%d\n", errno);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
diff --git a/hal/positioning_hal/LICENSE b/hal/positioning_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/positioning_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/positioning_hal/Makefile b/hal/positioning_hal/Makefile
new file mode 100755
index 0000000..0b5a74d
--- /dev/null
+++ b/hal/positioning_hal/Makefile
@@ -0,0 +1,91 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libpositioning_hal.so
+
+HEADER := hal_api/gps_hal.h hal_api/positioning_hal.h
+
+######### include paths/files ###################
+CXXFLAGS += -I.
+CXXFLAGS += -I./inc/Common
+CXXFLAGS += -I./inc/GpsCommon
+CXXFLAGS += -I./inc/LineSensDrv
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include/
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+CXXFLAGS += -DLINUX -D__CWORD71__VEHICLE_ -D__CWORD71_
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH := /usr/lib
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+#LIBS += -Wl,-Bdynamic -lgps_mng
+LIBS += -Wl,-Bdynamic -lPOS_base_API
+LIBS += -Wl,-Bdynamic -lns_backup
+
+######### source files ##########################
+VPATH := src/Common
+VPATH += src/GpsCommon
+VPATH += src/LineSensDrv
+
+OBJS += positioning_common.o
+OBJS += positioning_hal.o
+OBJS += MDev_Gps_API.o
+OBJS += MDev_Gps_Main.o
+OBJS += MDev_GpsRecv.o
+OBJS += MDev_Gps_Nmea.o
+OBJS += MDev_Gps_Common.o
+OBJS += MDev_Gps_Mtrx.o
+OBJS += MDev_Gps_TimerCtrl.o
+OBJS += LineSensDrv_Sensor.o
+OBJS += LineSensDrv_Thread.o
+OBJS += LineSensDrv_Api.o
+OBJS += MDev_GpsRollOver.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=:$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
+
+
diff --git a/hal/positioning_hal/README.md b/hal/positioning_hal/README.md
new file mode 100755
index 0000000..2d46d42
--- /dev/null
+++ b/hal/positioning_hal/README.md
@@ -0,0 +1,3 @@
+positioning_hal library
+==================
+Positioning HAL implementation library for AGL Reference Board.
diff --git a/hal/positioning_hal/hal_api/gps_hal.h b/hal/positioning_hal/hal_api/gps_hal.h
new file mode 100755
index 0000000..3321275
--- /dev/null
+++ b/hal/positioning_hal/hal_api/gps_hal.h
@@ -0,0 +1,932 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_GPS_HAL_H_
+#define HAL_API_GPS_HAL_H_
+
+/**
+ * @file gps_hal.h
+ */
+
+/** @addtogroup positioning
+ * @{
+ */
+/** @addtogroup positioning_hal
+ * @ingroup positioning
+ * @{
+ */
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include <native_service/frameworkunified_types.h>
+#include <vehicle_service/pos_message_header.h>
+#include <vehicle_service/std_types.h>
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+typedef int32 RET_API;
+typedef uint32_t DID;
+
+/*************************************************************************
+ * RET_API define
+ *************************************************************************/
+/*--- for message ---*/
+#define POS_TIMESTS_NG 0x00
+//!< \~english time has not been adjusted after GPS receiver reset(time input or master reset or CSF start)
+#define POS_TIMESTS_RTC 0x01
+//!< \~english time output from RTC Backup(have time adjustment)
+#define POS_TIMESTS_OK 0x02 //!< \~english time adjustment completed
+
+/* command ID */
+#define CID_POSIF_REGISTER_LISTENER_GPS_TIME 0x0201
+//!< \~english GPS time delivery command ID
+
+#define POS_DID_GPS__CWORD82__SETINITIAL 0x80000033
+//!< \~english data ID of setting initial location and time to GPS
+
+#define POS_DID_GPS__CWORD82__SETRMODEEX 0x80000035
+//!< \~english data ID of setting GPS receiver mode(pull extension sentence)
+
+#define POS_DID_GPS__CWORD82__SELSENT 0x80000036
+//!< \~english data ID of setting command to GPS that output any sentence
+
+/* NAVIINFO_RET_API */
+#define NAVIINFO_RET_NORMAL (0) //!< \~english normal finish
+#define NAVIINFO_RET_ERROR_PARAM (-1) //!< \~english parameter error
+#define NAVIINFO_RET_ERROR_INNER (-2) //!< \~english internal error
+#define NAVIINFO_RET_ERROR_BUFFULL (-3) //!< \~english buffer full
+#define NAVIINFO_RET_ERROR_NOSUPPORT (-4) //!< \~english no support
+#define NAVIINFO_RET_ERROR_RESOURCE (-5) //!< \~english lack of resource
+
+/* Positioning Level/GPS Information Positioning Status Information Definition */
+#define NAVIINFO_DIAG_GPS_FIX_STS_NON (0) //!< \~english position not fix
+#define NAVIINFO_DIAG_GPS_FIX_STS_2D (1) //!< \~english 2D position fix
+#define NAVIINFO_DIAG_GPS_FIX_STS_3D (2) //!< \~english 3D position fix
+
+/* Reception status definition */
+#define NAVIINFO_DIAG_GPS_RCV_STS_NOTUSE (0) //!< \~english not used
+#define NAVIINFO_DIAG_GPS_RCV_STS_SEARCHING (1) //!< \~english searching
+#define NAVIINFO_DIAG_GPS_RCV_STS_TRACHING (2) //!< \~english tracking
+#define NAVIINFO_DIAG_GPS_RCV_STS_NOTUSEFIX (3) //!< \~english not used for position fix
+#define NAVIINFO_DIAG_GPS_RCV_STS_USEFIX (4) //!< \~english used for position fix
+
+/* GPS Response Status Definition */
+#define GPS_SENDOK 0 //!< \~english send result OK
+#define GPS_SENDNG 1 //!< \~english send result NG
+
+/* GPS reset request mode definition */
+#define GPS_RST_COLDSTART 0xff
+//!< \~english GPS reset request(cold start)
+
+#define RET_NORMAL 0 //!< \~english normally end
+
+#define RET_RCVMSG 1 //!< \~english receive message only
+#define RET_RCVSIG 2 //!< \~english receive signal only
+#define RET_RCVBOTH 3 //!< \~english receive message and signal
+#define RET_NOMSG 4 //!< \~english receive no message
+
+#define RET_QUE 5 //!< \~english insert signal
+#define RET_NOTQUE 6 //!< \~english do not insert signal
+#define RET_PROCDOWN 7 //!< \~english sub process down found
+#define RET_SLEEP 100 //!< \~english sleep time
+
+
+#define RET_OSERROR (-127) //!< \~english OS system call error
+
+#define RET_ERROR (-1)
+//!< \~english abnormally end(do not know reason)
+#define RET_ERRPARAM (-2) //!< \~english parameter error
+#define RET_ERRNOTRDY (-3)
+//!< \~english port or semphore ID is not created
+#define RET_ERRPROC (-4) //!< \~english error occurs in API process
+#define RET_ERRTIMEOUT (-5)
+//!< \~english timeout occurs but process unfinished
+#define RET_ERRMSGFULL (-6) //!< \~english message table full
+
+
+#define RET_ERROVERFLW (-7)
+//!< \~english message size exceeds receive buffer size
+
+#define RET_ERRINIT (-8) //!< \~english abnormally initialization
+
+#define RET_EV_NONE (-20) //!< \~english event does not exist
+#define RET_EV_MAX (-21) //!< \~english event value exceeds max value
+#define RET_EV_MIN (-22)
+//!< \~english event value is lower than min value
+
+/* POS_RET_API */
+#define POS_RET_NORMAL 0 //!< \~english normal finish
+#define POS_RET_ERROR (-1) //!< \~english error occured
+#define POS_RET_ERROR_DID (-2) //!< \~english data ID error
+#define POS_RET_ERROR_INNER (-3) //!< \~english internal error
+#define POS_RET_ERROR_PARAM (-4) //!< \~english parameter error
+#define POS_RET_ERROR_BUFFULL (-5) //!< \~english buffer full error
+#define POS_RET_ERROR_CREATE_EVENT (-6) //!< \~english create event error
+#define POS_RET_ERROR_OUTOF_MEMORY (-8)
+//!< \~english share memory allocation size error
+
+#define POS_RET_ERROR_SIZE (-9) //!< \~english memory size error
+#define POS_RET_ERROR_TIMEOUT (-10) //!< \~english timeout error
+#define POS_RET_ERROR_NOSUPPORT (-11) //!< \~english no support
+#define POS_RET_ERROR_BUSY (-12) //!< \~english busy
+#define POS_RET_ERROR_RESOURCE (-13) //!< \~english lack of resources
+#define POS_RET_ERROR_MIN (-13) //!< \~english min value of error
+
+
+#define NUM_OF_100msData (10)
+//!< \~english number of gyro data every 100ms
+
+
+#define CID_GPS_SERIAL1 (CID)0x0101
+//!< \~english Defination of notification about Gps Data has been receiced
+
+#define CID_GPS_SERIAL2 (CID)0x0102 //!< \~english notification about 1PPS interupt
+
+
+#define CID_GPS_SERIAL3 (CID)0x0103
+//!< \~english Defination of SIF2 Data
+
+#define CID_GPS_SERIAL4 (CID)0x0104
+//!< \~english Defination of _CWORD82_ command send
+
+#define CID_GPS_SERIAL5 (CID)0x0105
+//!< \~english Defination of _CWORD82_ command send
+
+#define CID_GPS_SERIAL6 (CID)0x0106
+//!< \~english Defination of u-blox request data
+
+#define CID_GPS_SERIAL7 (CID)0x0107
+//!< \~english Defination of u-blox ack data
+
+#define CID_GPS_RECVDATA (CID)(CID_GPS_BASE | CID_GPS_SERIAL1)
+//!< \~english gps data receiced CID
+
+#define CID_GPS_1PPSINT (CID)(CID_GPS_BASE | CID_GPS_SERIAL2)
+//!< \~english 1PPS interupt CID
+
+#define CID_GPS_SIF2DATA (CID)(CID_GPS_BASE | CID_GPS_SERIAL3)
+//!< \~english SIF2 Data CID
+
+/**
+ * \~english @brief _CWORD82_ command send CID
+ * \~english @brief Message structure\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message main structure @ref TgGpsSndData\n
+ * \~english @brief Message data(Vehicle sensor information setting message) structure @ref VEHICLE_MSG_SEND_DAT\n
+ */
+#define CID_GPS__CWORD82__REQUEST (CID)(CID_GPS_BASE | CID_GPS_SERIAL4)
+
+#define CID_GPS_CYCLEDATA_PROV (CID)(CID_GPS_BASE | CID_GPS_SERIAL5)
+//!< \~english Gps cycle data CID
+
+#define CID_GPS_RCV_REQUESTDATA (CID)(CID_GPS_BASE | CID_GPS_SERIAL6)
+//!< \~english u-blox request data CID
+
+#define CID_GPS_RCV_ACKDATA (CID)(CID_GPS_BASE | CID_GPS_SERIAL7)
+//!< \~english u-blox ack data CID
+
+#define CID_GPS_SERIAL8 (CID)0x0108
+//!< \~english Defination of Time Setting request
+
+#define CID_GPS_SERIAL9 (CID)0x0109
+//!< \~english Defination of Time Setting ack
+
+#define CID_GPS_SERIAL10 (CID)0x010A
+//!< \~english Defination of back up data read request
+
+#define CID_GPS_SERIAL11 (CID)0x010B
+//!< \~english Defination gps of week count request
+
+/**
+ * \~english @brief Defination of Time Setting request
+ * \~english @brief Message structure\n
+ * \~english @brief Message header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message body structure @ref TgGpsSndData\n
+ * \~english @brief Positioning information structure @ref POS_MSGINFO\n
+ * */
+#define CID_GPS_TIMESETTING (CID)(CID_GPS_BASE | CID_GPS_SERIAL8)
+
+/**
+ * \~english @brief Defination of Time Setting ack
+ * \~english @brief Message structure\n
+ * \~english @brief Message body structure @ref TG_GPS_RET_TIMESET_MSG\n
+ */
+#define CID_GPS_RETTIMESETTING (CID)(CID_GPS_BASE | CID_GPS_SERIAL9)
+
+/**
+ * \~english @brief Read backup data request CID
+ * \~english @brief When this command is received, the backup data is read.\n
+ * \~english @brief Message-Related Structures\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER
+ */
+#define CID_GPS_BACKUPDATA_LOAD (CID)(CID_GPS_BASE | CID_GPS_SERIAL10)
+
+/**
+ * \~english @brief Gps Week count request CID
+ * \~english @brief Message structure\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message data(Gps Week correction count notify message) structure @ref GpsWeekCorCntMsg\n
+ */
+#define CID_GPSWEEKCOR_CNT_NOTIFICATION (CID)(CID_GPS_BASE | CID_GPS_SERIAL11)
+
+
+
+/**
+ * \~english @brief GPS reset result delivery command ID
+ * \~english @brief If you want to catch above envents, use NSFW like below.
+ * \~english @code
+ * l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hThread, TN_POSITIONING_GPS, CID_POSIF_REQ_GPS_RESET, OnRecivePosResetMsg);
+ * @endcode
+ */
+#define CID_POSIF_REQ_GPS_RESET 0x0784
+
+#define POSHAL_DID_GPS_CONNECT_ERROR 0x800000B5U
+//!< \~english GPS receive error DID
+
+#define GPS_READ_LEN 316
+//!< \~english Gps NMEA FULLBINARY max length
+
+#define GPS_CMD_NMEA_GGA_SZ (71U) //!< \~english GGA
+#define GPS_CMD_NMEA_DGGA_SZ (75U) //!< \~english double precison GGA
+#define GPS_CMD_NMEA_VTG_SZ (37U) //!< \~english VTG
+#define GPS_CMD_NMEA_RMC_SZ (61U) //!< \~english RMC
+#define GPS_CMD_NMEA_DRMC_SZ (67U) //!< \~english double precison RMC
+#define GPS_CMD_NMEA_GLL_SZ (44U) //!< \~english GLL
+#define GPS_CMD_NMEA_DGLL_SZ (50U) //!< \~english double precison GLL
+#define GPS_CMD_NMEA_GSA_SZ (66U) //!< \~english GSA
+#define GPS_CMD_NMEA_GSV_SZ (70U) //!< \~english GSV
+#define GPS_CMD_NMEA__CWORD44__GP_3_SZ (78U) //!< \~english _CWORD44_,GP,3
+#define GPS_CMD_NMEA__CWORD44__GP_4_SZ (25U) //!< \~english _CWORD44_,GP,4
+#define GPS_CMD_NMEA_P_CWORD82_F_GP_0_SZ (50U) //!< \~english _CWORD44_,GP,0
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_1_SZ (31U) //!< \~english _CWORD44_,GP,1
+#define GPS_CMD_NMEA_P_CWORD82_I_GP_SZ (71U) //!< \~english P_CWORD82_I,GP
+#define GPS_CMD_NMEA_P_CWORD82_E_GP_0_SZ (50U) //!< \~english P_CWORD82_E,GP,0
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_0_SZ (63U) //!< \~english P_CWORD82_J,GP,0
+#define GPS_CMD_NMEA_P_CWORD82_E_GP_2_SZ (21U) //!< \~english P_CWORD82_E,GP,2
+#define GPS_CMD_NMEA_P_CWORD82_G_GP_0_SZ (34U) //!< \~english P_CWORD82_G,GP,0
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_7_SZ (37U) //!< \~english P_CWORD82_J,GP,7
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_8_SZ (45U) //!< \~english P_CWORD82_J,GP,8
+#define GPS_CMD_BINARY_SZ (81U) //!< \~english standard binary
+
+#define GPS_CMD_FULLBIN_SZ (316U)
+//!< \~english FULL binary(GPS10 format)
+
+#define GPS_CMD_FULLBIN_VINFO (30U + 160U + 25U + 8U)
+//!< \~english FULL bianry version
+
+#define GPS_NMEA_MAX_SZ (255U) //!< \~english NMEA max size
+#define GPS_DATASIZE_RTC (13U) //!< \~english RTC Data size
+#define GPS_NMEARCVSTS_SZ (1U) //!< \~english received NMEA size
+
+#define GPS_GPSANT_SZ (1U) //!< \~english gps antenna status size
+#define GPS_SNSCNT_SZ (1U) //!< \~english Sensor Count value size
+
+
+#define GPS_CMD_NMEA_PROV_SZ (GPS_CMD_NMEA_DRMC_SZ + GPS_CMD_NMEA_GSA_SZ + \
+ (GPS_CMD_NMEA_GSV_SZ*3) + GPS_CMD_NMEA__CWORD44__GP_3_SZ)
+//!< \~english NMEA size
+
+#define GPS_NMEA_SZ (GPS_NMEARCVSTS_SZ + GPS_GPSANT_SZ + GPS_SNSCNT_SZ + GPS_CMD_NMEA_PROV_SZ)
+//!< \~english NEMA size
+
+#define GPS_FULLBIN_SZ (GPS_GPSANT_SZ + GPS_SNSCNT_SZ + GPS_CMD_FULLBIN_SZ)
+//!< \~english FULLBIN size
+
+#define GPS__CWORD44_GP4_SZ (GPS_GPSANT_SZ + GPS_SNSCNT_SZ + GPS_CMD_NMEA__CWORD44__GP_4_SZ)
+//!< \~english _CWORD44_GP4 size
+
+#define GPS_MSGDATA_SZ_MAX (512U) //!< \~english message maximum data size
+#define GPS_TLGRM_LEN 253 //!< \~english message data length
+#define GPS_MSG_VSINFO_DSIZE 1904 //!< \~english message body size
+
+#define POS_MSG_INFO_DSIZE 1028 //!< \~english message body maximum size
+
+/**
+ * @enum MdevGpsDataKind
+ * \~english enumeration of gps data kind
+ */
+typedef enum MdevGpsDataKind {
+ MDEV_GPS_DATA_RAWDATA_NMEA = 0, //!< \~english raw NMEA data of GPS
+ MDEV_GPS_DATA_RAWDATA_FULLBIN, //!< \~english raw binary data of GPS
+ MDEV_GPS_DATA_RAWDATA__CWORD44_GP4, //!< \~english raw _CWORD44_ data of GPS
+ MDEV_GPS_DATA_NAVISPEED, //!< \~english speed data
+ MDEV_GPS_DATA_CUSTOMDATA, //!< \~english position information
+ MDEV_GPS_DATA_GPSTIME, //!< \~english GPS time
+ MDEV_GPS_DATA_GPSTIME_RAW, //!< \~english raw time of GPS
+ MDEV_GPS_DATA_INITIAL //!< \~english initialize data
+} MDEV_GPS_DATA_KIND;
+
+/**
+ * @struct NAVIINFO_UTCTIME
+ * \~english UTC time information structure
+ */
+typedef struct {
+ uint16_t year; //!< \~english year
+ uint8_t month; //!< \~english month
+ uint8_t date; //!< \~english day
+ uint8_t hour; //!< \~english hour
+ uint8_t minute; //!< \~english minute
+ uint8_t second; //!< \~english second
+ uint8_t reserved; //!< \~english reserve
+} NAVIINFO_UTCTIME;
+
+/**
+ * @struct SENSORLOCATION_LONLATINFO_DAT
+ * \~english longitude and latitude information data
+ * - Get method(getMethod)
+ * - SENSOR_GET_METHOD_GPS - longitude and latitude from GPS
+ * - SENSOR_GET_METHOD_NAVI - longitude and latitude from Navigation
+ * - Synchrony count(SyncCnt)
+ * - Count for position data synchronous \n
+ * When delivery altitude and heading data, position data can be synchronized by SyncCnt.\n
+ * But the data of different method can not be synchronized by SyncCnt.\n
+ * Example 1: [LonLat from GPS] and [Heading from GPS] can be synchronized by SyncCnt.\n
+ * Example 2: [LonLat from GPS] and [LonLat from Navi] can not be synchronized by SyncCnt.\n
+ * Caution: The sensor count in sensor data delivery is another data.
+ * - Enable or not(isEnable) \n
+ * To describe this delivery message is whether can be used or not
+ * - 0 - not avaliable
+ * - not 0 - avaliable
+ * - when GPS data is specified,longitude and latitude is invalid at following condition:\n
+ * so [not avaliable] provieded
+ * - After system start, GPS unit has not received current location data and GPS unit \n
+ * status is not positioning fixed.
+ * - If it is not initialized status, certainly provide [avaliable] when Navigation data specified
+ * - If the status is [not avaliable], data following can not be guaranteed.
+ * - Position status(posSts)
+ * - It is valid only when "Get method is Navigation" and "evironment is _CWORD80_".(otherwise it will be set as 0)
+ * - Bit0 : GPS data used result(1:used, 0:not used, definition of maskbit:POS_LOC_INFO_USE_GSP)
+ * - Bit1 : DGPS data used result(1:used, 0:not used, definition of maskbit:POS_LOC_INFO_USE_DGPS)
+ * - Bit3 : MapMatching data used result(1:used, 0:not used, definition of \n
+ * maskbit:POS_LOC_INFO_USE_MAPMATCHING)
+ * - Position accuracy(posAcc)
+ * - Detected accruray of current position:1LSB=1m \n
+ * - It is valid only when "Get method is Navigation" and "evironment is _CWORD80_".(otherwise it will be set as 0)\n
+ * 0000H:0m \n
+ * 0001H:1m \n
+ * :\n
+ * FFFDH:65533m \n
+ * FFFEH:65534m and larger than 65534m \n
+ * FFFFH:no data
+ * - Longitude : (WGS-84)(10^ -7degree as 1) \n
+ * East longitude is positive value and west longitude is negative value.
+ * - Latitude : (WGS-84)(10^ -7degree as 1) \n
+ * North latitude positive value and south latitude is negative value.
+ */
+typedef struct {
+ uint8_t getMethod; //!< \~english get method
+ uint8_t SyncCnt; //!< \~english Synchrony count
+ uint8_t isEnable; //!< \~english enable or not
+ uint8_t posSts; //!< \~english position status
+ uint16_t posAcc; //!< \~english position accuracy
+ int32_t Longitude; //!< \~english longitude(10^-7degree)
+ //!< \~english max: +180.0000000degree[east longitude]
+ //!< \~english min: -170.9999999degree[west longitude]
+ int32_t Latitude; //!< \~english latitude(10^-7degree)
+ //!< \~english max: +90.0000000degree[north Latitude]
+ //!< \~english min: -90.0000000degree[south Latitude]
+} SENSORLOCATION_LONLATINFO_DAT;
+
+
+/**
+ * @struct SENSORLOCATION_ALTITUDEINFO_DAT
+ * \~english altitude information data
+ * - Get method(getMethod)
+ * - SENSOR_GET_METHOD_GPS - altitude from GPS
+ * - SENSOR_GET_METHOD_NAVI - altitude from Navigation
+ * - Synchrony count(SyncCnt)
+ * - Count for position data synchronous \n
+ * When delivery altitude and heading data, position data can be synchronized by SyncCnt. \n
+ * But the data of different method can not be synchronized by SyncCnt.\n
+ * example 1: [longitude and latitude from GPS] and [heading from GPS] can be synchronized by SyncCnt.\n
+ * example 2: [longitude and latitude from GPS] and [longitude and latitude from Navi] can not be
+ * synchronized by SyncCnt. \n
+ * Caution: The sensor count in sensor data delivery is another data.
+ * - Enable or not(isEnable) \n
+ * To describe this delivery message is whether can be used or not.
+ * - 0 - not avaliable
+ * - not 0 - avaliable
+ * - when GPS data specified, Altitude is invalid at following condition(so [not avaliable] provieded):
+ * - Immediately after system start, GPS unit has not received current location data and GPS unit status \n
+ * is not positioning fix
+ * - If it is not initialization status, certainly provide [avaliable] when Navi data specified
+ * - If the status is [not avaliable], data following can not be guaranteed.
+ * - Altitude
+ * - altitude data(unit 0.01m)
+ */
+typedef struct {
+ uint8_t getMethod; //!< \~english get method
+ uint8_t SyncCnt; //!< \~english Synchrony count
+ uint8_t isEnable; //!< \~english enable or not
+ uint8_t Reserved[3]; //!< \~english reserve
+ int32_t Altitude; //!< \~english altitude(0.01m)
+} SENSORLOCATION_ALTITUDEINFO_DAT;
+
+
+/**
+ * @struct SENSORMOTION_HEADINGINFO_DAT
+ * \~english heading information data
+ * - Get method(getMethod)
+ * - SENSOR_GET_METHOD_GPS - Heading from GPS
+ * - SENSOR_GET_METHOD_NAVI - Heading from Navi
+ * - Synchrony count(SyncCnt)
+ * - Count for position data synchronous \n
+ * When delivery altitude and heading data, position data can be synchronized by this count. \n
+ * But the data of different method can not be synchronized by this count.\n
+ * example 1: [longitude and latitude from GPS] and [heading from GPS] can be synchronized by the count. \n
+ * example 2: [longitude and latitude from GPS] and [longitude and latitude from Navi] can not be \n
+ * synchronized by the count. \n
+ * Caution: The sensor count in sensor data delivery is another data.
+ * - Enable or not(isEnable) \n
+ * To describe this data is whether enable or not
+ * - 0 - not avaliable
+ * - not 0 - avaliable
+ * - Heading is invalid at following condition when GPS data specified, so [not avaliable] provieded \n
+ * - Immediately after system start, GPS unit has not received current location data and GPS unit status \n
+ * is not positioning fix
+ * - If it is not initialization status, certainly provide [avaliable] when Navi data specified
+ * - If the status is [not avaliable], data following can not be guaranteed.
+ * - Position status(posSts)
+ * - It is valid only when "Get method is Navi" and "evironment is _CWORD80_".(otherwise it will be set as 0)
+ * - Bit0 : GPS data used result(1:used, 0:not used, definition of maskbit:POS_LOC_INFO_USE_GSP)
+ * - Bit1 : DGPS data used result(1:used, 0:not used, definition of maskbit:POS_LOC_INFO_USE_DGPS)
+ * - Bit3 : MapMatching data used result(1:used, 0:not used, definition of \n
+ * maskbit:POS_LOC_INFO_USE_MAPMATCHING)
+ * - Heading
+ * - Heading data(0.01degree as 1, based on north and clockwise count)\n
+ * But in environment _CWORD95_/_CWORD101___CWORD84_,the heading from Navi is a approximate that separate 360 degree \n
+ * into 16 part. \n
+ * example: 0, 2300, 4500, ..., 31500, 33800
+ */
+typedef struct {
+ uint8_t getMethod; //!< \~english get method
+ uint8_t SyncCnt; //!< \~english Synchrony count
+ uint8_t isEnable; //!< \~english enable or not
+ uint8_t posSts; //!< \~english position status
+ uint8_t Reserved1[2]; //!< \~english reserve
+ uint16_t Heading; //!< \~english heading(0.01degree)
+ //!< \~english max: 359.99 degree
+ //!< \~english min: 0.00 degree
+ uint8_t Reserved2[2]; //!< \~english reserve
+} SENSORMOTION_HEADINGINFO_DAT;
+
+/**
+ * @struct NAVIINFO_DIAG_GPS_FIX_CNT
+ * \~english position fix count data structure
+ */
+typedef struct {
+ uint32_t ulCnt3d; //!< \~english position fix count:3D
+ uint32_t ulCnt2d; //!< \~english position fix count:2D
+ uint32_t ulCntElse; //!< \~english position fix count:not fix
+} NAVIINFO_DIAG_GPS_FIX_CNT;
+
+/**
+ * @struct NAVIINFO_DIAG_GPS_FIX_XYZ
+ * \~english longitude and latitude data structure
+ */
+typedef struct {
+ int32_t lLat; //!< \~english GPS latitude
+ int32_t lLon; //!< \~english GPS longitude
+} NAVIINFO_DIAG_GPS_FIX_XYZ;
+
+/**
+ * @struct NAVIINFO_DIAG_GPS_FIX
+ * \~english position fix information structure
+ */
+typedef struct {
+ uint8_t ucFixSts; //!< \~english fix status
+ uint8_t ucReserve[3]; //!< \~english reserve
+ NAVIINFO_DIAG_GPS_FIX_CNT stCnt; //!< \~english fix count data
+ NAVIINFO_DIAG_GPS_FIX_XYZ stWgs84; //!< \~english longitude and latitude data
+} NAVIINFO_DIAG_GPS_FIX;
+
+/**
+ * @struct NAVIINFO_DIAG_GPS_PRN
+ * \~english satellite information structure
+ * - reception status(ucRcvSts)
+ * - NAVIINFO_DIAG_GPS_RCV_STS_NOTUSE : not used
+ * - NAVIINFO_DIAG_GPS_RCV_STS_SEARCHING : searching
+ * - NAVIINFO_DIAG_GPS_RCV_STS_TRACHING : tracking
+ * - NAVIINFO_DIAG_GPS_RCV_STS_NOTUSEFIX : not used for position fix
+ * - NAVIINFO_DIAG_GPS_RCV_STS_USEFIX : used for position fix
+ */
+typedef struct {
+ uint8_t ucRcvSts; //!< \~english reception status
+ uint8_t ucPrn; //!< \~english satellite No.
+ uint8_t ucelv; //!< \~english satellite dramatic angle
+ uint8_t ucLv; //!< \~english satellite signal level
+ uint16_t usAzm; //!< \~english satellite azimuth
+ uint8_t ucReserve[2]; //!< \~english reserve
+} NAVIINFO_DIAG_GPS_PRN;
+
+/**
+ * @struct NAVIINFO_DIAG_GPS_SAT
+ * \~english all satellite information structure
+ */
+typedef struct {
+ NAVIINFO_DIAG_GPS_PRN stPrn[12]; //!< \~english all satellite information
+} NAVIINFO_DIAG_GPS_SAT;
+
+/**
+ * @struct NAVIINFO_DIAG_GPS
+ * \~english position fixed and satellite information structure
+ */
+typedef struct {
+ NAVIINFO_DIAG_GPS_FIX stFix; //!< \~english position fixed information
+ NAVIINFO_DIAG_GPS_SAT stSat; //!< \~english all satellite information
+} NAVIINFO_DIAG_GPS;
+
+/**
+ * @struct NAVIINFO_NAVI_GPS
+ * \~english other GPS related information structure
+ * - altitude(altitude) \n
+ * As the altitude is used as unit [0.01m] in internal, \n
+ * the altitude data range is (-21,474,839~21,474,839).
+ * - UTC(utc)
+ * - The time set after rollover.
+ * - date and time status(tdsts)
+ * - 0= time has not been adjusted after GPS receiver reset(time input or master reset or CSF start)
+ * - 1= time output from RTC Backup(have time adjustment result)
+ * - 2= time adjustment completed
+ */
+typedef struct {
+ int32_t altitude; //!< \~english altitude
+ uint16_t speed; //!< \~english speed
+ uint16_t heading; //!< \~english heading
+ NAVIINFO_UTCTIME utc; //!< \~english UTC time
+ uint8_t tdsts; //!< \~english date and time status
+ uint8_t reserve[3]; //!< \~english reserve
+} NAVIINFO_NAVI_GPS;
+
+/**
+ * @struct NAVIINFO_ALL
+ * \~english Navi data structure
+ */
+typedef struct {
+ uint8_t ucSensorCnt; //!< \~english sensor count
+ uint8_t reserve[3]; //!< \~english reserve
+ NAVIINFO_DIAG_GPS stDiagGps; //!< \~english position fix related information
+ NAVIINFO_NAVI_GPS stNaviGps; //!< \~english other GPS related information
+} NAVIINFO_ALL;
+
+/**
+ * @struct POS_MSGINFO
+ * \~english message delivery positioning sensor information
+ */
+typedef struct {
+ DID did; //!< \~english data ID
+ PNO pno; //!< \~english delivery destination PNO
+ uint16_t size; //!< \~english data body size
+ uint8_t rcv_flag; //!< \~english received flag
+ uint8_t reserve; //!< \~english reserve
+ uint8_t data[POS_MSG_INFO_DSIZE]; //!< \~english data body
+} POS_MSGINFO;
+
+/**
+ * @struct SENSOR_GPSTIME
+ * \~english GPS time information
+ * - date amd time status(tdsts)
+ * - 0= time has not been adjusted after GPS receiver reset(time input or master reset or CSF start)
+ * - 1= time output from RTC Backup(have time adjustment result)
+ * - 2= time adjustment completed
+ */
+typedef struct {
+ NAVIINFO_UTCTIME utc; //!< \~english UTC time
+ uint8_t tdsts; //!< \~english time status
+ uint8_t reserve[3]; //!< \~english reserve
+} SENSOR_GPSTIME;
+
+#define SENSOR_MSG_GPSTIME SENSOR_GPSTIME //!< \~english GPS time information
+#define SENSOR_GPSTIME_RAW SENSOR_GPSTIME //!< \~english GPS time information
+
+/**
+ * @struct MdevGpsCustomData
+ * \~english Struct of Gps custom data
+ */
+typedef struct MdevGpsCustomData {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ SENSORLOCATION_LONLATINFO_DAT st_lonlat; //!< \~english longtitude,latitude
+ SENSORLOCATION_ALTITUDEINFO_DAT st_altitude; //!< \~english altitude
+ SENSORMOTION_HEADINGINFO_DAT st_heading; //!< \~english headings
+ SENSOR_MSG_GPSTIME st_gps_time; //!< \~english Gps Time
+ NAVIINFO_DIAG_GPS st_diag_gps; //!< \~english Gps data from diag
+} MDEV_GPS_CUSTOMDATA;
+
+/**
+ * @struct MdevGpsCustomDataMgs
+ * \~english Struct of Gps custom data message
+ */
+typedef struct MdevGpsCustomDataMgs {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header
+ MDEV_GPS_CUSTOMDATA st_data; //!< \~english Gps Custom Data
+} MDEV_GPS_CUSTOMDATA_MGS;
+
+/**
+ * @struct MdevGpsRtc
+ * \~english Struct of Gps RTC data
+ */
+typedef struct MdevGpsRtc {
+ u_int32 ul_retsts; //!< \~english return status
+ u_int8 uc_datalen; //!< \~english data length
+ u_int8 uc_ctrlcode; //!< \~english control code
+ u_int8 uc_bcd_year; //!< \~english year
+ u_int8 uc_bcd_month; //!< \~english month
+ u_int8 uc_bcd_day; //!< \~english day
+ u_int8 uc_bcd_hour; //!< \~english hour
+ u_int8 uc_bcd_min; //!< \~english minute
+ u_int8 uc_bcd_sec; //!< \~english second
+ u_int8 uc_status; //!< \~english status
+ u_int8 u_reserve[3]; //!< \~english reserve
+} MDEV_GPS_RTC;
+
+/**
+ * @struct MdevGpsGpsTime
+ * \~english Struct of Gps Time
+ */
+typedef struct MdevGpsGpsTime {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ MDEV_GPS_RTC st_rtc_data; //!< \~english Gps Time
+} MDEV_GPS_GPSTIME;
+
+/**
+ * @struct MdevGpsGpsTimeMgs
+ * \~english Struct of Gps Time message
+ */
+typedef struct MdevGpsGpsTimeMgs {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header
+ MDEV_GPS_GPSTIME st_data; //!< \~english Gps Time Data
+} MDEV_GPS_GPSTIME_MGS;
+
+/**
+ * @struct DevGpsUtcTime
+ * \~english Struct of Gps UTC time
+ */
+typedef struct DevGpsUtcTime {
+ u_int16 us_year; //!< \~english Year
+ u_int8 uc_month; //!< \~english month
+ u_int8 uc_date; //!< \~english day
+ u_int8 uc_hour; //!< \~english hour
+ u_int8 uc_minute; //!< \~english minute
+ u_int8 uc_second; //!< \~english second
+ u_int8 u_reserved; //!< \~english reserve
+} DEV_GPS_UTCTIME;
+
+/**
+ * @enum MdevGpsFixSts
+ * \~english enumeration of gps fix status
+ */
+typedef enum MdevGpsFixSts {
+ MDEV_GPS_NOTFIX = 0, //!< \~english not fix
+ MDEV_GPS_FIX //!< \~english fix
+} MDEV_GPS_FIX_STS;
+
+/**
+ * @struct MdevGpsNmea
+ * \~english Struct of gps NMEA Data
+ */
+typedef struct MdevGpsNmea {
+ u_int8 uc_nmea_data[GPS_MSG_VSINFO_DSIZE]; //!< \~english NMEA Data
+} MDEV_GPS_NMEA;
+
+/**
+ * @struct MdevGpsFullbin
+ * \~english Struct of Gps full bin data
+ */
+typedef struct MdevGpsFullbin {
+ u_int8 uc_fullbin_data[GPS_FULLBIN_SZ]; //!< \~english gps full bin data
+ u_int8 u_reserve[3]; //!< \~english reserve
+} MDEV_GPS_FULLBIN;
+
+/**
+ * @struct MdevGps_CWORD44_gp4
+ * \~english Struct of Gps _CWORD44_GP4 data
+ */
+typedef struct MdevGps_CWORD44_gp4 {
+ u_int8 uc__CWORD44_gp4_data[GPS__CWORD44_GP4_SZ]; //!< \~english gps _CWORD44_GP4 data
+ u_int8 u_reserve; //!< \~english reserve
+} MDEV_GPS__CWORD44_GP4;
+
+/**
+ * @struct MdevGpsCycledata
+ * \~english Struct of Gps cycle data
+ */
+typedef struct MdevGpsCycledata {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ u_int8 uc_data[GPS_MSGDATA_SZ_MAX - sizeof(MDEV_GPS_DATA_KIND)]; //!< \~english data
+} MDEV_GPS_CYCLEDATA;
+
+/**
+ * @struct MdevGpsCycledataMsg
+ * \~english Struct of Gps cycle data message
+ */
+typedef struct MdevGpsCycledataMsg {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header
+ MDEV_GPS_CYCLEDATA st_data; //!< \~english data
+} MDEV_GPS_CYCLEDATA_MSG;
+
+/**
+ * @struct MdevGpsRawdataNmea
+ * \~english Struct of Gps NMEA Raw Data
+ */
+typedef struct MdevGpsRawdataNmea {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ MDEV_GPS_NMEA st_nmea_data; //!< \~english NMEA Data
+} MDEV_GPS_RAWDATA_NMEA;
+
+/**
+ * @struct MdevGpsRawdataNmeaMsg
+ * \~english Struct of Gps NMEA Raw Data message
+ */
+typedef struct MdevGpsRawdataNmeaMsg {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header(see vs-positioning-base-library)
+ MDEV_GPS_RAWDATA_NMEA st_data; //!< \~english data
+} MDEV_GPS_RAWDATA_NMEA_MSG;
+
+/**
+ * @struct MdevGpsRawdataFullbin
+ * \~english Struct of Gps Full Bin Raw Data
+ */
+typedef struct MdevGpsRawdataFullbin {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ MDEV_GPS_FULLBIN st_fullbin_data; //!< \~english Full Binary Data
+} MDEV_GPS_RAWDATA_FULLBIN;
+
+/**
+ * @struct MdevGpsRawdataFullbinMsg
+ * \~english Struct of Gps Full Bin Raw Data message
+ */
+typedef struct MdevGpsRawdataFullbinMsg {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header
+ MDEV_GPS_RAWDATA_FULLBIN st_data; //!< \~english Gps Full Bin Data
+} MDEV_GPS_RAWDATA_FULLBIN_MSG;
+
+/**
+ * @struct MdevGpsRawdata_CWORD44_gp4
+ * \~english Struct of Gps _CWORD44_GP4 Raw Data
+ */
+typedef struct MdevGpsRawdata_CWORD44_gp4 {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ MDEV_GPS__CWORD44_GP4 st__CWORD44_gp4; //!< \~english Gps _CWORD44_GP4 Data
+} MDEV_GPS_RAWDATA__CWORD44_GP4;
+
+/**
+ * @struct MdevGpsRawdata_CWORD44_gp4Msg
+ * \~english Struct of Gps _CWORD44_GP4 Raw Data message
+ */
+typedef struct MdevGpsRawdata_CWORD44_gp4Msg {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header
+ MDEV_GPS_RAWDATA__CWORD44_GP4 st_data; //!< \~english Gps _CWORD44_GP4 Raw Data
+} MDEV_GPS_RAWDATA__CWORD44_GP4_MSG;
+
+/**
+ * @struct SENSORMOTION_SPEEDINFO_DAT
+ * \~english speed information data
+ * - Get method(getMethod)
+ * - SENSOR_GET_METHOD_POS - The speed calculated in positioning based on speed pulse will be deliveried.
+ * - SENSOR_GET_METHOD_NAVI - speed from Navi
+ * - Synchrony count(SyncCnt)
+ * - 0 (not change).
+ * - Enable or not(isEnable) \n
+ * To describe this data is whether enable or not
+ * - 0 - not avaliable
+ * - not 0 - avaliable
+ * - Speed is invalid at following condition when speed pulse specified, so [not avaliable] provieded
+ * - Immediately after system start, the sensor data have not been received from SYS micon
+ * - If it is not initialization status, certainly provide [avaliable] when Navi data specified
+ * - If the status is [not avaliable], data following can not be guaranteed.
+ * - Speed
+ * - speed data(unit 0.01m/sec)
+ */
+typedef struct {
+ uint8_t getMethod; //!< \~english get method
+ uint8_t SyncCnt; //!< \~english Synchrony count
+ uint8_t isEnable; //!< \~english enable or not
+ uint8_t Reserved1[3]; //!< \~english reserve
+ uint16_t Speed; //!< \~english speed(0.01m/sec)
+ uint8_t Reserved2[2]; //!< \~english reserve
+} SENSORMOTION_SPEEDINFO_DAT;
+
+/**
+ * @struct MdevGpsNavispeed
+ * \~english Struct of Gps speed data
+ */
+typedef struct MdevGpsNavispeed {
+ MDEV_GPS_DATA_KIND e_kind; //!< \~english kind
+ u_int16 us_speed_kmph; //!< \~english Speed(km/h)
+ u_int8 u_reserve[2]; //!< \~english reserve
+ SENSORMOTION_SPEEDINFO_DAT st_speed; //!< \~english speed data
+} MDEV_GPS_NAVISPEED;
+
+/**
+ * @struct MdevGpsNavispeedMsg
+ * \~english Struct of Gps speed data message
+ */
+typedef struct MdevGpsNavispeedMsg {
+ T_APIMSG_MSGBUF_HEADER h_dr; //!< \~english header
+ MDEV_GPS_NAVISPEED st_data; //!< \~english Gps Speed Data
+} MDEV_GPS_NAVISPEED_MSG;
+
+/**
+ * @struct TgGpsSndData
+ * \~english Struct of _CWORD82_ Gps send data
+ */
+typedef struct TgGpsSndData {
+ uint8_t reserve[4]; //!< \~english reserve
+ u_int16 us_size; //!< \~english send data length
+ u_int8 ub_data[502]; //!< \~english send data
+} TG_GPS_SND_DATA;
+
+/**
+ * @struct TgGpsRetPram
+ * \~english Gps Response data
+ */
+typedef struct TgGpsRetPram {
+ unsigned int ret_status; //!< \~english response flag
+ unsigned char data_len; //!< \~english data size
+ unsigned char ctrl_code; //!< \~english control code
+ unsigned char gps_data[GPS_TLGRM_LEN]; //!< \~english data contents
+} TG_GPS_RET_PRAM;
+
+/**
+ * @struct SensorWknRollOverHal
+ * \~english Struct of GPS week number
+ */
+typedef struct SensorWknRollOverHal {
+ uint16_t us_wkn; //!< \~english GPS week number
+} SENSOR_WKN_ROLLOVER_HAL;
+
+/**
+ * @struct POS_DATETIME
+ * \~english GPS time information structure
+ */
+typedef struct {
+ uint16_t year; //!< \~english year
+ uint8_t month; //!< \~english month
+ uint8_t date; //!< \~english day
+ uint8_t hour; //!< \~english hour
+ uint8_t minute; //!< \~english minute
+ uint8_t second; //!< \~english second
+ uint8_t reserved; //!< \~english reserve
+} POS_DATETIME;
+
+/**
+ * @struct TG_GPS_RET_RESET
+ * \~english GPS reset status
+ */
+typedef struct {
+ unsigned long ret_rst_status; //!< \~english response GPS reset status
+} TG_GPS_RET_RESET;
+
+/**
+ * @struct TG_GPS_RET_RESET_MSG
+ * \~english GPS reset information message
+ */
+typedef struct {
+ TG_GPS_RET_RESET data; //!< \~english GPS reset status data
+} TG_GPS_RET_RESET_MSG;
+
+/**
+ * @struct VEHICLE_MSG_SEND_DAT
+ * \~english Vehicle information setting message structure
+ */
+typedef struct {
+ DID did; //!< \~english Data ID
+ u_int16 size; //!< \~english Data size
+ u_int8 data[502]; //!< \~english Data
+} VEHICLE_MSG_SEND_DAT;
+
+/**
+ * @struct GpsWeekCorCntMsg
+ * \~english Gps Week correction count notify message structure
+ */
+typedef struct GpsWeekCorCntMsg {
+ T_APIMSG_MSGBUF_HEADER stHead; //!< \~english Message header
+ u_int8 gpsweekcorcnt; //!< \~english Gps Week correction count
+ int8 dummy[3]; //!< \~english Alignment adjustment
+} CLOCKGPS_GPSWEEKCOR_CNT_MSG;
+
+/** @}*/ // end of positioning_hal
+/** @}*/ // end of positioning
+
+/*---------------------------------------------------------------------------*/
+#endif // HAL_API_GPS_HAL_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/hal_api/positioning_hal.h b/hal/positioning_hal/hal_api/positioning_hal.h
new file mode 100755
index 0000000..8a74b81
--- /dev/null
+++ b/hal/positioning_hal/hal_api/positioning_hal.h
@@ -0,0 +1,872 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_POSITIONING_HAL_H_
+#define HAL_API_POSITIONING_HAL_H_
+
+/**
+ * @file positioning_hal.h
+ */
+
+/** @addtogroup positioning
+ * @{
+ */
+/** @addtogroup positioning_hal
+ * @ingroup positioning
+ * @{
+ */
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include <native_service/frameworkunified_types.h>
+#include <vehicle_service/pos_message_header.h>
+#include <vehicle_service/std_types.h>
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+#define POSHAL_THREAD_NAME_SENS "POS_Sens"
+//!< \~english Thread name for receive sensor
+#define POSHAL_THREAD_NAME_GPS_MAIN "POS_Gps"
+//!< \~english Thread name for GPS NMEA analysis and delivery message
+#define POSHAL_THREAD_NAME_GPS_RECV "POS_Gps_Recv"
+//!< \~english Thread name for receive GPS
+#define POSHAL_THREAD_NAME_GPS_ROLOVR "POS_Gps_Rolovr"
+//!< \~english Thread name for monitoring GPS rollover
+
+#define POSHAL_DID_SNS_COUNTER 0x8000001A
+//!< \~english Data ID of sensor counter
+#define POSHAL_DID_SPEED_PULSE 0x80000012
+//!< \~english Data ID of speed pulse
+#define POSHAL_DID_SPEED_PULSE_FLAG 0x80000076
+//!< \~english Data ID of speed pulse flag
+#define POSHAL_DID_SPEED_PULSE_FST 0x80000028
+//!< \~english Data ID of first time speed pulse
+#define POSHAL_DID_SPEED_PULSE_FLAG_FST 0x8000007D
+//!< \~english Data ID of first time speed pulse flag
+#define POSHAL_DID_SPEED_KMPH 0x80000013
+//!< \~english Data ID of KMPH speed
+#define POSHAL_DID_PULSE_TIME 0x8000003A
+//!< \~english Data ID of pulse time
+#define POSHAL_DID_GYRO_X 0x80000014
+//!< \~english Data ID of X axis of gyro
+#define POSHAL_DID_GYRO_Y 0x80000085
+//!< \~english Data ID of Y axis of gyro
+#define POSHAL_DID_GYRO_Z 0x80000086
+//!< \~english Data ID of Z axis ofgyro
+#define POSHAL_DID_GYRO POSHAL_DID_GYRO_X
+//!< \~english Data ID of gyro
+#define POSHAL_DID_GYRO_X_FST 0x80000029
+//!< \~english Data ID of first time X axis gyro
+#define POSHAL_DID_GYRO_Y_FST 0x80000043
+//!< \~english Data ID of first time Y axis gyro
+#define POSHAL_DID_GYRO_Z_FST 0x80000023
+//!< \~english Data ID of first time Z axis gyro
+#define POSHAL_DID_GYRO_FST POSHAL_DID_GYRO_X_FST
+//!< \~english Data ID of first time gyro
+#define POSHAL_DID_GYRO_EXT 0x80000027
+//!< \~english Data ID of extend gyro
+#define POSHAL_DID_GYRO_TEMP 0x80000090
+//!< \~english Data ID of gyro temperature
+#define POSHAL_DID_GYRO_TEMP_FST 0x80000091
+//!< \~english Data ID of first time gyro temperature
+#define POSHAL_DID_REV 0x80000017
+//!< \~english Data ID of reverse signal
+#define POSHAL_DID_REV_FST 0x8000007E
+//!< \~english Data ID of first time reverse signal
+#define POSHAL_DID_GSNS_X 0x80000015
+//!< \~english Data ID of x axis gsensor
+#define POSHAL_DID_GSNS_Y 0x80000016
+//!< \~english Data ID of Y axis gsensor
+#define POSHAL_DID_GSNS_Z 0x80000026
+//!< \~english Data ID of Z axis gsensor
+#define POSHAL_DID_GSNS_X_FST 0x80000087
+//!< \~english Data ID of first time x axis gsensor
+#define POSHAL_DID_GSNS_Y_FST 0x80000088
+//!< \~english Data ID of first time Y axis gsensor
+#define POSHAL_DID_GSNS_Z_FST 0x80000089
+//!< \~english Data ID of first time Z axis gsensor
+#define POSHAL_DID_GPS_NMEA 0x8000009AU
+//!< \~english Data ID of GPS NMEA sentence
+#define POSHAL_DID_GPS_ANTENNA 0x80000019
+//!< \~english Data ID of GPS antenna status
+#define POSHAL_DID_GPS_CUSTOMDATA 0x80000094U
+//!< \~english Data ID of GPS custom data
+#define POSHAL_DID_GPS_CUSTOMDATA_NAVI 0x800000A0
+//!< \~english Data ID of GPS custom data for navi
+#define POSHAL_DID_GPS_TIME 0x80000098
+//!< \~english Data ID of GPS time
+#define POSHAL_DID_GPS_TIME_RAW 0x800000B1U
+//!< \~english Data ID of GPS raw time
+#define POSHAL_DID_GPS_VERSION 0x8000001E
+//!< \~english Data ID of GPS version
+#define POSHAL_DID_GPS__CWORD82___CWORD44_GP4 0x80000031U
+//!< \~english Data ID of _CWORD82_ GPS _CWORD44_GP4 data
+#define POSHAL_DID_GPS__CWORD82__FULLBINARY 0x80000032U
+//!< \~english Data ID of _CWORD82_ GPS full binary data
+#define POSHAL_DID_GPS_WKNROLLOVER 0x800000B2U
+//!< \~english Data ID of GPS week counter
+#define POSHAL_DID_GPS_CLOCK_DRIFT 0x800000B3U
+//!< \~english Data ID of GPS time drift data
+#define POSHAL_DID_GPS_CLOCK_FREQ 0x800000B4U
+//!< \~english Data ID of GPS time frequency data
+#define POSHAL_DID_GPS_INTERRUPT_FLAG 0x80000077
+//!< \~english Data ID of GPS interrupt flag
+
+#define CONFIG_SENSOR_EXT_VALID 1 //!< \~english for first sensor
+
+#define CID_LINESENS_VEHICLE_DATA 0x0300 //!< \~english vehicle notify ID
+
+/**
+ * \~english @brief LineSensor Vehicle Signal Notification
+ * \~english @brief This command is sent when LineSensor vehicle signals are notified when sensor data is received.\n
+ * \~english @brief Message related structure @ref LsdrvMsgLsdataG\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref LsdrvMsgLsdataDatG\n
+ * \~english @brief Message body (vehicle signal notification message information) structure @ref LsdrvLsdataG\n
+ */
+#define CID_LINESENS_VEHICLE_DATA_G 0x0303
+
+/**
+ * \~english @brief Gyro Failure Status Notification
+ * \~english @brief This command is sent when giro failure status is notified.\n
+ * \~english @brief Message related structure @ref LsdrvMsgLsdataGyroTrouble\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref LsdrvMsgLsdataDatGyroTrouble\n
+ */
+#define CID_LINESENS_VEHICLE_DATA_GYRO_TROUBLE 0x0304
+
+/**
+ * \~english @brief Get SYS GPS Interrupt Signals
+ * \~english @brief This command is sent when SYS GPS interrupt signal is acquired.\n
+ * \~english @brief Message related structure @ref LsdrvMsgLsdataGpsInterruptSignal\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref LsdrvMsgLsdataDatGpsInterruptSignal\n
+ */
+#define CID_LINESENS_VEHICLE_DATA_SYS_GPS_INTERRUPT_SIGNAL 0x0305
+
+
+/**
+ * \~english @brief Gyro Connection Status Notification
+ * \~english @brief This command is sent when giro connection status is notified.\n
+ * \~english @brief Message related structure @ref LsdrvMsgLsdataGyroConnectStatus\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref LsdrvMsgLsdataDatGyroConnectStatus\n
+ */
+#define CID_LINESENS_VEHICLE_DATA_GYRO_CONNECT_STATUS 0x0306
+
+
+/**
+ * \~english @brief GPS Antenna Connection Status Notification
+ * \~english @brief This command is sent when the GPS antenna connection status is notified.\n
+ * \~english @brief Message related structure @ref LsdrvMsgLsdataGpsAntennaStatus\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref LsdrvMsgLsdataDatGpsAntennaStatus\n
+ */
+#define CID_LINESENS_VEHICLE_DATA_GPS_ANTENNA_STATUS 0x0307
+
+
+/**
+ * \~english @brief LineSensor Vehicle Signal Notification(Initial Sensor)
+ * \~english @brief This command is sent when LineSensor vehicle signals (initial sensor) are notified.\n
+ * \~english @brief Message related structure @ref LsdrvMsgLsdataFst\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref LsdrvMsgLsdataDatFst\n
+ * \~english @brief Gyro X-axis @ref LsdrvLsdataFstGyroX\n
+ * \~english @brief Gyro Y-axis @ref LsdrvLsdataFstGyroY\n
+ * \~english @brief Gyro Z-axis @ref LsdrvLsdataFstGyroZ\n
+ * \~english @brief Velocity information @ref LsdrvLsdataFstSpeed\n
+ * \~english @brief Vehicle speed pulse @ref LsdrvLsdataFstSpeedPulseFlag\n
+ * \~english @brief REV flag @ref LsdrvLsdataFstRev\n
+ * \~english @brief Gyro Temperature @ref LsdrvLsdataFstGyroTemp\n
+ * \~english @brief G-sensor X-axis @ref LsdrvLsdataFstGsensorX\n
+ * \~english @brief G-sensor Y-axis @ref LsdrvLsdataFstGsensorY\n
+ * \~english @brief G-sensor Z-axis @ref LsdrvLsdataFstGsensorZ\n
+ */
+#define CID_LINESENS_VEHICLE_DATA_FST 0x0302
+
+/**
+ * \~english @brief GPS data notification
+ * \~english @brief This command is used to notify the data input from the GPS receiver device.\n
+ * \~english @brief Message related structure @ref SensorMsgGpsdata\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message header structure @ref T_APIMSG_HEADER\n
+ * \~english @brief Message body structure @ref SensorMsgGpsdataDat\n
+ */
+#define CID_GPS_DATA 0x0301
+
+/**
+ * \~english @brief Notification of effective ephemeris number at shutdown
+ * \~english @brief This command is sent to notify the effective ephemeris number at shutdown.\n
+ * \~english @brief Message related structure @ref SensorMsgGpsdata\n
+ * \~english @brief Message buffer header structure @ref T_APIMSG_MSGBUF_HEADER\n
+ * \~english @brief Message body structure @ref SensorMsgGpsdata\n
+ */
+#define CID_EPH_NUM_NOTIFICATION 0x0310
+
+
+#define LSDRV_FSTSNS_SENSOR_FIRST_SAVE_NUM 50
+//!< \~english number of save first sensor
+
+#define LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM 30
+//!< \~english number of send first sensor
+
+#define LSDRV_FSTSNS_DETAILED_DATA_GYRO_NUM 10
+//!< \~english number of gyro including detail data
+
+#define LSDRV_FSTSNS_DETAILED_DATA_GSENSOR_NUM 10
+//!< \~english number of Gsns includeing detail data
+
+#define LSDRV_FSTSNS_DSIZE_GYRO_X (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * LSDRV_FSTSNS_DETAILED_DATA_GYRO_NUM * 2)
+//!< \~english data size of X axis of gyro
+#define LSDRV_FSTSNS_DSIZE_GYRO_Y (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * LSDRV_FSTSNS_DETAILED_DATA_GYRO_NUM * 2)
+//!< \~english data size of Y axis of gyro
+#define LSDRV_FSTSNS_DSIZE_GYRO_Z (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * LSDRV_FSTSNS_DETAILED_DATA_GYRO_NUM * 2)
+//!< \~english data size of Z axis of gyro
+#define LSDRV_FSTSNS_DSIZE_SPEED (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * 2)
+//!< \~english data size of speed
+#define LSDRV_FSTSNS_DSIZE_SPEED_FLG LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM
+//!< \~english data size of speed pulse
+#define LSDRV_FSTSNS_DSIZE_REV LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM
+//!< \~english data size of reverse
+#define LSDRV_FSTSNS_DSIZE_GYRO_TEMP (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * 2)
+//!< \~english data size of gyro temperature
+#define LSDRV_FSTSNS_DSIZE_GSENSOR_X (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * LSDRV_FSTSNS_DETAILED_DATA_GSENSOR_NUM * 2)
+//!< \~english data size of X axis of Gsns
+
+#define LSDRV_FSTSNS_DSIZE_GSENSOR_Y (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * LSDRV_FSTSNS_DETAILED_DATA_GSENSOR_NUM * 2)
+ //!< \~english data size of Y axis of Gsns
+#define LSDRV_FSTSNS_DSIZE_GSENSOR_Z (LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM * LSDRV_FSTSNS_DETAILED_DATA_GSENSOR_NUM * 2)
+//!< \~english data size of Z axis of Gsns
+
+#define SENSOR_MSG_VSINFO_DSIZE 1904 //!< \~english message body max size
+
+
+// Thread control Command ID
+#define CID_THREAD_CREATE_COMP (0x0001) //!< \~english Thread Start Complete Notify Command ID
+#define CID_THREAD_STOP_REQ (0x0002) //!< \~english Thread Stop Request Command ID
+#define CID_THREAD_STOP_COMP (0x0003) //!< \~english Thread Stop Complete Notify Command ID
+
+// A vehicle signal of data size
+#define LSDRV_SNDMSG_DTSIZE_1 1 //!< \~english SndMSG data size 1Byte
+#define LSDRV_SNDMSG_DTSIZE_2 2 //!< \~english SndMSG data size 2Byte
+#define LSDRV_SNDMSG_DTSIZE_20 20 //!< \~english SndMSG data size 20Byte
+#define LSDRV_SNDMSG_DTSIZE_132 132 //!< \~english SndMSG data size 132Byte
+
+// NMEA receive flag
+#define POS_SNS_GPS_NMEA_GGA (0x00000001U) //!< \~english GGA sentence
+#define POS_SNS_GPS_NMEA_GLL (0x00000002U) //!< \~english GLL sentence
+#define POS_SNS_GPS_NMEA_GSA1 (0x00000004U) //!< \~english GSA1 sentence
+#define POS_SNS_GPS_NMEA_GSA2 (0x00000008U) //!< \~english GSA2 sentence
+#define POS_SNS_GPS_NMEA_GSA3 (0x00000010U) //!< \~english GSA3 sentence
+#define POS_SNS_GPS_NMEA_GSA4 (0x00000020U) //!< \~english GSA4 sentence
+#define POS_SNS_GPS_NMEA_GST (0x00000040U) //!< \~english GST sentence
+#define POS_SNS_GPS_NMEA_RMC (0x00000080U) //!< \~english RMC sentence
+#define POS_SNS_GPS_NMEA_VTG (0x00000100U) //!< \~english VTG sentence
+#define POS_SNS_GPS_NMEA_GSV1 (0x00000200U) //!< \~english GSV1 sentence
+#define POS_SNS_GPS_NMEA_GSV2 (0x00000400U) //!< \~english GSV2 sentence
+#define POS_SNS_GPS_NMEA_GSV3 (0x00000800U) //!< \~english GSV3 sentence
+#define POS_SNS_GPS_NMEA_GSV4 (0x00001000U) //!< \~english GSV4 sentence
+#define POS_SNS_GPS_NMEA_GSV5 (0x00002000U) //!< \~english GSV5 sentence
+#define POS_SNS_GPS_NMEA_GSV6 (0x00004000U) //!< \~english GSV6 sentence
+#define POS_SNS_GPS_NMEA_GSV7 (0x00008000U) //!< \~english GSV7 sentence
+#define POS_SNS_GPS_NMEA_GSV8 (0x00010000U) //!< \~english GSV8 sentence
+#define POS_SNS_GPS_NMEA_GSV9 (0x00020000U) //!< \~english GSV9 sentence
+#define POS_SNS_GPS_NMEA_GSV10 (0x00040000U) //!< \~english GSV10 sentence
+#define POS_SNS_GPS_NMEA_GSV11 (0x00080000U) //!< \~english GSV11 sentence
+#define POS_SNS_GPS_NMEA_GSV12 (0x00100000U) //!< \~english GSV12 sentence
+#define POS_SNS_GPS_NMEA_GSV13 (0x00200000U) //!< \~english GSV13 sentence
+#define POS_SNS_GPS_NMEA_RESERVE1 (0x00400000U) //!< \~english Reserved
+#define POS_SNS_GPS_NMEA_RESERVE2 (0x00800000U) //!< \~english Reserved
+
+
+/**
+ * @enum POS_SNS_GPS_NMEA_SNO
+ * \~english type of NMEA
+ */
+typedef enum {
+ POS_SNS_GPS_NMEA_SNO_GGA = 0, //!< \~english GGA sentence
+ POS_SNS_GPS_NMEA_SNO_GLL, //!< \~english GLL sentence
+ POS_SNS_GPS_NMEA_SNO_GSA1, //!< \~english GSA1 sentence
+ POS_SNS_GPS_NMEA_SNO_GSA2, //!< \~english GSA2 sentence
+ POS_SNS_GPS_NMEA_SNO_GSA3, //!< \~english GSA3 sentence
+ POS_SNS_GPS_NMEA_SNO_GSA4, //!< \~english GSA4 sentence
+ POS_SNS_GPS_NMEA_SNO_GST, //!< \~english GST sentence
+ POS_SNS_GPS_NMEA_SNO_RMC, //!< \~english RMC sentence
+ POS_SNS_GPS_NMEA_SNO_VTG, //!< \~english VTG sentence
+ POS_SNS_GPS_NMEA_SNO_GSV1, //!< \~english GSV1 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV2, //!< \~english GSV2 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV3, //!< \~english GSV3 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV4, //!< \~english GSV4 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV5, //!< \~english GSV5 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV6, //!< \~english GSV6 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV7, //!< \~english GSV7 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV8, //!< \~english GSV8 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV9, //!< \~english GSV9 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV10, //!< \~english GSV10 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV11, //!< \~english GSV11 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV12, //!< \~english GSV12 sentence
+ POS_SNS_GPS_NMEA_SNO_GSV13, //!< \~english GSV13 sentence
+ POS_SNS_GPS_NMEA_SNO_RESERVE1, //!< \~english Reserved
+ POS_SNS_GPS_NMEA_SNO_RESERVE2, //!< \~english Reserved
+
+ POS_SNS_GPS_NMEA_SNO_MAX //!< \~english MAX sentence(invalid)
+} POS_SNS_GPS_NMEA_SNO;
+
+/**
+ * @enum LsDrvKind
+ * \~english type of Sensor
+ */
+typedef enum {
+ LSDRV_GYRO_X, //!< \~english Gyro X-Axis
+ LSDRV_GYRO_Y, //!< \~english Gyro Y-Axis
+ LSDRV_GYRO_Z, //!< \~english Gyro Z-Axis
+ LSDRV_SPEED_PULSE, //!< \~english Speed pulse
+ LSDRV_SPEED_PULSE_FLAG, //!< \~english Speed pulse Flag
+ LSDRV_SPEED_KMPH, //!< \~english Speed km/h
+ LSDRV_GYRO_EXT, //!< \~english extend Gyro
+ LSDRV_REV, //!< \~english Reverse
+ LSDRV_GYRO_TEMP, //!< \~english Gyro temperature
+ LSDRV_GSENSOR_X, //!< \~english G-sensor X-Axis
+ LSDRV_GSENSOR_Y, //!< \~english G-sensor Y-Axis
+ LSDRV_GSENSOR_Z, //!< \~english G-sensor Z-Axis
+ LSDRV_PULSE_TIME, //!< \~english Pulse time
+ LSDRV_SNS_COUNTER, //!< \~english Sensor counter
+ LSDRV_GPS_INTERRUPT_FLAG, //!< \~english GPS Interrupt Flag
+ LSDRV_KINDS_MAX //!< \~english MAX
+} LsDrvKind;
+
+
+/**
+ * @enum EnumTidPos
+ * \~english Thread id notified to positioning when starting or terminating each thread is completed.
+ */
+typedef enum EnumTidPos {
+ ETID_POS_MAIN = 0,
+ //!< \~english Thread for vehicle sensor(unused in hal)
+ ETID_POS_SENS,
+ //!< \~english Thread for receive sensor
+ ETID_POS_GPS,
+ //!< \~english Thread for GPS NMEA analysis and delivery message
+ ETID_POS_GPS_RECV,
+ //!< \~english Thread for receive GPS
+ ETID_POS_GPS_ROLLOVER,
+ //!< \~english Thread for monitoring GPS rollover
+ ETID_POS_MAX
+ //!< \~english Max thread id
+} EnumTID_POS;
+
+/**
+ * @struct LsdrvLsdata
+ * \~english Struct of LineSensor message
+ */
+typedef struct LsdrvLsdata {
+ u_int32 ul_did; //!< \~english data ID
+ u_int8 uc_size; //!< \~english data size
+ u_int8 uc_rcvflag; //!< \~english receive flag
+ u_int8 uc_sns_cnt; //!< \~english sensor count
+ u_int8 u_reserve; //!< \~english reserve
+ u_int8 uc_data[132]; //!< \~english data contents
+} LSDRV_LSDATA;
+
+/**
+ * @struct LsdrvLsdataG
+ * \~english Struct of LineSensorG message
+ */
+typedef struct LsdrvLsdataG {
+ u_int32 ul_did; //!< \~english data ID
+ u_int8 uc_size; //!< \~english data size
+ u_int8 uc_rcv_flag; //!< \~english receive flag
+ u_int8 uc_sns_cnt; //!< \~english sensor count
+ u_int8 reserve; //!< \~english reserve
+ u_int8 uc_data[132]; //!< \~english data content
+} LSDRV_LSDATA_G;
+
+/**
+ * @struct LsdrvLsdataFstGyroX
+ * \~english Struct of X axis of of gyro data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGyroX {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GYRO_X]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GYRO_X;
+
+/**
+ * @struct LsdrvLsdataFstGyroY
+ * \~english Struct of Y axis of of gyro data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGyroY {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GYRO_Y]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GYRO_Y;
+
+/**
+ * @struct LsdrvLsdataFstGyroZ
+ * \~english Struct of Z axis of of gyro data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGyroZ {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GYRO_Z]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GYRO_Z;
+
+/**
+ * @struct LsdrvLsdataFstSpeed
+ * \~english Struct of speed data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstSpeed {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_SPEED]; //!< \~english data contents
+} LSDRV_LSDATA_FST_SPEED;
+
+/**
+ * @struct LsdrvLsdataFstSpeedPulseFlag
+ * \~english Struct of speed pulse data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstSpeedPulseFlag {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_SPEED_FLG]; //!< \~english data contents
+} LSDRV_LSDATA_FST_SPEED_PULSE_FLAG;
+
+/**
+ * @struct LsdrvLsdataFstRev
+ * \~english Struct of reverse data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstRev {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_REV]; //!< \~english data contents
+} LSDRV_LSDATA_FST_REV;
+
+/**
+ * @struct LsdrvLsdataFstGyroTemp
+ * \~english Struct of gyro temperature data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGyroTemp {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GYRO_TEMP]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GYRO_TEMP;
+
+/**
+ * @struct LsdrvLsdataFstGsensorX
+ * \~english Struct of X axis of Gsns data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGsensorX {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GSENSOR_X]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GSENSOR_X;
+
+/**
+ * @struct LsdrvLsdataFstGsensorY
+ * \~english Struct of Y axis of Gsns data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGsensorY {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GSENSOR_Y]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GSENSOR_Y;
+
+/**
+ * @struct LsdrvLsdataFstGsensorZ
+ * \~english Struct of Z axis of Gsns data(first sensor message)
+ */
+typedef struct LsdrvLsdataFstGsensorZ {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[LSDRV_FSTSNS_DSIZE_GSENSOR_Z]; //!< \~english data contents
+} LSDRV_LSDATA_FST_GSENSOR_Z;
+
+/**
+ * @struct LsdrvMsgLsdataDatFst
+ * \~english Struct of LineSensor data (first sensor message)
+ */
+typedef struct LsdrvMsgLsdataDatFst {
+ LSDRV_LSDATA_FST_GYRO_X st_gyro_x; //!< \~english data of X axis of gyro
+ LSDRV_LSDATA_FST_GYRO_Y st_gyro_y; //!< \~english data of Y axis of gyro
+ LSDRV_LSDATA_FST_GYRO_Z st_gyro_z; //!< \~english data of Z axis of gyro
+ LSDRV_LSDATA_FST_SPEED st_speed; //!< \~english data of speed
+ LSDRV_LSDATA_FST_SPEED_PULSE_FLAG st_spd_pulse_flg; //!< \~english data of speed pulse
+ LSDRV_LSDATA_FST_REV st_rev; //!< \~english data of reverse
+ LSDRV_LSDATA_FST_GYRO_TEMP st_gyro_temp; //!< \~english data of gyro temperature
+ LSDRV_LSDATA_FST_GSENSOR_X st_gsns_x; //!< \~english data of X axis of Gsns
+ LSDRV_LSDATA_FST_GSENSOR_Y st_gsns_y; //!< \~english data of Y axis of Gsns
+ LSDRV_LSDATA_FST_GSENSOR_Z st_gsns_z; //!< \~english data of Z axis of Gsns
+} LSDRV_MSG_LSDATA_DAT_FST;
+
+/**
+ * @struct LsdrvMsgLsdataDat
+ * \~english Struct of LineSensor package data
+ */
+typedef struct LsdrvMsgLsdataDat {
+ u_int8 uc_data_num; //!< \~english data number
+ u_int8 reserve[3]; //!< \~english reserve
+ LSDRV_LSDATA st_data[12]; //!< \~english data
+} LSDRV_MSG_LSDATA_DAT;
+
+/**
+ * @struct LsdrvMsgLsdata
+ * \~english Struct of LineSensor message data
+ */
+typedef struct LsdrvMsgLsdata {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT st_para; //!< \~english data of gyro
+} LSDRV_MSG_LSDATA;
+
+/**
+ * @struct LsdrvMsgLsdataDatG
+ * \~english Struct of LineSensorG package data
+ */
+typedef struct LsdrvMsgLsdataDatG {
+ u_int8 uc_data_num; //!< \~english data number
+ u_int8 reserve[3]; //!< \~english reserve
+ LSDRV_LSDATA_G st_data[15]; //!< \~english data
+} LSDRV_MSG_LSDATA_DAT_G;
+
+/**
+ * @struct LsdrvMsgLsdataG
+ * \~english Struct of LineSensorG message data
+ */
+typedef struct LsdrvMsgLsdataG {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT_G st_para; //!< \~english data of message
+} LSDRV_MSG_LSDATA_G;
+
+/**
+ * @struct LsdrvMsgLsdataDatGyroTrouble
+ * \~english Struct of Gyro trouble
+ */
+typedef struct LsdrvMsgLsdataDatGyroTrouble {
+ u_int32 ul_did; //!< \~english data ID
+ u_int8 uc_size; //!< \~english data size
+ u_int8 reserve; //!< \~english reserve
+ u_int8 uc_data; //!< \~english data content
+ u_int8 reserve2; //!< \~english reserve
+} LSDRV_MSG_LSDATA_DAT_GYRO_TROUBLE;
+
+/**
+ * @struct LsdrvMsgLsdataGyroTrouble
+ * \~english Struct of message about Gyro trouble
+ */
+typedef struct LsdrvMsgLsdataGyroTrouble {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT_GYRO_TROUBLE st_para; //!< \~english data of message
+} LSDRV_MSG_LSDATA_GYRO_TROUBLE;
+
+/**
+ * @struct LsdrvMsgLsdataDatGpsInterruptSignal
+ * \~english Struct of Gps interrupt signal data
+ */
+typedef struct LsdrvMsgLsdataDatGpsInterruptSignal {
+ u_int32 ul_did; //!< \~english data ID
+ u_int8 uc_size; //!< \~english data size
+ u_int8 reserve; //!< \~english reserve
+ u_int8 uc_data; //!< \~english data content
+ u_int8 reserve2; //!< \~english reserve
+} LSDRV_MSG_LSDATA_DAT_GPS_INTERRUPT_SIGNAL;
+
+/**
+ * @struct LsdrvMsgLsdataGpsInterruptSignal
+ * \~english Struct of message about Gps interrupt signal
+ */
+typedef struct LsdrvMsgLsdataGpsInterruptSignal {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT_GPS_INTERRUPT_SIGNAL st_para; //!< \~english data of message
+} LSDRV_MSG_LSDATA_GPS_INTERRUPT_SIGNAL;
+
+/**
+ * @struct LsdrvMsgLsdataDatGyroConnectStatus
+ * \~english Struct of Gyro connect status
+ */
+typedef struct LsdrvMsgLsdataDatGyroConnectStatus {
+ u_int32 ul_did; //!< \~english data ID
+ u_int8 uc_size; //!< \~english data size
+ u_int8 reserve; //!< \~english reserve
+ u_int8 uc_data; //!< \~english data content
+ u_int8 reserve2; //!< \~english reserve
+} LSDRV_MSG_LSDATA_DAT_GYRO_CONNECT_STATUS;
+
+/**
+ * @struct LsdrvMsgLsdataGyroConnectStatus
+ * \~english Struct of message about Gyro connect status
+ */
+typedef struct LsdrvMsgLsdataGyroConnectStatus {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT_GYRO_CONNECT_STATUS st_para; //!< \~english data of message
+} LSDRV_MSG_LSDATA_GYRO_CONNECT_STATUS;
+
+/**
+ * @struct LsdrvMsgLsdataDatGpsAntennaStatus
+ * \~english Struct of Gps Antenna Status
+ */
+typedef struct LsdrvMsgLsdataDatGpsAntennaStatus {
+ u_int32 ul_did; //!< \~english data ID
+ u_int8 uc_size; //!< \~english data size
+ u_int8 uc_rcv_flag; //!< \~english receive flag
+ u_int8 uc_sns_cnt; //!< \~english sensor count
+ u_int8 uc_data; //!< \~english data content
+} LSDRV_MSG_LSDATA_DAT_GPS_ANTENNA_STATUS;
+
+/**
+ * @struct LsdrvMsgLsdataGpsAntennaStatus
+ * \~english Struct of message about Gps Antenna Status
+ */
+typedef struct LsdrvMsgLsdataGpsAntennaStatus {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT_GPS_ANTENNA_STATUS st_para; //!< \~english data of message
+} LSDRV_MSG_LSDATA_GPS_ANTENNA_STATUS;
+
+/**
+ * @struct LsdrvLsdataFst
+ * \~english Struct of sensor data (first sensor message)
+ */
+typedef struct LsdrvLsdataFst {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 uc_size; //!< \~english data size
+ u_int8 uc_partition_max; //!< \~english total of partition
+ u_int8 uc_partition_num; //!< \~english data number
+ u_int8 uc_data[60]; //!< \~english data contents
+} LSDRV_LSDATA_FST;
+
+/**
+ * @struct LsdrvMsgLsdataFst
+ * \~english Struct of message about sensor data (first sensor message)
+ */
+typedef struct LsdrvMsgLsdataFst {
+ T_APIMSG_MSGBUF_HEADER st_head; //!< \~english message header
+ LSDRV_MSG_LSDATA_DAT_FST st_para; //!< \~english data of message
+} LSDRV_MSG_LSDATA_FST;
+
+/**
+ * @struct SensorMsgGpsdataDat
+ * \~english Struct of Gps data
+ * \~english @par Detail
+ * This data structure can have 7 types of data that identified by data ID.\n
+ * The contents are as follows.\n
+ * | data ID | content | data format |
+ * |:----------------------------------|:------------------------------------------|:------------------------------|
+ * | @ref POSHAL_DID_GPS_NMEA | NMEA data | @ref MdevGpsNmea "MDEV_GPS_NMEA" |
+ * | @ref POSHAL_DID_GPS_CUSTOMDATA | GPS custom data | @ref MdevGpsCustomDataMgs "MDEV_GPS_CUSTOMDATA" |
+ * | @ref POSHAL_DID_GPS_CLOCK_DRIFT | clock drift | @ref int32_t |
+ * | @ref POSHAL_DID_GPS_CLOCK_FREQ | clock frequency | @ref int32_t |
+ * | @ref POSHAL_DID_GPS_WKNROLLOVER | GPS week number | @ref SensorWknRollOverHal |
+ * | @ref POSHAL_DID_GPS_CONNECT_ERROR | GPS signal error(TRUE:Error, FALSE:Normal)| @ref BOOL |
+ * | @ref POSHAL_DID_GPS_TIME (_RAW) | GPS time information | @ref SENSOR_GPSTIME |
+ */
+typedef struct SensorMsgGpsdataDat {
+ u_int32 ul_did; //!< \~english data ID
+ u_int16 us_size; //!< \~english data size
+ u_int8 uc_rcv_flag; //!< \~english receive flag
+ u_int8 uc_sns_cnt; //!< \~english sensor count
+ u_int8 uc_gps_cnt_flag; //!< \~english GPS count
+ u_int8 reserve[3]; //!< \~english reserve
+ u_int8 uc_data[SENSOR_MSG_VSINFO_DSIZE]; //!< \~english data contents
+} SENSOR_MSG_GPSDATA_DAT;
+
+/**
+ * @struct SensorMsgGpsdata
+ * \~english Struct of message about GPS data
+ */
+typedef struct SensorMsgGpsdata {
+ T_APIMSG_MSGBUF_HEADER st_head;
+ //!< \~english message header(see vs-positioning-base-library)
+ SENSOR_MSG_GPSDATA_DAT st_para;
+ //!< \~english data of message
+} SENSOR_MSG_GPSDATA;
+
+/**
+ * @struct TG_GPS_RET_TIMESET_MSG
+ * \~english Struct of message about GPS time set response
+ */
+typedef struct {
+ T_APIMSG_MSGBUF_HEADER header; //!< \~english message header
+ uint64_t status; //!< \~english response status
+} TG_GPS_RET_TIMESET_MSG;
+
+/**
+ * @struct TG_GPS_NMEA_SENTENCE_INFO
+ * \~english Struct of GPS NMEA sentence info
+ */
+typedef struct {
+ uint8_t uc_size; //!< \~english sentence size
+ uint8_t reserve; //!< \~english reserve
+ uint16_t us_offset; //!< \~english sentence start offset
+} TG_GPS_NMEA_SENTENCE_INFO;
+
+/**
+ * @struct TG_GPS_NMEA_INFO
+ * \~english Struct of GPS NMEA info
+ */
+typedef struct {
+ uint32_t ul_rcvsts; //!< \~english NMEA receive info
+ uint8_t reserve[4]; //!< \~english reserve
+ TG_GPS_NMEA_SENTENCE_INFO st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_MAX];
+ //!< \~english sentence infomation
+} TG_GPS_NMEA_INFO;
+
+/////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup positioning_hal
+/// \~english @par Brief
+/// - start thread of NMEA analysis and delivery message
+/// \~english @param [in] h_app
+/// HANDLE - handle
+///
+/// \~english @retval eFrameworkunifiedStatusOK Success
+/// \~english @retval eFrameworkunifiedStatusFail Failed
+///
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - This API can not change internal state
+/// \~english @par Conditions of processing failure
+/// - None
+/// \~english @par Detail
+/// - start thread of NMEA analysis and delivery message
+/// - the API can only be used by 1 process
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @see
+/// None
+/////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus StartGpsMainThreadPositioning(HANDLE h_app);
+
+/////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup positioning_hal
+/// \~english @par Brief
+/// - start thread for receive GPS manager
+/// \~english @param [in] h_app
+/// HANDLE - handle
+///
+/// \~english @retval eFrameworkunifiedStatusOK Success
+/// \~english @retval eFrameworkunifiedStatusFail Failed
+///
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - This API can not change internal state.
+/// \~english @par Conditions of processing failure
+/// - None
+/// \~english @par Detail
+/// - start model for receive GPS manager
+/// - the API can only be used by 1 process
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @see
+/// None
+/////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus StartGpsRecvThreadPositioning(HANDLE h_app);
+
+/////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup positioning_hal
+/// \~english @par Brief
+/// - start thread for receive sensor
+/// \~english @param [in] h_app
+/// HANDLE - handle
+///
+/// \~english @retval eFrameworkunifiedStatusOK Success
+/// \~english @retval eFrameworkunifiedStatusFail Failed
+///
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - This API can not change internal state.
+/// \~english @par Conditions of processing failure
+/// - None
+/// \~english @par Detail
+/// - start thread for receive sensor
+/// - the API can only be used by 1 process
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @see
+/// None
+/////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus StartLineSensorThreadPositioning(HANDLE h_app);
+
+/////////////////////////////////////////////////////////////////////////////////////
+/// \ingroup positioning_hal
+/// \~english @par Brief
+/// - start monitoring thread of GPS rollover
+/// \~english @param [in] h_app
+/// HANDLE - handle
+///
+/// \~english @retval eFrameworkunifiedStatusOK Success
+/// \~english @retval eFrameworkunifiedStatusFail Failed
+///
+/// \~english @par Prerequisite
+/// - None
+/// \~english @par Change of internal state
+/// - This API can not change internal state.
+/// \~english @par Conditions of processing failure
+/// - The parameter hApp is NULL [eFrameworkunifiedStatusFail]
+/// - When fail to start thread. [return value of FrameworkunifiedStartChildThread]
+/// \~english @par Detail
+/// - start monitoring thread of GPS rollover
+/// - the API can only be used by 1 process
+/// \~english @par Classification
+/// Public
+/// \~english @par Type
+/// Sync
+/// \~english @see
+/// FrameworkunifiedCreateChildThread, FrameworkunifiedStartChildThread
+/////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus StartGpsRolloverThreadPositioning(HANDLE h_app);
+
+/** @}*/ // end of positioning_hal
+/** @}*/ // end of positioning
+
+/*---------------------------------------------------------------------------*/
+#endif // HAL_API_POSITIONING_HAL_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/Common/LineSensDrv_Api.h b/hal/positioning_hal/inc/Common/LineSensDrv_Api.h
new file mode 100755
index 0000000..24c7f55
--- /dev/null
+++ b/hal/positioning_hal/inc/Common/LineSensDrv_Api.h
@@ -0,0 +1,44 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file LineSensDrv_Api.h
+*/
+
+#ifndef INC_COMMON_LINESENSDRV_API_H_
+#define INC_COMMON_LINESENSDRV_API_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Define
+
+#define MUTEX_GPS_IRQ_FLG "MUTEX_GPS_IRQ_FLG"
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+void DeliveryLineSensorDataPositioning(LSDRV_MSG_LSDATA_G*, u_int8);
+BOOL LineSensDrvApiInitialize(void);
+void LineSensDrvApiInitEstGpsCnt(void);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_COMMON_LINESENSDRV_API_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/Common/MDev_Gps_API.h b/hal/positioning_hal/inc/Common/MDev_Gps_API.h
new file mode 100755
index 0000000..d165a1e
--- /dev/null
+++ b/hal/positioning_hal/inc/Common/MDev_Gps_API.h
@@ -0,0 +1,51 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_API.h
+*/
+
+#ifndef INC_COMMON_MDEV_GPS_API_H_
+#define INC_COMMON_MDEV_GPS_API_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "gps_hal.h"
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+RET_API SendNmeaGps(const MDEV_GPS_NMEA* p_nmea_data);
+RET_API SendCustomGps(const SENSOR_MSG_GPSTIME* p_gps_time,
+ const SENSORLOCATION_LONLATINFO_DAT* p_lonlat,
+ const SENSORLOCATION_ALTITUDEINFO_DAT* p_altitude,
+ const SENSORMOTION_HEADINGINFO_DAT* p_heading,
+ const NAVIINFO_DIAG_GPS* p_diag_data);
+RET_API SendSpeedGps(const SENSORMOTION_SPEEDINFO_DAT* p_seed, u_int16 us_peed);
+RET_API SendTimeGps(const MDEV_GPS_RTC* p_rtc);
+RET_API SendClockDriftGps(int32_t drift);
+RET_API SendClockFrequencyGps(uint32_t freq);
+RET_API DevGpsSndWknRollover(const SensorWknRollOverHal* p_week_rollover);
+int32 DevGpsRstAnsSend(PNO u_pno, RID uc_rid, u_int32 ul_rst_sts);
+int32 DevGpsTimesetAnsSend(PNO u_pno, RID uc_rid, u_int32 ul_rst_sts);
+RET_API DevSendGpsConnectError(BOOL);
+RET_API SndGpsTimeRaw(const SENSOR_GPSTIME_RAW* pst_gpstime_raw);
+/*---------------------------------------------------------------------------*/
+#endif // INC_COMMON_MDEV_GPS_API_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/Common/positioning_common.h b/hal/positioning_hal/inc/Common/positioning_common.h
new file mode 100755
index 0000000..dad0272
--- /dev/null
+++ b/hal/positioning_hal/inc/Common/positioning_common.h
@@ -0,0 +1,63 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file positioning_common.h
+*/
+
+#ifndef INC_COMMON_POSITIONING_COMMON_H_
+#define INC_COMMON_POSITIONING_COMMON_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Definition
+
+/*---------------------------------------------------------------------------*/
+// ENUMERATION
+
+/*---------------------------------------------------------------------------*/
+// STRUCTURE
+
+typedef struct PosResetinfo {
+ uint8_t mode; // Reset mode
+ uint8_t reserve[3]; // reserve
+ PNO sndpno; // Caller PNO
+ PNO respno; // Destination PNO
+} POS_RESETINFO;
+
+/*!
+ @brief Thread activation information
+*/
+typedef struct StThreadSetupInfo {
+ EnumSetupMode_POS mode; // Thread activation mode
+} ST_THREAD_SETUP_INFO;
+
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+EFrameworkunifiedStatus PosInitialize(HANDLE h_app);
+EnumSetupMode_POS PosSetupThread(HANDLE h_app, EnumTID_POS e_tid);
+void PosTeardownThread(EnumTID_POS e_tid);
+EFrameworkunifiedStatus PosCreateThread(HANDLE h_app, int8_t index);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_COMMON_POSITIONING_COMMON_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/Common/positioning_def.h b/hal/positioning_hal/inc/Common/positioning_def.h
new file mode 100755
index 0000000..df95cb3
--- /dev/null
+++ b/hal/positioning_hal/inc/Common/positioning_def.h
@@ -0,0 +1,307 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file positioning_def.h
+*/
+
+#ifndef INC_COMMON_POSITIONING_DEF_H_
+#define INC_COMMON_POSITIONING_DEF_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include <string.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+
+#include <native_service/frameworkunified_types.h>
+#include <native_service/frameworkunified_application.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <native_service/frameworkunified_multithreading.h>
+#include <native_service/frameworkunified_service_protocol.h>
+#include <vehicle_service/std_types.h>
+#include <vehicle_service/pos_message_header.h>
+#include <vehicle_service/sys_timerapi.h>
+#include <vehicle_service/WPF_STD.h>
+
+#include "gps_hal.h"
+#include "positioning_hal.h"
+
+#include "positioning_log.h"
+
+/*---------------------------------------------------------------------------*/
+// Definition
+
+#define POS_THREAD_NAME "Positioning"
+
+/**
+ * @enum ENUM_GPS_NMEA_INDEX
+ * \~english NMEA index
+ */
+typedef enum {
+ GPS_NMEA_INDEX_GGA = 0, //!< \~english GGA
+ GPS_NMEA_INDEX_DGGA, //!< \~english DGGA
+ GPS_NMEA_INDEX_VTG, //!< \~english VTG
+ GPS_NMEA_INDEX_RMC, //!< \~english RMC
+ GPS_NMEA_INDEX_DRMC, //!< \~english DRMC
+ GPS_NMEA_INDEX_GLL, //!< \~english GLL
+ GPS_NMEA_INDEX_DGLL, //!< \~english DGLL
+ GPS_NMEA_INDEX_GSA, //!< \~english GSA
+ GPS_NMEA_INDEX_GSV1, //!< \~english GSV1
+ GPS_NMEA_INDEX_GSV2, //!< \~english GSV2
+ GPS_NMEA_INDEX_GSV3, //!< \~english GSV3
+ GPS_NMEA_INDEX_GSV4, //!< \~english GSV4
+ GPS_NMEA_INDEX_GSV5, //!< \~english GSV5
+ GPS_NMEA_INDEX_GST, //!< \~english GST
+ GPS_NMEA_INDEX__CWORD44__GP_3, //!< \~english _CWORD44_,GP,3
+ GPS_NMEA_INDEX__CWORD44__GP_4, //!< \~english _CWORD44_,GP,4
+ GPS_NMEA_INDEX_P_CWORD82_F_GP_0, //!< \~english _CWORD44_,GP,0
+ GPS_NMEA_INDEX_P_CWORD82_J_GP_1, //!< \~english _CWORD44_,GP,1
+ GPS_NMEA_INDEX_MAX //!< \~english GGA
+} ENUM_GPS_NMEA_INDEX;
+
+//!< \~english Gps cycle Data Event
+#define GPS_EVT_CYCLEDATA_PROV ("GPS_EVT_CYCLEDATA_PROV")
+//!< \~english Event value: Waiting.
+#define GPS_EVT_PROV_WAIT (0x00000000)
+//!< \~english Event value: Clear Waiting status.
+#define GPS_EVT_PROV_RELEASE (0x00000001)
+
+//!< \~english Gps received
+#define GPS_CYCLECMD_NOTRCV (0x00)
+//!< \~english Gps no received
+#define GPS_CYCLECMD_RCV (0x01)
+
+//!< \~english store position of Hour data
+#define GPSCMD_DRMC_HOUR_POS (7)
+//!< \~english store position of minute data
+#define GPSCMD_DRMC_MIN_POS (9)
+//!< \~english store position of second data
+#define GPSCMD_DRMC_SEC_POS (11)
+//!< \~english store position of status
+#define GPSCMD_DRMC_STATUS_POS (14)
+//!< \~english store position of day data
+#define GPSCMD_DRMC_DAY_POS (54)
+//!< \~english store position of month data
+#define GPSCMD_DRMC_MONTH_POS (56)
+//!< \~english store position of year data
+#define GPSCMD_DRMC_YEAR_POS (58)
+
+//!< \~english store position of control code
+#define GPSCMD_RTC_CTRLCODE_POS (0)
+//!< \~english store position of year data (BCD)
+#define GPSCMD_RTC_BCD_YEAR_POS (1)
+//!< \~english store position of month data(BCD)
+#define GPSCMD_RTC_BCD_MONTH_POS (2)
+//!< \~english store position of day data(BCD)
+#define GPSCMD_RTC_BCD_DAY_POS (3)
+//!< \~english store position of hour data(BCD)
+#define GPSCMD_RTC_BCD_HOUR_POS (4)
+//!< \~english store position of minute data(BCD)
+#define GPSCMD_RTC_BCD_MIN_POS (5)
+//!< \~english store position of second data(BCD)
+#define GPSCMD_RTC_BCD_SEC_POS (6)
+//!< \~english store position of status
+#define GPSCMD_RTC_STATUS_POS (7)
+
+#define GPSCMD_RTC_CTRLCODE (0xA4) //!< \~english control code (RTC)
+#define GPSCMD_RTC_STATUS_UTCTIME (0x00) //!< \~english Normal
+#define GPSCMD_RTC_STATUS_ERRTIME (0x03) //!< \~english AbNormal
+
+// Internal thread activation status determination
+#define THREAD_STS_MSK_POS_MAIN (0x01)
+#define THREAD_STS_MSK_POS_SENS (0x02)
+#define THREAD_STS_MSK_POS_GPS (0x04)
+#define THREAD_STS_MSK_POS_GPS_RECV (0x08)
+#define THREAD_STS_MSK_POS_GPS_ROLLOVER (0x10)
+#define POS_DID_GPS_NMEA 0x8000009AU /* QAC 1281 */
+#define POS_DID_GPS_CLOCK_DRIFT 0x800000B3U /* QAC 1281 */
+#define POS_DID_GPS_CLOCK_FREQ 0x800000B4U /* QAC 1281 */
+#define VEHICLE_DID_GPS_CUSTOMDATA 0x80000094U
+#define VEHICLE_DID_GPS_CLOCK_DRIFT POS_DID_GPS_CLOCK_DRIFT
+#define VEHICLE_DID_GPS_CLOCK_FREQ POS_DID_GPS_CLOCK_FREQ
+#define CID_NAVIINFO_DELIVER (0x0205) /* Navigation information setting CID */
+#define CID_NAVIINFO_SPEED_DELIVER (0x0206) /* Vehicle speed setting CID */
+#define VEHICLE_DID_GPS_WKNROLLOVER 0x800000B2U
+#define VEHICLE_DID_GPS_TIME_RAW 0x800000B1
+#define POS_DID_GYRO_TEMP 0x80000090
+#define VEHICLE_DID_SPEED_PULSE 0x80000012
+#define VEHICLE_DID_GYRO_X 0x80000014
+#define VEHICLE_DID_GYRO_Y 0x80000020
+#define VEHICLE_DID_GYRO_Z 0x80000021
+#define VEHICLE_DID_GYRO VEHICLE_DID_GYRO_X
+#define VEHICLE_DID_REV 0x80000017
+#define VEHICLE_DID_SNS_COUNTER 0x8000001A
+#define VEHICLE_DID_GPS_COUNTER 0x8000001B
+#define VEHICLE_DID_GYRO_EXT 0x80000027 /* 3 ~ 14bit A/D value,0bit:REV */
+#define VEHICLE_DID_SPEED_PULSE_FST 0x80000028 /* Pulse(Number) */
+#define VEHICLE_DID_GYRO_FST_X 0x80000029
+#define VEHICLE_DID_GYRO_FST_Y 0x80000022
+#define VEHICLE_DID_GYRO_FST_Z 0x80000023
+#define VEHICLE_DID_GYRO_FST VEHICLE_DID_GYRO_FST
+#define VEHICLE_DID_GYRO_TEMP POS_DID_GYRO_TEMP
+#define VEHICLE_DID_SPEED_KMPH 0x80000013
+#define VEHICLE_DID_GSNS_X 0x80000015
+#define VEHICLE_DID_GSNS_Y 0x80000016
+#define VEHICLE_DID_GSNS_Z 0x80000024
+#define VEHICLE_DID_PULSE_TIME 0x8000003A
+#define CID__CWORD83__CMD_RCV 0x0103
+#define CID__CWORD83__CMD_SND_STS 0x0104
+#define CID_GPS_SERIAL0 (CID)0x0100
+#define CID_GPS_REQRESET (CID)(CID_GPS_BASE | CID_GPS_SERIAL0)
+
+#define VEHICLE_CONFIG_GPS_UNITSET_NOGPS (0x00U) //!< \~english no Gps
+#define VEHICLE_CONFIG_GPS_UNITSET__CWORD82_ (0x01U) //!< \~english _CWORD82_ Gps
+#define VEHICLE_CONFIG_GPS_UNITSET_EXTBOX (0x02U) //!< \~english extern u-blox
+
+//!< \~english no Navi
+#define VEHICLE_CONFIG_NAVI_FUNCTION_NONAVI (0x00U)
+//!< \~english Navi has AW navi
+#define VEHICLE_CONFIG_NAVI_FUNCTION_AWNAVI (0x01U)
+
+#define VEHICLE_GPS_SYSTIME_YEAR_MAX (2085U) //!< \~english Gps Time allowed max year
+#define VEHICLE_GPS_SYSTIME_MONTH_MAX (12U) //!< \~english Gps Time allowed max month
+#define VEHICLE_GPS_SYSTIME_DAY_MAX (31U) //!< \~english Gps Time allowed max day
+#define VEHICLE_GPS_SYSTIME_HOUR_MAX (23U) //!< \~english Gps Time allowed max hour
+#define VEHICLE_GPS_SYSTIME_MINUTE_MAX (59U) //!< \~english Gps Time allowed max minute
+#define VEHICLE_GPS_SYSTIME_SECOND_MAX (59U) //!< \~english Gps Time allowed max second
+
+#define VEHICLE_GPS_SYSTIME_YEAR_MIN (1986U) //!< \~english Gps Time allowed min year
+#define VEHICLE_GPS_SYSTIME_MONTH_MIN (1U) //!< \~english Gps Time allowed min month
+#define VEHICLE_GPS_SYSTIME_DAY_MIN (1U) //!< \~english Gps Time allowed min day
+#define VEHICLE_GPS_SYSTIME_HOUR_MIN (0U) //!< \~english Gps Time allowed min hour
+#define VEHICLE_GPS_SYSTIME_MINUTE_MIN (0U) //!< \~english Gps Time allowed min minute
+#define VEHICLE_GPS_SYSTIME_SECOND_MIN (0U) //!< \~english Gps Time allowed min second
+#define VEHICLE_EVENT_VAL_INIT (-14) /* Event initial value */
+//!< \~english check OK (value not change)
+#define MDEV_GPS_SRAM_CHK_OK (0)
+//!< \~english check OK(vaule change)
+#define MDEV_GPS_SRAM_CHK_CHG (1)
+//!< \~english check NG
+#define MDEV_GPS_SRAM_CHK_NG (-1)
+
+/*---------------------------------------------------------------------------*/
+// ENUMERATION
+
+/*!
+ @brief Positioning operating status definitions
+*/
+typedef enum EnumExeStsPos {
+ EPOS_EXE_STS_STOP = 0, /* Stopped */
+ EPOS_EXE_STS_RUNNING, /* Running (from FrameworkunifiedOnStart to FrameworkunifiedOnStop) */
+ EPOS_EXE_STS_RUNNING_COLDSTART /* Running after cold start */
+} EnumExeSts_POS;
+
+/*!
+ @brief Positioning Thread Startup Modes
+*/
+typedef enum EnumSetupModePos {
+ EPOS_SETUP_MODE_NORMAL = 0, /* Normal start */
+ EPOS_SETUP_MODE_DATA_RESET /* Data reset start */ /* QAC 930 */
+} EnumSetupMode_POS;
+
+/**
+ * @struct TG_GPS_RCV_DATA
+ * \~english Struct of Gps receive data for VehicleSens
+ */
+typedef struct TgGpsRcvData {
+ uint32_t dwret_status; //!< \~english return status
+ uint16_t bydata_len; //!< \~english data length
+ uint8_t bygps_data[GPS_READ_LEN]; //!< \~english receive data
+ uint8_t u_reserve2[2]; //!< \~english reserve
+} TG_GPS_RCV_DATA;
+
+/**
+ * @struct TG_GPS_NMEA_DAT
+ * \~english Struct of NMEA data
+ */
+typedef struct TgGpsNmeaDat {
+ u_int8 uc_data[GPS_NMEA_MAX_SZ]; //!< \~english NMEA data
+} TG_GPS_NMEA_DAT;
+
+/**
+ * @struct TG_GPS_CYCLEDATA_NMEA
+ * \~english Struct of NMEA cycle data
+ */
+typedef struct TgGpsCycledataNmea {
+ //!< \~english receive flag
+ u_int8 uc_rcvflag[GPS_NMEA_INDEX_MAX];
+ //!< \~english reserve
+ u_int8 u_reserve[3];
+ //!< \~english structure of NMEA data
+ TG_GPS_NMEA_DAT st_nmea[GPS_NMEA_INDEX_MAX];
+} TG_GPS_CYCLEDATA_NMEA;
+
+/**
+ * @struct TG_GPS_CYCLEDATA_BINARY
+ * \~english Struct of binary cycle data
+ */
+typedef struct TgGpsCycledataBinary {
+ u_int8 uc_rcvflag; //!< \~english receive flag
+ u_int8 u_reserve[3]; //!< \~english reserve
+ u_int8 uc_data[GPS_CMD_BINARY_SZ]; //!< \~english binary data
+ u_int8 u_reserve2[3]; //!< \~english reserve flag
+} TG_GPS_CYCLEDATA_BINARY;
+
+/**
+ * @struct TG_GPS_CYCLEDATA_FULLBIN
+ * \~english Struct of full bin cycle data
+ */
+typedef struct TgGpsCycledataFullbin {
+ u_int8 uc_rcvflag; //!< \~english receive flag
+ u_int8 u_reserve[3]; //!< \~english reserve
+ u_int8 uc_data[GPS_CMD_FULLBIN_SZ]; //!< \~english fullbin data
+ u_int8 u_reserve2; //!< \~english reserve
+} TG_GPS_CYCLEDATA_FULLBIN;
+
+/**
+ * @struct TG_GPS_CYCLEDATA_RTC
+ * \~english Struct of RTC cycle data
+ */
+typedef struct TgGpsCycledataRtc {
+ u_int8 uc_rcvflag; //!< \~english receive flag
+ u_int8 u_reserve[3]; //!< \~english reserve
+ u_int8 uc_data[GPS_DATASIZE_RTC]; //!< \~english Rtc data
+} TG_GPS_CYCLEDATA_RTC;
+
+/**
+ * @struct TG_GPS_CYCLEDATA
+ * \~english Struct of Gps cycle data
+ */
+typedef struct TgGpsCycledata {
+ u_int8 uc_sesncnt; //!< \~english count value
+ u_int8 u_reserve[3]; //!< \~english reserve
+ TG_GPS_CYCLEDATA_NMEA st_nmea_data; //!< \~english NMEA Data
+ TG_GPS_CYCLEDATA_BINARY st_binary_data; //!< \~english binary Data
+ TG_GPS_CYCLEDATA_FULLBIN st_fullbin_data; //!< \~english Full Bin Data
+ TG_GPS_CYCLEDATA_RTC st_rtc_data; //!< \~english RTC Data
+} TG_GPS_CYCLEDATA;
+
+typedef struct {
+ u_int16 year; /* YEAR */
+ u_int8 month; /* MONTH */
+ u_int8 date; /* DAY */
+ u_int8 hour; /* HOUR */
+ u_int8 minute;/* MINUTE */
+ u_int8 second;/* SECOND */
+ u_int8 flag; /* Whether or not the time is set */
+} ST_GPS_SET_TIME;
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_COMMON_POSITIONING_DEF_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/Common/positioning_log.h b/hal/positioning_hal/inc/Common/positioning_log.h
new file mode 100755
index 0000000..6ca4c96
--- /dev/null
+++ b/hal/positioning_hal/inc/Common/positioning_log.h
@@ -0,0 +1,43 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file positioning_log.h
+*/
+
+#ifndef INC_COMMON_POSITIONING_LOG_H_
+#define INC_COMMON_POSITIONING_LOG_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include <stdio.h>
+
+/*---------------------------------------------------------------------------*/
+// Definition
+
+// #define POSITIONING_DEBUG
+
+#ifdef POSITIONING_DEBUG
+#define POSITIONING_LOG(...) printf(__VA_ARGS__)
+#else
+#define POSITIONING_LOG(...)
+#endif
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_COMMON_POSITIONING_LOG_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_GpsRecv.h b/hal/positioning_hal/inc/GpsCommon/MDev_GpsRecv.h
new file mode 100755
index 0000000..6ea4787
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_GpsRecv.h
@@ -0,0 +1,170 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_GpsRecv.h
+*/
+
+#ifndef INC_GPSCOMMON_MDEV_GPSRECV_H_
+#define INC_GPSCOMMON_MDEV_GPSRECV_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "gps_hal.h"
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Define
+
+/* ++ GPS _CWORD82_ support */
+#define GPS__CWORD82__CMD_LEN_MAX 200
+/* -- GPS _CWORD82_ support */
+
+/* ++ GPS _CWORD82_ support */
+#define GPS__CWORD82__RET_START_SEQ_NONE 0 /* _CWORD82_ Start Sequence Determination Result = None */
+#define GPS__CWORD82__RET_START_SEQ_NMEA 1 /* _CWORD82_ Start Sequence Determination Result = NMEA */
+#define GPS__CWORD82__RET_START_SEQ_FULL 2 /* _CWORD82_ Start Sequence Determination Result = Full customization */
+#define GPS__CWORD82__RET_START_SEQ_BIN 3 /* _CWORD82_ Start Sequence Determination Result = Standard binary #GPF_60_024 */
+
+#define GPS_UBLOX_RET_START_SEQ_UBX 4 /* Ublox Start Sequence Decision Result = UBX Protocol (binary) */
+#define GPS__CWORD82__FULLBINARY_LEN GPS_CMD_FULLBIN_SZ /* _CWORD82_ Full Customization Instruction Length */
+
+#define GPS__CWORD82__NORMALBINARY_LEN 81 /* _CWORD82_ standard binary instruction length #GPF_60_024 */
+/* -- GPS _CWORD82_ support */
+
+/* Maximum size of serial data read */
+#define GPS_RCV_MAXREADSIZE (2048) /* Changed from 256 -> 2048 #01 */
+
+/* Receive data storage buffer size */
+#define GPS_RCV_RCVBUFSIZE 512 /* Maximum size of the command to be received must be larger than the maximum size */
+
+/* Max-size receive commands ID4:(188+8)byte */
+/* Analysis data buffer size */
+#define GPS_RCV_ANADATABUFSIZE (GPS_RCV_MAXREADSIZE + GPS_RCV_RCVBUFSIZE)
+
+/* Receive frame buffer size */
+#define GPS_RCV_RCVFRAMEBUFSIZE GPS_RCV_RCVBUFSIZE /* Maximum size of the command to be received must be larger than the maximum size */
+
+/* Reception notification data buffer size */
+#define GPS_RCV_SNDCMD_SIZE_MAX
+
+/* Common return values */
+#define GPS_RCV_RET_ERR_EXT (-4) /* External cause error */
+#define GPS_RCV_RET_ERR_SYSTEM (-3) /* System error */
+#define GPS_RCV_RET_ERR (-1) /* Abnormality */
+#define GPS_RCV_RET_NML 0 /* Normal */
+
+// Reception thread reception frame detection result
+#define GPS_RCV_FRMSRCH_ERR_FORMAT (-1) /* Frame format error */
+#define GPS_RCV_FRMSRCH_FIXED 0 /* Frame determination */
+#define GPS_RCV_FRMSRCH_NOT_FIXED 1 /* Frame undetermined */
+#define GPS_RCV_FRMSRCH_NO_DATA 2 /* No analysis data */
+
+// Result of receive thread receive frame analysis
+#define GPS_RCV_FRMANA_ERR_PRM (-3) /* Parameter error */
+#define GPS_RCV_FRMANA_ERR_FORMAT (-2) /* Frame format error */
+#define GPS_RCV_FRMANA_ERR_CS (-1) /* Sumcheck error */
+#define GPS_RCV_FRMANA_OK 0 /* Normal data */
+
+/* Serial reception event determination result */
+enum GpsRcvRet {
+ GPS_RCV_REVT_NML = 0, /* Receiving(Normal) */
+ GPS_RCV_REVT_ERR, /* Receiving(Error) */
+ GPS_RCV_REVT_NUM /* Number of events received */
+};
+
+// Error logging
+#define ERLG_SER_FRAMEERR "Serial Framing Error"
+#define ERLG_SER_OVERRUNERR "Serial Overrun Error"
+#define ERLG_SER_PARITYERR "Serial Parity Error"
+#define ERLG_RCVEV_JDGERR "DEV_Gps_Recv_JdgSerEvt error"
+#define ERLG_RCVDATA_SNDERR "DEV_Gps_Recv_SndRcvData error"
+#define ERLG_COMEVNT_WAITERR "WaitCommEvent error"
+
+/*---------------------------------------------------------------------------*/
+// Struct
+
+// Serial receive buffer structure
+typedef struct GPSRecvData {
+ u_int16 us_read_size; /* Serial data read data size */
+ u_int8 uc_reserve[2]; /* Preliminary */
+ u_int8 uc_read_data[GPS_RCV_MAXREADSIZE]; /* Serial read data */
+} TG_GPS_RECV_RcvData;
+
+// Receive data storage buffer structure
+typedef struct GPSRecvBuf {
+ u_int16 r_size; /* Received size */
+ u_int8 rsv[2]; /* Reserved */
+ u_int8 r_buf[GPS_RCV_RCVBUFSIZE]; /* Receive command data */
+} TG_GPS_RECV_RcvBuf;
+
+// Data analysis buffer
+typedef struct GPSRecvAnaDataBuf {
+ u_int16 datsize; /* Size of the data */
+ u_int16 offset; /* Analysis start offset */
+ u_int8 datbuf[GPS_RCV_ANADATABUFSIZE]; /* Analysis data */
+} TG_GPS_RECV_AnaDataBuf;
+
+// Receive frame buffer
+typedef struct GPSRecvFrameBuf {
+ u_int16 size; /* Frame-size */
+ u_int8 rsv[2]; /* Reserved */
+ u_int8 buf[GPS_RCV_RCVFRAMEBUFSIZE]; /* Command data */
+} TG_GPS_RECV_RcvFrameBuf;
+
+/*---------------------------------------------------------------------------*/
+// External variable
+
+extern TG_GPS_RECV_RcvData g_gps_rcvdata; /* Serial receive buffer */
+extern TG_GPS_RECV_RcvBuf g_gps_rcvbuf; /* Receive data storage buffer */
+extern TG_GPS_RECV_AnaDataBuf g_gps_ana_databuf; /* Analysis data buffer */
+extern TG_GPS_RECV_RcvFrameBuf g_gps_rcv_framebuf; /* Receive frame buffer */
+extern u_int16 g_wrecv_err; /* Number of reception errors */
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+/* Initializing process */
+void DevGpsRecvInit(void);
+
+/* Buffer clear processing */
+void DevGpsRecvClrRcvBuf(void);
+
+/* Receive (normal) receive processing */
+void DevGpsRecvRcvNormal(void);
+
+/* Data reception processing */
+int32 DevGpsRecvReadRcvData(TG_GPS_RECV_RcvData* pst_rcv_data);
+
+/* Frame detection processing */
+int32 DevGpsRecvSearchFrameData(const TG_GPS_RECV_AnaDataBuf *adbuf_p, u_int16 *ana_size);
+
+/* Receive data transmission processing */
+void DevGpsRecvSndRcvData(const TG_GPS_RECV_RcvFrameBuf *p_frame_buf);
+
+/* Acknowledgement */
+RET_API DevRcvData(const TG_GPS_RCV_DATA* ptg_rcv_data);
+
+/* Pos_Gps_Recv Thread Stop Processing */
+void DevGpsRecvThreadStopProcess(void);
+
+EFrameworkunifiedStatus DevGpsRecvThread(HANDLE h_app);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_GPSCOMMON_MDEV_GPSRECV_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_GpsRollOver.h b/hal/positioning_hal/inc/GpsCommon/MDev_GpsRollOver.h
new file mode 100755
index 0000000..22da3c9
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_GpsRollOver.h
@@ -0,0 +1,34 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_GpsRollOver.h
+*/
+#ifndef INC_GPSCOMMON_MDEV_GPSROLLOVER_H_
+#define INC_GPSCOMMON_MDEV_GPSROLLOVER_H_
+
+#include <vehicle_service/WPF_STD.h>
+
+typedef struct TimRolovrYMD {
+ u_int16 year;
+ u_int16 month;
+ u_int16 day;
+ u_int8 dummy[2];
+} TG_TIM_ROLOVR_YMD;
+
+
+void GPSRollOverConvTime(TG_TIM_ROLOVR_YMD* base_ymd, TG_TIM_ROLOVR_YMD* conv_ymd, u_int8 gpsweekcorcnt);
+
+#endif // INC_GPSCOMMON_MDEV_GPSROLLOVER_H_
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Common.h b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Common.h
new file mode 100755
index 0000000..7812858
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Common.h
@@ -0,0 +1,187 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Common.h
+*/
+
+#ifndef INC_GPSCOMMON_MDEV_GPS_COMMON_H_
+#define INC_GPSCOMMON_MDEV_GPS_COMMON_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "positioning_def.h"
+#include "MDev_Gps_Main.h"
+
+/*---------------------------------------------------------------------------*/
+// Define
+
+#define NMEA_CHECKSUM_CHAR '*' /* *## (HEX) */
+#define NMEA_DATA_SEPARATOR ','
+
+#define GPS_NMEA_FIELD_LEN_MAX (GPS_NMEA_MAX_SZ)
+
+// NMEA GGA Sentence
+/* Fix Status */
+#define GPS_NMEA_GGA_FIX_STATUS_NON 0 /* invalid */
+#define GPS_NMEA_GGA_FIX_STATUS_GPS 1 /* GPS SPS Mode, Fix valid */
+#define GPS_NMEA_GGA_FIX_STATUS_DGPS 2 /* DGPS SPS Mode, Fix valid */
+#define GPS_NMEA_GGA_FIX_STATUS_DR 6 /* Estimated/Dead Reckoning */
+/* Field No */
+#define GPS_NMEA_FNO_GGA_FS 6
+#define GPS_NMEA_FNO_GGA_MSL 9
+
+/* number of SV Fields */
+#define GPS_NMEA_NUM_GSA_SV 12
+/* Fix Status */
+#define GPS_NMEA_GSA_FIX_STS_NON 1
+#define GPS_NMEA_GSA_FIX_STS_2D 2
+#define GPS_NMEA_GSA_FIX_STS_3D 3
+/* Field No */
+#define GPS_NMEA_FNO_GSA_FS 2
+#define GPS_NMEA_FNO_GSA_SV 3
+
+/* number of Satellite Infomation Fields (sv+elv+az+cno) */
+#define GPS_NMEA_NUM_GSV_SINFO 4
+ /* Field No */
+#define GPS_NMEA_FNO_GSV_NOSV 3
+#define GPS_NMEA_FNO_GSV_SV 4
+#define GPS_NMEA_FNO_GSV_ELV 5
+#define GPS_NMEA_FNO_GSV_AZ 6
+#define GPS_NMEA_FNO_GSV_CNO 7
+
+#define GPS_NMEA_RMC_STS_INVALID 'V'
+#define GPS_NMEA_RMC_STS_VALID 'A'
+#define GPS_NMEA_RMC_IND_NORTH 'N'
+#define GPS_NMEA_RMC_IND_EAST 'E'
+
+/* Field No */
+#define GPS_NMEA_FNO_RMC_UTC 1
+#define GPS_NMEA_FNO_RMC_STATUS 2
+#define GPS_NMEA_FNO_RMC_LATITUDE 3
+#define GPS_NMEA_FNO_RMC_NS 4
+#define GPS_NMEA_FNO_RMC_LONGITUDE 5
+#define GPS_NMEA_FNO_RMC_EW 6
+#define GPS_NMEA_FNO_RMC_SPEED 7
+#define GPS_NMEA_FNO_RMC_COG 8
+#define GPS_NMEA_FNO_RMC_DATE 9
+
+// Diag Fix Count
+#define GPS_DIAG_FIX_COUNT_3D (0x01)
+#define GPS_DIAG_FIX_COUNT_2D (0x02)
+#define GPS_DIAG_FIX_COUNT_ELSE (0x04)
+
+/* GPS time setting related */
+#define GPS_SETTIME_RANGE 5 /* 5 seconds : Valid range of GPS time setting */
+#define GPS_TIME_RANGE 10 /* 10 seconds : GPS time change range */
+
+/* NAV-SVINFO logging status */
+#define GPS_NAVSVINFO_STS_INIT 0
+#define GPS_NAVSVINFO_STS_READY 1
+#define GPS_NAVSVINFO_STS_DONE 2
+#define GPS_NAVSVINFO_STS_SETTING 3
+
+/* Time setting information */
+#define GPS_TIME_RX 0 /* Time not set */
+#define GPS_TIME_ROLOVR 1 /* First GPS reception(for rollover) */
+#define GPS_TIME_SET 2 /* Time setting in progress */
+
+/*!
+ @brief Satellite position information
+*/
+typedef struct GpsSatelliteInfoStr {
+ uint8_t sv; /* Satellite number */
+ uint8_t elv; /* Height 0-99 */
+ uint16_t az; /* Orientation 0-359 */
+ uint8_t cno; /* Signal strength */
+ uint8_t sts; /* Reception status */
+} GpsSatelliteInfo;
+
+/*---------------------------------------------------------------------------*/
+// Global values
+
+extern BOOL g_gps_rcv_thread_stop;
+extern uint8_t g_is_gpstime_sts;
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+void ChangeStatusGpsCommon(u_int32 sts);
+void RtyResetGpsCommon(void);
+void SendRtyResetGpsCommon(void);
+void SendReqGpsCommon(void);
+void GPSResetReqGpsCommon(void);
+void CyclDataTimeOutGpsCommon(void);
+RET_API CheckFrontStringPartGpsCommon(const u_char *p_tartget, const u_char *p_start);
+int32 JudgeFormatGpsCommon(u_char *p_send_data, u_int32 ul_length, TG_GPS_OUTPUT_FORMAT *p_format);
+RET_API CheckSumGpsCommon(const u_int8 p_uc_data[], u_int32 ul_length, TG_GPS_OUTPUT_FORMAT e_cmd_info);
+u_int8 AtoHGpsCommon(u_int8 ascii);
+RET_API DevGpsSaveCmd(TG_GPS_SAVECMD *p_send_data);
+void SendSaveCmdGpsCommon(void);
+void DeleteSaveCmdGpsCommon(void);
+void DeleteAllSaveCmdGpsCommon(void);
+void RcvCyclCmdNmeaGpsCommon(u_int8 *p_uc_data, u_int32 ul_len, TG_GPS_OUTPUT_FORMAT s_output_format);
+int32 CheckSendCmdGpsCommon(const u_char *p_rcv_data, u_int32 ul_length, TG_GPS_OUTPUT_FORMAT *p_format);
+int32_t GetStringFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, char* p_dst, size_t size);
+double GetNumericFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
+int32 GetIntegerFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src);
+int32 GetLonLatFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
+u_int16 GetHeadingFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
+int32 GetAltitudeFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
+u_int16 GetSpeedFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
+void StopThreadGpsCommon(void);
+uint8_t JudgeFormatOrderGpsCommon(TG_GPS_OUTPUT_FORMAT s_format_1, TG_GPS_OUTPUT_FORMAT s_format_2);
+ENUM_GPS_NMEA_INDEX GetNmeaIdxGpsCommon(TG_GPS_OUTPUT_FORMAT s_output_format);
+void SendResetReqGpsCommon(void);
+
+
+void WriteGpsTimeToBackup(uint8_t flag, POS_DATETIME* pst_datetime);
+void DevGpsCommSettingTime(void);
+RET_API GpsSetPosBaseEvent(uint16_t snd_pno, int32_t event_val);
+uint8_t HardResetChkGpsCommon(void);
+void RcvCyclCmdExtGpsCommon(u_int8 *p_data, u_int32 len, TG_GPS_OUTPUT_FORMAT format);
+
+BOOL DevGpsRcvProcGpsResetResp(TG_GPS_RCV_DATA*);
+void DevGpsRcvProcTimeSetResp(TG_GPS_RCV_DATA*);
+void DevGpsRcvProcWknRolloverGetResp(TG_GPS_RCV_DATA* p_data);
+void DevGpsRcvProcNavSvinfoAddResp(TG_GPS_RCV_DATA* p_data);
+void DevGpsReadGpsTime(POS_DATETIME* p_st_datetime);
+RET_API DevGpsRcvProcCmnResp(TG_GPS_RCV_DATA* p_data, uint8_t cmd);
+RET_API DevGpsResetReq(PNO us_pno, RID uc_rid);
+void DevGpsSettingTime(POS_DATETIME* p_st_datetime);
+int DevGpsYMD2JD(int y, int m, int d);
+BOOL DevGpsYMD2GPSTIME(const int32 y, const int32 m, const int32 d,
+ const int32 hh, const int32 mm, const int32 ss,
+ u_int16* gpsw, u_int32* gpsws);
+void DevGpsSetChkSum(u_int8* uc_buffer, u_int32 ul_length);
+RET_API DevGpsCatPollReq(uint8_t *p_ublox_data, uint16_t kind);
+void DevGpsSetGpsweekcorcnt(void);
+RET_API DevGpsNavTimeUTCAddReq(void);
+RET_API DevGpsWknRolloverGetReq(void);
+BOOL DevGpsCheckGpsTime(uint16_t set_gpsw, uint32_t set_gpsws,
+ uint16_t rcv_gpsw, uint32_t rcv_gpsws, int32_t offset_range);
+
+void DevGpsCnvLonLatNavi(SENSORLOCATION_LONLATINFO_DAT* p_lonlat,
+ u_int8 fix_sts, int32 lon, int32 lat);
+void DevGpsCnvAltitudeNavi(SENSORLOCATION_ALTITUDEINFO_DAT* p_altitude,
+ u_int8 fix_sts, int32 alt);
+void DevGpsCnvHeadingNavi(SENSORMOTION_HEADINGINFO_DAT* p_heading,
+ u_int8 fix_sts, u_int16 heading);
+/*---------------------------------------------------------------------------*/
+#endif // INC_GPSCOMMON_MDEV_GPS_COMMON_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Main.h b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Main.h
new file mode 100755
index 0000000..d40cb0c
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Main.h
@@ -0,0 +1,311 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Main.h
+*/
+
+#ifndef INC_GPSCOMMON_MDEV_GPS_MAIN_H_
+#define INC_GPSCOMMON_MDEV_GPS_MAIN_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "gps_hal.h"
+#include "positioning_def.h"
+
+// #include "gps_hal.h"
+// #include "MDev_Gps_Nmea.h"
+// #include "LineSensDrv_Api.h"
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+#define OFF 0 /* OFF */
+#define ON 1 /* ON */
+#define OK 0 /* Normal */
+#define NG (-1L) /* Abnormality */
+#define DAT_END 0xff /* Exit code */
+
+// State
+typedef enum GpsMatrixSts {
+ GPS_STS_STARTUP = 0, /* Startup confirmation */
+ GPS_STS_NORMAL, /* In operation */
+ GPS_STS_SENT, /* Command sent status */
+ GPS_STS_NUM
+}TG_GPS_MATRIX_STS;
+
+// Event
+typedef enum GpsMatrixEvt {
+ GPS_EVT_SENDREQ = 0, /* Transmission request */
+ GPS_EVT_RESETREQ, /* GPS reset request */
+ GPS_EVT_RECVCYCLDAT, /* Cyclic reception command reception */
+ GPS_EVT_RECVRSPDAT, /* Receive response command */
+ GPS_EVT_TIMEOUT_RSPDAT, /* Response monitoring timeout */
+ GPS_EVT_TIMEOUT_CYCLDAT, /* Periodic reception data monitoring timeout */
+ GPS_EVT_TIMEOUT_NAVI, /* Navigation providing data monitoring timeout */
+ GPS_EVT_TIMEOUT_DIAGCLKGUARD, /* Diagnosis provision time guard monitoring timeout*/
+ GPS_EVT_ACC_OFF, /* In-function ACC-OFF instructions */
+ GPS_EVT_NAVI_LOCATIONINFO, /* Providing navigation information */
+ GPS_EVT_NAVI_SPEEDINFO, /* Navigation speed information service */
+ GPS_EVT_TIMESETTING, /* GPS time setting instruction */
+ GPS_EVT_TIMEOUT_NMEADATAGUARD, /* NMEA data-providing guard monitoring timeout*/
+ GPS_EVT_BACKUPDATA_LOAD, /* Backup data read request */
+ GPS_EVT_STOPREQ, /* Thread stop request */
+ GPS_EVT_WEEKCOR_CNT_NOTIFICATIO, /* GPS Week Adjustment Counter Notification */
+ GPS_EVT_TIMEOUT_RECOVERY, /* GPS error monitoring reset timer */
+ GPS_EVT_TIMEOUT_RECEIVERERR, /* GPS receiver anomaly detection timeout */
+ GPS_EVT_NUM
+} TG_GPS_MATRIX_EVT;
+
+typedef enum GpsOutputFormat {
+ GPS_FORMAT_MIN = -1, /* Minimum Receive Format(Initialization) */
+ GPS_FORMAT_BINARY, /* Standard binary */
+ GPS_FORMAT_FULLBIN, /* Full binary */
+ GPS_FORMAT_GGA, /* GGA */
+ GPS_FORMAT_DGGA, /* DGGA */
+ GPS_FORMAT_VTG, /* VTG */
+ GPS_FORMAT_RMC, /* RMC */
+ GPS_FORMAT_DRMC, /* DRMC */
+ GPS_FORMAT_GLL, /* GLL */
+ GPS_FORMAT_DGLL, /* DGLL */
+ GPS_FORMAT_GSA, /* GSA */
+ GPS_FORMAT_GSV1, /* GSV(1) */
+ GPS_FORMAT_GSV2, /* GSV(2) */
+ GPS_FORMAT_GSV3, /* GSV(3) */
+ GPS_FORMAT_GSV4, /* GSV(4) */
+ GPS_FORMAT_GSV5, /* GSV(5) */
+ GPS_FORMAT_GST, /* GST */
+ GPS_FORMAT__CWORD44__GP3, /* _CWORD44_,GP,3 */
+ GPS_FORMAT__CWORD44__GP4, /* _CWORD44_,GP,4 */
+ GPS_FORMAT_P_CWORD82_F_GP0, /* P_CWORD82_F,GP,0 */
+ GPS_FORMAT_P_CWORD82_J_GP1, /* P_CWORD82_J,GP,1 */
+ GPS_FORMAT_P_CWORD82_I_GP, /* P_CWORD82_I,GP */
+ GPS_FORMAT_P_CWORD82_E_GP0, /* P_CWORD82_E,GP,0 */
+ GPS_FORMAT_P_CWORD82_J_GP0, /* P_CWORD82_J,GP,0 */
+ GPS_FORMAT_P_CWORD82_E_GP2, /* P_CWORD82_E,GP,2 */
+ GPS_FORMAT_P_CWORD82_G_GP0, /* P_CWORD82_G,GP,0 */
+ GPS_FORMAT_P_CWORD82_J_GP7, /* P_CWORD82_J,GP,7 */
+ GPS_FORMAT_P_CWORD82_J_GP8, /* P_CWORD82_J,GP,8 */
+ GPS_FORMAT_MON_VER, /* MON-VER */
+ GPS_FORMAT_AID_INI, /* AID-INI */
+ GPS_FORMAT_ACK_ACKNACK, /* ACK-ACKNACK */
+ GPS_FORMAT_NAV_TIMEUTC, /* NAV-TIMEUTC */
+ GPS_FORMAT_NAV_CLOCK, /* NAV-CLOCK */
+ GPS_FORMAT_RXM_RTC5, /* RXM-RTC5 */
+ GPS_FORMAT_NAV_SVINFO, /* NAV-SVINFO */
+ GPS_FORMAT_CFG_NAVX5, /* CFG-NAVX5 */
+ GPS_FORMAT_NMEA, /* NMEA (Sentence unspecified) */
+ GPS_FORMAT_UBX, /* UBX Protocol (binary) */
+ GPS_FORMAT_MAX /* Maximum Receive Format */
+} TG_GPS_OUTPUT_FORMAT;
+
+// Return value
+#define RETRY_OFF 0 /* No retry */
+#define RETRY_ON 1 /* Retry exists */
+#define RETRY_OUT 2 /* Retry out */
+#define NG_RETRYOUT 4 /* Transmission failure retry out */
+
+#define GPSRET_NOPCMD (0) /* Non notification target command #GPF_60_024 */
+#define GPSRET_SNDCMD (1) /* Notification target command #GPF_60_024 */
+#define GPSRET_CMDERR (-1) /* No applicable command #GPF_60_024 */
+
+// Number of Retries
+#define SRSET_MAX 4 /* Maximum serial reset retry value */
+#define HRSET_MAX 3 /* Maximum value of hard reset retry */
+#define SNDNG_MAX 4 /* Maximum retry value of transmission failure */
+
+/* The actual number of retries is SNDNG_MAX-1. */
+#define GPS_RECV_ERR_MAX 5 /* Maximum number of reception errors #GPF_60_024 */
+
+// Others
+#define SAV_MAX 11
+#define GPS_ALTITUDE_INVALID_VAL (-1000000) /* Value when fix altitude is invalid */
+#define GPS_HEADING_INVALID_VAL 36100 /* Value when measurement orientation is invalid */
+
+#define GPS_RECVOK 0 /* Normal reception #13 */
+#define GPS_RECVNG 1 /* Reception error #13 */
+#define GPS_OVERRUN 2 /* Overrun detection #13 */
+#define GPS_PARITY 3 /* Parity detection #13 */
+#define GPS_FRAMING 4 /* Framing detection #13 */
+
+// For the communication management thread
+#define GPS_NON_RECV 0 /* Not received */
+#define GPS_RECV_ACK 1 /* ACK received */
+#define GPS_RECV_DATA 2 /* Receive response command */
+
+#define GPS_SEND_ERR_MAX 5 /* Maximum number of transmission errors */
+#define GPS_CNCT_ERR_MAX 5 /* Maximum number of connection errors */
+
+#define GPS_START_EVT "GPS_EVT" /* Interthread synchronization events */
+#define GPS_EVT_VAL 99 /* Event settings */
+#define GPS_MSGDAT_BUF_SZ 500 /* Receive message buffer size */
+
+// Definition for receive command analysis table #GPF_60_024
+#define SENTENCE_STR_MAX 12 /* Maximum string for judging sentence */
+
+#define SENSOR_MSG_VSINFO_DSIZE 1904 //!< \~english message body max size
+
+/*---------------------------------------------------------------------------*/
+// Structure
+
+/********************************************************************************
+ * TAG :TG_GPS_MNG
+ * ABSTRACT :GPS process management information
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsMng {
+ u_int32 sts; /* Matrix state */
+ u_int32 event; /* Matrix event code */
+ u_int32 rcvsts; /* Response reception status */
+ u_int32 sndcnt; /* Number of transmission attempts */
+ u_int32 hrsetcnt; /* Number of tries before hard reset */
+ u_int32 sndngcnt; /* Number of failed-to-send attempts */
+ TG_GPS_OUTPUT_FORMAT rcv_cmd; /* Types of received GPS commands */
+ TG_GPS_OUTPUT_FORMAT resp_cmd; /* Types of GPS commands during response monitoring */
+ PNO resp_pno; /* Destination PNO */
+ RID resp_rid; /* RID to be notified when responding */
+ u_int8 resp_rst_flag; /* Response command reset flag */
+ BOOL rcv_err_flag; /* GPS receiver error detection flag */
+} TG_GPS_MNG;
+
+/********************************************************************************
+ * TAG :TG_GPS_SAVECMD
+ * ABSTRACT :GPS process pending command
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsSaveCmd {
+ TG_GPS_SND_DATA sndcmd; /* Sending commands(_CWORD82_ command) */
+ PNO us_pno; /* Result notification destination process number(Unused) */
+ RID uc_rid; /* Result Notification Resource ID(Unused) */
+ u_int8 uc_rst; /* Reset flag */
+ TG_GPS_OUTPUT_FORMAT e_cmd_info; /* Command information */
+} TG_GPS_SAVECMD;
+
+/********************************************************************************
+ * TAG :TG_GPS_SAVEBUF
+ * ABSTRACT :GPS process pending buffer management information
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsSaveBuf {
+ u_int32 saveno; /* Current pending index number */
+ u_int32 sendno; /* Current send index number */
+ u_int32 bufsav; /* Number of pending buffers used */
+ TG_GPS_SAVECMD savebuf[SAV_MAX]; /* Pending buffer */
+} TG_GPS_SAVEBUF;
+
+/********************************************************************************
+ * TAG :TG_GPS_MSGRCV
+ * ABSTRACT :Receive message
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsMsgRcv {
+ T_APIMSG_MSGBUF_HEADER header; /* Message header */
+ u_int8 msgdat[SENSOR_MSG_VSINFO_DSIZE + 12];
+} TG_GPS_MSGRCV;
+
+/********************************************************************************
+ * TAG :TG_GPS_MSGEVTCHNG
+ * ABSTRACT :GPS message event translation table
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsMsgEvtChng {
+ u_int32 cid; /* Matrix state */
+ u_int32 event; /* Matrix event code */
+} TG_GPS_MSGEVTCHNG;
+
+/********************************************************************************
+ * TAG :TG_GPS_TIMEVTCHNG
+ * ABSTRACT :GPS timer ID and event translation table
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsTimEvtChng {
+ u_int16 tim_id; /* Timer ID information */
+ u_int16 reserve; /* Reserved */
+ u_int32 event; /* Matrix event code */
+} TG_GPS_TIMEVTCHNG;
+
+/********************************************************************************
+ * TAG :Gps_Jmp_Tbl
+ * ABSTRACT :GPS jump table
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsJmpTbl {
+ void (*func)( void ); /* Jump-to module */
+} TG_GPS_JMP_TBL;
+
+/********************************************************************************
+ * TAG :TG_GPS_CMD_ANA_TBL
+ * ABSTRACT :Receive command analysis table structure
+ * NOTE :
+ ********************************************************************************/
+typedef struct TgGpsCmdAnaTbl {
+ u_char c_sentence[SENTENCE_STR_MAX]; /* Sentence identifier */
+ u_int32 ul_length; /* Length of the command */
+ u_int32 ul_rcv_kind; /* Receiving type */
+ BOOL b_snd_cmd_flg; /* Command notification flag */
+ TG_GPS_OUTPUT_FORMAT e_rcv_format; /* Receive Format */
+} TG_GPS_CMD_ANA_TBL;
+
+/********************************************************************************
+ * TAG :TG_GPS_TIME_BCD
+ * ABSTRACT :Time information (BCD) structure
+ * NOTE :
+ ********************************************************************************/
+typedef struct GpsTimeBCD {
+ u_int8 uc_year; /* Year information */
+ u_int8 uc_month; /* Month information */
+ u_int8 uc_day; /* Day information */
+ u_int8 uc_hour; /* Time information */
+ u_int8 uc_min; /* Minute information */
+ u_int8 uc_sec; /* Second information */
+} TG_GPS_TIME_BCD;
+
+/*---------------------------------------------------------------------------*/
+// Global values
+
+#define MDEV_GPSMSGCHKC_MAX 10
+#define MDEV_PSTIMCHKC_MAX 11
+extern const TG_GPS_MSGEVTCHNG kGpsMsgchkC[MDEV_GPSMSGCHKC_MAX]; /* Ignore -> MISRA-C:2004 Rule 8.12 */
+extern const TG_GPS_TIMEVTCHNG kGpsTimchkC[MDEV_PSTIMCHKC_MAX]; /* Ignore -> MISRA-C:2004 Rule 8.12 */
+extern const TG_GPS_JMP_TBL kGpsMatxC[GPS_STS_NUM][GPS_EVT_NUM];
+
+#define MDEV_GPSCMDANATBLNMEA_MAX 20
+extern const TG_GPS_CMD_ANA_TBL* kGpsCmdAnaTbl;
+extern const TG_GPS_CMD_ANA_TBL kGpsCmdAnaTblUblox[MDEV_GPSCMDANATBLNMEA_MAX];
+
+extern TG_GPS_SAVEBUF g_gps_save_cmdr;
+extern TG_GPS_MSGRCV g_gps_msg_rcvr;
+extern TG_GPS_MNG g_gps_mngr;
+
+extern u_int16 g_wsend_err; /* Number of transmission errors */
+extern u_int16 g_wcnct_err; /* Number of connection errors */
+extern TG_GPS_OUTPUT_FORMAT g_rcv_format; /* Receive Format */
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+EFrameworkunifiedStatus DevGpsMainThread(HANDLE h_app);
+BOOL DevGpsInit(void);
+void DevGpsRcvMsg(void);
+void DevGpsMsgEventCheck(void);
+void DevGpsTimEventCheck(void);
+void DevGpsGpsVersionCheck(void);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_GPSCOMMON_MDEV_GPS_MAIN_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Mtrx.h b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Mtrx.h
new file mode 100755
index 0000000..610b8d4
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Mtrx.h
@@ -0,0 +1,90 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Mtrx.h
+*/
+
+#ifndef INC_GPSCOMMON_MDEV_GPS_MTRX_H_
+#define INC_GPSCOMMON_MDEV_GPS_MTRX_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+void DevGpsNop(void);
+void DevGpsInitStartSendReq(void);
+void DevGpsInitStartGPSResetReq(void);
+void DevGpsInitStartRcvCyclCmd(void);
+void DevGpsInitStartCyclDataTimeOut(void);
+void DevGpsInitStartNaviDataTimeOut(void); /* #GPF_60_077 */
+void DevGpsInitStartDiagClkGuardTimeOut(void); /* #GPF_60_077 */
+void DevGpsInitStartAccOffStart(void); /* #GPF_60_024 */
+void DevGpsInitStartNaviInfoDeliver(void); /* #GPF_60_077 */
+void DevGpsInitStartNaviSpeedDeliver(void); /* #GPF_60_077 */
+void DevGpsInitStartSettingTime(void); /* #GPF_60_077 */
+void DevGpsInitStartNmeaDataGuardTimeOut(void); /* #GPF_60_109 */
+
+void DevGpsInitStartBackupDataLoadReq(void);
+void DevGpsInitStartStopReq(void);
+void DevGpsInitStartGpsweekcorcntNtf(void);
+void DevGpsInitStartRecoveryTimeOut(void);
+void DevGpsInitStartGpsReceiverErrTimeOut(void);
+
+void DevGpsNormalSendReq(void);
+void DevGpsNormalGPSResetReq(void);
+void DevGpsNormalRcvCyclCmd(void);
+void DevGpsNormalCyclDataTimeOut(void);
+void DevGpsNormalNaviDataTimeOut(void); /* #GPF_60_077 */
+void DevGpsNormalDiagClkGuardTimeOut(void); /* #GPF_60_077 */
+void DevGpsNormalAccOffStart(void); /* #GPF_60_024 */
+void DevGpsNormalNaviInfoDeliver(void); /* #GPF_60_077 */
+void DevGpsNormalNaviSpeedDeliver(void); /* #GPF_60_077 */
+void DevGpsNormalSettingTime(void); /* #GPF_60_077 */
+void DevGpsNormalNmeaDataGuardTimeOut(void); /* #GPF_60_109 */
+
+void DevGpsNormalBackupDataLoadReq(void);
+void DevGpsNormalStopReq(void);
+void DevGpsNormalGpsweekcorcntNtf(void);
+void DevGpsNormalRecoveryTimeOut(void);
+void DevGpsNormalGpsReceiverErrTimeOut(void);
+
+void DevGpsSendSendReq(void);
+void DevGpsSendGPSResetReq(void);
+void DevGpsSendRcvCyclCmd(void);
+void DevGpsSendRcvRspCmd(void); /* #GPF_60_040 */
+void DevGpsSendRspDataTimeOut(void); /* #GPF_60_040 */
+void DevGpsSendCyclDataTimeOut(void);
+void DevGpsSendNaviDataTimeOut(void); /* #GPF_60_077 */
+void DevGpsSendDiagClkGuardTimeOut(void); /* #GPF_60_077 */
+void DevGpsSendAccOffStart(void); /* #GPF_60_040 */
+void DevGpsSendNaviInfoDeliver(void); /* #GPF_60_077 */
+void DevGpsSendNaviSpeedDeliver(void); /* #GPF_60_077 */
+void DevGpsSendSettingTime(void); /* #GPF_60_077 */
+void DevGpsSendNmeaDataGuardTimeOut(void); /* #GPF_60_109 */
+
+void DevGpsSendBackupDataLoadReq(void);
+void DevGpsSendStopReq(void);
+void DevGpsSendGpsweekcorcntNtf(void);
+void DevGpsSendRecoveryTimeOut(void);
+void DevGpsSendGpsReceiverErrTimeOut(void);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_GPSCOMMON_MDEV_GPS_MTRX_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Nmea.h b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Nmea.h
new file mode 100755
index 0000000..a19e3d9
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_Nmea.h
@@ -0,0 +1,313 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_GpsUblox.h
+*/
+
+#ifndef INC_GPSCOMMON_MDEV_GPS_NMEA_H_
+#define INC_GPSCOMMON_MDEV_GPS_NMEA_H_
+
+/*---------------------------------------------------------------------------*/
+
+#include "gps_hal.h"
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+#define TEST_NMEA (0) /* 0:Normal mode 1:Testing mode */
+
+#define GPS_MAX_NUM_VISIBLE_SATELLITES (20) /* Maximum Number of Visible Satellites *Assume the GSV1~GSV5 */
+
+/* UBX command *****************************/
+
+/* CFG */
+#define UBX_CMD_SIZE_CFG_RST (12) /* size of CFG-RST of UBX sentences */
+#define UBX_CMD_SIZE_CFG_MSG (11) /* size of CFG-MSG of UBX sentences */
+#define UBX_CMD_SIZE_CFG_NAV5 (44) /* size of CFG-NAV5 of UBX sentences */
+#define UBX_CMD_SIZE_CFG_NAV5_POLL (8)
+#define UBX_CMD_SIZE_CFG_NAV5_PLUS_POLL (UBX_CMD_SIZE_CFG_NAV5 + UBX_CMD_SIZE_CFG_NAV5_POLL)
+#define UBX_CMD_SIZE_CFG_NAVX5_POLL (8)
+#define UBX_CMD_OFFSET_WKNROLLOVER (18) /* offset from the top of 'payload' */
+
+/* MON */
+#define UBX_CMD_SIZE_MON_VER (108) /* size of MON-VER of UBX sentences */
+#define UBX_CMD_SIZE_MON_VER_POLL (8)
+#define UBX_CMD_SIZE_MON_VER_SW_VER (30)
+
+/* AID */
+#define UBX_CMD_SIZE_AID_INI (56) /* size of AID-INI of UBX sentences */
+#define UBX_CMD_SIZE_AID_INI_POLL (8)
+#define UBX_CMD_SIZE_AID_INI_PLUS_POLL (UBX_CMD_SIZE_AID_INI + UBX_CMD_SIZE_AID_INI_POLL)
+
+/* ACK */
+#define UBX_CMD_OFFSET_ACKNAK (3) /* offset to Ack/Nack Infomation */
+
+/* NAV */
+#define UBX_CMD_MSK_NAV_TIMEUTC_VALID_TOW (1) /* mask bit for 'validTow' of NAV-TIMEUTC */
+#define UBX_CMD_MSK_NAV_TIMEUTC_VALID_WKN (2) /* mask bit for 'validKwn' of NAV-TIMEUTC */
+#define UBX_CMD_MSK_NAV_TIMEUTC_VALID_UTC (4) /* mask bit for 'validUtc' of NAV-TIMEUTC */
+
+/* Common */
+#define UBX_CMD_SIZE_HDR (2) /* size of 'header' of UBX sentence */
+#define UBX_CMD_SIZE_ID (2) /* size of 'id' of UBX sentence */
+#define UBX_CMD_SIZE_LEN (2) /* size of 'length' of UBX sentence */
+#define UBX_CMD_SIZE_MAX (400) /* size of NAV-SVINFO (numCh=32) */
+#define UBX_CMD_OFFSET_PAYLOAD (UBX_CMD_SIZE_HDR + UBX_CMD_SIZE_ID + UBX_CMD_SIZE_LEN)
+ /* offset to 'payload' of UBX sentence */
+
+/* Types of UBX Poll Request Commands ************/
+#define UBX_POLL_CMD_KIND_AID_INI (1)
+#define UBX_POLL_CMD_KIND_CFG_NAV5 (2)
+
+// GPS-command (_CWORD82_ NMEA) related definitions #GPF_60_024
+/* Command identification character string */
+#define GPS_CMD_NMEA_GGA ("$GPGGA") /* GGA/double precision GGAs */
+#define GPS_CMD_NMEA_VTG ("$GPVTG") /* VTG */
+#define GPS_CMD_NMEA_RMC ("$GPRMC") /* RMC/double precision RMCs */
+#define GPS_CMD_NMEA_GLL ("$GPGLL") /* GLL/double precision GLL */
+#define GPS_CMD_NMEA_GSA ("$GPGSA") /* GSA */
+#define GPS_CMD_NMEA_GSV_1 ("$GPGSV,*,1") /* GSV(1) */
+#define GPS_CMD_NMEA_GSV_2 ("$GPGSV,*,2") /* GSV(2) */
+#define GPS_CMD_NMEA_GSV_3 ("$GPGSV,*,3") /* GSV(3) */
+#define GPS_CMD_NMEA__CWORD44__GP_3 ("$_CWORD44_,GP,3") /* _CWORD44_,GP,3 */
+#define GPS_CMD_NMEA__CWORD44__GP_4 ("$_CWORD44_,GP,4") /* _CWORD44_,GP,4 */
+#define GPS_CMD_NMEA_P_CWORD82_F_GP_0 ("$P_CWORD82_F,GP,0") /* P_CWORD82_F,GP,0 */
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_1 ("$P_CWORD82_J,GP,1") /* P_CWORD82_J,GP,1 */
+#define GPS_CMD_NMEA_P_CWORD82_I_GP ("$P_CWORD82_I,GP") /* P_CWORD82_I,GP */
+#define GPS_CMD_NMEA_P_CWORD82_E_GP_0 ("$P_CWORD82_E,GP,0") /* P_CWORD82_E,GP,0 */
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_0 ("$P_CWORD82_J,GP,0") /* P_CWORD82_J,GP,0 */
+#define GPS_CMD_NMEA_P_CWORD82_E_GP_2 ("$P_CWORD82_E,GP,2") /* P_CWORD82_E,GP,2 */
+#define GPS_CMD_NMEA_P_CWORD82_G_GP_0 ("$P_CWORD82_G,GP,0") /* P_CWORD82_G,GP,0 */
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_7 ("$P_CWORD82_J,GP,7") /* P_CWORD82_J,GP,7 */
+#define GPS_CMD_NMEA_P_CWORD82_J_GP_8 ("$P_CWORD82_J,GP,8") /* P_CWORD82_J,GP,8 */
+#define GPS_CMD_NMEA_GST ("$GPGST") /* GST */
+#define GPS_CMD_NMEA_GSV_4 ("$GPGSV,*,4") /* GSV(4) */
+#define GPS_CMD_NMEA_GSV_5 ("$GPGSV,*,5") /* GSV(5) */
+
+/*-------------------------------------------------------------------------------
+ * GPS-command (_CWORD82_ Binary) related definitions #GPF_60_024
+ -------------------------------------------------------------------------------*/
+#define GPS_CMD_BINARY (0xC6) /* Standard binary */
+#define GPS_CMD_FULLBIN (0xB0) /* FULL binaries */
+
+#define ENDMARK "ENDENDEND" /* Table termination */
+#define GPSCMDANATBL_MAX 25 /* Maximum number of elements in table */
+#define RCV_CYCLE 0x01 /* Reception type cycle reception command*/
+#define RCV_RESP 0x02 /* Reception type response command */
+
+// Length of FULLBINARY commands
+#define GPS_CMD_FULLBIN1_SZ 30
+#define GPS_CMD_FULLBIN2_SZ 160
+#define GPS_CMD_FULLBIN3_SZ 25
+#define GPS_CMD_FULLBIN4_SZ 26
+#define GPS_CMD_FULLBIN5_SZ 14
+#define GPS_CMD_FULLBIN6_SZ 61
+
+/* Start offset of FULLBINARY command */
+#define GPS_CMD_FULLBIN1_OFFSET 0
+#define GPS_CMD_FULLBIN2_OFFSET (GPS_CMD_FULLBIN1_OFFSET + GPS_CMD_FULLBIN1_SZ)
+#define GPS_CMD_FULLBIN3_OFFSET (GPS_CMD_FULLBIN2_OFFSET + GPS_CMD_FULLBIN2_SZ)
+#define GPS_CMD_FULLBIN4_OFFSET (GPS_CMD_FULLBIN3_OFFSET + GPS_CMD_FULLBIN3_SZ)
+#define GPS_CMD_FULLBIN5_OFFSET (GPS_CMD_FULLBIN4_OFFSET + GPS_CMD_FULLBIN4_SZ)
+#define GPS_CMD_FULLBIN6_OFFSET (GPS_CMD_FULLBIN5_OFFSET + GPS_CMD_FULLBIN6_SZ)
+
+
+/* SUM value offset of FULLBINARY commands */
+#define GPS_CMD_FULLBIN1_SUMOFFSET (GPS_CMD_FULLBIN1_OFFSET + GPS_CMD_FULLBIN1_SZ - 2)
+#define GPS_CMD_FULLBIN2_SUMOFFSET (GPS_CMD_FULLBIN2_OFFSET + GPS_CMD_FULLBIN2_SZ - 2)
+#define GPS_CMD_FULLBIN3_SUMOFFSET (GPS_CMD_FULLBIN3_OFFSET + GPS_CMD_FULLBIN3_SZ - 2)
+#define GPS_CMD_FULLBIN4_SUMOFFSET (GPS_CMD_FULLBIN4_OFFSET + GPS_CMD_FULLBIN4_SZ - 2)
+#define GPS_CMD_FULLBIN5_SUMOFFSET (GPS_CMD_FULLBIN5_OFFSET + GPS_CMD_FULLBIN5_SZ - 2)
+#define GPS_CMD_FULLBIN6_SUMOFFSET (GPS_CMD_FULLBIN6_OFFSET + GPS_CMD_FULLBIN6_SZ - 2)
+#define GPS_CMD_FULLBIN_MASK 0x8F
+
+#define GPS_CMD_RESET 1 /* Reset request command */
+#define GPS_CMD_TIMESET 2 /* Time setting request command */
+#define GPS_CMD_VERSION 3 /* GPS version request command */
+#define GPS_CMD_SENTENCEADD_NMEAGST 4 /* Add sentence command NMEA GST */
+#define GPS_CMD_SENTENCEADD_NAVTIMEUTC 5 /* Add sentence command NAV-TIMEUTC */
+#define GPS_CMD_SENTENCEADD_NAVCLOCK 6 /* Add sentence command NAV-CLOCK */
+#define GPS_CMD_SENTENCEADD_RXMRTC5 7 /* Add sentence command RXM-RTC5 */
+#define GPS_CMD_SENTENCEADD_NAVSVINFO 8 /* Add sentence command NAV-SVINFO */
+#define GPS_CMD_AUTOMOTIVEMODE 9 /* Automatic mode request command */
+#define GPS_CMD_WKNROLLOVER 10 /* GPS rollover standard week number request command */
+#define GPS_CMD_NOTRST 0 /* Other request command */
+
+/*---------------------------------------------------------------------------*/
+// Struct
+
+/*!
+ @brief UBX command headers
+*/
+typedef struct GpsUbxPacketHeader {
+ u_int8 uc_sync_char1; /* u-blox starts with 2 Bytes 0xB5 0x62 */
+ u_int8 uc_sync_char2; /* u-blox starts with 2 Bytes 0xB5 0x62 */
+ u_int8 uc_class; /* Class */
+ u_int8 uc_id; /* ID */
+ u_int16 us_length; /* Length */
+} TG_GPS_UBX_PACKET_HEADER;
+
+/*!
+ @brief Command-structure without UBX data
+*/
+typedef struct GpsUbxCmdNoData {
+ TG_GPS_UBX_PACKET_HEADER header;
+ u_int8 uc_cka; /* Checksum_A */
+ u_int8 uc_ckb; /* Checksum_B */
+} TG_GPS_UBX_COMMAND_NO_DATA;
+
+/*!
+ @brief
+*/
+typedef struct GpsUbxAidIniPolled {
+ u_int8 uc_sync_char1; /* u-blox starts with 2 Bytes 0xB5 0x62 */
+ u_int8 uc_sync_char2; /* u-blox starts with 2 Bytes 0xB5 0x62 */
+ u_int8 uc_class; /* Class */
+ u_int8 uc_id; /* ID */
+ u_int8 uc_length[2]; /* Length */
+ u_int8 uc_ecefx_or_lat[4]; /* WGS84 ECEF X coordinate or latitude */
+ u_int8 uc_ecefy_or_lon[4]; /* WGS84 ECEF Y coordinate or longitude */
+ u_int8 uc_ecefz_or_alt[4]; /* WGS84 ECEF Z coordinate or altitude */
+ u_int8 uc_pos_acc[4]; /* Position accuracy (stddev) */
+ u_int8 uc_tm_cfg[2]; /* Time mark configuration */
+ u_int8 wn[2]; /* Actual week number */
+ u_int8 tow[4]; /* Actual time of week */
+ u_int8 uc_tow_ns[4]; /* Sub-millisecond part of time of week */
+ u_int8 uc_tacc_ms[4]; /* Milliseconds part of time accuracy */
+ u_int8 uc_tacc_ns[4]; /* Nanoseconds part of time accuracy */
+ u_int8 uc_clk_d_or_freq[4]; /* Clock drift or frequency */
+ u_int8 uc_clk_dacc_or_freqacc[4]; /* Accuracy of clock drift or frequency */
+ u_int8 uc_flags[4]; /* Bitmask with the following flags */
+ u_int8 uc_cka; /* Checksum_A */
+ u_int8 uc_ckb; /* Checksum_B */
+} TG_GPS_UBX_AID_INI_POLLED;
+
+/*!
+ @brief UBX ACK command data structures
+*/
+typedef struct GpsUbxAckData {
+ uint8_t uc_msg_class; /* Message Class */
+ uint8_t uc_msg_id; /* Message Identifier */
+} TG_GPS_UBX_ACK_DATA;
+
+/*!
+ @brief UBX NAV-TIMEUTC command data structures
+*/
+typedef struct GpsUbxNavUTC {
+ uint32_t ul_itow; /* GPS time of week */
+ uint32_t ul_tacc; /* Time accuracy estimate (UTC) */
+ int32_t nano; /* Fraction of second */
+ uint16_t year; /* Year, range 1999..2099 (UTC) */
+ uint8_t month; /* Month, range 1..12 (UTC) */
+ uint8_t day; /* Day of month, range 1..31 (UTC) */
+ uint8_t hour; /* Hour of day, range 0..23 (UTC) */
+ uint8_t min; /* Minute of hour, range 0..59 (UTC) */
+ uint8_t sec; /* Seconds of minute, range 0..60 (UTC) */
+ uint8_t valid; /* Validity Flags */
+} TG_GPS_UBX_NAV_TIMEUTC_DATA;
+
+/*!
+ @brief USB NAV-CLOCK command data structures
+*/
+typedef struct GpsUbxNavClock {
+ uint32_t ul_itow; /**< GPS Time of week */
+ int32_t l_clkb; /**< Clock bias */
+ int32_t l_clkd; /**< Clock drift */
+ uint32_t ul_tacc; /**< Time accuaracy estimate */
+ uint32_t ul_facc; /**< Frequency accuracy estimate */
+} TG_GPS_UBX_NAV_CLOCK;
+
+/*!
+ @brief GPS RXM-RTC5 command data structures
+*/
+typedef struct GpsUbxRxmRtc5 {
+ uint32_t ul_rtag_hw; /**< RTAG high word */
+ uint32_t ul_rtag_lw; /**< RTAG low word */
+ uint32_t freq; /**< Clock frequency */
+ uint32_t ul_freq_frac; /**< Clock frequency fractional part */
+ uint32_t ul_tow_frac; /**< Time of week fractional part */
+ uint32_t tow; /**< Time of week */
+ uint16_t wno; /**< GPS week number */
+ uint8_t uc_tow_valid; /**< TOW is valid flag */
+ uint8_t uc_freq_valid; /**< Frequency is valid flag */
+} TG_GPS_UBX_RXM_RTC5;
+
+/********************************************************************************
+ * TAG :TG_GPS_RCVDATA_NMEA
+ * ABSTRACT :Cyclic data (NMEA) area
+ * NOTE :I/F information between communication management thread and vehicle sensor
+ ********************************************************************************/
+typedef struct GpsRcvDataNMEA {
+ u_int8 uc_rcv_flag[GPS_NMEA_INDEX_MAX]; /* Receive flag */
+ u_int8 u_reserve[3]; /* Reserved */
+ TG_GPS_NMEA_DAT st_nmea[GPS_NMEA_INDEX_MAX]; /* NMEA data area */
+} TG_GPS_RCVDATA_NMEA;
+
+/********************************************************************************
+ * TAG :TG_GPS_RCVDATA_BINARY
+ * ABSTRACT :Cyclic data (standard binary) area
+ * NOTE :I/F information between communication management thread and vehicle sensor
+ ********************************************************************************/
+typedef struct GpsRcvDataBinary {
+ u_int8 uc_rcv_flag; /* Receive flag */
+ u_int8 u_reserve[3]; /* Reserved */
+ u_int8 uc_data[GPS_CMD_BINARY_SZ]; /* Standard binary data area */
+ u_int8 u_reserve2[3]; /* Reserved */
+} TG_GPS_RCVDATA_BINARY;
+
+/********************************************************************************
+ * TAG :TG_GPS_RCVDATA_FULLBIN
+ * ABSTRACT :Cyclic data (full binary) area
+ * NOTE :I/F information between communication management thread and vehicle sensor
+ ********************************************************************************/
+typedef struct GpsRcvDataFullbin {
+ u_int8 uc_rcv_flag; /* Receive flag */
+ u_int8 u_reserve[3]; /* Reserved */
+ u_int8 uc_data[GPS_CMD_FULLBIN_SZ]; /* Full binary data area */
+ u_int8 u_reserve2; /* Reserved */
+} TG_GPS_RCVDATA_FULLBIN;
+
+/********************************************************************************
+ * TAG :TG_GPS_RCVDATA
+ * ABSTRACT :Cyclic data storage area
+ * NOTE :I/F information between communication management thread and vehicle sensor
+ ********************************************************************************/
+typedef struct GpsRcvData {
+ u_int8 uc_sns_cnt; /* Sensor counter value */
+ u_int8 u_reserve[3]; /* Reserved */
+ TG_GPS_RCVDATA_NMEA st_nmea_data; /* NMEA data area */
+ TG_GPS_RCVDATA_BINARY st_binary_data; /* Standard binary region */
+ TG_GPS_RCVDATA_FULLBIN st_fullbin_data; /* Full binary data area */
+} TG_GPS_RCVDATA;
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+void DevGpsSndCycleDataNmea(void);
+void DevGpsRcvCyclCmd(void);
+u_int8 DevGpsGetGpsRcvSts(u_int8 sv);
+void DevGpsAnalyzeNmea(NAVIINFO_ALL* navilocinfo);
+void DevGpsCycleDataClear(void);
+void DevGpsCycleDataSetNmea(const u_int8*, u_int32, ENUM_GPS_NMEA_INDEX);
+BOOL DevGpsCycleDataGetNmea(u_int8*, u_int32, ENUM_GPS_NMEA_INDEX);
+void DevGpsCmdEventCheckNmea(void);
+void DevGpsSetChkSum(u_int8* buffer, u_int32 length);
+/*---------------------------------------------------------------------------*/
+#endif // INC_GPSCOMMON_MDEV_GPS_NMEA_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/GpsCommon/MDev_Gps_TimerCtrl.h b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_TimerCtrl.h
new file mode 100755
index 0000000..96616ef
--- /dev/null
+++ b/hal/positioning_hal/inc/GpsCommon/MDev_Gps_TimerCtrl.h
@@ -0,0 +1,113 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_TimerCtrl.h
+*/
+
+#ifndef INC_GPSCOMMON_MDEV_GPS_TIMERCTRL_H_
+#define INC_GPSCOMMON_MDEV_GPS_TIMERCTRL_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+/* GPS-related timer value */
+#define TIMVAL_GPS_STARTUP 500 /* 5Sec Start confirmation monitoring timer */
+#define TIMVAL_GPS_RCVCYCLDAT 500 /* 5Sec Periodic reception data monitoring timer */
+#define TIMVAL_GPS_RCVACK 500 /* 5Sec ACK reception monitoring timer */
+#define TIMVAL_GPS_RCVDAT 500 /* 5Sec Data reception monitoring timer(Unused) */
+#define TIMVAL_GPS_NAVIFST 3000 /* 30sec Initial navigation monitoring timer */
+#define TIMVAL_GPS_NAVICYCLE 300 /* 3sec Navigation monitoring timer */
+#define TIMVAL_GPS_NAVIDISRPT 1000 /* 10Sec Navigation monitoring disruption log output timer */
+#define TIMVAL_GPS_DIAGCLKGUARD 1000 /* 10sec Diagnosis provision time guard monitoring timer */
+#define TIMVAL_GPS_NMEADATAGUARD 1000 /* 10sec NMEA data-providing guard monitoring timer */
+#define TIMVAL_GPS_RECOVERY 60000 /* 600sec GPS recovery timer */
+#define TIMVAL_GPS_RECEIVERERR 60000 /* 600sec GPS receiver anomaly detection timer */
+
+/* Sensor-related timer value */
+#define TIMVAL_SNS_RCVFSTDAT 3000 /* 30Sec Initial sensor data reception monitoring timer */
+#define TIMVAL_SNS_RCVCYCLDAT 300 /* 3Sec Cyclic sensor data reception monitoring timer */
+#define TIMVAL_SNS_RCVDISRPT 1000 /* 10Sec Cyclic sensor data interruption log output timer */
+
+/* Timer management table */
+#define TIM_NON 0x00 /* Timer counter initial value */
+#define TIM_CNTMIN 0x01 /* Timer counter minimum value */
+#define TIM_CNTMAX 0xff /* Maximum value of timer counter */
+#define TIMER_OFF 0 /* Timer enable flag OFF */
+#define TIMER_ON 1 /* Timer enable flag ON */
+
+/*!
+ @brief Timer type
+ */
+typedef enum GpsTimKind {
+ GPS_STARTUP_TIMER = 0, /* 0 Start confirmation monitoring timer */
+ GPS_CYCL_TIMER, /* 1 Cyclic GPS data reception monitoring timer */
+ GPS_RECV_ACK_TIMER, /* 2 ACK reception monitoring timer */
+ GPS_NAVIFST_TIMER, /* 3 Initial navigation monitoring timer */
+ GPS_NAVICYCLE_TIMER, /* 4 Navigation monitoring timer */
+ GPS_NAVIDISRPT_TIMER, /* 5 Navigation monitoring disruption log output timer */
+ GPS_DIAGCLK_GUARDTIMER, /* 6 Diagnosis provision time guard monitoring timer */
+ GPS_NMEADATA_GUARDTIMER, /* 7 NMEA data-providing guard monitoring timer */
+ GPS_RECOVERY_TIMER, /* 8 GPS recovery timer */
+ GPS_RECEIVERERR_TIMER, /* 9 GPS receiver anomaly detection timer */
+ SNS_FST_TIMER, /* 10 Initial sensor data reception monitoring timer */
+ SNS_CYCLE_TIMER, /* 11 Cyclic sensor data reception monitoring timer */
+ SNS_DISRPT_TIMER, /* 12 Cyclic sensor data interruption log output timer */
+ TIM_NUM /* 13 Number of timer types */
+} GPS_TIM_KIND;
+
+/*!
+ @brief Timer status
+*/
+typedef struct GpsTimSts {
+ u_int8 flag; /**< Timer flag OFF:Stop,ON:Start */
+ u_int8 cnt; /**< Start counter */
+ int8 rsv[2]; /**< Reserved */
+} GPS_TIM_STS;
+
+/*!
+ @brief Timer status management table
+ */
+typedef struct GpsTimMng {
+ GPS_TIM_STS sts[TIM_NUM]; /**< Timer status */
+} GPS_TIM_MNG;
+
+/*!
+ @brief Timer setting information table
+*/
+typedef struct GpsTimInfo {
+ uint32_t timer_val; /**< Timer value */
+ PNO pno; /**< Event notification destination process number */
+} GPS_TIM_INFO;
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+void DevGpsTimInit(void);
+BOOL DevGpsTimeSet(GPS_TIM_KIND tim_kind);
+BOOL DevGpsTimeStop(GPS_TIM_KIND tim_kind);
+u_int16 DevGpsTimeMakSeqNo(GPS_TIM_KIND tim_kind);
+BOOL DevGpsTimeJdgKind(u_int16 seqno);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_GPSCOMMON_MDEV_GPS_TIMERCTRL_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/LineSensDrv/LineSensDrv_Sensor.h b/hal/positioning_hal/inc/LineSensDrv/LineSensDrv_Sensor.h
new file mode 100755
index 0000000..1b996b7
--- /dev/null
+++ b/hal/positioning_hal/inc/LineSensDrv/LineSensDrv_Sensor.h
@@ -0,0 +1,183 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file LineSensDrv_Sensor.h
+*/
+
+#ifndef INC_LINESENSDRV_LINESENSDRV_SENSOR_H_
+#define INC_LINESENSDRV_LINESENSDRV_SENSOR_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Macro definitions
+
+/* Message related */
+/* Message identification number definition received from the ICR */
+#define LSDRV_RCVMSG_INVALID 0x00 /* Not applicable */
+#define LSDRV_RCVMSG_SENSOR 0x12 /* Sensor data */
+
+/* LineSensor vehicle signal notification */
+
+#define LSDRV_SENS_MASK 0xFFF /* Sensor data MASK */
+#define LSDRV_PLSMAX 65536 /* Maximum vehicle speed pulse number */
+/* #011 start */
+#define LSDRV_SENS_COEFFICIENT 14.1287284284144427 /* Vehicle speed calculation factor */
+#define LSDRV_SPKMPH_METHOD_FST 0 /* Vehicle speed calculation method(Initial Sensor Data) */
+#define LSDRV_SPKMPH_METHOD_NML 1 /* Vehicle speed calculation method(Sensor data) */
+#define LSDRV_SPKMPH_AVE_TIME 29 /* Effective time for average calculation data(in units of 100ms) */ /* #013 */
+#define LSDRV_SPKMPH_NOISE_TIME (LSDRV_SPKMPH_AVE_TIME + 2) /* Effective Time for Noise Detection(in units of 100ms) */ /* #017 */
+#define LSDRV_SPKMPH_INVALID 1 /* No pulse of previous vehicle speed */
+#define LSDRV_SPKMPH_VALID 0 /* Last vehicle speed pulse */
+#define LSDRV_SENSCNT_BRW_ADD 256 /* Measures for borrow occurrence during search of sensor counters */
+/* #011 end */
+#define LSDRV_FSENS_NRCV 0 /* Not received */
+#define LSDRV_FSENS_RCV 1 /* Receiving */
+#define LSDRV_FSENS_RCVCOMP 2 /* Reception completion */
+#define LSDRV_FSENS_NORMAL 0 /* Receive data normal */ /* #001 */
+#define LSDRV_FSENS_ERROR 1 /* Receive data anomaly */ /* #001 */
+/* #016 start */
+#define LSDRV_PLSDATA_NRCV 0 /* Not received */
+#define LSDRV_PLSDATA_RCV 1 /* Received */
+#define LSDRV_SENSCNT_MAX 255 /* Maximum value of sensor counter */
+#define LSDRV_SPKMPH_MIN_DATA_N 6 /* Number of data required for vehicle speed calculation */
+#define LSDRV_FSPDPLS_NUM 3 /* Number of cumulative pulses registered for the first time */
+/* #016 end */
+#define LSDRV_REV_MASK 0x0040 /* REV-data MASK(Before endian conversion) */
+#define LSDRV_BITSHIFT_REV 6 /* REV data bit shift */
+#define LSDRV_TEMP_MASK 0x07FF /* Gyro temperature data MASK(after endian conversion) */
+#define LSDRV_PLSTIME_LEN 232 /* Data length when inter-pulse time exists */
+
+
+#define LSDRV_DETAILED_DATA_MULTI_ENABLE TRUE /* Detailed data multiplexing of initial sensor data Enabled/Disabled */
+
+#if LSDRV_DETAILED_DATA_MULTI_ENABLE
+#define LSDRV_DETAILED_DATA_MULTI_MAX_NUM 2 /* Detailed data multiplexing of initial sensor data Maximum number */
+#else
+#define LSDRV_DETAILED_DATA_MULTI_MAX_NUM 1 /* Detailed data multiplexing of initial sensor data Maximum number */
+#endif
+
+/* Total number of partitions of initial sensor data : Maximum value */
+#define LSDRV_FSENS_TOTAL_NUM_MAX LSDRV_FSTSNS_SENSOR_FIRST_SEND_NUM
+
+/* Detailed data of initial sensor data : Maximum number of acquisitions */
+#define LSDRV_DETAILED_DATA_MAX_NUM (LSDRV_FSENS_TOTAL_NUM_MAX * LSDRV_DETAILED_DATA_MULTI_MAX_NUM)
+
+/* Initial sensor data : Maximum number of saved messages */
+#define LSDRV_FSENS_SAVE_MSG_NUM (LSDRV_FSENS_TOTAL_NUM_MAX + 1)
+
+/* Initial sensor data : Maximum number of data stored */
+#define LSDRV_FSENS_SAVE_DATA_NUM (LSDRV_FSENS_SAVE_MSG_NUM * LSDRV_DETAILED_DATA_MULTI_MAX_NUM)
+
+#define LSDRV_DETAILED_DATA_GYRO_NUM LSDRV_FSTSNS_DETAILED_DATA_GYRO_NUM
+#define LSDRV_DETAILED_DATA_GSENSOR_NUM LSDRV_FSTSNS_DETAILED_DATA_GSENSOR_NUM
+#define LSDRV_DETAILED_DATA_GSENSOR_X_OFFSET 0 /* G-Sensor data X-axis offset included in detail data */
+#define LSDRV_DETAILED_DATA_GSENSOR_Y_OFFSET 1 /* G-Sensor data Y-axis offsets included in the detail data */
+#define LSDRV_DETAILED_DATA_GSENSOR_OFFSET 3 /* G-Sensor data access offset included in the detail data */
+
+/* Gyro Output Specifications:11500 ~ 54036LSB */
+#define GYRO_OUTPUPT_SPEC_LOWER_LIMIT 11500U
+#define GYRO_OUTPUPT_SPEC_UPPER_LIMIT 54036U
+
+/* Gyro Failure Status : How many normal status continues should be made to Gyro Failure Status normal when it is judged to be "error -> normal" */
+#define GYRO_TROUBLE_NORMAL_COUNTER_THRESHOLD 10U /* 10 ms (Gyro data acquisition interval) * 10 times = 100ms */
+
+/* Gyro Failure Status : How many error status continues should be made to Gyro Failure Status error when it is judged to be "normal -> error" */
+#define GYRO_TROUBLE_ERROR_COUNTER_THRESHOLD 3000U /* 10 ms (Gyro data acquisition interval) * 3000 times = 30s */
+
+/* SYS GPS Interrupt Signal : How many disable continues should be made to SYS GPS Interrupt Signal disable when it is judged to be "enable -> disable" */
+#define SYS_GPS_INTERRUPT_SIGNAL_INVALID_COUNTER_THRESHOLD 10U
+
+/* Gyro Failure Status : Match values with SENSORMOTION_NORMAL and ERROR,UNFIXED in SensorMotion_API.h */
+#define GYRO_NORMAL (0U)
+#define GYRO_ERROR (1U)
+#define GYRO_UNFIXED (2U)
+
+/* Gyro connection status : Match values with SENSOR_CONNECT and SENSOR_DISCONNECT in Sensor_API.h */
+#define GYRO_DISCONNECT (0U)
+#define GYRO_CONNECT (1U)
+
+/*** Data table for calculating vehicle speed *****************************************/
+#define LSDRV_SPKMPH_TBL_NUM 32 /* Number of data tables */ /* #50836 */
+#define LSDRV_SPKMPH_DATA_EN 0x01 /* Data storage flag valid */
+#define LSDRV_SPKMPH_DATA_DIS 0x00 /* Data storage flag invalid */
+
+/*** Operation code *********************************************/
+#define LSDRV_OPC_WILDCARD 0xFF /* Wildcarded #012 */
+
+#define LSDRV_OPC_EXTTERM_R 0x89 /* External pin status request */
+#define LSDRV_OPC_EXTTERM_A 0x99 /* External pin status notification */
+#define LSDRV_OPC_SENSOR 0xC1 /* Sensor data */
+#define LSDRV_OPC_FSENS_R 0xE4 /* Initial sensor data request */
+#define LSDRV_OPC_FSENS_A 0xF4 /* Initial sensor data response */
+
+/*---------------------------------------------------------------------------*/
+// Enum
+
+/*---------------------------------------------------------------------------*/
+// Struct
+
+typedef struct {
+ u_int16 uc_sensor_x; /* G-Sensor X data */
+ u_int16 uc_sensor_y; /* G-Sensor Y data */
+ u_int16 uc_sensor_z; /* G-Sensor Z data */
+} SENSORINPUT_INFO_DAT_GSENS;
+
+// TAG : LSDRV_SPEEDKMPH_DAT
+// ABSTRACT : Data Table Structure for Vehicle Speed Calculation
+typedef struct LsDrvSpeedKmph {
+ u_int8 uc_flag; /* Data storage flag */
+ u_int8 uc_sens_cnt; /* Sensor counter */
+ u_int16 us_speed_pulse; /* Vehicle speed pulse */
+ u_int8 uc_noise_flag; /* Noise flag */ /* #017 */
+ u_int8 u_reserve[3]; /* Reserved */ /* #017 */
+} LSDRV_SPEEDKMPH_DAT_DAT;
+
+typedef struct LsDrvSpeedKmphLast {
+ u_int8 uc_flag; /* Data storage flag */
+ u_int8 uc_sens_cnt; /* Sensor counter */
+ u_int16 us_speed_pulse; /* Vehicle speed pulse */
+} LSDRV_SPEEDKMPH_LAST_DAT;
+
+typedef struct LsDrvSpeedKmphDat {
+ u_int8 uc_ptr; /* Data storage pointer */
+ u_int8 uc_fstsns_rcv; /* Initial sensor data reception status */ /* #016 */
+ u_int8 uc_sns_rcv; /* Sensor data reception status */ /* #016 */
+ u_int8 uc_calc_start; /* Vehicle speed calculation start flag */ /* #016 */
+ LSDRV_SPEEDKMPH_LAST_DAT st_last_data; /* Previous vehicle speed pulse information */
+ LSDRV_SPEEDKMPH_DAT_DAT st_data[LSDRV_SPKMPH_TBL_NUM]; /* Data portion */
+} LSDRV_SPEEDKMPH_DAT;
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+void LineSensDrvSensor(u_int8*);
+u_int16 LineSensDrvSpeedCalc(u_int8);
+void LineSensDrvSpeedKmphDataInit(void);
+void LineSensDrvSpeedPulseSave(u_int16, u_int16, u_int8);
+u_int8 LineSensDrvCheckNoise(u_int8);
+
+u_int8 LineSensDrvGetLastSpeedPulse(u_int16*, u_int16, u_int8);
+void LineSensDrvSetLastSpeedPulse(u_int16, u_int8);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_LINESENSDRV_LINESENSDRV_SENSOR_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/inc/LineSensDrv/LineSensDrv_Thread.h b/hal/positioning_hal/inc/LineSensDrv/LineSensDrv_Thread.h
new file mode 100755
index 0000000..54a01dc
--- /dev/null
+++ b/hal/positioning_hal/inc/LineSensDrv/LineSensDrv_Thread.h
@@ -0,0 +1,66 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file LineSensDrv_Thread.h
+*/
+
+#ifndef INC_LINESENSDRV_LINESENSDRV_THREAD_H_
+#define INC_LINESENSDRV_LINESENSDRV_THREAD_H_
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "LineSensDrv_Api.h"
+#include "LineSensDrv_Sensor.h"
+
+/*---------------------------------------------------------------------------*/
+// Define
+
+// Return value
+#define RET_LSDRV_SUCCESS RET_NORMAL // API processing success
+#define RET_LSDRV_ERROR RET_ERROR // API processing failed
+
+/*---------------------------------------------------------------------------*/
+// Rcv Message Related
+
+// Size of data section
+#define LSDRV_RCVMSG_MSGBUF 512 // Byte count of RcvMSG data section
+
+/*---------------------------------------------------------------------------*/
+// Struct
+
+// TAG : LSDRV_RCVDATA
+// ABSTRACT : Message receive buffer structure
+typedef struct LsDrvRcvData {
+ T_APIMSG_MSGBUF_HEADER st_head; // Message header
+ u_int8 uc_data[LSDRV_RCVMSG_MSGBUF]; // Data portion
+} LSDRV_RCVDATA;
+
+/*---------------------------------------------------------------------------*/
+// Prototype
+
+int32 LineSensDrvMainThreadInit(HANDLE);
+void LineSensDrvParamInit(void);
+
+EFrameworkunifiedStatus LineSensDrvThread(HANDLE);
+void LineSensDrvThreadStopProcess(void);
+u_int8 LineSensDrvGetSysRecvFlag(void);
+
+/*---------------------------------------------------------------------------*/
+#endif // INC_LINESENSDRV_LINESENSDRV_THREAD_H_
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/Common/positioning_common.cpp b/hal/positioning_hal/src/Common/positioning_common.cpp
new file mode 100755
index 0000000..00b3a8b
--- /dev/null
+++ b/hal/positioning_hal/src/Common/positioning_common.cpp
@@ -0,0 +1,388 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file positioning_common.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "positioning_common.h"
+#include "MDev_Gps_Common.h"
+#include "MDev_GpsRecv.h"
+#include "LineSensDrv_Thread.h"
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+#define DATMOD_RETRY (3) /* Number of shared memory generation retries */
+#define DATMOD_PREINIT (0) /* Shared Memory State [Before initialization] */
+#define PRIM_NAME_MAX (32) /* Maximum Name Size */
+#define VEHICLE_SHARE_NAME ("POS_VEHICLE_SHARE_MEMORY") /* Shared memory name */
+
+/* Mask for managing various notification reception conditions */
+#define NTFY_MSK_NONE (0x00)
+/* Service availability notification */
+#define NTFY_MSK_COMMUNICATION_AVAILABILITY (0x01)
+#define NTFY_MSK_PS_COMMUSB_AVAILABILITY (0x02)
+#define NTFY_MSK_PS_PSMSHADOW_AVAILABILITY (0x04)
+#define NTFY_MSK_CLOCK_AVAILABILITY (0x08)
+#define NTFY_MSK_NS_BACKUPMGR_AVAILABILITY (0x10)
+#define NTFY_MSK_SS_DEVDETSRV_AVAILABILITY (0x20)
+/* Other Notices */
+#define NTFY_MSK_PS_PSMSHADOW_INIT_COMP (0x01) /* PSMShadow startup completion notice */
+#define NTFY_MSK_PS_LANSERVER_DEVICE_UPDATE (0x02) /* LanServer device configuration change notification */
+#define NTFY_MSK_PS_LANSERVER_WAKEUP_COMP (0x04) /* LanServer start completion notice */
+
+/* Thread state */
+#define THREAD_STS_NOEXIST (0x00)
+#define THREAD_STS_CREATING (0x01)
+#define THREAD_STS_CREATED (0x02)
+
+/*---------------------------------------------------------------------------*/
+// ENUMERATION
+
+/*---------------------------------------------------------------------------*/
+// STRUCTURE
+
+typedef struct StThreadInfo {
+ EnumTID_POS e_id; /**< Thread ID */
+ const int8_t* p_name; /**< Thread name */
+ PNO p_no; /**< Process number */
+ CbFuncPtr cb_routine; /**< Start routine */
+ uint8_t msk_available; /**< Dependent services Availability */
+ uint8_t msk_ntfy; /**< Dependent notification */
+ uint8_t msk_thread; /**< Dependent threads */
+ BOOL b_is_depended; /**< Positioning/Availability->TRUE change dependency */
+ uint8_t uc_status; /**< Thread activation state */
+ uint8_t uc_order; /**< Boot Sequence(Performance) */
+ uint8_t u_reserve[2];
+} ST_THREAD_CREATE_INFO;
+
+typedef struct {
+ char share_data_name[PRIM_NAME_MAX]; /**< Shared data name */
+ u_int32 data_size; /**< Shared data size */
+} ST_SHAREDATA;
+
+static const int8_t kThreadNamePosMain[15] = "POS_Main";
+static const int8_t kThreadNamePosSens[15] = "POS_Sens";
+static const int8_t kThreadNamePosGps[15] = "POS_Gps";
+static const int8_t kThreadNamePosGpsRecv[15] = "POS_Gps_Recv";
+static const int8_t kThreadNamePosGpsRollover[15] = "POS_Gps_Rolovr";
+
+static ST_THREAD_CREATE_INFO g_pos_thread_create_info[] = {
+ { /* POS_Main */
+ ETID_POS_MAIN, /* (1) */
+ NULL, /* (2) */
+ 0, /* (3) */
+ NULL, /* (4) */
+ (NTFY_MSK_NONE), /* (5) */
+ (NTFY_MSK_NONE), /* (6) */
+ 0, /* (7) */
+ FALSE, /* (8) */
+ THREAD_STS_NOEXIST, /* (9) */
+ 0 /* (10) */
+ },
+ { /* POS_sens */
+ ETID_POS_SENS, /* (1) */
+ kThreadNamePosSens, /* (2) */
+ PNO_LINE_SENS_DRV, /* (3) */
+ &LineSensDrvThread, /* (4) */
+ (NTFY_MSK_NONE), /* (5) */
+ (NTFY_MSK_NONE), /* (6) */
+ 0, /* (7) */
+ FALSE, /* (8) */
+ THREAD_STS_NOEXIST, /* (9) */
+ 0 /* (10) */
+ },
+ { /* POS_Gps */
+ ETID_POS_GPS, /* (1) */
+ kThreadNamePosGps, /* (2) */
+ PNO_NAVI_GPS_MAIN, /* (3) */
+ &DevGpsMainThread, /* (4) */
+ (NTFY_MSK_NONE), /* (5) */
+ (NTFY_MSK_NONE), /* (6) */
+ 0, /* (7) */
+ TRUE, /* (8) */
+ THREAD_STS_NOEXIST, /* (9) */
+ 0 /* (10) */
+ },
+ { /* POS_Gps_Recv */
+ ETID_POS_GPS_RECV, /* (1) */
+ kThreadNamePosGpsRecv, /* (2) */
+ PNO_NAVI_GPS_RCV, /* (3) */
+ &DevGpsRecvThread, /* (4) */
+ (NTFY_MSK_NONE), /* (5) */
+ (NTFY_MSK_NONE), /* (6) */
+ THREAD_STS_MSK_POS_GPS, /* (7) */
+ FALSE, /* (8) */
+ THREAD_STS_NOEXIST, /* (9) */
+ 0 /* (10) */
+ },
+ { /* POS_Gps_Rolovr */
+ ETID_POS_GPS_ROLLOVER, /* (1) */
+ NULL, /* (2) */
+ 0, /* (3) */
+ NULL, /* (4) */
+ (NTFY_MSK_NONE), /* (5) */
+ (NTFY_MSK_NONE), /* (6) */
+ 0, /* (7) */
+ FALSE, /* (8) */
+ THREAD_STS_NOEXIST, /* (9) */
+ 0 /* (10) */
+ },
+ { /* Termination */
+ ETID_POS_MAX, /* (1) */
+ NULL, /* (2) */
+ 0, /* (3) */
+ NULL, /* (4) */
+ NTFY_MSK_NONE, /* (5) */
+ NTFY_MSK_NONE, /* (6) */
+ 0, /* (7) */
+ FALSE, /* (8) */
+ THREAD_STS_NOEXIST, /* (9) */
+ 0 /* (10) */
+ },
+};
+
+static ST_SHAREDATA g_sharedata_tbl[] = {
+ /* Shared data name to be generated, Shared data size */
+ { {VEHICLE_SHARE_NAME}, 512 * 11 }, /* Vehicle sensor information acquisition */
+#if 0 /* Not used in _CWORD71_ below */
+ { {"SENSOR_SHARE_MEMORY"}, 512 * 11 }, /* Vehicle sensor information Pkg acquisition */
+ { {"GPS_INT_SIGNAL_SHARE_MEMORY"}, 4 }, /* GPS interrupt signal acquisition */
+ { {"LOG_SETTING_SHARE_MEMORY"}, 36 }, /* DR feature log acquisition */
+ { {"GYRO_CONNECT_STTS_SHARE_MEMORY"}, 4 }, /* Gyro connection status acquisition */
+ { {"EPHEMERIS_NUM_SHARE_MEMORY"}, 4 }, /* Effective ephemeris count acquisition at shutdown */
+ { {"LOCALTIME_SHARE_MEMORY"}, 12 }, /* Local time acquisition at shutdown */
+ { {"LONLAT_SHARE_MEMORY"}, 8 }, /* Location acquisition at shutdown */
+#endif
+ { {(int8)NULL}, 0 } /* Termination */
+};
+
+
+/*---------------------------------------------------------------------------*/
+// Functions
+
+static EFrameworkunifiedStatus PosStopThreadDummy(HANDLE h_app) {
+ return eFrameworkunifiedStatusOK;
+}
+
+static uint32_t PosGetMsg(HANDLE h_app, void** p_buf, uint32_t ul_size) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ uint32_t tmp_size = 0;
+ void* p_rev_buf = NULL;
+
+ if ((h_app == NULL) || (p_buf == NULL)) {
+ POSITIONING_LOG("Argument ERROR!! [h_app = %p, pBuf = %p]", h_app , p_buf);
+ } else {
+ /* Check the size of received data */
+ tmp_size = FrameworkunifiedGetMsgLength(h_app);
+ if (tmp_size > ul_size) {
+ POSITIONING_LOG("Message ul_size ERROR!! [tmp_size = %d, maxsize = %d]", tmp_size, ul_size);
+ tmp_size = 0;
+ } else {
+ /* Obtain data */
+ e_status = FrameworkunifiedGetDataPointer(h_app, &p_rev_buf);
+
+ if (e_status == eFrameworkunifiedStatusOK) {
+ *p_buf = p_rev_buf;
+ } else if (e_status == eFrameworkunifiedStatusInvldBufSize) {
+ e_status = FrameworkunifiedGetMsgDataOfSize(h_app, *p_buf, tmp_size);
+
+ if (e_status != eFrameworkunifiedStatusOK) {
+ POSITIONING_LOG("FrameworkunifiedGetMsgDataOfSize ERROR [e_status:%d]", e_status);
+ tmp_size = 0;
+ }
+ } else {
+ POSITIONING_LOG("FrameworkunifiedGetDataPointer ERROR [e_status:%d]", e_status);
+ tmp_size = 0;
+ }
+ }
+ }
+
+ return tmp_size;
+}
+
+static void PosCreateSharedMemory(void) {
+ RET_API ret_api = RET_NORMAL;
+ void *mod_exec_dmy; /* Module data pointer(dummy) */
+ int retry; /* Retry counter */
+ ST_SHAREDATA *p_shm_tbl;
+
+ /* Configure Shared Data Generating Tables */
+ p_shm_tbl = g_sharedata_tbl;
+
+ while (*(p_shm_tbl->share_data_name) != (int8)NULL) {
+ for (retry = 0; retry < DATMOD_RETRY; retry++) {
+ /* Shared Memory Generation */
+ ret_api = _pb_CreateShareData(p_shm_tbl->share_data_name, p_shm_tbl->data_size, &mod_exec_dmy);
+ if (ret_api == RET_NORMAL) {
+ /* Set the shared memory status flag to "Before initialization (0)" */
+ *reinterpret_cast<u_int32 *>(mod_exec_dmy) = DATMOD_PREINIT;
+ break;
+ } else {
+ /* Error Handling */
+ POSITIONING_LOG("_pb_CreateShareData ERROR [ret_api:%d]", ret_api);
+ }
+ }
+
+ if (retry >= DATMOD_RETRY) {
+ POSITIONING_LOG("_pb_CreateShareData failed more %d times.", DATMOD_RETRY);
+ _pb_Exit();
+ /* don't arrive here. */
+ }
+
+ /* Next shared memory generation */
+ p_shm_tbl++;
+ }
+ return;
+}
+
+EFrameworkunifiedStatus PosInitialize(HANDLE h_app) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ RET_API ret_api;
+ ret_api = _pb_Setup_CWORD64_API(h_app);
+ if (ret_api != RET_NORMAL) {
+ POSITIONING_LOG("_pb_Setup_CWORD64_API ERROR!! [ret_api = %d]", ret_api);
+
+ e_status = eFrameworkunifiedStatusFail;
+ } else {
+ PosCreateSharedMemory();
+ }
+ return e_status;
+}
+
+/**
+ * @brief
+ * Common processing after thread startup
+ *
+ * Thread naming, message queue creation, thread startup response
+ *
+ * @param[in] h_app Application handle
+ * @param[in] eTid Thread ID
+ *
+ * @return Thread startup mode
+ */
+EnumSetupMode_POS PosSetupThread(HANDLE h_app, EnumTID_POS e_tid) {
+ RET_API ret = RET_NORMAL;
+ ST_THREAD_CREATE_INFO* p_thread_info = g_pos_thread_create_info;
+ ST_THREAD_CREATE_INFO* p_info = p_thread_info + e_tid;
+ ST_THREAD_SETUP_INFO st_setup_info;
+ ST_THREAD_SETUP_INFO* pst_setup_info = &st_setup_info;
+ /* Application handle setting */
+ _pb_SetAppHandle(h_app);
+ /* Create Message Queue */
+ _pb_CreateMsg(p_info->p_no);
+ /* Get thread startup information */
+ pst_setup_info->mode = EPOS_SETUP_MODE_NORMAL;
+ (void)PosGetMsg(h_app, reinterpret_cast<void**>(&pst_setup_info), sizeof(ST_THREAD_SETUP_INFO));
+
+ POSITIONING_LOG("[mode = %d]", pst_setup_info->mode);
+
+ /* Issue thread creation completion notice */
+ ret = _pb_SndMsg_Ext(POS_THREAD_NAME,
+ CID_THREAD_CREATE_COMP,
+ sizeof(EnumTID_POS),
+ reinterpret_cast<const void*>(&e_tid),
+ 0);
+
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("_pb_SndMsg_Ext ERROR!! [ret = %d]", ret);
+ }
+
+ return pst_setup_info->mode;
+}
+
+/**
+ * @brief
+ * Common processing at thread stop
+ *
+ * Thread stop response, thread destruction
+ *
+ * @param[in] e_tid Thread ID
+ */
+void PosTeardownThread(EnumTID_POS e_tid) {
+ RET_API e_ret = RET_NORMAL;
+ ST_THREAD_CREATE_INFO* p_thread_info = g_pos_thread_create_info;
+
+ (p_thread_info + e_tid)->uc_status = THREAD_STS_NOEXIST;
+ /* Issue thread stop completion notice */
+ e_ret = _pb_SndMsg_Ext(POS_THREAD_NAME,
+ CID_THREAD_STOP_COMP,
+ sizeof(EnumTID_POS),
+ reinterpret_cast<const void*>(&e_tid),
+ 0);
+
+ if (e_ret != RET_NORMAL) {
+ POSITIONING_LOG("_pb_SndMsg_Ext ERROR!! [e_ret = %d]", e_ret);
+ }
+
+ /* Thread destruction */
+ _pb_ExitThread((DWORD)0);
+
+ return;
+}
+
+/**
+ * @brief
+ * Positioning in-process thread creation
+ *
+ * @param[in] hApp Application handle
+ */
+EFrameworkunifiedStatus PosCreateThread(HANDLE h_app, int8_t index) {
+ HANDLE thread_handle;
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ ST_THREAD_CREATE_INFO* p_thread_info = g_pos_thread_create_info;
+
+ p_thread_info += index;
+
+ static EnumSetupMode_POS g_setup_mode;
+
+ if (NULL == h_app) {
+ return eFrameworkunifiedStatusInvldHandle;
+ }
+
+ if (index < ETID_POS_MAX) {
+ if ((p_thread_info->uc_status == THREAD_STS_NOEXIST) && (p_thread_info->cb_routine != NULL)) {
+ /* Thread creation */
+ thread_handle = FrameworkunifiedCreateChildThread(h_app,
+ (PCSTR)(p_thread_info->p_name),
+ p_thread_info->cb_routine,
+ &PosStopThreadDummy);
+
+ if (thread_handle == NULL) {
+ POSITIONING_LOG("FrameworkunifiedCreateChildThread ERROR!! [tHandle=%p]", thread_handle);
+ } else {
+ e_status = FrameworkunifiedStartChildThread(h_app,
+ thread_handle,
+ sizeof(EnumSetupMode_POS),
+ &g_setup_mode);
+
+ if (e_status != eFrameworkunifiedStatusOK) {
+ POSITIONING_LOG("FrameworkunifiedStartChildThread ERROR!! [e_status=%d, name=%s]", e_status, p_thread_info->p_name);
+ } else {
+ p_thread_info->uc_status = THREAD_STS_CREATING;
+ POSITIONING_LOG("name=%s\n", p_thread_info->p_name);
+ }
+ }
+ }
+ }
+ return e_status;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/Common/positioning_hal.cpp b/hal/positioning_hal/src/Common/positioning_hal.cpp
new file mode 100755
index 0000000..94f79c4
--- /dev/null
+++ b/hal/positioning_hal/src/Common/positioning_hal.cpp
@@ -0,0 +1,49 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file positioning_hal.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include <stdio.h>
+
+#include "positioning_hal.h"
+#include "positioning_def.h"
+#include "positioning_common.h"
+
+/*---------------------------------------------------------------------------*/
+// Functions
+
+EFrameworkunifiedStatus StartGpsMainThreadPositioning(HANDLE h_app) {
+ return PosCreateThread(h_app, ETID_POS_GPS);
+}
+
+EFrameworkunifiedStatus StartGpsRecvThreadPositioning(HANDLE h_app) {
+ return PosCreateThread(h_app, ETID_POS_GPS_RECV);
+}
+
+EFrameworkunifiedStatus StartLineSensorThreadPositioning(HANDLE h_app) {
+ return PosCreateThread(h_app, ETID_POS_SENS);
+}
+
+EFrameworkunifiedStatus StartGpsRolloverThreadPositioning(HANDLE h_app) {
+ return eFrameworkunifiedStatusErrOther;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_GpsRecv.cpp b/hal/positioning_hal/src/GpsCommon/MDev_GpsRecv.cpp
new file mode 100755
index 0000000..13159b4
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_GpsRecv.cpp
@@ -0,0 +1,608 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_GpsRecv.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "MDev_GpsRecv.h"
+#include "MDev_Gps_Common.h"
+#include "positioning_common.h"
+#include "MDev_Gps_API.h"
+//extern "C" {
+//#include <stub/gps_mng_api.h>
+//}
+
+/*---------------------------------------------------------------------------*/
+// Global values
+
+#define FTEN_DRIVER 0
+#define TEST_HAL2
+
+#if FTEN_DRIVER
+static GpsMngApiObj g_gps_mng_obj;
+#endif
+
+/*---------------------------------------------------------------------------*/
+// Functions
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_RecvThread
+ * ABSTRACT : GPS communication management reception thread
+ * FUNCTION : GPS communication management reception thread main
+ * ARGUMENT : PVOID pv....Thread creation arguments
+ * NOTE : -
+ * RETURN : TRUE
+ ******************************************************************************/
+EFrameworkunifiedStatus DevGpsRecvThread(HANDLE h_app) {
+ int32 ret = GPS_RCV_RET_NML;
+ int32 gps_ret = 0;
+ BOOL* p_thread_stop_req = &g_gps_rcv_thread_stop;
+
+ (void)PosSetupThread(h_app, ETID_POS_GPS_RECV);
+
+ /* Initializing process */
+ DevGpsRecvInit();
+
+#if FTEN_DRIVER
+ gps_ret = GpsMngApiOpen(&g_gps_mng_obj);
+ if (gps_ret != GPS_CTL_RET_SUCCESS) {
+ printf("[For test] GpsMngApiOpen open failed\n");
+ }
+#endif
+
+ while (1) {
+ /* Thread stop request is received */
+ if (TRUE == *p_thread_stop_req) {
+ /* Thread stop processing */
+ DevGpsRecvThreadStopProcess();
+ }
+
+ ret = DevGpsRecvReadRcvData(&g_gps_rcvdata);
+
+ if (GPS_RCV_RET_NML == ret) {
+ /* For reception (normal) */
+ DevGpsRecvRcvNormal();
+ }
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_Recv_Init
+ * ABSTRACT : Receive thread initialization processing
+ * FUNCTION : Initialize the receive thread
+ * ARGUMENT : -
+ * NOTE : -
+ * RETURN : -
+ ******************************************************************************/
+void DevGpsRecvInit(void) {
+ /* Clears the receive buffer */
+ DevGpsRecvClrRcvBuf();
+
+ /* Clear receive error count */
+ g_wrecv_err = 0;
+
+ return;
+}
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_Recv_ClrRcvBuf
+ * ABSTRACT : Buffer clear processing
+ * FUNCTION : Clears the receive buffer for serial reception.
+ * ARGUMENT : -
+ * NOTE : -
+ * RETURN : -
+ ******************************************************************************/
+void DevGpsRecvClrRcvBuf(void) {
+ /*-----------------------------------------------------------------------*/
+ /* Clear serial receive data storage buffer */
+ /*-----------------------------------------------------------------------*/
+ memset(&g_gps_rcvdata, 0, sizeof(TG_GPS_RECV_RcvData));
+
+ /*-----------------------------------------------------------------------*/
+ /* Clear receive data storage buffer */
+ /*-----------------------------------------------------------------------*/
+ memset(&g_gps_rcvbuf, 0, sizeof(TG_GPS_RECV_RcvBuf));
+
+ /*-----------------------------------------------------------------------*/
+ /* Clear analysis data buffer */
+ /*-----------------------------------------------------------------------*/
+ memset(&g_gps_ana_databuf, 0, sizeof(TG_GPS_RECV_AnaDataBuf));
+
+ /*-----------------------------------------------------------------------*/
+ /* Clear receive frame buffer */
+ /*-----------------------------------------------------------------------*/
+ memset(&g_gps_rcv_framebuf, 0, sizeof(TG_GPS_RECV_RcvFrameBuf));
+}
+
+/*******************************************************************************
+ * MODULE : DevGpsRecvJudgeStartSeqence
+ * ABSTRACT : Start sequence determination process
+ * FUNCTION : Determine whether or not the beginning of the data is the start sequence of the _CWORD82_ command
+ * ARGUMENT : const u_char *buf_p ... Pointer to analysis data
+ * u_int16 ana_size ... Size of data to be analyzed
+ * NOTE :
+ * RETURN : GPS__CWORD82__RET_START_SEQ_NONE ... No start sequence
+ * GPS__CWORD82__RET_START_SEQ_NMEA ... NMEA Start Sequences
+ * GPS__CWORD82__RET_START_SEQ_FULL ... Full Customization Start Sequence
+ ******************************************************************************/
+static int32 DevGpsRecvJudgeStartSeqence(const u_char *buf_p, u_int16 ana_size) {
+ int32 ret = GPS__CWORD82__RET_START_SEQ_NONE;
+
+ if ((ana_size >= 1) && (buf_p[0] == 0x24u)) {
+ /* Ignore -> No applicable rules for MISRA-C */ /* 0x24: '$' QAC 285 */
+ ret = GPS__CWORD82__RET_START_SEQ_NMEA;
+ } else if ((ana_size >= 1) && (buf_p[0] == 0xB0)) {
+ ret = GPS__CWORD82__RET_START_SEQ_FULL;
+ } else if ((ana_size >= 1) && (buf_p[0] == 0xC6)) {
+ /* #GPF_60_024 */
+ ret = GPS__CWORD82__RET_START_SEQ_BIN;
+ } else if ((ana_size >= 1) && (buf_p[0] == 0xB5)) {
+ /* #GPF_60_024 */
+ ret = GPS_UBLOX_RET_START_SEQ_UBX;
+ } else {
+ ret = GPS__CWORD82__RET_START_SEQ_NONE;
+ }
+
+ return ret;
+}
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_Recv_SearchFrameData
+ * ABSTRACT : Frame detection processing
+ * FUNCTION : Find if a frame exists in the data
+ * ARGUMENT : TG_GPS_RECV_AnaDataBuf *adbuf_p ... Pointer to the analysis data storage buffer
+ * u_int16 *ana_size; ... Analysis completion data size
+ * NOTE : Since it is assumed that the beginning of the frame is stored in the analysis start offset,
+ * when the beginning of the frame is detected in the middle of the buffer,
+ * the processing is terminated with the data up to that point as abnormal format data.
+ * RETURN : GPS_RCV_FRMSRCH_ERR_FORMAT ... Frame format error
+ * GPS_RCV_FRMSRCH_FIXED ... Frame determination
+ * GPS_RCV_FRMSRCH_NOT_FIXED ... Frame undetermined
+ * GPS_RCV_FRMSRCH_NO_DATA ... No analysis data
+ ******************************************************************************/
+int32 DevGpsRecvSearchFrameData(const TG_GPS_RECV_AnaDataBuf *adbuf_p, u_int16 *ana_size) {
+ int32 ret = GPS_RCV_FRMSRCH_ERR_FORMAT; /* Return value(Frame format error) */
+ /* ++ GPS _CWORD82_ support */
+ int32 start_seq_type = GPS__CWORD82__RET_START_SEQ_NONE; /* Fully customized or NMEA */
+ /* -- GPS _CWORD82_ support */
+ u_int16 start_offset = 0; /* Analysis start offset */
+ u_int16 i = 0;
+ u_int16 d_size = 0; /* Unanalyzed data size */
+
+ /* Offset Initialization */
+ start_offset = adbuf_p->offset; /* Start of analysis */ /* Ignore -> No applicable rules for MISRA-C */
+
+ /* Setting of unanalyzed data size */
+ d_size = adbuf_p->datsize - start_offset;
+
+ /* For size 0 */
+ if (d_size == 0) {
+ /* No analysis data */
+ ret = GPS_RCV_FRMSRCH_NO_DATA;
+ /* Set the analysis completion size to 0. */
+ *ana_size = 0; /* Ignore -> No applicable rules for MISRA-C */
+ } else {
+ /* Since it is assumed that beginning of the frame is stored in the analysis start offset, */
+ /* determine if the start sequence is the first one. */
+
+ /* ++ GPS _CWORD82_ support */
+ start_seq_type = DevGpsRecvJudgeStartSeqence(&(adbuf_p->datbuf[start_offset]), d_size);
+
+ if (start_seq_type != GPS__CWORD82__RET_START_SEQ_NONE) {
+ /* -- GPS _CWORD82_ support */
+ /* Set the frame as undetermined */
+ ret = GPS_RCV_FRMSRCH_NOT_FIXED;
+
+ /* ++ GPS _CWORD82_ support */
+ /* Find end sequence */
+ if (start_seq_type == GPS__CWORD82__RET_START_SEQ_NMEA) {
+ for (i = 0; i < d_size; i++) {
+ if (adbuf_p->datbuf[(start_offset + i)] == 0x0A) {
+ /* If the end sequence is found, */
+ /* end as frame fix. */
+ ret = GPS_RCV_FRMSRCH_FIXED;
+
+ /* Set the frame size for the analysis completion size. */
+ *ana_size = i + 1;
+
+ break;
+ }
+ }
+
+ if (i == d_size) {
+ if (i >= GPS__CWORD82__CMD_LEN_MAX) {
+ /* If no end sequence is found, */
+ /* frame format error. */
+ ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
+ /* After that, searching for start sequence. */
+ } else {
+ /* Because the end sequence cannot be analyzed, */
+ /* frame undetermined. */
+ ret = GPS_RCV_FRMSRCH_NOT_FIXED;
+
+ /* Set the size of unanalyzed data for the analysis completion size. */
+ *ana_size = d_size;
+ }
+ }
+ } else if (start_seq_type == GPS__CWORD82__RET_START_SEQ_FULL) {
+ /* #GPF_60_024 */
+ /* Is there one frame of data for full customization information? */
+ if (d_size >= GPS__CWORD82__FULLBINARY_LEN) {
+ /* Is there an end sequence? */
+ if (adbuf_p->datbuf[( (start_offset + GPS__CWORD82__FULLBINARY_LEN) - 1)] == 0xDA) {
+ /* Ignore -> MISRA-C:2004 Rule 12.1 */
+ /* If an end sequence is found, */
+ /* end as frame fix. */
+ ret = GPS_RCV_FRMSRCH_FIXED;
+
+ /* Set the frame size for the analysis completion size. */
+ *ana_size = GPS__CWORD82__FULLBINARY_LEN;
+ } else {
+ /* If it is not an end sequence, */
+ /* frame format error. */
+ ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
+ /* Searching for Start Sequence */
+ }
+ } else {
+ /* Because the end sequence cannot be analyzed, */
+ /* frame undetermined. */
+ ret = GPS_RCV_FRMSRCH_NOT_FIXED;
+
+ /* Set the size of unanalyzed data for the analysis completion size. */
+ *ana_size = d_size;
+ }
+ } else if (start_seq_type == GPS__CWORD82__RET_START_SEQ_BIN) {
+ /* Is there data for one standard binary frame? */
+ if (d_size >= GPS__CWORD82__NORMALBINARY_LEN) {
+ /* Is there an end sequence? */
+ if (adbuf_p->datbuf[((start_offset + GPS__CWORD82__NORMALBINARY_LEN) - 1)] == 0xDA) {
+ /* Ignore -> MISRA-C:2004 Rule 12.1 */
+ /* If an end sequence is found, */
+ /* end as frame fix. */
+ ret = GPS_RCV_FRMSRCH_FIXED;
+
+ /* Set the frame size for the analysis completion size. */
+ *ana_size = GPS__CWORD82__NORMALBINARY_LEN;
+ } else {
+ /* If it is not an end sequence, */
+ /* frame format error. */
+ ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
+ /* Searching for Start Sequence */
+ }
+ } else {
+ /* Because the end sequence cannot be analyzed, */
+ /* frame undetermined. */
+ ret = GPS_RCV_FRMSRCH_NOT_FIXED;
+
+ /* Set the size of unanalyzed data for the analysis completion size. */
+ *ana_size = d_size;
+ }
+ } else if (start_seq_type == GPS_UBLOX_RET_START_SEQ_UBX) {
+ /* TODO Checksum calculation using data from start_offset to d_size */
+ /* TODO Check that the checksum is correct. (See test code.) */
+ /* If the if checksums match, */
+ /* end as frame fix. */
+ ret = GPS_RCV_FRMSRCH_FIXED;
+
+ /* Set the frame size for the analysis completion size. */
+ *ana_size = d_size;
+ } else {
+ }
+ /* -- #GPF_60_024 */
+ } else {
+ /* It is not a start sequence, so it is regarded as a frame format error. */
+ ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
+
+ /* After that, searching for Start Sequence. */
+ }
+
+ /* If the frame format is abnormal, search for the start sequence. */
+ if (ret == GPS_RCV_FRMSRCH_ERR_FORMAT) {
+ POSITIONING_LOG("FORMAT ERROR [start_seq_type:%d]\n", start_seq_type);
+
+ /* Assuming that the start sequence has not been found until the end, */
+ /* the size of the analysis completed is set as the size of the unanalyzed data. */
+ *ana_size = d_size;
+
+ /* ++ GPS _CWORD82_ support (Search from the second byte for safety (at least the first byte is checked at the beginning of the function)))*/
+ for (i = start_offset + 1; i < (u_int32)(start_offset + d_size); i++) {
+ /* for( i = (start_offset + 2); i < (u_int32)(start_offset + d_size); i++ ) */
+ /* -- GPS _CWORD82_ support */
+ /* Start Sequence? */
+ /* ++ GPS _CWORD82_ support */
+ if (DevGpsRecvJudgeStartSeqence(&(adbuf_p->datbuf[i]), d_size) != GPS__CWORD82__RET_START_SEQ_NONE) {
+ /* if( (adbuf_p->datbuf[(i-1)] == GPS_CODE_START_SQ_HI) && */
+ /* (adbuf_p->datbuf[i] == GPS_CODE_START_SQ_LOW) ) */
+ /* -- GPS _CWORD82_ support */
+ /* In the case of a start sequence, the analysis is completed before that. #01 */
+ *ana_size = (i - start_offset - 1);
+
+ break;
+ }
+ }
+ }
+ }
+
+ return ret;
+}
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_Recv_ReadRcvData
+ * ABSTRACT : Data reception processing
+ * FUNCTION : Read serial data
+ * ARGUMENT : TG_GPS_RECV_RcvData* pst_rcv_data : Receive data read buffer
+ * NOTE : -
+ * RETURN : T_ErrCodes Error code
+ * MCSUB_NML Normal
+ * MCCOM_ERR_SYSTEM Abnormality
+ ******************************************************************************/
+int32 DevGpsRecvReadRcvData(TG_GPS_RECV_RcvData* pst_rcv_data) {
+ int32 ret = GPS_RCV_RET_ERR;
+ INT32 gps_ret = 0;
+
+#if FTEN_DRIVER
+ static int msg_kind = GPS_RCV_NMEA_GGA;
+
+ // Serial data capture
+ GpsMngApiDat gps_mng_data;
+
+ memset(&gps_mng_data, 0, sizeof(gps_mng_data));
+#ifdef TEST_HAL2
+ if (msg_kind > GPS_RCV_NMEA_RMC) {
+ msg_kind = GPS_RCV_NMEA_GGA;
+ }
+#else
+ if (msg_kind == GPS_RCV_NMEA_GGA) {
+ msg_kind = GPS_RCV_NMEA_RMC;
+ } else if (msg_kind == GPS_RCV_NMEA_RMC) {
+ msg_kind = GPS_RCV_NMEA_GGA;
+ } else {
+ msg_kind = GPS_RCV_NMEA_GGA;
+ }
+#endif
+
+ gps_ret = GpsMngApiGetRcvMsg(&g_gps_mng_obj, msg_kind, &gps_mng_data);
+
+#ifdef TEST_HAL2
+ msg_kind++;
+#endif
+
+ pst_rcv_data->us_read_size = (u_int16)gps_mng_data.dataLength;
+
+ if (pst_rcv_data->us_read_size >= GPS_RCV_MAXREADSIZE) {
+ return GPS_RCV_RET_ERR_SYSTEM;
+ }
+
+ memcpy(pst_rcv_data->uc_read_data, gps_mng_data.data, pst_rcv_data->us_read_size);
+
+ // Add '\0'
+ pst_rcv_data->uc_read_data[pst_rcv_data->us_read_size] = '\0';
+
+ if (GPS_CTL_RET_SUCCESS != gps_ret) {
+ ret = GPS_RCV_RET_ERR_SYSTEM;
+ } else {
+ ret = GPS_RCV_RET_NML;
+ }
+#endif
+
+ return ret;
+}
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_Recv_RcvNormal
+ * ABSTRACT : Receive (normal) Receive processing
+ * FUNCTION : Receive (normal) Processing at event reception
+ * ARGUMENT : -
+ * NOTE :
+ * RETURN : -
+ ******************************************************************************/
+void DevGpsRecvRcvNormal(void) {
+ TG_GPS_RECV_RcvData* pst_rcv_data = NULL; /* Buffer for reading serial data */
+ TG_GPS_RECV_RcvBuf* pst_rcv_buf = NULL; /* Receive data storage buffer */
+ TG_GPS_RECV_AnaDataBuf* pst_ana_data_buf = NULL; /* Analysis data storage buffer */
+ TG_GPS_RECV_RcvFrameBuf* pst_rcv_frame_buf = NULL; /* Receive frame buffer */
+ int32 i_ret = 0; /* Frame Detection Result */
+ u_int16 ana_size = 0; /* Data analysis size storage */
+
+ /* Initializing process */
+ pst_ana_data_buf = &g_gps_ana_databuf;
+
+ /* Fast _CWORD71_ processing(memset fix) */
+ /* Initializes the offset that needs initialization in the receive data storage buffer. */
+ pst_ana_data_buf->offset = 0;
+
+ /* Serial continuous reception data analysis processing */
+ pst_rcv_data = &g_gps_rcvdata;
+ pst_rcv_buf = &g_gps_rcvbuf;
+ memcpy(&(pst_ana_data_buf->datbuf[0]), &(pst_rcv_buf->r_buf[0]), pst_rcv_buf->r_size);
+ memcpy(&(pst_ana_data_buf->datbuf[pst_rcv_buf->r_size]),
+ &(pst_rcv_data->uc_read_data[0]),
+ pst_rcv_data->us_read_size);
+
+ pst_ana_data_buf->datsize = pst_rcv_buf->r_size + pst_rcv_data->us_read_size;
+
+ /* Serial receive data analysis process */
+ do {
+ /* Frame detection processing */
+ i_ret = DevGpsRecvSearchFrameData(pst_ana_data_buf, &ana_size);
+
+ /* For frame determination */
+ if (i_ret == GPS_RCV_FRMSRCH_FIXED) {
+ /* Frames are stored in the receive frame buffer. */
+ pst_rcv_frame_buf = &g_gps_rcv_framebuf;
+ memset(pst_rcv_frame_buf, 0, sizeof(TG_GPS_RECV_RcvFrameBuf)); /* Ignore -> No applicable rules for MISRA-C */
+ /* Ignore -> No applicable rules for MISRA-C */ /* QAC 3200 */
+ memcpy(& (pst_rcv_frame_buf->buf[0]),
+ &(pst_ana_data_buf->datbuf[pst_ana_data_buf->offset]),
+ ana_size);
+ pst_rcv_frame_buf->size = ana_size;
+
+ /* Reception of the command */
+ /* Send receipt notice (command) to main thread */
+ /* Send Received Data to Main Thread */
+ DevGpsRecvSndRcvData(pst_rcv_frame_buf);
+ } else if (i_ret == GPS_RCV_FRMSRCH_NOT_FIXED) {
+ /* Store unconfirmed data in the received data storage buffer, */
+ /* and leave no unanalyzed data. */
+ memset(pst_rcv_buf, 0, sizeof(TG_GPS_RECV_RcvBuf)); /* Ignore -> No applicable rules for MISRA-C */
+ memcpy(& (pst_rcv_buf->r_buf[0]),
+ &(pst_ana_data_buf->datbuf[pst_ana_data_buf->offset]),
+ ana_size);
+ pst_rcv_buf->r_size = ana_size;
+ i_ret = GPS_RCV_FRMSRCH_NO_DATA;
+ } else if (i_ret == GPS_RCV_FRMSRCH_ERR_FORMAT) {
+ /* [Measures against resetting with 1S + _CWORD82_]From here */
+ /* Clears the unanalyzed data stored in the receive data storage buffer, */
+ /* and flag is set to "No Unparsed Data" so that data can be parsed from the beginning of the next. */
+ memset(&(pst_rcv_buf->r_buf[0]), 0, pst_rcv_buf->r_size);
+ pst_rcv_buf->r_size = 0;
+ i_ret = GPS_RCV_FRMSRCH_NO_DATA;
+ /* [Measures against resetting with 1S + _CWORD82_]Up to this point */
+ /* Since this section discards garbage data, */
+ /* not subject to diagnosis registration. */
+ /* Diagnosis registration check */
+ } else if (i_ret == GPS_RCV_FRMSRCH_NO_DATA) {
+ /* Ignore -> No applicable rules for MISRA-C */
+ memset(pst_rcv_buf, 0, sizeof(TG_GPS_RECV_RcvBuf));
+ /* Termination */
+ } else {
+ /* No unanalyzed data is assumed because it is impossible. */
+ i_ret = GPS_RCV_FRMSRCH_NO_DATA;
+
+ /* Ignore -> No applicable rules for MISRA-C */
+ memset(pst_rcv_buf, 0, sizeof(TG_GPS_RECV_RcvBuf));
+ }
+
+ /* Update analysis data offset */
+ pst_ana_data_buf->offset += ana_size;
+
+ /* Repeat until no unanalyzed data is found. */
+ } while (i_ret != GPS_RCV_FRMSRCH_NO_DATA);
+}
+
+/********************************************************************************
+ * MODULE : DEV_RcvDATA
+ * ABSTRACT : Acknowledgement
+ * FUNCTION : Send message notifications to the communication management thread
+ * ARGUMENT : TG_GPS_RCV_DATA *ptg_rcv_data....I/F information between the receiving thread
+ * and the communication management thread
+ * NOTE :
+ * RETURN : RET_API :RET_NORMAL:Normal completion
+ * :RET_ERROR:ABENDs
+ ********************************************************************************/
+RET_API DevRcvData(const TG_GPS_RCV_DATA* ptg_rcv_data) {
+ RET_API ret = RET_NORMAL; /* Return value */
+ u_int16 w_size = 0; /* Data length setting */
+ u_int16 w_all_len = 0; /* Sent message length */
+ u_int16 w_mode = 0; /* Mode information */
+ RID req_id = 0; /* Resources ID */
+ T_APIMSG_MSGBUF_HEADER tg_header; /* Message header */
+
+ // Initialzie struct
+ memset(&tg_header, 0, sizeof(tg_header));
+
+ /* Transmitting buffer */
+ u_int8 by_snd_buf[(sizeof(T_APIMSG_MSGBUF_HEADER) + sizeof(TG_GPS_RCV_DATA))];
+
+ /* Calculation of transmission data length */
+ w_size = ptg_rcv_data->bydata_len + sizeof(ptg_rcv_data->dwret_status) + sizeof(ptg_rcv_data->bydata_len);
+
+ /* <<Creation of message header section>>>> */
+ tg_header.signo = 0; /* Signal information setting */
+ tg_header.hdr.sndpno = PNO_NAVI_GPS_RCV; /* Source thread No. setting */
+ tg_header.hdr.respno = 0; /* Destination process No. */
+ tg_header.hdr.cid = CID_GPS_RECVDATA; /* Command ID setting */
+ tg_header.hdr.msgbodysize = w_size; /* Message data length setting */
+ tg_header.hdr.rid = req_id; /* Resource ID Setting */
+ tg_header.hdr.reserve = 0; /* Reserved area clear */
+
+ memcpy(&by_snd_buf[ 0 ], &tg_header, sizeof(T_APIMSG_MSGBUF_HEADER));
+ /* <<Creation of data section>> */
+ /* Copy data to send buffer */
+ memcpy(&by_snd_buf[ sizeof(T_APIMSG_MSGBUF_HEADER)], ptg_rcv_data, w_size);
+
+ /* <<Messaging>> */
+ /* Calculation of Sent Message Length */
+ w_all_len = w_size + sizeof(T_APIMSG_MSGBUF_HEADER);
+
+ /* Mode information(Reserved) */
+ w_mode = 0;
+
+ /* Message transmission request */
+ ret = _pb_SndMsg(PNO_NAVI_GPS_MAIN, w_all_len, reinterpret_cast<void*>(by_snd_buf), w_mode);
+
+ /* End of the process */
+ return ret;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Recv_SndRcvData
+ * ABSTRACT : Receive data transmission processing
+ * FUNCTION : Transmit received data
+ * ARGUMENT : TG_GPS_RECV_RcvFrameBuf *frame_baf Receive frame buffer pointer
+ * NOTE : Fetches a command from the receive frame buffer and
+ * issue received data notifications to the main thread
+ * RETURN : None
+ ********************************************************************************/
+void DevGpsRecvSndRcvData(const TG_GPS_RECV_RcvFrameBuf* p_frame_buf) {
+ TG_GPS_RCV_DATA tg_rcv_data;
+ u_int16 w_cmd_len = 0;
+
+ // Initialzie struct
+ memset(&tg_rcv_data, 0, sizeof(tg_rcv_data));
+
+ if (p_frame_buf != NULL) {
+ w_cmd_len = p_frame_buf->size;
+
+ if (w_cmd_len <= GPS_READ_LEN) {
+ /* Ignore -> No applicable rules for MISRA-C */
+ memset(&tg_rcv_data, 0, sizeof(TG_GPS_RCV_DATA));
+
+ /* Status Settings */
+ tg_rcv_data.dwret_status = GPS_RECVOK;
+
+ /* Command length setting */
+ tg_rcv_data.bydata_len = w_cmd_len;
+
+ /* Receive data setting */
+ /* Sending from the Beginning of the Sirf Binary #03 */
+ memcpy(&tg_rcv_data.bygps_data[0], &p_frame_buf->buf[0], w_cmd_len);
+
+ /* Issuance of reception notice */
+ DevRcvData(&tg_rcv_data); /* Ignore -> No applicable rules for MISRA-C */
+ }
+ }
+}
+
+/**
+ * @brief
+ * Pos_Gps_Recv Thread Stop Processing
+ */
+void DevGpsRecvThreadStopProcess(void) {
+#if FTEN_DRIVER
+ GpsMngApiClose(&g_gps_mng_obj);
+#endif
+ PosTeardownThread(ETID_POS_GPS_RECV);
+ return;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_GpsRollOver.cpp b/hal/positioning_hal/src/GpsCommon/MDev_GpsRollOver.cpp
new file mode 100755
index 0000000..62227c2
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_GpsRollOver.cpp
@@ -0,0 +1,275 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_GpsRollOver.cpp
+*/
+
+#include "MDev_GpsRollOver.h"
+
+#define TIM_ROLOVR_CALCORCNT_DAYS (1024 * 7) /*1024 weeks * 7 days */
+
+#define TMT_OK (1) /* Definition indicating normal status */
+#define TMT_NG (0) /* Definitions indicating abnormal status */
+#define TMT_TRUE (1) /* Definitions indicating the status for which the condition is true */
+#define TMT_FALSE (0) /* Definitions indicating a status in which the condition is false */
+
+#define TIM_ROLOVR_LEAPYEARDAYS (366) /*Number of days in the leap year */
+#define TIM_ROLOVR_NOTLEAPYEARDAYS (365) /*Year days in non-leap years */
+
+static const WORD kMonth[2][12] = {
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, /* Number of days per month(For non-leap year) */
+ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} /* Number of days per month(For leap years) */
+};
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * FUNCTION : ChkLeapYear
+ * Function : Leap year determination processing
+ * Feature Overview : Determine whether it is a leap year
+ * Input : u_int16 year
+ * Output : None
+ * Return value : u_int32
+ TMT_TRUE Leap year
+ TMT_FALSE Non-leap year
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static u_int32 ChkLeapYear(u_int16 year) {
+ int32 leap_year;
+
+ /* Leap year determination processing (select subscripts in the [LEAP YEAR] table) *The processing that matches the time correction processing after time difference value addition/subtraction is used. */
+ leap_year = TMT_FALSE;
+ if ((year % 4) == 0) {
+ leap_year = TMT_TRUE;
+ }
+ if ((year % 100) == 0) {
+ leap_year = TMT_FALSE;
+ }
+
+ if ((year % 400) == 0) {
+ leap_year = TMT_TRUE;
+ }
+
+ return (leap_year);
+}
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * FUNCTION : RollOverFormerLaterDays
+ * Function : Calculation of the number of days before and after
+ * Feature Overview : The number of days from the beginning of the month to the previous day of the specified date,
+ and calculates the number of days after a given date, up to the end of the month
+ * Input : TG_TIM_ROLOVR_YMD* base_ymd Reference date
+ * Output : u_int32* former_days Number of days before (number of days before the specified date from the beginning of the month)
+ u_int32* later_days Number of days after(Number of days following the specified date until the end of the month)
+ * Return value : None
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static void RollOverFormerLaterDays(TG_TIM_ROLOVR_YMD* base_ymd, u_int32* former_days, u_int32* later_days) {
+ int32 leap_year;
+
+ leap_year = ChkLeapYear(base_ymd->year);
+
+ *former_days = base_ymd->day - 1;
+
+ *later_days = kMonth[leap_year][base_ymd->month - 1] - base_ymd->day;
+}
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * FUNCTION : RollOverCalDaysWithinBY
+ * Function : Calculation of the difference in the number of days in the base year
+ * Feature Overview : Calculate the difference in the number of days between the base date and the conversion target date.
+ [Restriction]If the base date > conversion target date, the number of days difference is 0.
+ * Input : TG_TIM_ROLOVR_YMD* base_ymd Reference date
+ TG_TIM_ROLOVR_YMD* conv_ymd Conversion Date
+ * Output : None
+ * Return value : u_int32 Difference in the number of days(positive only)
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static u_int32 RollOverCalDaysWithinBY(TG_TIM_ROLOVR_YMD* base_ymd, TG_TIM_ROLOVR_YMD* conv_ymd) {
+ int32 leap_year; /* Subscripts in the [LEAP YEAR] table */
+ u_int32 days; /* Day Difference Calculation Result */
+ u_int32 l_days; /* Number of days after the reference month */
+ u_int32 f_days; /* Number of days before the conversion target month */
+ u_int32 dmy_days; /* Dummy days(For storing unnecessary number of days in this function) */
+ u_int32 m_days; /* Sum of the number of days in the month between the base month and the month to be converted */
+ int32 cnt; /* A counter that sums the number of days in a month between the base month and the month to be converted */
+ u_int16 diff_month; /* Difference between the conversion target month and the base month */
+ u_int16 chk_month; /* Number of days of month to be acquired */
+
+ days = 0;
+
+ if (base_ymd->month == conv_ymd->month) {
+ if (base_ymd->day <= conv_ymd->day) {
+ days = conv_ymd->day - base_ymd->day;
+ } else {
+ days = 0; /* Set the difference to 0(Negative difference in number of days is not calculated.) */
+ }
+ } else if (base_ymd->month < conv_ymd->month) {
+ RollOverFormerLaterDays(base_ymd, &dmy_days, &l_days);
+
+ m_days = 0;
+ diff_month = conv_ymd->month - base_ymd->month;
+
+ leap_year = ChkLeapYear(base_ymd->year);
+
+ /* Calculate the sum of the number of days in the month between the base month and the conversion target month B */
+ chk_month = base_ymd->month + 1;
+ for (cnt = 0; cnt < (diff_month - 1); cnt++) {
+ m_days += kMonth[leap_year][chk_month - 1];
+ chk_month++;
+ }
+
+ RollOverFormerLaterDays(conv_ymd, &f_days, &dmy_days);
+
+ days = l_days + m_days + f_days + 1; /* Calculate the difference in number of days as A+B+C+1 */
+
+ } else {
+ days = 0; /* Set the difference to 0(Negative difference in number of days is not calculated.) */
+ }
+
+ return days;
+}
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * FUNCTION : RollOverGetAYearDays
+ * Function : Process of obtaining the number of days per year
+ * Feature Overview : Get the number of days in a given year
+ * Input : u_int16 base_year Year
+ * Output : None
+ * Return value : u_int32 Number of days
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static u_int32 RollOverGetAYearDays(u_int16 base_year) {
+ int32 leap_year; /* Subscripts in the [LEAP YEAR] table */
+ u_int32 days;
+
+ leap_year = ChkLeapYear(base_year); /* Leap year determination processing */
+
+ if (leap_year == TMT_TRUE) {
+ days = TIM_ROLOVR_LEAPYEARDAYS;
+ } else {
+ days = TIM_ROLOVR_NOTLEAPYEARDAYS;
+ }
+
+ return days;
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * FUNCTION : RollOverConvYMDWithoutBY
+ * Function : Date conversion processing outside the base year, month, and day
+ * Feature Overview : Calculate the date shifted by the specified number of days from the specified date.
+ *If less than (1024 weeks x 7 days) is specified as the number of days difference, the calculation result is
+ returns the specified date(No correction)
+ * Input : TG_TIM_ROLOVR_YMD* base_ymd Reference date
+ u_int32 days Difference in the number of days
+ u_int32 days_by Number of days after + number of days after month
+ * Output : TG_TIM_ROLOVR_YMD* conv_ymd Date of the conversion result
+ * Return value : None
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static void RollOverConvYMDWithoutBY(TG_TIM_ROLOVR_YMD* base_ymd, u_int32 days,
+ u_int32 days_by, TG_TIM_ROLOVR_YMD* conv_ymd) {
+ int32 leap_year; /* Subscripts in the [LEAP YEAR] table */
+ u_int32 rest_days; /* Remaining number of days */
+ u_int16 cal_year; /* For year calculation */
+ u_int16 cal_month; /* For monthly calculation */
+ u_int32 cal_days; /* To calculate the number of days */
+
+ rest_days = days - days_by; /* Remaining number of days is different from the number of initialization days.-(Number of days after + Number of days after month) */
+ cal_year = base_ymd->year + 1; /* The year is set to the year following the year of the initialization reference date. */ /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+
+ cal_days = RollOverGetAYearDays(cal_year); /* Process of obtaining the number of days per year */
+
+ while (rest_days > cal_days) {
+ rest_days -= cal_days; /* Remaining Days = Remaining Days-Updated as Days of Year */
+
+ cal_year++; /* Increment Year */
+
+ cal_days = RollOverGetAYearDays(cal_year); /* Process of obtaining the number of days per year */
+ }
+
+ /* Year Finalization */
+ conv_ymd->year = cal_year; /* Year Calculated */
+
+ cal_month = 1; /* Initialize Month January */
+
+ leap_year = ChkLeapYear(conv_ymd->year); /* Leap year determination processing */
+
+ cal_days = kMonth[leap_year][cal_month - 1]; /* Acquisition processing of the number of days/month */ /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+
+ while (rest_days > cal_days) {
+ rest_days -= cal_days; /* Remaining Days = Remaining Days-Updated as Days of Month */
+
+ cal_month++; /* Increment month */
+
+ cal_days = kMonth[leap_year][cal_month - 1]; /* Acquisition processing of the number of days/month */ /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ }
+
+ /* Fix month */
+ conv_ymd->month = cal_month; /* Month Calculated */
+
+ /* Date set */
+ conv_ymd->day = (u_int16)rest_days; /* Day calculated Remaining number of days */
+}
+
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * FUNCTION : RollOverConvYMD
+ * Function : Date conversion processing
+ * Feature Overview : Calculate the date shifted by the specified number of days from the specified date.
+ *If the base date is shifted by the number of days but the year is the same as the base date, the result returns the base date
+ * Input : TG_TIM_ROLOVR_YMD* base_ymd Reference date
+ u_int32 days Difference in the number of days
+ * Output : TG_TIM_ROLOVR_YMD* conv_ymd Date of the conversion result
+ * Return value : None
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static void RollOverConvYMD(TG_TIM_ROLOVR_YMD* base_ymd, u_int32 days, TG_TIM_ROLOVR_YMD* conv_ymd) {
+ u_int32 days_by; /* Number of days after + number of days after month(=difference in number of days from the base date to the end of the year) */
+ TG_TIM_ROLOVR_YMD tmp_ymd;
+
+
+ /* (number of days after + number of days after)Set calculation date( 12/31 ) */
+ tmp_ymd.year = base_ymd->year;
+ tmp_ymd.month = 12;
+ tmp_ymd.day = 31;
+
+ days_by = RollOverCalDaysWithinBY(base_ymd, &tmp_ymd); /* Calculation of the difference in the number of days in the base year */
+
+ if (days_by >= days) {
+ memcpy(conv_ymd, base_ymd, sizeof(TG_TIM_ROLOVR_YMD)); /* Returns the base date regardless of the number of days difference */
+
+ } else {
+ RollOverConvYMDWithoutBY(base_ymd, days, days_by, conv_ymd);
+ }
+}
+
+
+
+/**
+ * @brief
+ * Conversion to a time that takes the GPS week correction counter into account
+ *
+ * Converting the GPS Week Correction Counter to a Considered Time
+ *
+ * @param[in] TG_TIM_ROLOVR_YMD* base_ymd Reference date
+ * @param[in] u_int8 gpsweekcorcnt GPS weekly correction counter
+ * @param[out] TG_TIM_ROLOVR_YMD* conv_ymd Correction Date
+ * @return none
+ * @retval none
+ */
+void GPSRollOverConvTime(TG_TIM_ROLOVR_YMD* base_ymd, TG_TIM_ROLOVR_YMD* conv_ymd, u_int8 gpsweekcorcnt) {
+ u_int32 days; /* Difference in the number of days */
+
+ days = TIM_ROLOVR_CALCORCNT_DAYS * gpsweekcorcnt; /* (1024 weeks x 7 days) x GPS week correction counter to calculate the difference in the number of days */
+
+ RollOverConvYMD(base_ymd, days, conv_ymd); /* Date conversion processing */
+}
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_Gps_API.cpp b/hal/positioning_hal/src/GpsCommon/MDev_Gps_API.cpp
new file mode 100755
index 0000000..35f5201
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_Gps_API.cpp
@@ -0,0 +1,491 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_API.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "MDev_Gps_API.h"
+#include "positioning_hal.h"
+#include "positioning_def.h"
+#include "MDev_Gps_Nmea.h"
+
+/*---------------------------------------------------------------------------*/
+// Functions
+
+/******************************************************************************
+@brief SendNmeaGps<BR>
+ NMEA transmission process
+@outline Send NMEA to VehicleSensor Thread
+@param[in] TG_GPS_NMEA* : pstNmeaData ... NMEA data
+@param[out] none
+@return RET_API
+@retval RET_NORMAL : Normal completion
+@retval RET_ERROR : ABENDs
+*******************************************************************************/
+RET_API SendNmeaGps(const MDEV_GPS_NMEA* p_nmea_data) {
+ MDEV_GPS_RAWDATA_NMEA_MSG s_send_msg;
+ SENSOR_MSG_GPSDATA s_msg_buf;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /* Create GPS Data Notification Message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /* Message header */
+ s_send_msg.h_dr.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.h_dr.hdr.respno = 0x0000;
+ s_send_msg.h_dr.hdr.cid = CID_GPS_DATA;
+ s_send_msg.h_dr.hdr.msgbodysize = sizeof(MDEV_GPS_RAWDATA_NMEA);
+ s_send_msg.h_dr.hdr.rid = 0x00;
+
+ /* Message data */
+ s_send_msg.st_data.e_kind = MDEV_GPS_DATA_RAWDATA_NMEA;
+ (void)memcpy(&(s_send_msg.st_data.st_nmea_data), p_nmea_data, sizeof(s_send_msg.st_data.st_nmea_data));
+
+ /* Create message buffer */
+ (void)memset(&s_msg_buf, 0, sizeof(s_msg_buf));
+ (void)memcpy(&(s_msg_buf.st_head.hdr), &(s_send_msg.h_dr.hdr), sizeof(T_APIMSG_HEADER));
+
+ s_msg_buf.st_para.ul_did = POS_DID_GPS_NMEA;
+ s_msg_buf.st_para.us_size = GPS_NMEA_SZ;
+
+ (void)memcpy(&(s_msg_buf.st_para.uc_data), &(s_send_msg.st_data.st_nmea_data), s_msg_buf.st_para.us_size);
+
+ ret = _pb_SndMsg(u_pno, sizeof(s_msg_buf), &s_msg_buf, 0);
+
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("_pb_SndMsg ERROR!! [ret=%d]\n", ret);
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief
+ * GPS processing data transmission process
+ *
+ * @param[in] pstGpsTime SENSOR_MSG_GPSTIME - GPS time information
+ * @param[in] p_lonlat SENSORLOCATION_LONLATINFO - Latitude and longitude information
+ * @param[in] p_altitude SENSOR_LOCATION_ALTITUDEINFO - Altitude information
+ * @param[in] p_heading SENSORMOTION_HEADINGINFO_DAT - Bearing information
+ *
+ * @return RET_NORMAL Normal completion
+ * RET_ERROR ABENDs
+ */
+RET_API SendCustomGps(const SENSOR_MSG_GPSTIME* p_gps_time,
+ const SENSORLOCATION_LONLATINFO_DAT* p_lonlat,
+ const SENSORLOCATION_ALTITUDEINFO_DAT* p_altitude,
+ const SENSORMOTION_HEADINGINFO_DAT* p_heading,
+ const NAVIINFO_DIAG_GPS* p_diag_data) {
+ SENSOR_MSG_GPSDATA s_send_msg = {0};
+ MDEV_GPS_CUSTOMDATA* p_custom_data = NULL;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ /* Fast _CWORD71_ processing(memset fix) */
+ /* Initializes an area whose value is undefined in the message buffer. */
+ (void)memset(&s_send_msg.st_head, 0x00, sizeof(s_send_msg.st_head));
+
+ /** Message header */
+ s_send_msg.st_head.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.st_head.hdr.respno = 0x0000;
+ s_send_msg.st_head.hdr.cid = CID_GPS_DATA;
+ s_send_msg.st_head.hdr.msgbodysize = sizeof(MDEV_GPS_CUSTOMDATA);
+ s_send_msg.st_head.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_para.ul_did = VEHICLE_DID_GPS_CUSTOMDATA;
+ s_send_msg.st_para.us_size = sizeof(MDEV_GPS_CUSTOMDATA);
+ p_custom_data = reinterpret_cast<MDEV_GPS_CUSTOMDATA *>(&(s_send_msg.st_para.uc_data));
+
+ (void)memcpy(&(p_custom_data->st_lonlat), p_lonlat, sizeof(SENSORLOCATION_LONLATINFO_DAT));
+ (void)memcpy(&(p_custom_data->st_altitude), p_altitude, sizeof(SENSORLOCATION_ALTITUDEINFO_DAT));
+ (void)memcpy(&(p_custom_data->st_heading), p_heading, sizeof(SENSORMOTION_HEADINGINFO_DAT));
+ (void)memcpy(&(p_custom_data->st_diag_gps), p_diag_data, sizeof(NAVIINFO_DIAG_GPS));
+ (void)memcpy(&(p_custom_data->st_gps_time), p_gps_time, sizeof(SENSOR_MSG_GPSTIME));
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, sizeof(s_send_msg), reinterpret_cast<void*>(&s_send_msg), 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/******************************************************************************
+@brief SendSpeedGps<BR>
+ Rate information transmission processing
+@outline Sending speed information to vehicle sensor thread
+@param[in] SENSORMOTION_SPEEDINFO_DAT* : p_seed ... Velocity information
+@param[in] u_int16 : us_peed ... Vehicle speed(km/h)
+@param[out] none
+@return RET_API
+@retval RET_NORMAL : Normal completion
+@retval RET_ERROR : ABENDs
+*******************************************************************************/
+RET_API SendSpeedGps(const SENSORMOTION_SPEEDINFO_DAT* p_seed, u_int16 us_peed) {
+ MDEV_GPS_NAVISPEED_MSG s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /** Message header */
+ s_send_msg.h_dr.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.h_dr.hdr.respno = 0x0000;
+ s_send_msg.h_dr.hdr.cid = CID_GPS_DATA;
+ s_send_msg.h_dr.hdr.msgbodysize = sizeof(MDEV_GPS_NAVISPEED);
+ s_send_msg.h_dr.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_data.e_kind = MDEV_GPS_DATA_NAVISPEED;
+ s_send_msg.st_data.us_speed_kmph = us_peed;
+
+ (void)memcpy( &s_send_msg.st_data.st_speed, p_seed, sizeof(s_send_msg.st_data.st_speed) );
+
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, (sizeof(T_APIMSG_MSGBUF_HEADER) + sizeof(MDEV_GPS_NAVISPEED)), &s_send_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/* ++ #GPF_60_103 */
+/******************************************************************************
+@brief SendTimeGps<BR>
+ Time information transmission processing
+@outline Send GPS time information to vehicle sensor thread
+@param[in] MDEV_GPS_RTC* : p_rtc ... GPS time information
+@param[out] none
+@return RET_API
+@retval RET_NORMAL : Normal completion
+@retval RET_ERROR : ABENDs
+*******************************************************************************/
+RET_API SendTimeGps(const MDEV_GPS_RTC* p_rtc) {
+ MDEV_GPS_GPSTIME_MGS s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS data notification message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /** Message header */
+ s_send_msg.h_dr.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.h_dr.hdr.respno = 0x0000;
+ s_send_msg.h_dr.hdr.cid = CID_GPS_DATA;
+ s_send_msg.h_dr.hdr.msgbodysize = sizeof(MDEV_GPS_GPSTIME);
+ s_send_msg.h_dr.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_data.e_kind = MDEV_GPS_DATA_GPSTIME;
+
+ (void)memcpy(&s_send_msg.st_data.st_rtc_data, p_rtc, sizeof(s_send_msg.st_data.st_rtc_data));
+
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, (sizeof(T_APIMSG_MSGBUF_HEADER) + sizeof(MDEV_GPS_GPSTIME)), &s_send_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief
+ * GPS clock drift transmit process
+ *
+ * @param[in] drift Clock drift
+ *
+ * @return RET_NORMAL Normal completion
+ * @return RET_ERROR ABENDs
+ */
+RET_API SendClockDriftGps(int32_t drift) {
+ SENSOR_MSG_GPSDATA s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /** Message header */
+ s_send_msg.st_head.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.st_head.hdr.respno = 0x0000;
+ s_send_msg.st_head.hdr.cid = CID_GPS_DATA;
+ s_send_msg.st_head.hdr.msgbodysize = sizeof(SENSOR_MSG_GPSDATA_DAT);
+ s_send_msg.st_head.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_para.ul_did = VEHICLE_DID_GPS_CLOCK_DRIFT;
+ s_send_msg.st_para.us_size = sizeof(int32_t);
+
+ (void)memcpy(&(s_send_msg.st_para.uc_data), &drift, s_send_msg.st_para.us_size);
+
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, sizeof(s_send_msg), &s_send_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief
+ * GPS clock-frequency transmit process
+ *
+ * @param[in] Freq Clocking frequencies
+ *
+ * @return RET_NORMAL Normal completion
+ * @return RET_ERROR ABENDs
+ */
+RET_API SendClockFrequencyGps(uint32_t freq) {
+ SENSOR_MSG_GPSDATA s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /** Message header */
+ s_send_msg.st_head.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.st_head.hdr.respno = 0x0000;
+ s_send_msg.st_head.hdr.cid = CID_GPS_DATA;
+ s_send_msg.st_head.hdr.msgbodysize = sizeof(SENSOR_MSG_GPSDATA_DAT);
+ s_send_msg.st_head.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_para.ul_did = VEHICLE_DID_GPS_CLOCK_FREQ;
+ s_send_msg.st_para.us_size = sizeof(uint32_t);
+
+ (void)memcpy(&(s_send_msg.st_para.uc_data), &freq, s_send_msg.st_para.us_size);
+
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, sizeof(s_send_msg), &s_send_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return(ret);
+}
+
+/**
+ * @brief
+ * GPS rollover standard week number transmission processing
+ *
+ * @param[in] *p_week_rollover GPS rollover base week number
+ *
+ * @return RET_NORMAL Normal completion
+ * @return RET_ERROR ABENDs
+ */
+RET_API DevGpsSndWknRollover(const SensorWknRollOverHal* p_week_rollover) {
+ SENSOR_MSG_GPSDATA s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ (void)memset( &s_send_msg, 0x00, sizeof(s_send_msg) );
+
+ /** Message header */
+ s_send_msg.st_head.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.st_head.hdr.respno = 0x0000;
+ s_send_msg.st_head.hdr.cid = CID_GPS_DATA;
+ s_send_msg.st_head.hdr.msgbodysize = sizeof(SensorWknRollOverHal);
+ s_send_msg.st_head.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_para.ul_did = VEHICLE_DID_GPS_WKNROLLOVER;
+ s_send_msg.st_para.us_size = sizeof(SensorWknRollOverHal);
+
+ (void)memcpy(&(s_send_msg.st_para.uc_data), p_week_rollover, s_send_msg.st_para.us_size);
+
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, sizeof(s_send_msg), &s_send_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/******************************************************************************
+@brief DevGpsRstAnsSend<BR>
+ Reset response issuance processing
+@outline Issue a reset response
+@param[in] PNO : u_pno ... Notify-To Process No.
+@param[in] RID : uc_rid ... Response resource ID
+@param[in] u_int32 : ul_rst_sts ... Response result
+@param[out] none
+@return int32
+@retval RET_NORMAL : Normal
+@retval RET_ERROR : Abnormality
+*******************************************************************************/
+int32 DevGpsRstAnsSend(PNO u_pno, RID uc_rid, u_int32 ul_rst_sts) {
+ TG_GPS_RET_RESET_MSG s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PCSTR l_thread_name;
+
+ if (u_pno != PNO_NONE) {
+ /** Create GPS Reset Notification Message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /** Message data */
+ s_send_msg.data.ret_rst_status = ul_rst_sts;
+
+ /* Messaging */
+ l_thread_name = _pb_CnvPno2Name(u_pno);
+ /* External Process Transmission and Reception Messages */
+ ret = _pb_SndMsg_Ext(l_thread_name,
+ CID_POSIF_REQ_GPS_RESET,
+ sizeof(s_send_msg.data),
+ reinterpret_cast<void *>(&(s_send_msg.data)),
+ 0);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("GpsCommCtl # DevGpsRstAnsSend SndMsg Error ret[%d] pno[%03X]\n", ret, u_pno);
+ ret = RET_ERROR;
+ }
+ }
+
+ return ret;
+}
+
+
+/**
+ * @brief Time setting response issuance processing
+ *
+ * @param[in] us_pno Notify-To Process No.
+ * @param[in] uc_rid Response resource ID
+ * @param[in] ul_rst_sts Response result
+ *
+ * @return Processing result
+ * @retval RET_NORMAL : Normal
+ * @retval RET_ERROR : Abnormality
+ */
+int32 DevGpsTimesetAnsSend(PNO us_pno, RID uc_rid, u_int32 ul_rst_sts) {
+ TG_GPS_RET_TIMESET_MSG st_snd_msg;
+ RET_API ret = RET_NORMAL;
+
+ /** Create GPS Reset Notification Message */
+ memset( &st_snd_msg, 0x00, sizeof(st_snd_msg) ); /* QAC 3200 */
+ /** Message header */
+ st_snd_msg.header.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ st_snd_msg.header.hdr.respno = 0x0000;
+ st_snd_msg.header.hdr.cid = CID_GPS_RETTIMESETTING;
+ st_snd_msg.header.hdr.msgbodysize = sizeof(st_snd_msg.status);
+ st_snd_msg.header.hdr.rid = uc_rid;
+ /** Message data */
+ st_snd_msg.status = ul_rst_sts;
+
+ /* Messaging */
+ if (us_pno != PNO_NONE) {
+ ret = _pb_SndMsg(us_pno, sizeof(st_snd_msg), &st_snd_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("DevGpsTimesetAnsSend SndMsg Error ret[%d] pno[%03X] \r\n", ret, us_pno);
+
+ ret = RET_ERROR;
+ }
+ }
+
+ return(ret);
+}
+
+
+/**
+ * @brief
+ * GPS clock drift transmit process
+ *
+ * @param[in] drift Clock drift
+ *
+ * @return RET_NORMAL Normal completion
+ * @return RET_ERROR ABENDs
+ *
+ */
+RET_API DevSendGpsConnectError(BOOL is_err) {
+ SENSOR_MSG_GPSDATA s_send_msg;
+ RET_API ret = RET_NORMAL;
+ PNO u_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ (void)memset(&s_send_msg, 0x00, sizeof(s_send_msg));
+
+ /** Message header */
+ s_send_msg.st_head.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ s_send_msg.st_head.hdr.respno = 0x0000;
+ s_send_msg.st_head.hdr.cid = CID_GPS_DATA;
+ s_send_msg.st_head.hdr.msgbodysize = sizeof(SENSOR_MSG_GPSDATA_DAT);
+ s_send_msg.st_head.hdr.rid = 0x00;
+
+ /** Message data */
+ s_send_msg.st_para.ul_did = POSHAL_DID_GPS_CONNECT_ERROR;
+ s_send_msg.st_para.us_size = sizeof(uint32_t);
+
+ (void)memcpy(&(s_send_msg.st_para.uc_data), &is_err, s_send_msg.st_para.us_size);
+
+ /* Messaging */
+ ret = _pb_SndMsg(u_pno, sizeof(s_send_msg), &s_send_msg, 0);
+
+ if (ret != RET_NORMAL) {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+
+RET_API SndGpsTimeRaw(const SENSOR_GPSTIME_RAW* ps_gpstime_raw) {
+ SENSOR_MSG_GPSDATA st_snd_msg;
+ RET_API ret;
+ PNO _us_pno = PNO_VEHICLE_SENSOR;
+
+ /** Create GPS Data Notification Message */
+ (void)memset( &st_snd_msg, 0x00, sizeof(st_snd_msg) ); /* QAC 3200 */
+ /** Message header */
+ st_snd_msg.st_head.hdr.sndpno = PNO_NAVI_GPS_MAIN;
+ st_snd_msg.st_head.hdr.respno = 0x0000;
+ st_snd_msg.st_head.hdr.cid = CID_GPS_DATA;
+ st_snd_msg.st_head.hdr.msgbodysize = sizeof(SENSOR_MSG_GPSDATA_DAT);
+ st_snd_msg.st_head.hdr.rid = 0x00;
+ /** Message data */
+ st_snd_msg.st_para.ul_did = VEHICLE_DID_GPS_TIME_RAW;
+ st_snd_msg.st_para.us_size = sizeof(SENSOR_GPSTIME_RAW);
+ (void)memcpy(&(st_snd_msg.st_para.uc_data), ps_gpstime_raw, st_snd_msg.st_para.us_size); /* QAC 3200 */
+
+ /* Messaging */
+ ret = _pb_SndMsg( _us_pno, sizeof(st_snd_msg), &st_snd_msg, 0 );
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("_pb_SndMsg ERROR!! [ret=%d]\n", ret);
+ ret = RET_ERROR;
+ }
+
+ return(ret);
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_Gps_Common.cpp b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Common.cpp
new file mode 100755
index 0000000..c8b5c9a
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Common.cpp
@@ -0,0 +1,2105 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Common.h
+*/
+
+/*---------------------------------------------------------------------------*/
+
+#include "MDev_Gps_Common.h"
+
+#include <native_service/ns_backup.h>
+#include <native_service/ns_backup_id.h>
+#include "positioning_common.h"
+#include "MDev_Gps_API.h"
+#include "MDev_Gps_TimerCtrl.h"
+#include "MDev_Gps_Nmea.h"
+#include "MDev_GpsRecv.h"
+
+/*---------------------------------------------------------------------------*/
+// Value define
+
+#define BK_ID_POS_GPS_TD_STS_SZ 1 /* Datetime Status-Size */
+#define BK_GPSFIXCNT_OFFSET_CHK 12 /* Fix Count-Offset-Check SRAM */
+#define BK_GPSFIXCNT_RAM_OK 0 /* Fix Count RAM Status OK */
+#define BK_GPSFIXCNT_RAM_FILE_NG 1 /* Fix Count RAM Status FILE NG */
+#define BK_GPSFIXCNT_RAM_NG 2 /* Fix Count RAM Status NG */
+
+#define JULIAN_DAY (-32044.0f) /* Be based on March 1, 4800 BC */
+#define MODIFIED_JULIAN_DAY_OFFSET (2400000.5f)
+#define GPS_WS_MAX (7 * 24 * 60 * 60) /* GPS time(Weekly seconds)*/
+#define GET_METHOD_GPS (1) //!< \~english GPS
+
+/* Presence information definitions DR */
+#define SENSORLOCATION_EXISTDR_NODR (0) /* Without DR */
+#define SENSORLOCATION_EXISTDR_DR (1) /* There DR */
+/* DR state definition */
+#define SENSORLOCATION_DRSTATUS_INVALID (0) /* Invalid */
+#define SENSORLOCATION_DRSTATUS_GPS_NODR (1) /* Information use GPS, not yet implemented DR */
+#define SENSORLOCATION_DRSTATUS_NOGPS_DR (2) /* No information available GPS, DR implementation */
+#define SENSORLOCATION_DRSTATUS_GPS_DR (3) /* Information use GPS, DR implementation */
+
+#define SENSORLOCATION_STATUS_DISABLE (0) //!< \~english Not available
+#define SENSORLOCATION_STATUS_ENABLE (1) //!< \~english Available
+/*---------------------------------------------------------------------------*/
+// Global values
+
+uint8_t g_gps_reset_cmd_sending = FALSE; /* Reset command transmission in progress judgment flag */
+uint8_t g_is_gpstime_sts = FALSE; /* Date/Time Status Fixed Value Setting Indication Flag */
+uint8_t g_gpstime_raw_tdsts = 0;
+extern u_int8 g_gps_week_cor_cnt;
+/*---------------------------------------------------------------------------*/
+// Functions
+void WriteGpsTimeToBackup(uint8_t flag, POS_DATETIME* pst_datetime) {
+ int32_t ret;
+ ST_GPS_SET_TIME buf;
+
+ memset(reinterpret_cast<void *>(&buf), 0, (size_t)sizeof(buf));
+
+ buf.flag = flag;
+ buf.year = pst_datetime->year;
+ buf.month = pst_datetime->month;
+ buf.date = pst_datetime->date;
+ buf.hour = pst_datetime->hour;
+ buf.minute = pst_datetime->minute;
+ buf.second = pst_datetime->second;
+
+ ret = Backup_DataWt(D_BK_ID_POS_GPS_TIME_SET_INFO, &buf, 0, sizeof(ST_GPS_SET_TIME));
+ if (ret != BKUP_RET_NORMAL) {
+ POSITIONING_LOG("Backup_DataWt ERROR!! [ret=%d]", ret);
+ }
+
+ return;
+}
+
+
+
+/********************************************************************************
+ * MODULE : ChangeStatusGpsCommon
+ * ABSTRACT : State transition processing
+ * FUNCTION : Changes the state of the GPS communication management process to the specified state
+ * ARGUMENT : u_int32 sts : State of the transition destination
+ * NOTE :
+ * RETURN : None
+ ********************************************************************************/
+void ChangeStatusGpsCommon(u_int32 sts ) {
+ /* Set the transition destination state in the management information state */
+ g_gps_mngr.sts = sts;
+}
+
+/********************************************************************************
+ * MODULE : RtyResetGpsCommon
+ * ABSTRACT : Reset retry counter(Periodic reception)
+ * FUNCTION : Reset the retry counter
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : None
+ ********************************************************************************/
+void RtyResetGpsCommon(void) {
+ g_gps_mngr.hrsetcnt = 0; /* Initialization of the number of tries until a hard reset */
+ g_gps_mngr.sndngcnt = 0; /* Initialization of the number of tries until serial reset */
+}
+
+/******************************************************************************
+@brief SendRtyResetGpsCommon<BR>
+ Reset retry counter(ACK response)
+@outline Reset the retry counter
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void SendRtyResetGpsCommon(void) {
+ g_gps_mngr.sndcnt = 0; /* Initialization of the number of transmission retries */
+}
+
+uint8_t HardResetChkGpsCommon(void) {
+ uint8_t ret = RETRY_OFF; /* Return value */
+ static uint8_t uc_hardreset_cnt = 0; /* Number of hard resets */
+
+ g_gps_mngr.hrsetcnt++; /* Add number of tries until hard reset */
+
+ if (g_gps_mngr.hrsetcnt >= HRSET_MAX) {
+ // Todo For test don't have hardReset Method.
+ // DEV_Gps_HardReset();
+
+ g_gps_mngr.hrsetcnt = 0; /* Initialization of the number of tries until a hard reset */
+ /* Discard all pending commands */
+ DeleteAllSaveCmdGpsCommon();
+ /* Determination of the number of hard reset executions */
+ uc_hardreset_cnt++;
+ if (uc_hardreset_cnt >= 3) {
+ ret = RETRY_OFF; /* Set the return value (No retry: Specified number of hard resets completed) */
+ uc_hardreset_cnt = 0; /* Clear the number of hard resets */
+ } else {
+ ret = RETRY_OUT; /* Set the return value (retry out: hardware reset) */
+ }
+ } else { /* When the number of tries until the hard reset is less than the maximum value */
+ ret = RETRY_ON; /* Set return value (with retry) */
+ }
+
+ return (ret); /* End of the process */
+}
+
+
+/******************************************************************************
+@brief SendReqGpsCommon<BR>
+ Common-Transmit Request Reception Matrix Function
+@outline Common processing when receiving a transmission request
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void SendReqGpsCommon(void) {
+ RET_API ret = RET_NORMAL;
+ TG_GPS_SND_DATA* p_rcv_data = NULL;
+ TG_GPS_SAVECMD s_send_data;
+ TG_GPS_OUTPUT_FORMAT s_output_format;
+
+ p_rcv_data = reinterpret_cast<TG_GPS_SND_DATA*>(&(g_gps_msg_rcvr.msgdat[0])); /* Incoming message structure */
+
+ /** Transmit Data Format Check */
+ ret = CheckSendCmdGpsCommon(p_rcv_data->ub_data, p_rcv_data->us_size, &s_output_format);
+
+ /** Normal format */
+ if (ret == RET_NORMAL) {
+ memset( &s_send_data, 0x00, sizeof(s_send_data) ); /* Ignore -> MISRA-C:2004 Rule 16.10 */
+
+ s_send_data.us_pno = 0; /* Result notification destination process number */
+ s_send_data.uc_rid = 0; /* Result Notification Resource ID */
+ s_send_data.uc_rst = GPS_CMD_NOTRST; /* Reset flag */
+ s_send_data.e_cmd_info = s_output_format; /* Command information */
+ memcpy( &s_send_data.sndcmd, p_rcv_data, sizeof(TG_GPS_SND_DATA) ); /* Sending commands */
+
+ /* Command is suspended and terminated. */
+ ret = DevGpsSaveCmd(&s_send_data); /* #GPF_60_040 */
+
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("GPS Command Reserve bufferFull ! \r\n");
+ }
+ } else {
+ POSITIONING_LOG("# GpsCommCtl # GPS Command Format Error!! \r\n");
+ }
+
+ return;
+}
+
+/******************************************************************************
+@brief GPSResetReqGpsCommon<BR>
+ Common-GPS reset request reception matrix function
+@outline Common processing at GPS reset reception
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void GPSResetReqGpsCommon(void) {
+ RET_API ret = RET_NORMAL;
+ POS_RESETINFO st_rcv_msg;
+
+ memset(&st_rcv_msg, 0x00, sizeof(st_rcv_msg)); /* 2015/03/31 Coverity CID: 21530 support */
+
+ if (g_gps_reset_cmd_sending == FALSE) {
+ memcpy(&st_rcv_msg, reinterpret_cast<POS_RESETINFO *>(&(g_gps_msg_rcvr.msgdat)),
+ sizeof(POS_RESETINFO));
+ ret = DevGpsResetReq(st_rcv_msg.respno, 0);
+ if (ret == RET_NORMAL) {
+ /* Set the reset command transmission judgment flag to transmission in progress */
+ g_gps_reset_cmd_sending = TRUE;
+ /* Send reset command(Normal response transmission)*/
+ GpsSetPosBaseEvent(st_rcv_msg.sndpno, POS_RET_NORMAL);
+ } else if (ret == RET_EV_NONE) {
+ /* nop */
+ } else {
+ /* Send reset command(Internal Processing Error Response Transmission)*/
+ GpsSetPosBaseEvent(st_rcv_msg.sndpno, POS_RET_ERROR_INNER);
+ }
+ } else {
+ memcpy(&st_rcv_msg, reinterpret_cast<POS_RESETINFO*>(&(g_gps_msg_rcvr.msgdat)), sizeof(POS_RESETINFO));
+ GpsSetPosBaseEvent(st_rcv_msg.sndpno, POS_RET_ERROR_BUSY);
+ }
+ return;
+}
+
+/******************************************************************************
+@brief CyclDataTimeOutGpsCommon<BR>
+ Common-Receive data monitoring timeout matrix function
+@outline Common processing at reception cycle data monitoring timeout
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void CyclDataTimeOutGpsCommon(void) {
+ g_wcnct_err++; /* Count number of connection errors */
+
+ /* Stop all timers */
+ DevGpsTimeStop(GPS_STARTUP_TIMER); /* Start confirmation monitoring timer */ /* Ignore -> MISRA-C:2004 Rule 16.10 */
+ DevGpsTimeStop(GPS_RECV_ACK_TIMER); /* ACK reception monitoring timer */ /* Ignore -> MISRA-C:2004 Rule 16.10 */
+
+ /* Clear cyclic receive data up to now */
+ DevGpsCycleDataClear();
+
+ /* Start confirmation monitoring timer setting */
+ DevGpsTimeSet(GPS_STARTUP_TIMER); /* Ignore -> MISRA-C:2004 Rule 16.10 */
+
+ /* State-transition(Start Confirmation Monitor) */
+ ChangeStatusGpsCommon(GPS_STS_STARTUP);
+
+ return;
+}
+
+/********************************************************************************
+ * MODULE : CheckFrontStringPartGpsCommon
+ * ABSTRACT : Message start character string determination processing
+ * FUNCTION : Check that the message starts with the specified string
+ * ARGUMENT : pubTarget : Message
+ * : pubStart : Character string
+ * NOTE : When target is equal to start, it is also judged to be TRUE.
+ * : "*" in the start is treated as a single-character wildcard.
+ * RETURN : RET_NORMAL : Decision success
+ * : RET_ERROR : Decision failure
+ ********************************************************************************/
+RET_API CheckFrontStringPartGpsCommon(const u_char *p_tartget, const u_char *p_start) {
+ RET_API ret = RET_ERROR;
+
+ while (((*p_tartget == *p_start)
+ || ('*' == *p_start)) /* #GPF_60_024 */ /* Ignore -> No applicable rules for MISRA-C */
+ && (*p_tartget != '\0')
+ && (*p_start != '\0')) {
+ p_tartget++; /* Ignore -> MISRA-C:2004 Rule 17.4 */
+ p_start++; /* Ignore -> MISRA-C:2004 Rule 17.4 */
+ }
+
+ if (*p_start == '\0') {
+ ret = RET_NORMAL;
+ } else {
+ ret = RET_ERROR;
+ }
+
+ return ret;
+}
+
+/******************************************************************************
+@brief JudgeFormatGpsCommon<BR>
+ Format determination processing
+@outline Determine the format of the received GPS data
+@param[in] pubSndData : Message to be judged
+@param[in] ul_length : Message length
+@param[out] peFormat : Where to Return the Format
+@input none
+@return int32
+@retval GPSRET_SNDCMD : Commands to be notified
+@retval GPSRET_NOPCMD : User unset command
+@retval GPSRET_CMDERR : No applicable command
+*******************************************************************************/
+int32 JudgeFormatGpsCommon(u_char *p_send_data, u_int32 ul_length, TG_GPS_OUTPUT_FORMAT *p_format) {
+ int32 ret = GPSRET_NOPCMD; /* Return value */
+ u_int32 cnt = 0; /* Ignore -> MISRA-C:2004 Rule 5.6 */
+
+ for (cnt = 0; cnt < (u_int32)GPSCMDANATBL_MAX; cnt++) {
+ /** End-of-table decision */
+ if (CheckFrontStringPartGpsCommon((const u_char*)ENDMARK, kGpsCmdAnaTbl[cnt].c_sentence) == RET_NORMAL) {
+ /** When there is no matching sentence, */
+ /** set return value. */
+ ret = GPSRET_NOPCMD; /* Ignore -> MISRA-C:2004 Rule 3.1 */
+ break;
+ }
+
+ /* ++ #GPF_60_040 */
+ /* Sentence determination of received command */
+
+ if (kGpsCmdAnaTbl[cnt].e_rcv_format == g_gps_mngr.rcv_cmd) {
+ /* Format set */
+ (*p_format) = g_gps_mngr.rcv_cmd;
+
+ /* Notification judgment */
+ if (kGpsCmdAnaTbl[cnt].b_snd_cmd_flg == TRUE) {
+ /* Checksum implementation */
+ if (CheckSumGpsCommon(reinterpret_cast<u_int8*>(p_send_data),
+ ul_length,
+ kGpsCmdAnaTbl[cnt].e_rcv_format) != RET_NORMAL) {
+ /* Receive data anomaly */
+ POSITIONING_LOG("# GpsCommCtl # GPS Data SUM ERROR! \r\n");
+
+ g_wrecv_err++;
+
+ /* Set data error in return value */
+ ret = GPSRET_CMDERR;
+ } else {
+ /* Notification to vehicle sensor */
+ ret = GPSRET_SNDCMD;
+ g_wrecv_err = 0;
+ }
+ }
+
+ break;
+ }
+ }
+
+ return ret;
+}
+
+
+/******************************************************************************
+@brief CheckSumGpsCommon<BR>
+ Checksum processing
+@outline Checking the integrity of GPS commands
+@param[in] none
+@param[out] none
+@input u_int8 : p_uc_data[] ... Receive data pointer
+@input u_int32 : ul_length ... Data length
+@input u_int32 : e_cmd_info ... Command information<BR>
+ -FORMAT_NMEA NMEA data<BR>
+ -FORMAT_BIN Standard binary<BR>
+ -FORMAT_FULLBIN FULL binaries
+@return RET_API
+@retval RET_NORMAL : Normal completion
+@retval RET_ERROR : ABENDs
+*******************************************************************************/
+RET_API CheckSumGpsCommon(const u_int8 p_uc_data[], u_int32 ul_length, TG_GPS_OUTPUT_FORMAT e_cmd_info) {
+ RET_API l_ret = RET_ERROR;
+ u_int32 i = 0;
+ u_int8 uc_char = 0;
+ u_int8 uc_sum = 0;
+ u_int8 uc_cmp = 0;
+ int32_t ret = 0;
+
+ static u_int8 uc_work[UBX_CMD_SIZE_MAX];
+
+ if ((GPS_FORMAT_MON_VER == e_cmd_info)
+ || (GPS_FORMAT_AID_INI == e_cmd_info)
+ || (GPS_FORMAT_ACK_ACKNACK == e_cmd_info)
+ || (GPS_FORMAT_NAV_TIMEUTC == e_cmd_info)
+ || (GPS_FORMAT_NAV_CLOCK == e_cmd_info)
+ || (GPS_FORMAT_RXM_RTC5 == e_cmd_info)
+ || (GPS_FORMAT_NAV_SVINFO == e_cmd_info)
+ || (GPS_FORMAT_CFG_NAVX5 == e_cmd_info)) {
+ (void)memcpy(uc_work, p_uc_data, ul_length - 2);
+ DevGpsSetChkSum(uc_work, ul_length);
+
+ ret = memcmp(uc_work, p_uc_data, ul_length);
+
+ if (ret == 0) {
+ l_ret = RET_NORMAL;
+ } else {
+ }
+ } else {
+ /** XOR each character between '$' and '*' */
+ for ( i = 1; i < ul_length; i++ ) {
+ if (p_uc_data[i] == (u_int8)'*') {
+ /** '*'Detection */
+ l_ret = RET_NORMAL; /* #GPF_60_111 */
+ break;
+ } else {
+ /** '*'Not detected */
+ uc_char = p_uc_data[i];
+ uc_sum ^= uc_char;
+ }
+ }
+
+ /** When the position of '*' is within two characters following '*' (access check of the receive buffer range) */
+ if ( (l_ret == RET_NORMAL) && ((GPS_READ_LEN - 2) > i) ) {
+ /** Convert two characters following '*' to two hexadecimal digits */
+ uc_cmp = (AtoHGpsCommon(p_uc_data[i + 1]) * 16) + AtoHGpsCommon(p_uc_data[i + 2]);
+
+ /** Checksum result determination */
+ if ( uc_cmp != uc_sum ) {
+ /** Abnormality */
+ l_ret = RET_ERROR;
+ }
+ } else {
+ /** '*' Not detected, data length invalid */
+ /** Abnormality */
+ l_ret = RET_ERROR;
+ }
+ }
+
+ return l_ret;
+}
+
+/******************************************************************************
+@brief AtoHGpsCommon<BR>
+ ASCII-> hexadecimal conversions
+@outline Convert ASCII codes to hexadecimal
+@param[in] none
+@param[out] none
+@input u_int8 : ascii ... ASCII code('0' ~ '9', 'a' ~ 'f', 'A' ~ 'F')
+@return u_int8
+@retval Hexadecimal number
+*******************************************************************************/
+u_int8 AtoHGpsCommon(u_int8 ascii) {
+ u_int8 hex = 0;
+ if ((ascii >= '0') && (ascii <= '9')) {
+ hex = ascii - '0';
+ } else if ((ascii >= 'a') && (ascii <= 'f')) {
+ hex = (ascii - 'a') + 0xa; /* Ignore -> MISRA-C:2004 Rule 12.1 */
+ } else if ( (ascii >= 'A') && (ascii <= 'F') ) {
+ hex = (ascii - 'A') + 0xa; /* Ignore -> MISRA-C:2004 Rule 12.1 */
+ } else {
+ /* nop */
+ }
+
+ return hex;
+}
+
+/******************************************************************************
+@brief DevGpsSaveCmd<BR>
+ Command pending processing
+@outline Temporarily save commands to be sent to GPS
+@param[in] TG_GPS_SND_DATA* pstSndMsg : Sending commands
+@param[out] none
+@return RET_API
+@retval RET_NORMAL : Normal completion
+@retval RET_ERROR : ABENDs(buffer full)
+*******************************************************************************/
+RET_API DevGpsSaveCmd(TG_GPS_SAVECMD *p_send_data) {
+ RET_API ret = RET_NORMAL;
+ u_int32 savp = 0; /* Holding buffer location storage */
+
+ /* Pending buffer full */
+ if ( g_gps_save_cmdr.bufsav >= SAV_MAX ) {
+ /* Return an abend */
+ ret = RET_ERROR;
+ } else {
+ savp = g_gps_save_cmdr.saveno; /* Get pending buffer position */
+
+ /* Copy data to pending buffer */
+ memset(&g_gps_save_cmdr.savebuf[savp], 0x00, sizeof(g_gps_save_cmdr.savebuf[savp]));
+ memcpy(&g_gps_save_cmdr.savebuf[savp], p_send_data, sizeof(TG_GPS_SAVECMD));
+
+ g_gps_save_cmdr.saveno++; /* Pending index addition */
+
+ if (g_gps_save_cmdr.saveno >= SAV_MAX) {
+ g_gps_save_cmdr.saveno = 0; /* Reset Pending Index */
+ }
+
+ g_gps_save_cmdr.bufsav++; /* Number of pending buffers added */
+ }
+
+ return ret;
+}
+
+/******************************************************************************
+@brief SendSaveCmdGpsCommon<BR>
+ Pending command transmission processing
+@outline Send Pending Commands to GPS
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void SendSaveCmdGpsCommon(void) {
+ u_int32 sndp = 0; /* Holding buffer location storage */
+ // TG_GPS_SND_DATA* p_send_data = NULL; /* Pointer to the pending command */
+ BOOL b_ret = FALSE; /* Command send return value */
+
+ /** Retrieves one pending command, if any, and sends it. */
+ if (g_gps_save_cmdr.bufsav != 0) {
+ /** Send position acquisition */
+ sndp = g_gps_save_cmdr.sendno;
+ // p_send_data = reinterpret_cast<TG_GPS_SND_DATA*>(&(g_gps_save_cmdr.savebuf[sndp]));
+
+ // todo For test No Uart
+ // b_ret = DEV_Gps_CmdWrite( p_send_data->us_size, &(p_send_data->uc_data[0]) );/* #GPF_60_106 */
+ if ( b_ret != TRUE ) {
+ POSITIONING_LOG("DEV_Gps_CmdWrite fail. ret=[%d]\n", b_ret);
+ // ucResult = SENSLOG_RES_FAIL;
+ }
+
+ /* ++ #GPF_60_040 */
+ /** Configure Monitored Commands */
+ g_gps_mngr.resp_cmd = g_gps_save_cmdr.savebuf[ sndp ].e_cmd_info;
+ g_gps_mngr.resp_pno = g_gps_save_cmdr.savebuf[ sndp ].us_pno;
+ g_gps_mngr.resp_rid = g_gps_save_cmdr.savebuf[ sndp ].uc_rid;
+ g_gps_mngr.resp_rst_flag = g_gps_save_cmdr.savebuf[ sndp ].uc_rst;
+
+ /** Perform response monitoring */
+ DevGpsTimeSet(GPS_RECV_ACK_TIMER); /* Ignore -> MISRA-C:2004 Rule 16.10 */
+ /* State transition processing(sending) */
+ ChangeStatusGpsCommon(GPS_STS_SENT);
+ } else {
+ /** No monitored commands */
+ g_gps_mngr.resp_cmd = GPS_FORMAT_MIN;
+ g_gps_mngr.resp_pno = 0x0000;
+ g_gps_mngr.resp_rid = 0x00;
+ g_gps_mngr.resp_rst_flag = GPS_CMD_NOTRST;
+ }
+
+ return;
+}
+
+/* ++ #GPF_60_040 */
+/******************************************************************************
+@brief DeleteSaveCmdGpsCommon<BR>
+ Pending command deletion processing
+@outline Deleting a Pending Command
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DeleteSaveCmdGpsCommon(void) {
+ u_int32 sndp = 0; /* Holding buffer location storage */
+
+ /** Delete one pending command, if any. */
+ if (g_gps_save_cmdr.bufsav != 0) {
+ /** Send position acquisition */
+ sndp = g_gps_save_cmdr.sendno;
+
+ /** Clear Stored Data */
+ memset(&g_gps_save_cmdr.savebuf[sndp], 0x00, sizeof(g_gps_save_cmdr.savebuf[sndp]));
+
+ /** Transmit index addition */
+ g_gps_save_cmdr.sendno++;
+ if ( g_gps_save_cmdr.sendno >= SAV_MAX ) {
+ /** Transmit index MAX or higher */
+ /** Initialize transmission index */
+ g_gps_save_cmdr.sendno = 0;
+ }
+
+ /** Subtract pending buffers */
+ g_gps_save_cmdr.bufsav--;
+ }
+
+ return;
+}
+
+/******************************************************************************
+@brief DeleteAllSaveCmdGpsCommon<BR>
+ Hold command abort processing
+@outline Discards all pending commands and returns a reset response
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DeleteAllSaveCmdGpsCommon(void) {
+ u_int32 sndp = 0; /* Holding buffer location storage */
+ PNO us_pno = 0; /* Ignore -> MISRA-C:2004 Rule 5.6 */
+ RID uc_rid = 0; /* Ignore -> MISRA-C:2004 Rule 5.6 */
+
+ while (g_gps_save_cmdr.bufsav != 0) {
+ /** Determine whether it is a pending command that requires a response. */
+ sndp = g_gps_save_cmdr.sendno;
+
+ if (g_gps_save_cmdr.savebuf[ sndp ].uc_rst == GPS_CMD_RESET) {
+ /** In the case of a reset request, a reset response (communication error) is notified. */
+ us_pno = g_gps_save_cmdr.savebuf[ sndp ].us_pno;
+ uc_rid = g_gps_save_cmdr.savebuf[ sndp ].uc_rid;
+ DevGpsRstAnsSend(us_pno, uc_rid, GPS_SENDNG); /* Ignore -> MISRA-C:2004 Rule 16.10 */
+ }
+
+ /** Delete */
+ DeleteSaveCmdGpsCommon();
+ }
+
+ return;
+}
+/******************************************************************************
+@brief RcvCyclCmdNmeaGpsCommon<BR>
+ Cyclic data (NMEA) notification process
+@outline Notifying VehicleSensor of Cyclic Data (NMEA) Reception
+@param[in] u_int8 : *p_uc_data ... Receive data pointer
+@param[in] u_int32 : ul_len ... Received data length
+@param[in] TG_GPS_OUTPUT_FORMAT : s_output_format ... Receive Format
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void RcvCyclCmdNmeaGpsCommon(u_int8 *p_uc_data, u_int32 ul_len, TG_GPS_OUTPUT_FORMAT s_output_format) {
+ NAVIINFO_ALL navilocinfo; /* Navigation information */
+ BOOL bcycle_rcv_flag = FALSE; /* Cyclic reception judgment result */
+
+ if (JudgeFormatOrderGpsCommon(s_output_format, g_rcv_format) == 0) {
+ /** If a sentence is received before the last received sentence, */
+ /** determine as the beginning of cyclic data. */
+ bcycle_rcv_flag = TRUE;
+ }
+
+ if (bcycle_rcv_flag == TRUE) {
+ DevGpsSndCycleDataNmea();
+
+ /* Reset navigation information */
+ memset(&navilocinfo, 0x00, sizeof(NAVIINFO_ALL));
+
+ /* NMEA data analysis */
+ DevGpsAnalyzeNmea(&navilocinfo);
+
+ /** Clear Buffer */
+ // DevGpsCycleDataClear();
+ }
+
+ DevGpsCycleDataSetNmea(p_uc_data, (u_int32)ul_len, GetNmeaIdxGpsCommon(s_output_format));
+
+ /** Update receive format */
+ g_rcv_format = s_output_format;
+
+ return;
+}
+
+
+/**
+ * @brief
+ * Cyclic data (UBX) notification processing
+ *
+ * Notify vehicle sensor of reception of cyclic data (UBX)
+ *
+ * @param[in] u_int8 : *p_uc_data ... Receive data pointer
+ * @param[in] u_int32 : ul_len ... Received data length
+ * @param[in] TG_GPS_OUTPUT_FORMAT : eFormat ... Receive Format
+ */
+void RcvCyclCmdExtGpsCommon(u_int8 *p_uc_data, u_int32 ul_len, TG_GPS_OUTPUT_FORMAT e_format) {
+ SENSOR_GPSTIME_RAW st_gpstime_raw;
+ TG_GPS_UBX_NAV_TIMEUTC_DATA *pst_navtime_utc;
+ BOOL b_validtow; /* Valid Time of Week */
+ BOOL b_validwkn; /* Valid Week of Number */
+ BOOL b_validutc; /* Valid UTC Time */
+
+ /* For NAV-TIMEUTC */
+ if (e_format == GPS_FORMAT_NAV_TIMEUTC) {
+ memset(&st_gpstime_raw, 0x00, sizeof(st_gpstime_raw));
+
+ /* NAV-TIMEUTC analysis */
+ pst_navtime_utc = reinterpret_cast<TG_GPS_UBX_NAV_TIMEUTC_DATA*>(p_uc_data + UBX_CMD_OFFSET_PAYLOAD);
+
+ st_gpstime_raw.utc.year = pst_navtime_utc->year;
+ st_gpstime_raw.utc.month = pst_navtime_utc->month;
+ st_gpstime_raw.utc.date = pst_navtime_utc->day;
+ st_gpstime_raw.utc.hour = pst_navtime_utc->hour;
+ st_gpstime_raw.utc.minute = pst_navtime_utc->min;
+ st_gpstime_raw.utc.second = pst_navtime_utc->sec;
+ b_validtow = (BOOL)(((pst_navtime_utc->valid) & UBX_CMD_MSK_NAV_TIMEUTC_VALID_TOW)
+ >> (uint8_t)(UBX_CMD_MSK_NAV_TIMEUTC_VALID_TOW / 2));
+ b_validwkn = (BOOL)(((pst_navtime_utc->valid) & UBX_CMD_MSK_NAV_TIMEUTC_VALID_WKN)
+ >> (uint8_t)(UBX_CMD_MSK_NAV_TIMEUTC_VALID_WKN / 2));
+ b_validutc = (BOOL)(((pst_navtime_utc->valid) & UBX_CMD_MSK_NAV_TIMEUTC_VALID_UTC)
+ >> (uint8_t)(UBX_CMD_MSK_NAV_TIMEUTC_VALID_UTC / 2));
+
+ if ((b_validtow == TRUE) && (b_validwkn == TRUE)) {
+ st_gpstime_raw.tdsts = 2; /* Calibrated */
+ g_gpstime_raw_tdsts = 2;
+ } else {
+ st_gpstime_raw.tdsts = 0; /* Uncalibrated */
+ g_gpstime_raw_tdsts = 0;
+ }
+
+ b_validutc = b_validutc;
+ POSITIONING_LOG("year=%04d, month=%02d, date=%02d, hour=%02d, minute=%02d,"
+ " second=%02d, validTow=%d, validWkn=%d, validUtc=%d",
+ st_gpstime_raw.utc.year, st_gpstime_raw.utc.month, st_gpstime_raw.utc.date,
+ st_gpstime_raw.utc.hour, st_gpstime_raw.utc.minute, st_gpstime_raw.utc.second,
+ b_validtow, b_validwkn, b_validutc);
+ /* Notify GPS time to vehicle sensor */
+ SndGpsTimeRaw((const SENSOR_GPSTIME_RAW*)&st_gpstime_raw);
+ } else {
+ POSITIONING_LOG("Forbidden ERROR!![e_format=%d]", e_format);
+ }
+
+ /** Update Receive Format */
+ g_rcv_format = e_format;
+
+ return;
+}
+
+/******************************************************************************
+@brief CheckSendCmdGpsCommon<BR>
+ Send command check processing
+@outline Check the format of the send command
+@param[in] const u_char* pubRcvData : Receive command
+@param[in] u_int32 ul_length : Length of the command
+@param[out] TG_GPS_OUTPUT_FORMAT* peFormat : Command format information
+@return int32
+@retval RET_NORMAL : Normal
+@retval RET_ERROR : Abnormality
+*******************************************************************************/
+int32 CheckSendCmdGpsCommon(const u_char *p_rcv_data, u_int32 ul_length, TG_GPS_OUTPUT_FORMAT *p_format) {
+ u_int32 ret = RET_NORMAL;
+ u_int32 cnt = 0; /* Ignore -> MISRA-C:2004 Rule 5.6 */
+
+ /** Analysis of received commands */
+ for (cnt = 0; cnt < (u_int32)GPSCMDANATBL_MAX; cnt++) {
+ /** End-of-table decision */
+ if (CheckFrontStringPartGpsCommon((const u_char*)ENDMARK, kGpsCmdAnaTbl[cnt].c_sentence) == RET_NORMAL) {
+ /** When there is no matching sentence */
+
+ /** Return value setting */
+ ret = RET_ERROR; /* Ignore -> MISRA-C:2004 Rule 3.1 */
+ break;
+ }
+
+ /** Sentence determination of received command */
+ if (CheckFrontStringPartGpsCommon(p_rcv_data, kGpsCmdAnaTbl[cnt].c_sentence) == RET_NORMAL) {
+ if (ul_length == kGpsCmdAnaTbl[cnt].ul_length) {
+ /** When the sentences match */
+
+ /** Reception type determination */
+ if ( kGpsCmdAnaTbl[cnt].ul_rcv_kind == RCV_RESP ) {
+ /** Response monitor format setting */
+ *p_format = kGpsCmdAnaTbl[cnt].e_rcv_format;
+ } else {
+ /** Return value setting */
+ ret = RET_ERROR; /* Ignore -> MISRA-C:2004 Rule 3.1 */
+ }
+
+ break; /* Ignore -> MISRA-C:2004 Rule 14.6 */
+ }
+ }
+ }
+
+ return ret;
+}
+
+
+/**
+ * @brief
+ * Get a string of fields from a NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ * @param[out] p_dst Pointer to the output area
+ * @param[in] size Maximum output size
+ *
+ * @return Size
+ */
+int32_t GetStringFromNmeaGpsCommon(u_int8 field_number, u_int8* p_src, char* p_dst, size_t size ) {
+ uint8_t* ptr = NULL;
+ /* int32_t numeric; */
+ uint32_t i = 0;
+ int32_t cnt = 0;
+ int8_t buf[GPS_NMEA_FIELD_LEN_MAX] = {0};
+
+ /* Null check */
+ if ((p_src == NULL) || (p_dst == NULL)) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p, p_dst=%p]", p_src, p_dst);
+ return 0;
+ }
+
+ ptr = p_src;
+
+ for (i = 0; i <= GPS_NMEA_MAX_SZ; i++) {
+ if (cnt == field_number) {
+ break;
+ }
+
+ if (*ptr == NMEA_DATA_SEPARATOR) {
+ cnt++;
+ }
+
+ ptr++;
+ }
+
+ i = 0;
+ if (*ptr != NMEA_DATA_SEPARATOR) {
+ for (i = 0; i < (GPS_NMEA_FIELD_LEN_MAX - 1); i++) {
+ buf[i] = *ptr;
+ ptr++;
+
+ if ((*ptr == NMEA_DATA_SEPARATOR) || (*ptr == NMEA_CHECKSUM_CHAR)) {
+ i++;
+ break;
+ }
+ }
+ }
+
+ buf[i] = '\0';
+ strncpy(p_dst, (const char *)buf, size);
+
+ return i;
+}
+
+/**
+ * @brief
+ * Get the number (real type) of a field from a NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ * @param[out] p_valid Validity of numerical data
+ *
+ * @return Real-number - double
+ */
+double_t GetNumericFromNmeaGpsCommon(u_int8 field_number, u_int8* p_src, BOOL* p_valid) {
+ double_t numeric = 0;
+ char buf[GPS_NMEA_FIELD_LEN_MAX] = {0};
+ int32_t ret = 0;
+
+ /* Null check */
+ if (p_src == NULL) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p]", p_src);
+ }
+
+ ret = GetStringFromNmeaGpsCommon(field_number, p_src, buf, GPS_NMEA_FIELD_LEN_MAX);
+
+ if (ret > 0) {
+ numeric = atof((const char *)buf);
+ *p_valid = TRUE;
+ } else {
+ *p_valid = FALSE;
+ }
+
+ return numeric;
+}
+
+/**
+ * @brief
+ * Get the integer value (integer type) of a field from a NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ *
+ * @return Integer - int32
+ */
+int32 GetIntegerFromNmeaGpsCommon(u_int8 field_number, u_int8* p_src) {
+ int32_t integer = 0;
+ char buf[GPS_NMEA_FIELD_LEN_MAX] = {0};
+
+ /* Null check */
+ if (p_src == NULL) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p]", p_src);
+ }
+
+ GetStringFromNmeaGpsCommon(field_number, p_src, buf, GPS_NMEA_FIELD_LEN_MAX);
+ integer = atoi((const char *)buf);
+
+ return integer;
+}
+
+/**
+ * @brief
+ * Get the latitude/longitude of the given fi eld from the NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ * @param[out] p_valid Validity of the data
+ *
+ * @return Latitude and longitude [1/256 sec]
+ */
+int32_t GetLonLatFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid) {
+ int32_t result = 0;
+ double_t value = 0.0;
+ int32_t deg = 0;
+ double_t min = 0.0;
+
+ /* Null check */
+ if (p_src == NULL) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p]", p_src);
+ }
+
+ value = GetNumericFromNmeaGpsCommon(field_number, p_src, p_valid);
+
+ if ((value < 0.0) || (value > 0.0)) {
+ deg = (int32_t)(value / 100.0f);
+ min = (double_t)(value - (deg * 100.0f));
+ result = (int32_t)(((60.0f * 60.0f * 256.0f) * deg) + ((60.0f * 256.0f) * min));
+ }
+
+ return result;
+}
+
+/**
+ * @brief
+ * Get the orientation of any fields from a NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ * @param[out] p_valid Validity of the data
+ *
+ * @return Orientation[0.01 degree]
+ */
+u_int16 GetHeadingFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid) {
+ u_int16 result = 0;
+ double_t value = 0.0;
+
+ /* Null check */
+ if (p_src == NULL) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p]", p_src);
+ }
+
+ value = GetNumericFromNmeaGpsCommon(field_number, p_src, p_valid);
+
+ result = (u_int16)((value + 0.005f) * 100.0f);
+
+ return result;
+}
+
+
+/**
+ * @brief
+ * Get the orientation of any fields from a NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ * @param[out] p_valid Validity of the data
+ *
+ * @return speed[0.01m/s]
+ */
+u_int16 GetSpeedFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid) {
+ u_int16 result = 0;
+ double_t value = 0.0;
+
+ /* Null check */
+ if (p_src == NULL) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p]", p_src);
+ }
+
+ value = GetNumericFromNmeaGpsCommon(field_number, p_src, p_valid);
+
+ // speed[0.01m/s]
+ result = static_cast<u_int16>(value * 1.852 * 100 / 3.6);
+
+ return result;
+}
+
+/**
+ * @brief
+ * Get the altitude of certain fields from a NMEA sentence
+ *
+ * Operation is not guaranteed if a pointer other than a pointer to the NMEA sentence is specified.
+ *
+ * @param[in] field_number Field No.
+ * @param[in] p_src Pointers to NMEA sentences
+ * @param[out] p_valid Validity of the data
+ *
+ * @return Altitude [0.01m]
+ */
+int32 GetAltitudeFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid) {
+ int32 result = 0;
+ double_t value = 0.0;
+
+ /* Null check */
+ if (p_src == NULL) {
+ POSITIONING_LOG("Argument ERROR [p_src=%p]", p_src);
+ }
+
+ value = GetNumericFromNmeaGpsCommon(field_number, p_src, p_valid);
+
+ result = static_cast<int32>((value + 0.005f) * 100.0f);
+
+ return result;
+}
+
+/**
+ * @brief
+ * GPS Control Thread Stop Processing
+ */
+void StopThreadGpsCommon(void) {
+ /** Stop the start confirmation monitoring timer */
+ (void)DevGpsTimeStop(GPS_STARTUP_TIMER); /* Start confirmation monitoring timer */
+
+ /** Stop the periodic reception data monitoring timer */
+ (void)DevGpsTimeStop(GPS_CYCL_TIMER); /* Periodic reception data monitoring timer */
+
+ /** Stop the ACK reception monitoring timer */
+ (void)DevGpsTimeStop(GPS_RECV_ACK_TIMER); /* ACK reception monitoring timer */
+
+ /** Stop the Navigation Providing Monitor Timer */
+ (void)DevGpsTimeStop(GPS_NAVIFST_TIMER); /* Initial Navigation Monitoring Timer */
+
+ /** Stop the Navigation Providing Monitor Timer */
+ (void)DevGpsTimeStop(GPS_NAVICYCLE_TIMER); /* Navi monitoring timer */
+
+ /** Stop the Navigation Providing Monitor Timer */
+ (void)DevGpsTimeStop(GPS_NAVIDISRPT_TIMER); /* Navigation Monitoring Disruption Log Output Timer */
+
+ /** Stop Time Offering Monitor Timer */
+ /* (void)DevGpsTimeStop(GPS_DIAGCLK_GUARDTIMER); */ /* Time Offering Monitoring Timer */
+
+ PosTeardownThread(ETID_POS_GPS);
+
+ /* don't arrive here */
+ return;
+}
+
+/**
+ * @brief
+ * GPS format order determination process
+ *
+ * @param[in] s_format_1 GPS format1
+ * @param[in] s_format_2 GPS format2
+ * @return 0 Format 1 first<br>
+ * 1 Format 2 first<br>
+ * 2 Same as<br>
+ * 3 Unable to determine
+ */
+uint8_t JudgeFormatOrderGpsCommon(TG_GPS_OUTPUT_FORMAT s_format_1, TG_GPS_OUTPUT_FORMAT s_format_2) {
+ uint8_t ret = 3;
+ u_int32 cnt = 0;
+
+ if (s_format_1 == s_format_2) {
+ ret = 2;
+ } else if ((s_format_1 == GPS_FORMAT_MAX) || (s_format_2 == GPS_FORMAT_MIN)) {
+ ret = 1;
+ } else {
+ for (cnt = 0; cnt < static_cast<u_int32>(GPSCMDANATBL_MAX); cnt++) {
+ /** End-of-table decision */
+ if (CheckFrontStringPartGpsCommon((const u_char*)ENDMARK, kGpsCmdAnaTbl[cnt].c_sentence) == RET_NORMAL) {
+ /** There is no matching sentence */
+ ret = 3;
+ break;
+ }
+
+ if (kGpsCmdAnaTbl[cnt].e_rcv_format == s_format_1) {
+ ret = 0;
+ break;
+ } else if (kGpsCmdAnaTbl[cnt].e_rcv_format == s_format_2) {
+ ret = 1;
+ break;
+ }
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * @brief
+ * Get NMEA index process
+ *
+ * @param[in] iFmt GPS formats
+ * @return NMEA indexes
+ */
+ENUM_GPS_NMEA_INDEX GetNmeaIdxGpsCommon(TG_GPS_OUTPUT_FORMAT s_output_format) {
+ ENUM_GPS_NMEA_INDEX ret = GPS_NMEA_INDEX_MAX;
+
+ switch (s_output_format) {
+ case GPS_FORMAT_GGA:
+ /* GGA */
+ ret = GPS_NMEA_INDEX_GGA;
+ break;
+ case GPS_FORMAT_DGGA:
+ /* DGGA */
+ ret = GPS_NMEA_INDEX_DGGA;
+ break;
+ case GPS_FORMAT_VTG:
+ /* VTG */
+ ret = GPS_NMEA_INDEX_VTG;
+ break;
+ case GPS_FORMAT_RMC:
+ /* RMC */
+ ret = GPS_NMEA_INDEX_RMC;
+ break;
+ case GPS_FORMAT_DRMC:
+ /* DRMC */
+ ret = GPS_NMEA_INDEX_DRMC;
+ break;
+ case GPS_FORMAT_GLL:
+ /* GLL */
+ ret = GPS_NMEA_INDEX_GLL;
+ break;
+ case GPS_FORMAT_DGLL:
+ /* DGLL */
+ ret = GPS_NMEA_INDEX_DGLL;
+ break;
+ case GPS_FORMAT_GSA:
+ /* GSA */
+ ret = GPS_NMEA_INDEX_GSA;
+ break;
+ case GPS_FORMAT_GSV1:
+ /* GSV(1) */
+ ret = GPS_NMEA_INDEX_GSV1;
+ break;
+ case GPS_FORMAT_GSV2:
+ /* GSV(2) */
+ ret = GPS_NMEA_INDEX_GSV2;
+ break;
+ case GPS_FORMAT_GSV3:
+ /* GSV(3) */
+ ret = GPS_NMEA_INDEX_GSV3;
+ break;
+ case GPS_FORMAT_GSV4:
+ /* GSV(4) */
+ ret = GPS_NMEA_INDEX_GSV4;
+ break;
+ case GPS_FORMAT_GSV5:
+ /* GSV(5) */
+ ret = GPS_NMEA_INDEX_GSV5;
+ break;
+ case GPS_FORMAT_GST:
+ /* GST */
+ ret = GPS_NMEA_INDEX_GST;
+ break;
+ case GPS_FORMAT__CWORD44__GP3:
+ /* _CWORD44_,GP,3 */
+ ret = GPS_NMEA_INDEX__CWORD44__GP_3;
+ break;
+ case GPS_FORMAT__CWORD44__GP4:
+ /* _CWORD44_,GP,4 */
+ ret = GPS_NMEA_INDEX__CWORD44__GP_4;
+ break;
+ case GPS_FORMAT_P_CWORD82_F_GP0:
+ /* P_CWORD82_F,GP,0 */
+ ret = GPS_NMEA_INDEX_P_CWORD82_F_GP_0;
+ break;
+ case GPS_FORMAT_P_CWORD82_J_GP1:
+ /* P_CWORD82_J,GP,1 */
+ ret = GPS_NMEA_INDEX_P_CWORD82_J_GP_1;
+ break;
+ default:
+ /* nop */
+ break;
+ }
+ return ret;
+}
+
+/**
+ * @brief
+ * GPS reset request command transmission processing
+ */
+void SendResetReqGpsCommon(void) {
+ T_APIMSG_MSGBUF_HEADER s_msg_header; /* Message header */
+ POS_RESETINFO s_send_msg; /* Reset information */
+ u_int8 uc_send_buf[(sizeof(T_APIMSG_MSGBUF_HEADER) + sizeof(POS_RESETINFO))]; /* Transmitting buffer */
+ RET_API ret = RET_NORMAL;
+
+ /* Send reset request */
+ POSITIONING_LOG("GPS Reset Request");
+
+ /* <<Creation of message header section>>>> */
+ s_msg_header.signo = 0; /* Signal information setting */
+ s_msg_header.hdr.sndpno = PNO_NAVI_GPS_MAIN; /* Source thread No. setting */
+ s_msg_header.hdr.respno = PNO_NAVI_GPS_MAIN; /* Destination process No. */
+ s_msg_header.hdr.cid = CID_GPS_REQRESET; /* Command ID setting */
+ s_msg_header.hdr.msgbodysize = sizeof(POS_RESETINFO); /* Message data length setting */
+ s_msg_header.hdr.rid = 0; /* Resource ID Setting */
+ s_msg_header.hdr.reserve = 0; /* Reserved area clear */
+
+ (void)memcpy(&uc_send_buf[ 0 ], &s_msg_header, sizeof(T_APIMSG_MSGBUF_HEADER));
+
+ /* <<Creation of data section>> */
+ s_send_msg.mode = GPS_RST_COLDSTART; /* Reset mode */
+ s_send_msg.sndpno = PNO_NAVI_GPS_MAIN; /* Caller PNo. */
+ s_send_msg.respno = PNO_NAVI_GPS_MAIN; /* Destination PNo. */
+ s_send_msg.reserve[0] = 0;
+ s_send_msg.reserve[1] = 0;
+ s_send_msg.reserve[2] = 0;
+
+ /* Copy data to send buffer */
+ (void)memcpy( &uc_send_buf[ sizeof( T_APIMSG_MSGBUF_HEADER ) ], &s_send_msg, sizeof(POS_RESETINFO) );
+
+ /* <<Messaging>> */
+ ret = _pb_SndMsg(PNO_NAVI_GPS_MAIN, sizeof(uc_send_buf), reinterpret_cast<void *>(uc_send_buf), 0);
+
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("GPS Reset Request Error[ret = %d]", ret);
+ }
+}
+
+
+
+void DevGpsCommSettingTime(void) {
+ TG_GPS_SND_DATA *pst_rcv_data;
+ RET_API ret = RET_NORMAL;
+
+ pst_rcv_data = reinterpret_cast<TG_GPS_SND_DATA*>(&(g_gps_msg_rcvr.msgdat[0]));
+
+ ret = DevGpsResetReq(PNO_NONE, 0);
+ if (RET_NORMAL != ret) {
+ POSITIONING_LOG("DevGpsResetReq failed.");
+ } else {
+ /* Time setting(u-blox) */
+ DevGpsSettingTime(reinterpret_cast<POS_DATETIME *>(pst_rcv_data->ub_data));
+ }
+ return;
+}
+
+void DevGpsReadGpsTime(POS_DATETIME* pst_datetime) {
+ int32_t ret;
+ ST_GPS_SET_TIME buf;
+ POS_DATETIME st_datetime;
+ memset(&st_datetime, 0, sizeof(st_datetime));
+
+ // if (isGpsTimeStatusProof == TRUE) {
+ /* Clear the flag if the date and time status has already been calibrated. */
+ // WriteGpsTimeToBackup(FALSE, &st_datetime);
+ // POSITIONING_LOG("D_BK_ID_POS_GPS_TIME_SET_INFO:W:Clear");
+ // } else {
+ /* Read from backup RAM */
+ ret = Backup_DataRd(D_BK_ID_POS_GPS_TIME_SET_INFO, 0, &buf, sizeof(ST_GPS_SET_TIME));
+ if (ret == BKUP_RET_NORMAL) {
+ pst_datetime->year = buf.year;
+ pst_datetime->month = buf.month;
+ pst_datetime->date = buf.date;
+ pst_datetime->hour = buf.hour;
+ pst_datetime->minute = buf.minute;
+ pst_datetime->second = buf.second;
+
+ /* Update of the date/time status fixed value setting indication flag */
+ if (buf.flag == TRUE) {
+ g_is_gpstime_sts = TRUE;
+ POSITIONING_LOG("g_is_gpstime_sts = TRUE");
+ POSITIONING_LOG("%d/%d/%d %d:%d:%d", buf.year,
+ buf.month,
+ buf.date,
+ buf.hour,
+ buf.minute,
+ buf.second);
+ } else {
+ g_is_gpstime_sts = FALSE;
+ POSITIONING_LOG("g_is_gpstime_sts = FALSE");
+ }
+ } else {
+ POSITIONING_LOG("Backup_DataRd ERROR!! [ret=%d]", ret);
+ }
+ // }
+ return;
+}
+
+RET_API GpsSetPosBaseEvent(uint16_t ul_snd_pno, int32_t event_val) {
+ RET_API ret = RET_ERROR; /* Return value */
+ EventID ul_eventid = 0; /* Event ID */
+ char event_name[32]; /* Event name character string buffer */
+
+ memset(reinterpret_cast<void *>(event_name), 0, sizeof(event_name));
+ snprintf(event_name, sizeof(event_name), "VEHICLE_%X", ul_snd_pno);
+ /* Event Generation */
+ ul_eventid = _pb_CreateEvent(FALSE, 0, event_name);
+
+ // initialize EventID
+ if (0 != ul_eventid) {
+ ret = _pb_SetEvent(ul_eventid, SAPI_EVSET_ABSOLUTE, VEHICLE_EVENT_VAL_INIT);
+ if (RET_NORMAL != ret) {
+ /* Delete event and return event generation failed */
+ ret = _pb_DeleteEvent(ul_eventid);
+ ul_eventid = 0;
+ }
+ }
+
+ if (0 != ul_eventid) {
+ /* Event publishing(Event wait release) */
+ ret = _pb_SetEvent(ul_eventid, SAPI_EVSET_ABSOLUTE, event_val);
+ if (RET_NORMAL != ret) {
+ /* Event issuance failure */
+ POSITIONING_LOG("set Event failed.");
+ }
+ /* Event deletion */
+ _pb_DeleteEvent(ul_eventid);
+ } else {
+ /* Event generation failure */
+ POSITIONING_LOG("create Event failed.");
+ }
+ return ret;
+}
+
+/**
+ * @brief
+ * GPS reset response command reception processing
+ *
+ * @param[in] p_data Pointer to the received GPS command
+ */
+BOOL DevGpsRcvProcGpsResetResp(TG_GPS_RCV_DATA* p_data) {
+ RET_API ret;
+ u_int32 ul_reset_sts = GPS_SENDNG;
+ BOOL b_snd_flag = TRUE;
+ uint8_t *p_gps_data;
+ char date[6]; /* ddmmyy */
+ char work[8]; /* Work buffer for converting String data */
+
+ if (p_data == NULL) {
+ POSITIONING_LOG("Argument ERROR!! [p_data = %p]", p_data);
+ } else {
+ p_gps_data = p_data->bygps_data;
+
+ /* Checksum determination */
+ ret = CheckSumGpsCommon(p_gps_data, p_data->bydata_len, GPS_FORMAT_RMC);
+ if (ret == RET_NORMAL) {
+ /* Get Date information */
+ GetStringFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_DATE, p_gps_data, date, 6);
+
+ strncpy(work, &date[4], 2);
+
+ if (atoi(work) == 0) {
+ ul_reset_sts = GPS_SENDOK; /* Reset Successful */
+ /* Reissuing commands to a GPS device from here */
+ /* Send NAV-TIMEUTC sentence addition requests */
+ DevGpsNavTimeUTCAddReq();
+ }
+ POSITIONING_LOG("reset flag = %d, year after reset = %s", ul_reset_sts, work);
+ } else {
+ b_snd_flag = FALSE; /* If the checksum is NG, wait for the next reply message without sending a callback. */
+ POSITIONING_LOG("wrong checksum [ret = %d]", ret);
+ }
+
+ if (b_snd_flag == TRUE) {
+ /** Drop the time status to an abnormal time */
+ // Todo Suntec MACRO __CWORD71_ Disable, This Functions do nothing actrually.
+ // DEV_Gps_SetTimeStatus_NG();
+
+ /** Send Reset Response(Successful transmission) */
+ DevGpsRstAnsSend(g_gps_mngr.resp_pno, g_gps_mngr.resp_rid, ul_reset_sts);
+
+ POSITIONING_LOG("DEV_Gps_RstAndSend CALL!! [ul_reset_sts = %d]", ul_reset_sts);
+
+ /** Clear reset command sending judgment flag */
+ g_gps_reset_cmd_sending = FALSE;
+ }
+ }
+ return b_snd_flag;
+}
+
+/**
+ * @brief
+ * GPS time setting response command reception processing
+ *
+ * @param[in] p_data Pointer to the received GPS command
+ */
+void DevGpsRcvProcTimeSetResp(TG_GPS_RCV_DATA* p_data) {
+ u_int32 ul_reset_sts = GPS_SENDNG;
+ BOOL b_snd_flag = TRUE;
+ POS_DATETIME st_datetime; /* Setting time */
+ uint16_t set_gpsw;
+ uint32_t set_gpsws;
+ uint16_t rcv_gpsw;
+ uint32_t rcv_gpsws;
+ BOOL ret = FALSE;
+ int32_t status;
+
+ if (p_data == NULL) {
+ POSITIONING_LOG("Argument ERROR!! [p_data = %p]", p_data);
+ } else {
+ /* Read from backup RAM */
+ status = Backup_DataRd(D_BK_ID_POS_GPS_TIME_SET_INFO, 0, &st_datetime, sizeof(ST_GPS_SET_TIME));
+ if (status == BKUP_RET_NORMAL) {
+ /* Convert to GSP week number, GPS week second */
+ DevGpsYMD2GPSTIME(static_cast<int32>(st_datetime.year),
+ static_cast<int32>(st_datetime.month),
+ static_cast<int32>(st_datetime.date), static_cast<int32>(st_datetime.hour),
+ static_cast<int32>(st_datetime.minute),
+ static_cast<int32>(st_datetime.second), &set_gpsw, &set_gpsws);
+
+ memcpy(&rcv_gpsw, &(p_data->bygps_data[24]), sizeof(uint16_t));
+ memcpy(&rcv_gpsws, &(p_data->bygps_data[26]), sizeof(uint32_t));
+ rcv_gpsws /= 1000; /* Convert week (ms) to week (s) */
+ POSITIONING_LOG("recived gpsw[%d] gpsws[%d]\n", rcv_gpsw, rcv_gpsws);
+
+ /* Check if GPS week number and GPS week second are within valid range */
+ ret = DevGpsCheckGpsTime(set_gpsw, set_gpsws, rcv_gpsw, rcv_gpsws, GPS_SETTIME_RANGE);
+ if (ret == TRUE) {
+ /* Date/Time Status Fixed Value Setting Indication Flag ON */
+ g_is_gpstime_sts = TRUE;
+ POSITIONING_LOG("g_is_gpstime_sts = TRUE");
+
+ /* Time Setting Successful : Update backup RAM time */
+ ul_reset_sts = GPS_SENDOK;
+ WriteGpsTimeToBackup(TRUE, &st_datetime);
+ POSITIONING_LOG("SetGpsTime Success");
+ POSITIONING_LOG("D_BK_ID_POS_GPS_TIME_SET_INFO:W:%d/%d/%d %d:%d:%d",
+ st_datetime.year,
+ st_datetime.month,
+ st_datetime.date,
+ st_datetime.hour,
+ st_datetime.minute,
+ st_datetime.second);
+ } else {
+ /* Time setting error (Difference in set time): Time deletion of backup RAM */
+ memset(&st_datetime, 0, sizeof(st_datetime));
+ WriteGpsTimeToBackup(FALSE, &st_datetime);
+ POSITIONING_LOG("SetGpsTime failed\n");
+ POSITIONING_LOG("D_BK_ID_POS_GPS_TIME_SET_INFO:W:Clear\n");
+ }
+ } else {
+ /* Backup RAM read failed */
+ b_snd_flag = FALSE;
+ POSITIONING_LOG("Backup_DataRd ERROR!! [status=%d", status);
+ }
+
+ if (b_snd_flag == TRUE) {
+ /** Send Time Set Response */
+ DevGpsTimesetAnsSend(g_gps_mngr.resp_pno, g_gps_mngr.resp_rid, ul_reset_sts);
+
+ POSITIONING_LOG("DEV_Gps_TimesetAndSend CALL!! [ul_reset_sts = %d]", ul_reset_sts);
+ }
+ }
+ return;
+}
+
+/**
+ * @brief
+ * GPS rollover standard week number acquisition response reception processing
+ *
+ * @param[in] p_data Pointer to the received GPS command
+ */
+void DevGpsRcvProcWknRolloverGetResp(TG_GPS_RCV_DATA* p_data) {
+ RET_API ret;
+ SENSOR_WKN_ROLLOVER_HAL st_wkn_rollover;
+
+ if (p_data == NULL) {
+ POSITIONING_LOG("Argument ERROR!! [p_data = %p]", p_data);
+ } else {
+ /* Checksum determination */
+ ret = CheckSumGpsCommon(p_data->bygps_data, p_data->bydata_len, GPS_FORMAT_CFG_NAVX5);
+ if (ret == RET_NORMAL) {
+ /* Version information extraction */
+ (void)memcpy(&(st_wkn_rollover.us_wkn),
+ &(p_data->bygps_data[UBX_CMD_OFFSET_PAYLOAD + UBX_CMD_OFFSET_WKNROLLOVER]),
+ sizeof(st_wkn_rollover.us_wkn));
+ POSITIONING_LOG("wknRollover=%d", st_wkn_rollover.us_wkn);
+
+ // gwknRollover = st_wkn_rollover.us_wkn;
+
+ /* Send reference week number to vehicle sensor */
+ ret = DevGpsSndWknRollover(&st_wkn_rollover);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("VehicleUtility_pb_SndMsg ERROR!! [ret=%d]", ret);
+ }
+ } else {
+ POSITIONING_LOG("CheckSumGpsCommon ERROR!! [ret = %d]", ret);
+ }
+
+ if (ret != RET_NORMAL) {
+ /* GPS rollover standard week number acquisition request retransmission */
+ ret = DevGpsWknRolloverGetReq();
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("DevGpsWknRolloverGetReq ERROR!! [ret=%d]", ret);
+ }
+ }
+ }
+
+ return;
+}
+
+/**
+ * @brief
+ * Receiving additional responses to NAV-SVINFO commands
+ *
+ * @param[in] p_data Pointer to the received GPS command
+ */
+void DevGpsRcvProcNavSvinfoAddResp(TG_GPS_RCV_DATA* p_data) {
+ RET_API ret;
+ /* Common Response Command Reception Processing */
+ ret = DevGpsRcvProcCmnResp(p_data, GPS_CMD_SENTENCEADD_NAVSVINFO);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("DEV_Gps_RcvProcCmnResp(ADD_NAVSVINFO) ERROR!!");
+ /* Retransmission of requests to add NAV-SVINFO commands */
+ (void)DevGpsNavTimeUTCAddReq();
+ }
+ return;
+}
+
+
+/**
+ * @brief
+ * Common processing when a GPS receiver error is detected
+ */
+void GpsReceiverErrGpsCommon(void) {
+ BOOL *pb_rcv_err = &(g_gps_mngr.rcv_err_flag); /* GSP receiver error detection status */
+
+ /* Update GPS receiver anomaly detection flag */
+ *pb_rcv_err = TRUE;
+
+ DevSendGpsConnectError(TRUE);
+
+ return;
+}
+
+
+/**
+ * @brief
+ * GPS device setting response reception processing
+ *
+ * @param[in] p_data Pointer to the received GPS command
+ * @param[in] cmd Command in the configuration request
+ * @return RET_NORMAL Normal completion<br>
+ * RET_ERROR ABENDs
+ */
+RET_API DevGpsRcvProcCmnResp(TG_GPS_RCV_DATA* p_data, uint8_t cmd) {
+ RET_API ret = RET_ERROR;
+ uint8_t is_ack; /* 1=ACK, 0=NACK */
+ TG_GPS_UBX_ACK_DATA st_ack;
+ uint8_t *puc_msg_class = &(st_ack.uc_msg_class);
+ uint8_t *puc_msg_id = &(st_ack.uc_msg_id);
+
+ if (p_data == NULL) {
+ POSITIONING_LOG("Argument ERROR!![p_data=%p]", p_data);
+ } else {
+ /* Checksum determination */
+ ret = CheckSumGpsCommon(p_data->bygps_data, p_data->bydata_len, GPS_FORMAT_ACK_ACKNACK);
+ if (ret == RET_NORMAL) {
+ is_ack = p_data->bygps_data[UBX_CMD_OFFSET_ACKNAK];
+ if (is_ack == 1) {
+ /* Response command information extraction */
+ (void)memcpy(&st_ack, &(p_data->bygps_data[UBX_CMD_OFFSET_PAYLOAD]), sizeof(st_ack));
+ POSITIONING_LOG("msgClass=0x%02x, msgID=0x%02x", *puc_msg_class, *puc_msg_id);
+
+ /* When the response wait command does not match the reception command */
+ if (((cmd == GPS_CMD_SENTENCEADD_NMEAGST) && ((*puc_msg_class != 0x06) || (*puc_msg_id != 0x01))) ||
+ ((cmd == GPS_CMD_SENTENCEADD_NAVTIMEUTC) && ((*puc_msg_class != 0x06) || (*puc_msg_id != 0x01))) ||
+ ((cmd == GPS_CMD_SENTENCEADD_NAVCLOCK) && ((*puc_msg_class != 0x06) || (*puc_msg_id != 0x01))) ||
+ ((cmd == GPS_CMD_SENTENCEADD_RXMRTC5) && ((*puc_msg_class != 0x06) || (*puc_msg_id != 0x01))) ||
+ ((cmd == GPS_CMD_SENTENCEADD_NAVSVINFO) && ((*puc_msg_class != 0x06) || (*puc_msg_id != 0x01))) ||
+ ((cmd == GPS_CMD_AUTOMOTIVEMODE) && ((*puc_msg_class != 0x06) || (*puc_msg_id != 0x24)))) {
+ POSITIONING_LOG("Invalid ACK/NACK!! [cmd=%d, msgClass=0x%02x, msgID=0x%02x]\n",
+ cmd, *puc_msg_class, *puc_msg_id);
+ ret = RET_ERROR;
+ }
+ } else {
+ ret = RET_ERROR;
+ }
+ } else {
+ POSITIONING_LOG("DEV_Gps_ChkSum ERROR!![ret=%d]", ret);
+ }
+ }
+ return ret;
+}
+
+
+RET_API DevGpsResetReq(PNO us_pno, RID uc_rid) {
+ RET_API ret;
+ TG_GPS_SAVECMD st_save_cmd;
+ TG_GPS_SND_DATA* pst_snd_data;
+ uint8_t* p_ublox_data;
+
+ /* SYNC_CHAR_1_2 CLASS ID length(L/U) */
+ static const u_int8 csnd_cmd[] = { 0xB5, 0x62, 0x06, 0x04, 0x04, 0x00,
+ /* navBbrMask(L/U) resetMode/res CK_A CK_B */
+ 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 };
+
+ pst_snd_data = &(st_save_cmd.sndcmd);
+ p_ublox_data = pst_snd_data->ub_data;
+
+ memset(&st_save_cmd, 0x00, sizeof(st_save_cmd));
+ memcpy(p_ublox_data, csnd_cmd, UBX_CMD_SIZE_CFG_RST);
+
+ /* Checksum assignment */
+ DevGpsSetChkSum(p_ublox_data, UBX_CMD_SIZE_CFG_RST);
+
+ pst_snd_data->us_size = UBX_CMD_SIZE_CFG_RST;
+ st_save_cmd.us_pno = us_pno; /* Result notification destination process number */
+ st_save_cmd.uc_rid = uc_rid; /* Result Notification Resource ID */
+ st_save_cmd.uc_rst = GPS_CMD_RESET; /* Reset flag */
+ st_save_cmd.e_cmd_info = GPS_FORMAT_RMC; /* Command information */
+
+ /* Command is suspended and terminated. */
+ ret = DevGpsSaveCmd(&st_save_cmd);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("# GpsCommCtl # GPS Command Reserve bufferFull !");
+
+ /** When the pending buffer is full, a reset response (communication error) is returned. */
+ DevGpsRstAnsSend(st_save_cmd.us_pno, st_save_cmd.uc_rid, GPS_SENDNG);
+ }
+
+ return ret;
+}
+
+void DevGpsSettingTime(POS_DATETIME* pst_datetime) {
+ RET_API ret;
+ TG_GPS_SAVECMD st_save_cmd;
+ TG_GPS_SND_DATA* pst_snd_data;
+ uint8_t* p_ublox_data;
+ TG_GPS_UBX_AID_INI_POLLED* pst_ublox_data;
+
+ uint16_t gpsw;
+ uint32_t gpsws;
+
+ if (pst_datetime == NULL) {
+ POSITIONING_LOG("Argument ERROR!! [pstDataTime = %p]", pst_datetime);
+ } else {
+ pst_snd_data = &(st_save_cmd.sndcmd);
+ p_ublox_data = pst_snd_data->ub_data;
+
+ (void)memset(&st_save_cmd, 0x00, sizeof(st_save_cmd));
+
+ /* Convert to GSP week number, GPS week second */
+ (void)DevGpsYMD2GPSTIME(static_cast<int32>(pst_datetime->year),
+ static_cast<int32>(pst_datetime->month),
+ static_cast<int32>(pst_datetime->date),
+ static_cast<int32>(pst_datetime->hour),
+ static_cast<int32>(pst_datetime->minute),
+ static_cast<int32>(pst_datetime->second), &gpsw, &gpsws);
+
+
+ /* Send command sequence generation */
+ pst_ublox_data = reinterpret_cast<TG_GPS_UBX_AID_INI_POLLED*>(reinterpret_cast<void *>(p_ublox_data));
+ pst_ublox_data->uc_sync_char1 = 0xB5;
+ pst_ublox_data->uc_sync_char2 = 0x62;
+ pst_ublox_data->uc_class = 0x0B;
+ pst_ublox_data->uc_id = 0x01;
+ pst_ublox_data->uc_length[0] = 0x30;
+ pst_ublox_data->uc_length[1] = 0x00;
+ pst_ublox_data->uc_flags[0] = 0x02; /* Time setting: The second bit from the low order is 1. */
+
+ (void)memcpy(pst_ublox_data->wn, &gpsw, sizeof(uint16_t));
+
+ gpsws *= 1000;
+ (void)memcpy(pst_ublox_data->tow, &gpsws, sizeof(uint32_t));
+
+ /* Checksum assignment */
+ DevGpsSetChkSum(reinterpret_cast<u_int8 *>(reinterpret_cast<void*>(pst_ublox_data)),
+ UBX_CMD_SIZE_AID_INI);
+
+ /* Concatenate Poll Request Command */
+ ret = DevGpsCatPollReq(p_ublox_data, UBX_POLL_CMD_KIND_AID_INI);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("DEV_Gps_CatPollReqUblox ERROR!! [ret = %d]", ret);
+ } else {
+ pst_snd_data->us_size = UBX_CMD_SIZE_AID_INI_PLUS_POLL;
+ st_save_cmd.us_pno = PNO_VEHICLE_SENSOR; /* Result notification destination process number */
+ st_save_cmd.uc_rid = 0; /* Result Notification Resource ID */
+ st_save_cmd.uc_rst = GPS_CMD_TIMESET; /* Response flag */
+ st_save_cmd.e_cmd_info = GPS_FORMAT_AID_INI;/* Command information */
+
+ /* Command is suspended and terminated. */
+ ret = DevGpsSaveCmd(&st_save_cmd);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("DevGpsSaveCmd ERROR!! [ret = %d]", ret);
+ /* Todo: retransmission by timer */
+ }
+ /* Update non-volatile of time setting */
+ WriteGpsTimeToBackup(FALSE, pst_datetime);
+ /* Waiting for a GPS device to respond */
+ g_is_gpstime_sts = FALSE;
+ POSITIONING_LOG("Start SetGpsTime\n");
+ POSITIONING_LOG("D_BK_ID_POS_GPS_TIME_SET_INFO:W:%d/%d/%d %d:%d:%d\n",
+ pst_datetime->year,
+ pst_datetime->month,
+ pst_datetime->date,
+ pst_datetime->hour,
+ pst_datetime->minute,
+ pst_datetime->second);
+ }
+ }
+ return;
+}
+
+/**
+ * @brief
+ * Converting from the Gregorian calendar to the Julian Day of Modification
+ *
+ * @param[in] y year
+ * @param[in] m month
+ * @param[in] d day
+ *
+ * @return Modified Julian Date
+ */
+int DevGpsYMD2JD(int y, int m, int d) {
+ double jd = JULIAN_DAY;
+ double tmp;
+ int mjd = 0;
+
+ if (m <= 2) { /* In January, February in December and 14th of the previous year */
+ y--;
+ m += 12;
+ }
+ y += 4800;
+ m -= 3;
+ d -= 1;
+
+ tmp = static_cast<double>(y / 400);
+ y %= 400;
+ jd += tmp * 146097;
+
+ tmp = static_cast<double>(y / 100);
+ y %= 100;
+ jd += tmp * 36524;
+
+ tmp = static_cast<double>(y / 4);
+ y %= 4;
+ jd += tmp * 1461;
+ jd += static_cast<double>(y * 365);
+
+ tmp = static_cast<double>(m / 5);
+ m %= 5;
+ jd += tmp * 153;
+
+ tmp = static_cast<double>(m / 2);
+ m %= 2;
+ jd += tmp * 61;
+ jd += static_cast<double>(m * 31);
+ jd += static_cast<double>(d);
+
+ mjd = static_cast<int>(jd - MODIFIED_JULIAN_DAY_OFFSET); /* Julian Date-> Modified Julian Date */
+
+ return mjd;
+}
+
+/**
+ * @brief
+ * Converting from year, month, day, hour, minute and second (GPS hour) to GPS week and GPS week seconds
+ *
+ * Converting y:year, m:month, d:day, hh:hour, mm:minute, ss:second (GPS hour) to GPS week/GPS week second
+ *
+ * @param[in] y year
+ * @param[in] m month
+ * @param[in] d day
+ * @param[in] hh hour
+ * @param[in] mm munites
+ * @param[in] ss sec
+ * @param[out] gpsw
+ * @param[out] gpsws
+ *
+ * @return TRUE / FALSE
+ */
+BOOL DevGpsYMD2GPSTIME(const int32 y, const int32 m, const int32 d, const int32 hh,
+ const int32 mm, const int32 ss, u_int16* gpsw, u_int32* gpsws) {
+ /*
+ MJD :Y year M month D date modified Julian date (Convert date to modified Julian date)
+ GPSW : GPS week
+ GPSWS: GPS week second
+ */
+ int mjd = DevGpsYMD2JD(y, m, d);
+
+ *gpsw = (uint16_t)((mjd - 44244) / 7);
+ *gpsws = (uint32_t)(((mjd - 44244 - (*gpsw * 7)) * 86400) +
+ (hh * 3600) + (mm * 60) + ss + 16); /* Add leap seconds ( 16 seconds) at 2015/1/1 */
+
+ if (*gpsws >= GPS_WS_MAX) {
+ (*gpsw)++;
+ *gpsws -= GPS_WS_MAX;
+ }
+
+ POSITIONING_LOG("*gpsw = %d, *gpsws = %d", *gpsw, *gpsws);
+
+ return TRUE;
+}
+
+/**
+ * @brief
+ * Concatenating Poll Request commands to UBX commands
+ *
+ * @param[in/out] *p_ublox_data Pointer to the concatenated UBX command
+ * @param[in] kind Additional command types
+ *
+ * @return RET_NORAML / RET_ERROR
+ */
+RET_API DevGpsCatPollReq(uint8_t *p_ublox_data, uint16_t kind) {
+ RET_API ret_api = RET_NORMAL;
+ TG_GPS_UBX_PACKET_HEADER *pst_ubx_pkg_hdr;
+ TG_GPS_UBX_COMMAND_NO_DATA *pst_ubx_poll_req;
+ uint32_t length;
+
+ /* Header ID length Checksum */
+ static uint8_t c_aidini_poll_cmd[] = {0xB5, 0x62, 0x0B, 0x01, 0x00, 0x00, 0x00, 0x00};
+ static uint8_t c_cfgnav5_poll_cmd[] = {0xB5, 0x62, 0x06, 0x24, 0x00, 0x00, 0x00, 0x00};
+
+ uint8_t* p_poll_cmd;
+ uint16_t poll_cmd_length;
+
+ if (p_ublox_data == NULL) {
+ POSITIONING_LOG("Argument ERROR!! [p_ublox_data=%p]", p_ublox_data);
+ ret_api = RET_ERROR;
+ } else {
+ if (kind == UBX_POLL_CMD_KIND_AID_INI) {
+ p_poll_cmd = c_aidini_poll_cmd;
+ poll_cmd_length = UBX_CMD_SIZE_AID_INI_POLL;
+ } else if (kind == UBX_POLL_CMD_KIND_CFG_NAV5) {
+ p_poll_cmd = c_cfgnav5_poll_cmd;
+ poll_cmd_length = UBX_CMD_SIZE_CFG_NAV5_POLL;
+ } else {
+ POSITIONING_LOG("Argument ERROR!! [kind=%d]", kind);
+ ret_api = RET_ERROR;
+ }
+
+ if (ret_api != RET_ERROR) {
+ pst_ubx_pkg_hdr = reinterpret_cast<TG_GPS_UBX_PACKET_HEADER*>(reinterpret_cast<void*>(p_ublox_data));
+ length = pst_ubx_pkg_hdr->us_length;
+
+ if (length == 0) {
+ POSITIONING_LOG("pst_ubx_pkg_hdr->us_length=0 ERROR!!");
+ ret_api = RET_ERROR;
+ } else {
+ /* Add Poll Request Command */
+ pst_ubx_poll_req = reinterpret_cast<TG_GPS_UBX_COMMAND_NO_DATA*>(reinterpret_cast<void*>(p_ublox_data +
+ length +
+ sizeof(TG_GPS_UBX_COMMAND_NO_DATA)));
+
+ memcpy(reinterpret_cast<void*>(pst_ubx_poll_req), reinterpret_cast<void*>(p_poll_cmd), poll_cmd_length);
+
+ DevGpsSetChkSum(reinterpret_cast<u_int8 *>(reinterpret_cast<void*>(pst_ubx_poll_req)), poll_cmd_length);
+ }
+ }
+ }
+
+ return ret_api;
+}
+
+void DevGpsSetGpsweekcorcnt(void) {
+ CLOCKGPS_GPSWEEKCOR_CNT_MSG gpsweekcor_cnt_msg;
+ memcpy(&gpsweekcor_cnt_msg, &g_gps_msg_rcvr, sizeof(CLOCKGPS_GPSWEEKCOR_CNT_MSG));
+ g_gps_week_cor_cnt = gpsweekcor_cnt_msg.gpsweekcorcnt;
+ return;
+}
+
+RET_API DevGpsNavTimeUTCAddReq(void) {
+ RET_API ret;
+ TG_GPS_SAVECMD st_save_cmd;
+ TG_GPS_SND_DATA* pst_snd_data;
+ uint8_t* p_ublox_data;
+
+ /* SYNC_CHAR_1_2 CLASS ID length(L/U) Payload CK_A CK_B */
+ static const u_int8 csnd_cmd[] = { 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x21, 0x01, 0x00, 0x00 };
+
+ pst_snd_data = &(st_save_cmd.sndcmd);
+ p_ublox_data = pst_snd_data->ub_data;
+
+ memset(&st_save_cmd, 0x00, sizeof(st_save_cmd));
+
+ /* Send command generation */
+ memcpy(p_ublox_data, csnd_cmd, UBX_CMD_SIZE_CFG_MSG);
+
+ /* Checksum assignment */
+ DevGpsSetChkSum(p_ublox_data, UBX_CMD_SIZE_CFG_MSG);
+
+ pst_snd_data->us_size = UBX_CMD_SIZE_CFG_MSG;
+ st_save_cmd.us_pno = PNO_VEHICLE_SENSOR; /* Result notification destination process number */
+ st_save_cmd.uc_rid = 0; /* Result notification resource ID */
+ st_save_cmd.uc_rst = GPS_CMD_SENTENCEADD_NAVTIMEUTC; /* Response flag */
+ st_save_cmd.e_cmd_info = GPS_FORMAT_ACK_ACKNACK; /* Command information */
+
+ /* Command is suspended and terminated. */
+ ret = DevGpsSaveCmd(&st_save_cmd);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("# GpsCommCtl # GPS Command Reserve bufferFull !");
+ }
+
+ return ret;
+}
+
+RET_API DevGpsWknRolloverGetReq(void) {
+ RET_API ret;
+ TG_GPS_SAVECMD st_save_cmd;
+ TG_GPS_SND_DATA* pst_snd_data;
+ uint8_t* p_ublox_data;
+
+ /* SYNC_CHAR_1_2 CLASS ID length(L/U) CK_A CK_B */
+ static const u_int8 csnd_cmd[] = { 0xB5, 0x62, 0x06, 0x23, 0x00, 0x00, 0x00, 0x00 };
+
+ pst_snd_data = &(st_save_cmd.sndcmd);
+ p_ublox_data = pst_snd_data->ub_data;
+
+ (void)memset(&st_save_cmd, 0x00, sizeof(st_save_cmd)); /* QAC 3200 */
+
+ /* Send command generation */
+ (void)memcpy(p_ublox_data, csnd_cmd, UBX_CMD_SIZE_CFG_NAVX5_POLL); /* QAC 3200 */
+
+ /* Checksum assignment */
+ DevGpsSetChkSum(p_ublox_data, UBX_CMD_SIZE_CFG_NAVX5_POLL);
+
+ pst_snd_data->us_size = UBX_CMD_SIZE_CFG_NAVX5_POLL;
+ st_save_cmd.us_pno = PNO_VEHICLE_SENSOR; /* Result notification destination process number */
+ st_save_cmd.uc_rid = 0; /* Result notification resource ID */
+ st_save_cmd.uc_rst = GPS_CMD_WKNROLLOVER; /* Response flag */
+ st_save_cmd.e_cmd_info = GPS_FORMAT_CFG_NAVX5; /* Command information */
+
+ /* Command is suspended and terminated. */
+ ret = DevGpsSaveCmd(&st_save_cmd);
+ if (ret != RET_NORMAL) {
+ POSITIONING_LOG("# GpsCommCtl # GPS Command Reserve bufferFull !");
+ /* If an error occurs at this point that is not expected due to a command queue full error, retransmission control is required. */
+ }
+ return ret;
+}
+
+/**
+ * @brief
+ * GPS time setting validity check process
+ *
+ * @param[in] set_gpsw Set GPS week
+ * @param[in] set_gpsws Set GPS Week
+ * @param[in] rcv_gpsw Answer GPS Week
+ * @param[in] rcv_gpsws Answer GPS Weeksec
+ * @param[in] offset_range Tolerance time difference[sec]
+ * @return BOOL TRUE:Effective time / FALSE:Invalid time
+ */
+BOOL DevGpsCheckGpsTime(uint16_t set_gpsw, uint32_t set_gpsws,
+ uint16_t rcv_gpsw, uint32_t rcv_gpsws, int32_t offset_range) {
+ BOOL ret = FALSE;
+ int16_t gap_gpsw = 0;
+ int32_t gap_gpsws = 0;
+
+ /* Check if GPS week number and GPS week second are within valid range */
+ /* NG when Set Time > Receive Time */
+ gap_gpsw = (int16_t)(rcv_gpsw - set_gpsw); /* QAC 3758 */
+ if (gap_gpsw == 0) {
+ /* There is no difference between the set GPS week and the received GPS week */
+ gap_gpsws = (int32_t)(rcv_gpsws - set_gpsws); /* QAC 3771 */
+ if ((0 <= gap_gpsws) && (gap_gpsws <= offset_range)) {
+ /* Setting of GPS time succeeded if the difference between GPS week seconds is within the range. */
+ ret = TRUE;
+ }
+ } else if (gap_gpsw == 1) {
+ /* Difference between the set GPS week and the received GPS week is 1 (over 7 weeks) */
+ gap_gpsws = (int32_t)((rcv_gpsws + GPS_WS_MAX) - set_gpsws); /* QAC 3771 */
+ if ((0 <= gap_gpsws) && (gap_gpsws <= offset_range)) {
+ /* Setting of GPS time succeeded if the difference between GPS week seconds is within the range. */
+ ret = TRUE;
+ }
+ } else {
+ /* Set GPS time failed except above */
+ }
+
+ return ret;
+}
+
+
+/****************************************************************************
+@brief DevGpsCnvLonLatNavi<BR>
+ Longitude/latitude information conversion process(Navigation-provided data)
+@outline Converts the latitude/longitude information provided by the navigation system into the format provided to the vehicle sensor.
+@param[in] u_int8 : fix_sts ... Current positioning status
+@param[in] int32 : lon ... Longitude information
+@param[in] int32 : lat ... Latitude-information
+@param[out] SENSORLOCATION_LONLATINFO_DAT* : p_lonlat ... Latitude and longitude information after conversion
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsCnvLonLatNavi(SENSORLOCATION_LONLATINFO_DAT* p_lonlat, u_int8 fix_sts, int32 lon, int32 lat) {
+ int32 longtitude;
+ int32 latitude;
+ int64_t tmp;
+ BOOL b_ret_lon = TRUE;
+ BOOL b_ret_lat = TRUE;
+ BOOL b_fix_sts = TRUE;
+
+ /** Provides latitude/longitude info for positioning status (2D/3D) */
+ if ((NAVIINFO_DIAG_GPS_FIX_STS_2D == fix_sts ) ||
+ (NAVIINFO_DIAG_GPS_FIX_STS_3D == fix_sts)) {
+ /** Get longitude information */
+ tmp = (int64_t)lon * 10000000;
+ longtitude = static_cast<int32>(tmp / (int64_t)(256 * 60 * 60));
+ if (longtitude == -1800000000) {
+ /** West longitude 180 degrees -> East longitude 180 degrees */
+ longtitude = +1800000000;
+ }
+ if ((longtitude > +1800000000) ||
+ (longtitude < -1800000000)) {
+ /** Longitude range error */
+ b_ret_lon = FALSE;
+ }
+ /** Get latitude information */
+ tmp = (int64_t)lat * 10000000;
+
+ latitude = static_cast<int32>(tmp / (int64_t)(256 * 60 * 60));
+
+ if ((latitude > +900000000) ||
+ (latitude < -900000000)) {
+ /** Latitude range error */
+ b_ret_lat = FALSE;
+ }
+ } else {
+ /** Does not provide latitude/longitude information in non-positioning state. */
+ b_fix_sts = FALSE;
+ }
+
+ /** Provided data setting */
+ p_lonlat->getMethod = GET_METHOD_GPS;
+ p_lonlat->SyncCnt = 0x00; /* Synchronization counter value(fixed to 0) */ /* Ignore -> No applicable rules for MISRA-C */
+ /** Available/Unusable Decision */
+ if ((b_fix_sts == TRUE) && (b_ret_lon == TRUE) && (b_ret_lat == TRUE)) {
+ p_lonlat->isEnable = SENSORLOCATION_STATUS_ENABLE; /* Available status: Available */
+ p_lonlat->Longitude = longtitude; /* Longitude */ /* Ignore -> MISRA-C:2004 Rule 9.1 */
+ p_lonlat->Latitude = latitude; /* Latitude */ /* Ignore -> MISRA-C:2004 Rule 9.1 */
+ } else {
+ p_lonlat->isEnable = SENSORLOCATION_STATUS_DISABLE; /* Available status: Not available */
+ p_lonlat->Longitude = 0; /* Longitude 0 degree fixed */
+ p_lonlat->Latitude = 0; /* Latitude fixed to 0 degrees */
+ }
+ return;
+}
+
+
+/****************************************************************************
+@brief DevGpsCnvAltitudeNavi<BR>
+ Altitude information conversion process(Navigation-provided data)
+@outline Converts the altitude information provided by the navigation system into the format provided to the vehicle sensor.
+@param[in] u_int8 : fix_sts ... Current positioning status
+@param[in] int32 : alt ... Altitude information
+@param[out] SENSORLOCATION_ALTITUDEINFO_DAT* : p_altitude ... Converted altitude information
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsCnvAltitudeNavi(SENSORLOCATION_ALTITUDEINFO_DAT* p_altitude, u_int8 fix_sts, int32 alt) {
+ int32 altitude;
+ BOOL b_fix_sts = TRUE;
+
+ /** Provides altitude information when in Fix Status (2D/3D) */
+ if (((NAVIINFO_DIAG_GPS_FIX_STS_2D == fix_sts) ||
+ (NAVIINFO_DIAG_GPS_FIX_STS_3D == fix_sts)) &&
+ (alt != GPS_ALTITUDE_INVALID_VAL)) {
+ /* The unit of alt is [0.01m], so conversion is not necessary. */
+ altitude = alt;
+ } else {
+ /** Does not provide altitude information in the non-positioning state. */
+ b_fix_sts = FALSE;
+ }
+ /** Provided data setting */
+ p_altitude->getMethod = GET_METHOD_GPS;
+ p_altitude->SyncCnt = 0x00; /* Synchronization counter value(fixed to 0) */ /* Ignore -> No applicable rules for MISRA-C */
+ /** Available/Unusable Decision */
+ if (b_fix_sts == TRUE) {
+ p_altitude->isEnable = SENSORLOCATION_STATUS_ENABLE; /* Available status: Available */
+ p_altitude->Altitude = altitude; /* Altitude */ /* Ignore -> MISRA-C:2004 Rule 9.1 */
+ } else {
+ p_altitude->isEnable = SENSORLOCATION_STATUS_DISABLE; /* Available status: Not available */
+ p_altitude->Altitude = 0; /* Altitude 0m fixed */
+ }
+ return;
+}
+
+/****************************************************************************
+@brief DevGpsCnvHeadingNavi<BR>
+ Orientation information conversion processing(Navigation-provided data)
+@outline Converts the orientation information provided by the navigation system into the format provided to the vehicle sensor.
+@param[in] u_int8 : fix_sts ... Current positioning status
+@param[in] u_int16 : head ... Bearing information
+@param[out] SENSORMOTION_HEADINGINFO_DAT* : p_heading ... Converted backward direction information
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsCnvHeadingNavi(SENSORMOTION_HEADINGINFO_DAT* p_heading, u_int8 fix_sts, u_int16 head) {
+ u_int16 us_heading;
+ BOOL b_fix_sts = TRUE;
+
+ /** Provides orientation when in Fix Status (2D/3D) */
+ if (((NAVIINFO_DIAG_GPS_FIX_STS_2D == fix_sts ) ||
+ (NAVIINFO_DIAG_GPS_FIX_STS_3D == fix_sts)) &&
+ (head != GPS_HEADING_INVALID_VAL)) {
+ /** Orientation information conversion */
+ us_heading = head;
+ /* Units of head are [0.01 degree] so no conversion is necessary. */
+ us_heading -= (u_int16)((us_heading / 36000) * 36000);
+ } else {
+ /** Azimuth information is not provided in the non-positioning state. */
+ b_fix_sts = FALSE;
+ }
+
+ /** Provided data setting */
+ p_heading->getMethod = GET_METHOD_GPS;
+ p_heading->SyncCnt = 0x00; /* Synchronization counter value(fixed to 0) */ /* Ignore -> No applicable rules for MISRA-C */
+ /** Available/Unusable Decision */
+ if (b_fix_sts == TRUE) {
+ p_heading->isEnable = SENSORLOCATION_STATUS_ENABLE; /* Available status: Available */
+ p_heading->Heading = us_heading; /* Orientation */ /* Ignore -> MISRA-C:2004 Rule 9.1 */
+ } else {
+ p_heading->isEnable = SENSORLOCATION_STATUS_DISABLE; /* Available status: Not available */
+ p_heading->Heading = 0; /* Azimuth 0 degree fixed */
+ }
+
+ return;
+}
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_Gps_Main.cpp b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Main.cpp
new file mode 100755
index 0000000..0b9a4be
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Main.cpp
@@ -0,0 +1,362 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Main.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "MDev_Gps_Main.h"
+#include "positioning_common.h"
+#include "MDev_Gps_Mtrx.h"
+#include "MDev_Gps_TimerCtrl.h"
+#include "MDev_Gps_Common.h"
+#include "MDev_Gps_Nmea.h"
+#include "MDev_GpsRecv.h"
+#include "LineSensDrv_Thread.h"
+
+/*---------------------------------------------------------------------------*/
+// Global values
+
+BOOL g_gps_rcv_thread_stop = FALSE;
+
+/********************************************************************************
+ * Matrix event translation table(Message input)
+ ********************************************************************************/
+const TG_GPS_MSGEVTCHNG kGpsMsgchkC[MDEV_GPSMSGCHKC_MAX] = {
+ /* ++ #GPF_60_024 */
+ /* Matrix Event Translation Table for _CWORD82_ NMEA */
+ {CID_GPS__CWORD82__REQUEST, GPS_EVT_SENDREQ}, /* NMEA transmission request */
+ {CID_INI_INTERNAL_ACCOFF_START, GPS_EVT_ACC_OFF}, /* In-function ACC-OFF instructions */
+ {CID_GPS_REQRESET, GPS_EVT_RESETREQ}, /* GPS reset request */
+ {CID_NAVIINFO_DELIVER, GPS_EVT_NAVI_LOCATIONINFO}, /* Providing navigation information */
+ {CID_NAVIINFO_SPEED_DELIVER, GPS_EVT_NAVI_SPEEDINFO}, /* Navigation speed information service */
+ {CID_GPS_TIMESETTING, GPS_EVT_TIMESETTING}, /* GPS time setting instruction */
+ {CID_GPS_BACKUPDATA_LOAD, GPS_EVT_BACKUPDATA_LOAD}, /* Backup memory read request */
+ {CID_THREAD_STOP_REQ, GPS_EVT_STOPREQ}, /* Thread stop request */
+ {CID_GPSWEEKCOR_CNT_NOTIFICATION, GPS_EVT_WEEKCOR_CNT_NOTIFICATIO}, /* GPS Week Adjustment Counter Notification */
+ {DAT_END, DAT_END} /* Table end */
+ /* -- #GPF_60_024 */
+};
+
+/********************************************************************************
+ * Matrix event translation table(Input Timeout [ Timer ID])
+ ********************************************************************************/
+const TG_GPS_TIMEVTCHNG kGpsTimchkC[MDEV_PSTIMCHKC_MAX] = {
+ {GPS_STARTUP_TIMER, 0, GPS_EVT_TIMEOUT_CYCLDAT}, /* Start confirmation monitoring timer */
+ {GPS_CYCL_TIMER, 0, GPS_EVT_TIMEOUT_CYCLDAT}, /* Periodic reception data monitoring timer */
+ {GPS_RECV_ACK_TIMER, 0, GPS_EVT_TIMEOUT_RSPDAT}, /* ACK reception monitoring timer */
+ {GPS_NAVIFST_TIMER, 0, GPS_EVT_TIMEOUT_NAVI}, /* Initial NAVI monitoring timer */
+ {GPS_NAVICYCLE_TIMER, 0, GPS_EVT_TIMEOUT_NAVI}, /* NAVIGATION monitoring timer */
+ {GPS_NAVIDISRPT_TIMER, 0, GPS_EVT_TIMEOUT_NAVI}, /* NAVIGATION Disruption Log Output Timer */
+ {GPS_DIAGCLK_GUARDTIMER, 0, GPS_EVT_TIMEOUT_DIAGCLKGUARD}, /* Diagnosis provision time guard monitoring timer */
+ {GPS_NMEADATA_GUARDTIMER, 0, GPS_EVT_TIMEOUT_NMEADATAGUARD}, /* NMEA data-providing guard monitoring timer */
+ {GPS_RECOVERY_TIMER, 0, GPS_EVT_TIMEOUT_RECOVERY}, /* GPS recovery timer */
+ {GPS_RECEIVERERR_TIMER, 0, GPS_EVT_TIMEOUT_RECEIVERERR}, /* GPS receiver anomaly detection timer */
+ {DAT_END, 0, DAT_END} /* Table end */
+};
+
+/********************************************************************************
+ * Processing Branch Table
+ ********************************************************************************/
+/********************************************************************************
+ * TAG : TG_GPS_JMP_TBL
+ * ABSTRACT : GPS jump table
+ * NOTE : GPS Communication Management Matrix Table
+ ********************************************************************************/
+const TG_GPS_JMP_TBL kGpsMatxC[GPS_STS_NUM][GPS_EVT_NUM] = {
+ /* - - - - - Confirming Start - - - - - */
+ {
+ {&DevGpsInitStartSendReq}, /* Transmission request */
+ {&DevGpsInitStartGPSResetReq}, /* GPS reset request */
+ {&DevGpsInitStartRcvCyclCmd}, /* Cyclic reception command reception */
+ {&DevGpsNop}, /* Receive Response Command */
+ {&DevGpsNop}, /* Response monitoring timeout */
+ {&DevGpsInitStartCyclDataTimeOut}, /* Periodic reception data monitoring timeout */
+ {&DevGpsInitStartNaviDataTimeOut}, /* Navigation providing data monitoring timeout */
+ {&DevGpsInitStartDiagClkGuardTimeOut}, /* Diagnosis provision time guard monitoring timeout */
+ {&DevGpsInitStartAccOffStart}, /* In-function ACC-OFF instructions */
+ {&DevGpsInitStartNaviInfoDeliver}, /* Providing navigation information */
+ {&DevGpsInitStartNaviSpeedDeliver}, /* Navigation speed information service */
+ {&DevGpsInitStartSettingTime}, /* GPS time setting instruction */
+ {&DevGpsInitStartNmeaDataGuardTimeOut}, /* NMEA data-providing guard monitoring timeout */
+ {&DevGpsInitStartBackupDataLoadReq}, /* Backup data read request */
+ {&DevGpsInitStartStopReq}, /* Thread stop request */
+ {&DevGpsInitStartGpsweekcorcntNtf}, /* GPS Week Adjustment Counter Notification */
+ {&DevGpsInitStartRecoveryTimeOut}, /* GPS error monitoring timer out */
+ {&DevGpsInitStartGpsReceiverErrTimeOut} /* GPS receiver anomaly detection timeout */
+ },
+ /* - - - - - - In operation - - - - - - */
+ {
+ {&DevGpsNormalSendReq}, /* Transmission request */
+ {&DevGpsNormalGPSResetReq}, /* GPS reset request */
+ {&DevGpsNormalRcvCyclCmd}, /* Cyclic reception command reception */
+ {&DevGpsNop}, /* Receive Response Command */
+ {&DevGpsNop}, /* Response monitoring timeout */
+ {&DevGpsNormalCyclDataTimeOut}, /* Periodic reception data monitoring timeout */
+ {&DevGpsNormalNaviDataTimeOut}, /* Navigation providing data monitoring timeout */
+ {&DevGpsNormalDiagClkGuardTimeOut}, /* Diagnosis provision time guard monitoring timeout */
+ {&DevGpsNormalAccOffStart}, /* In-function ACC-OFF instructions */
+ {&DevGpsNormalNaviInfoDeliver}, /* Providing navigation information */
+ {&DevGpsNormalNaviSpeedDeliver}, /* Navigation speed information service */
+ {&DevGpsNormalSettingTime}, /* GPS time setting instruction */
+ {&DevGpsNormalNmeaDataGuardTimeOut}, /* NMEA data-providing guard monitoring timeout */
+ {&DevGpsNormalBackupDataLoadReq}, /* Backup data read request */
+ {&DevGpsNormalStopReq}, /* Thread stop request */
+ {&DevGpsNormalGpsweekcorcntNtf}, /* GPS Week Adjustment Counter Notification */
+ {&DevGpsNormalRecoveryTimeOut}, /* GPS error monitoring timer out */
+ {&DevGpsNormalGpsReceiverErrTimeOut} /* GPS receiver anomaly detection timeout */
+ },
+ /* - - - - -- Sending - - - - - - */
+ {
+ {&DevGpsSendSendReq}, /* Transmission request */
+ {&DevGpsSendGPSResetReq}, /* GPS reset request */
+ {&DevGpsSendRcvCyclCmd}, /* Cyclic reception command reception */
+ {&DevGpsSendRcvRspCmd}, /* Receive Response Command */
+ {&DevGpsSendRspDataTimeOut}, /* Response monitoring timeout */
+ {&DevGpsSendCyclDataTimeOut}, /* Periodic reception data monitoring timeout */
+ {&DevGpsSendNaviDataTimeOut}, /* Navigation providing data monitoring timeout */
+ {&DevGpsSendDiagClkGuardTimeOut}, /* Diagnosis provision time guard monitoring timeout */
+ {&DevGpsSendAccOffStart}, /* In-function ACC-OFF instructions */
+ {&DevGpsSendNaviInfoDeliver}, /* Providing navigation information */
+ {&DevGpsSendNaviSpeedDeliver}, /* Navigation speed information service */
+ {&DevGpsSendSettingTime}, /* GPS time setting instruction */
+ {&DevGpsSendNmeaDataGuardTimeOut}, /* NMEA data-providing guard monitoring timeout */
+ {&DevGpsSendBackupDataLoadReq}, /* Backup data read request */
+ {&DevGpsSendStopReq}, /* Thread stop request */
+ {&DevGpsSendGpsweekcorcntNtf}, /* GPS Week Adjustment Counter Notification */
+ {&DevGpsSendRecoveryTimeOut}, /* GPS error monitoring timer out */
+ {&DevGpsSendGpsReceiverErrTimeOut} /* GPS receiver anomaly detection timeout */
+ }
+};
+
+// Receive command analysis table(NMEA format)
+const TG_GPS_CMD_ANA_TBL* kGpsCmdAnaTbl = kGpsCmdAnaTblUblox;
+
+//GPS process pending buffer management table
+TG_GPS_MSGRCV g_gps_msg_rcvr; /* Incoming message */
+TG_GPS_MNG g_gps_mngr; /* GPS process management information */
+
+// Global variable for GPS communication management
+u_int16 g_wsend_err; /* Number of transmission errors */
+u_int16 g_wcnct_err; /* Number of connection errors */
+TG_GPS_OUTPUT_FORMAT g_rcv_format; /* Receive Format */
+
+// Global variable for the receive thread
+TG_GPS_RECV_RcvData g_gps_rcvdata; /* Serial receive buffer */
+TG_GPS_RECV_RcvBuf g_gps_rcvbuf; /* Receive data storage buffer */
+TG_GPS_RECV_AnaDataBuf g_gps_ana_databuf; /* Analysis data buffer */
+TG_GPS_RECV_RcvFrameBuf g_gps_rcv_framebuf; /* Receive frame buffer */
+TG_GPS_SAVEBUF g_gps_save_cmdr; /* Command pending buffer */
+u_int16 g_wrecv_err; /* Number of reception errors */
+
+/*---------------------------------------------------------------------------*/
+// Functions
+
+/********************************************************************************
+ * MODULE : DEV_Gps_MainThread
+ * ABSTRACT : Communication Management Thread Domain Processing
+ * FUNCTION : Receive a request from the host application and send a command to the serial port.
+ * ARGUMENT : PVOID pv....Thread Creation Arguments
+ * NOTE :
+ * RETURN : TRUE :Normal completion
+ * FALSE:ABENDs
+ ********************************************************************************/
+EFrameworkunifiedStatus DevGpsMainThread(HANDLE h_app) {
+ BOOL ret = FALSE;
+
+ PosSetupThread(h_app, ETID_POS_GPS);
+
+ ret = DevGpsInit();
+
+ if (TRUE == ret) {
+ g_gps_rcv_thread_stop = FALSE;
+
+ /* Start receiving message */
+ DevGpsRcvMsg();
+ } else {
+ /* Initialization failed */
+ POSITIONING_LOG("DevGpsMainThread Init Fail \n");
+ }
+
+ return eFrameworkunifiedStatusFail;
+}
+
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Init
+ * ABSTRACT : Communication management thread initialization processing
+ * FUNCTION : Initialize internal tables and serial ports
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : TRUE :Normal completion
+ * FALSE:ABENDs
+ ********************************************************************************/
+BOOL DevGpsInit(void) {
+ BOOL ret = FALSE;
+
+ /* Global variable initialization(GPS Communication Management Thread Internal Use Variable) */
+ /* Clear process management information */
+ memset(&g_gps_mngr, 0x00, sizeof(g_gps_mngr)); /* #05 */
+
+ /* Clear the message receive buffer */
+ memset(&g_gps_msg_rcvr, 0x00, sizeof(g_gps_msg_rcvr)); /* #05 */
+
+ /* Clear the pending buffer */
+ memset(&g_gps_save_cmdr, 0x00, sizeof(g_gps_save_cmdr)); /* #05 */
+
+ /* Clear RTC backup-related data */
+ g_gps_mngr.rcv_cmd = GPS_FORMAT_MIN; /* #GPF_60_040 */
+ g_gps_mngr.resp_cmd = GPS_FORMAT_MIN; /* #GPF_60_040 */
+ g_gps_mngr.rcv_err_flag = FALSE;
+
+ g_wsend_err = 0; /* Initialization of the number of transmission errors */
+ g_wcnct_err = 0; /* Connection error count initialization */
+ g_rcv_format = GPS_FORMAT_MIN; /* Initialize Receive Format #GPF_60_024*/
+
+ /* Initialize the timer function initialization processing management table */
+ DevGpsTimInit();
+
+ /* Start confirmation monitoring timer setting(5Sec) */
+ ret = DevGpsTimeSet(GPS_STARTUP_TIMER);
+
+ /* GPS receiver anomaly detection timer setting(600Sec) */
+ ret = DevGpsTimeSet(GPS_RECEIVERERR_TIMER);
+
+ // Set command table
+ kGpsCmdAnaTbl = kGpsCmdAnaTblUblox;
+
+ /* State transition processing(Start Confirmation Monitor) */
+ ChangeStatusGpsCommon(GPS_STS_STARTUP);
+
+ return(ret);
+}
+
+/******************************************************************************
+@brief DEV_Gps_RcvMsg<BR>
+ Message reception processing
+@outline Receive a message and distribute processing into a matrix
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsRcvMsg(void) {
+ RET_API ret = RET_NORMAL;
+ void* p_rcv_msg = &g_gps_msg_rcvr;
+
+ while (1) {
+ p_rcv_msg = &g_gps_msg_rcvr;
+
+ // Receive meaasge
+ ret = _pb_RcvMsg(PNO_NAVI_GPS_MAIN, sizeof(g_gps_msg_rcvr), &p_rcv_msg, RM_WAIT);
+
+ if (RET_RCVMSG == ret) {
+ memcpy(&g_gps_msg_rcvr, p_rcv_msg, sizeof(g_gps_msg_rcvr));
+
+ /* Message Event Check Processing */
+ DevGpsMsgEventCheck();
+
+ if ((u_int32)NG != g_gps_mngr.event) {
+ /* If the event check is successful */
+ /* Start Processing by Matrix */
+ (kGpsMatxC[g_gps_mngr.sts][g_gps_mngr.event].func)();
+ }
+ } else {
+ /** MSG reception error */
+ POSITIONING_LOG("DevGpsRcvMsg error ret[%d] \n", ret);
+ }
+ }
+}
+
+static inline void SetStopFlag(void) {
+ g_gps_rcv_thread_stop = TRUE;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_MsgEventCheck
+ * ABSTRACT : Message Event Check Processing
+ * FUNCTION : Check received messages and convert them to events
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : None
+ ********************************************************************************/
+void DevGpsMsgEventCheck(void) {
+ u_int32 ul_cnt = 0;
+
+ /* Set Error to Event No. */
+ g_gps_mngr.event = (u_int32)NG;
+
+ /* For timeout notification */
+ if (g_gps_msg_rcvr.header.hdr.cid == CID_TIMER_TOUT) {
+ /* Get event number from sequence number */
+ DevGpsTimEventCheck();
+ } else if (g_gps_msg_rcvr.header.hdr.cid == CID_GPS_RECVDATA) {
+ DevGpsCmdEventCheckNmea();
+ } else {
+ while (kGpsMsgchkC[ul_cnt].cid != DAT_END) {
+ if (g_gps_msg_rcvr.header.hdr.cid == kGpsMsgchkC[ul_cnt].cid) {
+ POSITIONING_LOG("DevGpsMsgEventCheck: cid = %d", g_gps_msg_rcvr.header.hdr.cid);
+
+ /* Get event number */
+ g_gps_mngr.event = kGpsMsgchkC[ul_cnt].event;
+
+ if (GPS_EVT_STOPREQ == g_gps_mngr.event) {
+ SetStopFlag();
+ LineSensDrvThreadStopProcess();
+ }
+
+ break;
+ }
+
+ ul_cnt++;
+ }
+ }
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_TimEventCheck
+ * ABSTRACT : Timeout-Event check processing
+ * FUNCTION : Check received timeout messages and convert them to events
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : None
+ ********************************************************************************/
+void DevGpsTimEventCheck(void) {
+ u_int8 uc_time_kind = 0;
+ TimerToutMsg st_rcv_msg;
+ BOOL ret = FALSE;
+
+ // Set Error to Event No.
+ g_gps_mngr.event = (u_int32)NG;
+
+ // Get message
+ memcpy(&st_rcv_msg, &g_gps_msg_rcvr, sizeof(TimerToutMsg));
+
+ // Time judge kind
+ ret = DevGpsTimeJdgKind((u_int16)st_rcv_msg.TimerSeq);
+
+ if (TRUE == ret) {
+ /* If the sequence numbers match, */
+ /* Set the conversion code to the event number */
+ uc_time_kind = (u_int8)((st_rcv_msg.TimerSeq >> 8) & 0x00FF);
+ g_gps_mngr.event = kGpsTimchkC[uc_time_kind].event;
+ }
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_Gps_Mtrx.cpp b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Mtrx.cpp
new file mode 100755
index 0000000..b36a617
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Mtrx.cpp
@@ -0,0 +1,866 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Mtrx.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+#include "MDev_Gps_Mtrx.h"
+#include "positioning_def.h"
+
+#include "MDev_Gps_Main.h"
+#include "MDev_Gps_API.h"
+#include "MDev_GpsRecv.h"
+#include "MDev_Gps_Common.h"
+#include "MDev_Gps_Nmea.h"
+#include "MDev_Gps_TimerCtrl.h"
+
+extern uint8_t g_gps_reset_cmd_sending;
+/*---------------------------------------------------------------------------*/
+// Functions
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Nop
+ * ABSTRACT : No processing
+ * FUNCTION : NOP processing of the matrix
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : None
+ ********************************************************************************/
+void DevGpsNop(void) {
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_InitStart_SendReq
+ * ABSTRACT : Startup confirmation - Transmit request reception matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsInitStartSendReq(void) {
+ /** Send Request Receive Common Processing Call */
+ SendReqGpsCommon();
+ /* -- #GPF_60_040 */
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_InitStart_GPSResetReq
+ * ABSTRACT : Startup confirmation - GPS reset request reception matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsInitStartGPSResetReq(void) {
+ /** Reset request reception common processing call */
+ GPSResetReqGpsCommon();
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_InitStart_RcvCyclCmd
+ * ABSTRACT : Startup confirmation - Cyclic receive command receive matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsInitStartRcvCyclCmd(void) {
+ BOOL* pb_rcverr = &(g_gps_mngr.rcv_err_flag); /* GSP receiver error detection status */
+
+ /* Stop start confirmation monitoring timer */
+ (void)DevGpsTimeStop(GPS_STARTUP_TIMER); /* Ignore -> MISRA-C:2004 Rule 16.10 */ /* QAC 3200 */
+
+ /* GPS receiver anomaly detection timer stopped */
+ (void)DevGpsTimeStop(GPS_RECEIVERERR_TIMER);
+
+ /* State transition processing(in operation) */
+ ChangeStatusGpsCommon(GPS_STS_NORMAL);
+
+ // Send NAV-TIMEUTC sentence addition requests
+ DevGpsNavTimeUTCAddReq();
+
+ DevGpsWknRolloverGetReq();
+
+ /* Receive command analysis(u-blox) */
+ if (g_gps_reset_cmd_sending == FALSE) {
+ DevGpsRcvCyclCmd();
+ }
+
+ /* If a GPS receiver error is detected, the diagnosis code (current) is deleted. */
+ if (*pb_rcverr == TRUE) {
+ *pb_rcverr = FALSE;
+ DevSendGpsConnectError(FALSE);
+ }
+ // }
+ /* Reset retry counter */
+ RtyResetGpsCommon();
+
+ /* Sending pending commands */
+ SendSaveCmdGpsCommon(); /* State transition if pending commands exist( -> Sending) */
+
+ /* Cyclic reception data monitoring timer setting */
+ (void)DevGpsTimeSet(GPS_CYCL_TIMER); /* Ignore -> MISRA-C:2004 Rule 16.10 */ /* QAC 3200 */
+
+ /* GPS receiver anomaly detection timer setting */
+ (void)DevGpsTimeSet(GPS_RECEIVERERR_TIMER);
+
+ /* -- #GPF_60_024 */
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_InitStart_CyclDataTimeOut
+ * ABSTRACT : Startup confirmation - Reception cycle data monitoring timeout matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsInitStartCyclDataTimeOut(void) {
+ uint8_t ret = RETRY_OFF;
+
+ POSITIONING_LOG("DEV_Gps_InitStart_CyclDataTimeOut");
+
+ g_wcnct_err++; /* Count number of connection errors */
+
+ /* Stop all timers */
+ DevGpsTimeStop(GPS_STARTUP_TIMER);
+
+ DevGpsTimeStop(GPS_CYCL_TIMER);
+
+ DevGpsTimeStop(GPS_RECV_ACK_TIMER);
+
+ /* Hard reset judgment processing */
+ ret = HardResetChkGpsCommon();
+ if (RETRY_ON == ret) {
+ DevGpsResetReq(PNO_NONE, 0);
+
+ SendSaveCmdGpsCommon(); /* State transition if pending commands exist( -> Sending) */
+ } else if (RETRY_OFF == ret) {
+ /* Fixed number of hard resets completed */
+ } else {
+ /* Retrying(with hard reset) */
+ }
+ /* Clear cyclic receive data up to now */
+ DevGpsCycleDataClear();
+ /* Start confirmation monitoring timer setting */
+ DevGpsTimeSet(GPS_STARTUP_TIMER);
+ return;
+}
+
+/******************************************************************************
+@brief DEV_Gps_InitStart_NaviDataTimeOut<BR>
+ Startup confirmation - Navigation providing data monitoring timeout matrix function
+@outline Navigation providing data monitoring timeout matrix processing during startup confirmation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsInitStartNaviDataTimeOut(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_InitStart_DiagClkGuardTimeOut<BR>
+ Startup confirmation - Time guard monitoring timeout matrix functions provided by diagnosis
+@outline Diagnosis provision time guard monitoring timeout matrix process during startup checking
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsInitStartDiagClkGuardTimeOut(void) {
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_InitStart_AccOffStart
+ * ABSTRACT : Startup confirmation - Feature ACC-OFF instruction matrix functions
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsInitStartAccOffStart(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_InitStart_NaviInfoDeliver<BR>
+ Startup confirmation - Navigation information provision matrix processing
+@outline Navigation information provision matrix processing during startup confirmation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsInitStartNaviInfoDeliver(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_InitStart_NaviSpeedDeliver<BR>
+ Startup confirmation - Navigation vehicle speed information provision matrix processing
+@outline Navigation speed information provision matrix processing during startup confirmation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsInitStartNaviSpeedDeliver(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_InitStart_SettingTime<BR>
+ Startup confirmation - GPS time setting matrix processing
+@outline GPS time setting matrix process during startup confirmation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsInitStartSettingTime(void) {
+ POSITIONING_LOG("DEV_Gps_InitStart_SettingTime\n");
+ DevGpsCommSettingTime();
+ return;
+}
+
+/* start #GPF_60_109 */
+/******************************************************************************
+@brief DEV_Gps_InitStart_NmeaDataGuardTimeOut<BR>
+ Startup confirmation - NMEA monitoring timeout matrix processing
+@outline NMEA data-providing guard monitoring timeout process during startup checking
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsInitStartNmeaDataGuardTimeOut(void) {
+}
+
+/**
+ * @brief
+ * Startup confirmation - Backup memory read request matrix processing
+ */
+void DevGpsInitStartBackupDataLoadReq(void) {
+ POS_DATETIME st_date_time;
+ memset(&st_date_time, 0x00, sizeof(st_date_time));
+ /* Import GPS date and time settings */
+ DevGpsReadGpsTime(&st_date_time);
+ // Todo For Test don't need gstGpsFixCnt??
+ // DEV_Gps_ReadGpsFixCnt(); /* Read GPS fix count */
+ if (g_is_gpstime_sts == TRUE) {
+ DevGpsSettingTime(&st_date_time); /* Time setting */
+ }
+ return;
+}
+
+/**
+ * @brief
+ * Startup confirmation - Thread stop request matrix processing
+ */
+void DevGpsInitStartStopReq(void) {
+ /* Thread stop processing */
+ StopThreadGpsCommon();
+
+ return;
+}
+
+/**
+ * @brief
+ * Startup confirmation - GPS week adjustment counter notification process
+ */
+void DevGpsInitStartGpsweekcorcntNtf(void) {
+ DevGpsSetGpsweekcorcnt();
+ return;
+}
+
+/**
+ * @brief
+ * Startup confirmation - GPS recovery timeout process
+ */
+void DevGpsInitStartRecoveryTimeOut(void) {
+ return;
+}
+
+/**
+ * @brief
+ * Startup confirmation - GPS receiver anomaly detection timeout processing
+ */
+void DevGpsInitStartGpsReceiverErrTimeOut(void) {
+ BOOL* pb_rcverr = &(g_gps_mngr.rcv_err_flag); /* GSP receiver error detection status */
+
+ *pb_rcverr = TRUE;
+ DevSendGpsConnectError(TRUE);
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Normal_SendReq
+ * ABSTRACT : In operation - Transmit request reception matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsNormalSendReq(void) {
+ /** Store in a pending buffer #GPF_60_040 */
+ SendReqGpsCommon();
+
+ /** Send the command #GPF_60_040 */
+ SendSaveCmdGpsCommon();
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Normal_GPSResetReq
+ * ABSTRACT : In operation - GPS reset request reception matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsNormalGPSResetReq(void) {
+ /** Store in a pending buffer #GPF_60_040 */
+ GPSResetReqGpsCommon();
+
+ /** Send the command #GPF_60_040 */
+ SendSaveCmdGpsCommon();
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Normal_RcvCyclCmd_Nmea
+ * ABSTRACT : In operation - Cyclic receive command receive matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsNormalRcvCyclCmd(void) {
+ /* Cyclic reception data monitoring timer stopped */
+ (void)DevGpsTimeStop(GPS_CYCL_TIMER);
+ /* GPS receiver anomaly detection timer stopped */
+ (void)DevGpsTimeStop(GPS_RECEIVERERR_TIMER);
+
+ /* Notify Vehicle Sensor */
+ if (g_gps_reset_cmd_sending == FALSE) {
+ DevGpsRcvCyclCmd();
+ }
+
+ /* Reset retry counter */
+ RtyResetGpsCommon();
+
+ /* Cyclic reception data monitoring timer setting */
+ (void)DevGpsTimeSet(GPS_CYCL_TIMER); /* Ignore -> MISRA-C:2004 Rule 16.10 */ /* QAC 3200 */
+
+ /* GPS receiver anomaly detection timer setting */
+ (void)DevGpsTimeSet(GPS_RECEIVERERR_TIMER);
+
+ return;
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Normal_CyclDataTimeOut
+ * ABSTRACT : In operation - Reception cycle data monitoring timeout matrix function
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsNormalCyclDataTimeOut(void) {
+ /* Cyclic reception timeout common processing call */
+ CyclDataTimeOutGpsCommon();
+}
+
+/******************************************************************************
+@brief DEV_Gps_Normal_NaviDataTimeOut<BR>
+ In operation - Navigation providing data monitoring timeout matrix function
+@outline Navigation providing data monitoring timeout matrix processing during operation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsNormalNaviDataTimeOut(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Normal_DiagClkGuardTimeOut<BR>
+ In operation - Time guard monitoring timeout matrix functions provided by diagnosis
+@outline Diagnosis provision time guard monitoring timeout matrix process during operation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsNormalDiagClkGuardTimeOut(void) {
+}
+
+/********************************************************************************
+ * MODULE : DEV_Gps_Normal_AccOffStart
+ * ABSTRACT : Startup confirmation - Feature ACC-OFF instruction matrix functions
+ * FUNCTION :
+ * ARGUMENT :
+ * NOTE :
+ * RETURN :
+ ********************************************************************************/
+void DevGpsNormalAccOffStart(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Normal_NaviInfoDeliver<BR>
+ In operation - Navigation information provision matrix processing
+@outline Navigation information provision matrix processing during operation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsNormalNaviInfoDeliver(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Normal_NaviSpeedDeliver<BR>
+ In operation - Navigation vehicle speed information provision matrix processing
+@outline Navigation vehicle speed information provision matrix processing during operation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsNormalNaviSpeedDeliver(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Normal_SettingTime<BR>
+ In operation - GPS time setting matrix processing
+@outline GPS time setting matrix processing during operation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsNormalSettingTime(void) {
+ POSITIONING_LOG("DEV_Gps_Normal_SettingTime");
+ DevGpsCommSettingTime();
+ /** Send the command */
+ SendSaveCmdGpsCommon();
+
+ return;
+}
+
+/* start #GPF_60_109 */
+/******************************************************************************
+@brief DEV_Gps_Normal_NmeaDataGuardTimeOut<BR>
+ In operation - NMEA monitoring timeout matrix processing
+@outline NMEA data-providing guard monitoring timeout process during operation
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsNormalNmeaDataGuardTimeOut(void) {
+}
+
+/**
+ * @brief
+ * In operation - Backup memory read request matrix processing
+ */
+void DevGpsNormalBackupDataLoadReq(void) {
+ POS_DATETIME st_date_time;
+ memset(&st_date_time, 0x00, sizeof(st_date_time));
+ /* Import GPS date and time settings */
+ DevGpsReadGpsTime(&st_date_time);
+ // Todo For test don't need gstGpsFixCnt??
+ // DEV_Gps_ReadGpsFixCnt(); /* Read GPS fix count */
+ if (g_is_gpstime_sts == TRUE) {
+ DevGpsSettingTime(&st_date_time); /* Time setting */
+ }
+ return;
+}
+
+/**
+ * @brief
+ * In operation - Thread stop request matrix processing
+ */
+void DevGpsNormalStopReq(void) {
+ /* Thread stop processing */
+ StopThreadGpsCommon();
+
+ return;
+}
+
+/**
+ * @brief
+ * In operation - GPS week adjustment counter notification process
+ */
+void DevGpsNormalGpsweekcorcntNtf(void) {
+ DevGpsSetGpsweekcorcnt();
+ return;
+}
+
+/**
+ * @brief
+ * In operation - GPS recovery timeout processing
+ */
+void DevGpsNormalRecoveryTimeOut(void) {
+}
+
+/**
+ * @brief
+ * In operation - GPS receiver anomaly detection timeout processing
+ */
+void DevGpsNormalGpsReceiverErrTimeOut(void) {
+ BOOL* pb_rcverr = &(g_gps_mngr.rcv_err_flag); /* GSP receiver error detection status */
+
+ *pb_rcverr = TRUE;
+ DevSendGpsConnectError(TRUE);
+ return;
+}
+
+/* ++ #GPF_60_040 */
+/******************************************************************************
+@brief DEV_Gps_Send_SendReq<BR>
+ Sending - Transmit request reception matrix function
+@outline Processing for receiving a transmission request during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendSendReq(void) {
+ SendReqGpsCommon();
+ return;
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_GPSResetReq<BR>
+ Sending - GPS reset request reception matrix function
+@outline Processing when receiving a GPS reset request during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendGPSResetReq(void) {
+ GPSResetReqGpsCommon();
+ return;
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_RcvCyclCmd<BR>
+ Sending - Cyclic receive command receive matrix function
+@outline Processing at the reception of cyclic reception command during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendRcvCyclCmd(void) {
+ /* Cyclic reception data monitoring timer stopped */
+ DevGpsTimeStop(GPS_CYCL_TIMER);
+
+ /* GPS receiver anomaly detection timer stopped */
+ DevGpsTimeStop(GPS_RECEIVERERR_TIMER);
+
+ /* Notify Vehicle Sensor */
+ if (g_gps_reset_cmd_sending == FALSE) {
+ DevGpsRcvCyclCmd();
+ }
+
+ /* Reset retry counter */
+ RtyResetGpsCommon();
+
+ /* Cyclic reception data monitoring timer setting */
+ (void)DevGpsTimeSet(GPS_CYCL_TIMER);
+
+ (void)DevGpsTimeSet(GPS_RECEIVERERR_TIMER);
+
+ return;
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_RcvRspCmd<BR>
+ Sending - Response command reception matrix function
+@outline Processing when receiving a response command during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendRcvRspCmd(void) {
+ TG_GPS_OUTPUT_FORMAT rcv_cmd = g_gps_mngr.rcv_cmd;
+ BOOL b_snd_flag = TRUE;
+
+ /** Check whether the command matches the command being monitored. */
+ if (rcv_cmd == g_gps_mngr.resp_cmd) {
+ /** When the command being monitored is a cold start request */
+ if (g_gps_mngr.resp_rst_flag == GPS_CMD_RESET) {
+ POSITIONING_LOG("GPS_CMD_RESET\n");
+ b_snd_flag = DevGpsRcvProcGpsResetResp(reinterpret_cast<TG_GPS_RCV_DATA*>
+ (reinterpret_cast<void*>(g_gps_msg_rcvr.msgdat)));
+ } else if (g_gps_mngr.resp_rst_flag == GPS_CMD_TIMESET) {
+ POSITIONING_LOG("GPS_CMD_TIMESET\n");
+ DevGpsRcvProcTimeSetResp(reinterpret_cast<TG_GPS_RCV_DATA*>
+ (reinterpret_cast<void*>(g_gps_msg_rcvr.msgdat)));
+ } else if (g_gps_mngr.resp_rst_flag == GPS_CMD_SENTENCEADD_NAVTIMEUTC) {
+ POSITIONING_LOG("GPS_CMD_SENTENCEADD_NAVTIMEUTC\n");
+ DevGpsRcvProcNavSvinfoAddResp(reinterpret_cast<TG_GPS_RCV_DATA*>
+ (reinterpret_cast<void*>(g_gps_msg_rcvr.msgdat)));
+ } else if ( g_gps_mngr.resp_rst_flag == GPS_CMD_WKNROLLOVER ) {
+ POSITIONING_LOG("GPS_CMD_WKNROLLOVER\n");
+ DevGpsRcvProcWknRolloverGetResp(reinterpret_cast<TG_GPS_RCV_DATA*>
+ (reinterpret_cast<void*>(g_gps_msg_rcvr.msgdat)));
+ } else {
+ POSITIONING_LOG("g_gps_mngr.resp_rst_flag INVALID!! [resp_rst_flag = %d]", g_gps_mngr.resp_rst_flag);
+ }
+
+ if (b_snd_flag == TRUE) {
+ /** Stop ACK monitoring timer */
+ DevGpsTimeStop(GPS_RECV_ACK_TIMER);
+ /* State transition processing(in operation) */
+ ChangeStatusGpsCommon(GPS_STS_NORMAL);
+ /** Reset retry counter */
+ SendRtyResetGpsCommon();
+ /** Delete command from pending buffer */
+ DeleteSaveCmdGpsCommon();
+ /* Sending pending commands */
+ SendSaveCmdGpsCommon();
+ }
+ } else {
+ }
+
+ return;
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_RspDataTimeOut<BR>
+ Sending - Response monitoring timeout reception matrix function
+@outline Processing at reception of response monitoring timeout during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendRspDataTimeOut(void) {
+ DevGpsTimeStop(GPS_RECV_ACK_TIMER);
+ /** Send retry count */
+ g_gps_mngr.sndcnt++;
+
+ /** Retry judgment */
+ if (g_gps_mngr.sndcnt == SNDNG_MAX) {
+ /** At the time of retry */
+ POSITIONING_LOG("GPS Hw Reset : sndcnt[%d]", g_gps_mngr.sndcnt);
+
+ /** When the command being monitored is a cold start request */
+ if (g_gps_mngr.resp_rst_flag == GPS_CMD_RESET) {
+ POSITIONING_LOG("g_gps_mngr.sndcnt == SNDNG_MAX (GPS_CMD_RESET)");
+ /** Send Reset ResponseCommunication error */
+ DevGpsRstAnsSend(g_gps_mngr.resp_pno, g_gps_mngr.resp_rid, GPS_SENDNG);
+ g_gps_reset_cmd_sending = FALSE;
+
+ } else if (g_gps_mngr.resp_rst_flag == GPS_CMD_TIMESET) {
+ POSITIONING_LOG("g_gps_mngr.sndcnt == SNDNG_MAX (GPS_CMD_TIMESET)");
+ DevGpsTimesetAnsSend(g_gps_mngr.resp_pno, g_gps_mngr.resp_rid, GPS_SENDNG);
+ } else if (g_gps_mngr.resp_rst_flag == GPS_CMD_SENTENCEADD_NAVTIMEUTC) {
+ POSITIONING_LOG("g_gps_mngr.sndcnt == SNDNG_MAX (GPS_CMD_SENTENCEADD_NAVTIMEUTC)");
+ DevGpsNavTimeUTCAddReq(); /* Retransmission of requests to add NAV-SVINFO commands */
+ } else if (g_gps_mngr.resp_rst_flag == GPS_CMD_WKNROLLOVER) { /* GPS rollover reference date acquisition response */
+ POSITIONING_LOG("g_gps_mngr.sndcnt == SNDNG_MAX (GPS_CMD_WKNROLLOVER)");
+ DevGpsWknRolloverGetReq(); /* GPS rollover standard week number acquisition request retransmission */
+ } else {
+ POSITIONING_LOG("g_gps_mngr.resp_rst_flag INVALID!! [resp_rst_flag = %d]", g_gps_mngr.resp_rst_flag);
+ }
+
+ DeleteSaveCmdGpsCommon();
+
+ ChangeStatusGpsCommon(GPS_STS_NORMAL);
+
+ SendSaveCmdGpsCommon();
+ /** Reset retry counter */
+ SendRtyResetGpsCommon();
+ } else {
+ POSITIONING_LOG("GPS Send Retry : sndcnt[%d]", g_gps_mngr.sndcnt);
+ /** Retransmission of pending command */
+ SendSaveCmdGpsCommon();
+ }
+
+ return;
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_CyclDataTimeOut<BR>
+ Sending - Reception cycle data monitoring timeout matrix function
+@outline Processing when receiving periodic reception data monitoring timeout during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendCyclDataTimeOut(void) {
+ CyclDataTimeOutGpsCommon();
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_NaviDataTimeOut<BR>
+ Sending - Navigation providing data monitoring timeout matrix function
+@outline Navigation providing data monitoring timeout matrix processing during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendNaviDataTimeOut(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_DiagClkGuardTimeOut<BR>
+ Sending - Time guard monitoring timeout matrix functions provided by diagnosis
+@outline Diagnosis providing time guard monitoring timeout matrix process during sending
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendDiagClkGuardTimeOut(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_AccOffStart<BR>
+ Sending - Feature ACC-OFF instruction reception matrix functions
+@outline Processing when receiving ACC-OFF instruction in function being transmitted
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendAccOffStart(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_NaviInfoDeliver<BR>
+ Sending - Navigation information provision matrix processing
+@outline Navigation information provision matrix processing during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendNaviInfoDeliver(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_NaviSpeedDeliver<BR>
+ Sending - Navigation vehicle speed information provision matrix processing
+@outline Navigation vehicle speed information provision matrix processing during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendNaviSpeedDeliver(void) {
+}
+
+/******************************************************************************
+@brief DEV_Gps_Send_SettingTime<BR>
+ Sending - GPS time setting matrix processing
+@outline GPS time setting matrix processing during transmission
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendSettingTime(void) {
+ DevGpsCommSettingTime();
+ return;
+}
+
+/* start #GPF_60_109 */
+/******************************************************************************
+@brief DEV_Gps_Send_NmeaDataGuardTimeOut<BR>
+ Sending - NMEA monitoring timeout matrix processing
+@outline Sending NMEA monitoring timeouts
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsSendNmeaDataGuardTimeOut(void) {
+}
+
+/**
+ * @brief
+ * Sending - Backup memory read request matrix processing
+ */
+void DevGpsSendBackupDataLoadReq(void) {
+ POS_DATETIME st_date_time;
+
+ memset(&st_date_time, 0x00, sizeof(st_date_time));
+ /* Import GPS date and time settings */
+ DevGpsReadGpsTime(&st_date_time);
+ // Todo For test don't need gstGpsFixCnt??
+ // DEV_Gps_ReadGpsFixCnt(); /* Read GPS fix count */
+ if (g_is_gpstime_sts == TRUE) {
+ DevGpsSettingTime(&st_date_time); /* Time setting */
+ }
+
+ return;
+}
+
+/**
+ * @brief
+ * Sending - Thread stop request matrix processing
+ */
+void DevGpsSendStopReq(void) {
+ /* Thread stop processing */
+ StopThreadGpsCommon();
+ return;
+}
+
+/**
+ * @brief
+ * Sending - GPS week adjustment counter notification process
+ */
+void DevGpsSendGpsweekcorcntNtf(void) {
+ DevGpsSetGpsweekcorcnt();
+ return;
+}
+
+/**
+ * @brief
+ * Sending - GPS recovery timeout processing
+ */
+void DevGpsSendRecoveryTimeOut(void) {
+ return;
+}
+
+/**
+ * @brief
+ * Sending - GPS receiver anomaly detection timeout processing
+ */
+void DevGpsSendGpsReceiverErrTimeOut(void) {
+ BOOL* pb_rcverr = &(g_gps_mngr.rcv_err_flag); /* GSP receiver error detection status */
+
+ *pb_rcverr = TRUE;
+ DevSendGpsConnectError(TRUE);
+ return;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_Gps_Nmea.cpp b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Nmea.cpp
new file mode 100755
index 0000000..60fa1d8
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_Gps_Nmea.cpp
@@ -0,0 +1,928 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_Nmea.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "MDev_Gps_Nmea.h"
+#include "positioning_common.h"
+#include "MDev_Gps_API.h"
+#include "MDev_Gps_Main.h"
+#include "MDev_GpsRecv.h"
+#include "MDev_Gps_Common.h"
+#include "MDev_GpsRollOver.h"
+
+/*---------------------------------------------------------------------------*/
+// Value define
+#define ROLOVR_GPSWEEKCOR_NG 0xFF /* WEEK COMP. CORRECT CORRECTOR INVALUE */
+#define TMT_TGET_INI_INTERVAL (100) /* GPS time compensation interval immediately after startup (value with 10[msec] as 1) */
+#define TMT_DISCONTINUITY_TIME_TOUT_SEQ (0x5051) /* Sequence number of GPS time acquisition timeout based on date/time discontinuity */
+
+/*---------------------------------------------------------------------------*/
+// Global values
+
+static TG_GPS_RCVDATA g_st_gpscycle_data;
+u_int8 g_gps_week_cor_cnt = ROLOVR_GPSWEEKCOR_NG;
+
+extern uint8_t g_gpstime_raw_tdsts;
+
+const TG_GPS_CMD_ANA_TBL kGpsCmdAnaTblUblox[MDEV_GPSCMDANATBLNMEA_MAX] = {
+ /* Sentences Maximum length Receiving type Presence of notification Receive Format */
+ /* NMEA */
+ {{GPS_CMD_NMEA_RMC}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_RMC }, /* RMC information */
+ {{GPS_CMD_NMEA_VTG}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_VTG }, /* VTG information */
+ {{GPS_CMD_NMEA_GGA}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GGA }, /* GGA information */
+ {{GPS_CMD_NMEA_GSA}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GSA }, /* GSA information */
+ {{GPS_CMD_NMEA_GSV_1}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GSV1 }, /* GSV information1 */
+ {{GPS_CMD_NMEA_GSV_2}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GSV2 }, /* GSV information2 */
+ {{GPS_CMD_NMEA_GSV_3}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GSV3 }, /* GSV information3 */
+ {{GPS_CMD_NMEA_GSV_4}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GSV4 }, /* GSV information4 */
+ {{GPS_CMD_NMEA_GSV_5}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GSV5 }, /* GSV information5 */
+ {{GPS_CMD_NMEA_GLL}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GLL }, /* GLL information */
+ {{GPS_CMD_NMEA_GST}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_GST }, /* GST information */
+ /* UBX */
+ {{0xB5, 0x62, 0x0A, 0x04}, GPS_NMEA_MAX_SZ, RCV_RESP, TRUE, GPS_FORMAT_MON_VER }, /* MON-VER */
+ {{0xB5, 0x62, 0x0B, 0x01}, GPS_NMEA_MAX_SZ, RCV_RESP, TRUE, GPS_FORMAT_AID_INI }, /* AID-INI */
+ {{0xB5, 0x62, 0x05 }, GPS_NMEA_MAX_SZ, RCV_RESP, TRUE, GPS_FORMAT_ACK_ACKNACK }, /* ACK-ACKNACK */
+ {{0xB5, 0x62, 0x01, 0x21}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_NAV_TIMEUTC }, /* NAV-TIMEUTC */
+ {{0xB5, 0x62, 0x01, 0x22}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_NAV_CLOCK }, /* NAV-CLOCK */
+ {{0xB5, 0x62, 0x02, 0x23}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_RXM_RTC5 }, /* RXM-RTC5 */
+ {{0xB5, 0x62, 0x01, 0x30}, GPS_NMEA_MAX_SZ, RCV_CYCLE, TRUE, GPS_FORMAT_NAV_SVINFO }, /* NAV-SVINFO */
+ {{0xB5, 0x62, 0x06, 0x23}, GPS_NMEA_MAX_SZ, RCV_RESP, TRUE, GPS_FORMAT_CFG_NAVX5 }, /* CFG-NAVX5 */
+ {{ENDMARK}, 0, 0, FALSE, GPS_FORMAT_MIN } /* Table termination */
+};
+
+/*---------------------------------------------------------------------------*/
+// Functions
+/**
+ * @brief
+ * Time Calculation Process Considering Rollover
+ *
+ * @param[in/out]
+ *
+ * @return none
+ * @retval none
+ */
+static BOOL DevCalcRollOverTime(TG_TIM_ROLOVR_YMD* base_ymd, TG_TIM_ROLOVR_YMD* conv_ymd) {
+ BOOL ret = TRUE;
+ static u_int16 year_old = 0;
+ static u_int16 confirm_cnt = 0;
+ u_int8 gps_week_corr = g_gps_week_cor_cnt;
+
+ if (gps_week_corr == ROLOVR_GPSWEEKCOR_NG) {
+ gps_week_corr = 0;
+ ret = FALSE;
+ } else {
+ if (year_old > base_ymd->year) {
+ confirm_cnt++;
+ if (confirm_cnt >= 10) {
+ confirm_cnt = 0;
+ year_old = base_ymd->year;
+ g_gps_week_cor_cnt = ROLOVR_GPSWEEKCOR_NG;
+ /* Starting the GPS time acquisition timer (1 second timer) based on date/time discontinuity */
+ _pb_ReqTimerStart(PNO_CLK_GPS, TMT_DISCONTINUITY_TIME_TOUT_SEQ, TIMER_TYPE_USN, TMT_TGET_INI_INTERVAL);
+ }
+ ret = FALSE;
+ } else {
+ confirm_cnt = 0;
+ year_old = base_ymd->year;
+ }
+ }
+ /* Calculate time for rollover */
+ GPSRollOverConvTime(base_ymd, conv_ymd, gps_week_corr);
+
+ return ret;
+}
+/******************************************************************************************************/
+
+
+/**
+ * @brief
+ * NMEA data notification
+ */
+void DevGpsSndCycleDataNmea(void) {
+ /* Notifying vehicle sensor of NMEA */
+
+ MDEV_GPS_NMEA st_nmea;
+ TG_GPS_NMEA_INFO st_gps_nmea_info;
+ RET_API l_ret = RET_NORMAL;
+ BOOL b_get = FALSE;
+ u_int8 uc_nmea_data[GPS_NMEA_MAX_SZ];
+ u_int32 ul_strlen = 0;
+ u_int16 us_offset = sizeof(TG_GPS_NMEA_INFO);
+
+ memset(&st_nmea, 0x00, sizeof(st_nmea) ); /* QAC 3200 */
+ memset(&st_gps_nmea_info, 0x00, sizeof(st_gps_nmea_info) ); /* QAC 3200 */
+ memset(uc_nmea_data, 0x00, sizeof(uc_nmea_data) ); /* QAC 3200 */
+
+ /* Get received NMEA data from storage area(GGA) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_GGA);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GGA; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GGA].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GGA].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GLL) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_GLL);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GLL; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GLL].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GLL].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GSA) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_GSA);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GSA1; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSA1].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSA1].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GST) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_GST);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GST; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GST].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GST].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(RMC) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_RMC);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_RMC; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_RMC].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_RMC].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(VTG) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_VTG);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_VTG; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_VTG].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_VTG].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GSV1) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_GSV1);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GSV1; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV1].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV1].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GSV2) */
+ b_get = DevGpsCycleDataGetNmea( uc_nmea_data, sizeof(uc_nmea_data), GPS_NMEA_INDEX_GSV2 );
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GSV2; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen); /* Data storage */
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV2].uc_size = (u_int8)ul_strlen;
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV2].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GSV3) */
+ b_get = DevGpsCycleDataGetNmea( uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_GSV3 );
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GSV3; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen);
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV3].uc_size = static_cast<u_int8>(ul_strlen);
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV3].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GSV4) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data), GPS_NMEA_INDEX_GSV4);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GSV4; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen);
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV4].uc_size = static_cast<u_int8>(ul_strlen);
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV4].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ /* Get received NMEA data from storage area(GSV5) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data), GPS_NMEA_INDEX_GSV5);
+ if (b_get == TRUE) {
+ /* Data present */
+ st_gps_nmea_info.ul_rcvsts |= POS_SNS_GPS_NMEA_GSV5; /* Receive flag */
+ ul_strlen = strlen(reinterpret_cast<const char *>(uc_nmea_data)); /* QAC 310 */
+ if (ul_strlen > GPS_NMEA_MAX_SZ) {
+ ul_strlen = GPS_NMEA_MAX_SZ;
+ }
+
+ if ((us_offset + ul_strlen) < SENSOR_MSG_VSINFO_DSIZE) {
+ (void)memcpy(&(st_nmea.uc_nmea_data[us_offset]), uc_nmea_data, ul_strlen);
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV5].uc_size = static_cast<u_int8>(ul_strlen);
+ st_gps_nmea_info.st_nmea_sentence_info[POS_SNS_GPS_NMEA_SNO_GSV5].us_offset = us_offset;
+ us_offset += (u_int16)ul_strlen;
+ }
+ }
+
+ if (0 != st_gps_nmea_info.ul_rcvsts) {
+ /* Receive flag */
+ (void)memcpy(&(st_nmea.uc_nmea_data[0]), &st_gps_nmea_info, sizeof(st_gps_nmea_info));
+
+ /* Provided to vehicle sensor */
+ l_ret = SendNmeaGps(&st_nmea);
+
+ if (RET_NORMAL != l_ret) {
+ POSITIONING_LOG("SendNmeaGps SndMsg Error\n");
+ }
+ } else {
+ /* Do not provide to vehicle sensor when data acquisition fails or no data */
+ }
+
+ return;
+}
+
+/**
+ * @brief
+ * Analysis of the received command
+ */
+void DevGpsRcvCyclCmd(void) {
+ int32 i_ret = 0;
+ TG_GPS_OUTPUT_FORMAT e_format = GPS_FORMAT_MIN;
+
+ TG_GPS_RCV_DATA st_rcv_data; /* Pointer to the received message */
+ (void)memcpy(&st_rcv_data, &(g_gps_msg_rcvr.msgdat[0]), sizeof(st_rcv_data) ); /* QAC 3200 */
+
+ /* Analysis of received commands */
+ i_ret = JudgeFormatGpsCommon(reinterpret_cast<u_char*>(&(st_rcv_data.bygps_data[0])),
+ static_cast<u_int32>(st_rcv_data.bydata_len),
+ &e_format);
+
+ if (i_ret == GPSRET_SNDCMD) {
+ /* For NMEA formats */
+ if ((e_format == GPS_FORMAT_RMC) ||
+ (e_format == GPS_FORMAT_VTG) ||
+ (e_format == GPS_FORMAT_GGA) ||
+ (e_format == GPS_FORMAT_GSA) ||
+ (e_format == GPS_FORMAT_GSV1) ||
+ (e_format == GPS_FORMAT_GSV2) ||
+ (e_format == GPS_FORMAT_GSV3) ||
+ (e_format == GPS_FORMAT_GSV4) ||
+ (e_format == GPS_FORMAT_GSV5) ||
+ (e_format == GPS_FORMAT_GLL) ||
+ (e_format == GPS_FORMAT_GST)) {
+ /* NMEA reception process */
+ RcvCyclCmdNmeaGpsCommon(&(st_rcv_data.bygps_data[0]), (u_int32)st_rcv_data.bydata_len, e_format);
+ } else if ((e_format == GPS_FORMAT_MON_VER) ||
+ (e_format == GPS_FORMAT_AID_INI) ||
+ (e_format == GPS_FORMAT_ACK_ACKNACK) ||
+ (e_format == GPS_FORMAT_NAV_TIMEUTC) ||
+ (e_format == GPS_FORMAT_NAV_CLOCK) ||
+ (e_format == GPS_FORMAT_RXM_RTC5) ||
+ (e_format == GPS_FORMAT_NAV_SVINFO)) {
+ /* UBX reception process */
+ RcvCyclCmdExtGpsCommon(&(st_rcv_data.bygps_data[0]), (u_int32)st_rcv_data.bydata_len, e_format);
+ } else {
+ POSITIONING_LOG("Forbidden ERROR!![e_format=%d]", (int)e_format);
+ }
+ } else if (i_ret == GPSRET_CMDERR) {
+ /* Receive command error */
+
+ /* Discard previously received data */
+ DevGpsCycleDataClear();
+ /* Initialize receive format */
+ g_rcv_format = GPS_FORMAT_MIN;
+ } else {
+ }
+
+ return;
+}
+
+/**
+ * @brief
+ * Check of the received command
+ */
+void DevGpsCmdEventCheckNmea(void) {
+ u_int32 ul_cnt = 0;
+ TG_GPS_RCV_DATA st_rcv_data;
+ u_char* pub_rcv_data = NULL;
+ BOOL brk_flg = FALSE;
+
+ memset(&st_rcv_data, 0, sizeof(TG_GPS_RCV_DATA));
+ memcpy( &st_rcv_data, &(g_gps_msg_rcvr.msgdat[0]), sizeof(TG_GPS_RCV_DATA) );
+ pub_rcv_data = reinterpret_cast<u_char*>(&(st_rcv_data.bygps_data[0]));
+
+ /* Analysis of received commands */
+ for (ul_cnt = 0; ul_cnt < (u_int32)GPSCMDANATBL_MAX; ul_cnt++) {
+ /* End-of-table decision */
+ if (CheckFrontStringPartGpsCommon(reinterpret_cast<const u_char*>(ENDMARK),
+ reinterpret_cast<const u_char*>(kGpsCmdAnaTbl[ul_cnt].c_sentence)) == RET_NORMAL ) {
+ g_wrecv_err++;
+
+ /* Data error is set to Event ID. */
+ g_gps_mngr.event = (u_int32)NG;
+
+ brk_flg = TRUE;
+ } else if (CheckFrontStringPartGpsCommon(pub_rcv_data, kGpsCmdAnaTbl[ul_cnt].c_sentence) == RET_NORMAL) {
+ /* Reception type determination */
+
+ /* Using $GPRMC in responses to resets */
+ if ((g_gps_mngr.sts == GPS_STS_SENT) &&
+ (g_gps_mngr.resp_cmd == GPS_FORMAT_RMC) &&
+ (kGpsCmdAnaTbl[ul_cnt].e_rcv_format == GPS_FORMAT_RMC)) {
+ POSITIONING_LOG("Received response ($GPRMC) form GPS device.\n");
+
+ /** Response command */
+ g_gps_mngr.event = GPS_EVT_RECVRSPDAT;
+
+ /** Receive format setting */
+ g_gps_mngr.rcv_cmd = kGpsCmdAnaTbl[ul_cnt].e_rcv_format;
+ } else if (kGpsCmdAnaTbl[ul_cnt].ul_rcv_kind == RCV_CYCLE) {
+ /* Cyclic receive command */
+ g_gps_mngr.event = GPS_EVT_RECVCYCLDAT;
+
+ /* Receive format setting */
+ g_gps_mngr.rcv_cmd = kGpsCmdAnaTbl[ul_cnt].e_rcv_format;
+ } else if (kGpsCmdAnaTbl[ul_cnt].ul_rcv_kind == RCV_RESP) {
+ /** Response command */
+ g_gps_mngr.event = GPS_EVT_RECVRSPDAT;
+
+ /** Receive format setting */
+ g_gps_mngr.rcv_cmd = kGpsCmdAnaTbl[ul_cnt].e_rcv_format;
+ } else {
+ /* Undefined value */
+ /* Data error is set to Event ID. */
+ g_gps_mngr.event = (u_int32)NG;
+ }
+
+ brk_flg = TRUE;
+ }
+
+ if (brk_flg == TRUE) {
+ break;
+ }
+ }
+
+ return;
+}
+
+/**
+ * @brief
+ * Get GPS reception status
+ *
+ * By analyzing the last received GSA-sentence and using the satellite-number as the Satellite number
+ * Determines the reception status based on whether or not notification has been made, and returns it.
+ *
+ * @param[in] no_sv Satellite number
+ *
+ * @return NAVIINFO_DIAG_GPS_RCV_STS_NOTUSEFIX - Positioning not used
+ * NAVIIFNO_DIAG_GPS_RCV_STS_USEFIX - Positioning use
+ */
+u_int8 DevGpsGetGpsRcvSts(u_int8 sv) {
+ u_int8 rcv_sts = NAVIINFO_DIAG_GPS_RCV_STS_TRACHING; /* Tracking in progress */
+ u_int8 uc_nmea_data[GPS_NMEA_MAX_SZ];
+ u_int8 uc_no = 0;
+ BOOL b_get = FALSE;
+ int32 i = 0;
+
+ /* Get received NMEA data from storage area(GSA) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data), GPS_NMEA_INDEX_GSA);
+
+ if (b_get == TRUE) {
+ for (i = 0; i < GPS_NMEA_NUM_GSA_SV; i++) {
+ /* Get satellite number */
+ uc_no = (uint8_t)GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSA_SV + (u_int8)(1 * i), uc_nmea_data);
+
+ if (uc_no == sv) {
+ rcv_sts = NAVIINFO_DIAG_GPS_RCV_STS_USEFIX; /* Positioning use */
+ break;
+ }
+ }
+ }
+
+ return rcv_sts;
+}
+
+/**
+ * @brief
+ * GPS information analysis
+ *
+ * Analyzing received NMEA sentences
+ * @param[out] navilocinfo Navigation information
+ */
+void DevGpsAnalyzeNmea(NAVIINFO_ALL* navilocinfo) {
+ u_int8 uc_nmea_data[GPS_NMEA_MAX_SZ];
+ int32 no_sv = 0; /* number of Satellites in View */
+ int32 __offset = 0;
+ char utc_time[12]; /* hhmmss.sss */
+ char _date[6]; /* ddmmyy */
+ char _status = 0; /* 'V' or 'A' */
+ char indicator; /* 'N' or 'S' or 'E' or 'W' */
+ char work[8]; /* Work buffer for converting String data */
+ BOOL b_get = FALSE;
+ uint8_t fixsts = NAVIINFO_DIAG_GPS_FIX_STS_NON;
+ uint8_t fixsts_gga;
+ BOOL bvalid_lon = FALSE;
+ BOOL bvalid_lat = FALSE;
+ BOOL bvalid = FALSE;
+ TG_TIM_ROLOVR_YMD base_ymd;
+ TG_TIM_ROLOVR_YMD conv_ymd;
+ BOOL roll_over_sts;
+ u_int8 _tdsts = g_gpstime_raw_tdsts;
+
+ GpsSatelliteInfo st_visible_satellite_list[GPS_MAX_NUM_VISIBLE_SATELLITES]; /* Visible satellite list */
+ GpsSatelliteInfo st_tmp_buf;
+
+ int32 i = 0;
+ int32 j = 0;
+ int32 k = 0;
+
+ SENSORLOCATION_LONLATINFO_DAT st_lonlat;
+ SENSORLOCATION_ALTITUDEINFO_DAT st_altitude;
+ SENSORMOTION_HEADINGINFO_DAT st_heading;
+ // MDEV_GPS_RTC st_rtc;
+ SENSOR_MSG_GPSTIME st_gps_time;
+ SENSORMOTION_SPEEDINFO_DAT st_speed;
+
+ memset(&st_lonlat, 0x00, sizeof(SENSORLOCATION_LONLATINFO_DAT));
+ memset(&st_altitude, 0x00, sizeof(SENSORLOCATION_ALTITUDEINFO_DAT));
+ memset(&st_heading, 0x00, sizeof(SENSORMOTION_HEADINGINFO_DAT));
+ // memset(&st_rtc, 0x00, sizeof(MDEV_GPS_RTC));
+ memset(&st_gps_time, 0x00, sizeof(SENSOR_MSG_GPSTIME));
+ memset(&st_speed, 0x00, sizeof(SENSORMOTION_SPEEDINFO_DAT));
+
+ /* Satellite signal strength list initialization */
+ (void)memset(st_visible_satellite_list, 0x00, sizeof(GpsSatelliteInfo) * GPS_MAX_NUM_VISIBLE_SATELLITES);
+
+ /* Get received NMEA data from storage area(GSA) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data), GPS_NMEA_INDEX_GSA);
+
+ if (b_get == TRUE) {
+ fixsts = static_cast<uint8_t>(GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSA_FS, uc_nmea_data));
+ }
+
+ /* Get received NMEA data from storage area(RMC) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data) , GPS_NMEA_INDEX_RMC);
+
+ if (b_get == TRUE) {
+ navilocinfo->stDiagGps.stFix.stWgs84.lLat =
+ GetLonLatFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_LATITUDE, uc_nmea_data, &bvalid_lat); /* GPS location information and latitude */
+
+ GetStringFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_NS, uc_nmea_data, &indicator, sizeof(indicator));
+
+ if (indicator != GPS_NMEA_RMC_IND_NORTH) {
+ navilocinfo->stDiagGps.stFix.stWgs84.lLat *= -1;
+ }
+
+ POSITIONING_LOG("lLat = %d", navilocinfo->stDiagGps.stFix.stWgs84.lLat);
+
+ navilocinfo->stDiagGps.stFix.stWgs84.lLon =
+ GetLonLatFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_LONGITUDE, uc_nmea_data, &bvalid_lon); /* GPS position information and longitude */
+
+ GetStringFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_EW, uc_nmea_data, &indicator, sizeof(indicator));
+
+ if (indicator != GPS_NMEA_RMC_IND_EAST) {
+ navilocinfo->stDiagGps.stFix.stWgs84.lLon *= -1;
+ }
+
+ st_lonlat.Longitude = navilocinfo->stDiagGps.stFix.stWgs84.lLon;
+ st_lonlat.Latitude = navilocinfo->stDiagGps.stFix.stWgs84.lLat;
+
+ POSITIONING_LOG("lLon = %d", navilocinfo->stDiagGps.stFix.stWgs84.lLon);
+
+ /* Get Date information */
+ (void)GetStringFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_DATE, uc_nmea_data, _date, 6);
+ (void)memset(&base_ymd, 0, sizeof(base_ymd)); /* QAC 3200 */
+ (void)memset(&conv_ymd, 0, sizeof(conv_ymd)); /* QAC 3200 */
+ (void)memset(work, 0, sizeof(work)); /* QAC 3200 */
+
+ (void)strncpy(work, &_date[4], 2); /* QAC 3200 */
+ base_ymd.year = (u_int16)(2000 + atoi(work)); /* YEAR */
+
+ st_gps_time.utc.year = (uint8_t)atoi(work);
+
+ (void)strncpy(work, &_date[2], 2); /* QAC 3200 */
+ base_ymd.month = (u_int16)(atoi(work)); /* MONTH */
+
+ st_gps_time.utc.month = (uint8_t)atoi(work);
+
+ (void)strncpy(work, &_date[0], 2); /* QAC 3200 */
+ base_ymd.day = (u_int16)(atoi(work)); /* DAY */
+
+ st_gps_time.utc.date = (uint8_t)atoi(work);
+
+ POSITIONING_LOG("year = %d", base_ymd.year);
+ POSITIONING_LOG("month = %d", base_ymd.month);
+ POSITIONING_LOG("date = %d", base_ymd.day);
+
+ /* UTC time information acquisition */
+ (void)GetStringFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_UTC, uc_nmea_data, utc_time, 12);
+
+ (void)strncpy(work, &utc_time[0], 2); /* QAC 3200 */
+ navilocinfo->stNaviGps.utc.hour = (uint8_t)atoi(work); /* HOUR */
+
+ st_gps_time.utc.hour = navilocinfo->stNaviGps.utc.hour;
+ POSITIONING_LOG("hour = %d", navilocinfo->stNaviGps.utc.hour);
+
+ (void)strncpy(work, &utc_time[2], 2); /* QAC 3200 */
+ navilocinfo->stNaviGps.utc.minute = (uint8_t)atoi(work); /* MINUTE */
+
+ st_gps_time.utc.minute = navilocinfo->stNaviGps.utc.minute;
+ POSITIONING_LOG("minute = %d", navilocinfo->stNaviGps.utc.minute);
+
+ (void)strncpy(work, &utc_time[4], 2); /* QAC 3200 */
+ navilocinfo->stNaviGps.utc.second = (uint8_t)atoi(work); /* SECOND */
+
+ st_gps_time.utc.second = navilocinfo->stNaviGps.utc.second;
+ POSITIONING_LOG("second = %d", navilocinfo->stNaviGps.utc.second);
+
+ /* Compass information acquisition */
+ navilocinfo->stNaviGps.heading =
+ GetHeadingFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_COG, uc_nmea_data, &bvalid);
+
+ st_heading.Heading = navilocinfo->stNaviGps.heading;
+ POSITIONING_LOG("heading = %u", navilocinfo->stNaviGps.heading);
+
+ st_speed.Speed = GetSpeedFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_SPEED, uc_nmea_data, &bvalid);
+
+ /* Fix Status/Time Status Calculation */
+ (void)GetStringFromNmeaGpsCommon(GPS_NMEA_FNO_RMC_STATUS, uc_nmea_data, &_status, sizeof(_status));
+
+ if ((_status == GPS_NMEA_RMC_STS_VALID) && (bvalid_lat == TRUE) && (bvalid_lon == TRUE)) {
+ /* Fix status information */
+ switch (fixsts) {
+ case GPS_NMEA_GSA_FIX_STS_NON:
+ navilocinfo->stDiagGps.stFix.ucFixSts = NAVIINFO_DIAG_GPS_FIX_STS_NON;
+ break;
+ case GPS_NMEA_GSA_FIX_STS_2D:
+ navilocinfo->stDiagGps.stFix.ucFixSts = NAVIINFO_DIAG_GPS_FIX_STS_2D;
+ break;
+ case GPS_NMEA_GSA_FIX_STS_3D:
+ navilocinfo->stDiagGps.stFix.ucFixSts = NAVIINFO_DIAG_GPS_FIX_STS_3D;
+ break;
+ default:
+ POSITIONING_LOG("GSA Nav Mode Error [fixsts:%d]", fixsts);
+ break;
+ }
+
+ if (_tdsts == POS_TIMESTS_OK) {
+ roll_over_sts = DevCalcRollOverTime(&base_ymd, &conv_ymd);
+ navilocinfo->stNaviGps.utc.year = conv_ymd.year; /* year (after conversion) */
+ navilocinfo->stNaviGps.utc.month = (u_int8)(conv_ymd.month); /* month (after conversion) */
+ navilocinfo->stNaviGps.utc.date = (u_int8)(conv_ymd.day); /* dat (after conversion) */
+ if (roll_over_sts == FALSE) {
+ navilocinfo->stNaviGps.tdsts = POS_TIMESTS_NG;
+ /* Reserve[0] is time setting information: anomaly time, but can be calculated by rolling over. */
+ navilocinfo->stNaviGps.reserve[0] = GPS_TIME_ROLOVR;
+ } else {
+ /* When the location information is normal, the time information is also judged to be normal. */
+ navilocinfo->stNaviGps.tdsts = POS_TIMESTS_OK; /* Time calibration completed */
+ /* Reserve[0] is time setting information: Use time status received from GPS device. */
+ navilocinfo->stNaviGps.reserve[0] = GPS_TIME_RX;
+ }
+ } else {
+ navilocinfo->stNaviGps.tdsts = POS_TIMESTS_NG; /* Time uncalibrated */
+ /* Reserve[0] is time setting information: Use time status received from GPS device. */
+ navilocinfo->stNaviGps.reserve[0] = GPS_TIME_RX;
+ navilocinfo->stNaviGps.utc.year = base_ymd.year; /* year(after conversion) */
+ navilocinfo->stNaviGps.utc.month = (u_int8)(base_ymd.month); /* month (after conversion) */
+ navilocinfo->stNaviGps.utc.date = (u_int8)(base_ymd.day); /* day (after conversion) */
+ }
+
+ if (bvalid != TRUE) {
+ /* Invalid value if measurement orientation is invalid. */
+ navilocinfo->stNaviGps.heading = GPS_HEADING_INVALID_VAL;
+ // POSITIONING_LOG("RMC Heading[cog] Invalid");
+ }
+ } else {
+ /* Fix status information: Non-position fix is set regardless of FS of GSA. */
+ navilocinfo->stDiagGps.stFix.ucFixSts = NAVIINFO_DIAG_GPS_FIX_STS_NON;
+ /* If the location information is invalid, the time information is also judged to be invalid. */
+ /* Time not calibrated after receiver reset (time entry or master reset or CSF activation) */
+ navilocinfo->stNaviGps.tdsts = POS_TIMESTS_NG;
+ /* Reserve[0] is time setting information: Use time status received from GPS device. */
+ navilocinfo->stNaviGps.reserve[0] = GPS_TIME_RX;
+ navilocinfo->stNaviGps.utc.year = base_ymd.year; /* year (after conversion) */
+ navilocinfo->stNaviGps.utc.month = (u_int8)(base_ymd.month); /* month (after conversion) */
+ navilocinfo->stNaviGps.utc.date = (u_int8)(base_ymd.day); /* day (after conversion) */
+ // POSITIONING_LOG("RMC Invalid[status:%d, bvalidLat:%d, bvalidLon:%d]", _status, bvalid_lat, bvalid_lon);
+ }
+
+ // POSITIONING_LOG("year(Fix) = %d", navilocinfo->stNaviGps.utc.year);
+ // POSITIONING_LOG("month(Fix) = %d", navilocinfo->stNaviGps.utc.month);
+ // POSITIONING_LOG("date(Fix) = %d", navilocinfo->stNaviGps.utc.date);
+ // POSITIONING_LOG("tdsts = %d", navilocinfo->stNaviGps.tdsts);
+ }
+
+ /* Get received NMEA data from storage area(GGA) */
+ b_get = DevGpsCycleDataGetNmea(uc_nmea_data, sizeof(uc_nmea_data), GPS_NMEA_INDEX_GGA);
+
+ if (b_get == TRUE) {
+ /* Data status acquisition */
+ fixsts_gga = (uint8_t)GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GGA_FS, uc_nmea_data);
+
+ /* Altitude information acquisition */
+ if (((fixsts == GPS_NMEA_GSA_FIX_STS_2D) ||
+ (fixsts == GPS_NMEA_GSA_FIX_STS_3D)) &&
+ ((fixsts_gga == GPS_NMEA_GGA_FIX_STATUS_GPS) ||
+ (fixsts_gga == GPS_NMEA_GGA_FIX_STATUS_DGPS) ||
+ (fixsts_gga == GPS_NMEA_GGA_FIX_STATUS_DR))) {
+ navilocinfo->stNaviGps.altitude =
+ GetAltitudeFromNmeaGpsCommon(GPS_NMEA_FNO_GGA_MSL, uc_nmea_data, &bvalid);
+
+ if (bvalid != TRUE) {
+ /* If the location information is invalid, set an invalid value. */
+ navilocinfo->stNaviGps.altitude = GPS_ALTITUDE_INVALID_VAL;
+ // POSITIONING_LOG("GGA Altitude[msl] Invalid");
+ }
+ } else {
+ /* If the location information is invalid, set an invalid value. */
+ navilocinfo->stNaviGps.altitude = GPS_ALTITUDE_INVALID_VAL;
+ // POSITIONING_LOG("GGA Invalid[fixsts:%d, fixstsGGA:%d]", fixsts, fixsts_gga);
+ }
+
+ st_altitude.Altitude = navilocinfo->stNaviGps.altitude;
+ // POSITIONING_LOG("altitude = %d", navilocinfo->stNaviGps.altitude);
+ }
+
+ DevGpsCnvLonLatNavi(&st_lonlat, navilocinfo->stDiagGps.stFix.ucFixSts, navilocinfo->stDiagGps.stFix.stWgs84.lLon,
+ navilocinfo->stDiagGps.stFix.stWgs84.lLat);
+
+ DevGpsCnvAltitudeNavi(&st_altitude, navilocinfo->stDiagGps.stFix.ucFixSts, navilocinfo->stNaviGps.altitude);
+
+ DevGpsCnvHeadingNavi(&st_heading, navilocinfo->stDiagGps.stFix.ucFixSts, navilocinfo->stNaviGps.heading);
+
+ SendCustomGps(&st_gps_time, &st_lonlat, &st_altitude, &st_heading, &navilocinfo->stDiagGps);
+ // For test todo don't needed
+ // SendTimeGps(&st_rtc);
+ // SendSpeedGps(&st_speed, 0);
+
+ /* Create visual satellite information list from GSV1~GSV5 and GSV */
+ for (i = 0; i < 5; i++) {
+ /* Get received NMEA data from storage area */
+ b_get = DevGpsCycleDataGetNmea( uc_nmea_data, sizeof(uc_nmea_data),
+ (ENUM_GPS_NMEA_INDEX)(GPS_NMEA_INDEX_GSV1 + i));
+
+ if (b_get == TRUE) {
+ /* Get number of Satellites in View */
+ no_sv = GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSV_NOSV, uc_nmea_data);
+
+ for (j = 0; j < GPS_NMEA_NUM_GSV_SINFO; j++) {
+ if (__offset >= no_sv) {
+ break;
+ }
+
+ st_visible_satellite_list[__offset].sv = static_cast<uint8_t>(
+ GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSV_SV + (u_int8)(4 * j), uc_nmea_data)); /* Satellite information_No */
+ st_visible_satellite_list[__offset].elv = static_cast<uint8_t>(
+ GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSV_ELV + (u_int8)(4 * j), uc_nmea_data)); /* Satellite information_elevation */
+ st_visible_satellite_list[__offset].az = static_cast<uint16_t>(
+ GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSV_AZ + (u_int8)(4 * j), uc_nmea_data)); /* Satellite Information_Azimuth */
+ st_visible_satellite_list[__offset].cno = static_cast<uint8_t>(
+ GetIntegerFromNmeaGpsCommon(GPS_NMEA_FNO_GSV_CNO + (u_int8)(4 * j), uc_nmea_data)); /* Satellite information_level */
+ st_visible_satellite_list[__offset].sts = DevGpsGetGpsRcvSts(st_visible_satellite_list[__offset].sv);
+
+ /* Sort in ascending order of status (priority to use fix) and received signal strength */
+ for (k = __offset; k > 0; k--) {
+ if (((st_visible_satellite_list[k].sts == NAVIINFO_DIAG_GPS_RCV_STS_USEFIX) &&
+ (st_visible_satellite_list[k - 1].sts == NAVIINFO_DIAG_GPS_RCV_STS_TRACHING)) ||
+ ((st_visible_satellite_list[k - 1].sts == st_visible_satellite_list[k].sts) &&
+ (st_visible_satellite_list[k].cno > st_visible_satellite_list[k - 1].cno))) {
+ (void)memcpy(&st_tmp_buf, &st_visible_satellite_list[k], sizeof(GpsSatelliteInfo));
+ (void)memcpy(&st_visible_satellite_list[k], &st_visible_satellite_list[k - 1], sizeof(GpsSatelliteInfo));
+ (void)memcpy(&st_visible_satellite_list[k - 1], &st_tmp_buf, sizeof(GpsSatelliteInfo));
+ } else {
+ break;
+ }
+ }
+
+ __offset++;
+ }
+ }
+ }
+
+ return;
+}
+
+/****************************************************************************
+@brief DevGpsCycleDataClear<BR>
+ Cyclic data storage area clear processing
+@outline Clear the cyclic data storage area
+@param[in] none
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsCycleDataClear(void) {
+ int32 i = 0;
+
+ /* Sensor counter, reception flag initialization */
+ g_st_gpscycle_data.uc_sns_cnt = 0;
+
+ for (i = 0; i < GPS_NMEA_INDEX_MAX; i++) {
+ g_st_gpscycle_data.st_nmea_data.uc_rcv_flag[i] = GPS_CYCLECMD_NOTRCV;
+ }
+
+ g_st_gpscycle_data.st_binary_data.uc_rcv_flag = GPS_CYCLECMD_NOTRCV;
+ g_st_gpscycle_data.st_fullbin_data.uc_rcv_flag = GPS_CYCLECMD_NOTRCV;
+}
+
+/******************************************************************************
+@brief DEV_Gps_CycleData_SetNmea<BR>
+ NMEA data setting process
+@outline Set NMEA data in cyclic data storage area
+@param[in] u_int8* : p_data ... NMEA data to be set
+@param[in] u_int32 : ul_length ... Data length
+@param[in] ENUM_GPS_NMEA_INDEX: e_format ... Sentence identification
+@param[out] none
+@return none
+@retval none
+*******************************************************************************/
+void DevGpsCycleDataSetNmea(const u_int8* p_data, u_int32 ul_length, ENUM_GPS_NMEA_INDEX e_format) {
+ u_int32 ul_copy_sz = 0;
+
+ /** Anomaly detection */
+ if (e_format >= GPS_NMEA_INDEX_MAX) {
+ POSITIONING_LOG("# GpsCommCtl_API # Set NMEA Sentence ERROR ! \r\n");
+ } else {
+ /** Storage size determination */
+ if (GPS_NMEA_MAX_SZ < ul_length) {
+ ul_copy_sz = GPS_NMEA_MAX_SZ;
+ POSITIONING_LOG("# GpsCommCtl_API # Set NMEA Cmd Size ERROR ! \r\n");
+ } else {
+ ul_copy_sz = ul_length;
+ }
+
+ /** Storing */
+ g_st_gpscycle_data.st_nmea_data.uc_rcv_flag[e_format] = GPS_CYCLECMD_RCV;
+ memset(&(g_st_gpscycle_data.st_nmea_data.st_nmea[e_format].uc_data[0]), 0x00, GPS_NMEA_MAX_SZ);
+ memcpy(&(g_st_gpscycle_data.st_nmea_data.st_nmea[e_format].uc_data[0]), p_data, ul_copy_sz);
+ }
+
+ return;
+}
+
+/******************************************************************************
+@brief DevGpsCycleDataGetNmea<BR>
+ NMEA data setting process
+@outline Set NMEA data in cyclic data storage area
+@param[in] u_int32 : ul_buf_size ... Storage destination buffer size
+@param[in] ENUM_GPS_NMEA_INDEX: e_format ... Sentence identification
+@param[out] u_int8* : p_data ... Storage destination buffer pointer
+@return BOOL
+@retval TRUE : Data present
+@retval FALSE : No data
+*******************************************************************************/
+BOOL DevGpsCycleDataGetNmea(u_int8 *p_data, u_int32 ul_buf_size, ENUM_GPS_NMEA_INDEX e_format) {
+ BOOL ret = TRUE;
+
+ /** Determining whether data exists in the cyclic data area */
+ if (GPS_CYCLECMD_RCV == g_st_gpscycle_data.st_nmea_data.uc_rcv_flag[e_format]) {
+ if (GPS_NMEA_MAX_SZ <= ul_buf_size) {
+ /** Copy to storage destination buffer */
+ memcpy(p_data, &(g_st_gpscycle_data.st_nmea_data.st_nmea[e_format].uc_data[0]), GPS_NMEA_MAX_SZ);
+ } else {
+ /** Storage destination buffer size is small */
+ ret = FALSE;
+ }
+ } else {
+ /** Not received */
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief
+ * Setting of the check sum
+ *
+ * @param[in] buffer Pointer of data
+ * @param[in] length length of data
+ */
+void DevGpsSetChkSum(u_int8* buffer, u_int32 length) {
+ u_int16 i = 0;
+ u_int8 ck_a = 0;
+ u_int8 ck_b = 0;
+
+ if (buffer != NULL) {
+ for (i = 2; i < (length - 2); i++) {
+ ck_a = ck_a + buffer[i];
+ ck_b = ck_b + ck_a;
+ }
+
+ /* Checksum_Set */
+ buffer[length - 2] = ck_a;
+ buffer[length - 1] = ck_b;
+ } else {
+ }
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/GpsCommon/MDev_Gps_TimerCtrl.cpp b/hal/positioning_hal/src/GpsCommon/MDev_Gps_TimerCtrl.cpp
new file mode 100755
index 0000000..8dbf8dc
--- /dev/null
+++ b/hal/positioning_hal/src/GpsCommon/MDev_Gps_TimerCtrl.cpp
@@ -0,0 +1,293 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file MDev_Gps_TimerCtrl.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "MDev_Gps_TimerCtrl.h"
+
+// #include "MDev_Gps_Main.h"
+// #include "MDev_GpsRecv.h"
+
+/*---------------------------------------------------------------------------*/
+// Global values
+
+static GPS_TIM_MNG g_st_tim_mng;
+
+/** Timer setting information table */
+static const GPS_TIM_INFO kTimInfo[TIM_NUM] = {
+ /* GSP related */
+ {TIMVAL_GPS_STARTUP, PNO_NAVI_GPS_MAIN}, /* Start confirmation monitoring timer */
+ {TIMVAL_GPS_RCVCYCLDAT, PNO_NAVI_GPS_MAIN}, /* Periodic reception data monitoring timer */
+ {TIMVAL_GPS_RCVACK, PNO_NAVI_GPS_MAIN}, /* ACK reception monitoring timer */
+ {TIMVAL_GPS_NAVIFST, PNO_NAVI_GPS_MAIN}, /* Initial Navigation Monitoring Timer */
+ {TIMVAL_GPS_NAVICYCLE, PNO_NAVI_GPS_MAIN}, /* Navi monitoring timer */
+ {TIMVAL_GPS_NAVIDISRPT, PNO_NAVI_GPS_MAIN}, /* Navigation Monitoring Disruption Log Output Timer */
+ {TIMVAL_GPS_DIAGCLKGUARD, PNO_NAVI_GPS_MAIN}, /* Diagnosis provision time guard monitoring timer */
+ {TIMVAL_GPS_NMEADATAGUARD, PNO_NAVI_GPS_MAIN}, /* NMEA data providing guard monitoring timer */
+ {TIMVAL_GPS_RECOVERY, PNO_NAVI_GPS_MAIN}, /* GPS recovery timer */
+ {TIMVAL_GPS_RECEIVERERR, PNO_NAVI_GPS_MAIN}, /* GPS receiver anomaly detection timer */
+ /* Sensor related */
+ {TIMVAL_SNS_RCVFSTDAT, PNO_VEHICLE_SENSOR}, /* Initial cyclic sensor data reception monitoring timer */
+ {TIMVAL_SNS_RCVCYCLDAT, PNO_VEHICLE_SENSOR}, /* Cyclic sensor data reception monitoring timer */
+ {TIMVAL_SNS_RCVDISRPT, PNO_VEHICLE_SENSOR}, /* Cyclic sensor data interruption log output timer */
+};
+
+/*---------------------------------------------------------------------------*/
+// Functions
+
+static uint16_t TimeMakSeqNo(GPS_TIM_KIND tim_kind) {
+ GPS_TIM_MNG* pst_tim_mng = NULL;
+ u_int16 seq_no = 0; /* Timer sequence number */
+
+ pst_tim_mng = &g_st_tim_mng;
+
+ /*------------------------------------------------------------------------*/
+ /* Definition of Sequence Number */
+ /* |------------------- Sequence number(2Byte) -----------------------| */
+ /* 15 8 7 0 */
+ /* +-------------------------------+-----------------------------------+ */
+ /* | Timer type(1Byte) | Counter(1Byte)(0x01 ? 0xFF) | */
+ /* +-------------------------------+-----------------------------------+ */
+ /* The timer type is 0x00. ? (Number of timers-1) */
+ /* counters is 0x01 ? 0xFF(Do not use 0x00) */
+ /* (Counters are counted up each time a timer is started. */
+ /* If the counter counts up when it is 0xFF, */
+ /* be counted up from the 0x01.) */
+ /*------------------------------------------------------------------------*/
+ seq_no = ((u_int16)tim_kind << 8) | (pst_tim_mng->sts[tim_kind].cnt);
+
+ return seq_no;
+}
+
+static BOOL VehicleUtilitySetTimer(GPS_TIM_KIND tim_kind) {
+ GPS_TIM_MNG* pst_tim_mng = NULL;
+ const uint32_t * p_time_val;
+ const PNO* p_pno;
+ RET_API api_ret = RET_NORMAL;
+ u_int16 seq_no = 0;
+ BOOL ret = TRUE;
+
+ // Initialize
+ pst_tim_mng = &g_st_tim_mng;
+ p_time_val = &(kTimInfo[tim_kind].timer_val); /* Timer set value */
+ p_pno = &(kTimInfo[tim_kind].pno); /* Notify party PNO */
+
+ if (pst_tim_mng->sts[tim_kind].flag == TIMER_ON) {
+ /*-----------------------------------------------------------------------*/
+ /* When the same timer has already started, */
+ /* terminate without starting the timer because the timer is set multiple times. */
+ /*-----------------------------------------------------------------------*/
+ ret = FALSE;
+ } else {
+ /*-----------------------------------------------------------------------*/
+ /* Count up the timer counter of the corresponding timer by 1. */
+ /*-----------------------------------------------------------------------*/
+ if (pst_tim_mng->sts[tim_kind].cnt >= TIM_CNTMAX) {
+ /*-----------------------------------------------------------------------*/
+ /* When the count reaches the maximum number, it counts again from 1. */
+ /*-----------------------------------------------------------------------*/
+ pst_tim_mng->sts[tim_kind].cnt = TIM_CNTMIN;
+ } else {
+ /*-----------------------------------------------------------------------*/
+ /* If the count has not reached the maximum, it is counted up. */
+ /*-----------------------------------------------------------------------*/
+ pst_tim_mng->sts[tim_kind].cnt++;
+ }
+
+ /*-----------------------------------------------------------------------*/
+ /* Creating timer sequence numbers */
+ /*-----------------------------------------------------------------------*/
+ seq_no = TimeMakSeqNo(tim_kind);
+
+ /*-----------------------------------------------------------------------*/
+ /* Start the timer */
+ /*-----------------------------------------------------------------------*/
+ api_ret = _pb_ReqTimerStart(*p_pno, seq_no, TIMER_TYPE_USN, static_cast<u_int32>(*p_time_val));
+ if (api_ret != RET_NORMAL) {
+ ret = FALSE;
+ } else {
+ /*-----------------------------------------------------------------------*/
+ /* If successful timer start, */
+ /* set the start/stop flag of the corresponding timer to start (MCSUB_ON). */
+ /*-----------------------------------------------------------------------*/
+ pst_tim_mng->sts[tim_kind].flag = TIMER_ON;
+ }
+ }
+
+ return ret;
+}
+
+static BOOL VehicleUtilityStopTimer(GPS_TIM_KIND tim_kind) {
+ GPS_TIM_MNG* pst_tim_mng = NULL;
+ const PNO* p_pno;
+ BOOL ret = TRUE;
+ RET_API api_ret = RET_NORMAL;
+ u_int16 seq_no = 0;
+
+ // Initialize
+ pst_tim_mng = &g_st_tim_mng;
+ p_pno = &(kTimInfo[tim_kind].pno); /* Notify party PNO */
+
+ /* Check timer start/stop flag */
+ if (pst_tim_mng->sts[tim_kind].flag == TIMER_OFF) {
+ /* If it is already stopped, do nothing. */
+ ret = FALSE;
+ } else {
+ /*-----------------------------------------------------------------------*/
+ /* Creating timer sequence numbers */
+ /*-----------------------------------------------------------------------*/
+ seq_no = TimeMakSeqNo(tim_kind);
+
+ /*-----------------------------------------------------------------------*/
+ /* Set the corresponding timer to stop */
+ /*-----------------------------------------------------------------------*/
+ api_ret = _pb_TimerStop(*p_pno, seq_no, TIMER_TYPE_USN);
+
+ if (api_ret != RET_NORMAL) {
+ ret = FALSE;
+ }
+
+ /*-----------------------------------------------------------------------*/
+ /* Set the start/stop flag of the corresponding timer to stop (MCSUB_OFF) */
+ /* Set the ID of the corresponding timer to invalid (DEV_TED_INVALID) */
+ /*-----------------------------------------------------------------------*/
+ pst_tim_mng->sts[tim_kind].flag = TIMER_OFF;
+ }
+
+ return ret;
+}
+
+static BOOL VehicleUtilityTimeJdgKnd(uint16_t seqno) {
+ GPS_TIM_MNG* pst_tim_mng = NULL;
+ BOOL ret = FALSE;
+ u_int8 timekind = 0;
+ u_int8 count = 0;
+
+ // Initialize
+ pst_tim_mng = &g_st_tim_mng;
+
+ timekind = (u_int8)((seqno & 0xff00) >> 8);
+ count = (u_int8)(seqno & 0x00ff);
+
+ /* Timer type is unexpected */
+ if (timekind >= TIM_NUM) {
+ ret = FALSE;
+ } else {
+ if ((pst_tim_mng->sts[timekind].cnt == count) && (pst_tim_mng->sts[timekind].flag == TIMER_ON)) {
+ /* The counter matches and the counter start/stop flag is "Start". */
+ ret = TRUE;
+ } else {
+ /* Not applicable due to differences */
+ ret = FALSE;
+ }
+ }
+
+ return ret;
+}
+
+/*******************************************************************************
+ * MODULE : DEV_Gps_Tim_Init
+ * ABSTRACT : Timer function initialization processing
+ * FUNCTION : Initialize the timer function
+ * ARGUMENT : None
+ * NOTE : 1.Initialize timer management table
+ * RETURN : None
+ ******************************************************************************/
+void DevGpsTimInit(void) {
+ GPS_TIM_MNG* pst_tim_mng = NULL;
+ u_int32 i = 0;
+
+ // Initialie
+ pst_tim_mng = &g_st_tim_mng;
+
+ /* Initialize timer management table */
+ memset(pst_tim_mng, 0x00, sizeof(GPS_TIM_MNG));
+
+ for (i = 0; i < TIM_NUM; i++) {
+ pst_tim_mng->sts[i].flag = TIMER_OFF;
+ pst_tim_mng->sts[i].cnt = 0;
+ }
+
+ return;
+}
+
+/*******************************************************************************
+ * MODULE : DevGpsTimeSet
+ * ABSTRACT : Timer start processing
+ * FUNCTION : Starts a timer of the specified type
+ * ARGUMENT : GPS_TIM_KIND tim_kind Timer type
+ * NOTE : 1.Increment total number of timer start
+ * 2.Timer Sequence Number Creation
+ * 3.Get timeout value
+ * 4.Timer start
+ * RETURN : TRUE : Normal completion
+ * : FALSE : ABENDs
+ ******************************************************************************/
+BOOL DevGpsTimeSet(GPS_TIM_KIND tim_kind) {
+ BOOL ret = TRUE;
+
+ /* Binding of unused timer */
+ if ((tim_kind != GPS_RECV_ACK_TIMER)
+ && (tim_kind != GPS_STARTUP_TIMER)
+ && (tim_kind != GPS_CYCL_TIMER)
+ && (tim_kind != GPS_NAVIFST_TIMER)
+ && (tim_kind != GPS_NAVICYCLE_TIMER)
+ && (tim_kind != GPS_NAVIDISRPT_TIMER)
+ && (tim_kind != GPS_RECOVERY_TIMER)
+ && (tim_kind != GPS_RECEIVERERR_TIMER)) {
+ return ret;
+ }
+ ret = VehicleUtilitySetTimer(tim_kind);
+ return ret;
+}
+
+/*******************************************************************************
+ * MODULE : DevGpsTimeStop
+ * ABSTRACT : Timer stop processing
+ * FUNCTION : Stops a timer of the specified type
+ * ARGUMENT : GPS_TIM_KIND tim_kind Timer type
+ * NOTE : 1.Get the sequence number of the specified type
+ * 2.Timer stop
+ * RETURN : TRUE : Normal completion
+ * : FALSE : ABENDs
+ ******************************************************************************/
+BOOL DevGpsTimeStop(GPS_TIM_KIND tim_kind) {
+ BOOL ret = TRUE;
+ ret = VehicleUtilityStopTimer(tim_kind);
+ return ret;
+}
+
+/********************************************************************************
+ * MODULE : DevGpsTimeJdgKind
+ * ABSTRACT : Timer Sequence Number Determination
+ * FUNCTION : Determine whether the timer sequence number corresponds to the one being managed
+ * ARGUMENT : Timer Sequence Number
+ * NOTE :
+ * RETURN : TRUE : Normal completion(No problem)
+ * : FALSE : ABENDs(Unusual number)
+ ********************************************************************************/
+BOOL DevGpsTimeJdgKind(u_int16 seqno) {
+ BOOL ret;
+ ret = VehicleUtilityTimeJdgKnd(seqno);
+ return ret;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Api.cpp b/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Api.cpp
new file mode 100755
index 0000000..d363a4b
--- /dev/null
+++ b/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Api.cpp
@@ -0,0 +1,136 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file LineSensDrv_Api.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "LineSensDrv_Api.h"
+#include "positioning_def.h"
+
+/*---------------------------------------------------------------------------*/
+// Macro definitions
+
+#define LSDRV_GPS_DATA_TOP_TH 5 // Threshold for determining the beginning of GPS data
+#define LSDRV_SENS_DATA_RCV_WAIT_TIME 400 // Sensor data wait time of GPS reception flag ON(Total)
+#define LSDRV_SENS_DATA_RCV_WAIT_TERM 50 // Sensor data wait time of GPS reception flag ON(1 time)
+
+#define LSDRV_EST_GPS_CNT_ARRAY_NUM 3U // Number of arrays for holding estimated GPS counter
+#define LSDRV_EST_GPS_CNT_ENABLE_TH 5U // Estimated GPS counter enable/disable determination threshold
+#define LSDRV_EST_GPS_CNT_ADD_VALUE 10U // Estimated GPS counter update addition value
+
+// GPS data reception cycle:1sec sensor counters: 100ms
+
+// for debug
+#define LINE_SENS_DRV_API_DEBUG_SWITCH 0 // 0:OFF 1:ON
+
+/*---------------------------------------------------------------------------*/
+// Global variable
+
+static HANDLE g_gps_irq_mutex = NULL; // GPS received flag Mutex handles
+static BOOL g_rcv_pps_int = FALSE; // PPS interrupt reception flag (GPS->_CWORD102_)
+static BOOL g_rcv_gps_irq = FALSE; // GPS reception flag (GPS->_CWORD56_)
+static u_int8 g_rcv_gps_sens_cnt_tmp = 0; // Sensor counter when GPS reception flag is ON(for retention)
+static u_int8 g_rcv_gps_sens_cnt = 0; // Sensor counter when GPS reception flag is ON
+static u_int8 g_gps_sens_cnt_top = 0; // Sensor counter when first GPS data is received
+static u_int8 g_est_gps_cnt[LSDRV_EST_GPS_CNT_ARRAY_NUM]; // Array for storing estimated GPS counter values
+static BOOL g_est_gps_cnt_available = FALSE; // Estimated GPS counter value enable/disable judgment
+
+typedef struct VehicleSensDataMaster {
+ DID ul_did; // Data ID
+ u_int16 us_size; // Size of the data
+ u_int8 uc_rcv_flag; // Receive flag
+ u_int8 uc_sns_cnt; // Sensor counter
+ u_int8 uc_data[132]; // Vehicle sensor data
+} VEHICLESENS_DATA_MASTER;
+
+
+/*******************************************************************************
+ * MODULE : DeliveryLineSensorDataPositioning
+ * ABSTRACT : LineSensor vehicle signaling notification messages sending process
+ * FUNCTION : Send LineSensor vehicle signalling notification messages
+ * ARGUMENT : *pstSendBuf:Transmitted data
+ * : uc_data_num :Number of sent data
+ * NOTE :
+ * RETURN : None
+ ******************************************************************************/
+void DeliveryLineSensorDataPositioning(LSDRV_MSG_LSDATA_G* pst_send_buf, u_int8 uc_data_num) {
+ if (pst_send_buf != NULL) {
+ /* Initializing sent messages */
+ memset(reinterpret_cast<void *>(&(pst_send_buf->st_head)), 0, sizeof(T_APIMSG_MSGBUF_HEADER));
+
+ /* Message Header Settings */
+ pst_send_buf->st_head.hdr.sndpno = PNO_LINE_SENS_DRV; /* Source process number */
+ pst_send_buf->st_head.hdr.cid = CID_LINESENS_VEHICLE_DATA_G; /* Command ID */
+ pst_send_buf->st_head.hdr.msgbodysize = sizeof(LSDRV_MSG_LSDATA_DAT_G); /* Message data body length */
+
+ /* Message data is already set */
+ pst_send_buf->st_para.uc_data_num = uc_data_num;
+
+ /* Send messages */
+ (void)_pb_ZcSndMsg(PNO_VEHICLE_SENSOR, sizeof( LSDRV_MSG_LSDATA_G ), 0);
+ }
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrvApi_Initialize
+ * ABSTRACT : LineSensDrvApi initialization process
+ * FUNCTION : LineSensDrvApi initialization process
+ * ARGUMENT : -
+ * NOTE :
+ * RETURN : -
+ ******************************************************************************/
+BOOL LineSensDrvApiInitialize(void) {
+ BOOL ret = TRUE;
+
+ g_gps_irq_mutex = _pb_CreateMutex(NULL, FALSE, MUTEX_GPS_IRQ_FLG);
+
+ if (g_gps_irq_mutex == 0) {
+ ret = FALSE;
+ } else {
+ g_rcv_gps_irq = FALSE;
+ g_rcv_gps_sens_cnt_tmp = 0;
+ LineSensDrvApiInitEstGpsCnt();
+ ret = TRUE;
+ }
+
+ return (ret);
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrvApi_InitEstGpsCnt
+ * ABSTRACT : Estimated GPS counter related parameter initialization processing
+ * FUNCTION : Estimated GPS counter related parameter initialization processing
+ * ARGUMENT : -
+ * NOTE :
+ * RETURN : -
+ ******************************************************************************/
+void LineSensDrvApiInitEstGpsCnt(void) {
+ /* Initializing process */
+ g_rcv_pps_int = FALSE;
+ g_rcv_gps_sens_cnt = 0;
+ g_gps_sens_cnt_top = 0;
+
+ (void)memset(reinterpret_cast<void *>(&g_est_gps_cnt[0]), 0, sizeof(g_est_gps_cnt));
+ g_est_gps_cnt_available = FALSE;
+
+ return;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Sensor.cpp b/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Sensor.cpp
new file mode 100755
index 0000000..78ae488
--- /dev/null
+++ b/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Sensor.cpp
@@ -0,0 +1,622 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file LineSensDrv_Snesor.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "LineSensDrv_Sensor.h"
+#include "LineSensDrv_Api.h"
+
+/*---------------------------------------------------------------------------*/
+// Value Define
+
+#define LSDRV_MASK_WORD_L 0x00FF
+#define LSDRV_MASK_WORD_U 0xFF00
+
+#define LINE_SENS_DRV_SENSOR_DEBUG_FACTORY 0
+#define LINE_SENS_DRV_SENSOR_DEBUG_DIAG 0
+
+#define VEHICLE_SNS_INFO_PULSE_NUM 32
+
+/*---------------------------------------------------------------------------*/
+// Global variable
+
+static LSDRV_SPEEDKMPH_DAT g_speed_kmph_data;
+static uint8_t g_rcv_data_len; /* Receive SYS data length */
+extern uint8_t g_uc_vehicle_reverse;
+/*---------------------------------------------------------------------------*/
+// Functions
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_Sensor
+ * ABSTRACT : Sensor data reception processing
+ * FUNCTION : Convert sensor data to delivery format
+ * ARGUMENT : *ucRcvdata : Data pointer
+ * NOTE :
+ * RETURN : None
+ ******************************************************************************/
+void LineSensDrvSensor(u_int8* uc_rcvdata) {
+ u_int8 uc_sens_cnt = 0;
+ u_int16 us_sp_kmph = 0; /* Vehicle speed(km/h) */
+ u_int16 us_sp_pls1 = 0; /* Total vehicle speed pulse(Latest) */
+ u_int16 us_sp_pls2 = 0; /* Total vehicle speed pulse(Last time) */
+ u_int8 us_sp_ret = 0; /* Last vehicle speed information acquisition result */
+ u_int8 uc_size = 0; /* Size of the data */
+ u_int16 us_cnt = 0; /* Data counter */
+ u_int16 us_cnt2 = 0; /* Data counter */
+ u_int8* uc_data_pos = NULL; /* Data storage location */
+ LSDRV_MSG_LSDATA_G* p_snd_buf = NULL;
+ LSDRV_LSDATA_G* p_snd_data_base = NULL;
+ LSDRV_LSDATA_G* p_snd_data = NULL;
+ RET_API ret = RET_NORMAL;
+
+ /* Receive sensor data top address acquisition */
+ uc_data_pos = (uc_rcvdata);
+
+ /* Create send buffer/delivery all received data */
+ ret = _pb_GetZcSndBuf(PNO_VEHICLE_SENSOR, reinterpret_cast<void**>(&p_snd_buf));
+ if ((ret == RET_NORMAL) && (p_snd_buf != NULL)) {
+ p_snd_data_base = p_snd_buf->st_para.st_data;
+ (void)memset(p_snd_data_base, 0, LSDRV_KINDS_MAX * sizeof( LSDRV_LSDATA_G ));
+
+ /* Sensor counter */
+ p_snd_data = p_snd_data_base + LSDRV_SNS_COUNTER;
+ uc_sens_cnt = (u_int8)*(uc_data_pos);
+ p_snd_data->ul_did = VEHICLE_DID_SNS_COUNTER; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_1; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ p_snd_data->uc_data[0] = uc_sens_cnt; /* Data content */
+ uc_data_pos = (uc_data_pos + LSDRV_SNDMSG_DTSIZE_1);
+
+ /* Gyro output */
+ p_snd_data = p_snd_data_base + LSDRV_GYRO_EXT;
+ p_snd_data->ul_did = VEHICLE_DID_GYRO_EXT; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_20; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ for (us_cnt = 0; us_cnt < LSDRV_SNDMSG_DTSIZE_20; us_cnt++) {
+ /* Since [0] is older and [9] is newer, the order of received data is switched. */
+ /* Be in reverse order for endian conversion */
+ p_snd_data->uc_data[LSDRV_SNDMSG_DTSIZE_20 - (us_cnt + 1)] = (u_int8)*(uc_data_pos + us_cnt);
+ }
+ uc_data_pos = (uc_data_pos + LSDRV_SNDMSG_DTSIZE_20);
+
+ p_snd_data = p_snd_data_base + LSDRV_GYRO_X;
+ p_snd_data->ul_did = VEHICLE_DID_GYRO; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_20; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ for (us_cnt = 0; us_cnt < LSDRV_SNDMSG_DTSIZE_20; us_cnt++) {
+ /* Since [0] is older and [9] is newer, the order of received data is switched. */
+ /* Be in reverse order for endian conversion */
+ p_snd_data->uc_data[LSDRV_SNDMSG_DTSIZE_20 - (us_cnt + 1)] = (u_int8)*(uc_data_pos + us_cnt);
+ }
+ uc_data_pos = (uc_data_pos + LSDRV_SNDMSG_DTSIZE_20);
+
+ /* Reverse flag */
+ p_snd_data = p_snd_data_base + LSDRV_REV;
+ p_snd_data->ul_did = VEHICLE_DID_REV; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_1; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor Counter */
+ p_snd_data->uc_data[0] = g_uc_vehicle_reverse;
+ /* Gyro Temperature */
+ p_snd_data = p_snd_data_base + LSDRV_GYRO_TEMP;
+ p_snd_data->ul_did = VEHICLE_DID_GYRO_TEMP; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_2; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ p_snd_data->uc_data[1] = (u_int8)(*(uc_data_pos ) & (u_int8)(LSDRV_TEMP_MASK >> 8));
+ p_snd_data->uc_data[0] = (u_int8)(*(uc_data_pos + 1) & (u_int8)(LSDRV_TEMP_MASK));
+ uc_data_pos = (uc_data_pos + LSDRV_SNDMSG_DTSIZE_2);
+
+ /* Vehicle speed pulse */
+ p_snd_data = p_snd_data_base + LSDRV_SPEED_PULSE;
+ p_snd_data->ul_did = VEHICLE_DID_SPEED_PULSE; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_20; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ for (us_cnt = 0; us_cnt < LSDRV_SNDMSG_DTSIZE_20; us_cnt++) {
+ /* Since [0] is older and [9] is newer, the order of received data is switched. */
+ /* Be in reverse order for endian conversion */
+ p_snd_data->uc_data[LSDRV_SNDMSG_DTSIZE_20 - (us_cnt + 1)] = (u_int8)*(uc_data_pos + us_cnt);
+ }
+ uc_data_pos = (uc_data_pos + LSDRV_SNDMSG_DTSIZE_20);
+
+ /* Vehicle speed(km/h) */
+ p_snd_data = p_snd_data_base + LSDRV_SPEED_PULSE;
+ us_sp_kmph = 0;
+ us_sp_pls1 = (u_int16)p_snd_data->uc_data[1];
+ us_sp_pls1 = (u_int16)((us_sp_pls1 << 8) | p_snd_data->uc_data[0]);
+ us_sp_ret = LineSensDrvGetLastSpeedPulse(&us_sp_pls2, us_sp_pls1, uc_sens_cnt);
+
+ LineSensDrvSetLastSpeedPulse(us_sp_pls1, uc_sens_cnt);
+
+ p_snd_data = p_snd_data_base + LSDRV_SPEED_KMPH;
+ if (us_sp_ret != LSDRV_SPKMPH_INVALID) {
+ /* Vehicle speed pulse before 100 ms is valid */
+ LineSensDrvSpeedPulseSave(us_sp_pls1, us_sp_pls2, uc_sens_cnt);
+ us_sp_kmph = LineSensDrvSpeedCalc(uc_sens_cnt);
+ /* The size can be set only when the vehicle speed [km/h] is calculated. "0" is notified to the vehicle sensor when the size cannot be set. */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_2; /* Size of the data */
+ }
+ p_snd_data->ul_did = VEHICLE_DID_SPEED_KMPH; /* Data ID */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ p_snd_data->uc_data[0] = (u_int8)(us_sp_kmph & 0x00FF);
+ p_snd_data->uc_data[1] = (u_int8)(us_sp_kmph >> 8);
+
+ POSITIONING_LOG("[LOG, %d(cnt), %d(km/h), %d(pls1), %d(pls2)] \r\n",
+ uc_sens_cnt,
+ us_sp_kmph,
+ us_sp_pls1,
+ us_sp_pls2);
+
+ /* G-Sensor X-axes */
+ p_snd_data = p_snd_data_base + LSDRV_GSENSOR_X;
+ p_snd_data->ul_did = VEHICLE_DID_GSNS_X; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_20; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ us_cnt2 = p_snd_data->uc_size - 1;
+ for (us_cnt = 0; us_cnt < 10; us_cnt++) {
+ /* Since [0] is older and [9] is newer, the order of received data is switched. */
+ p_snd_data->uc_data[us_cnt2 ] = (u_int8)*( uc_data_pos + (sizeof(SENSORINPUT_INFO_DAT_GSENS) * us_cnt) );
+ p_snd_data->uc_data[us_cnt2 - 1] = (u_int8)*( uc_data_pos + (sizeof(SENSORINPUT_INFO_DAT_GSENS) * us_cnt) + 1);
+ us_cnt2 = us_cnt2 - 2;
+ }
+
+ /* G-Sensor Y-axes */
+ p_snd_data = p_snd_data_base + LSDRV_GSENSOR_Y;
+ p_snd_data->ul_did = VEHICLE_DID_GSNS_Y; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_20; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+ us_cnt2 = p_snd_data->uc_size - 1;
+ for (us_cnt = 0; us_cnt < 10; us_cnt++) {
+ /* Since [0] is older and [9] is newer, the order of received data is switched. */
+ p_snd_data->uc_data[us_cnt2] = (u_int8)*( (uc_data_pos + sizeof(u_int16)) \
+ + (sizeof(SENSORINPUT_INFO_DAT_GSENS) * us_cnt));
+
+ p_snd_data->uc_data[us_cnt2-1] = (u_int8)*( (uc_data_pos + sizeof(u_int16)) \
+ + (sizeof(SENSORINPUT_INFO_DAT_GSENS) * us_cnt) + 1);
+ us_cnt2 = us_cnt2 - 2;
+ }
+ uc_data_pos = ( uc_data_pos + (sizeof(SENSORINPUT_INFO_DAT_GSENS) * 10) );
+
+ /* Inter-Pulse time */
+ p_snd_data = p_snd_data_base + LSDRV_PULSE_TIME;
+ p_snd_data->ul_did = VEHICLE_DID_PULSE_TIME; /* Data ID */
+ p_snd_data->uc_size = LSDRV_SNDMSG_DTSIZE_132; /* Size of the data */
+ p_snd_data->uc_sns_cnt = uc_sens_cnt; /* Sensor counter */
+
+ /* Clear the buffer for variable length */
+ (void)memset(&p_snd_data->uc_data[0], 0x00, sizeof(p_snd_data->uc_data));
+
+ if (g_rcv_data_len == LSDRV_PLSTIME_LEN) {
+ /* Inter-Pulse time (number of items + time). The number of items is stored at the beginning. */
+ uc_size = (u_int8)*uc_data_pos;
+ if (uc_size > VEHICLE_SNS_INFO_PULSE_NUM) {
+ uc_size = VEHICLE_SNS_INFO_PULSE_NUM;
+ }
+ p_snd_data->uc_data[0] = uc_size;
+ p_snd_data->uc_data[1] = 0x00;
+ p_snd_data->uc_data[2] = 0x00;
+ p_snd_data->uc_data[3] = 0x00;
+ uc_data_pos = ( uc_data_pos + sizeof(u_int8) );
+
+ /* Since [0] is old and [31] is new in the received time, the order is changed. */
+ /* Be in reverse order for endian conversion */
+ for (us_cnt = 0; us_cnt < (uc_size * sizeof(u_int32)); us_cnt++) {
+ p_snd_data->uc_data[(uc_size * sizeof(u_int32)) - (us_cnt + 1) + 4] = (u_int8)*(uc_data_pos + us_cnt);
+ }
+ }
+
+ /* Messaging */
+ DeliveryLineSensorDataPositioning(p_snd_buf, LSDRV_KINDS_MAX);
+ }
+
+ return;
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_SpeedCalc
+ * ABSTRACT : Vehicle speed calculation processing for sensor data
+ * FUNCTION : Calculate vehicle speed for sensor data
+ * ARGUMENT : uc_sens_cnt : Sensor counter
+ * NOTE :
+ * RETURN : Vehicle speed(0.01km/h)
+ ******************************************************************************/
+u_int16 LineSensDrvSpeedCalc(u_int8 uc_sens_cnt) {
+ u_int32 ul_sp_caluc = 0; /* Vehicle speed(2^-8km/h) */
+ u_int16 us_speed = 0; /* Vehicle speed(km/h) */
+ u_int8 uc_ptr = 0; /* Data storage pointer for sensor data */ /* #010 */
+ u_int8 uc_ptr2 = 0; /* Data storage pointer for sensor data */ /* #010 */
+ u_int32 ul_work = 0; /* Variables for unsigned 32-bit type calculations */ /* #010 */
+ double d_work = 0.0; /* Variables for calculating double types */ /* #010 */ /* Ignore -> MISRA-C++:2008 Rule 3-9-2 */
+ u_int16 us_sens_cnt_search = 0; /* Sensor counter to be searched */ /* #010 */
+ u_int16 us_sens_cnt_ref = 0; /* Sensor counters to be compared */ /* #010 */
+ int32 i = 0; /* Generic counters */ /* #010 */
+ int32 j = 0; /* Generic counters */ /* #010 */
+ u_int16 us_offset = 0; /* Offset value */ /* #010 */
+
+ /* #016 start */
+ /* Is the number of data that can be calculated at the vehicle speed already received? */
+ if (LSDRV_PLSDATA_NRCV == g_speed_kmph_data.uc_calc_start) {
+ /* Do not compute if there is not enough data. */
+ } else {
+ if (0 == g_speed_kmph_data.uc_ptr) {
+ uc_ptr = LSDRV_SPKMPH_TBL_NUM - 1;
+ uc_ptr2 = LSDRV_SPKMPH_TBL_NUM - 1;
+ } else {
+ uc_ptr = g_speed_kmph_data.uc_ptr - 1; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ uc_ptr2 = g_speed_kmph_data.uc_ptr - 1; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ }
+
+ ul_work = 0;
+ if (LSDRV_SPKMPH_AVE_TIME > uc_sens_cnt) {
+ us_offset = LSDRV_SENSCNT_BRW_ADD;
+ } else {
+ us_offset = 0;
+ }
+
+ us_sens_cnt_search = (u_int16)uc_sens_cnt + us_offset - LSDRV_SPKMPH_AVE_TIME;
+
+ for (i = 0; i < LSDRV_SPKMPH_TBL_NUM; i++) {
+ /* Invalid data is detected, and the search is completed. */
+ if (LSDRV_SPKMPH_DATA_DIS == g_speed_kmph_data.st_data[uc_ptr].uc_flag) {
+ break;
+ }
+
+ /* When the sensor counter is 29 or less, the borrow is considered. */
+ if (LSDRV_SPKMPH_AVE_TIME > g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt) {
+ us_sens_cnt_ref = g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt + us_offset;
+ } else {
+ us_sens_cnt_ref = g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt;
+ }
+
+ /* Checking the sensor counter to finish search */
+ if (us_sens_cnt_search >= us_sens_cnt_ref) {
+ break;
+ }
+
+ /* Add to calculate average value */
+ ul_work += (u_int32)g_speed_kmph_data.st_data[uc_ptr].us_speed_pulse;
+
+ if (0 == uc_ptr) {
+ uc_ptr = LSDRV_SPKMPH_TBL_NUM - 1; /* To the end of the data table */
+ } else {
+ uc_ptr--; /* To the previous data */
+ }
+ }
+
+ /* Averaging computation */
+ if (0 == i) {
+ d_work = 0;
+ } else {
+ if (ul_work == 1) {
+ for (j = 0; j < LSDRV_SPKMPH_TBL_NUM; j++) {
+ if ((g_speed_kmph_data.st_data[uc_ptr2].us_speed_pulse == 1)
+ && (g_speed_kmph_data.st_data[uc_ptr2].uc_noise_flag == 1)) {
+ ul_work = 0;
+ break;
+ } else if (g_speed_kmph_data.st_data[uc_ptr2].us_speed_pulse == 1 &&
+ g_speed_kmph_data.st_data[uc_ptr2].uc_noise_flag == 0) {
+ ul_work = 1;
+ break;
+ } else {
+ /* nop */
+ }
+
+ /* Borrow actions for pointer values */
+ if (0 == uc_ptr2) {
+ uc_ptr2 = LSDRV_SPKMPH_TBL_NUM - 1; /* To the end of the data table */
+ } else {
+ uc_ptr2--; /* To the previous data */
+ }
+ }
+ }
+
+ d_work = static_cast<double>(ul_work);
+ d_work = d_work / static_cast<double>(i);
+ d_work = d_work * static_cast<double>(LSDRV_SENS_COEFFICIENT);
+ d_work = d_work * 100; /* [1km/h] -> [0.01km/h] */
+ d_work = d_work + 0.5; /* Preparation for rounding */
+ }
+
+ ul_sp_caluc = static_cast<int32>(d_work);
+
+ /* When the vehicle speed calculation result overflows, the upper limit value is used for clipping. */
+ if (LSDRV_PLSMAX - 1 >= ul_sp_caluc) {
+ us_speed = (u_int16)ul_sp_caluc;
+ } else {
+ us_speed = (u_int16)(LSDRV_PLSMAX - 1);
+ }
+ }
+
+ return us_speed;
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_SpeedKmphDataInit
+ * ABSTRACT : Data table initialization process for vehicle speed calculation
+ * FUNCTION : Initialize the data table for calculating the vehicle speed
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : None
+ ******************************************************************************/
+void LineSensDrvSpeedKmphDataInit(void) {
+ int32 i = 0;
+
+ memset(reinterpret_cast<void*>(&g_speed_kmph_data), static_cast<int32>(0), (size_t)sizeof(g_speed_kmph_data));
+
+ /* Disable all data storage flags */
+ for (i = 0; i < LSDRV_SPKMPH_TBL_NUM; i++) {
+ g_speed_kmph_data.st_data[i].uc_flag = LSDRV_SPKMPH_DATA_DIS;
+ }
+
+ return;
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_SpeedPulseSave
+ * ABSTRACT : Sensor data vehicle speed pulse save processing
+ * FUNCTION : Saving the vehicle speed pulse of the sensor data to the data table for calculating the vehicle speed
+ * ARGUMENT : us_sp1 : Vehicle speed pulse of the latest information
+ * : us_sp2 : Vehicle speed pulse of the previous information
+ * : uc_sens_cnt : Sensor counter
+ * NOTE :
+ * RETURN : None
+ ******************************************************************************/
+void LineSensDrvSpeedPulseSave(u_int16 us_sp1, u_int16 us_sp2, u_int8 uc_sens_cnt) {
+ u_int16 us_sp_diff = 0; /* Vehicle speed pulse difference */
+ u_int8 uc_ptr = 0; /* Data storage pointer for sensor data */ /* #010 */
+ u_int8 us_last_ptr = 0; /* Last pointer */ /* #010 */
+ int32 i = 0; /* Generic counters */ /* #010 */
+ u_int8 uc_fstsns_cnt = 0; /* Initial sensor data sensor counter value */ /* #016 */
+ int32 l_data_num = 0; /* Number of registered data */ /* #016 */
+ u_int8 uc_noise_flag = 0; /* Noise flag */ /* #017 */
+
+ /* Calculate the vehicle speed pulse difference between the latest and last 100ms information */
+ if (us_sp1 >= us_sp2) {
+ /* The cumulative pulse number of the latest information is larger. */
+ us_sp_diff = us_sp1 - us_sp2; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ } else {
+ /* The cumulative pulse number of the latest information is smaller (the accumulated pulse overflows) */
+ us_sp_diff = (LSDRV_PLSMAX - us_sp2) + us_sp1; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ }
+
+ /* Call noise check only if us_sp_diff is 1 */
+ if (us_sp_diff == 1) {
+ uc_noise_flag = LineSensDrvCheckNoise(uc_sens_cnt);
+ }
+
+ /* Saving sensor data vehicle speed pulse in data table for vehicle speed calculation */
+ if (LSDRV_PLSDATA_NRCV == g_speed_kmph_data.uc_sns_rcv) {
+ if (LSDRV_PLSDATA_RCV == g_speed_kmph_data.uc_fstsns_rcv) {
+ /* If the sensor data has already been received for the first time, set the temporary sensor counter value when the sensor data has been saved for the first time. */
+ uc_fstsns_cnt = uc_sens_cnt;
+ for (i = (LSDRV_SPKMPH_TBL_NUM - 1); i >= 0 ; i--) {
+ if (LSDRV_SPKMPH_DATA_EN == g_speed_kmph_data.st_data[i].uc_flag) {
+ /* Data storage flag is valid */
+ if (0 != uc_fstsns_cnt) {
+ uc_fstsns_cnt--;
+ } else {
+ uc_fstsns_cnt = LSDRV_SENSCNT_MAX;
+ }
+
+ g_speed_kmph_data.st_data[i].uc_sens_cnt = uc_fstsns_cnt;
+ }
+ }
+ }
+
+ /* Sensor data reception status <- "Received" */
+ g_speed_kmph_data.uc_sns_rcv = LSDRV_PLSDATA_RCV;
+ }
+
+ uc_ptr = g_speed_kmph_data.uc_ptr;
+
+ /* If the sensor counter is the same as the previous one, overwrite update */
+ if (0 == uc_ptr) {
+ us_last_ptr = LSDRV_SPKMPH_TBL_NUM - 1;
+ } else {
+ us_last_ptr = uc_ptr - 1; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ }
+
+ if (g_speed_kmph_data.st_data[us_last_ptr].uc_sens_cnt == uc_sens_cnt) {
+ /* Next update of the data storage location */
+ if (0 == g_speed_kmph_data.uc_ptr) {
+ g_speed_kmph_data.uc_ptr = LSDRV_SPKMPH_TBL_NUM - 1;
+ } else {
+ g_speed_kmph_data.uc_ptr--;
+ }
+
+ uc_ptr = g_speed_kmph_data.uc_ptr;
+ }
+
+ /* Input into data table for calculation of vehicle speed */
+ g_speed_kmph_data.st_data[uc_ptr].uc_flag = LSDRV_SPKMPH_DATA_EN; /* Data validity */
+ g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt = uc_sens_cnt; /* Sensor counter input */
+ g_speed_kmph_data.st_data[uc_ptr].us_speed_pulse = us_sp_diff; /* Vehicle speed pulse difference */
+ g_speed_kmph_data.st_data[uc_ptr].uc_noise_flag = uc_noise_flag; /* Noise flag */ /* #017 */
+
+ /* Next update of the data storage location */
+ if ((LSDRV_SPKMPH_TBL_NUM - 1) <= g_speed_kmph_data.uc_ptr) {
+ g_speed_kmph_data.uc_ptr = 0;
+ } else {
+ g_speed_kmph_data.uc_ptr++;
+ }
+
+ /* Determine whether the vehicle speed can be calculated. */
+ if (g_speed_kmph_data.uc_calc_start == LSDRV_PLSDATA_NRCV) {
+ /* Data count detection */
+ l_data_num = 0;
+ for (i = 0; i < LSDRV_SPKMPH_TBL_NUM; i++) {
+ if (LSDRV_SPKMPH_DATA_EN == g_speed_kmph_data.st_data[i].uc_flag) {
+ l_data_num++;
+ }
+ }
+
+ if (LSDRV_SPKMPH_MIN_DATA_N <= l_data_num) {
+ /* Vehicle Speed Calculation Required Data Number Received */
+ g_speed_kmph_data.uc_calc_start = LSDRV_PLSDATA_RCV;
+ }
+ }
+
+ return;
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_CheckNoise
+ * ABSTRACT : Sensor data noise check processing
+ * FUNCTION : The vehicle speed pulse is saved in the data table for the vehicle speed calculation.
+ * ARGUMENT : uc_sens_cnt : Sensor counter of the latest data
+ * NOTE :
+ * RETURN : Noise flag
+ ******************************************************************************/
+u_int8 LineSensDrvCheckNoise(u_int8 uc_sens_cnt) {
+ int32 i = 0; /* Generic counters */
+ u_int16 us_sens_cnt_search = 0; /* Sensor counter to be searched*/
+ u_int8 uc_ptr = 0; /* Data storage pointer */
+ u_int16 us_offset = 0; /* Offset value */
+ u_int8 noise_flag = 0; /* Noise flag */
+ u_int16 us_sens_cnt_ref = 0; /* Sensor counters to be compared */
+
+ /* If there is no point where the difference in vehicle speed pulse is 1 or more
+ between -1 and -14 of sensor counter of the latest data,
+ set the noise flag of the latest data to 1. */
+ /* Set the noise flag to 1 */
+ noise_flag = 1;
+
+ /* The Target is the one before the storage location of the latest data. */
+ if (0 == g_speed_kmph_data.uc_ptr) {
+ uc_ptr = LSDRV_SPKMPH_TBL_NUM - 1;
+ } else {
+ uc_ptr = g_speed_kmph_data.uc_ptr - 1; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ }
+
+ if (LSDRV_SPKMPH_NOISE_TIME > uc_sens_cnt) {
+ us_offset = LSDRV_SENSCNT_BRW_ADD;
+ } else {
+ us_offset = 0;
+ }
+
+ us_sens_cnt_search = (u_int16)uc_sens_cnt + us_offset - LSDRV_SPKMPH_NOISE_TIME;
+
+ for (i = 0; i < LSDRV_SPKMPH_NOISE_TIME; i++) {
+ /* When the sensor counter is 15 or less, the borrow is considered. */
+ if (LSDRV_SPKMPH_NOISE_TIME > g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt) {
+ us_sens_cnt_ref = g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt + us_offset;
+ } else {
+ us_sens_cnt_ref = g_speed_kmph_data.st_data[uc_ptr].uc_sens_cnt; /* Ignore -> MISRA-C++:2008 Rule 5-0-5 */
+ }
+
+ /* Checking the sensor Counter to Finish Search */
+ if (us_sens_cnt_ref <= us_sens_cnt_search) {
+ noise_flag = 1;
+ break;
+ } else {
+ if (g_speed_kmph_data.st_data[uc_ptr].us_speed_pulse >= 1) {
+ noise_flag = 0;
+ break;
+ }
+ }
+
+ /* Borrow actions for pointer values */
+ if (0 == uc_ptr) {
+ uc_ptr = LSDRV_SPKMPH_TBL_NUM - 1; /* To the end of the data table */
+ } else {
+ uc_ptr--; /* To the previous data */
+ }
+ }
+
+ return noise_flag;
+}
+
+/**
+ * @brief
+ * Return the last (100ms ago) vehicle speed pulse
+ *
+ * @param[out] us_sp2 Last vehicle speed pulse
+ * @param[in] us_sp1 The latest vehicle speed pulse
+ * @param[in] uc_sens_cnt Latest sensor counter
+ *
+ * @return LSDRV_SPKMPH_INVALID Vehicle speed pulse information valid<br>
+ * LSDRV_SPKMPH_VALID Vehicle speed pulse information invalid
+ */
+u_int8 LineSensDrvGetLastSpeedPulse(u_int16* us_sp2, u_int16 us_sp1, u_int8 uc_sens_cnt) {
+ u_int8 ret = LSDRV_SPKMPH_INVALID; /* Return value */
+ u_int16 sp_pls_diff = 0; /* Vehicle speed pulse difference */
+ u_int16 sp_pls = 0; /* Vehicle speed pulse every 100 ms */
+ u_int8 cnt_diff = 0; /* Sensor counter difference */
+
+ /* Check if the last vehicle speed pulse has been set */
+ if (g_speed_kmph_data.st_last_data.uc_flag == LSDRV_SPKMPH_DATA_EN) {
+ /* Differential calculation of sensor counter */
+ if (uc_sens_cnt >= g_speed_kmph_data.st_last_data.uc_sens_cnt) {
+ /* Latest sensor counter is larger */
+ cnt_diff = uc_sens_cnt - g_speed_kmph_data.st_last_data.uc_sens_cnt;
+ } else {
+ /* Last sensor counter is larger(sensor counter overflows) */
+ cnt_diff = (LSDRV_SENSCNT_MAX - g_speed_kmph_data.st_last_data.uc_sens_cnt) + uc_sens_cnt + 1;
+ }
+
+ /* Check if sensor counter is continuous */
+ if (cnt_diff <= 1) {
+ /* Continuous or same as the previous one, so the previous (100ms previous) vehicle speed pulse is set as it is */
+ *us_sp2 = g_speed_kmph_data.st_last_data.us_speed_pulse;
+ } else {
+ /* Determine the vehicle speed pulse 100ms ago from the average considering the skipped portion because it is not consecutive. */
+ if (us_sp1 >= g_speed_kmph_data.st_last_data.us_speed_pulse) {
+ /* Larger latest cumulative vehicle speed pulse */
+ sp_pls_diff = us_sp1 - g_speed_kmph_data.st_last_data.us_speed_pulse;
+ } else {
+ /* Last cumulative vehicle speed pulse is larger(Cumulative vehicle speed pulse overflows) */
+ sp_pls_diff = (LSDRV_PLSMAX - g_speed_kmph_data.st_last_data.us_speed_pulse) + us_sp1;
+ }
+
+ /* Calculate average vehicle speed pulse including skip period */
+ sp_pls = (u_int16)(sp_pls_diff / cnt_diff);
+
+ /* Calculate the vehicle speed pulse 100ms ahead from the vehicle speed average */
+ if (us_sp1 >= sp_pls) {
+ /* Does not overflow even if the 100ms vehicle speed pulse is pulled from the latest one. */
+ *us_sp2 = us_sp1 - sp_pls;
+ } else {
+ /* Subtracting a 100ms vehicle speed pulse from the latest one overflows */
+ *us_sp2 = LSDRV_PLSMAX - (sp_pls - us_sp1);
+ }
+ }
+
+ ret = LSDRV_SPKMPH_VALID;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief
+ * Return the last (100ms ago) vehicle speed pulse
+ *
+ * @param[in] us_sp Vehicle speed pulse
+ * @param[in] uc_sens_cnt Sensor counter
+ */
+void LineSensDrvSetLastSpeedPulse(u_int16 us_sp, u_int8 uc_sens_cnt) {
+ /* Vehicle speed pulse information valid setting */
+ g_speed_kmph_data.st_last_data.uc_flag = LSDRV_SPKMPH_DATA_EN;
+ /* Sensor counter setting */
+ g_speed_kmph_data.st_last_data.uc_sens_cnt = uc_sens_cnt;
+ /* Vehicle speed pulse setting */
+ g_speed_kmph_data.st_last_data.us_speed_pulse = us_sp;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Thread.cpp b/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Thread.cpp
new file mode 100755
index 0000000..9fb1c29
--- /dev/null
+++ b/hal/positioning_hal/src/LineSensDrv/LineSensDrv_Thread.cpp
@@ -0,0 +1,125 @@
+/*
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+* @file LineSensDrv_Thread.cpp
+*/
+
+/*---------------------------------------------------------------------------*/
+// Include files
+
+#include "LineSensDrv_Thread.h"
+#include <native_service/frameworkunified_types.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include "positioning_def.h"
+#include "positioning_common.h"
+/*---------------------------------------------------------------------------*/
+// Global variable
+
+static u_int8 g_sys_recv_flg = 0; // For debugging
+char g_threadname[] = "POS_Sens";
+uint8_t g_uc_vehicle_reverse = 0;
+uint8_t g_uc_reverse_state = 0;
+static BOOL g_line_sens_thread_stop = FALSE;
+
+#define POS_REV_STATE_PROCESSING 0
+#define POS_REV_STATE_IDLE 1
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_Thread
+ * ABSTRACT : LineSensor driver thread main process
+ * FUNCTION : Main processing
+ * ARGUMENT : lpvPara :
+ * NOTE :
+ * RETURN :
+ ******************************************************************************/
+EFrameworkunifiedStatus LineSensDrvThread(HANDLE h_app) {
+ int32 l_ret = RET_LSDRV_SUCCESS;
+ EFrameworkunifiedStatus l_status = eFrameworkunifiedStatusOK;
+
+
+ (void)PosSetupThread(h_app, ETID_POS_SENS);
+
+ /* Execute the initialization processes */
+ l_ret = LineSensDrvMainThreadInit(h_app);
+ if (RET_LSDRV_SUCCESS != l_ret) {
+ l_status = eFrameworkunifiedStatusFail;
+ }
+
+ return l_status;
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_MainThread_Init
+ * ABSTRACT : Thread initialization process
+ * FUNCTION : Initialize thread
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : RET_LSDRV_SUCCESS:Success in initialization
+ * RET_LSDRV_ERROR :Initialization failed
+ ******************************************************************************/
+int32 LineSensDrvMainThreadInit(HANDLE h_app) {
+ int32 l_ret = RET_LSDRV_SUCCESS;
+ BOOL b_ret = TRUE;
+
+ /****** Global variable initialization **********/
+ LineSensDrvParamInit();
+
+ /****** LineSensDrvApi initialization **********/
+ b_ret = LineSensDrvApiInitialize();
+
+ if (TRUE != b_ret) {
+ l_ret = RET_LSDRV_ERROR;
+ }
+
+ return l_ret;
+}
+
+/*******************************************************************************
+ * MODULE : LineSensDrv_Param_Init
+ * ABSTRACT : Global variable initialization processing
+ * FUNCTION : Initialize global variables
+ * ARGUMENT : None
+ * NOTE :
+ * RETURN : None
+ ******************************************************************************/
+void LineSensDrvParamInit(void) {
+ LineSensDrvSpeedKmphDataInit(); // Data table initialization process for vehicle speed calculation
+}
+
+/**
+ * @brief
+ * Pos_Sens thread stop processing
+ */
+void LineSensDrvThreadStopProcess(void) {
+ g_line_sens_thread_stop = TRUE;
+
+ if (POS_REV_STATE_IDLE == g_uc_reverse_state) {
+ PosTeardownThread(ETID_POS_SENS);
+ }
+
+ return;
+}
+
+/**
+ * @brief
+ * Get initial sensor data reception flag
+ */
+u_int8 LineSensDrvGetSysRecvFlag(void) {
+ return g_sys_recv_flg;
+}
+
+/*---------------------------------------------------------------------------*/
+/*EOF*/
diff --git a/hal/power_hal/LICENSE b/hal/power_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/power_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/power_hal/Makefile b/hal/power_hal/Makefile
new file mode 100755
index 0000000..b0a0c28
--- /dev/null
+++ b/hal/power_hal/Makefile
@@ -0,0 +1,66 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libpower_hal.so
+
+HEADER := hal_api/power_hal.h
+
+######### include paths/files ###################
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+#CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include/stub
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH := /usr/agl/lib
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+#LIBS += -Wl,-Bdynamic -lCommUSB
+
+######### source files ##########################
+VPATH := src
+OBJS := power_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/power_hal/README.md b/hal/power_hal/README.md
new file mode 100755
index 0000000..6841186
--- /dev/null
+++ b/hal/power_hal/README.md
@@ -0,0 +1,3 @@
+power_hal library
+==================
+Power HAL implementation library for AGL Reference Board.
diff --git a/hal/power_hal/hal_api/power_hal.h b/hal/power_hal/hal_api/power_hal.h
new file mode 100755
index 0000000..f1acc42
--- /dev/null
+++ b/hal/power_hal/hal_api/power_hal.h
@@ -0,0 +1,572 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file power_hal.h
+ * @brief Interface and struct define for power_hal
+ */
+
+#ifndef HAL_API_POWER_HAL_H_
+#define HAL_API_POWER_HAL_H_
+
+#include <native_service/frameworkunified_types.h>
+
+/** @addtogroup system_manager
+ * @{
+ */
+/** @addtogroup power_hal
+ * @ingroup system_manager
+ * @{
+ */
+/** @}*/ // end of power_hal
+/** @}*/ // end of system_manager
+
+/** @addtogroup power_supply_manager_shadow
+ * @{
+ */
+/** @addtogroup power_hal
+ * @ingroup power_supply_manager_shadow
+ * @{
+ */
+
+/**
+ * \~english Definition of program update is not occured
+ */
+#define PWR_PROGUPDATE_STATE_NONE (0x0)
+
+/**
+ * \~english Bit position of program update
+ */
+#define PWR_PROGUPDATE_STATE_UPDATED (0x01)
+
+/**
+ * \~english Bit position of map update
+ */
+#define PWR_PROGUPDATE_STATE_MAP_UPDATED (0x02)
+
+/**
+ * \~english Bit position of map difference update
+ */
+#define PWR_PROGUPDATE_STATE_MAPDIFF_UPDATED (0x04)
+
+/**
+ * \~english None reset state
+ */
+#define PWR_DATA_RESET_STATE_NONE 0
+
+/**
+ * \~english Reset state for initialization of user information
+ */
+#define PWR_DATA_RESET_STATE_USER 1
+
+/**
+ * \~english Reset state for factory initialization
+ */
+#define PWR_DATA_RESET_STATE_FACTORY 2
+
+/*
+ * @~english
+ * @brief Command ID power_hal -> User
+ */
+/*! @~english power_hal command receive notification */
+#define CID_PWR_CMD_RCV 0x0103
+
+/*! @~english power_hal command send result notification */
+#define CID_PWR_CMD_SND_STS 0x0104
+
+/**
+ * \~english DRAM backup status
+ */
+enum PsmSysupDramT {
+ /**
+ * \~english normal value
+ */
+ PSM_SYSUP_DRAM_NORMAL,
+
+ /**
+ * \~english abnormal Soft Reset(software abnormality)
+ */
+ PSM_SYSUP_DRAM_SFTERRSR,
+
+ /**
+ * \~english need to discard backup dram
+ */
+ PSM_SYSUP_DRAM_DISCARD,
+
+ /**
+ * \~english max value
+ */
+ PSM_SYSUP_DRAM_MAX,
+};
+
+/**
+ * \~english Start Status
+ */
+enum PsmStartStatusT {
+ /**
+ * \~english cold start
+ */
+ PSM_START_STATUS_FACTRESET,
+
+ /**
+ * \~english hot start
+ */
+ PSM_START_STATUS_NORMAL,
+
+ /**
+ * \~english max value
+ */
+ PSM_START_STATUS_MAX,
+};
+
+/**
+ * \~english Communication state
+ */
+enum PsmComStsT {
+ /**
+ * \~english Communication normal
+ */
+ PSM_COM_STS_NORMAL,
+
+ /**
+ * \~english Communication abnormal
+ */
+ PSM_COM_STS_ABNORMAL,
+
+ /**
+ * \~english max value
+ */
+ PSM_COM_STS_MAX,
+};
+
+/**
+ * \~english DRAM power supply abnormality check result
+ */
+enum PsmDramStsT {
+ /**
+ * \~english DRAM power supply abnormality check result normal
+ */
+ PSM_DRAM_STS_NORMAL,
+
+ /**
+ * \~english DRAM power supply abnormality check result abnormal
+ */
+ PSM_DRAM_STS_ABNORMAL,
+
+ /**
+ * \~english max value
+ */
+ PSM_DRAM_STS_MAX,
+};
+
+/**
+ * \~english ACC customize setting.
+ */
+enum PsmAccCustomizeT {
+ /**
+ * \~english ACC customize setting OFF.
+ */
+ PSM_ACC_CUSTOMIZE_OFF,
+ /**
+ * \~english ACC customize setting ON.
+ */
+ PSM_ACC_CUSTOMIZE_ON
+};
+
+/**
+ * \~english Reset history recording flag.
+ */
+#define PSM_RESET_HISTORY (0x10000000)
+
+/**
+ * \~english Reset(Start-up) factor.
+ */
+enum PsmFactorT {
+ /**
+ * \~english none
+ */
+ PSM_FACTOR_NONE,
+ /**
+ * \~english Restart due to AGL.
+ */
+ PSM_FACTOR_AGL,
+ /**
+ * \~english Restart due to Tier1.
+ */
+ PSM_FACTOR_TIER1,
+ /**
+ * \~english Restart due to user.
+ */
+ PSM_FACTOR_USER,
+ /**
+ * \~english Restart due to AGL(Need to record reset history).
+ */
+ PSM_FACTOR_AGL_WITH_HISTORY = (PSM_RESET_HISTORY | PSM_FACTOR_AGL),
+ /**
+ * \~english Restart due to Tier1(Need to record reset history).
+ */
+ PSM_FACTOR_TIER1_WITH_HISTORY = (PSM_RESET_HISTORY | PSM_FACTOR_TIER1),
+ /**
+ * \~english Restart due to user(Need to record reset history).
+ */
+ PSM_FACTOR_USER_WITH_HISTORY = (PSM_RESET_HISTORY | PSM_FACTOR_USER)
+};
+
+/**
+ * \~english Reset information type.
+ */
+enum PowerHalResetInfoId {
+ /**
+ * \~english Count of error log.
+ */
+ AGL_ERRLOG_COUNTER = 0,
+ /**
+ * \~english Abnormal reset count detected by AGL.
+ */
+ AGL_RESET_COUNTER,
+ /**
+ * \~english State of program update.
+ */
+ AGL_PROGUPDATE_STATE,
+ /**
+ * \~english Data reset state.
+ */
+ AGL_DATARESET_STATE,
+ /**
+ * \~english Flag of abnormal reset.
+ */
+ AGL_ILLRESET_FLAG,
+ /**
+ * \~english Max of reset information type.
+ */
+ AGL_RESERVED_LIMIT = 32
+};
+
+/**
+ * \ingroup PsmNaviResetPower
+ * \~english @par Brief
+ * API to do navi reset that is forced reset if end sequence of MainSoC is not completed.
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [in] reset_factor Reset factor
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do navi reset process.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmNaviResetPower(HANDLE h_app, PsmFactorT reset_factor);
+
+/**
+ * \ingroup PsmClrRamJudgeFlgPower
+ * \~english @par Brief
+ * API to do ram judge flag clear
+ * \~english @param [in] h_app Handle for Application
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do ram judge flag clear process.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmClrRamJudgeFlgPower(HANDLE h_app);
+
+/**
+ * \ingroup PsmGetDramBackupStatusPower
+ * \~english @par Brief
+ * API to do get dram backup status
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [out] p_dram1 DRAM1 BackUp Status
+ * \~english @param [out] p_dram2 DRAM2 BackUp Status
+ * \~english @param [out] p_dram3 DRAM3 BackUp Status
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do get dram backup status process.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmGetDramBackupStatusPower(HANDLE h_app, PsmSysupDramT *p_dram1, PsmSysupDramT *p_dram2, PsmSysupDramT *p_dram3);
+
+/**
+ * \ingroup PsmGetStartStatusPower
+ * \~english @par Brief
+ * API to do get start status
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [out] p_start_sts start status
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do get startup state process.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmGetStartStatusPower(HANDLE h_app, PsmStartStatusT *p_start_sts);
+
+/**
+ * \ingroup PsmGetSyscomStatusPower
+ * \~english @par Brief
+ * API to do get communication status between mainsoc-sys
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [out] p_com_sts communication status between mainsoc-sys
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do get communication status between mainsoc-sys process.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmGetSyscomStatusPower(HANDLE h_app, PsmComStsT *p_com_sts);
+
+/**
+ * \ingroup PsmGetDramPowerSupplyAbnormalityCheckResultPower
+ * \~english @par Brief
+ * API to do get dram power supply abnormality check result
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [out] p_dram_sts DRAM power supply abnormality check result
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do get dram power supply abnormality check result process.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmGetDramPowerSupplyAbnormalityCheckResultPower(HANDLE h_app, PsmDramStsT *p_dram_sts);
+
+/**
+ * \ingroup PsmGetAccCustomizeSetting
+ * \~english @par Brief
+ * API to do get ACC customize setting
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [out] p_acc_customize ACC customize Setting
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do get ACC customize setting.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmGetAccCustomizeSetting(HANDLE h_app, PsmAccCustomizeT* p_acc_customize);
+
+/**
+ * \ingroup PsmChgAccCustomizeSetting
+ * \~english @par Brief
+ * API to do change ACC customize setting
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [in] acc_customize ACC customize Setting
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do set ACC customize setting.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmChgAccCustomizeSetting(HANDLE h_app, PsmAccCustomizeT acc_customize);
+
+/**
+ * \ingroup PsmGetStartupFactor
+ * \~english @par Brief
+ * API to do get start-up factor.
+ * \~english @param [in] h_app Handle for Application
+ * \~english @param [out] p_startup_factor Start-up factor
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * \~english @par Detail
+ * - do get Start-up factor.
+ * - After the API call, start-up factor is clear.
+ * - The API can only be used by 1 process
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+int PsmGetStartupFactor(HANDLE h_app, PsmFactorT* p_startup_factor);
+
+/**
+ * \ingroup PowerHalSetResetInfo
+ * \~english @par Brief
+ * API to do set reset information.
+ * \~english @param [in] id Reset information type.
+ * \~english @param [in] val setting value.
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * - Save error to non-volatile memory. [-1]
+ * \~english @par Detail
+ * - Do set value to Reset information type(\ref PowerHalResetInfoId). \n
+ * \ref AGL_PROGUPDATE_STATE is not applicable(Only get value used by \ref PowerHalGetResetInfo). \n
+ * Domains of each reset information type are as below. \n
+ * \ref AGL_ERRLOG_COUNTER : 0 <= val <= UINT32_MAX \n
+ * \ref AGL_RESET_COUNTER : 0 <= val <= UINT32_MAX \n
+ * \ref AGL_DATARESET_STATE : It is set as below in each state of data reset. \n
+ * None reset state == \ref PWR_DATA_RESET_STATE_NONE \n
+ * Reset state for initialization of user information == \ref PWR_DATA_RESET_STATE_USER \n
+ * Reset state for factory initialization == \ref PWR_DATA_RESET_STATE_FACTORY \n
+ * \ref AGL_ILLRESET_FLAG : val = 0 or 1 (Abnormal reset is 1)
+ * - When the API is success, setting value is saved as non-volatile data.
+ * - Non-volatile memory is allocated \ref AGL_RESERVED_LIMIT for extendability.
+ * - Values setting by the API are saved when it is cold start(is_batterydiscon is true of PsmSysMcEVSysResUpChkPrmT notified from power_hal).
+ * - The API is completed within 1msec after the API is called.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * PowerHalGetResetInfo
+ */
+int PowerHalSetResetInfo(enum PowerHalResetInfoId id, uint32_t val);
+
+/**
+ * \ingroup PowerHalGetResetInfo
+ * \~english @par Brief
+ * API to do get setting value of reset information .
+ * \~english @param [in] id Reset information type.
+ * \~english @param [out] val Buffer of value.
+ * \~english @retval 0 : Ok
+ * \~english @retval -1 : Failed
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Internal IO error. [-1]
+ * - Read fail of value. [-1]
+ * \~english @par Detail
+ * - Do get value from each reset information type(\ref PowerHalResetInfoId).
+ * - Value of \ref AGL_PROGUPDATE_STATE, low 3bits are assigned as below, \n
+ * and corresponding bit is set if state is updating. \n
+ * Low 1bit(\ref PWR_PROGUPDATE_STATE_UPDATED) : Program update \n
+ * Low 2bit(\ref PWR_PROGUPDATE_STATE_MAP_UPDATED) : Map update \n
+ * Low 3bit(\ref PWR_PROGUPDATE_STATE_MAPDIFF_UPDATED) : Map difference update \n
+ * - The API is completed within 1msec after the API is called.
+ * - Completeness of data getting by the API is assured by lower layer than power_hal, \n
+ * and return -1 as internal IO error when it is occurred abnormal error.
+ * - The API can only be used by 1 process.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * PowerHalSetResetInfo
+ */
+int PowerHalGetResetInfo(enum PowerHalResetInfoId id, uint32_t *val);
+
+/** @}*/ // end of power_hal
+/** @}*/ // end of power_supply_manager_shadow
+
+#endif // HAL_API_POWER_HAL_H_
diff --git a/hal/power_hal/src/power_hal.cpp b/hal/power_hal/src/power_hal.cpp
new file mode 100755
index 0000000..aba2d1e
--- /dev/null
+++ b/hal/power_hal/src/power_hal.cpp
@@ -0,0 +1,97 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "power_hal.h"
+
+int PsmNaviResetPower(HANDLE h_app, PsmFactorT reset_factor) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmClrRamJudgeFlgPower(HANDLE h_app) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmGetDramBackupStatusPower(HANDLE h_app, PsmSysupDramT *p_dram1, PsmSysupDramT *p_dram2, PsmSysupDramT *p_dram3) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmGetStartStatusPower(HANDLE h_app, PsmStartStatusT *p_start_sts) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmGetSyscomStatusPower(HANDLE h_app, PsmComStsT *p_com_sts) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmGetDramPowerSupplyAbnormalityCheckResultPower(HANDLE h_app, PsmDramStsT *p_dram_sts) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmGetAccCustomizeSetting(HANDLE h_app, PsmAccCustomizeT* p_acc_customize) {
+ if (NULL == h_app) {
+ return -1;
+ }
+ *p_acc_customize = PSM_ACC_CUSTOMIZE_ON;
+ return 0;
+}
+
+int PsmChgAccCustomizeSetting(HANDLE h_app, PsmAccCustomizeT acc_customize) {
+ if (NULL == h_app) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int PsmGetStartupFactor(HANDLE h_app, PsmFactorT* p_startup_factor) {
+ if (NULL == h_app) {
+ return -1;
+ }
+ *p_startup_factor = PSM_FACTOR_NONE;
+ return 0;
+}
+
+int PowerHalSetResetInfo(enum PowerHalResetInfoId id, uint32_t val) {
+ return 0;
+}
+
+int PowerHalGetResetInfo(enum PowerHalResetInfoId id, uint32_t *val) {
+ return 0;
+}
diff --git a/hal/security_hal/LICENSE b/hal/security_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/security_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/security_hal/Makefile b/hal/security_hal/Makefile
new file mode 100755
index 0000000..5435be7
--- /dev/null
+++ b/hal/security_hal/Makefile
@@ -0,0 +1,67 @@
+#
+# @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libsecurity_hal.so
+
+HEADER := hal_api/security_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH :=
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+######### source files ##########################
+VPATH := src
+OBJS := security_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
+
diff --git a/hal/security_hal/hal_api/security_hal.h b/hal/security_hal/hal_api/security_hal.h
new file mode 100755
index 0000000..5d2bf90
--- /dev/null
+++ b/hal/security_hal/hal_api/security_hal.h
@@ -0,0 +1,1131 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_SECURITY_HAL_H_
+#define HAL_API_SECURITY_HAL_H_
+
+#include <stdint.h>
+#include <native_service/frameworkunified_types.h>
+
+/**
+ * @file security_hal.h
+ */
+
+/** @addtogroup update_service
+ * @{
+ */
+/** @addtogroup security_hal
+ * @ingroup update_service
+ * @{
+ */
+
+/**
+ * \~english The max size of RSA modulus
+ */
+#define RSA_MODULUS_MAX_SIZE 2048
+/**
+ * \~english The max size of RSA public exponent
+ */
+#define RSA_PUBLIC_EXPONENT_MAX_SIZE 2048
+/**
+ * \~english The max size of RSA private exponent
+ */
+#define RSA_PRIVATE_EXPONENT_MAX_SIZE 2048
+/**
+ * \~english The minimum size of RSA padding
+ */
+#define RSA_PADDING_MINIMUM_SIZE 11
+
+/**
+ * \~english Cipher type
+ */
+enum CipherType {
+ /**
+ * \~english AES symmetric cipher
+ */
+ SYMMETRIC_CIPHER_AES = 1,
+ /**
+ * \~english BLOWFISH symmetric cipher
+ */
+ SYMMETRIC_CIPHER_BLOWFISH,
+ /**
+ * \~english CAST5 symmetric cipher
+ */
+ SYMMETRIC_CIPHER_CAST5,
+ /**
+ * \~english DES symmetric cipher
+ */
+ SYMMETRIC_CIPHER_DES,
+ /**
+ * \~english DESEDA symmetric cipher
+ */
+ SYMMETRIC_CIPHER_DESEDA,
+ /**
+ * \~english DESEDA3 symmetric cipher
+ */
+ SYMMETRIC_CIPHER_DESEDA3,
+ /**
+ * \~english IDEA symmetric cipher
+ */
+ SYMMETRIC_CIPHER_IDEA,
+ /**
+ * \~english RC2 symmetric cipher
+ */
+ SYMMETRIC_CIPHER_RC2,
+ /**
+ * \~english RC4 symmetric cipher
+ */
+ SYMMETRIC_CIPHER_RC4,
+ /**
+ * \~english RC5 symmetric cipher
+ */
+ SYMMETRIC_CIPHER_RC5,
+ /**
+ * \~english RSA asymmetric cipher
+ */
+ ASYMMETRIC_CIPHER_RSA,
+ /**
+ * \~english DSA asymmetric cipher
+ */
+ ASYMMETRIC_CIPHER_DSA,
+ /**
+ * \~english ECDSA asymmetric cipher
+ */
+ ASYMMETRIC_CIPHER_ECDSA
+};
+
+/**
+ * \~english Symmetric Cipher Mode
+ */
+enum SymmetricCipherMode {
+ /**
+ * \~english Stream symmetric cipher mode
+ */
+ SYMMETRIC_CIPHER_MODE_STREAM = 0x00000001,
+ /**
+ * \~english ECB symmetric cipher mode
+ */
+ SYMMETRIC_CIPHER_MODE_BLOCK_ECB = 0x00000002,
+ /**
+ * \~english CBC symmetric cipher mode
+ */
+ SYMMETRIC_CIPHER_MODE_BLOCK_CBC = 0x00000004,
+ /**
+ * \~english CFB symmetric cipher mode
+ */
+ SYMMETRIC_CIPHER_MODE_BLOCK_CFB = 0x00000008,
+ /**
+ * \~english OFB symmetric cipher mode
+ */
+ SYMMETRIC_CIPHER_MODE_BLOCK_OFB = 0x00000010
+};
+
+/**
+ * \~english Symmetric cipher Block Size
+ */
+enum SymmetricCipherBlockSize {
+ /**
+ * \~english Symmetric cipher block size is 4 bytes
+ */
+ SYMMETRIC_CIPHER_BLOCK_SIZE_4 = 0x00000001,
+ /**
+ * \~english Symmetric cipher block size is 8 bytes
+ */
+ SYMMETRIC_CIPHER_BLOCK_SIZE_8 = 0x00000002,
+ /**
+ * \~english Symmetric cipher block size is 16 bytes
+ */
+ SYMMETRIC_CIPHER_BLOCK_SIZE_16 = 0x00000004,
+ /**
+ * \~english Symmetric cipher block size is 32 bytes
+ */
+ SYMMETRIC_CIPHER_BLOCK_SIZE_32 = 0x00000008
+};
+
+/**
+ * \~english Symmetric Cipher Round
+ */
+enum SymmetricCipherRound {
+ /**
+ * \~english Symmetric cipher round is 1
+ */
+ SYMMETRIC_CIPHER_ROUND_1 = 0x00000001,
+ /**
+ * \~english Symmetric cipher round is 2
+ */
+ SYMMETRIC_CIPHER_ROUND_2 = 0x00000002,
+ /**
+ * \~english Symmetric cipher round is 8.5
+ */
+ SYMMETRIC_CIPHER_ROUND_8_5 = 0x00000004,
+ /**
+ * \~english Symmetric cipher round is 10
+ */
+ SYMMETRIC_CIPHER_ROUND_10 = 0x00000008,
+ /**
+ * \~english Symmetric cipher round is 12
+ */
+ SYMMETRIC_CIPHER_ROUND_12 = 0x00000010,
+ /**
+ * \~english Symmetric cipher round is 14
+ */
+ SYMMETRIC_CIPHER_ROUND_14 = 0x00000020,
+ /**
+ * \~english Symmetric cipher round is 16
+ */
+ SYMMETRIC_CIPHER_ROUND_16 = 0x00000040
+};
+
+/**
+ * \~english Asymmetric Padding Mode
+ */
+enum AsymmetricPaddingMode {
+ /**
+ * \~english RSA PKCS1 asymmetric padding mode
+ */
+ ASYMMETRIC_PADDING_MODE_RSA_PKCS1 = 1,
+ /**
+ * \~english RSA SSLV23 asymmetric padding mode
+ */
+ ASYMMETRIC_PADDING_MODE_RSA_SSLV23,
+ /**
+ * \~english RSA NOPADDING asymmetric padding mode
+ */
+ ASYMMETRIC_PADDING_MODE_RSA_NOPADDING,
+ /**
+ * \~english RSA OAEP asymmetric padding mode
+ */
+ ASYMMETRIC_PADDING_MODE_RSA_OAEP,
+ /**
+ * \~english RSA PSS asymmetric padding mode
+ */
+ ASYMMETRIC_PADDING_MODE_RSA_PSS
+};
+
+/**
+ * @union CipherParameter
+ * \~english @par Brief
+ * Union of cipher parameter
+ */
+union CipherParameter {
+ /**
+ * \~english Struct of symmetric cipher parameter
+ */
+ struct SymmetricCipherParameter {
+ /**
+ * \~english Symmetric cipher mode
+ */
+ enum SymmetricCipherMode mode;
+ /**
+ * \~english Symmetric cipher block size
+ */
+ enum SymmetricCipherBlockSize block_size;
+ /**
+ * \~english Symmetric cipher round
+ */
+ enum SymmetricCipherRound round;
+ /**
+ * \~english Padding ON/OFF. Only used in CBC mode and ECB mode.
+ * Padding ON :
+ * Encrypt:
+ * 1.If plaintext length isn't aligned with block size, the
+ * ciphertext length is aligned with block size.
+ * 2.If plaintext length is aligned with block size, the
+ * ciphertext length is equal to plaintext length + 1 block size.
+ * Decrypt:
+ * 1.If ciphertext length isn't aligned with block size, return error.
+ * 2.If ciphertext length is aligned with block size, plaintext length
+ * is equal to ciphertext length minus padding length. Padding length
+ * is greater than 0 and not greater than block size.
+ * Padding OFF:
+ * Encrypt:
+ * 1.If plaintext length isn't aligned with block size, return error.
+ * 2.If plaintext length is aligned with block size, the
+ * ciphertext length is equal to plaintext length.
+ * Decrypt:
+ * 1.If ciphertext length isn't aligned with block size, return error.
+ * 2.If ciphertext length is aligned with block size, the
+ * plaintext length is equal to ciphertext length.
+ */
+ bool to_pad;
+ } symmetric;
+
+ /**
+ * \~english Struct of asymmetric cipher parameter
+ */
+ struct AsymmetricCipherParameter {
+ /**
+ * \~english Asymmetric padding mode
+ */
+ enum AsymmetricPaddingMode mode;
+ } asymmetric;
+};
+
+
+/**
+ * \~english Symmetric cipher key type
+ */
+enum SymmetricCipherKeyType {
+ /**
+ * \~english Key is managed by hardware/chip
+ */
+ SYMMETRIC_CIPHER_KEY_TYPE_MANAGED,
+ /**
+ * \~english Key is provided by user
+ */
+ SYMMETRIC_CIPHER_KEY_TYPE_USER
+};
+
+/**
+ * @struct RsaPrivateKey
+ * \~english @par Brief
+ * Struct of RSA private key
+ */
+struct RsaPrivateKey {
+ /**
+ * \~english Private exponent
+ */
+ uint8_t d[RSA_PRIVATE_EXPONENT_MAX_SIZE];
+ /**
+ * \~english Modulus
+ */
+ uint8_t n[RSA_MODULUS_MAX_SIZE];
+ /**
+ * \~english The length of private exponent
+ */
+ uint32_t d_length;
+ /**
+ * \~english The length of modulus
+ */
+ uint32_t n_length;
+};
+
+/**
+ * @union PrivateKey
+ * \~english @par Brief
+ * Union of private key
+ */
+union PrivateKey {
+ /**
+ * \~english Rsa private key
+ */
+ struct RsaPrivateKey rsa;
+};
+
+/**
+ * @struct RsaPublicKey
+ * \~english @par Brief
+ * Union of RSA public key
+ */
+struct RsaPublicKey {
+ /**
+ * \~english Public exponent
+ */
+ uint8_t e[RSA_PUBLIC_EXPONENT_MAX_SIZE];
+ /**
+ * \~english Modulus
+ */
+ uint8_t n[RSA_MODULUS_MAX_SIZE];
+ /**
+ * \~english The length of public exponent
+ */
+ uint32_t e_length;
+ /**
+ * \~english The length of modulus
+ */
+ uint32_t n_length;
+};
+
+/**
+ * @union PublicKey
+ * \~english @par Brief
+ * Union of public key
+ */
+union PublicKey {
+ /**
+ * \~english Struct of rsa public key
+ */
+ struct RsaPublicKey rsa;
+};
+
+/**
+ * \~english Asymmetric cipher key type
+ */
+enum AsymmetricCipherKeyType {
+ /**
+ * \~english Key is managed by hardware/chip
+ */
+ ASYMMETRIC_CIPHER_KEY_TYPE_MANAGED,
+ /**
+ * \~english Public key is provided by user
+ */
+ ASYMMETRIC_CIPHER_KEY_TYPE_USER_PUBLIC,
+ /**
+ * \~english Private key is provided by user
+ */
+ ASYMMETRIC_CIPHER_KEY_TYPE_USER_PRIVATE
+};
+
+/**
+ * @union KeyParam
+ * \~english @par Brief
+ * Union of key parameter
+ */
+union KeyParam {
+ /**
+ * \~english Struct of symmetric key paramater
+ */
+ struct SymmetricKeyParam {
+ /**
+ * \~english Symmetric cipher key type
+ */
+ enum SymmetricCipherKeyType key_type;
+ /**
+ * \~english Union of symmetric key parameter
+ */
+ union {
+ /**
+ * \~english The symmetric key index
+ */
+ uint32_t managed_key_index;
+ /**
+ * \~english Struct of user key
+ */
+ struct {
+ /**
+ * \~english Key source
+ */
+ uint8_t* key;
+ /**
+ * \~english Key length
+ */
+ uint32_t key_len;
+ /**
+ * \~english Key Initialization vector.
+ */
+ uint8_t* iv;
+ /**
+ * \~english Initialization vector length.The length should be
+ * equal to block size, otherwise return error.
+ */
+ uint32_t iv_len;
+ } user_key;
+ } key_param;
+ } symmetric;
+ /**
+ * \~english Struct of asymmetric key parameter
+ */
+ struct AsymmetricKeyParam {
+ /**
+ * \~english Asymmetric cipher key type
+ */
+ enum AsymmetricCipherKeyType key_type;
+ /**
+ * \~english Union of asymmetric key parameter
+ */
+ union {
+ /**
+ * \~english The asymmetric key index
+ */
+ uint32_t managed_key_index;
+ /**
+ * \~english Union of user key
+ */
+ union {
+ /**
+ * \~english Public key
+ */
+ union PublicKey* public_key;
+ /**
+ * \~english Private key
+ */
+ union PrivateKey* private_key;
+ } user_key;
+ } key_param;
+ } asymmetric;
+};
+
+/**
+ * \~english hash type
+ */
+enum HashType {
+ /**
+ * \~english hash type is md5
+ */
+ HASH_TYPE_MD5 = 1,
+ /**
+ * \~english hash type is sha1
+ */
+ HASH_TYPE_SHA1,
+ /**
+ * \~english hash type is sha224
+ */
+ HASH_TYPE_SHA224,
+ /**
+ * \~english hash type is sha256
+ */
+ HASH_TYPE_SHA256,
+ /**
+ * \~english hash type is sha384
+ */
+ HASH_TYPE_SHA384,
+ /**
+ * \~english hash type is sha512
+ */
+ HASH_TYPE_SHA512
+};
+
+/**
+ * \ingroup EncryptStart
+ * \~english @par Brief
+ * Initialize the encrypt context information.
+ * \~english @param [in] cipher_type
+ * enum CipherType - Cipher type.
+ * \~english @param [in] param
+ * union CipherParameter* - Cipher parameter
+ * \~english @param [in] key
+ * union KeyParam* - Key parameter
+ * \~english @param [out] ctx
+ * void** - The encrypt information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize
+ * fail or hardware I/O operation fail or
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter "cipher_type" is less than SYMMETRIC_CIPHER_AES
+ * or greater than ASYMMETRIC_CIPHER_ECDSA [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "param" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "key" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle initialize failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Initialize the encrypt context information according to cipher type,
+ * cipher parameter and key parameter.
+ * - If EncryptStart() was called successfully, EncryptCleanup() should
+ * be called to clean up encrypt context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * EncryptUpdate, EncryptFinish, EncryptCleanup
+ */
+EFrameworkunifiedStatus EncryptStart(enum CipherType cipher_type, union CipherParameter* param,
+ union KeyParam* key, void** ctx);
+
+/**
+ * \ingroup EncryptUpdate
+ * \~english @par Brief
+ * Encrypt plaintext information.
+ * \~english @param [in] ctx
+ * void* - The encrypt information context handle.
+ * \~english @param [in] in
+ * const uint8_t* - The plaintext to be encrypted.
+ * \~english @param [in] in_len
+ * uint32_t - The input buffer length
+ * in_len shall be greater than 0 for symmetric encrypt.
+ * in_len shall be greater than 0 and not greater than
+ * RSA_PRIVATE_EXPONENT_MAX_SIZE/8 - RSA_PADDING_MINIMUM_SIZE
+ * for RSA asymmetric encrypt.
+ * \~english @param [out] out
+ * uint8_t* - The ciphertext after plaintext had been encrypted.
+ * \~english @param [in] out_len
+ * uint32_t - The output buffer length.
+ * out_len shall not be less than in_len + 1 block size for symmetric encrypt.
+ * out_len shall not be less than RSA_PRIVATE_EXPONENT_MAX_SIZE/8 for RSA asymmetric encrypt.
+ * \~english @param [out] true_length
+ * uint32_t* - The ciphertext length.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - EncryptStart() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in_len" is 0 for symmetric encrypt[eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in_len" is 0 or greater than
+ * RSA_PRIVATE_EXPONENT_MAX_SIZE/8 - RSA_PADDING_MINIMUM_SIZE for RSA asymmetric encrypt[eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is less than in_len + 1 block size
+ * for symmetric encrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is less than RSA_PRIVATE_EXPONENT_MAX_SIZE/8
+ * for RSA asymmetric encrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "true_length" is NULL [eFrameworkunifiedStatusFail]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Update the plaintext to ciphertext by symmetric or asymmetric encrypt algorithm.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * EncryptStart, EncryptFinish, EncryptCleanup
+ */
+EFrameworkunifiedStatus EncryptUpdate(void* ctx, const uint8_t* in, uint32_t in_len,
+ uint8_t* out, uint32_t out_len, uint32_t* true_length);
+
+/**
+ * \ingroup EncryptFinish
+ * \~english @par Brief
+ * Encrypt the final plaintext information.
+ * \~english @param [in] ctx
+ * void* - The encrypt information context handle.
+ * \~english @param [out] out
+ * uint8_t* - The ciphertext after plaintext had been encrypted.
+ * out is useless for RSA asymmetric encrypt.
+ * \~english @param [in] out_len
+ * uint32_t - The final output buffer length.
+ * out_len shall not be less than 1 block size for symmetric encrypt.
+ * out_len is useless for RSA asymmetric encrypt.
+ * \~english @param [out] true_length
+ * uint32_t* - The ciphertext length.
+ * true_length is useless for RSA asymmetric encrypt.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - EncryptStart() and EncryptUpdate() were called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is less than 1 block size
+ * for symmetric encrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "true_length" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Update the final plaintext to ciphertext for symmetric encrypt and do nothing for asymmetric encrypt.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * EncryptStart, EncryptUpdate, EncryptCleanup
+ */
+EFrameworkunifiedStatus EncryptFinish(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length);
+
+/**
+ * \ingroup EncryptCleanup
+ * \~english @par Brief
+ * Clean up encrypt context information.
+ * \~english @param [in] ctx
+ * void* - The encrypt information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - EncryptStart() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * \~english @par Detail
+ * - Clean up encrypt context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * EncryptStart, EncryptUpdate, EncryptFinish
+ */
+EFrameworkunifiedStatus EncryptCleanup(void* ctx);
+
+/**
+ * \ingroup DecryptStart
+ * \~english @par Brief
+ * Initialize the decrypt context information.
+ * \~english @param [in] cipher_type
+ * enum CipherType - Cipher type.
+ * \~english @param [in] param
+ * union CipherParameter* - Cipher parameter
+ * \~english @param [in] key
+ * union KeyParam* - Key parameter
+ * \~english @param [out] ctx
+ * void** - The decrypt information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail or hardware I/O
+ * operation fail or hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter "cipher_type" is less than SYMMETRIC_CIPHER_AES
+ * or greater than ASYMMETRIC_CIPHER_ECDSA [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "param" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "key" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle initialize failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Initialize the decrypt context information according to cipher type, cipher parameter and key parameter.
+ * - If DecryptStart() was called successfully, DecryptCleanup() should be called
+ * to clean up decrypt context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * DecryptUpdate, DecryptFinish, DecryptCleanup
+ */
+EFrameworkunifiedStatus DecryptStart(enum CipherType cipher_type, union CipherParameter* param,
+ union KeyParam *key, void** ctx);
+
+/**
+ * \ingroup DecryptUpdate
+ * \~english @par Brief
+ * Decrypt ciphertext information.
+ * \~english @param [in] ctx
+ * void* - The decrypt information context handle.
+ * \~english @param [in] in
+ * const uint8_t* - The ciphertext to be decrypted.
+ * \~english @param [in] in_len
+ * uint32_t - The input buffer length
+ * in_len shall be greater than 0 for symmetric decrypt.
+ * in_len shall be equal to RSA_PRIVATE_EXPONENT_MAX_SIZE/8
+ * for RSA asymmetric decrypt.
+ * \~english @param [out] out
+ * uint8_t* - The plaintext after ciphertext had been decrypted.
+ * \~english @param [in] out_len
+ * uint32_t - The output buffer length.
+ * out_len shall not be less than in_len + 1 block size for symmetric decrypt.
+ * out_len shall not be less than RSA_PRIVATE_EXPONENT_MAX_SIZE/8 - RSA_PADDING_MINIMUM_SIZE
+ * for RSA asymmetric decrypt.
+ * \~english @param [out] true_length
+ * uint32_t* - The plaintext length.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - DecryptStart() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in_len" is 0 for symmetric decrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in_len" isn't equal to
+ * RSA_PRIVATE_EXPONENT_MAX_SIZE/8 for RSA asymmetric decrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is less than in_len
+ * for symmetric decrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is less than RSA_PRIVATE_EXPONENT_MAX_SIZE/8 - RSA_PADDING_MINIMUM_SIZE
+ * for RSA asymmetric decrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "true_length" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Update the ciphertext to plaintext by symmetric or asymmetric decrypt algorithm.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * DecryptStart, DecryptFinish, DecryptCleanup
+ */
+EFrameworkunifiedStatus DecryptUpdate(void* ctx, const uint8_t* in, uint32_t in_len,
+ uint8_t* out, uint32_t out_len, uint32_t* true_length);
+
+/**
+ * \ingroup DecryptFinish
+ * \~english @par Brief
+ * Decrypt the final ciphertext information.
+ * \~english @param [in] ctx
+ * void* - The decrypt information context handle.
+ * \~english @param [out] out
+ * uint8_t* - The plaintext after ciphertext had been decrypted.
+ * out is useless for RSA asymmetric decrypt.
+ * \~english @param [in] out_len
+ * uint32_t - The final output buffer length.
+ * out_len shall not be less than 1 block size for symmetric decrypt.
+ * out_len is useless for RSA asymmetric decrypt.
+ * \~english @param [out] true_length
+ * uint32_t* - The plaintext length.
+ * true_length is useless for RSA asymmetric decrypt.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - DecryptStart() and DecryptUpdate() were called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is less than 1 block size
+ * for symmetric decrypt [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "true_length" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Update the final ciphertext to plaintext for symmetric decrypt and do nothing for asymmetric decrypt.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * DecryptStart, DecryptUpdate, DecryptCleanup
+ */
+EFrameworkunifiedStatus DecryptFinish(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length);
+
+/**
+ * \ingroup DecryptCleanup
+ * \~english @par Brief
+ * Clean up decrypt context information.
+ * \~english @param [in] ctx
+ * void* - The decrypt information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+
+ * \~english @par Prerequisite
+ * - DecryptStart() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * \~english @par Detail
+ * - Clean up decrypt context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * DecryptStart, DecryptUpdate, DecryptFinish
+ */
+EFrameworkunifiedStatus DecryptCleanup(void* ctx);
+
+/**
+ * \ingroup HashStart
+ * \~english @par Brief
+ * Initialize hash context information.
+ * \~english @param [in] hash_type
+ * enum HashType - Hash type.
+ * \~english @param [out] ctx
+ * void** - The hash information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail or hardware I/O operation
+ * fail or hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter "hash_type" less than HASH_TYPE_MD5
+ * or greater than HASH_TYPE_SHA512 [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle initialize failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Initialize hash context information according to hash type.
+ * - If HashStart() was called successfully, HashCleanup() should be called
+ * to clean up hash context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * HashUpdate, HashFinish, HashCleanup
+ */
+EFrameworkunifiedStatus HashStart(enum HashType hash_type, void** ctx);
+
+/**
+ * \ingroup HashUpdate
+ * \~english @par Brief
+ * Caculate hash value of input data.
+ * \~english @param [in] ctx
+ * void* - The hash information context handle.
+ * \~english @param [in] in
+ * const uint8_t* - The input data to be hashed.
+ * \~english @param [in] in_len
+ * uint32_t - The input buffer length
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - HashStart() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "in_len" is 0 [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Caculate hash value of input data.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * HashStart, HashFinish, HashCleanup
+ */
+EFrameworkunifiedStatus HashUpdate(void* ctx, const uint8_t* in, uint32_t in_len);
+
+/**
+ * \ingroup HashFinish
+ * \~english @par Brief
+ * Caculate final message digest.
+ * \~english @param [in] ctx
+ * void* - The hash information context handle.
+ * \~english @param [out] out
+ * uint8_t* - The message digest after all input data had been hashed.
+ * \~english @param [in] out_len
+ * uint32_t - The output buffer length.
+ * \~english @param [out] true_length
+ * uint32_t* - The message digest length.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - HashStart() and HashUpdate() were called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is 0 [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "true_length" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Caculate final message digest.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * HashStart, HashUpdate, HashCleanup
+ */
+EFrameworkunifiedStatus HashFinish(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length);
+
+/**
+ * \ingroup HashCleanup
+ * \~english @par Brief
+ * Clean up hash context information.
+ * \~english @param [in] ctx
+ * void* - The hash information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - HashStart() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * \~english @par Detail
+ * - Clean up hash context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * HashStart, HashUpdate, HashFinish
+ */
+EFrameworkunifiedStatus HashCleanup(void* ctx);
+
+/**
+ * \ingroup RandomInit
+ * \~english @par Brief
+ * Initialize random number context information.
+ * \~english @param [out] ctx
+ * void** - The random number information context handle.
+ * \~english @param [in] seed_buffer
+ * uint8_t* - The random number seed buffer.
+ * \~english @param [in] buffer_len
+ * uint32_t - The random number seed buffer length.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail or hardware I/O operation
+ * fail or hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "seed_buffer" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "buffer_len" is 0 [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle initialize failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Initialize random number context information according to random number seed.
+ * - If RandomInit() was called successfully, RandomCleanup() should be called to
+ * clean up random number context information. If RandomInit() was called faild,
+ * RandomCleanup() must not be called.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * RandomGet, RandomCleanup
+ */
+EFrameworkunifiedStatus RandomInit(void** ctx, uint8_t* seed_buffer, uint32_t buffer_len);
+
+/**
+ * \ingroup RandomGet
+ * \~english @par Brief
+ * Get random number.
+ * \~english @param [in] ctx
+ * void* - The random number information context handle.
+ * \~english @param [out] out
+ * uint8_t* - The random number that caculated by random number seed.
+ * \~english @param [in] out_len
+ * uint32_t - The output buffer length.
+ * \~english @param [out] true_length
+ * uint32_t* - The random number length.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware/handle initialize fail, hardware I/O operation fail,
+ * hardware device busy or allocate context handle fail.
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - RandomInit() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "out_len" is 0 [eFrameworkunifiedStatusInvldParam]
+ * - If the parameter "true_length" is NULL [eFrameworkunifiedStatusInvldParam]
+ * - If the hardware/handle init failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * - If ctx can not be allocated [eFrameworkunifiedStatusFail]
+ * \~english @par Detail
+ * - Get random number.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * RandomInit, RandomCleanup
+ */
+EFrameworkunifiedStatus RandomGet(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length);
+
+/**
+ * \ingroup RandomCleanup
+ * \~english @par Brief
+ * Clean up random number context information.
+ * \~english @param [in] ctx
+ * void* - The random number information context handle.
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusInvldParam : indicates parameter error.
+ * \~english @par Prerequisite
+ * - RandomInit() was called successfully.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the parameter "ctx" is NULL [eFrameworkunifiedStatusInvldParam]
+ * \~english @par Detail
+ * - Clean up random number context information.
+ * - The API can be used by multiple processes.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * RandomInit, RandomGet
+ */
+EFrameworkunifiedStatus RandomCleanup(void* ctx);
+
+/**
+ * \ingroup ResetSecurityIC
+ * \~english @par Brief
+ * Security IC Reset.
+ * \~english @param none
+ * \~english @retval eFrameworkunifiedStatusOK : indicates success
+ * \~english @retval eFrameworkunifiedStatusFail : indicates the hardware initialize fail, hardware I/O operation fail,
+ * hardware device busy.
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur
+ * \~english @par Conditions of processing failure
+ * - If the hardware initialize failed [eFrameworkunifiedStatusFail]
+ * - If the hardware I/O operation failed [eFrameworkunifiedStatusFail]
+ * - If the hardware device is busy [eFrameworkunifiedStatusFail]
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Security IC Reset.
+ * - The API can be used by multiple processes.
+ * - This API does not cleanup context information when EncryptStart(), DecryptStart() or HashStart() is successfull.
+ * Use EncryptCleanup(), DecryptCleanup() or RandomCleanup() to cleanup context information.
+ * \~english @see
+ * None
+ */
+EFrameworkunifiedStatus ResetSecurityIC(void);
+
+/** @}*/ // end of security_hal
+/** @}*/ // end of update_service
+
+#endif // HAL_API_SECURITY_HAL_H_
diff --git a/hal/security_hal/inc/security_hal_securityhallog.h b/hal/security_hal/inc/security_hal_securityhallog.h
new file mode 100755
index 0000000..44de2ac
--- /dev/null
+++ b/hal/security_hal/inc/security_hal_securityhallog.h
@@ -0,0 +1,76 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_SECURITY_HAL_SECURITYHALLOG_H_
+#define INC_SECURITY_HAL_SECURITYHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_SECURITY_HAL_SECURITYHALLOG_H_
diff --git a/hal/security_hal/src/security_hal.cpp b/hal/security_hal/src/security_hal.cpp
new file mode 100755
index 0000000..ee9f7ea
--- /dev/null
+++ b/hal/security_hal/src/security_hal.cpp
@@ -0,0 +1,615 @@
+/*
+ * @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "security_hal.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "security_hal_securityhallog.h"
+
+#define MD5_DIGEST_LENGTH 16 // md5 digest length
+#define SHA1_DIGEST_LENGTH 20 // sha1 digest length
+#define SHA224_DIGEST_LENGTH 28 // sha224 digest length
+#define SHA256_DIGEST_LENGTH 32 // sha256 digest length
+#define SHA384_DIGEST_LENGTH 48 // sha384 digest length
+#define SHA512_DIGEST_LENGTH 64 // sha512 digest length
+#define BITS_PER_BYTE 8 // the number of bits per byte
+#define KEY_SOURCE_SIZE_128 16 // the size of key source is 128 bits
+#define KEY_SOURCE_SIZE_192 24 // the size of key source is 192 bits
+#define KEY_SOURCE_SIZE_256 32 // the size of key source is 256 bits
+
+/**
+ * the max length of input buffer for RSA asymmetric encrypt or
+ * the minimum length of output buffer for RSA asymmetric decrypt
+ */
+#define RSA_PRIVATE_MAX_SIZE_BYTE \
+ (RSA_PRIVATE_EXPONENT_MAX_SIZE/BITS_PER_BYTE - RSA_PADDING_MINIMUM_SIZE)
+
+/**
+ * cipher context information
+ */
+struct CipherContext {
+ enum CipherType cipher_type;
+ union CipherParameter cipher_parameter;
+ union KeyParam key_param;
+};
+
+/**
+ * hash context information
+ */
+struct HashContext {
+ enum HashType hash_type;
+};
+
+/**
+ * random number context information
+ */
+struct RandomContext {
+ uint8_t* seed_buffer;
+ uint32_t buffer_len;
+};
+
+bool CheckParameterVaildity(enum CipherType cipher_type,
+ union CipherParameter* param, union KeyParam* key) {
+ if (SYMMETRIC_CIPHER_AES == cipher_type) {
+ // check cipher mode for symmetric encrypt/decrypt
+ if (SYMMETRIC_CIPHER_MODE_BLOCK_ECB != param->symmetric.mode &&
+ SYMMETRIC_CIPHER_MODE_BLOCK_CBC != param->symmetric.mode &&
+ SYMMETRIC_CIPHER_MODE_BLOCK_CFB != param->symmetric.mode &&
+ SYMMETRIC_CIPHER_MODE_BLOCK_OFB != param->symmetric.mode) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "don't support the cipher mode for AES symmetric encrypt/decrypt");
+ return false;
+ }
+ // check cipher block size for AES symmetric encrypt/decrypt
+ if (SYMMETRIC_CIPHER_BLOCK_SIZE_16 != param->symmetric.block_size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "don't support the block size for AES symmetric encrypt/decrypt");
+ return false;
+ }
+ // check cipher key type for AES symmetric encrypt/decrypt
+ if (SYMMETRIC_CIPHER_KEY_TYPE_MANAGED != key->symmetric.key_type &&
+ SYMMETRIC_CIPHER_KEY_TYPE_USER != key->symmetric.key_type) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "don't support the cipher key type for AES symmetric encrypt/decrypt");
+ return false;
+ }
+ if (SYMMETRIC_CIPHER_KEY_TYPE_MANAGED == key->symmetric.key_type) {
+ // check cipher rounds for AES symmetric encrypt/decrypt
+ if (SYMMETRIC_CIPHER_ROUND_10 != param->symmetric.round &&
+ SYMMETRIC_CIPHER_ROUND_12 != param->symmetric.round &&
+ SYMMETRIC_CIPHER_ROUND_14 != param->symmetric.round) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "don't support the cipher round for AES symmetric encrypt/decrypt");
+ return false;
+ }
+ } else {
+ // check parameter of key provided by user for AES symmetric encrypt/decrypt
+ if (NULL == key->symmetric.key_param.user_key.key) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "user_key.key is NULL");
+ return false;
+ }
+ if (KEY_SOURCE_SIZE_128 == key->symmetric.key_param.user_key.key_len) {
+ if (SYMMETRIC_CIPHER_ROUND_10 != param->symmetric.round) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "cipher round should be 10 if key len is 128 bits");
+ return false;
+ }
+ } else if (KEY_SOURCE_SIZE_192 == key->symmetric.key_param.user_key.key_len) {
+ if (SYMMETRIC_CIPHER_ROUND_12 != param->symmetric.round) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "cipher round should be 12 if key len is 192 bits");
+ return false;
+ }
+ } else if (KEY_SOURCE_SIZE_256 == key->symmetric.key_param.user_key.key_len) {
+ if (SYMMETRIC_CIPHER_ROUND_14 != param->symmetric.round) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "cipher round should be 14 if key len is 256 bits");
+ return false;
+ }
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "key len should be 128, 192 or 256 bits for AES symmetric encrypt/decrypt");
+ return false;
+ }
+ if (SYMMETRIC_CIPHER_MODE_BLOCK_ECB != param->symmetric.mode) {
+ if (NULL == key->symmetric.key_param.user_key.iv) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "user_key.iv is NULL");
+ return false;
+ }
+ if (key->symmetric.key_param.user_key.iv_len != param->symmetric.block_size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "user_key.iv_len is not equal to block size for AES symmetric encrypt/decrypt");
+ return false;
+ }
+ }
+ }
+ } else if (ASYMMETRIC_CIPHER_RSA == cipher_type) {
+ // check the padding mode for RSA asymmetric encrypt/decrypt
+ if (ASYMMETRIC_PADDING_MODE_RSA_PKCS1 != param->asymmetric.mode &&
+ ASYMMETRIC_PADDING_MODE_RSA_SSLV23 != param->asymmetric.mode &&
+ ASYMMETRIC_PADDING_MODE_RSA_NOPADDING != param->asymmetric.mode &&
+ ASYMMETRIC_PADDING_MODE_RSA_OAEP != param->asymmetric.mode &&
+ ASYMMETRIC_PADDING_MODE_RSA_PSS != param->asymmetric.mode) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "don't support the cipher mode for asymmetric encrypt/decrypt");
+ return false;
+ }
+ // check cipher key type for RSA asymmetric encrypt/decrypt
+ if (ASYMMETRIC_CIPHER_KEY_TYPE_MANAGED != key->asymmetric.key_type &&
+ ASYMMETRIC_CIPHER_KEY_TYPE_USER_PUBLIC != key->asymmetric.key_type &&
+ ASYMMETRIC_CIPHER_KEY_TYPE_USER_PRIVATE != key->asymmetric.key_type) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "don't support the cipher key type for asymmetric encrypt/decrypt");
+ return false;
+ }
+ if (ASYMMETRIC_CIPHER_KEY_TYPE_USER_PUBLIC == key->asymmetric.key_type) {
+ // check parameter of public key provided by user for RSA asymmetric encrypt/decrypt
+ if (NULL == key->asymmetric.key_param.user_key.public_key) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "public_key is NULL");
+ return false;
+ }
+ if (RSA_PUBLIC_EXPONENT_MAX_SIZE <
+ key->asymmetric.key_param.user_key.public_key->rsa.e_length ||
+ RSA_MODULUS_MAX_SIZE <
+ key->asymmetric.key_param.user_key.public_key->rsa.n_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "e_length or n_length is too large, e_length:%d, n_length:%d",
+ key->asymmetric.key_param.user_key.public_key->rsa.e_length,
+ key->asymmetric.key_param.user_key.public_key->rsa.n_length);
+ return false;
+ }
+ } else if (ASYMMETRIC_CIPHER_KEY_TYPE_USER_PRIVATE == key->asymmetric.key_type) {
+ // check parameter of key provided by user for RSA asymmetric encrypt/decrypt
+ if (NULL == key->asymmetric.key_param.user_key.private_key) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "private_key is NULL");
+ return false;
+ }
+ if (RSA_PRIVATE_EXPONENT_MAX_SIZE <
+ key->asymmetric.key_param.user_key.private_key->rsa.d_length ||
+ RSA_MODULUS_MAX_SIZE <
+ key->asymmetric.key_param.user_key.private_key->rsa.n_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "d_length or n_length is too large, d_length:%d, n_length:%d",
+ key->asymmetric.key_param.user_key.private_key->rsa.d_length,
+ key->asymmetric.key_param.user_key.private_key->rsa.n_length);
+ return false;
+ }
+ }
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "the cipher_type isn't support");
+ return false;
+ }
+ return true;
+}
+
+// Initialize the encrypt context information
+EFrameworkunifiedStatus EncryptStart(enum CipherType cipher_type, union CipherParameter* param,
+ union KeyParam* key, void** ctx) {
+ if (SYMMETRIC_CIPHER_AES != cipher_type && ASYMMETRIC_CIPHER_RSA != cipher_type) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "the cipher_type isn't support");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == param || NULL == key || NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "param, key or ctx is NULL, param:%p key:%p ctx:%p", param, key, ctx);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ bool ret = CheckParameterVaildity(cipher_type, param, key);
+ if (true != ret) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "parameter error");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ void* ctx_temp = malloc(sizeof(CipherContext));
+ if (NULL == ctx_temp) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to malloc %lu byte for ctx, errno=%d",
+ sizeof(CipherContext), errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ memset(ctx_temp, 0, sizeof(CipherContext));
+ CipherContext* pcipher_context = reinterpret_cast<CipherContext*>(ctx_temp);
+ pcipher_context->cipher_type = cipher_type;
+ pcipher_context->cipher_parameter = *param;
+ pcipher_context->key_param = *key;
+ *ctx = ctx_temp;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Encrypt plaintext information
+EFrameworkunifiedStatus EncryptUpdate(void* ctx, const uint8_t* in, uint32_t in_len,
+ uint8_t* out, uint32_t out_len, uint32_t* true_length) {
+ if (NULL == ctx || NULL == in || NULL == out || NULL == true_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "ctx, in, out or true_length is NULL, ctx:%p in:%p out:%p true_length:%p",
+ ctx, in, out, true_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (0 == in_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "in_len is equal to 0");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ CipherContext* pcipher_context = reinterpret_cast<CipherContext*>(ctx);
+ if (SYMMETRIC_CIPHER_AES == pcipher_context->cipher_type) { // symmetric encrypt
+ uint32_t block_size = pcipher_context->cipher_parameter.symmetric.block_size;
+ if (out_len < in_len + block_size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "out_len is less than in_len plus block_size");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memcpy(out, in, in_len);
+ *true_length = in_len;
+ } else if (ASYMMETRIC_CIPHER_RSA == pcipher_context->cipher_type) { // asymmetric encrypt
+ if (RSA_PRIVATE_MAX_SIZE_BYTE < in_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "in_len is greater than RSA_PRIVATE_MAX_SIZE_BYTE");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (RSA_PRIVATE_EXPONENT_MAX_SIZE/BITS_PER_BYTE > out_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "out_len is less than RSA_PRIVATE_EXPONENT_MAX_SIZE/BITS_PER_BYTE");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ // out_len is greater than in_len
+ memcpy(out, in, in_len);
+ *true_length = in_len;
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "the cipher_type isn't support, cipher_type:%d", pcipher_context->cipher_type);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+// Encrypt the final plaintext information
+EFrameworkunifiedStatus EncryptFinish(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length) {
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ CipherContext* pcipher_context = reinterpret_cast<CipherContext*>(ctx);
+ if (SYMMETRIC_CIPHER_AES == pcipher_context->cipher_type) { // symmetric encrypt
+ if (NULL == out || NULL == true_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "out or true_length is NULL, out:%p true_length:%p", out, true_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ uint32_t block_size = pcipher_context->cipher_parameter.symmetric.block_size;
+ if (out_len < block_size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "out_len is less than block_size");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (true == pcipher_context->cipher_parameter.symmetric.to_pad) {
+ // Padding on, the true_length is equal to block_size.
+ *true_length = block_size;
+ } else {
+ // Padding off, true_length is equal to 0.
+ *true_length = 0;
+ }
+ } else if (ASYMMETRIC_CIPHER_RSA == pcipher_context->cipher_type) {
+ // EncryptFinish is useless for RSA asymmetric encrypt. So do nothing.
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "the cipher_type isn't support, cipher_type:%d", pcipher_context->cipher_type);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+// Clean up encrypt context information
+EFrameworkunifiedStatus EncryptCleanup(void* ctx) {
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memset(ctx, 0, sizeof(CipherContext));
+ free(ctx);
+ return eFrameworkunifiedStatusOK;
+}
+
+// Initialize the decrypt context information
+EFrameworkunifiedStatus DecryptStart(enum CipherType cipher_type, union CipherParameter* param,
+ union KeyParam *key, void** ctx) {
+ if (SYMMETRIC_CIPHER_AES != cipher_type && ASYMMETRIC_CIPHER_RSA != cipher_type) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "the cipher_type isn't support");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == param || NULL == key || NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "param, key or ctx is NULL, param:%p key:%p ctx:%p", param, key, ctx);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ bool ret = CheckParameterVaildity(cipher_type, param, key);
+ if (true != ret) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "parameter error");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ void* ctx_temp = malloc(sizeof(CipherContext));
+ if (NULL == ctx_temp) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to malloc %lu byte for ctx, errno=%d",
+ sizeof(CipherContext), errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ memset(ctx_temp, 0, sizeof(CipherContext));
+ CipherContext* pcipher_context = reinterpret_cast<CipherContext*>(ctx_temp);
+ pcipher_context->cipher_type = cipher_type;
+ pcipher_context->cipher_parameter = *param;
+ pcipher_context->key_param = *key;
+ *ctx = ctx_temp;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Decrypt ciphertext information
+EFrameworkunifiedStatus DecryptUpdate(void* ctx, const uint8_t* in, uint32_t in_len,
+ uint8_t* out, uint32_t out_len, uint32_t* true_length) {
+ if (NULL == ctx || NULL == in || NULL == out || NULL == true_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "ctx, in, out or true_length is NULL, ctx:%p in:%p out:%p true_length:%p",
+ ctx, in, out, true_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ CipherContext* pcipher_context = reinterpret_cast<CipherContext*>(ctx);
+ if (SYMMETRIC_CIPHER_AES == pcipher_context->cipher_type) { // symmetric decrypt
+ if (0 == in_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "in_len is equal to 0");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ uint32_t block_size = pcipher_context->cipher_parameter.symmetric.block_size;
+ if (out_len < in_len + block_size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "out_len is less than in_len plus block_size");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memcpy(out, in, in_len);
+ *true_length = in_len;
+ } else if (ASYMMETRIC_CIPHER_RSA == pcipher_context->cipher_type) { // asymmetric decrypt
+ if (RSA_PRIVATE_EXPONENT_MAX_SIZE/BITS_PER_BYTE != in_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "in_len isn't equal to RSA_PRIVATE_EXPONENT_MAX_SIZE/BITS_PER_BYTE");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (SHA256_DIGEST_LENGTH > out_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "out_len is less than SHA256_DIGEST_LENGTH");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memcpy(out, in, SHA256_DIGEST_LENGTH);
+ *true_length = SHA256_DIGEST_LENGTH;
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "the cipher_type isn't support, cipher_type:%d", pcipher_context->cipher_type);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+// Decrypt the final ciphertext information
+EFrameworkunifiedStatus DecryptFinish(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length) {
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ CipherContext* pcipher_context = reinterpret_cast<CipherContext*>(ctx);
+ if (SYMMETRIC_CIPHER_AES == pcipher_context->cipher_type) { // symmetric encrypt
+ if (NULL == out || NULL == true_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "out or true_length is NULL, out:%p true_length:%p", out, true_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ uint32_t block_size = pcipher_context->cipher_parameter.symmetric.block_size;
+ if (out_len < block_size) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "out_len is less than block_size");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (true == pcipher_context->cipher_parameter.symmetric.to_pad) {
+ // Padding on, the true_length is equal to block_size - padding_length. Because security_hal
+ // is stub implement, padding_length is unknown. Set true_length to 0.
+ *true_length = 0;
+ } else {
+ // Padding off, true_length is equal to 0.
+ *true_length = 0;
+ }
+ } else if (ASYMMETRIC_CIPHER_RSA == pcipher_context->cipher_type) {
+ // EncryptFinish is useless for RSA asymmetric decrypt. So do nothing.
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "the cipher_type isn't support, cipher_type:%d", pcipher_context->cipher_type);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+// Clean up decrypt context information
+EFrameworkunifiedStatus DecryptCleanup(void* ctx) {
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memset(ctx, 0, sizeof(CipherContext));
+ free(ctx);
+ return eFrameworkunifiedStatusOK;
+}
+
+// Initialize hash context information
+EFrameworkunifiedStatus HashStart(enum HashType hash_type, void** ctx) {
+ if (HASH_TYPE_MD5 > hash_type || HASH_TYPE_SHA512 < hash_type) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "the hash_type isn't support");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ void* ctx_temp = malloc(sizeof(HashContext));
+ if (NULL == ctx_temp) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to malloc %lu byte for ctx, errno=%d",
+ sizeof(HashContext), errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ memset(ctx_temp, 0, sizeof(HashContext));
+ HashContext* phash_context = reinterpret_cast<HashContext*>(ctx_temp);
+ phash_context->hash_type = hash_type;
+ *ctx = ctx_temp;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Caculate hash value of input data
+EFrameworkunifiedStatus HashUpdate(void* ctx, const uint8_t* in, uint32_t in_len) {
+ if (NULL == ctx || NULL == in) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx or in is NULL, ctx:%p in:%p", ctx, in);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (0 == in_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "in_len is equal to 0");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+// Caculate final message digest
+EFrameworkunifiedStatus HashFinish(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length) {
+ if (NULL == ctx || NULL == out || NULL == true_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "ctx, out or true_length is NULL, ctx:%p out:%p true_length:%p",
+ ctx, out, true_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ HashContext* phash_context = reinterpret_cast<HashContext*>(ctx);
+ uint32_t digest_length = 0;
+ switch (phash_context->hash_type) {
+ case HASH_TYPE_MD5:
+ digest_length = HASH_TYPE_MD5;
+ break;
+ case HASH_TYPE_SHA1:
+ digest_length = SHA1_DIGEST_LENGTH;
+ break;
+ case HASH_TYPE_SHA224:
+ digest_length = SHA224_DIGEST_LENGTH;
+ break;
+ case HASH_TYPE_SHA256:
+ digest_length = SHA256_DIGEST_LENGTH;
+ break;
+ case HASH_TYPE_SHA384:
+ digest_length = SHA384_DIGEST_LENGTH;
+ break;
+ case HASH_TYPE_SHA512:
+ digest_length = SHA512_DIGEST_LENGTH;
+ break;
+ default:
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "the hash_type isn't support, hash_type:%d", phash_context->hash_type);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (out_len < digest_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "out_len is less than %u", digest_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memset(out, 0x00, digest_length);
+ *true_length = digest_length;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Clean up hash context information
+EFrameworkunifiedStatus HashCleanup(void* ctx) {
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ memset(ctx, 0, sizeof(HashContext));
+ free(ctx);
+ return eFrameworkunifiedStatusOK;
+}
+
+// Initialize random number context information
+EFrameworkunifiedStatus RandomInit(void** ctx, uint8_t* seed_buffer, uint32_t buffer_len) {
+ if (NULL == ctx || NULL == seed_buffer) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "ctx or seed_buffer is NULL, ctx:%p seed_buffer:%p", ctx, seed_buffer);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (0 == buffer_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "buffer_len is equal to 0");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ void* ctx_temp = malloc(sizeof(RandomContext));
+ if (NULL == ctx_temp) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to malloc %lu byte for ctx, errno=%d",
+ sizeof(RandomContext), errno);
+ return eFrameworkunifiedStatusFail;
+ }
+ memset(ctx_temp, 0, sizeof(RandomContext));
+ RandomContext* prandom_context = reinterpret_cast<RandomContext*>(ctx_temp);
+ prandom_context->seed_buffer = reinterpret_cast<uint8_t*>(malloc(buffer_len));
+ if (NULL == prandom_context->seed_buffer) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to malloc %d byte for seed_buffer, errno=%d",
+ buffer_len, errno);
+ free(ctx_temp);
+ ctx_temp = NULL;
+ return eFrameworkunifiedStatusFail;
+ }
+ memcpy(prandom_context->seed_buffer, seed_buffer, buffer_len);
+ prandom_context->buffer_len = buffer_len;
+ *ctx = ctx_temp;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Get random number
+EFrameworkunifiedStatus RandomGet(void* ctx, uint8_t* out, uint32_t out_len, uint32_t* true_length) {
+ if (NULL == ctx || NULL == out || NULL == true_length) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
+ "ctx, out or true_length is NULL, ctx:%p out:%p true_length:%p",
+ ctx, out, true_length);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ if (0 == out_len) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "out_len is equal to 0");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ // Because security_hal is stub implement, don't assignment value to out or true_length.
+ return eFrameworkunifiedStatusOK;
+}
+
+// Clean up random number context information
+EFrameworkunifiedStatus RandomCleanup(void* ctx) {
+ if (NULL == ctx) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ctx is NULL");
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ RandomContext* prandom_context;
+ prandom_context = reinterpret_cast<RandomContext*>(ctx);
+ if (NULL != prandom_context->seed_buffer) {
+ memset(prandom_context->seed_buffer, 0, prandom_context->buffer_len);
+ free(prandom_context->seed_buffer);
+ prandom_context->seed_buffer = NULL;
+ }
+ memset(prandom_context, 0, sizeof(RandomContext));
+ free(prandom_context);
+ prandom_context = NULL;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Reset Security IC
+EFrameworkunifiedStatus ResetSecurityIC(void) {
+ /*
+ * Note.
+ * This feature needs to be implemented by the vendor.
+ */
+ return eFrameworkunifiedStatusOK;
+}
diff --git a/hal/soc_temperature_hal/LICENSE b/hal/soc_temperature_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/soc_temperature_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/soc_temperature_hal/Makefile b/hal/soc_temperature_hal/Makefile
new file mode 100755
index 0000000..fa30b35
--- /dev/null
+++ b/hal/soc_temperature_hal/Makefile
@@ -0,0 +1,66 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libsoc_temperature_hal.so
+
+HEADER := hal_api/soc_temperature_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH :=
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+######### source files ##########################
+VPATH := src
+OBJS := soc_temperature_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/soc_temperature_hal/hal_api/soc_temperature_hal.h b/hal/soc_temperature_hal/hal_api/soc_temperature_hal.h
new file mode 100755
index 0000000..16c5f6d
--- /dev/null
+++ b/hal/soc_temperature_hal/hal_api/soc_temperature_hal.h
@@ -0,0 +1,89 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file soc_temperature_hal.h
+ */
+
+#ifndef HAL_API_SOC_TEMPERATURE_HAL_H_
+#define HAL_API_SOC_TEMPERATURE_HAL_H_
+
+#include <native_service/frameworkunified_types.h>
+
+/** @addtogroup soc_temperature_hal
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * \ingroup GetSoCTemperature
+ * \~english @par Brief
+ * Get SoC temperature value(unit:celsius).
+ * \~english @param [out] temperature
+ * float* - degree celsius
+ * \~english @retval eFrameworkunifiedStatusOK Success
+ * \~english @retval eFrameworkunifiedStatusNullPointer NULL pointer specified
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error (system error)
+ * \~english @par Prerequisite
+ * - The SoC has temperature sensor, and the thermal driver is available.
+ * \~english @par Change of internal state
+ * - Change of internal state according to the API does not occur.
+ * \~english @par Conditions of processing failure
+ * - Parameter temperature is NULL[eFrameworkunifiedStatusNullPointer]
+ * - System error(open/read/close failed)[eFrameworkunifiedStatusFail]
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Get SoC temperature value.
+ * - On success eFrameworkunifiedStatusOK is returned and the parameter temperature is set.
+ * - Not eFrameworkunifiedStatusOK is returned if an error occurred.
+ * - Return value shall be checked before temperature is refered.
+ * - Sample code:
+ * @code
+ * #include <stdio.h>
+ * #include <stdlib.h>
+ * #include <soc_temperature_hal.h>
+ * #include <native_service/frameworkunified_types.h>
+ *
+ * int main(int argc, char *argv[]) {
+ * float temperature = 0.0f;
+ * EFrameworkunifiedStatus status = GetSoCTemperature(&temperature);
+ * if (status != eFrameworkunifiedStatusOK) {
+ * printf("Get SoC temperature failed\n");
+ * exit(EXIT_FAILURE);
+ * }
+ * printf("SoC temperature: %f\n", temperature);
+ * exit(EXIT_SUCCESS);
+ * }
+ * @endcode
+ * \~english @see
+ * - None
+ */
+EFrameworkunifiedStatus GetSoCTemperature(float* temperature);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+/** @}*/ // end of soc_temperature_hal
+
+#endif // HAL_API_SOC_TEMPERATURE_HAL_H_
+
diff --git a/hal/soc_temperature_hal/inc/soc_temperature_hal_soctemperaturehallog.h b/hal/soc_temperature_hal/inc/soc_temperature_hal_soctemperaturehallog.h
new file mode 100755
index 0000000..6e256e8
--- /dev/null
+++ b/hal/soc_temperature_hal/inc/soc_temperature_hal_soctemperaturehallog.h
@@ -0,0 +1,75 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_SOC_TEMPERATURE_HAL_SOCTEMPERATUREHALLOG_H_
+#define INC_SOC_TEMPERATURE_HAL_SOCTEMPERATUREHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+#endif // INC_SOC_TEMPERATURE_HAL_SOCTEMPERATUREHALLOG_H_
diff --git a/hal/soc_temperature_hal/src/soc_temperature_hal.cpp b/hal/soc_temperature_hal/src/soc_temperature_hal.cpp
new file mode 100755
index 0000000..33b96ee
--- /dev/null
+++ b/hal/soc_temperature_hal/src/soc_temperature_hal.cpp
@@ -0,0 +1,106 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "soc_temperature_hal.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "soc_temperature_hal_soctemperaturehallog.h"
+
+#define MAX_TEMPERATURE_FROM_DRIVER_LENGTH (9) // 9bytes can content -999999\n\0 - 9999999\n\0 (unit:millicelsius)
+#define DECIMAL (10)
+#define THERMAL_ZONE0_TEMPERATURE_PATH "/sys/class/thermal/thermal_zone0/temp"
+#define THERMAL_ZONE1_TEMPERATURE_PATH "/sys/class/thermal/thermal_zone1/temp"
+#define THERMAL_ZONE2_TEMPERATURE_PATH "/sys/class/thermal/thermal_zone2/temp"
+
+EFrameworkunifiedStatus GetCoreTemperature(int64_t* temperature, const char* node_path) {
+ if ((NULL == temperature) || (NULL == node_path)) {
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ char sz_temperature[MAX_TEMPERATURE_FROM_DRIVER_LENGTH] = { 0 };
+
+ // read temperature
+ int fd = open(node_path, O_RDONLY);
+ if (0 > fd) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open error(%d,%s)", errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ ssize_t ret = read(fd, sz_temperature, MAX_TEMPERATURE_FROM_DRIVER_LENGTH - 1);
+ int read_error = errno;
+ close(fd);
+ if (-1 == ret) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "read error(%d,%s)", read_error, strerror(read_error));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ errno = 0;
+ int64_t temp = strtol(sz_temperature, NULL, DECIMAL);
+ if (errno) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "strtol error(%d,%s)", errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ *temperature = temp;
+ return eFrameworkunifiedStatusOK;
+}
+
+// Get SoC temperature value.
+EFrameworkunifiedStatus GetSoCTemperature(float *temperature) {
+ if (NULL == temperature) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "parameter *temperature is null");
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ // Get temperature from thermal_zone0
+ int64_t temperature0 = 0;
+ EFrameworkunifiedStatus e_status = GetCoreTemperature(&temperature0, THERMAL_ZONE0_TEMPERATURE_PATH);
+ if (eFrameworkunifiedStatusOK != e_status) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "get temperature0 failed");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // Get temperature from thermal_zone1
+ int64_t temperature1 = 0;
+ e_status = GetCoreTemperature(&temperature1, THERMAL_ZONE1_TEMPERATURE_PATH);
+ if (eFrameworkunifiedStatusOK != e_status) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "get temperature1 failed");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // Get temperature from thermal_zone2
+ int64_t temperature2 = 0;
+ e_status = GetCoreTemperature(&temperature2, THERMAL_ZONE2_TEMPERATURE_PATH);
+ if (eFrameworkunifiedStatusOK != e_status) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "get temperature2 failed");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // get max temperature
+ int64_t max_temperature = temperature0;
+ if (max_temperature < temperature1) {
+ max_temperature = temperature1;
+ }
+ if (max_temperature < temperature2) {
+ max_temperature = temperature2;
+ }
+
+ *temperature = max_temperature / 1000.0f;
+ return eFrameworkunifiedStatusOK;
+}
diff --git a/hal/update_hal/LICENSE b/hal/update_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/update_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/update_hal/Makefile b/hal/update_hal/Makefile
new file mode 100755
index 0000000..8accb94
--- /dev/null
+++ b/hal/update_hal/Makefile
@@ -0,0 +1,34 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+HEADER = hal_api/update_hal.h
+
+.PHONY:all
+
+######### make targets ##########################
+all:
+ @echo $@ done.
+
+######### make cleans ###########################
+clean:
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/include
+ install -m 0644 $(HEADER) $(DESTDIR)/usr/include
+ @echo $@ done.
diff --git a/hal/update_hal/hal_api/update_hal.h b/hal/update_hal/hal_api/update_hal.h
new file mode 100755
index 0000000..92da9d7
--- /dev/null
+++ b/hal/update_hal/hal_api/update_hal.h
@@ -0,0 +1,165 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief This file provides support for Software Download.
+///
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @file update_hal.h
+ */
+
+/** @addtogroup update_service
+ * @{
+ */
+/** @addtogroup update_hal
+ * @ingroup update_service
+ * @{
+ */
+
+#ifndef INCLUDE_UPDATE_HAL_H_
+#define INCLUDE_UPDATE_HAL_H_
+#include <stdint.h>
+
+/* status of VUP_COMPLETE */
+#define VUP_SUCCESS 0 //!< \~english Success
+#define VUP_FAIL 1 //!< \~english Failed
+
+/* Inter process command codes */
+
+/**
+* \~english Start all updates\n
+* Command ID that the user specifies when requesting update_hal to start all updates \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* In this case, specify updater as the destination and UpdateDataInfo as the datatype.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_VUPSTART 205
+
+/**
+* \~english Start differential update\n
+* Command ID that the user specifies when requesting incremental update start from update_hal \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* In this case, specify updater as the destination and UpdateDataInfo as the datatype.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_DIFFVUPSTART 209
+
+/**
+* \~english Copy of the updated side\n
+* Command ID that the user specifies when requesting update_hal to copy the update plane \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* In this case, specify updater as the destination and UpdateDataInfo as the datatype.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_COPY 216
+
+/**
+* \~english Cancel update\n
+* Command ID that the user specifies when requesting update_hal to cancel the update \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* At this time, specify updater as the destination.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_CANCEL 207
+
+/**
+* \~english Update cancellation completion notice\n
+* Command ID that notifies the user that update cancellation processing has been completed from update_hal \n
+* When receiving the event of this command,
+* Use of interfaces provided by interface_unified (such as FrameworkunifiedAttachCallbackToDispatcher)
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_RES_CANCEL 208
+
+/**
+* \~english Progress status notification\n
+* Command ID that notifies the update progress status from update_hal to the user \n
+* When receiving the event of this command,
+* Use of interfaces provided by interface_unified (such as FrameworkunifiedAttachCallbackToDispatcher)
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_PROGRESS 203
+
+/**
+* \~english Update completion notice\n
+* Command ID that notifies the end of update from update_hal to the user \n
+* When receiving the event of this command,
+* Use of interfaces provided by interface_unified (such as FrameworkunifiedAttachCallbackToDispatcher)
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_COMPLETE 204
+
+#define UPDATE_START_TYPE_UPDATE 1 //!< \~english Type of Update
+#define UPDATE_START_TYPE_VERIFY 2 //!< \~english Type of Verification
+
+/* Data format of request to updater to exec update(UpdateService -> updater) */
+// Formate is:
+// num_of_fileset x 1 : UI_32
+// fileset x N : UpdateDataInfo(struct) x N
+#define KWI_MAX_MOD_FPATH 128 //!< \~english Max file path of module in Detailed info
+#define VUP_MAX_KWI_FNAME (KWI_MAX_MOD_FPATH+1) //!< \~english 129 Max size of the string which to save the file path
+#define KWI_SIZE_HASH 32 //!< \~english HashSize length
+#define VUP_MAX_KWI_DETAIL 15 //!< \~english Max file path of Data infos
+
+/**
+* \~english Structure for starts update external update
+*/
+typedef struct _UpdateDataInfo {
+ UI_32 ID; /*!< \~english ID originated by 0(ROOTFS:0, BOOT:1)*/
+ char filename[VUP_MAX_KWI_FNAME]; /*!< \~english source file(device) name(fullpath)*/
+ char srcname[VUP_MAX_KWI_FNAME]; /*!< \~english source file(device) name in diff update(fullpath)*/
+ char destname[VUP_MAX_KWI_FNAME]; /*!< \~english destinamtion file(device) name(fullpath)*/
+ UI_64 offset; /*!< \~english offset of source file*/
+ UI_64 seek; /*!< \~english seek of destination file*/
+ UI_32 size; /*!< \~english size of data*/
+ char src_hash[KWI_SIZE_HASH]; /*!< \~english Original Data Hash(for diff update only)*/
+ char dst_hash[KWI_SIZE_HASH]; /*!< \~english Restored Data Hash*/
+ UI_32 num_of_div; /*!< \~english Num of Detail files*/
+ UI_64 mod_offset; /*!< \~english offset of module in KWI file*/
+ UI_64 div_offset; /*!< \~english offset of divide header in KWI file*/
+} UpdateDataInfo;
+
+/**
+* \~english List of structure for starts update external update
+*/
+typedef struct _UpdateDataInfos {
+ UI_32 units; /*!< \~english Num of Data Info*/
+ UpdateDataInfo info[VUP_MAX_KWI_DETAIL]; /*!< \~english Data Infos*/
+} UpdateDataInfos;
+
+/**
+* \~english Structure for notify update complete
+*/
+typedef union _ResUpdCompletion {
+ // for Normal/SYS Updater
+ struct {
+ UI_32 type; /*!< \~english type*/
+ UI_32 status; /*!< \~english result*/
+ } inner;
+ // for Outer Updater
+ struct {
+ UI_32 status; /*!< \~english result*/
+ UI_32 need_reboot; /*!< \~english Whether it is necessary to reboot system.*/
+ } outer;
+} ResUpdCompletion;
+
+
+/** @}*/ // end of update_hal
+/** @}*/ // end of update_service
+
+#endif // INCLUDE_UPDATE_HAL_H_
diff --git a/hal/update_hal/include/update_hal.h b/hal/update_hal/include/update_hal.h
new file mode 100755
index 0000000..92da9d7
--- /dev/null
+++ b/hal/update_hal/include/update_hal.h
@@ -0,0 +1,165 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief This file provides support for Software Download.
+///
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @file update_hal.h
+ */
+
+/** @addtogroup update_service
+ * @{
+ */
+/** @addtogroup update_hal
+ * @ingroup update_service
+ * @{
+ */
+
+#ifndef INCLUDE_UPDATE_HAL_H_
+#define INCLUDE_UPDATE_HAL_H_
+#include <stdint.h>
+
+/* status of VUP_COMPLETE */
+#define VUP_SUCCESS 0 //!< \~english Success
+#define VUP_FAIL 1 //!< \~english Failed
+
+/* Inter process command codes */
+
+/**
+* \~english Start all updates\n
+* Command ID that the user specifies when requesting update_hal to start all updates \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* In this case, specify updater as the destination and UpdateDataInfo as the datatype.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_VUPSTART 205
+
+/**
+* \~english Start differential update\n
+* Command ID that the user specifies when requesting incremental update start from update_hal \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* In this case, specify updater as the destination and UpdateDataInfo as the datatype.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_DIFFVUPSTART 209
+
+/**
+* \~english Copy of the updated side\n
+* Command ID that the user specifies when requesting update_hal to copy the update plane \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* In this case, specify updater as the destination and UpdateDataInfo as the datatype.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_COPY 216
+
+/**
+* \~english Cancel update\n
+* Command ID that the user specifies when requesting update_hal to cancel the update \n
+* This command should be sent using the interface_unified FrameworkunifiedSendMsg. \n
+* At this time, specify updater as the destination.
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_REQ_CANCEL 207
+
+/**
+* \~english Update cancellation completion notice\n
+* Command ID that notifies the user that update cancellation processing has been completed from update_hal \n
+* When receiving the event of this command,
+* Use of interfaces provided by interface_unified (such as FrameworkunifiedAttachCallbackToDispatcher)
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_RES_CANCEL 208
+
+/**
+* \~english Progress status notification\n
+* Command ID that notifies the update progress status from update_hal to the user \n
+* When receiving the event of this command,
+* Use of interfaces provided by interface_unified (such as FrameworkunifiedAttachCallbackToDispatcher)
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_PROGRESS 203
+
+/**
+* \~english Update completion notice\n
+* Command ID that notifies the end of update from update_hal to the user \n
+* When receiving the event of this command,
+* Use of interfaces provided by interface_unified (such as FrameworkunifiedAttachCallbackToDispatcher)
+* \~english @attention Do not send this command from multiple processes or threads at the same time.
+*/
+#define VUP_COMPLETE 204
+
+#define UPDATE_START_TYPE_UPDATE 1 //!< \~english Type of Update
+#define UPDATE_START_TYPE_VERIFY 2 //!< \~english Type of Verification
+
+/* Data format of request to updater to exec update(UpdateService -> updater) */
+// Formate is:
+// num_of_fileset x 1 : UI_32
+// fileset x N : UpdateDataInfo(struct) x N
+#define KWI_MAX_MOD_FPATH 128 //!< \~english Max file path of module in Detailed info
+#define VUP_MAX_KWI_FNAME (KWI_MAX_MOD_FPATH+1) //!< \~english 129 Max size of the string which to save the file path
+#define KWI_SIZE_HASH 32 //!< \~english HashSize length
+#define VUP_MAX_KWI_DETAIL 15 //!< \~english Max file path of Data infos
+
+/**
+* \~english Structure for starts update external update
+*/
+typedef struct _UpdateDataInfo {
+ UI_32 ID; /*!< \~english ID originated by 0(ROOTFS:0, BOOT:1)*/
+ char filename[VUP_MAX_KWI_FNAME]; /*!< \~english source file(device) name(fullpath)*/
+ char srcname[VUP_MAX_KWI_FNAME]; /*!< \~english source file(device) name in diff update(fullpath)*/
+ char destname[VUP_MAX_KWI_FNAME]; /*!< \~english destinamtion file(device) name(fullpath)*/
+ UI_64 offset; /*!< \~english offset of source file*/
+ UI_64 seek; /*!< \~english seek of destination file*/
+ UI_32 size; /*!< \~english size of data*/
+ char src_hash[KWI_SIZE_HASH]; /*!< \~english Original Data Hash(for diff update only)*/
+ char dst_hash[KWI_SIZE_HASH]; /*!< \~english Restored Data Hash*/
+ UI_32 num_of_div; /*!< \~english Num of Detail files*/
+ UI_64 mod_offset; /*!< \~english offset of module in KWI file*/
+ UI_64 div_offset; /*!< \~english offset of divide header in KWI file*/
+} UpdateDataInfo;
+
+/**
+* \~english List of structure for starts update external update
+*/
+typedef struct _UpdateDataInfos {
+ UI_32 units; /*!< \~english Num of Data Info*/
+ UpdateDataInfo info[VUP_MAX_KWI_DETAIL]; /*!< \~english Data Infos*/
+} UpdateDataInfos;
+
+/**
+* \~english Structure for notify update complete
+*/
+typedef union _ResUpdCompletion {
+ // for Normal/SYS Updater
+ struct {
+ UI_32 type; /*!< \~english type*/
+ UI_32 status; /*!< \~english result*/
+ } inner;
+ // for Outer Updater
+ struct {
+ UI_32 status; /*!< \~english result*/
+ UI_32 need_reboot; /*!< \~english Whether it is necessary to reboot system.*/
+ } outer;
+} ResUpdCompletion;
+
+
+/** @}*/ // end of update_hal
+/** @}*/ // end of update_service
+
+#endif // INCLUDE_UPDATE_HAL_H_
diff --git a/hal/usb_hal/LICENSE b/hal/usb_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/usb_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/usb_hal/Makefile b/hal/usb_hal/Makefile
new file mode 100755
index 0000000..1a107ce
--- /dev/null
+++ b/hal/usb_hal/Makefile
@@ -0,0 +1,66 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libusb_hal.so
+
+HEADER := ./hal_api/usb_hal.h
+
+######### include paths/files ###################
+CXXFLAGS += -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH :=
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+
+######### source files ##########################
+VPATH := src
+OBJS := usb_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/usb_hal/hal_api/usb_hal.h b/hal/usb_hal/hal_api/usb_hal.h
new file mode 100755
index 0000000..9f93d9b
--- /dev/null
+++ b/hal/usb_hal/hal_api/usb_hal.h
@@ -0,0 +1,379 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file usb_hal.h
+ * @brief usb_hal API
+ */
+
+#ifndef HAL_API_USB_HAL_H_
+#define HAL_API_USB_HAL_H_
+
+#include "native_service/frameworkunified_types.h"
+
+/** @addtogroup device_detection_service
+ * @{
+ */
+/** @addtogroup usb_hal
+ * @ingroup device_detection_service
+ * @{
+ */
+
+/**
+ * \~english Definition of Host/Function mode of USB OTG port.
+ */
+enum UsbRoleType {
+ /**
+ * \~english Host mode
+ */
+ USB_ROLE_HOST = 0,
+ /**
+ * \~english Function mode
+ */
+ USB_ROLE_FUNCTION,
+};
+
+/**
+ * \ingroup GetUsbRoleSwitch
+ * \~english @par Brief
+ * Get USB role
+ * \~english @param [out] usb_role
+ * UsbRoleType* - USB role
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusNullPointer NULL Pointer
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - When State value is "status faile", Can not get host/funtcion mode of USB OTG port.
+ * \~english @par Change of internal state
+ * - None.
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusNullPointer
+ * - Internal process error(open/read)
+ * - eFrameworkunifiedStatusFail
+ * - Internal process error(State value is "status faile")
+ * - eFrameworkunifiedStatusFail
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Get Host/Funtcion mode of USB OTG port.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see SetUsbRoleSwitch
+ */
+EFrameworkunifiedStatus GetUsbRoleSwitch(UsbRoleType* usb_role);
+
+/**
+ * \ingroup SetUsbRoleSwitch
+ * \~english @par Brief
+ * Set USB role.
+ * \~english @param [in] usb_role
+ * UsbRoleType - USB role
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Invalid Parameter
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - When State value is "status faile", Can not set host/funtcion mode of USB OTG port.
+ * \~english @par Change of internal state
+ * - Change "USB role is host mode"or"USB role is host mode"
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusInvldParam
+ * - Internal process error(open/read/write)
+ * - eFrameworkunifiedStatusFail
+ * - Internal process error(State value is "status faile")
+ * - eFrameworkunifiedStatusFail
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Set Host/Funtcion mode of USB OTG port.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see GetUsbRoleSwitch
+ */
+EFrameworkunifiedStatus SetUsbRoleSwitch(UsbRoleType usb_role);
+
+/**
+ * \~english USB authentication error information
+ */
+enum UsbAuthenticationError {
+ /**
+ * \~english USB authentication no error
+ */
+ USB_AUTHENTICATION_ERROR_NONE = 0,
+ /**
+ * \~english The connected device has no response
+ */
+ USB_AUTHENTICATION_ERROR_ENUMERATE,
+ /**
+ * \~english The device connected to bus-powered HUB is overcurrent
+ */
+ USB_AUTHENTICATION_ERROR_HUB_OVERCURRENT,
+ /**
+ * \~english HUB tier levels
+ */
+ USB_AUTHENTICATION_ERROR_HUB_TIER_LEVELS,
+ /**
+ * \~english The number of connected devices is more than supported
+ */
+ USB_AUTHENTICATION_ERROR_CONNECTION_EXCESS
+};
+
+/**
+ * \ingroup CheckUsbAuthenticationError
+ * \~english @par Brief
+ * Check USB authentication error
+ * \~english @param [out] usb_auth_error
+ * UsbAuthenticationError* - USB authentication error
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusNullPointer NULL Pointer
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - When State value is "status faile", Can not check USB authentication error .
+ * \~english @par Change of internal state
+ * - None.
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusNullPointer
+ * - Internal process error(open/read)
+ * - eFrameworkunifiedStatusFail
+ * - Internal process error(State value is "status faile")
+ * - eFrameworkunifiedStatusFail
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Check USB authentication error information.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see None.
+ */
+EFrameworkunifiedStatus CheckUsbAuthenticationError(UsbAuthenticationError* usb_auth_error);
+
+/**
+ * \~english Definition of USB port number.
+ * - The USB port number is defined according to the RefHW,
+ * modification will be necessary if there's any change about USB port.
+ */
+enum UsbPortNumber {
+ /**
+ * \~english USB0(IF-BOX)
+ */
+ USB_PORT_NUMBER_0 = 0,
+ /**
+ * \~english USB1(DCM)
+ */
+ USB_PORT_NUMBER_1,
+ /**
+ * \~english USB2(DSRC/ETC)
+ */
+ USB_PORT_NUMBER_2,
+ /**
+ * \~english USB3(External deck)
+ */
+ USB_PORT_NUMBER_3,
+ /**
+ * \~english USB4(Drive recorder)
+ */
+ USB_PORT_NUMBER_4,
+ /**
+ * \~english Maximum of USB port number.
+ */
+ USB_PORT_NUMBER_MAX
+};
+
+/**
+ * \ingroup ResetUsbVbus
+ * \~english @par Brief
+ * USB VBus Reset.
+ * \~english @param [in] usb_port_no
+ * UsbPortNumber - USB port number
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Invalid Parameter
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - When State value is "status faile", Can not USB VBus reset .
+ * \~english @par Change of internal state
+ * - "USB power ON" from the "USB power OFF".
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusInvldParam
+ * - Internal process error(open/read/write)
+ * - eFrameworkunifiedStatusFail
+ * - Internal process error(State value is "status faile")
+ * - eFrameworkunifiedStatusFail
+ * - Not change internal state.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - USB VBus Reset.
+ * - The API is a block I/F which costs a while due to the sleep time between power off and power on.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see IsUsbPortPowered, PowerOnUsbPort, PowerOffUsbPort
+ */
+EFrameworkunifiedStatus ResetUsbVbus(UsbPortNumber usb_port_no);
+
+/**
+ * \ingroup IsUsbPortPowered
+ * \~english @par Brief
+ * Check the power state of USB port.
+ * \~english @param [in] usb_port_no
+ * UsbPortNumber - USB port number
+ * \~english @param [out] is_powered
+ * bool*\n
+ * - true : Power is on
+ * - false : Power is off
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Invalid Parameter
+ * \~english @retval eFrameworkunifiedStatusNullPointer NULL Pointer
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - None.
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusInvldParam
+ * - eFrameworkunifiedStatusNullPointer
+ * - Internal process error(open/read)
+ * - eFrameworkunifiedStatusFail
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Check the power state of USB port.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see ResetUsbVbus, PowerOnUsbPort, PowerOffUsbPort
+ */
+EFrameworkunifiedStatus IsUsbPortPowered(UsbPortNumber usb_port_no, bool* is_powered);
+
+/**
+ * \ingroup PowerOnUsbPort
+ * \~english @par Brief
+ * Power on USB port.
+ * \~english @param [in] usb_port_no
+ * UsbPortNumber - USB port number
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Invalid Parameter
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - When State value is "status faile", Can not power on USB port.
+ * \~english @par Change of internal state
+ * - Change state "USB power on"
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusInvldParam
+ * - Internal process error(open/read/write)
+ * - eFrameworkunifiedStatusFail
+ * - Internal process error(State value is "status faile")
+ * - eFrameworkunifiedStatusFail
+ * - Not change internal state.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Power on USB port.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see ResetUsbVbus, IsUsbPortPowered, PowerOffUsbPort
+ */
+EFrameworkunifiedStatus PowerOnUsbPort(UsbPortNumber usb_port_no);
+
+/**
+ * \ingroup PowerOffUsbPort
+ * \~english @par Brief
+ * Power off USB port.
+ * \~english @param [in] usb_port_no
+ * UsbPortNumber - USB port number
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Invalid Parameter
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - Change state "USB power off"
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusInvldParam
+ * - Internal process error(open/read/write)
+ * - eFrameworkunifiedStatusFail
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Power off USB port.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see ResetUsbVbus, IsUsbPortPowered, PowerOnUsbPort
+ */
+EFrameworkunifiedStatus PowerOffUsbPort(UsbPortNumber usb_port_no);
+
+/**
+ * \~english USB abnormal status
+ */
+enum UsbAbnormalStatus {
+ /**
+ * \~english USB is not abnormal
+ */
+ USB_ABNORMAL_STATUS_NONE = 0,
+ /**
+ * \~english USB is overcurrent
+ */
+ USB_ABNORMAL_STATUS_OVERCURRENT
+};
+
+/**
+ * \ingroup CheckUsbAbnormalStatus
+ * \~english @par Brief
+ * Check the abnormal status of USB port
+ * \~english @param [in] usb_port_no
+ * UsbPortNumber - USB port number
+ * \~english @param [out] usb_abnormal_status
+ * UsbAbnormalStatus* - USB abnormal status
+ * \~english @retval eFrameworkunifiedStatusOK OK
+ * \~english @retval eFrameworkunifiedStatusInvldParam Invalid Parameter
+ * \~english @retval eFrameworkunifiedStatusNullPointer NULL Pointer
+ * \~english @retval eFrameworkunifiedStatusFail Abnormal Error
+ * \~english @par Prerequisite
+ * - None.
+ * \~english @par Change of internal state
+ * - change state "usb port status faile" or "usb port status ok".
+ * \~english @par Conditions of processing failure
+ * - Input parameter error
+ * - eFrameworkunifiedStatusInvldParam
+ * - eFrameworkunifiedStatusNullPointer
+ * - Internal process error(open/read)
+ * - eFrameworkunifiedStatusFail
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Check the abnormal status of USB port, including overcurrent and so on.
+ * - The API can not be used by multiple processes, threads at the same time.
+ * \~english @see None.
+ */
+EFrameworkunifiedStatus CheckUsbAbnormalStatus(UsbPortNumber usb_port_no, UsbAbnormalStatus* usb_abnormal_status);
+
+/** @}*/ // end of usb_hal
+/** @}*/ // end of device_detection_service
+
+#endif // HAL_API_USB_HAL_H_
diff --git a/hal/usb_hal/inc/usb_hal_debug.h b/hal/usb_hal/inc/usb_hal_debug.h
new file mode 100755
index 0000000..15b307a
--- /dev/null
+++ b/hal/usb_hal/inc/usb_hal_debug.h
@@ -0,0 +1,31 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_USB_HAL_DEBUG_H_
+#define INC_USB_HAL_DEBUG_H_
+
+#include "usb_hal_usbhallog.h"
+
+/* Log output control flag */
+#define USB_LOG_ENABLE_ERROR /* Error log */
+
+#ifdef USB_LOG_ENABLE_ERROR
+#define USB_ERROR_LOG(fmt, ...) FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, fmt, ##__VA_ARGS__)
+#else
+#define USB_ERROR_LOG(fmt, ...)
+#endif
+
+#endif // INC_USB_HAL_DEBUG_H_
diff --git a/hal/usb_hal/inc/usb_hal_internal.h b/hal/usb_hal/inc/usb_hal_internal.h
new file mode 100755
index 0000000..86c3905
--- /dev/null
+++ b/hal/usb_hal/inc/usb_hal_internal.h
@@ -0,0 +1,165 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_USB_HAL_INTERNAL_H_
+#define INC_USB_HAL_INTERNAL_H_
+
+#define FILE_CONTENT_LENGTH (32)
+#define FILE_PATH_LENGTH (128)
+
+/**
+ * USB role file
+ */
+#define USB_ROLE_FILE "/sys/devices/platform/soc/ee080200.usb-phy/role"
+
+/**
+ * USB host value
+ */
+#define USB_HOST_STRING "host\n"
+
+/**
+ * USB function value
+ */
+#define USB_FUNCTION_STRING "peripheral\n"
+
+/**
+ * gpio high value
+ */
+const char kUsbGpioHighValue = '1';
+
+/**
+ * gpio low value
+ */
+const char kUsbGpioLowValue = '0';
+
+/**
+ * gpio export file
+ */
+const char kUsbGpioExportFile[] = "/sys/class/gpio/export";
+
+/**
+ * gpio file prefix
+ */
+const char kUsbGpioFilePrefix[] = "/sys/class/gpio/gpio";
+
+/**
+ * gpio direction file
+ */
+const char kUsbGpioDirectionFile[] = "/direction";
+
+/**
+ * gpio direction in
+ */
+const char kUsbGpioDirectionIn[] = "in";
+
+/**
+ * gpio direction out high
+ */
+const char kUsbGpioDirectionHigh[] = "high";
+
+/**
+ * gpio direction out low
+ */
+const char kUsbGpioDirectionLow[] = "low";
+
+/**
+ * gpio value file
+ */
+const char kUsbGpioValueFile[] = "/value";
+
+/**
+ * structure of USB role switch information
+ */
+struct UsbRoleSwitchInfo {
+ const char* file_path; //!< USB role switch file path
+ const char* usb_host_value; //!< USB host value
+ const char* usb_function_value; //!< USB function value
+};
+
+/**
+ * USB gpio port definition
+ */
+enum UsbGpioPort {
+ USB_GPIO_PORT_USB0_PWEN = 0, //!< USB0 power enable
+ USB_GPIO_PORT_USB1_PWEN, //!< USB1 power enable
+ USB_GPIO_PORT_USB2_PWEN, //!< USB2 power enable
+ USB_GPIO_PORT_USB0_OVC, //!< USB0 overcurrent
+ USB_GPIO_PORT_USB1_OVC, //!< USB1 overcurrent
+ USB_GPIO_PORT_USB2_OVC, //!< USB2 overcurrent
+ USB_GPIO_PORT_MAX
+};
+
+/**
+ * USB gpio port value definition
+ */
+enum GpioPortValue {
+ GPIO_PORT_OFF = 0, //!< gpio port on
+ GPIO_PORT_ON //!< gpio port off
+};
+
+/**
+ * Length for USB gpio port name
+ */
+#define USB_PORT_NAME_LENGTH (8)
+
+/**
+ * USB gpio port information
+ */
+struct UsbGpioPortInfo {
+ bool active_low; //!< active low or high
+ bool is_output; //!< direction output or input
+ const char* port_name; //!< gpio port name
+ char default_value; //!< output port default value (high or low)
+};
+
+/**
+ * USB gpio port config table
+ */
+const char kUsbGpioPortNameUsb0Pwen[] = "375";
+const char kUsbGpioPortNameUsb1Pwen[] = "387";
+const char kUsbGpioPortNameUsb2Pwen[] = "389";
+const char kUsbGpioPortNameUsb0Ovc[] = "376";
+const char kUsbGpioPortNameUsb1Ovc[] = "388";
+const char kUsbGpioPortNameUsb2Ovc[] = "390";
+
+const UsbGpioPortInfo kUsbGpioInfo[] = {
+ { false, true, kUsbGpioPortNameUsb0Pwen, kUsbGpioHighValue },
+ { false, true, kUsbGpioPortNameUsb1Pwen, kUsbGpioHighValue },
+ { false, true, kUsbGpioPortNameUsb2Pwen, kUsbGpioHighValue },
+ { false, false, kUsbGpioPortNameUsb0Ovc, kUsbGpioLowValue },
+ { false, false, kUsbGpioPortNameUsb1Ovc, kUsbGpioLowValue },
+ { false, false, kUsbGpioPortNameUsb2Ovc, kUsbGpioLowValue }
+};
+
+/**
+ * gpio port list of USB power enable
+ */
+const UsbGpioPort kUsbPowerEnableGpio[] = {
+ USB_GPIO_PORT_USB0_PWEN,
+ USB_GPIO_PORT_USB1_PWEN,
+ USB_GPIO_PORT_USB2_PWEN
+};
+
+/**
+ * gpio port list of USB overcurrent
+ */
+const UsbGpioPort kUsbOvercurrentGpio[] = {
+ USB_GPIO_PORT_USB0_OVC,
+ USB_GPIO_PORT_USB1_OVC,
+ USB_GPIO_PORT_USB2_OVC
+};
+
+#endif // INC_USB_HAL_INTERNAL_H_
diff --git a/hal/usb_hal/inc/usb_hal_usbhallog.h b/hal/usb_hal/inc/usb_hal_usbhallog.h
new file mode 100755
index 0000000..53c0a6b
--- /dev/null
+++ b/hal/usb_hal/inc/usb_hal_usbhallog.h
@@ -0,0 +1,77 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_USB_HAL_USBHALLOG_H_
+#define INC_USB_HAL_USBHALLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_USB_HAL_USBHALLOG_H_
diff --git a/hal/usb_hal/src/usb_hal.cpp b/hal/usb_hal/src/usb_hal.cpp
new file mode 100755
index 0000000..7e09ad4
--- /dev/null
+++ b/hal/usb_hal/src/usb_hal.cpp
@@ -0,0 +1,500 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Information.
+ * This source code is a sample source code .
+ * Implementation of the function must be performed by the vendor.
+ */
+
+#include "usb_hal.h"
+#include "usb_hal_internal.h"
+#include "usb_hal_debug.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+
+/**
+ * USB role switch information table
+ */
+const UsbRoleSwitchInfo kUsbRoleSwitchTable = {USB_ROLE_FILE, USB_HOST_STRING, USB_FUNCTION_STRING};
+
+/**
+ * Read content of USB role switch file, then determine HOST/FUNCTION role
+ * according to the specified HOST/FUNCTION value.
+ */
+static EFrameworkunifiedStatus GetUsbRoleType(const char* file_path, const char* usb_host_value, const char* usb_function_value,
+ UsbRoleType* usb_role) {
+ if (!file_path || !usb_host_value || !usb_function_value || !usb_role) {
+ USB_ERROR_LOG("parameter is NULL.");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // 1. open role switch file
+ int fd = open(file_path, O_RDONLY);
+ if (-1 == fd) {
+ USB_ERROR_LOG("open [%s] failed.(%d, %s)", file_path, errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // 2. read file content
+ char file_content[FILE_CONTENT_LENGTH];
+ memset(file_content, 0, sizeof(file_content));
+ ssize_t ret = read(fd, file_content, sizeof(file_content) - 1);
+ int read_error = errno;
+
+ // 3. close file
+ close(fd);
+
+ if (-1 == ret) {
+ USB_ERROR_LOG("read failed.(%d, %s)", read_error, strerror(read_error));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // 4. compare file content to HOST/FUNCTION value
+ if (!strcmp(usb_host_value, file_content)) {
+ *usb_role = USB_ROLE_HOST;
+ } else if (!strcmp(usb_function_value, file_content)) {
+ *usb_role = USB_ROLE_FUNCTION;
+ } else {
+ USB_ERROR_LOG("content error.[%s]", file_content);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * Write the specified role value to USB role switch file.
+ */
+static EFrameworkunifiedStatus SetUsbRoleValue(const char* file_path, const char* role_value) {
+ if (!file_path || !role_value) {
+ USB_ERROR_LOG("parameter is NULL.");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // 1. open role switch file
+ int fd = open(file_path, O_WRONLY | O_TRUNC);
+ if (-1 == fd) {
+ USB_ERROR_LOG("open [%s] failed.(%d, %s)", file_path, errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // 2. write role file
+ ssize_t ret = write(fd, role_value, strlen(role_value));
+ int write_error = errno;
+
+ // 3. close file
+ close(fd);
+
+ // 4. check write result
+ if (static_cast<ssize_t>(strlen(role_value)) != ret) {
+ USB_ERROR_LOG("write [%s] failed, ret=%zd.(%d, %s)", role_value, ret, write_error, strerror(write_error));
+ return eFrameworkunifiedStatusFail;
+ } else {
+ return eFrameworkunifiedStatusOK;
+ }
+}
+
+/**
+ * Check whether the specified USB port supports power control.
+ */
+static bool CheckSupportPowerControl(UsbPortNumber usb_port_no) {
+ if (USB_PORT_NUMBER_MAX <= usb_port_no) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Check whether the specified gpio port is available.
+ */
+static bool CheckGpioPortAvailable(UsbGpioPort gpio_port) {
+ if (USB_GPIO_PORT_MAX <= gpio_port) {
+ USB_ERROR_LOG("port %d is invalid.", gpio_port);
+ return false;
+ }
+
+ if (!kUsbGpioInfo[gpio_port].port_name || (0 == strlen(kUsbGpioInfo[gpio_port].port_name))) {
+ USB_ERROR_LOG("port %d is not available.", gpio_port);
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Open gpio export file.
+ */
+static int OpenExportFile() {
+ return open(kUsbGpioExportFile, O_WRONLY);
+}
+
+/**
+ * Open the direction file of the specified gpio port.
+ */
+static int OpenDirectionFile(const char* port_name) {
+ if (!port_name || (0 == strlen(port_name))) {
+ USB_ERROR_LOG("port name is invalid.");
+ return -1;
+ }
+
+ char dir_file[FILE_PATH_LENGTH];
+ // /sys/class/gpio/gpio123/direction
+ snprintf(dir_file, sizeof(dir_file), "%s%s%s", kUsbGpioFilePrefix, port_name, kUsbGpioDirectionFile);
+ return open(dir_file, O_RDWR);
+}
+
+/**
+ * Open the value file of the specified gpio port.
+ */
+static int OpenValueFile(const char* port_name, bool ro) {
+ if (!port_name || (0 == strlen(port_name))) {
+ USB_ERROR_LOG("port name is invalid.");
+ return -1;
+ }
+
+ char value_file[FILE_PATH_LENGTH];
+ // /sys/class/gpio/gpio123/value
+ snprintf(value_file, sizeof(value_file), "%s%s%s", kUsbGpioFilePrefix, port_name, kUsbGpioValueFile);
+ return open(value_file, ro ? O_RDONLY : O_RDWR);
+}
+
+/**
+ * Initialize gpio port value.
+ */
+static EFrameworkunifiedStatus InitializeGpioPort(UsbGpioPort gpio_port) {
+ if (!CheckGpioPortAvailable(gpio_port)) {
+ return eFrameworkunifiedStatusFail;
+ }
+
+ char port_file[FILE_PATH_LENGTH];
+ snprintf(port_file, sizeof(port_file), "%s%s", kUsbGpioFilePrefix, kUsbGpioInfo[gpio_port].port_name);
+
+ // check if port is exported already
+ if (0 == access(port_file, F_OK)) {
+ return eFrameworkunifiedStatusOK;
+ }
+
+ // open the export file
+ int export_fd = OpenExportFile();
+ if (-1 == export_fd) {
+ USB_ERROR_LOG("open [%s] failed.(%d, %s)", "export", errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // do export by writing the export file
+ ssize_t ret = write(export_fd, kUsbGpioInfo[gpio_port].port_name, strlen(kUsbGpioInfo[gpio_port].port_name));
+ int write_error = errno;
+
+ // close the export file
+ close(export_fd);
+
+ // check write result
+ if (static_cast<ssize_t>(strlen(kUsbGpioInfo[gpio_port].port_name)) != ret) {
+ USB_ERROR_LOG("write [%s] failed, ret=%zd.(%d, %s)", kUsbGpioInfo[gpio_port].port_name, ret, write_error,
+ strerror(write_error));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // open the direction file
+ int direction_fd = OpenDirectionFile(kUsbGpioInfo[gpio_port].port_name);
+ if (-1 == direction_fd) {
+ USB_ERROR_LOG("open direction file failed.(%d, %s)", errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // set direction
+ const char* direction_value;
+ if (!kUsbGpioInfo[gpio_port].is_output) {
+ // for input port, set direction as "in"
+ direction_value = kUsbGpioDirectionIn;
+ } else {
+ if (kUsbGpioHighValue == kUsbGpioInfo[gpio_port].default_value) {
+ // for output port, if default value is high, set direction as "high"
+ direction_value = kUsbGpioDirectionHigh;
+ } else if (kUsbGpioLowValue == kUsbGpioInfo[gpio_port].default_value) {
+ // for output port, if default value is low, set direction as "low"
+ direction_value = kUsbGpioDirectionLow;
+ } else {
+ USB_ERROR_LOG("unknown default value[%c]", kUsbGpioInfo[gpio_port].default_value);
+ return eFrameworkunifiedStatusFail;
+ }
+ }
+
+ ret = write(direction_fd, direction_value, strlen(direction_value));
+ write_error = errno;
+ close(direction_fd);
+ if (static_cast<ssize_t>(strlen(direction_value)) != ret) {
+ USB_ERROR_LOG("write direction %s failed, ret=%zd.(%d, %s)", direction_value, ret, write_error,
+ strerror(write_error));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * Get gpio port value.
+ */
+static EFrameworkunifiedStatus GetGpioPortValue(UsbGpioPort port_name, bool* port_value) {
+ if ((USB_GPIO_PORT_MAX <= port_name) || !port_value) {
+ USB_ERROR_LOG("parameter is invalid.");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // initialize gpio port
+ EFrameworkunifiedStatus result = InitializeGpioPort(port_name);
+ if (eFrameworkunifiedStatusOK != result) {
+ return result;
+ }
+
+ // open port value file
+ int fd = OpenValueFile(kUsbGpioInfo[port_name].port_name, true);
+ if (-1 == fd) {
+ USB_ERROR_LOG("open value file failed.(%d, %s)", errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // read file content
+ char file_content = '\0';
+ ssize_t ret = read(fd, &file_content, sizeof(file_content));
+ int read_error = errno;
+
+ // close file
+ close(fd);
+
+ if (sizeof(file_content) != ret) {
+ USB_ERROR_LOG("read failed.(%d, %s)", read_error, strerror(read_error));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // compare file content to high/low value
+ if (kUsbGpioHighValue == file_content) {
+ *port_value = (kUsbGpioInfo[port_name].active_low ? false : true);
+ } else if (kUsbGpioLowValue == file_content) {
+ *port_value = (kUsbGpioInfo[port_name].active_low ? true : false);
+ } else {
+ USB_ERROR_LOG("content error.[%c]", file_content);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+/**
+ * Set gpio port value.
+ */
+static EFrameworkunifiedStatus SetGpioPortValue(UsbGpioPort port_name, GpioPortValue port_value) {
+ if (USB_GPIO_PORT_MAX <= port_name) {
+ USB_ERROR_LOG("parameter is invalid.");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // initialize gpio port
+ EFrameworkunifiedStatus result = InitializeGpioPort(port_name);
+ if (eFrameworkunifiedStatusOK != result) {
+ return result;
+ }
+
+ // check direction is output
+ if (!kUsbGpioInfo[port_name].is_output) {
+ USB_ERROR_LOG("%d not an output port.", port_name);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // open port value file
+ int fd = OpenValueFile(kUsbGpioInfo[port_name].port_name, false);
+ if (-1 == fd) {
+ USB_ERROR_LOG("open value file failed.(%d, %s)", errno, strerror(errno));
+ return eFrameworkunifiedStatusFail;
+ }
+
+ // write value
+ bool port_active = (GPIO_PORT_ON == port_value ? true : false);
+ bool write_low = (kUsbGpioInfo[port_name].active_low ? port_active : !port_active);
+ char write_value = (write_low ? kUsbGpioLowValue : kUsbGpioHighValue);
+ ssize_t ret = write(fd, &write_value, sizeof(write_value));
+ int write_error = errno;
+
+ // close file
+ close(fd);
+
+ // check write result
+ if (sizeof(write_value) != ret) {
+ USB_ERROR_LOG("write [%c] failed, ret=%zd.(%d, %s)", write_value, ret, write_error, strerror(write_error));
+ return eFrameworkunifiedStatusFail;
+ } else {
+ return eFrameworkunifiedStatusOK;
+ }
+}
+
+/**
+ * Check overcurrent.
+ */
+static EFrameworkunifiedStatus CheckUsbOvercurrent(UsbPortNumber usb_port_no, bool* is_ovc) {
+ if ((USB_PORT_NUMBER_MAX <= usb_port_no) || !is_ovc) {
+ return eFrameworkunifiedStatusFail;
+ }
+
+ return GetGpioPortValue(kUsbOvercurrentGpio[usb_port_no], is_ovc);
+}
+
+EFrameworkunifiedStatus GetUsbRoleSwitch(UsbRoleType* usb_role) {
+ // check NULL pointer
+ if (!usb_role) {
+ USB_ERROR_LOG("parameter is NULL.");
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ return GetUsbRoleType(kUsbRoleSwitchTable.file_path, kUsbRoleSwitchTable.usb_host_value,
+ kUsbRoleSwitchTable.usb_function_value, usb_role);
+}
+
+EFrameworkunifiedStatus SetUsbRoleSwitch(UsbRoleType usb_role) {
+ if ((USB_ROLE_HOST != usb_role) && (USB_ROLE_FUNCTION != usb_role)) {
+ USB_ERROR_LOG("parameter error.[%d]", usb_role);
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ // check current usb role:
+ // allow to switch only when usb_role is different from current usb role.
+ UsbRoleType current_role;
+ if (eFrameworkunifiedStatusOK != GetUsbRoleSwitch(&current_role)) {
+ return eFrameworkunifiedStatusFail;
+ }
+
+ if (current_role == usb_role) {
+ return eFrameworkunifiedStatusOK;
+ }
+
+ // check usb role type
+ // - HOST: write HOST value to role file
+ // - FUNCTION: write FUNCTION value to role file
+ return SetUsbRoleValue(kUsbRoleSwitchTable.file_path, (USB_ROLE_HOST == usb_role)
+ ? kUsbRoleSwitchTable.usb_host_value
+ : kUsbRoleSwitchTable.usb_function_value);
+}
+
+EFrameworkunifiedStatus CheckUsbAuthenticationError(UsbAuthenticationError* usb_auth_error) {
+ // check NULL pointer
+ if (!usb_auth_error) {
+ USB_ERROR_LOG("parameter is NULL.");
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ // Empty Stub implementations
+ *usb_auth_error = USB_AUTHENTICATION_ERROR_NONE;
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus ResetUsbVbus(UsbPortNumber usb_port_no) {
+ // check support power control
+ if (!CheckSupportPowerControl(usb_port_no)) {
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ // step 1: power off USB port
+ EFrameworkunifiedStatus result = SetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], GPIO_PORT_OFF);
+ if (eFrameworkunifiedStatusOK != result) {
+ USB_ERROR_LOG("power off USB%d failed.", usb_port_no);
+ return result;
+ }
+
+ // step 2: sleep 1.1 sec
+ usleep(1100 * 1000);
+
+ // step 3: power on USB port
+ result = SetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], GPIO_PORT_ON);
+ if (eFrameworkunifiedStatusOK != result) {
+ USB_ERROR_LOG("power on USB%d failed.", usb_port_no);
+ }
+ return result;
+}
+
+EFrameworkunifiedStatus IsUsbPortPowered(UsbPortNumber usb_port_no, bool* is_powered) {
+ if (!is_powered) {
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ // check support power control
+ if (!CheckSupportPowerControl(usb_port_no)) {
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ return GetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], is_powered);
+}
+
+EFrameworkunifiedStatus PowerOnUsbPort(UsbPortNumber usb_port_no) {
+ // check support power control
+ if (!CheckSupportPowerControl(usb_port_no)) {
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ bool current_power = false;
+ if (eFrameworkunifiedStatusOK != GetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], &current_power)) {
+ return eFrameworkunifiedStatusFail;
+ }
+
+ if (current_power) {
+ return eFrameworkunifiedStatusOK;
+ }
+ return SetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], GPIO_PORT_ON);
+}
+
+EFrameworkunifiedStatus PowerOffUsbPort(UsbPortNumber usb_port_no) {
+ // check support power control
+ if (!CheckSupportPowerControl(usb_port_no)) {
+ return eFrameworkunifiedStatusInvldParam;
+ }
+ bool current_power = false;
+ if (eFrameworkunifiedStatusOK != GetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], &current_power)) {
+ return eFrameworkunifiedStatusFail;
+ }
+
+ if (!current_power) {
+ return eFrameworkunifiedStatusOK;
+ }
+
+ return SetGpioPortValue(kUsbPowerEnableGpio[usb_port_no], GPIO_PORT_OFF);
+}
+
+EFrameworkunifiedStatus CheckUsbAbnormalStatus(UsbPortNumber usb_port_no, UsbAbnormalStatus* usb_abnormal_status) {
+ if (USB_PORT_NUMBER_MAX <= usb_port_no) {
+ return eFrameworkunifiedStatusInvldParam;
+ }
+
+ // check NULL pointer
+ if (!usb_abnormal_status) {
+ return eFrameworkunifiedStatusNullPointer;
+ }
+
+ // check overcurrent
+ bool is_ovc = false;
+ EFrameworkunifiedStatus result = CheckUsbOvercurrent(usb_port_no, &is_ovc);
+ if (eFrameworkunifiedStatusOK == result) {
+ if (is_ovc) {
+ *usb_abnormal_status = USB_ABNORMAL_STATUS_OVERCURRENT;
+ } else {
+ *usb_abnormal_status = USB_ABNORMAL_STATUS_NONE;
+ }
+ }
+ return result;
+}
diff --git a/hal/vehicle_hal/LICENSE b/hal/vehicle_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/vehicle_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/vehicle_hal/Makefile b/hal/vehicle_hal/Makefile
new file mode 100755
index 0000000..d009b13
--- /dev/null
+++ b/hal/vehicle_hal/Makefile
@@ -0,0 +1,69 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libvehicle_hal.so
+
+HEADER := hal_api/vehicle_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH := /usr/lib
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lpthread
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+#LIBS += -Wl,-Bdynamic -lcarsignal_mng
+
+######### source files ##########################
+VPATH := src
+OBJS := vehicle_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=:$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
+
diff --git a/hal/vehicle_hal/README.md b/hal/vehicle_hal/README.md
new file mode 100755
index 0000000..6636a4f
--- /dev/null
+++ b/hal/vehicle_hal/README.md
@@ -0,0 +1,3 @@
+vehicle_hal library
+==================
+Vehicle HAL implementation library for AGL Reference Board.
diff --git a/hal/vehicle_hal/hal_api/vehicle_hal.h b/hal/vehicle_hal/hal_api/vehicle_hal.h
new file mode 100755
index 0000000..4e6cc89
--- /dev/null
+++ b/hal/vehicle_hal/hal_api/vehicle_hal.h
@@ -0,0 +1,210 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_VEHICLE_HAL_H_
+#define HAL_API_VEHICLE_HAL_H_
+/**
+ * @file vehicle_hal.h
+ */
+
+/** @addtogroup vehicle
+ * @{
+ */
+/** @addtogroup vehicle_hal
+ * @ingroup vehicle
+ * @{
+ */
+
+#include <native_service/frameworkunified_types.h>
+
+/**
+ * \~english Name of the send thread
+ */
+#define TN_LINE_SENS_READ "Vehicle Hal"
+
+/**
+ * @enum LineSensReadInternalServiceProtocol
+ * \~english Command ID used by Vehicle_hal to send the vehicle signal input from the jicage line to the user \n
+ To receive events with this command ID, use the interface defined in framework_unified as follows
+ * @code
+ * ret_status = FrameworkunifiedAttachCallbackToDispatcher(h_app, TN_LINE_SENS_READ, CID_VEHICLEHAL_LINESENS, CbCallbackFunc);
+ * @endcode
+ */
+enum LineSensReadInternalServiceProtocol {
+ CID_VEHICLEHAL_LINESENS = 0x00000101, //!< \~english LineSens Message Command ID
+ CID_VEHICLEHAL_SPDPULSE = 0x00000102, //!< \~english SpeedPulse Message Command ID
+ CID_VEHICLEHAL_SPD = 0x00000103, //!< \~english Speed Message Command ID
+ CID_VEHICLEHAL_LINESENS_POL = 0x00000104,
+ //!< \~english voltage and RHEOSTAT Message Command ID
+};
+
+/**
+ * @enum VehiclehalLinesenskindMicBit
+ * \~english MIC BIT
+ */
+enum VehiclehalLinesenskindMicBit {
+ VEHICLEHAL_LINESENSKIND_MIC_BIT_MIC = 0x01, //!< \~english MIC
+ VEHICLEHAL_LINESENSKIND_MIC_BIT_ANALOGMIC1 = 0x02, //!< \~english ANALOGMIC1
+ VEHICLEHAL_LINESENSKIND_MIC_BIT_ANALOGMIC2 = 0x04, //!< \~english ANALOGMIC2
+};
+
+/**
+ * @enum VehiclehalLinesenskindMic2Bit
+ * \~english MIC2 BIT
+ */
+enum VehiclehalLinesenskindMic2Bit {
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_A2BHUB = 0x01, //!< \~english A2BHUB
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC1 = 0x02, //!< \~english MULTIMIC1
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC2 = 0x04, //!< \~english MULTIMIC2
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC3 = 0x08, //!< \~english MULTIMIC3
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC4 = 0x10, //!< \~english MULTIMIC4
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC5 = 0x20, //!< \~english MULTIMIC5
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC6 = 0x40, //!< \~english MULTIMIC6
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_ANC = 0x80, //!< \~english ANC
+};
+
+/**
+ * @enum VehicleHalLineSensKind
+ * \~english Line Sensor kind
+ */
+enum VehicleHalLineSensKind {
+ VEHICLEHAL_LINESENSKIND_IG = 0, //!< \~english IG
+ VEHICLEHAL_LINESENSKIND_PKB, //!< \~english PKB
+ VEHICLEHAL_LINESENSKIND_REV, //!< \~english REV
+ VEHICLEHAL_LINESENSKIND_ILL, //!< \~english ILL
+ VEHICLEHAL_LINESENSKIND_LOWVOLTAGE, //!< \~english LOWVOLTAGE
+ VEHICLEHAL_LINESENSKIND_ADIM, //!< \~english ADIM
+ VEHICLEHAL_LINESENSKIND_MIC, //!< \~english MIC,ANALOGMIC1,ANALOGMIC2
+ VEHICLEHAL_LINESENSKIND_USBPOWERSUPPLY, //!< \~english USB Power Supply[10mA]
+ VEHICLEHAL_LINESENSKIND_MIC2, //!< \~english A2BHUB,MULTIMIC1 to 6,ANC
+ VEHICLEHAL_LINESENSKIND_NUM, //!< \~english MAX Number
+};
+
+/**
+ * @enum VEHICLEHAL_RET_TYPE
+ * \~english The return value of vehicle_hal API
+ */
+typedef enum {
+ /**
+ * \~english Success
+ */
+ VEHICLEHAL_RET_SUCCESS = 0,
+ /**
+ * \~english Car Signal Ctrl Api Initialize failed
+ */
+ VEHICLEHAL_RET_ERR_HARDINIT,
+ /**
+ * \~english McSend Open failed
+ */
+ VEHICLEHAL_RET_ERR_MCOPEN,
+ /**
+ * \~english Create Thread failed
+ */
+ VEHICLEHAL_RET_ERR_THREADSTART,
+ /**
+ * \~english Invalid paramter
+ */
+ VEHICLEHAL_RET_ERR_PARAM,
+}VEHICLEHAL_RET_TYPE;
+
+/**
+ * @struct VehicleHalSpeedPulse
+ * \~english Struct of SpeedPulse
+ */
+struct VehicleHalSpeedPulse {
+ float pulse; //!< \~english speed pulse[Hz]
+ float period; //!< \~english pulse period[ms]
+};
+
+/**
+ * @struct VehicleHalLineSensMsg
+ * \~english Struct of Meassage
+ */
+struct VehicleHalLineSensMsg {
+ uint8_t stdata[VEHICLEHAL_LINESENSKIND_NUM]; //!< \~english line data
+};
+
+/**
+ * @struct VehicleHalPol
+ * \~english Struct of VehicleHalPolling
+ */
+struct VehicleHalPol {
+ uint8_t vb; //!< \~english voltage [10 * v]
+ uint8_t rheostat; //!< \~english RHEOSTAT [10 * v]
+};
+
+/**
+ * \ingroup VehicleHalStart
+ * \~english @par Brief
+ * API to start the vehicle_hal
+ * \~english @param [in] happ
+ * HANDLE - Handle for Application
+ * \~english @retval VEHICLEHAL_RET_SUCCESS : Success
+ * \~english @retval VEHICLEHAL_RET_ERR_HARDINIT : Car Signal Ctrl Api Initialize failed
+ * \~english @retval VEHICLEHAL_RET_ERR_MCOPEN : McSend Open failed
+ * \~english @retval VEHICLEHAL_RET_ERR_THREADSTART : Create Thread failed
+ * \~english @retval VEHICLEHAL_RET_ERR_PARAM : Invalid paramter
+ * \~english @par Prerequisite
+ * None
+ * \~english @par Change of internal state
+ * - If start successfully, vehicle_hal changes from stop to start.
+ * - If start failed, the state of the vehicle_hal remains no change.
+ * \~english @par Conditions of processing failure
+ * - Car Signal Ctrl Api Initialize failed.
+ * - McSend Open failed.
+ * - Create Thread failed.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Start the vehicle_hal service.
+ * - The API can only be used by 1 process.
+ * \~english @see
+ * None
+ */
+VEHICLEHAL_RET_TYPE VehicleHalStart(HANDLE happ);
+
+/**
+ * \ingroup VehicleHalStop
+ * \~english @par Brief
+ * API to stop the vehicle_hal
+ * \~english @param [in] happ
+ * HANDLE - Handle for Application
+ * \~english @retval VEHICLEHAL_RET_SUCCESS : Success
+ * \~english @retval VEHICLEHAL_RET_ERR_PARAM : Invalid paramter
+ * \~english @par Prerequisite
+ * vehicle_hal start successfully.
+ * \~english @par Change of internal state
+ * - If start successfully, vehicle_hal changes from start to stop.
+ * - If start failed, the state of the vehicle_hal remains no change.
+ * \~english @par Conditions of processing failure
+ * None.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Stop the vehicle_hal service.
+ * - The API can only be used by 1 process.
+ * \~english @see
+ * None
+ */
+VEHICLEHAL_RET_TYPE VehicleHalStop(HANDLE happ);
+
+/** @}*/ //!< end of vehicle_hal
+/** @}*/ //!< end of vehicle
+#endif // HAL_API_VEHICLE_HAL_H_
diff --git a/hal/vehicle_hal/inc/vehicle_hal_frameworkunifiedlog.h b/hal/vehicle_hal/inc/vehicle_hal_frameworkunifiedlog.h
new file mode 100755
index 0000000..2cee8eb
--- /dev/null
+++ b/hal/vehicle_hal/inc/vehicle_hal_frameworkunifiedlog.h
@@ -0,0 +1,78 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_VEHICLE_HAL_FRAMEWORKUNIFIEDLOG_H_
+#define INC_VEHICLE_HAL_FRAMEWORKUNIFIEDLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_VEHICLE_HAL_FRAMEWORKUNIFIEDLOG_H_
+
diff --git a/hal/vehicle_hal/src/vehicle_hal.cpp b/hal/vehicle_hal/src/vehicle_hal.cpp
new file mode 100755
index 0000000..258c51a
--- /dev/null
+++ b/hal/vehicle_hal/src/vehicle_hal.cpp
@@ -0,0 +1,398 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <agl_thread.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <native_service/frameworkunified_dispatcher.h>
+#include <native_service/frameworkunified_multithreading.h>
+#include "vehicle_hal_frameworkunifiedlog.h"
+
+extern "C" {
+// #include "carsignal_mng_api.h"
+}
+
+#include "vehicle_hal.h"
+
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_ADIM_DATA "VEHICLEHAL_LINESENSKIND_ADIM"
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_MIC_DATA "VEHICLEHAL_LINESENSKIND_MIC"
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_VB_DATA "VEHICLEHAL_LINESENSKIND_VB"
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_RHEOSTAT_DATA "VEHICLEHAL_LINESENSKIND_RHEOSTAT"
+
+#define VEHICLEHAL_LOWVB_VALUE 75
+
+// send message flag
+static HANDLE g_sendmsg_handle = NULL;
+
+// work thread exit flag
+static BOOL g_loopendflag = FALSE;
+
+// polling thread exit flag
+static BOOL g_polloopendflag = FALSE;
+
+// isOpen flag
+static BOOL g_isopenflag = FALSE;
+
+// thread id
+static pthread_t g_threadid = 0;
+
+// hard object struct
+//static VclCtlApiObj g_sclientobj;
+
+// app name
+static CHAR g_appname[MAX_NAME_SIZE_APP];
+
+// line sense list
+const UINT8 kLineSensList[VEHICLEHAL_LINESENSKIND_NUM] = {
+// CARSIGNAL_IG,
+// CARSIGNAL_PKB,
+// CARSIGNAL_REV,
+// CARSIGNAL_ILL,
+};
+
+static void *VehicleHalProcess(void *arg);
+
+HANDLE g_vehiclehalext_thread;
+HANDLE g_vehiclehalpol_thread;
+EFrameworkunifiedStatus VehicleHalProcessExtStart(HANDLE happ);
+EFrameworkunifiedStatus VehicleHalProcessExtStop(HANDLE happ);
+EFrameworkunifiedStatus VehicleHalProcessRecvSpeed(HANDLE happ);
+
+EFrameworkunifiedStatus VehicleHalProcessPolStart(HANDLE happ);
+EFrameworkunifiedStatus VehicleHalProcessPolStop(HANDLE happ);
+
+static const FrameworkunifiedProtocolCallbackHandler kVehicleHalSpd[] = { {
+ CID_VEHICLEHAL_SPD, VehicleHalProcessRecvSpeed } };
+
+#define VEHICLEHAL_SPEED "VehicleHalSpd"
+#define VEHICLEHAL_EXT "VehicleHalExt"
+#define VEHICLEHAL_POL "VehicleHalPol"
+
+VEHICLEHAL_RET_TYPE VehicleHalStart(HANDLE happ) {
+ if (NULL == happ) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Handle is NULL");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+
+ // check open flag
+ if (TRUE == g_isopenflag) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Already Opened");
+ return VEHICLEHAL_RET_SUCCESS;
+ }
+
+// memset(&g_sclientobj, 0, sizeof(g_sclientobj));
+
+ // enter loop
+ g_loopendflag = FALSE;
+
+ g_polloopendflag = FALSE;
+
+ // get app name
+ PCSTR app_name = FrameworkunifiedGetAppName(happ);
+ if (NULL == app_name) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Get App Name Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+
+ memset(g_appname, 0, sizeof(g_appname));
+ memcpy(g_appname, app_name, sizeof(g_appname));
+ g_appname[MAX_NAME_SIZE_APP] = '\0';
+
+// // Start VLC data input control API
+// UINT32 ret = VclCtlApiOpen(&g_sclientobj);
+// if ( CARSIGNAL_CTL_RET_SUCCESS != ret ) {
+// FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Ten Api Open Failed");
+// return VEHICLEHAL_RET_ERR_HARDINIT;
+// }
+
+ // Open message queue for sending
+ g_sendmsg_handle = McOpenSender(g_appname);
+ if (NULL == g_sendmsg_handle) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Open Mc Sender Failed");
+// VclCtlApiClose(&g_sclientobj);
+ return VEHICLEHAL_RET_ERR_MCOPEN;
+ }
+
+ // create thread
+ int iret = pthread_create(&g_threadid,
+ NULL,
+ VehicleHalProcess,
+ NULL);
+ if ( 0 != iret ) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Create Thread Failed");
+ McClose(g_sendmsg_handle);
+// VclCtlApiClose(&g_sclientobj);
+ return VEHICLEHAL_RET_ERR_THREADSTART;
+ }
+
+ g_vehiclehalext_thread = FrameworkunifiedCreateChildThread(happ, VEHICLEHAL_EXT,
+ VehicleHalProcessExtStart,
+ VehicleHalProcessExtStop);
+
+ EFrameworkunifiedStatus estatus = FrameworkunifiedStartChildThread(happ, g_vehiclehalext_thread, 0, NULL);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedStartChildThread Failed");
+ McClose(g_sendmsg_handle);
+ return VEHICLEHAL_RET_ERR_THREADSTART;
+ }
+
+ g_vehiclehalpol_thread = FrameworkunifiedCreateChildThread(happ, VEHICLEHAL_POL,
+ VehicleHalProcessPolStart,
+ VehicleHalProcessPolStop);
+
+ EFrameworkunifiedStatus estatus_pol = FrameworkunifiedStartChildThread(happ, g_vehiclehalpol_thread, 0, NULL);
+ if (eFrameworkunifiedStatusOK != estatus_pol) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedStartChildThread polling Failed");
+ McClose(g_sendmsg_handle);
+ return VEHICLEHAL_RET_ERR_THREADSTART;
+ }
+
+
+ // set open flag true
+ g_isopenflag = TRUE;
+
+ return VEHICLEHAL_RET_SUCCESS;
+}
+
+VEHICLEHAL_RET_TYPE VehicleHalStop(HANDLE happ) {
+ if (NULL == happ) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Handle is NULL");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+
+ if (NULL != g_vehiclehalext_thread) {
+ EFrameworkunifiedStatus estatus = FrameworkunifiedDestroyChildThread(happ, g_vehiclehalext_thread);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedDestroyChildThread Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+ g_vehiclehalext_thread = NULL;
+ }
+
+ // set open flag of polling to fasle
+ g_polloopendflag = TRUE;
+
+ if (NULL != g_vehiclehalpol_thread) {
+ EFrameworkunifiedStatus estatus = FrameworkunifiedStopChildThread(happ, g_vehiclehalpol_thread, 0, NULL);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedDestroyChildThread polling Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+ estatus = FrameworkunifiedDestroyChildThread(happ, g_vehiclehalpol_thread);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedDestroyChildThread polling Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+ g_vehiclehalpol_thread = NULL;
+ }
+
+ // set open flag fasle
+ g_isopenflag = FALSE;
+
+ // exit loop
+ g_loopendflag = TRUE;
+
+ // destroy thead
+ pthread_join(g_threadid, NULL);
+
+ // Close message queue
+ McClose(g_sendmsg_handle);
+
+// // End VLC data input control API
+// VclCtlApiClose(&g_sclientobj);
+
+ return VEHICLEHAL_RET_SUCCESS;
+}
+
+void *VehicleHalProcess(void *arg) {
+ // Line Sense Message
+ VehicleHalLineSensMsg s_linesensmsg;
+ memset( &s_linesensmsg, 0xFF, sizeof(s_linesensmsg) );
+
+ // main loop
+ while (TRUE != g_loopendflag) {
+ char* p_env_vb = NULL;
+ p_env_vb = getenv(VEHICLEHAL_LINESENSKIND_VB_DATA);
+ if (NULL != p_env_vb) {
+ // low voltage
+ if (VEHICLEHAL_LOWVB_VALUE >= atoi(p_env_vb)) {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_LOWVOLTAGE] = 1;
+ } else {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_LOWVOLTAGE] = 0;
+ }
+ }
+
+ // loop to get line sense status
+ for (UI_32 iloopnum = 0; iloopnum <= VEHICLEHAL_LINESENSKIND_ILL; ++iloopnum) {
+ // line sense status
+ UINT8 signalret = 0;
+
+// // get line sense status
+// UINT32 ret = VclCtlApiRcvVclData(&g_sclientobj, kLineSensList[iloopnum], &signalret);
+// if ( CARSIGNAL_CTL_RET_SUCCESS != ret ) {
+// FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Get LineSens [%d] status faild [%d]", kLineSensList[iloopnum], ret);
+// continue;
+// }
+
+ // convert 0 to 1 or 1 to 0 for IG,REV according car signal api reference
+ switch (kLineSensList[iloopnum]) {
+// case CARSIGNAL_IG:
+// case CARSIGNAL_REV:
+// signalret = 1 - signalret;
+// break;
+
+ default:
+ break;
+ }
+
+ // check status
+ if (signalret != s_linesensmsg.stdata[iloopnum]) {
+ s_linesensmsg.stdata[iloopnum] = signalret;
+ }
+ }
+
+ char* p_env_adim = NULL;
+ p_env_adim = getenv(VEHICLEHAL_LINESENSKIND_ADIM_DATA);
+ if (NULL != p_env_adim) {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_ADIM] = atoi(p_env_adim);
+ }
+
+ char* p_env_mic = NULL;
+ p_env_mic = getenv(VEHICLEHAL_LINESENSKIND_MIC_DATA);
+ if (NULL != p_env_mic) {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_MIC] = atoi(p_env_mic);
+ }
+
+ // send line sens
+ EFrameworkunifiedStatus eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_LINESENS,
+ sizeof(s_linesensmsg), (PVOID)&s_linesensmsg);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend LineSens failed");
+ }
+
+ // wait 10ms
+ usleep(10000);
+ }
+ return NULL;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessExtStart(HANDLE happ) {
+ EFrameworkunifiedStatus estatus = FrameworkunifiedAttachCallbacksToDispatcher(happ, VEHICLEHAL_SPEED,
+ kVehicleHalSpd,
+ static_cast<UI_32>(_countof(kVehicleHalSpd)));
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__,
+ "Error FrameworkunifiedAttachCallbacksToDispatcher Vehicle_Hal_Speed:%d", estatus);
+ return estatus;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessExtStop(HANDLE happ) {
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessRecvSpeed(HANDLE happ) {
+ // Speed Pusle Message
+ VehicleHalSpeedPulse speedpulsemsg;
+ memset( &speedpulsemsg, 0xFF, sizeof(speedpulsemsg) );
+
+ // get vehicle speed
+ UINT16 speed = 0;
+ EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusOK;
+
+ estatus = FrameworkunifiedGetMsgDataOfSize(happ, &speed, sizeof(speed), eSMRRelease);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "failed FrameworkunifiedGetMsgDataOfSize() Status=[%d]", estatus);
+ return estatus;
+ }
+
+ // calculate speed to speed pulse
+ float speedpulse = static_cast<float>(speed * (4.0*637.0) / (60.0 * 60.0));
+ if ( speedpulse != speedpulsemsg.pulse ) {
+ speedpulsemsg.pulse = speedpulse;
+ if (0.0 != speedpulse) {
+ speedpulsemsg.period = static_cast<float>((1 / speedpulse) * 1000);
+ } else {
+ speedpulsemsg.period = 0;
+ }
+ }
+
+ // send line sens
+ EFrameworkunifiedStatus eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_SPDPULSE,
+ sizeof(speedpulsemsg), (PVOID)&speedpulsemsg);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend Speed Pulse failed");
+ }
+
+ eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_SPD,
+ sizeof(UINT16), (PVOID)&speed);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend Speed failed");
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessPolStart(HANDLE happ) {
+ VehicleHalPol s_pol;
+ memset( &s_pol, 0xFF, sizeof(s_pol) );
+
+ while (!g_polloopendflag) {
+ char* p_env_vb = NULL;
+ char* p_env_rheostat = NULL;
+ p_env_vb = getenv(VEHICLEHAL_LINESENSKIND_VB_DATA);
+ p_env_rheostat = getenv(VEHICLEHAL_LINESENSKIND_RHEOSTAT_DATA);
+ if (NULL != p_env_vb) {
+ // covert voltage value
+ s_pol.vb = atoi(p_env_vb);
+ }
+
+ if (NULL != p_env_rheostat) {
+ // covert RHEOSTAT value
+ s_pol.rheostat = atoi(p_env_rheostat);
+ }
+ // send vb and rheostat
+ EFrameworkunifiedStatus eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_LINESENS_POL,
+ sizeof(s_pol), (PVOID)&s_pol);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend Vb and RHEOSTAT failed");
+ }
+ // sleep 700ms
+ usleep(700000);
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessPolStop(HANDLE happ) {
+ return eFrameworkunifiedStatusOK;
+}
diff --git a/hal/video_in_hal/LICENSE b/hal/video_in_hal/LICENSE
new file mode 100755
index 0000000..f433b1a
--- /dev/null
+++ b/hal/video_in_hal/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/hal/video_in_hal/Makefile b/hal/video_in_hal/Makefile
new file mode 100755
index 0000000..25ebaab
--- /dev/null
+++ b/hal/video_in_hal/Makefile
@@ -0,0 +1,61 @@
+#
+# @copyright Copyright (c) 2018-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET = libvideo_in_hal.so
+
+HEADER = hal_api/video_in_hal.h
+
+######### include paths/files ###################
+CFLAGS += -I./hal_api/
+CFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -Wl,--warn-unresolved-symbols
+
+######### linked library ########################
+
+######### source files ##########################
+VPATH := ./src/
+
+OBJS := video_in_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
diff --git a/hal/video_in_hal/README.md b/hal/video_in_hal/README.md
new file mode 100755
index 0000000..bb50e72
--- /dev/null
+++ b/hal/video_in_hal/README.md
@@ -0,0 +1,3 @@
+video_in_hal library
+==================
+video_in HAL implementation library for AGL Reference Board.
diff --git a/hal/video_in_hal/hal_api/video_in_hal.h b/hal/video_in_hal/hal_api/video_in_hal.h
new file mode 100755
index 0000000..20b45a0
--- /dev/null
+++ b/hal/video_in_hal/hal_api/video_in_hal.h
@@ -0,0 +1,567 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_VIDEO_IN_HAL_H_
+#define HAL_API_VIDEO_IN_HAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file video_in_hal.h
+ * @brief API definition of the function to control video
+ */
+
+/** @addtogroup graphics_service
+ * @{
+ */
+/** @addtogroup video_in_hal
+ * @ingroup graphics_service
+ * @{
+ */
+
+
+/* Monitor state */
+#define VIH_DISP_MONITOR_ON (0) //!< \~english Monitor on
+#define VIH_DISP_MONITOR_OFF (1) //!< \~english Monitor Off
+
+/* Illumination */
+#define VIH_DISP_ILLUMI_INIT (0) //!< \~english Not configured
+#define VIH_DISP_ILLUMI_DAY (1) //!< \~english Day screen
+#define VIH_DISP_ILLUMI_NIGHT (2) //!< \~english Night screen
+#define VIH_DISP_ILLUMI_FOURCE_DAY (3) //!< \~english Force day screen
+#define VIH_DISP_ILLUMI_FOURCE_NIGHT (4) //!< \~english Force night screen
+
+/* Auto dimmer */
+#define VIH_DISP_AUTO_DIMMER_OFF (0) //!< \~english Auto dimmer off
+#define VIH_DISP_AUTO_DIMMER_ON (1) //!< \~english Auto dimmer on
+
+/* MUTE */
+#define VIH_DISP_MUTE_OFF (0) //!< \~english Mute off
+#define VIH_DISP_MUTE_ON (1) //!< \~english Mute on
+
+/* Back light */
+#define VIH_DISP_BACKLIGHT_OFF (0) //!< \~english Back light off
+#define VIH_DISP_BACKLIGHT_ON (1) //!< \~english Back light on
+
+/* Type of video source */
+#define VIH_VIDEO_SOURCE_R_CAMERA (0x00) //!< \~english Rear video camera
+#define VIH_VIDEO_SOURCE_F_CAMERA (0x01) //!< \~english Front video camera
+#define VIH_VIDEO_SOURCE_S_CAMERA (0x02) //!< \~english Side video camera
+#define VIH_VIDEO_SOURCE_STOP (0x03) //!< \~english Stop the video
+#define VIH_VIDEO_SOURCE_DVD (0x04) //!< \~english DVD video
+#define VIH_VIDEO_SOURCE_BD (0x05) //!< \~english BD video
+#define VIH_VIDEO_SOURCE_DTV (0x06) //!< \~english DTV(Built-in)
+#define VIH_VIDEO_SOURCE_EXT_DTV (0x07) //!< \~english DTV(External)
+#define VIH_VIDEO_SOURCE_SD_VIDEO (0x08) //!< \~english SD video
+#define VIH_VIDEO_SOURCE_VTR (0x09) //!< \~english VTR(Built-in)
+#define VIH_VIDEO_SOURCE_VTR2 (0x0A) //!< \~english VTR2(Built-in)
+#define VIH_VIDEO_SOURCE_EXT_VTR (0x0B) //!< \~english VTR(External)
+#define VIH_VIDEO_SOURCE_EXT_NAVI (0x0C) //!< \~english NAVI(External)
+#define VIH_VIDEO_SOURCE_EXT (0x0D) //!< \~english Extension box
+#define VIH_VIDEO_SOURCE__CWORD57__VIDEO (0x0E) //!< \~english _CWORD57_(Video)
+#define VIH_VIDEO_SOURCE__CWORD57__OUT (0x0F) //!< \~english _CWORD57_(Out)
+#define VIH_VIDEO_SOURCE__CWORD57__NAVI (0x10) //!< \~english _CWORD57_(Navi)
+#define VIH_VIDEO_SOURCE_MIRRORLINK (0x11) //!< \~english Mirror link
+#define VIH_VIDEO_SOURCE_USB_VIDEO (0x12) //!< \~english USB video
+#define VIH_VIDEO_SOURCE_MIRACAST (0x16) //!< \~english Miracast
+#define VIH_VIDEO_SOURCE__CWORD27_ (0x17) //!< \~english _CWORD111_
+#define VIH_VIDEO_SOURCE_SD_VIDEO_CPRM (0x18) //!< \~english SD source(CPRM)
+#define VIH_VIDEO_SOURCE_SD_VIDEO_AVCHD (0x19) //!< \~english SD source(AVCHD)
+#define VIH_VIDEO_SOURCE_DIAG_CAMERA (0x1A) //!< \~english Camera diagnosis
+#define VIH_VIDEO_SOURCE_BLANK (0xFE) //!< \~english Blank
+
+/* Type of TV system */
+#define VIH_VIDEO_TVTYPE_NONE (0) //!< \~english Not configured
+#define VIH_VIDEO_TVTYPE_NTSC (1) //!< \~english NTSC
+#define VIH_VIDEO_TVTYPE_PAL (2) //!< \~english PAL
+#define VIH_VIDEO_TVTYPE_SECAM (3) //!< \~english SECAM
+#define VIH_VIDEO_TVTYPE_AUTO (255) //!< \~english Auto
+
+/* de-interlace */
+#define VIH_VIDEO_INTERLACE_DEFAULT (0) //!< \~english Interlaced(Default)
+#define VIH_VIDEO_INTERLACE_REPLICATE (1) //!< \~english Interlaced(Reprica)
+#define VIH_VIDEO_INTERLACE_WEAVE (2) //!< \~english Interlaced(Weave)
+#define VIH_VIDEO_INTERLACE_BOB (3) //!< \~english Interlaced(Bob)
+#define VIH_VIDEO_INTERLACE_AUTO (4) //!< \~english Interlaces(Auto)
+#define VIH_VIDEO_INTERLACE_LINE (5) //!< \~english Interlaces(Line)
+
+/* Aspect */
+#define VIH_VIDEO_ASPECT_NORMAL (0) //!< \~english Normal
+#define VIH_VIDEO_ASPECT_WIDE (1) //!< \~english Wide
+#define VIH_VIDEO_ASPECT_FULL (2) //!< \~english Full
+#define VIH_VIDEO_ASPECT_ZOOM (3) //!< \~english Zoom
+
+/* Aspect Ratio */
+#define VIH_VIDEO_ASPECT_RATIO_DEFAULT (0) //!< \~english Default
+#define VIH_VIDEO_ASPECT_RATIO_4_3 (1) //!< \~english 4:3
+#define VIH_VIDEO_ASPECT_RATIO_16_9 (2) //!< \~english 16:9
+#define VIH_VIDEO_ASPECT_RATIO_4_3_LB (3) //!< \~english 4:3(Letter box)
+
+/* Enable or disable */
+#define VIH_ENABLE (1) //!< \~english Enable
+#define VIH_DISABLE (0) //!< \~english Disable
+
+/* Send information: Control module */
+#define VIH_DISP_SEQ_CTRL 0x0003 //!< \~english Sequence control
+#define VIH_DISP_VCAP1_CTRL 0x0005 //!< \~english Video capture1 control
+#define VIH_DISP_VCAP2_CTRL 0x0006 //!< \~english Video capture2 control
+
+/* Message ID: Put or delete diagnosis code */
+#define VIH_DISP_MAIN_IND_PUTDIAG (0x5200) //!< \~english Put diagnosis code
+#define VIH_DISP_MAIN_IND_DELDIAG (0x5201) //!< \~english Delete diagnosis code
+
+/**
+ * \~english Event ID
+ */
+typedef enum TagVideoInHalEventID {
+ VIH_EVENT_ID_SOURCE, //!< \~english Display source change
+ VIH_EVENT_ID_QUALITY, //!< \~english Set quality(display)
+ VIH_EVENT_ID_VIDEOQUALITY, //!< \~english Set quality(video)
+ VIH_EVENT_ID_ASPECT, //!< \~english Set aspect
+ VIH_EVENT_ID_MONITOR, //!< \~english Set monitor(display)
+ VIH_EVENT_ID_VIDEOVISIBLE, //!< \~english Set video visible(video)
+ VIH_EVENT_ID_MUTE, //!< \~english Set mute
+ VIH_EVENT_ID_BACKLIGHT, //!< \~english Set backlight
+ VIH_EVENT_ID_NUM_MAX
+} VIH_EVENTID;
+
+/**
+ * \~english Control ID
+ */
+typedef enum TagVideoInHalControlID {
+ VIH_CONTROL_ID_SOURCE, //!< \~english Display source change
+ VIH_CONTROL_ID_QUALITY, //!< \~english Set quality(display)
+ VIH_CONTROL_ID_VIDEOQUALITY, //!< \~english Set quality(video)
+ VIH_CONTROL_ID_ASPECT, //!< \~english Set aspect
+ VIH_CONTROL_ID_MONITOR, //!< \~english Set monitor(display)
+ VIH_CONTROL_ID_VIDEOVISIBLE, //!< \~english Set video visible(video)
+ VIH_CONTROL_ID_START_CAPTURE, //!< \~english Start capture
+ VIH_CONTROL_ID_STOP_CAPTURE, //!< \~english Stop capture
+ VIH_CONTROL_ID_TVTYPE, //!< \~english Set TV type
+ VIH_CONTROL_ID_DEINTERLACE, //!< \~english Set de-interlace
+ VIH_CONTROL_ID_VMUTE, //!< \~english Set mute
+ VIH_CONTROL_ID_BACKLIGHT, //!< \~english Set backlight
+ VIH_CONTROL_ID_NUM_MAX
+} VIH_CONTROLID;
+
+/**
+ * \~english Type of video device's return value
+ */
+typedef enum TagVideoInHalRet {
+ VIH_RET_SUCCESS, //!< \~english OK
+ VIH_RET_INVALID_PARAMETER, //!< \~english Invalid parameter
+ VIH_RET_INTERNAL_ERROR, //!< \~english Internal error
+ VIH_RET_NUM_MAX
+} VIH_RET;
+
+/**
+ * \~english context kind
+ */
+typedef enum TagVideoInHalContext {
+ VIH_CONTEXT_DISP = 0, //!< \~english Display
+ VIH_CONTEXT_VIDEO, //!< \~english Video
+ VIH_CONTEXT_NUM_MAX
+} VIH_CONTEXT;
+
+/**
+ * \~english Display ID
+ */
+typedef enum TagVideoInHalDispIdx {
+ VIH_DISP_IDX_MONITOR0, //!< \~english Monitor0 (Front monitor)
+ VIH_DISP_IDX_MONITOR1, //!< \~english Monitor1 (Rear monitor)
+ VIH_DISP_IDX_MONITOR2, //!< \~english Monitor2
+ VIH_DISP_IDX_MONITOR3, //!< \~english Monitor3
+ VIH_DISP_IDX_MONITOR4, //!< \~english Monitor4
+ VIH_DISP_IDX_MONITOR5, //!< \~english Monitor5
+ VIH_DISP_IDX_NUM_MAX
+} VIH_DISP_IDX;
+
+/**
+ * \~english Video ID
+ */
+typedef enum TagVideoInHalVideoOut {
+ VIH_VIDEO_OUT_MONITOR0 = 0, //!< \~english Monitor0 (Front monitor)
+ VIH_VIDEO_OUT_MONITOR1, //!< \~english Monitor1 (Rear monitor)
+ VIH_VIDEO_OUT_MONITOR2, //!< \~english Monitor2
+ VIH_VIDEO_OUT_MONITOR3, //!< \~english Monitor3
+ VIH_VIDEO_OUT_MONITOR4, //!< \~english Monitor4
+ VIH_VIDEO_OUT_MONITOR5, //!< \~english Monitor5
+ VIH_VIDEO_OUT_NONE, //!< \~english Monitor none
+ VIH_VIDEO_OUT_NUM_MAX
+} VIH_VIDEO_OUT;
+
+/**
+ * \~english Structure for display tone color
+ */
+typedef struct TagVideoInHalDispTone {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_DISPTONE;
+
+/**
+ * \~english Structure for display tone hue
+ */
+typedef struct TagVideoInHalDispHue {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_DISPHUE;
+
+/**
+ * \~english Structure for display tone contrast
+ */
+typedef struct TagVideoInHalDispContrast {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_DISPCONTRAST;
+
+/**
+ * \~english Structure for display tone brightness
+ */
+typedef struct TagVideoInHalDispBrightness {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_DISPBRIGHTNESS;
+
+/**
+ * \~english Structure for display image quality parameters
+ */
+typedef struct TagVideoInHalDispParamSetUp {
+ u_int8_t source; //!< \~english Source type for quality setting
+ u_int8_t reserved[3]; //!< \~english Reserved
+ VIH_DISPTONE tone; //!< \~english Tone
+ VIH_DISPHUE hue; //!< \~english Hue
+ VIH_DISPCONTRAST contrast; //!< \~english Contrast
+ VIH_DISPBRIGHTNESS brightness; //!< \~english Brightness
+} VIH_DISP_PARAM_SETUP;
+
+/**
+ * \~english Structure for display parameters
+ */
+typedef struct TagVideoInHalDispParam {
+ u_int8_t monitor; //!< \~english Monitor state
+ u_int8_t reserve[3]; //!< \~english Reserve
+ VIH_DISP_PARAM_SETUP setup; //!< \~english Quality setting
+ u_int8_t illumi; //!< \~english Illumination
+ u_int8_t dimmer; //!< \~english Auto dimmer
+ u_int8_t mute; //!< \~english Mute
+ u_int8_t backlight; //!< \~english Back light
+} VIH_DISPPARAM;
+
+/**
+ * \~english Structure for video tone color
+ */
+typedef struct TagVideoInHalVideoTone {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_VIDEOTONE;
+
+/**
+ * \~english Structure for video tone hue
+ */
+typedef struct TagVideoInHalVideoHue {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_VIDEOHUE;
+
+/**
+ * \~english Structure for video tone contrast
+ */
+typedef struct TagVideoInHalVideoContrast {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_VIDEOCONTRAST;
+
+/**
+ * \~english Structure for video tone brightness
+ */
+typedef struct TagVideoInHalVideoBrightness {
+ int16_t day; //!< \~english Day screen
+ int16_t night; //!< \~english Night screen
+ int16_t force_day; //!< \~english Force day screen
+ int16_t force_night; //!< \~english Force night screen
+} VIH_VIDEOBRIGHTNESS;
+
+/**
+ * \~english Structure for video image quality parameters
+ */
+typedef struct TagVideoInHalVideoParamSetUp {
+ u_int8_t source; //!< \~english Source type for quality setting
+ u_int8_t reserve[3]; //!< \~english reserve
+ VIH_VIDEOTONE tone; //!< \~english Tone
+ VIH_VIDEOHUE hue; //!< \~english Hue
+ VIH_VIDEOCONTRAST contrast; //!< \~english Contrast
+ VIH_VIDEOBRIGHTNESS brightness; //!< \~english Brightness
+} VIH_VIDEO_PARAM_SETUP;
+
+/**
+ * \~english Structure for video position and angle
+ */
+typedef struct TagVideoInHalVideoPos {
+ u_int32_t aspect_x; //!< \~english Display position x
+ u_int32_t aspect_y; //!< \~english Display position y
+ u_int32_t aspect_w; //!< \~english Display width
+ u_int32_t aspect_h; //!< \~english Display height
+} VIH_VIDEOPOS;
+
+/**
+ * \~english Structure for video parameters
+ */
+typedef struct TagVideoInHalVideoParam {
+ u_int8_t source; //!< \~english Video Source
+ u_int8_t type; //!< \~english TV type
+ u_int8_t interlace; //!< \~english De-interlace
+ u_int8_t aspect; //!< \~english Aspect Value
+ VIH_VIDEOPOS angle; //!< \~english Angle
+ VIH_VIDEO_PARAM_SETUP setup; //!< \~english Quality setting
+ u_int8_t monitor; //!< \~english Monitor
+ u_int8_t mute; //!< \~english Mute
+ u_int8_t aspect_ratio; //!< \~english Aspect ratio
+ u_int8_t reserve; //!< \~english Reserve
+ u_int32_t window_priority; //!< \~english Window priority
+} VIH_VIDEOPARAM;
+
+/**
+ * \~english Structure for display identify
+ */
+typedef struct TagVideoInHalDispVideoID {
+ VIH_CONTEXT kind; //!< \~english Context type
+ struct timespec tp; //!< \~english Context create time
+} VIH_DISPVIDEOID;
+
+/**
+ * \~english Structure for display information
+ */
+typedef struct TagVideoInHalDispVideoInfo {
+ VIH_DISPVIDEOID context_id; //!< \~english Context identify
+ u_int32_t dsp_idx; //!< \~english Display index
+ u_int32_t chgflg; //!< \~english Setting change flag
+} VIH_DISPVIDEOINFO;
+
+/**
+ * \~english Structure for display context
+ */
+typedef struct TagVideoInHalDispMngCtx {
+ VIH_DISPVIDEOINFO info; //!< \~english Display information
+ VIH_DISPPARAM disp_param[VIH_DISP_IDX_NUM_MAX]; //!< \~english Display parameter
+ VIH_VIDEOPARAM video_param[VIH_VIDEO_OUT_NUM_MAX]; //!< \~english Video parameter
+} VIH_DISPMNGCTX;
+
+/**
+ * \~english Structure for diagnosis code data
+ */
+typedef struct TagVideoInHalGRMainReqDiagData {
+ uint64_t err_id; //!< \~english Error ID
+ uint16_t videoinhal_code; //!< \~english Code
+ uint8_t reserve1[2]; //!< \~english Reserve
+} VIH_GR_MAIN_REQ_DIAGDATA;
+
+
+/**
+ * \ingroup SendDiagCodeCallBack
+ * \~english @par Brief
+ * Send diagnosis code call back.
+ * \~english @param [in] snd_info
+ * u_int16_t - Send information
+ * \~english @param [in] msg_id
+ * u_int32_t - Message ID
+ * \~english @param [in] diag_data
+ * VIH_GR_MAIN_REQ_DIAGDATA* - Diagnosis code data
+ * \~english @par
+ * u_int16_t snd_info
+ * \~english @code
+ * VIH_DISP_SEQ_CTRL 0x0003 // Sequence control
+ * VIH_DISP_VCAP1_CTRL 0x0005 // Video capture1 control
+ * VIH_DISP_VCAP2_CTRL 0x0006 // Video capture2 control
+ * @endcode
+ * \~english @par
+ * u_int32_t msg_id
+ * \~english @code
+ * VIH_DISP_MAIN_IND_PUTDIAG (0x5200) // Put diagnosis code
+ * VIH_DISP_MAIN_IND_DELDIAG (0x5201) // Delete diagnosis code
+ * @endcode
+ * \~english @par
+ * VIH_GR_MAIN_REQ_DIAGDATA struct
+ * \~english @code
+ * typedef struct TagVideoInHalGRMainReqDiagData
+ * {
+ * uint64_t err_id; // Error ID
+ * uint16_t videoinhal_code; // Videoinhal code
+ * uint8_t reserve1[2]; // Reserve
+ * } VIH_GR_MAIN_REQ_DIAGDATA;
+ * @endcode
+ * \~english @retval 0 : OK
+ * \~english @retval -1 : Invalid parameter
+ * \~english @par Detail
+ * - Notify diagnosis code request to graphics_service.
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Conditions of processing failure
+ * - When input parameter diag_data is NULL, return with error. [-1]
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+typedef int (*SendDiagCodeCallBack)(u_int16_t snd_info, u_int32_t msg_id, VIH_GR_MAIN_REQ_DIAGDATA* diag_data);
+
+/**
+ * \ingroup InitVideo
+ * \~english @par Brief
+ * API to display device initialize.
+ * \~english @param [in] call_back
+ * SendDiagCodeCallBack - Send diagnosis trace code call back function
+ * \~english @retval VIH_RET_SUCCESS : OK
+ * \~english @retval VIH_RET_INVALID_PARAMETER : Invalid parameter
+ * \~english @par Detail
+ * - Display device initialize, init parameter and threads.
+ * - The API can only be used by 1 process.
+ * \~english @par Prerequisite
+ * - None
+ * \~english @par Conditions of processing failure
+ * - When display device driver can not be found, return with error. [VIH_RET_INVALID_PARAMETER]
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+VIH_RET InitVideo(SendDiagCodeCallBack call_back);
+
+/**
+ * \ingroup ControlVideo
+ * \~english @par Brief
+ * API to Control display device.
+ * \~english @param [in] pctx
+ * VIH_DISPMNGCTX* - Point of parameter used by control display device
+ * \~english @param [in] event_id
+ * VIH_EVENTID - Event ID
+ * \~english @param [in] control_id
+ * VIH_CONTROLID - Control ID
+ * \~english @par
+ * VIH_DISPMNGCTX struct
+ * \~english @code
+ * typedef struct TagVideoInHalDispMngCtx
+ * {
+ * VIH_DISPVIDEOINFO info; // Information of display
+ * VIH_DISPPARAM disp_param[VIH_DISP_IDX_NUM_MAX]; // Paramter of diaplay
+ * VIH_VIDEOPARAM video_param[VIH_VIDEO_OUT_NUM_MAX]; // Paramter of video
+ * } VIH_DISPMNGCTX;
+ * @endcode
+ * \~english @par
+ * VIH_EVENTID enum
+ * \~english @code
+ * typedef enum TagVideoInHalEventID
+ * {
+ * VIH_EVENT_ID_SOURCE, // Display source change
+ * VIH_EVENT_ID_QUALITY, // Set quality(display)
+ * VIH_EVENT_ID_VIDEOQUALITY, // Set quality(video)
+ * VIH_EVENT_ID_ASPECT, // Set aspect
+ * VIH_EVENT_ID_MONITOR, // Set monitor(display)
+ * VIH_EVENT_ID_VIDEOVISIBLE, // Set video visible(video)
+ * VIH_EVENT_ID_MUTE, // Set mute
+ * VIH_EVENT_ID_BACKLIGHT, // Set backlight
+ * VIH_EVENT_ID_NUM_MAX
+ * } VIH_EVENTID;
+ * @endcode
+ * \~english @par
+ * VIH_CONTROLID enum
+ * \~english @code
+ * typedef enum TagVideoInHalControlID
+ * {
+ * VIH_CONTROL_ID_SOURCE, // Display source change
+ * VIH_CONTROL_ID_QUALITY, // Set quality(display)
+ * VIH_CONTROL_ID_VIDEOQUALITY, // Set quality(video)
+ * VIH_CONTROL_ID_ASPECT, // Set aspect
+ * VIH_CONTROL_ID_MONITOR, // Set monitor(display)
+ * VIH_CONTROL_ID_VIDEOVISIBLE, // Set video visible(video)
+ * VIH_CONTROL_ID_START_CAPTURE, // Start capture
+ * VIH_CONTROL_ID_STOP_CAPTURE, // Stop capture
+ * VIH_CONTROL_ID_TVTYPE, // Set TV type
+ * VIH_CONTROL_ID_DEINTERLACE, // Set de-interlace
+ * VIH_CONTROL_ID_VMUTE, // Set mute
+ * VIH_CONTROL_ID_BACKLIGHT, // Set backlight
+ * VIH_CONTROL_ID_NUM_MAX
+ * } VIH_CONTROLID;
+ * @endcode
+ * \~english @retval VIH_RET_SUCCESS : OK
+ * \~english @retval VIH_RET_INVALID_PARAMETER : Invalid parameter
+ * \~english @retval VIH_RET_INTERNAL_ERROR : Internal error
+ * \~english @par Detail
+ * - Control display device. Include display source, quality(display), quality(video), aspect , monitor, video visible, start capture, stop capture, mute, backlight, TV type, de-interlace.
+ * - The API can only be used by 1 process.
+ * \~english @par Prerequisite
+ * - Call InitVideo()
+ * \~english @par Conditions of processing failure
+ * - The point param is null [VIH_RET_INVALID_PARAMETER]
+ * - The display driver return error [VIH_RET_INTERNAL_ERROR]
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Fire and Forget
+ * \~english @see
+ * None
+ */
+VIH_RET ControlVideo(VIH_DISPMNGCTX* pctx, VIH_EVENTID event_id, VIH_CONTROLID control_id);
+
+/**
+ * \ingroup TerminateVideo
+ * \~english @par Brief
+ * API to display device Terminate.
+ * \~english @param None
+ * \~english @retval VIH_RET_SUCCESS : OK
+ * \~english @par Detail
+ * - Display device Terminate, init parameter.
+ * - The API can only be used by 1 process.
+ * \~english @par Prerequisite
+ * - Call InitVideo().
+ * \~english @par Conditions of processing failure
+ * - None
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @see
+ * None
+ */
+VIH_RET TerminateVideo();
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @}*/ //!< end of video_in_hal
+/** @}*/ //!< end of graphics_service
+
+#endif // HAL_API_VIDEO_IN_HAL_H_
diff --git a/hal/video_in_hal/src/video_in_hal.c b/hal/video_in_hal/src/video_in_hal.c
new file mode 100755
index 0000000..b639a83
--- /dev/null
+++ b/hal/video_in_hal/src/video_in_hal.c
@@ -0,0 +1,50 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Information.
+ * This source code is a sample source code .
+ * Implementation of the function must be performed by the vendor.
+ */
+
+#include "video_in_hal.h"
+
+VIH_RET InitVideo(SendDiagCodeCallBack call_back)
+{
+ /*
+ * Note.
+ * This feature needs to be implemented by the vendor.
+ */
+ return VIH_RET_SUCCESS;
+}
+
+VIH_RET ControlVideo(VIH_DISPMNGCTX* pctx, VIH_EVENTID event_id, VIH_CONTROLID control_id)
+{
+ /*
+ * Note.
+ * This feature needs to be implemented by the vendor.
+ */
+ return VIH_RET_SUCCESS;
+}
+
+VIH_RET TerminateVideo()
+{
+ /*
+ * Note.
+ * This feature needs to be implemented by the vendor.
+ */
+ return VIH_RET_SUCCESS;
+}