VSF Documented
vsf_template_hal_driver.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
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 *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
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. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_TEMPLATE_COMMON_H__
19#define __VSF_TEMPLATE_COMMON_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28/*============================ MACROS ========================================*/
29/*============================ MACROFIED FUNCTIONS ===========================*/
30
31#define VSF_HAL_TEMPLATE_API_OP(__prefix_name, __return, __module__, __name, __first_args, ...) \
32 .__name = (__return (*)( VSF_MCONNECT(vsf, _, __module__, _t) *, ##__VA_ARGS__ ))& VSF_MCONNECT(__prefix_name, _, __module__, _, __name),
33
34#define VSF_HAL_TEMPLATE_API_FP(__prefix_name, __return, __module__, __name, __first_args, ...) \
35 __return (* __name )( __first_args, ##__VA_ARGS__ );
36
37#define VSF_HAL_TEMPLATE_API_EXTERN(__prefix_name, __return, __module__, __name, __first_args, ...) \
38 extern __return VSF_MCONNECT(__prefix_name, _, __module__, _, __name)( __first_args, ##__VA_ARGS__ );
39
40#define VSF_HAL_TEMPLATE_API_DEFINE(__prefix_name, __return, __module__, __name, __first_args, ...) \
41 __return VSF_MCONNECT(__prefix_name, _, __module__, _, __name)( __first_args, ##__VA_ARGS__ )
42
43#define __VSF_HAL_COUNT_TO_MASK(__CNT) \
44 ((0x1ull << (__CNT > 0x00 ? 0x00 : 0)) | \
45 (0x1ull << (__CNT > 0x01 ? 0x01 : 0)) | \
46 (0x1ull << (__CNT > 0x02 ? 0x02 : 0)) | \
47 (0x1ull << (__CNT > 0x03 ? 0x03 : 0)) | \
48 (0x1ull << (__CNT > 0x04 ? 0x04 : 0)) | \
49 (0x1ull << (__CNT > 0x05 ? 0x05 : 0)) | \
50 (0x1ull << (__CNT > 0x06 ? 0x06 : 0)) | \
51 (0x1ull << (__CNT > 0x07 ? 0x07 : 0)) | \
52 (0x1ull << (__CNT > 0x08 ? 0x08 : 0)) | \
53 (0x1ull << (__CNT > 0x09 ? 0x09 : 0)) | \
54 (0x1ull << (__CNT > 0x0A ? 0x0A : 0)) | \
55 (0x1ull << (__CNT > 0x0B ? 0x0B : 0)) | \
56 (0x1ull << (__CNT > 0x0C ? 0x0C : 0)) | \
57 (0x1ull << (__CNT > 0x0D ? 0x0D : 0)) | \
58 (0x1ull << (__CNT > 0x0E ? 0x0E : 0)) | \
59 (0x1ull << (__CNT > 0x0F ? 0x0F : 0)) | \
60 (0x1ull << (__CNT > 0x10 ? 0x10 : 0)) | \
61 (0x1ull << (__CNT > 0x11 ? 0x11 : 0)) | \
62 (0x1ull << (__CNT > 0x12 ? 0x12 : 0)) | \
63 (0x1ull << (__CNT > 0x13 ? 0x13 : 0)) | \
64 (0x1ull << (__CNT > 0x14 ? 0x14 : 0)) | \
65 (0x1ull << (__CNT > 0x15 ? 0x15 : 0)) | \
66 (0x1ull << (__CNT > 0x16 ? 0x16 : 0)) | \
67 (0x1ull << (__CNT > 0x17 ? 0x17 : 0)) | \
68 (0x1ull << (__CNT > 0x18 ? 0x18 : 0)) | \
69 (0x1ull << (__CNT > 0x19 ? 0x19 : 0)) | \
70 (0x1ull << (__CNT > 0x1A ? 0x1A : 0)) | \
71 (0x1ull << (__CNT > 0x1B ? 0x1B : 0)) | \
72 (0x1ull << (__CNT > 0x1C ? 0x1C : 0)) | \
73 (0x1ull << (__CNT > 0x1D ? 0x1D : 0)) | \
74 (0x1ull << (__CNT > 0x1E ? 0x1E : 0)) | \
75 (0x1ull << (__CNT > 0x1F ? 0x1F : 0)) | \
76 (0x1ull << (__CNT > 0x20 ? 0x20 : 0)) | \
77 (0x1ull << (__CNT > 0x21 ? 0x21 : 0)) | \
78 (0x1ull << (__CNT > 0x22 ? 0x22 : 0)) | \
79 (0x1ull << (__CNT > 0x23 ? 0x23 : 0)) | \
80 (0x1ull << (__CNT > 0x24 ? 0x24 : 0)) | \
81 (0x1ull << (__CNT > 0x25 ? 0x25 : 0)) | \
82 (0x1ull << (__CNT > 0x26 ? 0x26 : 0)) | \
83 (0x1ull << (__CNT > 0x27 ? 0x27 : 0)) | \
84 (0x1ull << (__CNT > 0x28 ? 0x28 : 0)) | \
85 (0x1ull << (__CNT > 0x29 ? 0x29 : 0)) | \
86 (0x1ull << (__CNT > 0x2A ? 0x2A : 0)) | \
87 (0x1ull << (__CNT > 0x2B ? 0x2B : 0)) | \
88 (0x1ull << (__CNT > 0x2C ? 0x2C : 0)) | \
89 (0x1ull << (__CNT > 0x2D ? 0x2D : 0)) | \
90 (0x1ull << (__CNT > 0x2E ? 0x2E : 0)) | \
91 (0x1ull << (__CNT > 0x2F ? 0x2F : 0)) | \
92 (0x1ull << (__CNT > 0x30 ? 0x30 : 0)) | \
93 (0x1ull << (__CNT > 0x31 ? 0x31 : 0)) | \
94 (0x1ull << (__CNT > 0x32 ? 0x32 : 0)) | \
95 (0x1ull << (__CNT > 0x33 ? 0x33 : 0)) | \
96 (0x1ull << (__CNT > 0x34 ? 0x34 : 0)) | \
97 (0x1ull << (__CNT > 0x35 ? 0x35 : 0)) | \
98 (0x1ull << (__CNT > 0x36 ? 0x36 : 0)) | \
99 (0x1ull << (__CNT > 0x37 ? 0x37 : 0)) | \
100 (0x1ull << (__CNT > 0x38 ? 0x38 : 0)) | \
101 (0x1ull << (__CNT > 0x39 ? 0x39 : 0)) | \
102 (0x1ull << (__CNT > 0x3A ? 0x3A : 0)) | \
103 (0x1ull << (__CNT > 0x3B ? 0x3B : 0)) | \
104 (0x1ull << (__CNT > 0x3C ? 0x3C : 0)) | \
105 (0x1ull << (__CNT > 0x3D ? 0x3D : 0)) | \
106 (0x1ull << (__CNT > 0x3E ? 0x3E : 0)) | \
107 (0x1ull << (__CNT > 0x3F ? 0x3F : 0)))
108
109#define VSF_HAL_COUNT_TO_MASK(__CNT) \
110 __VSF_HAL_COUNT_TO_MASK(__CNT)
111
112#define __VSF_HAL_MASK_TO_COUNT(__MASK) \
113 ((__MASK & (0x01ull << 0x00) ? 1 : 0) + \
114 (__MASK & (0x01ull << 0x01) ? 1 : 0) + \
115 (__MASK & (0x01ull << 0x02) ? 1 : 0) + \
116 (__MASK & (0x01ull << 0x03) ? 1 : 0) + \
117 (__MASK & (0x01ull << 0x04) ? 1 : 0) + \
118 (__MASK & (0x01ull << 0x05) ? 1 : 0) + \
119 (__MASK & (0x01ull << 0x06) ? 1 : 0) + \
120 (__MASK & (0x01ull << 0x07) ? 1 : 0) + \
121 (__MASK & (0x01ull << 0x08) ? 1 : 0) + \
122 (__MASK & (0x01ull << 0x09) ? 1 : 0) + \
123 (__MASK & (0x01ull << 0x0A) ? 1 : 0) + \
124 (__MASK & (0x01ull << 0x0B) ? 1 : 0) + \
125 (__MASK & (0x01ull << 0x0C) ? 1 : 0) + \
126 (__MASK & (0x01ull << 0x0D) ? 1 : 0) + \
127 (__MASK & (0x01ull << 0x0E) ? 1 : 0) + \
128 (__MASK & (0x01ull << 0x0F) ? 1 : 0) + \
129 (__MASK & (0x01ull << 0x10) ? 1 : 0) + \
130 (__MASK & (0x01ull << 0x11) ? 1 : 0) + \
131 (__MASK & (0x01ull << 0x12) ? 1 : 0) + \
132 (__MASK & (0x01ull << 0x13) ? 1 : 0) + \
133 (__MASK & (0x01ull << 0x14) ? 1 : 0) + \
134 (__MASK & (0x01ull << 0x15) ? 1 : 0) + \
135 (__MASK & (0x01ull << 0x16) ? 1 : 0) + \
136 (__MASK & (0x01ull << 0x17) ? 1 : 0) + \
137 (__MASK & (0x01ull << 0x18) ? 1 : 0) + \
138 (__MASK & (0x01ull << 0x19) ? 1 : 0) + \
139 (__MASK & (0x01ull << 0x1A) ? 1 : 0) + \
140 (__MASK & (0x01ull << 0x1B) ? 1 : 0) + \
141 (__MASK & (0x01ull << 0x1C) ? 1 : 0) + \
142 (__MASK & (0x01ull << 0x1D) ? 1 : 0) + \
143 (__MASK & (0x01ull << 0x1E) ? 1 : 0) + \
144 (__MASK & (0x01ull << 0x1F) ? 1 : 0) + \
145 (__MASK & (0x01ull << 0x20) ? 1 : 0) + \
146 (__MASK & (0x01ull << 0x21) ? 1 : 0) + \
147 (__MASK & (0x01ull << 0x22) ? 1 : 0) + \
148 (__MASK & (0x01ull << 0x23) ? 1 : 0) + \
149 (__MASK & (0x01ull << 0x24) ? 1 : 0) + \
150 (__MASK & (0x01ull << 0x25) ? 1 : 0) + \
151 (__MASK & (0x01ull << 0x26) ? 1 : 0) + \
152 (__MASK & (0x01ull << 0x27) ? 1 : 0) + \
153 (__MASK & (0x01ull << 0x28) ? 1 : 0) + \
154 (__MASK & (0x01ull << 0x29) ? 1 : 0) + \
155 (__MASK & (0x01ull << 0x2A) ? 1 : 0) + \
156 (__MASK & (0x01ull << 0x2B) ? 1 : 0) + \
157 (__MASK & (0x01ull << 0x2C) ? 1 : 0) + \
158 (__MASK & (0x01ull << 0x2D) ? 1 : 0) + \
159 (__MASK & (0x01ull << 0x2E) ? 1 : 0) + \
160 (__MASK & (0x01ull << 0x2F) ? 1 : 0) + \
161 (__MASK & (0x01ull << 0x30) ? 1 : 0) + \
162 (__MASK & (0x01ull << 0x31) ? 1 : 0) + \
163 (__MASK & (0x01ull << 0x32) ? 1 : 0) + \
164 (__MASK & (0x01ull << 0x33) ? 1 : 0) + \
165 (__MASK & (0x01ull << 0x34) ? 1 : 0) + \
166 (__MASK & (0x01ull << 0x35) ? 1 : 0) + \
167 (__MASK & (0x01ull << 0x36) ? 1 : 0) + \
168 (__MASK & (0x01ull << 0x37) ? 1 : 0) + \
169 (__MASK & (0x01ull << 0x38) ? 1 : 0) + \
170 (__MASK & (0x01ull << 0x39) ? 1 : 0) + \
171 (__MASK & (0x01ull << 0x3A) ? 1 : 0) + \
172 (__MASK & (0x01ull << 0x3B) ? 1 : 0) + \
173 (__MASK & (0x01ull << 0x3C) ? 1 : 0) + \
174 (__MASK & (0x01ull << 0x3D) ? 1 : 0) + \
175 (__MASK & (0x01ull << 0x3E) ? 1 : 0) + \
176 (__MASK & (0x01ull << 0x3F) ? 1 : 0))
177
178#define VSF_HAL_MASK_TO_COUNT(__MASK) \
179 __VSF_HAL_MASK_TO_COUNT(__MASK)
180
181/*============================ TYPES =========================================*/
182
183typedef struct vsf_hal_device_t {
184 void *pointer;
185 char *name;
187
188/*
189 * if __VSF_HAL_XXXX_IS_REG_CLK_ASYNC__ is defined for some module, means
190 * vsf_xxx_enable/vsf_xxx_disable will not succeed in one run. And user can
191 * not call vsf_xxx_init before disabled. Or, user don't need to call
192 * vsf_xxx_disable before re-initializing(by calling vsf_xxx_init).
193 */
194
199};
200
201
204 union {
205 struct {
213 };
216
217 union {
218 struct {
225 uint8_t : 2;
226 };
229
230 union {
231 struct {
232 /* Data Type: 2^(u3DataTypeSize) */
234
235 /* Block Size: 2^(u5BlockSize) */
238 };
241};
242
245def_interface(i_peripheral_t)
246 vsf_peripheral_status_t (*fn_Status) (void);
249 union {
251 fsm_rt_t (*fn_Open) (void);
252 };
253 union {
256 };
257end_def_interface(i_peripheral_t)
259
260def_interface(vsf_async_block_access_t)
271 vsf_err_t (*fn_Request)(uint8_t *buffer_ptr, uint_fast32_t size);
272
275
278end_def_interface(vsf_async_block_access_t)
279
280
281/*============================ GLOBAL VARIABLES ==============================*/
282/*============================ PROTOTYPES ====================================*/
283
284#ifdef __cplusplus
285}
286#endif
287
288#endif
vsf_err_t
Definition __type.h:42
end_def_interface(i_pm_wakeup_t) struct vsf_pm_pclk_cfg_t
Definition device.h:249
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
int int_fast32_t
Definition stdint.h:26
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_hal_driver.h:183
void * pointer
Definition vsf_template_hal_driver.h:184
char * name
Definition vsf_template_hal_driver.h:185
Definition vsf_template_hal_driver.h:203
uint16_t info
Definition vsf_template_hal_driver.h:239
uint8_t can_write_block
Definition vsf_template_hal_driver.h:220
uint8_t can_read_byte
Definition vsf_template_hal_driver.h:206
uint8_t can_write
Definition vsf_template_hal_driver.h:227
uint16_t u5_block_size
Definition vsf_template_hal_driver.h:236
union vsf_peripheral_capability_t::@530 Write
uint8_t can_read_block
Definition vsf_template_hal_driver.h:207
union vsf_peripheral_capability_t::@531 Feature
uint8_t support_dma
Definition vsf_template_hal_driver.h:209
uint8_t random_access
Definition vsf_template_hal_driver.h:211
uint8_t can_write_byte
Definition vsf_template_hal_driver.h:219
uint8_t support_isr
Definition vsf_template_hal_driver.h:210
union vsf_peripheral_capability_t::@529 Read
uint16_t u3_data_type_size
Definition vsf_template_hal_driver.h:233
uint8_t can_read
Definition vsf_template_hal_driver.h:214
uint8_t support_fifo
Definition vsf_template_hal_driver.h:208
Definition vsf_template_hal_driver.h:196
uint32_t is_busy
Definition vsf_template_hal_driver.h:197
fsm_rt_t
Definition vsf_fsm.h:315
vsf_err_t(* fn_Cancel)(void)
cancel on going communication
Definition vsf_template_hal_driver.h:274
fsm_rt_t(* fn_Open)(void)
Definition vsf_template_hal_driver.h:251
fsm_rt_t(* fn_Enable)(void)
Definition vsf_template_hal_driver.h:250
fsm_rt_t(* fn_Uninit)(void)
Definition vsf_template_hal_driver.h:248
def_interface(i_peripheral_t) vsf_peripheral_status_t(*fn_Status)(void)
vsf_peripheral_capability_t(* fn_Capability)(void)
Definition vsf_template_hal_driver.h:247
fsm_rt_t(* fn_Close)(void)
Definition vsf_template_hal_driver.h:255
fsm_rt_t(* fn_Disable)(void)
Definition vsf_template_hal_driver.h:254
int_fast32_t(* fn_GetTransferredCount)(void)
get transferred count
Definition vsf_template_hal_driver.h:277
uint_fast32_t size
Definition vsf_template_hal_driver.h:271