Andriy Makukha
/
football_project_wo_output
football_project_wo_output
Fork of football_project by
Diff: main.cpp
- Revision:
- 48:4c9551c826e9
- Parent:
- 46:28c29ef61276
- Child:
- 49:626e84ce5e52
--- a/main.cpp Mon Jan 11 16:38:59 2016 +0000 +++ b/main.cpp Tue Jan 12 00:05:34 2016 +0000 @@ -206,7 +206,7 @@ 'T', 'X' }; // Custom ID trick UARTService *uartServicePtr; -PhoneAppIO *phoneP; +PhoneAppIO *phoneP = NULL; BatteryService *battServiceP; // Buffer for holding data from the phone @@ -350,7 +350,7 @@ extern "C" void writeToPhone(char *format, ...) { va_list arg; - va_start(arg, format ); + va_start( arg, format ); /**/phoneP->vprintf( format, arg ); @@ -632,6 +632,8 @@ #endif */ + srnd( rndHW() ); // Seed the sw RNG w/ the hw. + uint32_t p_count; uint32_t pstorageErr = pstorage_init(); // This needs to be called, even though apparently called in bootloader--Check other stuff. pstorage_access_status_get( &p_count ); @@ -752,4 +754,39 @@ NVIC_SystemReset(); } +extern "C" uint32_t rndHW() +{ + uint32_t rndVal; + uint8_t bytes_available; + for(;;) + { + sd_rand_application_bytes_available_get( &bytes_available ); + if( bytes_available >= 4 ) + { + if( NRF_SUCCESS == sd_rand_application_vector_get( (uint8_t *)&rndVal, 4 ) ) + break; + } + } + + return rndVal; +} + +static uint32_t rndZ = 0xCAFE, rndW = 0xF00D; +// Seed for rnd() +extern "C" void srnd( uint32_t seed ) +{ + rndZ = 0xCAFE; + rndW = seed; +} + +// Simple RNG -- Allows cross-platform compat if we want to run +// an apples-to-apples freeform competition by using same seed. +extern "C" uint32_t rnd() +{ + rndZ = 36969 * (rndZ & 0xffff) + (rndZ >>16); + rndW = 18000 * (rndW & 0xffff) + (rndW >>16); + + return ((rndZ <<16) + rndW); +} + /* EOF */