ChibiOS  21.6.0
hal_trng.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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  * @file hal_trng.h
19  * @brief TRNG Driver macros and structures.
20  *
21  * @addtogroup TRNG
22  * @{
23  */
24 
25 #ifndef HAL_TRNG_H
26 #define HAL_TRNG_H
27 
28 #if (HAL_USE_TRNG == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /*===========================================================================*/
35 /* Driver pre-compile time settings. */
36 /*===========================================================================*/
37 
38 /*===========================================================================*/
39 /* Derived constants and error checks. */
40 /*===========================================================================*/
41 
42 /*===========================================================================*/
43 /* Driver data structures and types. */
44 /*===========================================================================*/
45 
46 /**
47  * @brief Driver state machine possible states.
48  */
49 typedef enum {
50  TRNG_UNINIT = 0, /**< Not initialized. */
51  TRNG_STOP = 1, /**< Stopped. */
52  TRNG_READY = 2, /**< Ready. */
53  TRNG_RUNNING = 3 /**< Generating random number. */
54 } trngstate_t;
55 
56 /**
57  * @brief Type of a structure representing a TRNG driver.
58  */
59 typedef struct hal_trng_driver TRNGDriver;
60 
61 /**
62  * @brief Driver configuration structure.
63  * @note It could be empty on some architectures.
64  */
65 typedef struct hal_trng_config TRNGConfig;
66 
67 /* Including the low level driver header, it exports information required
68  for completing types.*/
69 #include "hal_trng_lld.h"
70 
71 /**
72  * @brief Driver configuration structure.
73  */
75  /* End of the mandatory fields.*/
76  trng_lld_config_fields;
77 };
78 
79 /**
80  * @brief Structure representing a TRNG driver.
81  */
83  /**
84  * @brief Driver state.
85  */
87  /**
88  * @brief Current configuration data.
89  */
91 #if defined(TRNG_DRIVER_EXT_FIELDS)
92  TRNG_DRIVER_EXT_FIELDS
93 #endif
94  /* End of the mandatory fields.*/
95  trng_lld_driver_fields;
96 };
97 
98 /*===========================================================================*/
99 /* Driver macros. */
100 /*===========================================================================*/
101 
102 /*===========================================================================*/
103 /* External declarations. */
104 /*===========================================================================*/
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109  void trngInit(void);
110  void trngObjectInit(TRNGDriver *trngp);
111  void trngStart(TRNGDriver *trngp, const TRNGConfig *config);
112  void trngStop(TRNGDriver *trngp);
113  bool trngGenerate(TRNGDriver *trngp, size_t size, uint8_t *out);
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* HAL_USE_TRNG == TRUE */
119 
120 #endif /* HAL_TRNG_H */
121 
122 /** @} */
trngstate_t
trngstate_t
Driver state machine possible states.
Definition: hal_trng.h:49
out
USBOutEndpointState out
OUT EP0 state.
Definition: hal_usb_lld.c:61
trngObjectInit
void trngObjectInit(TRNGDriver *trngp)
Initializes the standard part of a TRNGDriver structure.
Definition: hal_trng.c:68
trngStart
void trngStart(TRNGDriver *trngp, const TRNGConfig *config)
Configures and activates the TRNG peripheral.
Definition: hal_trng.c:83
trngGenerate
bool trngGenerate(TRNGDriver *trngp, size_t size, uint8_t *out)
True random numbers generator.
Definition: hal_trng.c:133
trngStop
void trngStop(TRNGDriver *trngp)
Deactivates the TRNG peripheral.
Definition: hal_trng.c:103
TRNG_UNINIT
@ TRNG_UNINIT
Definition: hal_trng.h:50
TRNG_RUNNING
@ TRNG_RUNNING
Definition: hal_trng.h:53
hal_trng_config
Driver configuration structure.
Definition: hal_trng.h:74
hal_trng_driver::state
trngstate_t state
Driver state.
Definition: hal_trng.h:86
hal_trng_driver
Structure representing a TRNG driver.
Definition: hal_trng.h:82
TRNG_STOP
@ TRNG_STOP
Definition: hal_trng.h:51
trngInit
void trngInit(void)
TRNG Driver initialization.
Definition: hal_trng.c:56
hal_trng_lld.h
PLATFORM TRNG subsystem low level driver header.
hal_trng_driver::config
const TRNGConfig * config
Current configuration data.
Definition: hal_trng.h:90
TRNG_READY
@ TRNG_READY
Definition: hal_trng.h:52