-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea74a22
commit 70e66c5
Showing
8 changed files
with
582 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Auto-generated config file hpl_trng_config.h */ | ||
#ifndef HPL_TRNG_CONFIG_H | ||
#define HPL_TRNG_CONFIG_H | ||
|
||
// <<< Use Configuration Wizard in Context Menu >>> | ||
|
||
// <h> Advanced configurations | ||
|
||
// <q> Run In Standby | ||
// <i> Indicates whether the TRNG works in standby mode | ||
// <id> trng_runstdby | ||
#ifndef CONF_TRNG_RUNSTDBY | ||
#define CONF_TRNG_RUNSTDBY 0 | ||
#endif | ||
|
||
// <q> Data Ready Event Output Enable | ||
// <i> Indicates whether the TRNG generates event on Data Ready | ||
// <id> trng_datardyeo | ||
#ifndef CONF_TRNG_DATARDYEO | ||
#define CONF_TRNG_DATARDYEO 0 | ||
#endif | ||
|
||
// </h> | ||
|
||
// <<< end of configuration section >>> | ||
|
||
#endif // HPL_TRNG_CONFIG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
========================================== | ||
Random Number Generator Synchronous driver | ||
========================================== | ||
|
||
Random Number Generator (RAND) generates a sequence of numbers that can not | ||
be reasonably predicted better than by a random chance. | ||
|
||
In some implementation cases, seed is required for the Random Number Generator | ||
to generate random numbers. rand_sync_set_seed is used to update the seed. | ||
If it's actually not required by the generator implementation, the function just | ||
returns ERR_UNSUPPORTED_OP. | ||
|
||
Features | ||
-------- | ||
|
||
* Initialization and de-initialization | ||
* Enabling and Disabling | ||
* Setting seed | ||
* 8-bit and 32-bit random data/data array generation | ||
|
||
Applications | ||
------------ | ||
|
||
* Generate random keys for data encryption | ||
|
||
Dependencies | ||
------------ | ||
|
||
* Random number generation hardware/software | ||
|
||
Concurrency | ||
----------- | ||
N/A | ||
|
||
Limitations | ||
----------- | ||
|
||
N/A | ||
|
||
Known issues and workarounds | ||
---------------------------- | ||
N/A | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* \file | ||
* | ||
* \brief Generic Random Number Generator (RAND) functionality declaration. | ||
* | ||
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. | ||
* | ||
* \asf_license_start | ||
* | ||
* \page License | ||
* | ||
* Subject to your compliance with these terms, you may use Microchip | ||
* software and any derivatives exclusively with Microchip products. | ||
* It is your responsibility to comply with third party license terms applicable | ||
* to your use of third party software (including open source software) that | ||
* may accompany Microchip software. | ||
* | ||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, | ||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, | ||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, | ||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE | ||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL | ||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE | ||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE | ||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT | ||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY | ||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, | ||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. | ||
* | ||
* \asf_license_stop | ||
* | ||
*/ | ||
|
||
#ifndef _HAL_RAND_SYNC_H_INCLUDED | ||
#define _HAL_RAND_SYNC_H_INCLUDED | ||
|
||
#include <hpl_rand_sync.h> | ||
|
||
#include <utils_assert.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* \addtogroup doc_driver_hal_rand_sync | ||
* | ||
*@{ | ||
*/ | ||
|
||
/** Random Number Generator polling device. */ | ||
struct rand_sync_desc { | ||
struct _rand_sync_dev dev; | ||
}; | ||
|
||
/** | ||
* \brief Initialize the Random Number Generator Driver | ||
* \param[out] desc Pointer to the device descriptor instance struct | ||
* \param[in, out] hw Pointer to the hardware for device instance | ||
* \return Initialization operation result status, ERR_NONE (0) for OK. | ||
*/ | ||
int32_t rand_sync_init(struct rand_sync_desc *const desc, void *const hw); | ||
|
||
/** | ||
* \brief Deinitialize the Random Number Generator Driver | ||
* \param[out] desc Pointer to the device descriptor instance struct | ||
*/ | ||
void rand_sync_deinit(struct rand_sync_desc *const desc); | ||
|
||
/** | ||
* \brief Enable the Random Number Generator Driver | ||
* \param[out] desc Pointer to the device descriptor instance struct | ||
* \return Enable operation result status, ERR_NONE (0) for OK. | ||
*/ | ||
int32_t rand_sync_enable(struct rand_sync_desc *const desc); | ||
|
||
/** | ||
* \brief Disable the Random Number Generator Driver | ||
* \param[out] desc Pointer to the device descriptor instance struct | ||
*/ | ||
void rand_sync_disable(struct rand_sync_desc *const desc); | ||
|
||
/** | ||
* \brief Set seed for the Random Number Generator Driver | ||
* \param[out] desc Pointer to the device descriptor instance struct | ||
*/ | ||
int32_t rand_sync_set_seed(struct rand_sync_desc *const desc, const uint32_t seed); | ||
|
||
/** | ||
* \brief Read the 8-bit Random Number | ||
* \param[in] desc Pointer to the device descriptor instance struct | ||
* \return The random number generated | ||
*/ | ||
uint8_t rand_sync_read8(const struct rand_sync_desc *const desc); | ||
|
||
/** | ||
* \brief Read the 32-bit Random Number | ||
* \param[in] desc Pointer to the device descriptor instance struct | ||
* \return The random number generated | ||
*/ | ||
uint32_t rand_sync_read32(const struct rand_sync_desc *const desc); | ||
|
||
/** | ||
* \brief Read the 8-bit Random Number Sequence into a buffer | ||
* \param[in] desc Pointer to the device descriptor instance struct | ||
* \param[out] buf Pointer to the buffer to fill an array of generated numbers | ||
* \param[in] len Number of random numbers to read | ||
*/ | ||
void rand_sync_read_buf8(const struct rand_sync_desc *const desc, uint8_t *buf, uint32_t len); | ||
|
||
/** | ||
* \brief Read the 32-bit Random Number Sequence into a buffer | ||
* \param[in] desc Pointer to the device descriptor instance struct | ||
* \param[out] buf Pointer to the buffer to fill an array of generated numbers | ||
* \param[in] len Number of random numbers to read | ||
*/ | ||
void rand_sync_read_buf32(const struct rand_sync_desc *const desc, uint32_t *buf, uint32_t len); | ||
|
||
/** | ||
* \brief Retrieve the current driver version | ||
* | ||
* \return Current driver version. | ||
*/ | ||
uint32_t rand_sync_get_version(void); | ||
|
||
/* I/O read will be used to get random data. */ | ||
|
||
/**@}*/ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _HAL_RAND_SYNC_H_INCLUDED */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* \file | ||
* | ||
* \brief Random Number Generator (RAND) related functionality declaration. | ||
* | ||
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. | ||
* | ||
* \asf_license_start | ||
* | ||
* \page License | ||
* | ||
* Subject to your compliance with these terms, you may use Microchip | ||
* software and any derivatives exclusively with Microchip products. | ||
* It is your responsibility to comply with third party license terms applicable | ||
* to your use of third party software (including open source software) that | ||
* may accompany Microchip software. | ||
* | ||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, | ||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, | ||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, | ||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE | ||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL | ||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE | ||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE | ||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT | ||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY | ||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, | ||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. | ||
* | ||
* \asf_license_stop | ||
* | ||
*/ | ||
|
||
#ifndef _HPL_RAND_SYNC_H_INCLUDED | ||
#define _HPL_RAND_SYNC_H_INCLUDED | ||
|
||
#include <compiler.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** Random Number Generator polling device. */ | ||
struct _rand_sync_dev { | ||
/** Pointer to private data or hardware base */ | ||
void *prvt; | ||
/** Number of bits generated for each read operation */ | ||
uint8_t n_bits; | ||
}; | ||
|
||
/** | ||
* \brief Initialize the Random Number Generator Driver | ||
* \param[out] dev Pointer to the device instance struct | ||
* \param[in, out] hw Pointer to the hardware for device instance | ||
* \return Initialization operation result status, 0 for OK. | ||
*/ | ||
int32_t _rand_sync_init(struct _rand_sync_dev *const dev, void *const hw); | ||
|
||
/** | ||
* \brief Deinitialize the Random Number Generator Driver | ||
* \param[in, out] dev Pointer to the device instance struct | ||
*/ | ||
void _rand_sync_deinit(struct _rand_sync_dev *const dev); | ||
|
||
/** | ||
* \brief Enable the Random Number Generator Driver | ||
* \param[out] dev Pointer to the device instance struct | ||
* \return Enable operation result status, 0 for OK. | ||
*/ | ||
int32_t _rand_sync_enable(struct _rand_sync_dev *const dev); | ||
|
||
/** | ||
* \brief Disable the Random Number Generator Driver | ||
* \param[out] dev Pointer to the device instance struct | ||
*/ | ||
void _rand_sync_disable(struct _rand_sync_dev *const dev); | ||
|
||
/** | ||
* \brief Set seed for the Random Number Generator Driver | ||
* \param[out] dev Pointer to the device instance struct | ||
* \param[in] seed The seed to set | ||
* \return Operation result | ||
* \retval ERR_NONE Operation complete success | ||
* \retval ERR_UNSUPPORTED_OP Seed not supported | ||
*/ | ||
int32_t _rand_sync_set_seed(struct _rand_sync_dev *const dev, const uint32_t seed); | ||
|
||
/** | ||
* \brief Polling random number until it's read back | ||
* \param[in] dev Pointer to the device instance struct | ||
* \return The random number value | ||
*/ | ||
uint32_t _rand_sync_read_one(const struct _rand_sync_dev *const dev); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
/**@}*/ | ||
#endif /* _HPL_RAND_SYNC_H_INCLUDED */ |
Oops, something went wrong.