mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
AP_HAL_Linux: add support for hw random number generation
This commit is contained in:
parent
2b93b17fae
commit
f2e947589d
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user