hal_trng.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_trng.h
  15. * @brief TRNG Driver macros and structures.
  16. *
  17. * @addtogroup TRNG
  18. * @{
  19. */
  20. #ifndef HAL_TRNG_H
  21. #define HAL_TRNG_H
  22. #if (HAL_USE_TRNG == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver pre-compile time settings. */
  28. /*===========================================================================*/
  29. /*===========================================================================*/
  30. /* Derived constants and error checks. */
  31. /*===========================================================================*/
  32. /*===========================================================================*/
  33. /* Driver data structures and types. */
  34. /*===========================================================================*/
  35. /**
  36. * @brief Driver state machine possible states.
  37. */
  38. typedef enum {
  39. TRNG_UNINIT = 0, /**< Not initialized. */
  40. TRNG_STOP = 1, /**< Stopped. */
  41. TRNG_READY = 2, /**< Ready. */
  42. TRNG_RUNNING = 3 /**< Generating random number. */
  43. } trngstate_t;
  44. /**
  45. * @brief Type of a structure representing a TRNG driver.
  46. */
  47. typedef struct hal_trng_driver TRNGDriver;
  48. /**
  49. * @brief Driver configuration structure.
  50. * @note It could be empty on some architectures.
  51. */
  52. typedef struct hal_trng_config TRNGConfig;
  53. /* Including the low level driver header, it exports information required
  54. for completing types.*/
  55. #include "hal_trng_lld.h"
  56. /**
  57. * @brief Driver configuration structure.
  58. */
  59. struct hal_trng_config {
  60. /* End of the mandatory fields.*/
  61. trng_lld_config_fields;
  62. };
  63. /**
  64. * @brief Structure representing a TRNG driver.
  65. */
  66. struct hal_trng_driver {
  67. /**
  68. * @brief Driver state.
  69. */
  70. trngstate_t state;
  71. /**
  72. * @brief Current configuration data.
  73. */
  74. const TRNGConfig *config;
  75. #if defined(TRNG_DRIVER_EXT_FIELDS)
  76. TRNG_DRIVER_EXT_FIELDS
  77. #endif
  78. /* End of the mandatory fields.*/
  79. trng_lld_driver_fields;
  80. };
  81. /*===========================================================================*/
  82. /* Driver macros. */
  83. /*===========================================================================*/
  84. /*===========================================================================*/
  85. /* External declarations. */
  86. /*===========================================================================*/
  87. #ifdef __cplusplus
  88. extern "C" {
  89. #endif
  90. void trngInit(void);
  91. void trngObjectInit(TRNGDriver *trngp);
  92. void trngStart(TRNGDriver *trngp, const TRNGConfig *config);
  93. void trngStop(TRNGDriver *trngp);
  94. bool trngGenerate(TRNGDriver *trngp, size_t size, uint8_t *out);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* HAL_USE_TRNG == TRUE */
  99. #endif /* HAL_TRNG_H */
  100. /** @} */