aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortakeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp>2020-10-21 13:34:46 +0900
committertakeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp>2020-10-21 13:34:46 +0900
commit99be467019cb2951e1a97544eb87602d997d215b (patch)
tree74a3e903293f45ab57411cb238106e5835a00c0a
parent706ad73eb02caf8532deaf5d38995bd258725cb8 (diff)
-rw-r--r--LICENSE177
-rw-r--r--Makefile19
-rw-r--r--README.md3
-rw-r--r--can_hal.mk39
-rw-r--r--hal_api/can_hal.h303
-rw-r--r--src/Makefile52
-rw-r--r--src/can_hal_api.cpp166
-rw-r--r--src/can_hal_core.cpp372
-rw-r--r--src/can_hal_stm.cpp243
-rw-r--r--src/driver_can__CWORD31_.c472
-rw-r--r--src/inc/can_hal_core.h37
-rw-r--r--src/inc/can_hal_frameworkunifiedlog.h76
-rw-r--r--src/inc/can_hal_internal.h31
-rw-r--r--src/inc/can_hal_stm.h45
-rw-r--r--src/inc/can_mng_api.h120
15 files changed, 2155 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..f433b1a5
--- /dev/null
+++ b/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/Makefile b/Makefile
new file mode 100644
index 00000000..61e5cc2c
--- /dev/null
+++ b/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/README.md b/README.md
new file mode 100644
index 00000000..e1a5e841
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+can_hal library
+==================
+CAN HAL implementation library for AGL Reference Board.
diff --git a/can_hal.mk b/can_hal.mk
new file mode 100644
index 00000000..19a824d0
--- /dev/null
+++ b/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_api/can_hal.h b/hal_api/can_hal.h
new file mode 100644
index 00000000..5f3ef4fa
--- /dev/null
+++ b/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/src/Makefile b/src/Makefile
new file mode 100644
index 00000000..f34eb759
--- /dev/null
+++ b/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/src/can_hal_api.cpp b/src/can_hal_api.cpp
new file mode 100644
index 00000000..86a0104d
--- /dev/null
+++ b/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/src/can_hal_core.cpp b/src/can_hal_core.cpp
new file mode 100644
index 00000000..bdbdbbce
--- /dev/null
+++ b/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/src/can_hal_stm.cpp b/src/can_hal_stm.cpp
new file mode 100644
index 00000000..fc24964a
--- /dev/null
+++ b/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/src/driver_can__CWORD31_.c b/src/driver_can__CWORD31_.c
new file mode 100644
index 00000000..bd9cb291
--- /dev/null
+++ b/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/src/inc/can_hal_core.h b/src/inc/can_hal_core.h
new file mode 100644
index 00000000..57a9c9d8
--- /dev/null
+++ b/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/src/inc/can_hal_frameworkunifiedlog.h b/src/inc/can_hal_frameworkunifiedlog.h
new file mode 100644
index 00000000..f3a5f500
--- /dev/null
+++ b/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/src/inc/can_hal_internal.h b/src/inc/can_hal_internal.h
new file mode 100644
index 00000000..f42a73f7
--- /dev/null
+++ b/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/src/inc/can_hal_stm.h b/src/inc/can_hal_stm.h
new file mode 100644
index 00000000..cd078140
--- /dev/null
+++ b/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/src/inc/can_mng_api.h b/src/inc/can_mng_api.h
new file mode 100644
index 00000000..ef03750f
--- /dev/null
+++ b/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__ */