VSF Documented
vsf_template_rng.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_RNG_H__
19#define __VSF_TEMPLATE_RNG_H__
20
21/*============================ INCLUDES ======================================*/
22
24#include "hal/arch/vsf_arch.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*============================ MACROS ========================================*/
31
38#ifndef VSF_RNG_CFG_MULTI_CLASS
39# define VSF_RNG_CFG_MULTI_CLASS ENABLED
40#endif
41
48#if defined(VSF_HW_RNG_COUNT) && !defined(VSF_HW_RNG_MASK)
49# define VSF_HW_RNG_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_RNG_COUNT)
50#endif
51
58#if defined(VSF_HW_RNG_MASK) && !defined(VSF_HW_RNG_COUNT)
59# define VSF_HW_RNG_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_RNG_MASK)
60#endif
61
70#ifndef VSF_RNG_CFG_PREFIX
71# if VSF_RNG_CFG_MULTI_CLASS == ENABLED
72# define VSF_RNG_CFG_PREFIX vsf
73# elif defined(VSF_HW_RNG_COUNT) && (VSF_HW_RNG_COUNT != 0)
74# define VSF_RNG_CFG_PREFIX vsf_hw
75# else
76# define VSF_RNG_CFG_PREFIX vsf
77# endif
78#endif
79
88#ifndef VSF_RNG_CFG_FUNCTION_RENAME
89# define VSF_RNG_CFG_FUNCTION_RENAME ENABLED
90#endif
91
102#ifndef VSF_RNG_CFG_REIMPLEMENT_TYPE_CAPABILITY
103# define VSF_RNG_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
104#endif
105
114#ifndef VSF_RNG_CFG_INHERIT_HAL_CAPABILITY
115# define VSF_RNG_CFG_INHERIT_HAL_CAPABILITY ENABLED
116#endif
117
118#ifndef VSF_RNG_CFG_REIMPLEMENT_TYPE_CTRL
119# define VSF_RNG_CFG_REIMPLEMENT_TYPE_CTRL DISABLED
120#endif
121
122/*============================ MACROFIED FUNCTIONS ===========================*/
123
133#define VSF_RNG_APIS(__prefix_name) \
134 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rng, init, VSF_MCONNECT(__prefix_name, _t) *rng_ptr) \
135 __VSF_HAL_TEMPLATE_API(__prefix_name, void, rng, fini, VSF_MCONNECT(__prefix_name, _t) *rng_ptr) \
136 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_rng_capability_t, rng, capability, VSF_MCONNECT(__prefix_name, _t) *rng_ptr) \
137 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rng, generate_request, VSF_MCONNECT(__prefix_name, _t) *rng_ptr, \
138 uint32_t *buffer, uint32_t num, void *param, vsf_rng_on_ready_callback_t * on_ready_cb) \
139 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rng, ctrl, VSF_MCONNECT(__prefix_name, _t) *rng_ptr, vsf_rng_ctrl_t ctrl, void* param)
140
141/*============================ TYPES =========================================*/
142
143#if VSF_RNG_CFG_REIMPLEMENT_TYPE_CTRL == DISABLED
154typedef enum vsf_rng_ctrl_t {
174#endif
175
176typedef struct vsf_rng_t vsf_rng_t;
177typedef void vsf_rng_on_ready_callback_t(void *param, uint32_t *buffer, uint32_t num);
178
179#if VSF_RNG_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
180typedef struct vsf_rng_capability_t {
181#if VSF_RNG_CFG_INHERIT_HAL_CAPABILITY == ENABLED
183#endif
185#endif /* VSF_RNG_CFG_REIMPLEMENT_TYPE_CAPABILITY */
186
187typedef struct vsf_rng_op_t {
189#undef __VSF_HAL_TEMPLATE_API
190#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
192
193 VSF_RNG_APIS(vsf_rng)
195
196#if VSF_RNG_CFG_MULTI_CLASS == ENABLED
197struct vsf_rng_t {
199};
200#endif
201
202/*============================ PROTOTYPES ====================================*/
203
221extern vsf_err_t vsf_rng_init(vsf_rng_t *rng_ptr);
222
234extern void vsf_rng_fini(vsf_rng_t *rng_ptr);
235
248
268extern vsf_err_t vsf_rng_generate_request(vsf_rng_t *rng_ptr, uint32_t *buffer, uint32_t num,
269 void *param, vsf_rng_on_ready_callback_t * on_ready_cb);
270
271extern vsf_err_t vsf_rng_ctrl(vsf_rng_t *rng_ptr, vsf_rng_ctrl_t ctrl, void * param);
272
273/*============================ INCLUDES ======================================*/
274
275/*============================ MACROFIED FUNCTIONS ===========================*/
276
278#if VSF_RNG_CFG_FUNCTION_RENAME == ENABLED
279# define __vsf_rng_t VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_t)
280# define vsf_rng_init(__RNG, ...) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_init) ((__vsf_rng_t *)(__RNG), ##__VA_ARGS__)
281# define vsf_rng_fini(__RNG) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_fini) ((__vsf_rng_t *)(__RNG))
282# define vsf_rng_capability(__RNG) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_capability) ((__vsf_rng_t *)(__RNG))
283# define vsf_rng_generate_request(__RNG, ...) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_generate_request) ((__vsf_rng_t *)(__RNG), ##__VA_ARGS__)
284# define vsf_rng_ctrl(__RNG, ...) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_ctrl) ((__vsf_rng_t *)(__RNG), ##__VA_ARGS__)
285#endif
287
288#ifdef __cplusplus
289}
290#endif
291
292#endif /*__VSF_TEMPLATE_RNG_H__*/
vsf_err_t
Definition __type.h:42
unsigned uint32_t
Definition stdint.h:9
Definition vsf_template_hal_driver.h:204
Definition vsf_template_rng.h:180
Definition vsf_template_rng.h:187
Definition vsf_template_rng.h:197
const vsf_rng_op_t * op
Definition vsf_template_rng.h:198
vsf_err_t vsf_rng_init(vsf_rng_t *rng_ptr)
Initialize a RNG instance.
Definition rng_common.c:37
void vsf_rng_on_ready_callback_t(void *param, uint32_t *buffer, uint32_t num)
Definition vsf_template_rng.h:177
vsf_rng_capability_t vsf_rng_capability(vsf_rng_t *rng_ptr)
Get the capability of RNG instance.
Definition rng_common.c:65
#define VSF_RNG_APIS(__prefix_name)
RNG API template, used to generate RNG type, specific prefix function declarations,...
Definition vsf_template_rng.h:133
vsf_err_t vsf_rng_generate_request(vsf_rng_t *rng_ptr, uint32_t *buffer, uint32_t num, void *param, vsf_rng_on_ready_callback_t *on_ready_cb)
RNG generate request.
Definition rng_common.c:55
void vsf_rng_fini(vsf_rng_t *rng_ptr)
Finalize a RNG instance.
Definition rng_common.c:46
vsf_rng_ctrl_t
Predefined VSF RNG control commands that can be reimplemented in specific HAL drivers.
Definition vsf_template_rng.h:154
@ __VSF_RNG_CTRL_DUMMY
Dummy value for compilation, required when no actual control commands are defined.
Definition vsf_template_rng.h:172
vsf_err_t vsf_rng_ctrl(vsf_rng_t *rng_ptr, vsf_rng_ctrl_t ctrl, void *param)
Definition rng_common.c:74
struct vsf_rng_capability_t vsf_rng_capability_t
Generated from commit: vsfteam/vsf@b2e9e8a