AP_HAL_Linux: add support for hw random number generation

This commit is contained in:
Siddharth Purohit 2021-06-24 22:19:47 +05:30 committed by Andrew Tridgell
parent 2b93b17fae
commit f2e947589d
2 changed files with 21 additions and 0 deletions

View File

@ -287,3 +287,21 @@ void *Util::heap_realloc(void *h, void *ptr, size_t new_size)
}
#endif // ENABLE_HEAP
/**
* This method will read random values with set size.
*/
bool Util::get_random_vals(uint8_t* data, size_t size)
{
int dev_random = open("/dev/urandom", O_RDONLY);
if (dev_random < 0) {
return false;
}
ssize_t result = read(dev_random, data, size);
if (result < 0) {
close(dev_random);
return false;
}
close(dev_random);
return true;
}

View File

@ -94,6 +94,9 @@ public:
_toneAlarm.set_buzzer_tone(frequency, volume, duration_ms);
}
// fills data with random values of requested size
bool get_random_vals(uint8_t* data, size_t size) override;
private:
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
static ToneAlarm_Disco _toneAlarm;