hal_trng_lld.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_lld.c
  15. * @brief PLATFORM TRNG subsystem low level driver source.
  16. *
  17. * @addtogroup TRNG
  18. * @{
  19. */
  20. #include "hal.h"
  21. #if (HAL_USE_TRNG == TRUE) || defined(__DOXYGEN__)
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver exported variables. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief TRNGD1 driver identifier.
  30. */
  31. #if (PLATFORM_TRNG_USE_TRNG1 == TRUE) || defined(__DOXYGEN__)
  32. TRNGDriver TRNGD1;
  33. #endif
  34. /*===========================================================================*/
  35. /* Driver local variables and types. */
  36. /*===========================================================================*/
  37. /*===========================================================================*/
  38. /* Driver local functions. */
  39. /*===========================================================================*/
  40. /*===========================================================================*/
  41. /* Driver interrupt handlers. */
  42. /*===========================================================================*/
  43. /*===========================================================================*/
  44. /* Driver exported functions. */
  45. /*===========================================================================*/
  46. /**
  47. * @brief Low level TRNG driver initialization.
  48. *
  49. * @notapi
  50. */
  51. void trng_lld_init(void) {
  52. #if PLATFORM_TRNG_USE_TRNG1 == TRUE
  53. /* Driver initialization.*/
  54. trngObjectInit(&TRNGD1);
  55. #endif
  56. }
  57. /**
  58. * @brief Configures and activates the TRNG peripheral.
  59. *
  60. * @param[in] trngp pointer to the @p TRNGDriver object
  61. *
  62. * @notapi
  63. */
  64. void trng_lld_start(TRNGDriver *trngp) {
  65. if (trngp->state == TRNG_STOP) {
  66. /* Enables the peripheral.*/
  67. #if PLATFORM_TRNG_USE_TRNG1 == TRUE
  68. if (&TRNGD1 == trngp) {
  69. }
  70. #endif
  71. }
  72. /* Configures the peripheral.*/
  73. }
  74. /**
  75. * @brief Deactivates the TRNG peripheral.
  76. *
  77. * @param[in] trngp pointer to the @p TRNGDriver object
  78. *
  79. * @notapi
  80. */
  81. void trng_lld_stop(TRNGDriver *trngp) {
  82. if (trngp->state == TRNG_READY) {
  83. /* Resets the peripheral.*/
  84. /* Disables the peripheral.*/
  85. #if PLATFORM_TRNG_USE_TRNG1 == TRUE
  86. if (&TRNGD1 == trngp) {
  87. }
  88. #endif
  89. }
  90. }
  91. /**
  92. * @brief True random numbers generator.
  93. * @note The function is blocking and likely performs polled waiting
  94. * inside the low level implementation.
  95. *
  96. * @param[in] trngp pointer to the @p TRNGDriver object
  97. * @param[in] size size of output buffer
  98. * @param[out] out output buffer
  99. * @return The operation status.
  100. * @retval false if a random number has been generated.
  101. * @retval true if an HW error occurred.
  102. *
  103. * @api
  104. */
  105. bool trng_lld_generate(TRNGDriver *trngp, size_t size, uint8_t *out) {
  106. (void)trngp;
  107. (void)size;
  108. (void)out;
  109. return true;
  110. }
  111. #endif /* HAL_USE_TRNG == TRUE */
  112. /** @} */