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