first cut at turnon scripts for EasyTimer v2
[fw/altos] / src / drivers / ao_trng.c
index db7429282620fac4fef34aa00c216cba4b9d8bf3..d89cc81a3809610c36ffbb212a20c9b2ff34d0e7 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -29,7 +30,8 @@ ao_trng_fetch(void)
        int             usb_buf_id;
        uint16_t        i;
        uint16_t        *buf;
-       uint32_t        *rnd;
+       uint16_t        t;
+       uint32_t        *rnd = (uint32_t *) ao_adc_ring;
 
        if (!buffer[0]) {
                buffer[0] = ao_usb_alloc();
@@ -50,10 +52,12 @@ ao_trng_fetch(void)
 
        ao_led_on(AO_LED_TRNG_READ);
        while (count--) {
-               rnd = (uint32_t *) ao_adc_get(AO_USB_IN_SIZE);  /* one 16-bit value per output byte */
+               t = ao_adc_get(AO_USB_IN_SIZE) >> 1;    /* one 16-bit value per output byte */
                buf = buffer[usb_buf_id];
-               for (i = 0; i < AO_USB_IN_SIZE / sizeof (uint16_t); i++)
-                       *buf++ = ao_crc_in_32_out_16(*rnd++);
+               for (i = 0; i < AO_USB_IN_SIZE / sizeof (uint16_t); i++) {
+                       *buf++ = ao_crc_in_32_out_16(rnd[t]);
+                       t = (t + 1) & ((AO_ADC_RING_SIZE>>1) - 1);
+               }
                ao_adc_ack(AO_USB_IN_SIZE);
                ao_led_toggle(AO_LED_TRNG_READ|AO_LED_TRNG_WRITE);
                ao_usb_write(buffer[usb_buf_id], AO_USB_IN_SIZE);