hif_hal.h
15.6 KB
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#ifndef __HIF_HAL_H__
/* !ignore me! */
#define __HIF_HAL_H__
#include "kal_general_types.h"
#include "drv_features.h"
#ifdef DRV_HIF_SUPPORT
/* <GROUP CallBackFunctions>
FUNCTION
HIF_CALLBACK
DESCRIPTION
HIF callback function
HIF callback function is called when HIF interrupt has arrived. It indicates HIF has finished the last data transfer.
HIF callback function is called in the context of HISR.
*/
typedef void (*HIF_CALLBACK)(void);
/* HIF Handle.
HIF handle can be retrieved from hif_open(). It is used for most HIF APIs.
*/
typedef kal_uint32 HIF_HANDLE;
/* HIF transfer type.
Defines the transfer type of HIF interface.
*/
typedef enum
{
/* HIF transfer with A0=1. Use CPU to move data. */
HIF_TYPE_A0H_CPU,
/* HIF transfer with A0=1. Use DMA to transfer data. */
HIF_TYPE_A0H_DMA,
/* HIF transfer with A0=0. Use CPU to move data. */
HIF_TYPE_A0L_CPU,
/* HIF transfer with A0=0. Use DMA to transfer data. */
HIF_TYPE_A0L_DMA,
} HIF_TYPE;
/* HIF result enum.
*/
typedef enum
{
/* Indicates no error occurs in the last operation. */
HIF_RESULT_OK,
/* Indicates some errors have occured in the last operation. */
HIF_RESULT_ERROR,
/* Indicates the function is not supported on the current platform. */
HIF_RESULT_NOT_SUPPORTED,
/* Indicates the HIF handle is not valid. */
HIF_RESULT_INVALID_HANDLE,
/* Indicates the input argument is not valid. */
HIF_RESULT_INVALID_ARGUMENT,
/* Indicates that the HIF power was not turned on when making HIF transactions. */
HIF_RESULT_HIF_NOT_POWER_ON,
/* Indicates that the HIF power was not turned on when making HIF transactions. */
HIF_RESULT_DMA_IS_BUSY
} HIF_RESULT;
/*************************************************************************************************************************************
* HIF IOCTL code definition.
* For detail description and usage of HIF control codes, please refer to <xref target="HIF HAL IOCTL Code" text="HIF IOCTL Code" />.
*************************************************************************************************************************************/
typedef enum
{
/****************************************************************************************************************
* Get the current HIF configuration parameters.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_GET_PARAM" />.
****************************************************************************************************************/
HIF_IOCTL_GET_PARAM,
/****************************************************************************************************************
* Set ultra high control for HIF.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_ULTRA_HIGH_CTRL" />.
****************************************************************************************************************/
HIF_IOCTL_ULTRA_HIGH_CTRL,
/****************************************************************************************************************
* Query HIF timing support.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_TIMING_SUPPORT" />.
****************************************************************************************************************/
HIF_IOCTL_QUERY_TIMING_SUPPORT,
/****************************************************************************************************************
* Query HIF capabilities.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_CAPABILITY" />.
****************************************************************************************************************/
HIF_IOCTL_QUERY_CAPABILITY,
/****************************************************************************************************************
* Query HIF clock support.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_CLOCK_SUPPORT" />.
****************************************************************************************************************/
HIF_IOCTL_QUERY_CLOCK_SUPPORT,
/****************************************************************************************************************
* Query HIF power state.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_POWER_STATE" />.
****************************************************************************************************************/
HIF_IOCTL_QUERY_POWER_STATE,
/****************************************************************************************************************
* TD realtime support.
* For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_REALTIME_REQUEST" />.
****************************************************************************************************************/
HIF_IOCTL_REALTIME_CALLBACK
} HIF_IOCTL_CODE;
/**********************************
* HIF configuration parameters.
*
* Remarks
* <img name="hif_write_timing" />
*
* <img name="hif_read_timing" />
**********************************/
typedef struct
{
/* Chip Select (LPCE#) to Write Strobe (LWR#) setup time. */
kal_uint32 hif_time_c2ws;
/* Chip Select (LPCE#) to Write Strobe (LWR#) hold time. */
kal_uint32 hif_time_c2wh;
/* Write wait state time. */
kal_uint32 hif_time_wst;
/* Chip Select (LPCE#) to Read Strobe (LRD#) setup time. */
kal_uint32 hif_time_c2rs;
/* Chip Select (LPCE#) to Read Strobe (LRD#) hold time. */
kal_uint32 hif_time_c2rh;
/* Read latency time. */
kal_uint32 hif_time_rlt;
/* Chip Select high width. */
kal_uint32 hif_time_chw;
/* HIF base clock. Unit in MHz. */
kal_uint32 hif_base_clk;
/* HIF bus width. */
kal_uint32 hif_bus_width;
} HIF_CONFIG_T;
/* This structure is used as the parameter of HIF_IOCTL_QUERY_TIMING_SUPPORT.
*/
typedef struct
{
/* Indicates whether C2WS is supported. */
kal_bool c2ws_support;
/* Indicates whether C2WH is supported. */
kal_bool c2wh_support;
/* Indicates whether WST is supported. */
kal_bool wst_support;
/* Indicates whether C2RS is supported. */
kal_bool c2rs_support;
/* Indicates whether C2RH is supported. */
kal_bool c2rh_support;
/* Indicates whether CHW is supported. */
kal_bool chw_support;
/* Indicates whether RLT is supported. */
kal_bool rlt_support;
} HIF_QUERY_TIMING_SUPPORT_T;
/* This structure is used as the parameter of HIF_IOCTL_QUERY_CLOCK_SUPPORT.
*/
typedef struct
{
/* This array contains the supported clock frequencies. Unit in MHz. Value 0 indicates invalid clock frequency.*/
kal_uint32 clock[4];
} HIF_QUERY_CLOCK_SUPPORT_T;
/* This structure is used as the parameter of HIF_IOCTL_QUERY_CAPABILITY.
*/
typedef struct
{
/* Minimum value for HIF transfer length. */
kal_uint32 transfer_length_min;
/* Maximum value for HIF transfer length. */
kal_uint32 transfer_length_max;
} HIF_CAPABILITY_T;
/* This structure is used as the parameter of HIF_IOCTL_ULTRA_HIGH_CTRL.
*/
typedef struct
{
/* Enable ultra high signal during HIF transaction. */
kal_bool ultra_high_en;
} HIF_ULTRA_HIGH_CTRL_T;
/* This structure is used as the parameter of HIF_IOCTL_QUERY_POWER_STATE.
*/
typedef struct
{
/* HIF power state. */
kal_bool hif_power_on;
} HIF_POWER_STATE_T;
/* This structure is used as the parameter of HIF_IOCTL_REALTIME_CALLBACK.
*/
typedef struct
{
/* Enable realtime request,Call HIF callback function(hif_hisr) at LISR level. */
kal_bool realtime_callback_en;
} HIF_REALTIME_CALLBACK_T;
/**************************************************************************************************************************************
* Function
* hif_init
* Description
* Initialize HIF hardware and structures.
* Returns
* None.
* Remarks
* <color Red>This function is called in system initialization. HIF user does not need to call this function.</color>
**************************************************************************************************************************************/
void hif_init(void);
/**************************************************************************************************************************************
* Function
* hif_open
* Description
* Open and get HIF handle.
* Parameters
* port : [IN] HIF port. Zero based port index.
* Returns
* Return a HIF handle.
* Example
* <code>
* HIF_HANDLE handle;
* handle = hif_open(0);
* </code>
**************************************************************************************************************************************/
HIF_HANDLE hif_open(kal_uint32 port);
/********************************************************
* Function
* hif_close
* Description
* Release a HIF handle.
* Parameters
* handle : [IN] HIF handle. Retrieved from hif_open().
* Returns
* Return a HIF result code.
* Example
* <code>
* HIF_HANDLE handle;
* handle = hif_open(0);
* // HIF operations.
* hif_close(handle);
* </code>
********************************************************/
HIF_RESULT hif_close(HIF_HANDLE handle);
/***********************************************************************
* Function
* hif_config
* Description
* Configure HIF timing parameters.
* HIF parameters must be set before any HIF transmissions.
* Parameters
* handle : [IN] HIF handle. Retrieved from hif_open().
* pConfigParam : [IN] HIF parameters. Refer to HIF_CONFIG_T for details.
* Returns
* Return a HIF result code.
* Example
* <code>
* HIF_HANDLE handle;
* HIF_CONFIG_T hif_config_param;
* handle = hif_open(0);
* hif_config_param.hif_time_c2ws = 3;
* hif_config_param.hif_time_c2wh = 2;
* hif_config_param.hif_time_wst = 15;
* hif_config_param.hif_time_c2rs = 4;
* hif_config_param.hif_time_c2rh = 0;
* hif_config_param.hif_time_rlt = 0x1f;
* hif_config_param.hif_base_clk = 122;
* hif_config_param.hif_bus_width = 16;
* hif_config(handle, &hif_config_param);
* // ...
* hif_close(handle);
* </code>
***********************************************************************/
HIF_RESULT hif_config(HIF_HANDLE handle, HIF_CONFIG_T* pConfigParam);
/*******************************************************************************
* Function
* hif_write
* Description
* Fire a HIF transmission for output.
* Parameters
* handle : [IN] HIF handle. Retrieved from hif_open().
* type : [IN] HIF transfer type. Refer to HIF_TYPE for details.
* addr : [IN] Data buffer address for output.
* size : [IN] Data length for HIF transfer. Unit in bytes.
* fCB : [IN] Specifies the callback function when the transmission completes.
* If fCB is specified, HIF driver uses interrupt mode. This API is asynchronous.
* If fCB is NULL, HIF drvier uses polling mode. This API becomes synchronous.
* Returns
* Return a HIF result code.
* Remarks
* If type is set to HIF_TYPE_A0H_CPU or HIF_TYPE_A0L_CPU, fCB is ignored. HIF driver works synchronous in CPU mode.
* Example
* <code>
* HIF_HANDLE handle;
* handle = hif_open(0);
* // ...
*
* // Synchronous call.
* hif_write(handle, HIF_TYPE_A0H_CPU, hif_test_buffer, 1024, NULL);
*
* // Asynchronous call.
* hif_write(handle, HIF_TYPE_A0H_DMA, hif_test_buffer, 1024, hif_test_cb);
* // Wait for a event which is set in callback function.
* // ...
* hif_close(handle);
* </code>
*******************************************************************************/
HIF_RESULT hif_write(HIF_HANDLE handle, HIF_TYPE type, kal_uint32 addr, kal_uint32 size, HIF_CALLBACK fCB);
/*******************************************************************************
* Function
* hif_read
* Description
* Fire a HIF transmission for input.
* Parameters
* handle : [IN] HIF handle. Retrieved from hif_open().
* type : [IN] HIF transfer type. Refer to HIF_TYPE for details.
* addr : [IN] Data buffer address for input.
* size : [IN] Data length for HIF transfer. Unit in bytes.
* fCB : [IN] Specifies the callback function when the transmission completes.
* If fCB is specified, HIF driver uses interrupt mode. This API is asynchronous.
* If fCB is NULL, HIF drvier uses polling mode. This API becomes synchronous.
* Returns
* Return a HIF result code.
* Remarks
* If type is set to HIF_TYPE_A0H_CPU or HIF_TYPE_A0L_CPU, fCB is ignored. HIF driver works synchronous in CPU mode.
* Example
* <code>
* HIF_HANDLE handle;
* handle = hif_open(0);
* // ...
*
* // Synchronous call.
* hif_read(handle, HIF_TYPE_A0H_CPU, hif_test_buffer, 1024, NULL);
*
* // Asynchronous call.
* hif_read(handle, HIF_TYPE_A0H_DMA, hif_test_buffer, 1024, hif_test_cb);
* // Wait for a event which is set in callback function.
* // ...
* hif_close(handle);
* </code>
*******************************************************************************/
HIF_RESULT hif_read(HIF_HANDLE handle, HIF_TYPE type, kal_uint32 addr, kal_uint32 size, HIF_CALLBACK fCB);
/*****************************************************************************
* Function
* hif_power_ctrl
* Description
* Enable or disable HIF hardware power.
* Parameters
* handle : [IN] HIF handle. Retrieved from hif_open().
* bPowerOn : [IN] Set KAL_TRUE to power on HIF hardware. Set KAL_FALSE to power off HIF hardware.
* Returns
* Return a HIF result code.
* Example
* <code>
* HIF_HANDLE handle;
* handle = hif_open(0);
* hif_power_ctrl(handle, KAL_TRUE);
* // HIF operations.
* hif_power_ctrl(handle, KAL_FALSE);
* hif_close(handle);
* </code>
*****************************************************************************/
HIF_RESULT hif_power_ctrl(HIF_HANDLE handle, kal_bool bPowerOn);
/*****************************************************************************
* Function
* hif_ioctl
* Description
* IO Control for HIF driver.
* A series of HIF control code is defined for extension usage. Refer to HIF_IOCTL_CODE.
* Parameters
* handle : [IN] HIF handle. Retrieved from hif_open().
* code : [IN] HIF control code. Refer to HIF_IOCTL_CODE.
* pParam : [IN/OUT] Parameter for HIF IO Control. The definition depends on the specified control code. Refer to HIF_IOCTL_CODE.
* Returns
* Return a HIF result code.
* The return value is HIF_RESULT_NOT_SUPPORTED if the current platform does not support the sepcific control code.
* Example
* <code>
* HIF_HANDLE handle;
* HIF_CONFIG_T config;
* handle = hif_open(0);
* hif_ioctl(handle, HIF_IOCTL_GET_PARAM, &config);
* hif_close(handle);
* </code>
*****************************************************************************/
HIF_RESULT hif_ioctl(HIF_HANDLE handle, HIF_IOCTL_CODE code, void* pParam);
HIF_RESULT hif_mcu_write_fast(HIF_HANDLE handle, HIF_TYPE type, kal_uint32 addr, kal_uint32 size);
HIF_RESULT hif_mcu_read_fast(HIF_HANDLE handle, HIF_TYPE type, kal_uint32 addr, kal_uint32 size);
#endif
#endif