Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_adc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 #include BOARD_CONFIG
24 #include "mcu.h"
25 #include "mcu_periph/sys_time.h"
26 #include "led.h"
27 #include "mcu_periph/adc.h"
28 #include "mcu_periph/uart.h"
30 
31 int main_periodic(void);
32 static inline void main_init( void );
33 static inline void main_periodic_task( void );
34 static inline void main_event_task( void );
35 
36 static struct adc_buf adc0_buf;
37 static struct adc_buf adc1_buf;
38 static struct adc_buf adc2_buf;
39 static struct adc_buf adc3_buf;
40 
42 
43 static inline void main_init( void ) {
44  mcu_init();
46  adc_init();
47  adc_buf_channel(0, &adc0_buf, 8);
48  adc_buf_channel(1, &adc1_buf, 3);
49  adc_buf_channel(2, &adc2_buf, 3);
50  adc_buf_channel(3, &adc3_buf, 3);
51 }
52 
53 int main( void ) {
54  main_init();
55 
56  while(1) {
59  }
61  }
62  return 0;
63 }
64 
65 static inline void main_periodic_task( void ) {
66  RunOnceEvery(100, {DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);});
67  RunOnceEvery(100, {/*LED_TOGGLE(7);*/ DOWNLINK_SEND_TIME(DefaultChannel, DefaultDevice, &sys_time.nb_sec);});
68  LED_PERIODIC();
69 }
70 
71 static inline void main_event_task( void ) {
72 
75  uint16_t v1 = 123;
76  uint16_t v2 = 123;
77  // v1 = (((adc0_buf.values[0])));
79  v2 = (((adc3_buf.values[0])));
80  RunOnceEvery(100, {DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, DefaultDevice, &v1, &v2)});
81  }
82 
83 }
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:61
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
uint16_t values[MAX_AV_NB_SAMPLE]
Definition: adc.h:62
static void main_event_task(void)
Definition: test_adc.c:71
static void main_init(void)
Definition: test_adc.c:43
uint8_t av_nb_sample
Definition: adc.h:64
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
static struct adc_buf adc1_buf
Definition: test_adc.c:37
int main(void)
Definition: test_adc.c:53
Architecture independent timing functions.
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:37
uint8_t adc_new_data_trigger
Definition: adc_arch.c:104
static bool_t sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:111
#define LED_PERIODIC()
Definition: led_hw.h:8
Arch independent mcu ( Micro Controller Unit ) utilities.
static struct adc_buf adc0_buf
Definition: test_adc.c:36
unsigned char uint8_t
Definition: types.h:14
int main_periodic(void)
Definition: main.c:194
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
static void main_periodic_task(void)
Definition: test_adc.c:65
void adc_init(void)
Starts conversions.
Definition: adc_arch.c:194
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
arch independent LED (Light Emitting Diodes) API
static struct adc_buf adc3_buf
Definition: test_adc.c:39
static struct adc_buf adc2_buf
Definition: test_adc.c:38