TEXT   46
hwrng init
Guest on 17th September 2023 09:45:43 PM


  1. #include <c8051f120.h>
  2.  
  3. void hwrng_init( ) {
  4.         char save = SFRPAGE;
  5.         SFRPAGE = TMR3_PAGE;
  6.  
  7.         RCAP3L = 0x00;
  8.         RCAP3H = 0x00;
  9.         TMR3CF = 0x08; /* no special features, clock divider = 1 */
  10.         TMR3CN = 0x04; /* enable timer3 in auto-reload mode */
  11.  
  12.         SFRPAGE = save;
  13. }
  14.  
  15. unsigned short hwrng_random( ) {
  16.         unsigned short ret;
  17.         char save = SFRPAGE;
  18.         SFRPAGE = TMR3_PAGE;
  19.        
  20.         ret = (TMR3H << 8) | (TMR3L);
  21.  
  22.         SFRPAGE = save;
  23.         return ret;
  24. }

Raw Paste

Login or Register to edit or fork this paste. It's free.