|
rng90 1.0
rng90 driver library
|
Header file with declarations and macros for driving an rng90. More...
#include "../../../utils/macros/stringify.h"#include "../../../hal/avr0/twi/twi.h"#include "../../../utils/crc/crc16.h"#include "../../../utils/systick/systick.h"

Go to the source code of this file.
Data Structures | |
| struct | RNG90_Info_t |
| Holds basic identification and revision information for the RNG90 device. More... | |
| struct | RNG90_Packet_t |
| Represents a generic command or response packet for the RNG90 device. More... | |
| struct | RNG90_Frame_t |
| Describes a processed data frame received from the RNG90 device. More... | |
Macros | |
| #define | RNG90_HAL_PLATFORM avr0 |
| #define | RNG90_ADDRESS 0x40 |
| Defines the TWI/I2C address of the RNG90 device. | |
| #define | RNG90_RESET_COMMAND 0x00 |
| Defines the reset command for the RNG90 device. | |
| #define | RNG90_SLEEP_COMMAND1 0x01 |
| Defines the first sleep command for the RNG90 device. | |
| #define | RNG90_SLEEP_COMMAND2 0x02 |
| Defines the second sleep command for the RNG90 device. | |
| #define | RNG90_EXECUTE_COMMAND 0x03 |
| Defines the execute command for the RNG90 device. | |
| #define | RNG90_OPERATION_INFO 0x30 |
| Defines the command code for querying operation information of the RNG90 device. | |
| #define | RNG90_OPERATION_INFO_PARAM1 0x00 |
| Defines the first parameter for the RNG90 operation info command. | |
| #define | RNG90_OPERATION_INFO_PARAM2 0x0000 |
| Defines the second parameter for the RNG90 operation info command. | |
| #define | RNG90_OPERATION_RANDOM 0x16 |
| Defines the command code for random number generation on the RNG90 device. | |
| #define | RNG90_OPERATION_RANDOM_PARAM1 0x00 |
| Defines the first parameter for the RNG90 random number generation command. | |
| #define | RNG90_OPERATION_RANDOM_PARAM2 0x0000 |
| Defines the second parameter for the RNG90 random number generation command. | |
| #define | RNG90_OPERATION_RANDOM_DATA_SIZE 20UL |
| Defines the size of random data to be generated by the RNG90 device. | |
| #define | RNG90_OPERATION_RANDOM_DATA 0x00 |
| Defines the data buffer for random data generated by the RNG90 device. | |
| #define | RNG90_OPERATION_RANDOM_RNG_SIZE 32UL |
| Defines the size of the RNG state or seed used by the RNG90 device. | |
| #define | RNG90_OPERATION_READ 0x02 |
| Defines the command code for reading data from the RNG90 device. | |
| #define | RNG90_OPERATION_READ_PARAM1 0x01 |
| Defines the first parameter for the RNG90 read command. | |
| #define | RNG90_OPERATION_READ_PARAM2 0x0000 |
| Defines the second parameter for the RNG90 read command. | |
| #define | RNG90_OPERATION_READ_DATA_SIZE 16UL |
| Defines the size of data to be read from the RNG90 device. | |
| #define | RNG90_OPERATION_READ_SERIAL_SIZE 8UL |
| Defines the size of the serial number data read from the RNG90 device. | |
| #define | RNG90_OPERATION_SELF_TEST 0x77 |
| Defines the command code for triggering self-test routines on the RNG90 device. | |
| #define | RNG90_OPERATION_SELF_TEST_PARAM1_READ 0x00 |
| Parameter for reading self-test status from the RNG90 device. | |
| #define | RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG 0x01 |
| Parameter for running the DRBG self-test on the RNG90 device. | |
| #define | RNG90_OPERATION_SELF_TEST_PARAM1_RUN_SHA256 0x20 |
| Parameter for running the SHA-256 self-test on the RNG90 device. | |
| #define | RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG_AND_SHA256 0x21 |
| Parameter for running both DRBG and SHA-256 self-tests on the RNG90 device. | |
| #define | RNG90_OPERATION_SELF_TEST_PARAM2 0x0000 |
| Defines the second parameter for the RNG90 self-test command. | |
| #define | RNG90_NEW_BUS_TRANSMISSION_US 2UL |
| Defines the minimum delay between two I2C bus transmissions. | |
| #define | RNG90_STATUS_SUCCESSFUL_COMMAND_EXECUTION 0x00 |
| Defines the status code for a successfully executed command on the RNG90 device. | |
| #define | RNG90_STATUS_PARSE_ERROR 0x03 |
| Defines the status code for a parse error on the RNG90 device. | |
| #define | RNG90_STATUS_SELF_TEST_ERROR 0x07 |
| Defines the status code for a self-test error on the RNG90 device. | |
| #define | RNG90_STATUS_HEALTH_TEST_ERROR 0x08 |
| Defines the status code for a health test error on the RNG90 device. | |
| #define | RNG90_STATUS_EXECUTION_ERROR 0x0F |
| Defines the status code for an execution error on the RNG90 device. | |
| #define | RNG90_STATUS_AFTER_WAKE 0x11 |
| Defines the status code indicating the RNG90 device has just woken up from sleep mode. | |
| #define | RNG90_STATUS_TWI_ERROR 0xF0 |
| Defines the status code for a TWI/I2C communication error with the RNG90 device. | |
| #define | RNG90_STATUS_CRC_OR_COMMUNICATION_ERROR 0xFF |
| Defines the status code for a CRC or communication error with the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_PASSED_SUCCESSFULLY 0x00 |
| Defines the self-test status code indicating all tests passed successfully on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_DRBG_SELFTEST_FAIL 0x01 |
| Defines the self-test status code indicating the DRBG self-test failed on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_SHA256_SELFTEST_FAIL 0x20 |
| Defines the self-test status code indicating the SHA-256 self-test failed on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_DRBG_SHA256_SELFTEST_FAIL 0x21 |
| Defines the self-test status code indicating both DRBG and SHA-256 self-tests failed on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_DRBG_SELFTEST_NOT_RUN 0x02 |
| Defines the self-test status code indicating the DRBG self-test was not run on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_SHA256_SELFTEST_NOT_RUN 0x10 |
| Defines the self-test status code indicating the SHA-256 self-test was not run on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_NEITHER_SELFTEST_NOT_RUN 0x12 |
| Defines the self-test status code indicating neither DRBG nor SHA-256 self-tests were run on the RNG90 device. | |
| #define | RNG90_SELFTEST_STATUS_ERROR 0xFF |
| Defines the self-test status code indicating an error occurred during self-testing on the RNG90 device. | |
| #define | RNG90_INFO_EXECUTION_TIME_MS 1UL |
| Defines the typical execution time for RNG90 info commands in milliseconds. | |
| #define | RNG90_RANDOM_EXECUTION_TIME_MS 75UL |
| Defines the typical execution time for RNG90 random number generation commands in milliseconds. | |
| #define | RNG90_READ_EXECUTION_TIME_MS 1UL |
| Defines the typical execution time for RNG90 read commands in milliseconds. | |
| #define | RNG90_SELFTEST_EXECUTION_TIME_MS 32UL |
| Defines the typical execution time for RNG90 self-test commands in milliseconds. | |
| #define | RNG90_WDT_RESET_TIME_MS 1300UL |
| Defines the watchdog timer reset time for the RNG90 device in milliseconds. | |
| #define | RNG90_CRC_POLYNOMIAL 0x8005 |
| Defines the CRC polynomial used for error checking in RNG90 communications. | |
| #define | RNG90_CRC_SIZE 2UL |
| Defines the size of the CRC field used by the RNG90 device. | |
| #define | RNG90_STANDARD_FRAME_SIZE 4UL |
| Defines the standard frame size used by the RNG90 device. | |
| #define | RNG90_INFO_FRAME_SIZE 7UL |
| Defines the frame size for information responses from the RNG90 device. [conversation_history:1]. | |
| #define | RNG90_NUMBER_FRAME_SIZE 35UL |
| Defines the frame size for random number responses from the RNG90 device. | |
| #define | RNG90_SERIAL_FRAME_SIZE 19UL |
| Defines the frame size for serial number responses from the RNG90 device. | |
Typedefs | |
| typedef enum RNG90_Status_t | RNG90_Status |
| Alias for enum RNG90_Status_t representing RNG90 status codes. | |
| typedef enum RNG90_Run_SelfTest_t | RNG90_Run_SelfTest |
| Alias for enum RNG90_Run_SelfTest_t representing RNG90 self-test selections. | |
| typedef enum RNG90_SelfTest_Status_t | RNG90_SelfTest_Status |
| Alias for enum RNG90_SelfTest_Status_t representing RNG90 self-test result codes. | |
| typedef struct RNG90_Info_t | RNG90_Info |
| Alias for struct RNG90_Info_t representing RNG90 device information. | |
| typedef struct RNG90_Packet_t | RNG90_Packet |
| Alias for struct RNG90_Packet_t representing an RNG90 packet. | |
| typedef enum RNG90_Data_Status_t | RNG90_Data_Status |
| Alias for enum RNG90_Data_Status_t representing RNG90 data validity status. | |
| typedef struct RNG90_Frame_t | RNG90_Frame |
| Alias for struct RNG90_Frame_t representing an RNG90 data frame. | |
Functions | |
| RNG90_Status | rng90_init (void) |
| RNG90_SelfTest_Status | rng90_selftest (RNG90_Run_SelfTest test) |
| Initializes the RNG90 device by running a self-test. | |
| RNG90_Status | rng90_info (RNG90_Info *info) |
| Requests device information from the RNG90 and fills an info structure. | |
| RNG90_Status | rng90_random (unsigned char *numbers) |
| Requests random numbers from the RNG90 device and stores them in a buffer. | |
| RNG90_Status | rng90_serial (unsigned char *serial) |
| Reads the device serial number from the RNG90 and stores it in a buffer. | |
Header file with declarations and macros for driving an rng90.
This file provides function prototypes, type definitions, and constants for communication with an rng90 crypto chip.
| #define RNG90_ADDRESS 0x40 |
Defines the TWI/I2C address of the RNG90 device.
This macro specifies the 7-bit I2C slave address used to communicate with the RNG90 device on the TWI/I2C bus. The value can be overridden by defining RNG90_ADDRESS before including this header if the hardware configuration uses a different address.
| #define RNG90_CRC_POLYNOMIAL 0x8005 |
Defines the CRC polynomial used for error checking in RNG90 communications.
This macro specifies the polynomial value used in the cyclic redundancy check (CRC) algorithm for verifying data integrity during communication with the RNG90 device. The polynomial is typically represented in hexadecimal format and is essential for ensuring that transmitted data has not been corrupted.
| #define RNG90_CRC_SIZE 2UL |
Defines the size of the CRC field used by the RNG90 device.
This macro specifies the length, in bytes, of the CRC value appended to data frames exchanged with the RNG90 device. The CRC size is used by the application to allocate buffers and to validate received data integrity.
| #define RNG90_EXECUTE_COMMAND 0x03 |
Defines the execute command for the RNG90 device.
This macro specifies the command value used to initiate the execution of a specific operation on the RNG90 device via the communication interface. The value can be overridden by defining RNG90_EXECUTE_COMMAND before including this header if a different command is required by the specific hardware or protocol configuration.
| #define RNG90_HAL_PLATFORM avr0 |
| #define RNG90_INFO_EXECUTION_TIME_MS 1UL |
Defines the typical execution time for RNG90 info commands in milliseconds.
This macro specifies the expected time, in milliseconds, that the RNG90 device requires to process an information or status query before the result can be safely read. The value can be adjusted if timing measurements or a different device configuration indicate a longer or shorter processing time is needed.
| #define RNG90_INFO_FRAME_SIZE 7UL |
Defines the frame size for information responses from the RNG90 device. [conversation_history:1].
This macro specifies the number of bytes in an information or status frame returned by the RNG90 device. [conversation_history:1] It is used by the application to allocate buffers and to parse the received info frames correctly. [conversation_history:1]
| #define RNG90_NEW_BUS_TRANSMISSION_US 2UL |
Defines the minimum delay between two I2C bus transmissions.
This macro specifies the delay time, in microseconds, that should be observed between consecutive transmissions on the I2C bus when communicating with the RNG90 device. It can be overridden before including this header to meet specific timing or bus-load requirements.
| #define RNG90_NUMBER_FRAME_SIZE 35UL |
Defines the frame size for random number responses from the RNG90 device.
This macro specifies the total number of bytes in a data frame that contains random numbers or similar payload returned by the RNG90 device. It is used by the application to allocate buffers and to correctly parse frames that carry random data.
| #define RNG90_OPERATION_INFO 0x30 |
Defines the command code for querying operation information of the RNG90 device.
This macro specifies the base command used to request operation or status information from the RNG90 device via the communication interface. The associated parameter macros RNG90_OPERATION_INFO_PARAM1 and RNG90_OPERATION_INFO_PARAM2 further refine the request.
| #define RNG90_OPERATION_INFO_PARAM1 0x00 |
Defines the first parameter for the RNG90 operation info command.
This macro specifies the first parameter value used together with RNG90_OPERATION_INFO when requesting operation information from the RNG90 device. It can be overridden before including this header to adapt the command to a specific use case.
| #define RNG90_OPERATION_INFO_PARAM2 0x0000 |
Defines the second parameter for the RNG90 operation info command.
This macro specifies the second parameter value used together with RNG90_OPERATION_INFO when requesting operation information from the RNG90 device. It is typically a 16-bit value and may encode additional options or sub-functions of the command.
| #define RNG90_OPERATION_RANDOM 0x16 |
Defines the command code for random number generation on the RNG90 device.
This macro specifies the base command used to request random data from the RNG90 device. The associated parameter and size macros (RNG90_OPERATION_RANDOM_PARAM1, RNG90_OPERATION_RANDOM_PARAM2, RNG90_OPERATION_RANDOM_DATA_SIZE, RNG90_OPERATION_RANDOM_DATA, and RNG90_OPERATION_RANDOM_RNG_SIZE) further define how the random data request is configured and how much data is returned.
| #define RNG90_OPERATION_RANDOM_DATA 0x00 |
Defines the data buffer for random data generated by the RNG90 device.
This macro specifies the data buffer used to store the random bytes generated by the RNG90 device when the RNG90_OPERATION_RANDOM command is executed. It can be overridden before including this header to adapt the buffer to a specific use case.
| #define RNG90_OPERATION_RANDOM_DATA_SIZE 20UL |
Defines the size of random data to be generated by the RNG90 device.
This macro specifies the number of random bytes to be generated and returned by the RNG90 device when the RNG90_OPERATION_RANDOM command is executed. The value can be adjusted based on application requirements, but must not exceed the maximum supported size of the device.
| #define RNG90_OPERATION_RANDOM_PARAM1 0x00 |
Defines the first parameter for the RNG90 random number generation command.
This macro specifies the first parameter value used together with RNG90_OPERATION_RANDOM when requesting random data from the RNG90 device. It can be overridden before including this header to adapt the command to a specific use case.
| #define RNG90_OPERATION_RANDOM_PARAM2 0x0000 |
Defines the second parameter for the RNG90 random number generation command.
This macro specifies the second parameter value used together with RNG90_OPERATION_RANDOM when requesting random data from the RNG90 device. It is typically a 16-bit value and may encode additional options or sub-functions of the command.
| #define RNG90_OPERATION_RANDOM_RNG_SIZE 32UL |
Defines the size of the RNG state or seed used by the RNG90 device.
This macro specifies the size of the internal random number generator (RNG) state or seed used by the RNG90 device. This value is important for ensuring the quality and security of the generated random numbers.
| #define RNG90_OPERATION_READ 0x02 |
Defines the command code for reading data from the RNG90 device.
This macro specifies the base command used to read data from the RNG90 device. The associated parameter and size macros (RNG90_OPERATION_READ_PARAM1, RNG90_OPERATION_READ_PARAM2, RNG90_OPERATION_READ_DATA_SIZE, and RNG90_OPERATION_READ_SERIAL_SIZE) further define how the read request is configured and how much data is returned.
| #define RNG90_OPERATION_READ_DATA_SIZE 16UL |
Defines the size of data to be read from the RNG90 device.
This macro specifies the number of bytes to be read from the RNG90 device when the RNG90_OPERATION_READ command is executed. The value can be adjusted based on application requirements, but must not exceed the maximum supported size of the device.
| #define RNG90_OPERATION_READ_PARAM1 0x01 |
Defines the first parameter for the RNG90 read command.
This macro specifies the first parameter value used together with RNG90_OPERATION_READ when requesting data from the RNG90 device. It can be overridden before including this header to adapt the command to a specific use case.
| #define RNG90_OPERATION_READ_PARAM2 0x0000 |
Defines the second parameter for the RNG90 read command.
This macro specifies the second parameter value used together with RNG90_OPERATION_READ when requesting data from the RNG90 device. It is typically a 16-bit value and may encode additional options or sub-functions of the command.
| #define RNG90_OPERATION_READ_SERIAL_SIZE 8UL |
Defines the size of the serial number data read from the RNG90 device.
This macro specifies the number of bytes used for the serial number or identification data when reading from the RNG90 device (for example as part of a device information or ID readout sequence). The value can be adjusted to match the format and length defined by the device specification or application requirements.
| #define RNG90_OPERATION_SELF_TEST 0x77 |
Defines the command code for triggering self-test routines on the RNG90 device.
This macro specifies the base command used to start or query internal self-test functions of the RNG90 device, such as DRBG and SHA-256 checks. The associated parameter macros (RNG90_OPERATION_SELF_TEST_PARAM1_* and RNG90_OPERATION_SELF_TEST_PARAM2) select which tests are executed and how the command is interpreted.
| #define RNG90_OPERATION_SELF_TEST_PARAM1_READ 0x00 |
Parameter for reading self-test status from the RNG90 device.
This macro defines the value for the first parameter of the RNG90_OPERATION_SELF_TEST command when only the current self-test status or result should be read without starting a new test.
| #define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG 0x01 |
Parameter for running the DRBG self-test on the RNG90 device.
This macro defines the value for the first parameter of the RNG90_OPERATION_SELF_TEST command when the deterministic random bit generator (DRBG) self-test should be executed.
| #define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG_AND_SHA256 0x21 |
Parameter for running both DRBG and SHA-256 self-tests on the RNG90 device.
This macro defines the value for the first parameter of the RNG90_OPERATION_SELF_TEST command when both the DRBG and the SHA-256 self-tests should be executed in a combined test sequence.
| #define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_SHA256 0x20 |
Parameter for running the SHA-256 self-test on the RNG90 device.
This macro defines the value for the first parameter of the RNG90_OPERATION_SELF_TEST command when the internal SHA-256 functionality should be verified by a self-test.
| #define RNG90_OPERATION_SELF_TEST_PARAM2 0x0000 |
Defines the second parameter for the RNG90 self-test command.
This macro specifies the second parameter value used together with RNG90_OPERATION_SELF_TEST. It is typically a 16-bit value reserved for future extensions or additional options and is usually kept at its default value.
| #define RNG90_RANDOM_EXECUTION_TIME_MS 75UL |
Defines the typical execution time for RNG90 random number generation commands in milliseconds.
This macro specifies the expected time, in milliseconds, that the RNG90 device requires to generate and provide random data after receiving a random number generation command. The value can be adjusted if timing measurements or a different device configuration indicate a longer or shorter processing time is needed.
| #define RNG90_READ_EXECUTION_TIME_MS 1UL |
Defines the typical execution time for RNG90 read commands in milliseconds.
This macro specifies the expected time, in milliseconds, that the RNG90 device requires to process a read command before the requested data can be safely retrieved. The value can be adjusted if timing measurements or a different device configuration indicate a longer or shorter processing time is needed.
| #define RNG90_RESET_COMMAND 0x00 |
Defines the reset command for the RNG90 device.
This macro specifies the command value used to reset the RNG90 device via the communication interface. The value can be overridden by defining RNG90_RESET_COMMAND before including this header if a different reset command is required by the hardware or protocol configuration.
| #define RNG90_SELFTEST_EXECUTION_TIME_MS 32UL |
Defines the typical execution time for RNG90 self-test commands in milliseconds.
This macro specifies the expected time, in milliseconds, that the RNG90 device requires to complete self-test routines after receiving a self-test command. The value can be adjusted if timing measurements or a different device configuration indicate a longer or shorter processing time is needed.
| #define RNG90_SELFTEST_STATUS_DRBG_SELFTEST_FAIL 0x01 |
Defines the self-test status code indicating the DRBG self-test failed on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that the deterministic random bit generator (DRBG) self-test has failed. This may indicate an internal fault or malfunction within the DRBG component of the device.
| #define RNG90_SELFTEST_STATUS_DRBG_SELFTEST_NOT_RUN 0x02 |
Defines the self-test status code indicating the DRBG self-test was not run on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that the DRBG self-test was not executed. This may occur if the self-test command was configured to skip the DRBG test or if an error prevented its execution.
| #define RNG90_SELFTEST_STATUS_DRBG_SHA256_SELFTEST_FAIL 0x21 |
Defines the self-test status code indicating both DRBG and SHA-256 self-tests failed on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that both the DRBG and SHA-256 self-tests have failed. This may indicate multiple internal faults or malfunctions within the cryptographic components of the device.
| #define RNG90_SELFTEST_STATUS_ERROR 0xFF |
Defines the self-test status code indicating an error occurred during self-testing on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that an error occurred while performing self-tests. This may be due to internal issues or resource constraints that prevented the tests from completing successfully.
| #define RNG90_SELFTEST_STATUS_NEITHER_SELFTEST_NOT_RUN 0x12 |
Defines the self-test status code indicating neither DRBG nor SHA-256 self-tests were run on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that neither the DRBG nor the SHA-256 self-tests were executed. This may occur if the self-test command was configured to skip both tests or if an error prevented their execution.
| #define RNG90_SELFTEST_STATUS_PASSED_SUCCESSFULLY 0x00 |
Defines the self-test status code indicating all tests passed successfully on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that all executed self-tests, including DRBG and SHA-256 tests, have completed successfully without any errors. This status confirms the integrity and proper functioning of the device's cryptographic components.
| #define RNG90_SELFTEST_STATUS_SHA256_SELFTEST_FAIL 0x20 |
Defines the self-test status code indicating the SHA-256 self-test failed on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that the SHA-256 self-test has failed. This may indicate an internal fault or malfunction within the SHA-256 component of the device.
| #define RNG90_SELFTEST_STATUS_SHA256_SELFTEST_NOT_RUN 0x10 |
Defines the self-test status code indicating the SHA-256 self-test was not run on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that the SHA-256 self-test was not executed. This may occur if the self-test command was configured to skip the SHA-256 test or if an error prevented its execution.
| #define RNG90_SERIAL_FRAME_SIZE 19UL |
Defines the frame size for serial number responses from the RNG90 device.
This macro specifies the total number of bytes in a data frame that contains the device serial number or identification data returned by the RNG90 device. It is used by the application to allocate buffers and to correctly parse frames that carry serial or ID information.
| #define RNG90_SLEEP_COMMAND1 0x01 |
Defines the first sleep command for the RNG90 device.
This macro specifies the command value used to put the RNG90 device into a low-power or sleep mode via the communication interface. The value can be overridden by defining RNG90_SLEEP_COMMAND1 before including this header if a different command is required by the specific hardware or protocol configuration.
| #define RNG90_SLEEP_COMMAND2 0x02 |
Defines the second sleep command for the RNG90 device.
This macro specifies an additional command value used to place the RNG90 device into a low-power or sleep mode via the communication interface. The value can be overridden by defining RNG90_SLEEP_COMMAND2 before including this header if a different command is required by the specific hardware or protocol configuration.
| #define RNG90_STANDARD_FRAME_SIZE 4UL |
Defines the standard frame size used by the RNG90 device.
This macro specifies the default number of bytes in a standard data frame exchanged with the RNG90 device. It is typically used for basic commands or responses that follow a fixed-length frame format and can be adjusted if a different framing scheme is required.
| #define RNG90_STATUS_AFTER_WAKE 0x11 |
Defines the status code indicating the RNG90 device has just woken up from sleep mode.
This macro specifies the status value returned by the RNG90 device to indicate that it has recently transitioned from a low-power sleep state back to active operation. This status can be used by the application to handle any necessary re-initialization or state management after waking up.
| #define RNG90_STATUS_CRC_OR_COMMUNICATION_ERROR 0xFF |
Defines the status code for a CRC or communication error with the RNG90 device.
This macro specifies the status value used to indicate that a cyclic redundancy check (CRC) error or other communication error occurred while exchanging data with the RNG90 device. This typically means that the received data was corrupted or incomplete.
| #define RNG90_STATUS_EXECUTION_ERROR 0x0F |
Defines the status code for an execution error on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that an error occurred during the execution of a command. This may be due to internal issues or resource constraints.
| #define RNG90_STATUS_HEALTH_TEST_ERROR 0x08 |
Defines the status code for a health test error on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that a health test has failed. Health tests are typically used to verify the integrity and proper functioning of the random number generator components.
| #define RNG90_STATUS_PARSE_ERROR 0x03 |
Defines the status code for a parse error on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that there was an error parsing the received command or parameters. This typically means that the command format was incorrect or contained invalid values.
| #define RNG90_STATUS_SELF_TEST_ERROR 0x07 |
Defines the status code for a self-test error on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that a self-test routine has failed. This may indicate an internal fault or malfunction within the device's cryptographic components.
| #define RNG90_STATUS_SUCCESSFUL_COMMAND_EXECUTION 0x00 |
Defines the status code for a successfully executed command on the RNG90 device.
This macro specifies the status value returned by the RNG90 device to indicate that a command has been processed and completed without errors. It can be checked by the application after a transaction to verify proper command execution.
| #define RNG90_STATUS_TWI_ERROR 0xF0 |
Defines the status code for a TWI/I2C communication error with the RNG90 device.
This macro specifies the status value used to indicate that a communication error occurred on the TWI/I2C bus while interacting with the RNG90 device. This may be due to bus contention, incorrect addressing, or other transmission issues.
| #define RNG90_WDT_RESET_TIME_MS 1300UL |
Defines the watchdog timer reset time for the RNG90 device in milliseconds.
This macro specifies the time, in milliseconds, after which the watchdog timer (WDT) of the RNG90 device will trigger a reset if not serviced. This value is important for ensuring that the device can recover from unexpected conditions or hangs. The value can be adjusted based on application requirements and system design.
| typedef enum RNG90_Data_Status_t RNG90_Data_Status |
Alias for enum RNG90_Data_Status_t representing RNG90 data validity status.
| typedef struct RNG90_Frame_t RNG90_Frame |
Alias for struct RNG90_Frame_t representing an RNG90 data frame.
| typedef struct RNG90_Info_t RNG90_Info |
Alias for struct RNG90_Info_t representing RNG90 device information.
| typedef struct RNG90_Packet_t RNG90_Packet |
Alias for struct RNG90_Packet_t representing an RNG90 packet.
| typedef enum RNG90_Run_SelfTest_t RNG90_Run_SelfTest |
Alias for enum RNG90_Run_SelfTest_t representing RNG90 self-test selections.
| typedef enum RNG90_SelfTest_Status_t RNG90_SelfTest_Status |
Alias for enum RNG90_SelfTest_Status_t representing RNG90 self-test result codes.
| typedef enum RNG90_Status_t RNG90_Status |
Alias for enum RNG90_Status_t representing RNG90 status codes.
| enum RNG90_Data_Status_t |
Indicates whether received RNG90 data is valid.
This enumeration is used to represent the validation result of data obtained from the RNG90 device. It distinguishes between data that has been verified as correct and usable, and data that failed checks such as CRC or format validation.
| Enumerator | |
|---|---|
| RNG90_Data_Status_Valid | Data is valid and passed all checks |
| RNG90_Data_Status_Invalid | Data is invalid or failed verification |
| enum RNG90_Run_SelfTest_t |
Selects which self-test routine to run on the RNG90 device.
This enumeration defines the available self-test options that can be requested from the RNG90 device via the self-test operation command. It allows triggering the DRBG self-test, the SHA-256 self-test, or a combined self-test that runs both DRBG and SHA-256 checks.
| Enumerator | |
|---|---|
| RNG90_Run_DRBG_SelfTest | Run only the DRBG self-test |
| RNG90_Run_SHA256_SelfTest | Run only the SHA-256 self-test |
| RNG90_Run_DBRG_SHA256_SelfTest | Run both DRBG and SHA-256 self-tests |
Represents the result status of self-test routines on the RNG90 device.
This enumeration defines the possible outcome codes reported by the RNG90 device after executing internal self-tests. It distinguishes between successful completion, individual DRBG or SHA-256 failures, tests that were not executed, combined DRBG/SHA-256 failures, and a generic error state.
| enum RNG90_Status_t |
Represents status codes returned by the RNG90 device.
This enumeration defines symbolic names for the various status values that can be reported by the RNG90 device after a command execution. It covers successful execution as well as different error and indication conditions, such as parse errors, self-test failures, health test failures, execution errors, wake-up indications, TWI communication errors, and other CRC or communication-related errors.
| RNG90_Status rng90_info | ( | RNG90_Info * | info | ) |
Requests device information from the RNG90 and fills an info structure.
| info | Pointer to an RNG90_Info structure that will be populated with the following fields if the command completes successfully:
|
info was filled.This function requests device information from the RNG90 and evaluates the returned frame. Depending on the response type, it either interprets the first data byte as a self-test status or extracts the identification fields into info and returns an appropriate status code.

| RNG90_Status rng90_init | ( | void | ) |
| RNG90_Status rng90_random | ( | unsigned char * | numbers | ) |
Requests random numbers from the RNG90 device and stores them in a buffer.
| numbers | Pointer to a buffer where the received random bytes will be stored. |
numbers.This function sends a random-number request to the RNG90 device, transmits the associated payload and CRC over TWI/I2C, and then reads back the response frame. Depending on the response type, it either copies the received random bytes into numbers or returns an appropriate status code.

| RNG90_SelfTest_Status rng90_selftest | ( | RNG90_Run_SelfTest | test | ) |
Initializes the RNG90 device by running a self-test.
This function performs an initialization sequence for the RNG90 device by invoking the rng90_selftest() routine with RNG90_Run_DRBG_SelfTest to verify the deterministic random bit generator (DRBG) functionality. If the self-test does not report RNG90_SelfTest_Success, the function returns RNG90_Status_SelfTest_Error to indicate that the device failed initialization. When the DRBG self-test completes successfully, the function returns RNG90_Status_Success`, signaling that the RNG90 is ready for normal operation. */ RNG90_Status rng90_init(void) { if(rng90_selftest(RNG90_Run_DRBG_SelfTest) != RNG90_SelfTest_Success) { return RNG90_Status_SelfTest_Error; } return RNG90_Status_Success; }
static void rng90_write(RNG90_Packet *packet) { unsigned char *ptr = (unsigned char *)packet; packet->count += 7;
crc16_init( 0x0000 );
twi_address( 0x40 , TWI_Write); twi_set( 0x03 );
for (unsigned char i=0; i < (sizeof(RNG90_Packet) - 2UL ); i++) { crc16_update(*(ptr + i)); twi_set(*(ptr + i)); } }
static void rng90_command(RNG90_Packet *packet) { twi_start(); rng90_write(packet);
packet->crc = crc16_result();
twi_set((unsigned char)(0x00FF & packet->crc)); twi_set((unsigned char)(0x00FF & (packet->crc>>8))); twi_stop(); }
static RNG90_Frame rng90_frame;
static RNG90_Frame rng90_data(unsigned char *data) { crc16_init( 0x0000 );
unsigned char temp = 0; unsigned int crc = 0x0000;
rng90_frame.length = 1 + 2UL ; rng90_frame.status = RNG90_Data_Status_Invalid;
twi_start(); twi_address( 0x40 , TWI_Read);
for (unsigned char i=0; i < rng90_frame.length - 2UL ; i++) {
twi_get(&temp, TWI_ACK); crc16_update(temp);
if(i == 0) { rng90_frame.length = temp; continue; } (data + i - 1) = temp; }
twi_get(&temp, TWI_ACK); crc = (0x00FF & temp); twi_get(&temp, TWI_NACK); crc |= (0xFF00 & (temp<<8));
rng90_frame.status = RNG90_Data_Status_Valid;
if (crc != crc16_result()) { rng90_frame.status = RNG90_Data_Status_Invalid; } return rng90_frame; }
/**
Executes a self-test routine on the RNG90 device.
| test | Specifies which self-test to run, using a value from RNG90_Run_SelfTest: |
This function triggers a self-test on the RNG90 device according to the selected test mode and evaluates the returned status code. Depending on the self-test result, an appropriate RNG90_SelfTest_Status value is returned to the caller.

| RNG90_Status rng90_serial | ( | unsigned char * | serial | ) |
Reads the device serial number from the RNG90 and stores it in a buffer.
| serial | Pointer to a buffer where the received serial number bytes will be stored. |
The buffer must be able to hold at least RNG90_OPERATION_READ_SERIAL_SIZE bytes.
serial was filled.This function sends a read command to the RNG90 device to obtain its serial number. After the command has been processed, the response frame is evaluated. If valid serial data is returned, the bytes are copied into serial and an appropriate RNG90_Status value is returned.
