summaryrefslogtreecommitdiffstats
path: root/can_hal/hal_api/can_hal.h
blob: 5f3ef4fa1af488da2ccccd5b0064a26d58b9a856 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
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_