settings for two channels each for better and stable entropy
authorNIIBE Yutaka <gniibe@fsij.org>
Mon, 1 Oct 2012 06:19:32 +0000 (15:19 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Mon, 1 Oct 2012 06:19:32 +0000 (15:19 +0900)
ChangeLog
boards/FST_01/board.h
src/random.c

index 71bdacf..12053ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2012-10-01  Niibe Yutaka  <gniibe@fsij.org>
 
+       * src/random.c (adcgrpcfg): ADC1 and ADC2 channels.
        * src/main.c (neug_setup, USB_NEUG_GET_ERR_COUNT): New.
 
 2012-09-28  Niibe Yutaka  <gniibe@fsij.org>
index a200266..a81ed00 100644 (file)
 #define GPIO_LED       GPIOB_LED
 #define IOPORT_LED     GPIOB
 
+#define NEUG_ADC_SETTING1_SMPR1 ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_1P5) \
+                              | ADC_SMPR1_SMP_VREF(ADC_SAMPLE_1P5)
+#define NEUG_ADC_SETTING1_SMPR2 0
+#define NEUG_ADC_SETTING1_SQR3  ADC_SQR3_SQ2_N(ADC_CHANNEL_SENSOR)   \
+                              | ADC_SQR3_SQ1_N(ADC_CHANNEL_VREFINT)
+#define NEUG_ADC_SETTING1_NUM_CHANNELS 2
+
+#define NEUG_ADC_SETTING2_SMPR1 0
+#define NEUG_ADC_SETTING2_SMPR2 ADC_SMPR2_SMP_AN0(ADC_SAMPLE_1P5)    \
+                              | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_1P5)
+#define NEUG_ADC_SETTING2_SQR3  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0)      \
+                              | ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1)
+#define NEUG_ADC_SETTING2_NUM_CHANNELS 2
+
 /*
  * Board identifier.
  */
 
 /*
  * Port A setup.
+ * PA0  - Digital input with PullUp.  AN0
+ * PA1  - Digital input with PullUp.  AN1
  * PA2  - Push pull output   (For Error LED)
  * PA10 - Push pull output   (USB 1:ON 0:OFF)
  * PA11 - input with pull-up (USBDM)
 
 /*
  * Port C setup.
- * PC0  - Push Pull output 50MHz.
- * PC1  - Push Pull output 50MHz.
  * Everything input with pull-up except:
  */
-#define VAL_GPIOCCRL            0x88888833      /*  PC7...PC0 */
+#define VAL_GPIOCCRL            0x88888888      /*  PC7...PC0 */
 #define VAL_GPIOCCRH            0x88888888      /* PC15...PC8 */
 #define VAL_GPIOCODR            0xFFFFFFFF
 
index 4a2f8ff..9c039d8 100644 (file)
@@ -62,28 +62,19 @@ static void adc2_start (void)
   rccEnableAPB2 (RCC_APB2ENR_ADC2EN, FALSE);
 
   ADC2->CR1 = ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0;
-  ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL | ADC_CR2_CONT | ADC_CR2_ADON;
-#ifdef NEUG_NON_DEFAULT_ADC_CHANNEL
-  ADC2->SMPR1 = 0;
-  ADC2->SMPR2 = ADC_SMPR2_SMP_ANx_B(ADC_SAMPLE_1P5);
-#else
-  ADC2->SMPR1 = ADC_SMPR1_SMP_AN11(ADC_SAMPLE_1P5);
-  ADC2->SMPR2 = 0;
-#endif
-  ADC2->SQR1 = ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS);
+  ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_CONT | ADC_CR2_ADON;
+  ADC2->SMPR1 = NEUG_ADC_SETTING2_SMPR1;
+  ADC2->SMPR2 = NEUG_ADC_SETTING2_SMPR2;
+  ADC2->SQR1 = ADC_SQR1_NUM_CH(NEUG_ADC_SETTING2_NUM_CHANNELS);
   ADC2->SQR2 = 0;
-#ifdef NEUG_NON_DEFAULT_ADC_CHANNEL
-  ADC2->SQR3 = ADC_SQR3_SQ1_N(NEUG_ADC_CHANNEL_B);
-#else
-  ADC2->SQR3 = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11);
-#endif
+  ADC2->SQR3 = NEUG_ADC_SETTING2_SQR3;
 
   chSysUnlock ();
 }
 
 static void adc2_start_conversion (void)
 {
-  ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL | ADC_CR2_CONT | ADC_CR2_ADON;
+  ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_CONT | ADC_CR2_ADON;
 }
 
 void adc2_stop_conversion (void)
@@ -121,21 +112,12 @@ static const ADCConversionGroup adcgrpcfg = {
   adccb,
   adccb_err,
   ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0,
-  ADC_CR2_EXTTRIG | ADC_CR2_SWSTART | ADC_CR2_EXTSEL,
-#ifdef NEUG_NON_DEFAULT_ADC_CHANNEL
-  0,
-  ADC_SMPR2_SMP_ANx_A(ADC_SAMPLE_1P5),
-#else
-  ADC_SMPR1_SMP_AN10(ADC_SAMPLE_1P5),
+  ADC_CR2_TSVREFE | ADC_CR2_EXTTRIG | ADC_CR2_SWSTART | ADC_CR2_EXTSEL,
+  NEUG_ADC_SETTING1_SMPR1,
+  NEUG_ADC_SETTING1_SMPR2,
+  ADC_SQR1_NUM_CH(NEUG_ADC_SETTING1_NUM_CHANNELS),
   0,
-#endif
-  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
-  0,
-#if NEUG_NON_DEFAULT_ADC_CHANNEL
-  ADC_SQR3_SQ1_N(NEUG_ADC_CHANNEL_A)
-#else
-  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN10)
-#endif
+  NEUG_ADC_SETTING1_SQR3
 };
 
 /*