|
rng90 1.0
rng90 driver library
|
Implementation of the RNG90 driver functions. More...
#include "rng90.h"
Functions | |
| 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. | |
Variables | |
| unsigned char | rng90_buffer [87] |
Implementation of the RNG90 driver functions.
This file contains the implementation of functions to initialize the RNG90 device, perform self-tests, retrieve device information, generate random numbers, and read the device serial number. It utilizes TWI/I2C communication to interact with the RNG90 hardware.
| 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_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.

| unsigned char rng90_buffer[87] |