summaryrefslogtreecommitdiffstats
path: root/usb_hal/hal_api/usb_hal.h
blob: 9f93d9b34dbba9807dc824b43f0bb7a2a9d2cd4a (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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
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_