2 * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef HAL_API_CAN_HAL_H_
17 #define HAL_API_CAN_HAL_H_
22 /** @addtogroup communication
25 /** @addtogroup can_hal
26 * @ingroup communication
30 #include <native_service/frameworkunified_types.h>
34 * \~english Max data length of nomarl can send
36 #define CAN_NORMAL_MESSAGE_LEN (8)
39 * \~english Maximum data length
41 #define CAN_MESSAGE_LEN (2048)
44 * \~english Maximum CAN_ID data length
46 #define CAN_NUM_MAX (125)
49 * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_CAN_SEND_STATUS, CANHalSndStsProcess);
51 * \~english Command ID to send CAN data and get the send status
53 #define CID_CANHAL_CMD_CAN_SEND_STATUS (0x0A03)
56 * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_CAN_RECV, CANHalRcvProcess);
58 * \~english Command ID to receive the CAN data
60 #define CID_CANHAL_CMD_CAN_RECV (0x0A04)
63 * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_CAN_READY, AnyCallback);
65 * \~english Command ID to receive Global CAN is ready.
67 #define CID_CANHAL_CMD_CAN_READY (0x0A0C)
70 * l_eStatus = FrameworkUnifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, CID_CANHAL_CMD_ERROR_NOTIFY, AnyCallback);
72 * \~english Command ID to receive can hal error.
74 #define CID_CANHAL_CMD_ERROR_NOTIFY (0x0A10)
77 * \~english No target address
79 #define CAN_NTA_NONE (0x00)
82 * \~english Size of error message.
84 #define CANHAL_ERROR_MESSAGE_LEN (2048)
87 * \~english Return type of the API
90 CANHAL_RET_NORMAL = 0, //!< \~english API Success
91 CANHAL_RET_ERR_ERR, //!< \~english API Failed
92 CANHAL_RET_ERR_PARAM, //!< \~english Parameter error
93 CANHAL_RET_ERR_STATE, //!< \~english Uninitialized(not called CanOpen)
100 CAN_HAL_TYPE_CAN = 0, //!< \~english CAN
101 NR_CAN_HAL_TYPES //!< \~english Number of CAN type
105 * \~english device State
108 DEVICE_STATE_UNAVAILABLE, //!< \~english device unavailable
109 DEVICE_STATE_AVAILABLE, //!< \~english device available
113 * \~english CAN Send Result
115 enum CAN_SEND_RESULT {
116 CAN_SEND_RESULT_FAILURE = 0, //!< \~english Send failure
117 CAN_SEND_RESULT_SUCCESS, //!< \~english Send success
121 * \~english structure of can data
123 typedef struct CanMessageT {
124 uint32_t can_id; //!< \~english Target CAN ID
125 uint32_t dlc; //!< \~english Data length(1~2048)
126 uint8_t rid; //!< \~english Replay ID
127 uint8_t data[CAN_MESSAGE_LEN]; //!< \~english Data buffer
131 * \~english structure of can send result
133 typedef struct CanSendResultT {
134 uint32_t can_id; //!< \~english CAN ID
135 uint8_t rid; //!< \~english RID
136 CAN_SEND_RESULT result; //!< \~english Send result
145 * \~english @par Brief
146 * API to start the can_hal service
147 * \~english @param [in] h_app
148 * HANDLE - Application handle
149 * \~english @param [in] type
150 * CanHalType - CAN type
151 * \~english @retval CANHAL_RET_NORMAL : API return OK
152 * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
153 * \~english @retval CANHAL_RET_ERR_ERR : Failed
154 * \~english @par Prerequisite
156 * \~english @par Change of internal state
157 * - When calling of this API succeeds, the requested channel state is set to open.
158 * \~english @par Conditions of processing failure
159 * - Input paramter is invalid.
160 * - Internal processing failure.
161 * \~english @par Classification
163 * \~english @par Type
165 * \~english @par Detail
166 * - Perform device use preparation processing of the requested communication path.
167 * - Up to one process can use this library.
171 CANHAL_RET_API CanOpen(HANDLE h_app, CanHalType type);
175 * \~english @par Brief
176 * API to stop the can_hal service
177 * \~english @param [in] h_app
178 * HANDLE - Application handle
179 * \~english @param [in] type
180 * CanHalType - CAN type
181 * \~english @retval CANHAL_RET_NORMAL : API return OK
182 * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
183 * \~english @retval CANHAL_RET_ERR_ERR : Failed
184 * \~english @retval CANHAL_RET_ERR_STATE : Failed because CanOpen is not called
185 * \~english @par Prerequisite
186 * Communication path status is open
187 * \~english @par Change of internal state
188 * - In the case of normal termination, the requested channel state is close.
189 * \~english @par Conditions of processing failure
190 * - CanOpen is not called.
191 * - Input paramter is invalid.
192 * - Internal processing failure.
193 * \~english @par Classification
195 * \~english @par Type
197 * \~english @par Detail
198 * - Perform device use finalize processing of the requested communication path.
199 * - Up to one process can use this library.
203 CANHAL_RET_API CanClose(HANDLE h_app, CanHalType type);
207 * \~english @par Brief
208 * API to send the Can data
209 * \~english @param [in] h_app
210 * HANDLE - Application handle
211 * \~english @param [in] message
212 * const CanMessage * - Pointer to the structure of
213 * the data which is sent to the CAN
214 * \~english @param [in] type
215 * CanHalType - CAN type
216 * \~english @retval CANHAL_RET_NORMAL : API return OK
217 * \~english @retval CANHAL_RET_ERR_ERR : Failed
218 * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
219 * \~english @retval CANHAL_RET_ERR_STATE : Failed because CanOpen is not called
220 * \~english @par Prerequisite
221 * - can_hal start successfully
222 * \~english @par Change of internal state
223 * - Change of internal state according to the API does not occur.
224 * \~english @par Conditions of processing failure
225 * - Input paramter is invalid.
226 * - CanOpen is not called.
227 * - Send data to the sending thread failed.
228 * \~english @par Classification
230 * \~english @par Type
232 * \~english @par Detail
233 * - Check the sending data, if data is valid, then send the data
234 * to the sending thread; If data if invalid, then return error.
235 * - The API can only be used by 1 process.
239 CANHAL_RET_API CanSend(HANDLE h_app, const CanMessage *message, CanHalType type);
242 * \ingroup CanGetVersion
243 * \~english @par Brief
244 * API to get the CAN micon version
245 * \~english @param [in] h_app
246 * HANDLE - Application handle
247 * \~english @param [out] p_version
248 * std::string * - Pointer to the version buffer
249 * \~english @retval CANHAL_RET_NORMAL : API return OK
250 * \~english @retval CANHAL_RET_ERR_STATE : Failed because CanOpen is not called
251 * \~english @retval CANHAL_RET_ERR_PARAM : Paramter error
252 * \~english @retval CANHAL_RET_ERR_ERR : Failed
253 * \~english @par Prerequisite
254 * - can_hal start successfully
255 * \~english @par Change of internal state
256 * - Change of internal state according to the API does not occur.
257 * \~english @par Conditions of processing failure
258 * - Input paramter is invalid.
259 * - CanOpen is not called.
260 * \~english @par Classification
262 * \~english @par Type
264 * \~english @par Detail
265 * - This API gets the CAN version.
266 * - The API can only be used by 1 process.
267 * - p_version detail\n
268 * Information on the following pink shaded part 4 BYTE in the version information \n
269 * of the CAN microcomputer is stored in string and returned.\n
272 * <th></th><th>7bit-0bit</th>
275 * <td>1BYTE</td><td>7bit:M/S 6-0bit:Message kind</td>
278 * <td>2BYTE</td><td>7bit-0bit Operation Code</td>
281 * <td>3BYTE</td><td bgcolor="pink">7bit-0bit Software kind</td>
284 * <td>4BYTE</td><td bgcolor="pink">7bit-0bit version(Higher order)</td>
287 * <td>5BYTE</td><td bgcolor="pink">7bit-0bit version(middle order)</td>
290 * <td>6BYTE</td><td bgcolor="pink">7bit-0bit version(lower order)</td>
296 CANHAL_RET_API CanGetVersion(HANDLE h_app, std::string *p_version);
298 /** @}*/ // end of can_hal
299 /** @}*/ // end of communication
303 #endif // HAL_API_CAN_HAL_H_