From bc7afe28ae154e8819b278e3e78313bc9f38c269 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Fri, 5 Sep 2014 23:25:58 +0200 Subject: [PATCH] [test] update test_adc send all raw ADC values --- sw/airborne/test/mcu_periph/test_adc.c | 54 ++++++++++++++------- sw/airborne/test/test_adcs.c | 66 -------------------------- 2 files changed, 37 insertions(+), 83 deletions(-) delete mode 100644 sw/airborne/test/test_adcs.c diff --git a/sw/airborne/test/mcu_periph/test_adc.c b/sw/airborne/test/mcu_periph/test_adc.c index 09f31c1291c..54d27262416 100644 --- a/sw/airborne/test/mcu_periph/test_adc.c +++ b/sw/airborne/test/mcu_periph/test_adc.c @@ -33,25 +33,41 @@ static inline void main_init( void ); static inline void main_periodic_task( void ); static inline void main_event_task( void ); -static struct adc_buf adc0_buf; -static struct adc_buf adc1_buf; -static struct adc_buf adc2_buf; -static struct adc_buf adc3_buf; -static struct adc_buf vsupply_buf; +#define ADC_NB_SAMPLES 16 -#ifndef VoltageOfAdc -#define VoltageOfAdc(adc) DefaultVoltageOfAdc(adc) -#endif +static struct adc_buf buf_adc[NB_ADC]; static inline void main_init( void ) { mcu_init(); - sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL); + sys_time_register_timer((1./100), NULL); adc_init(); - adc_buf_channel(0, &adc0_buf, 8); - adc_buf_channel(1, &adc1_buf, 3); - adc_buf_channel(2, &adc2_buf, 3); - adc_buf_channel(3, &adc3_buf, 3); - adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_buf, DEFAULT_AV_NB_SAMPLE); + +#ifdef ADC_0 + adc_buf_channel(ADC_0, &buf_adc[0], ADC_NB_SAMPLES); +#endif +#ifdef ADC_1 + adc_buf_channel(ADC_1, &buf_adc[1], ADC_NB_SAMPLES); +#endif +#ifdef ADC_2 + adc_buf_channel(ADC_2, &buf_adc[2], ADC_NB_SAMPLES); +#endif +#ifdef ADC_3 + adc_buf_channel(ADC_3, &buf_adc[3], ADC_NB_SAMPLES); +#endif +#ifdef ADC_4 + adc_buf_channel(ADC_4, &buf_adc[4], ADC_NB_SAMPLES); +#endif +#ifdef ADC_5 + adc_buf_channel(ADC_5, &buf_adc[5], ADC_NB_SAMPLES); +#endif +#ifdef ADC_6 + adc_buf_channel(ADC_6, &buf_adc[6], ADC_NB_SAMPLES); +#endif +#ifdef ADC_7 + adc_buf_channel(ADC_7, &buf_adc[7], ADC_NB_SAMPLES); +#endif + + mcu_int_enable(); } int main( void ) { @@ -71,9 +87,13 @@ static inline void main_periodic_task( void ) { RunOnceEvery(100, {DOWNLINK_SEND_TIME(DefaultChannel, DefaultDevice, &sys_time.nb_sec);}); LED_PERIODIC(); - uint16_t v1 = 10 * VoltageOfAdc((vsupply_buf.sum/vsupply_buf.av_nb_sample)); - uint16_t v2 = 10 * VoltageOfAdc((vsupply_buf.values[0])); - RunOnceEvery(50, {DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, DefaultDevice, &v1, &v2)}); + uint16_t values[NB_ADC]; + uint8_t i; + for(i = 0; i < NB_ADC; i++) + values[i] = buf_adc[i].sum / ADC_NB_SAMPLES; + + uint8_t id = 42; + DOWNLINK_SEND_ADC(DefaultChannel, DefaultDevice, &id, NB_ADC, values); } static inline void main_event_task( void ) { diff --git a/sw/airborne/test/test_adcs.c b/sw/airborne/test/test_adcs.c deleted file mode 100644 index 00b77816d22..00000000000 --- a/sw/airborne/test/test_adcs.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Basic program periodically sending the values of the 8 ADCs - */ - - -#include "std.h" -#include "mcu.h" -#include "mcu_periph/sys_time.h" -#include "mcu_periph/adc.h" -#include "messages.h" -#include "led.h" -#include "mcu_periph/uart.h" -#include "subsystems/datalink/downlink.h" - - -#define NB_ADC 8 -#define ADC_NB_SAMPLES 16 - -static struct adc_buf buf_adc[NB_ADC]; - -int main (int argc, char** argv) { - mcu_init(); - sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL); - led_init(); - adc_init(); - - adc_buf_channel(ADC_0, &buf_adc[0], ADC_NB_SAMPLES); - adc_buf_channel(ADC_1, &buf_adc[1], ADC_NB_SAMPLES); - adc_buf_channel(ADC_2, &buf_adc[2], ADC_NB_SAMPLES); - adc_buf_channel(ADC_3, &buf_adc[3], ADC_NB_SAMPLES); - adc_buf_channel(ADC_4, &buf_adc[4], ADC_NB_SAMPLES); - adc_buf_channel(ADC_5, &buf_adc[5], ADC_NB_SAMPLES); -#ifdef ADC_6 - adc_buf_channel(ADC_6, &buf_adc[6], ADC_NB_SAMPLES); -#endif -#ifdef ADC_7 - adc_buf_channel(ADC_7, &buf_adc[7], ADC_NB_SAMPLES); -#endif - -#if NB_ADC != 8 -#error "8 ADCs expected !" -#endif - -#if USE_UART0 - uart_periph_init(&uart0); -#endif -#if USE_UART1 - uart_periph_init(&uart1); -#endif - - mcu_int_enable(); - - while(1) { - if (sys_time_check_and_ack_timer(0)) { - LED_TOGGLE(1); - uint16_t values[NB_ADC]; - uint8_t i; - for(i = 0; i < NB_ADC; i++) - values[i] = buf_adc[i].sum / ADC_NB_SAMPLES; - - uint8_t id = 42; - DOWNLINK_SEND_ADC(&id, NB_ADC, values); - } - } - return 0; -}