2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 /******************************************************************************
18 * @brief header file for trng driver
21 ******************************************************************************/
25 #include "drv_common.h"
33 /// definition for trng handle.
34 typedef void *trng_handle_t;
35 /****** TRNG specific error codes *****/
37 TRNG_ERROR_MODE = 0, ///< Specified Mode not supported
40 /*----- TRNG Control Codes: Mode -----*/
42 TRNG_MODE_LOWPOWER = 0, ///< TRNG Low power Mode
43 TRNG_MODE_NORMAL ///< TRNG Normal Mode
51 uint32_t data_valid : 1; ///< Data is valid flag
54 /****** TRNG Event *****/
56 TRNG_EVENT_DATA_GENERATE_COMPLETE = 0 ///< Get data from TRNG success
58 typedef void (*trng_event_cb_t)(trng_event_e event); ///< Pointer to \ref trng_event_cb_t : TRNG Event call back.
61 \brief TRNG Device Driver Capabilities.
64 uint32_t lowper_mode : 1; ///< supports low power mode
65 } trng_capabilities_t;
67 // Function documentation
70 \brief get trng handle count.
71 \return trng handle count
73 int32_t csi_trng_get_instance_count(void);
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
81 trng_handle_t csi_trng_initialize(int32_t idx, trng_event_cb_t cb_event);
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.
88 int32_t csi_trng_uninitialize(trng_handle_t handle);
91 \brief Get driver capabilities.
92 \param[in] handle trng handle to operate.
93 \return \ref trng_capabilities_t
95 trng_capabilities_t csi_trng_get_capabilities(trng_handle_t handle);
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
104 int32_t csi_trng_get_data(trng_handle_t handle, void *data, uint32_t num);
107 \brief Get TRNG status.
108 \param[in] handle trng handle to operate.
109 \return TRNG status \ref trng_status_t
111 trng_status_t csi_trng_get_status(trng_handle_t handle);
118 #endif /* _CSI_TRNG_H_ */