diff options
Diffstat (limited to 'board/hammer/board.c')
-rw-r--r-- | board/hammer/board.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/board/hammer/board.c b/board/hammer/board.c index d50634aab8..b9f21acf1d 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -9,12 +9,14 @@ #include "touchpad_elan.h" #include "gpio.h" #include "hooks.h" +#include "hwtimer.h" #include "i2c.h" #include "keyboard_raw.h" #include "keyboard_scan.h" #include "pwm.h" #include "pwm_chip.h" #include "registers.h" +#include "rollback.h" #include "task.h" #include "timer.h" #include "update_fw.h" @@ -135,3 +137,30 @@ void board_usb_wake(void) gpio_set_flags(GPIO_BASE_DET, GPIO_INPUT); interrupt_enable(); } + +/* + * Get entropy based on Clock Recovery System, which is enabled on hammer to + * synchronize USB SOF with internal oscillator. + */ +int board_get_entropy(void *buffer, int len) +{ + int i = 0; + uint8_t *data = buffer; + uint32_t start; + /* We expect one SOF per ms, so wait at most 2ms. */ + const uint32_t timeout = 2*MSEC; + + for (i = 0; i < len; i++) { + STM32_CRS_ICR |= STM32_CRS_ICR_SYNCOKC; + start = __hw_clock_source_read(); + while (!(STM32_CRS_ISR & STM32_CRS_ISR_SYNCOKF)) { + if ((__hw_clock_source_read() - start) > timeout) + return 0; + usleep(500); + } + /* Pick 8 bits, including FEDIR and 7 LSB of FECAP. */ + data[i] = STM32_CRS_ISR >> 15; + } + + return 1; +} |