ChibiOS/HAL  7.0.3
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 
68 /* Including the low level driver header, it exports information required
69  for completing types.*/
70 #include "hal_trng_lld.h"
71 
72 /**
73  * @brief Driver configuration structure.
74  */
76  /* End of the mandatory fields.*/
77  trng_lld_config_fields;
78 };
79 
80 /**
81  * @brief Structure representing a TRNG driver.
82  */
84  /**
85  * @brief Driver state.
86  */
88  /**
89  * @brief Current configuration data.
90  */
92 #if defined(TRNG_DRIVER_EXT_FIELDS)
93  TRNG_DRIVER_EXT_FIELDS
94 #endif
95  /* End of the mandatory fields.*/
97 };
98 
99 /*===========================================================================*/
100 /* Driver macros. */
101 /*===========================================================================*/
102 
103 /*===========================================================================*/
104 /* External declarations. */
105 /*===========================================================================*/
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110  void trngInit(void);
111  void trngObjectInit(TRNGDriver *trngp);
112  void trngStart(TRNGDriver *trngp, const TRNGConfig *config);
113  void trngStop(TRNGDriver *trngp);
114  bool trngGenerate(TRNGDriver *trngp, size_t size, uint8_t *out);
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif /* HAL_USE_TRNG == TRUE */
120 
121 #endif /* HAL_TRNG_H */
122 
123 /** @} */
void trngStop(TRNGDriver *trngp)
Deactivates the TRNG peripheral.
Definition: hal_trng.c:103
bool trngGenerate(TRNGDriver *trngp, size_t size, uint8_t *out)
True random numbers generator.
Definition: hal_trng.c:133
void trngObjectInit(TRNGDriver *trngp)
Initializes the standard part of a TRNGDriver structure.
Definition: hal_trng.c:68
void trngStart(TRNGDriver *trngp, const TRNGConfig *config)
Configures and activates the TRNG peripheral.
Definition: hal_trng.c:83
Driver configuration structure.
Definition: hal_trng.h:75
void trngInit(void)
TRNG Driver initialization.
Definition: hal_trng.c:56
#define trng_lld_driver_fields
Low level fields of the TRNG driver structure.
Definition: hal_trng_lld.h:67
const TRNGConfig * config
Current configuration data.
Definition: hal_trng.h:91
PLATFORM TRNG subsystem low level driver header.
trngstate_t
Driver state machine possible states.
Definition: hal_trng.h:49
USBOutEndpointState out
OUT EP0 state.
Definition: hal_usb_lld.c:61
Structure representing a TRNG driver.
Definition: hal_trng.h:83
trngstate_t state
Driver state.
Definition: hal_trng.h:87