1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include <ch.h>
- #include <stdint.h>
- #include "wolfssl_chibios.h"
- #include "user_settings.h"
- unsigned int chibios_rand_generate(void)
- {
- static unsigned int last_value=0;
- static unsigned int new_value=0;
- unsigned int error_bits = 0;
- error_bits = RNG_SR_SEIS | RNG_SR_CEIS;
- while (new_value==last_value) {
-
- if ( ((RNG->SR & error_bits) == 0) && ( (RNG->SR & RNG_SR_DRDY) == 1 ) )
- new_value=RNG->DR;
- }
- last_value=new_value;
- return new_value;
- }
- int custom_rand_generate_block(unsigned char* output, unsigned int sz)
- {
- uint32_t i = 0;
- while (i < sz)
- {
-
- if( (i + sizeof(CUSTOM_RAND_TYPE)) > sz ||
- ((uint32_t)&output[i] % sizeof(CUSTOM_RAND_TYPE)) != 0
- ) {
-
- output[i++] = (unsigned char)chibios_rand_generate();
- }
- else {
-
- *((CUSTOM_RAND_TYPE*)&output[i]) = chibios_rand_generate();
- i += sizeof(CUSTOM_RAND_TYPE);
- }
- }
- return 0;
- }
|