drv_trng.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  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. * @file drv_trng.h
  18. * @brief header file for trng driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_TRNG_H_
  23. #define _CSI_TRNG_H_
  24. #include "drv_common.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #include <stdint.h>
  29. /// definition for trng handle.
  30. typedef void *trng_handle_t;
  31. /****** TRNG specific error codes *****/
  32. typedef enum {
  33. TRNG_ERROR_MODE = 0, ///< Specified Mode not supported
  34. } drv_trng_error_e;
  35. /*----- TRNG Control Codes: Mode -----*/
  36. typedef enum {
  37. TRNG_MODE_LOWPOWER = 0, ///< TRNG Low power Mode
  38. TRNG_MODE_NORMAL ///< TRNG Normal Mode
  39. } trng_mode_e;
  40. /**
  41. \brief TRNG Status
  42. */
  43. typedef struct {
  44. uint32_t busy : 1;
  45. uint32_t data_valid : 1; ///< Data is valid flag
  46. } trng_status_t;
  47. /****** TRNG Event *****/
  48. typedef enum {
  49. TRNG_EVENT_DATA_GENERATE_COMPLETE = 0 ///< Get data from TRNG success
  50. } trng_event_e;
  51. typedef void (*trng_event_cb_t)(trng_event_e event); ///< Pointer to \ref trng_event_cb_t : TRNG Event call back.
  52. /**
  53. \brief TRNG Device Driver Capabilities.
  54. */
  55. typedef struct {
  56. uint32_t lowper_mode : 1; ///< supports low power mode
  57. } trng_capabilities_t;
  58. // Function documentation
  59. /**
  60. \brief get trng handle count.
  61. \return trng handle count
  62. */
  63. int32_t csi_trng_get_instance_count(void);
  64. /**
  65. \brief Initialize TRNG Interface. 1. Initializes the resources needed for the TRNG interface 2.registers event callback function
  66. \param[in] idx must not exceed return value of csi_trng_get_instance_count()
  67. \param[in] cb_event Pointer to \ref trng_event_cb_t
  68. \return pointer to trng handle
  69. */
  70. trng_handle_t csi_trng_initialize(int32_t idx, trng_event_cb_t cb_event);
  71. /**
  72. \brief De-initialize TRNG Interface. stops operation and releases the software resources used by the interface
  73. \param[in] handle trng handle to operate.
  74. \return error code
  75. */
  76. int32_t csi_trng_uninitialize(trng_handle_t handle);
  77. /**
  78. \brief Get driver capabilities.
  79. \param[in] handle trng handle to operate.
  80. \return \ref trng_capabilities_t
  81. */
  82. trng_capabilities_t csi_trng_get_capabilities(trng_handle_t handle);
  83. /**
  84. \brief Get data from the TRNG.
  85. \param[in] handle trng handle to operate.
  86. \param[out] data Pointer to buffer with data get from TRNG
  87. \param[in] num Number of data items to obtain
  88. \return error code
  89. */
  90. int32_t csi_trng_get_data(trng_handle_t handle, void *data, uint32_t num);
  91. /**
  92. \brief Get TRNG status.
  93. \param[in] handle trng handle to operate.
  94. \return TRNG status \ref trng_status_t
  95. */
  96. trng_status_t csi_trng_get_status(trng_handle_t handle);
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* _CSI_TRNG_H_ */