1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv_trng.h 7 * @brief header file for trng driver 8 * @version V1.0 9 * @date 02. June 2017 10 * @model trng 11 ******************************************************************************/ 12 #ifndef _CSI_TRNG_H_ 13 #define _CSI_TRNG_H_ 14 15 #include "drv/common.h" 16 17 #include <stdint.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /// definition for trng handle. 24 typedef void *trng_handle_t; 25 /****** TRNG specific error codes *****/ 26 typedef enum { 27 TRNG_ERROR_MODE = (DRV_ERROR_SPECIFIC + 1) ///< Specified Mode not supported 28 } trng_error_e; 29 30 /** 31 \brief TRNG Status 32 */ 33 typedef struct { 34 uint32_t busy : 1; 35 uint32_t data_valid : 1; ///< Data is valid flag 36 } trng_status_t; 37 38 /****** TRNG Event *****/ 39 typedef enum { 40 TRNG_EVENT_DATA_GENERATE_COMPLETE = 0 ///< True random number generates completely 41 } trng_event_e; 42 typedef void (*trng_event_cb_t)(int32_t idx, trng_event_e event); ///< Pointer to \ref trng_event_cb_t : TRNG Event call back. 43 44 /** 45 \brief TRNG Device Driver Capabilities. 46 */ 47 typedef struct { 48 uint32_t lowper_mode : 1; ///< supports low power mode 49 } trng_capabilities_t; 50 51 // Function documentation 52 53 /** 54 \brief Initialize TRNG Interface. 1. Initializes the resources needed for the TRNG interface 2.registers event callback function 55 \param[in] idx device id 56 \param[in] cb_event event call back function \ref trng_event_cb_t 57 \return pointer to trng handle 58 */ 59 trng_handle_t csi_trng_initialize(int32_t idx, trng_event_cb_t cb_event); 60 61 /** 62 \brief De-initialize TRNG Interface. stops operation and releases the software resources used by the interface 63 \param[in] handle trng handle to operate. 64 \return error code 65 */ 66 int32_t csi_trng_uninitialize(trng_handle_t handle); 67 68 /** 69 \brief control trng power. 70 \param[in] handle trng handle to operate. 71 \param[in] state power state.\ref csi_power_stat_e. 72 \return error code 73 */ 74 int32_t csi_trng_power_control(trng_handle_t handle, csi_power_stat_e state); 75 76 /** 77 \brief Get driver capabilities. 78 \param[in] idx device id. 79 \return \ref trng_capabilities_t 80 */ 81 trng_capabilities_t csi_trng_get_capabilities(int32_t idx); 82 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 /** 93 \brief Get TRNG status. 94 \param[in] handle trng handle to operate. 95 \return TRNG status \ref trng_status_t 96 */ 97 trng_status_t csi_trng_get_status(trng_handle_t handle); 98 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif /* _CSI_TRNG_H_ */ 105