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
32// multi-class support enabled by default for maximum availability.
33#ifndef VSF_RNG_CFG_MULTI_CLASS
34# define VSF_RNG_CFG_MULTI_CLASS ENABLED
35#endif
36
37#if defined(VSF_HW_RNG_COUNT) && !defined(VSF_HW_RNG_MASK)
38# define VSF_HW_RNG_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_RNG_COUNT)
39#endif
40
41#if defined(VSF_HW_RNG_MASK) && !defined(VSF_HW_RNG_COUNT)
42# define VSF_HW_RNG_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_RNG_MASK)
43#endif
44
45// application code can redefine it
46#ifndef VSF_RNG_CFG_PREFIX
47# if VSF_RNG_CFG_MULTI_CLASS == ENABLED
48# define VSF_RNG_CFG_PREFIX vsf
49# elif defined(VSF_HW_RNG_COUNT) && (VSF_HW_RNG_COUNT != 0)
50# define VSF_RNG_CFG_PREFIX vsf_hw
51# else
52# define VSF_RNG_CFG_PREFIX vsf
53# endif
54#endif
55
56#ifndef VSF_RNG_CFG_FUNCTION_RENAME
57# define VSF_RNG_CFG_FUNCTION_RENAME ENABLED
58#endif
59
63#if VSF_RNG_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
64# define VSF_RNG_CFG_REIMPLEMENT_TYPE_CFG DISABLED
65#endif
66
70#if VSF_RNG_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
71# define VSF_RNG_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
72#endif
73
74#ifndef VSF_RNG_CFG_INHERT_HAL_CAPABILITY
75# define VSF_RNG_CFG_INHERT_HAL_CAPABILITY ENABLED
76#endif
77
78/*============================ MACROFIED FUNCTIONS ===========================*/
79
80#define VSF_RNG_APIS(__prefix_name) \
81 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rng, init, VSF_MCONNECT(__prefix_name, _rng_t) *rng_ptr) \
82 __VSF_HAL_TEMPLATE_API(__prefix_name, void, rng, fini, VSF_MCONNECT(__prefix_name, _rng_t) *rng_ptr) \
83 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_rng_capability_t, rng, capability, VSF_MCONNECT(__prefix_name, _rng_t) *rng_ptr) \
84 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rng, generate_request, VSF_MCONNECT(__prefix_name, _rng_t) *rng_ptr, \
85 uint32_t *buffer, uint32_t num, void *param, vsf_rng_on_ready_callback_t * on_ready_cb)
86
87/*============================ TYPES =========================================*/
88
89typedef struct vsf_rng_t vsf_rng_t;
90typedef void vsf_rng_on_ready_callback_t(void *param, uint32_t *buffer, uint32_t num);
91
92typedef struct vsf_rng_capability_t {
93#if VSF_RNG_CFG_INHERT_HAL_CAPABILITY == ENABLED
95#endif
97
98typedef struct vsf_rng_op_t {
99#undef __VSF_HAL_TEMPLATE_API
100#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
101
102 VSF_RNG_APIS(vsf)
104
105#if VSF_RNG_CFG_MULTI_CLASS == ENABLED
106struct vsf_rng_t {
108};
109#endif
110
111/*============================ PROTOTYPES ====================================*/
112
132extern vsf_err_t vsf_rng_init(vsf_rng_t *rng_ptr);
133
146extern void vsf_rng_fini(vsf_rng_t *rng_ptr);
147
160
176extern vsf_err_t vsf_rng_generate_request(vsf_rng_t *rng_ptr, uint32_t *buffer, uint32_t num,
177 void *param, vsf_rng_on_ready_callback_t * on_ready_cb);
178
179/*============================ INCLUDES ======================================*/
180
181/*============================ MACROFIED FUNCTIONS ===========================*/
182
183#if VSF_RNG_CFG_FUNCTION_RENAME == ENABLED
184# define __vsf_rng_t VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_t)
185# define vsf_rng_init(__RNG, ...) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_init) ((__vsf_rng_t *)(__RNG), ##__VA_ARGS__)
186# define vsf_rng_fini(__RNG) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_fini) ((__vsf_rng_t *)(__RNG))
187# define vsf_rng_capability(__RNG) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_capability) ((__vsf_rng_t *)(__RNG))
188# define vsf_rng_generate_request(__RNG, ...) VSF_MCONNECT(VSF_RNG_CFG_PREFIX, _rng_generate_request) ((__vsf_rng_t *)(__RNG), ##__VA_ARGS__)
189#endif
190
191#ifdef __cplusplus
192}
193#endif
194
195#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:203
Definition vsf_template_rng.h:92
Definition vsf_template_rng.h:98
Definition vsf_template_rng.h:106
const vsf_rng_op_t * op
Definition vsf_template_rng.h:107
void vsf_rng_on_ready_callback_t(void *param, uint32_t *buffer, uint32_t num)
Definition vsf_template_rng.h:90
#define VSF_RNG_APIS(__prefix_name)
Definition vsf_template_rng.h:80
#define vsf_rng_fini(__RNG)
Definition vsf_template_rng.h:186
#define vsf_rng_capability(__RNG)
Definition vsf_template_rng.h:187
#define vsf_rng_init(__RNG,...)
Definition vsf_template_rng.h:185
#define vsf_rng_generate_request(__RNG,...)
Definition vsf_template_rng.h:188