Commit d1b04bca authored by Martin Ling's avatar Martin Ling Committed by Rahix
Browse files

feat(trng): Add TRNG read to Epicardium API

parent 6c2d7e47
......@@ -8,7 +8,6 @@
#include "ble_api.h"
#include "hci_vs.h"
#include "att_api.h"
#include "trng.h"
#include "FreeRTOS.h"
#include "timers.h"
......@@ -101,7 +100,7 @@ static void setAddress(void)
bdAddr[0] = 0xCA;
bdAddr[1] = 0x4D;
bdAddr[2] = 0x10;
TRNG_Read(MXC_TRNG, bdAddr + 3, 3);
epic_trng_read(bdAddr + 3, 3);
sprintf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x\n",
bdAddr[0],
......
......@@ -98,6 +98,9 @@ typedef _Bool bool;
#define API_GPIO_GET_PIN_MODE 0xA1
#define API_GPIO_WRITE_PIN 0xA2
#define API_GPIO_READ_PIN 0xA3
#define API_TRNG_READ 0xB0
/* clang-format on */
typedef uint32_t api_int_id_t;
......@@ -1209,4 +1212,21 @@ API(API_RTC_SCHEDULE_ALARM, int epic_rtc_schedule_alarm(uint32_t timestamp));
*/
API_ISR(EPIC_INT_RTC_ALARM, epic_isr_rtc_alarm);
/**
* TRNG
* ====
*/
/**
* Read random bytes from the TRNG.
*
* :param uint8_t * dest: Destination buffer
* :param size: Number of bytes to read.
* :return: `0` on success or a negative value if an error occured. Possible
* errors:
*
* - ``-EFAULT``: Invalid destination address.
*/
API(API_TRNG_READ, int epic_trng_read(uint8_t *dest, size_t size));
#endif /* _EPICARDIUM_H */
......@@ -18,6 +18,7 @@
#include "gpio.h"
#include "i2c.h"
#include "spi.h"
#include "trng.h"
/*
* Early init is called at the very beginning and is meant for modules which
......
......@@ -13,5 +13,6 @@ module_sources = files(
'rtc.c',
'serial.c',
'stream.c',
'trng.c',
'vibra.c',
)
#include "epicardium.h"
#include "trng.h"
int epic_trng_read(uint8_t *dest, size_t size)
{
if (dest == NULL)
return -EFAULT;
TRNG_Read(MXC_TRNG, dest, size);
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment