Paparazzi UAS  v5.15_devel-88-gb3ad7fe
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adc_arch.c File Reference

Driver for the analog to digital converters on STM32. More...

#include "mcu_periph/adc.h"
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/adc.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/timer.h>
#include <string.h>
#include "mcu_periph/gpio.h"
#include "mcu_arch.h"
#include "std.h"
#include <BOARD_CONFIG>
+ Include dependency graph for adc_arch.c:

Go to the source code of this file.

Macros

#define NVIC_ADC_IRQ_PRIO   0
 
#define USE_AD3   0
 
#define ADC_TIMER_PERIOD   10000
 
#define ADC_TIMER_FREQUENCY   2000000
 Timer frequency for ADC Timer will trigger an update event after reaching the period reload value. More...
 
#define TIM_ADC   TIM2
 
#define RCC_TIM_ADC   RCC_TIM2
 

Functions

static void adc_init_single (uint32_t adc, uint8_t nb_channels, uint8_t *channel_map)
 
static void adc_push_sample (struct adc_buf *buf, uint16_t sample)
 
static void adc_init_rcc (void)
 Configure and enable RCC for peripherals (ADC1, ADC2, Timer) More...
 
static void adc_init_irq (void)
 Configure and enable ADC interrupt. More...
 
void adc_init (void)
 Starts conversions. More...
 
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: More...
 

Variables

static uint8_t nb_adc1_channels = 0
 
static uint8_t nb_adc2_channels = 0
 
static uint8_t nb_adc3_channels = 0
 

Detailed Description

Driver for the analog to digital converters on STM32.

Usage: Define flags for ADCs to use (can be explicitly disabled by setting to 0):

-DUSE_ADC_1 -DUSE_ADC_3=1 -DUSE_ADC_4=0

would explicitly enable the ADC_1 and ADC_3 and disable ADC_4.

The mapping of these virtual "board" ADC_x numbers to a concrete AD converter and channel is done in the sw/airborne/boards/<boardname>.h header files. Some ADCs are normally already enabled in the board files per default (e.g. for battery voltage measurement).

Definition in file adc_arch.c.

Macro Definition Documentation

#define ADC_TIMER_FREQUENCY   2000000

Timer frequency for ADC Timer will trigger an update event after reaching the period reload value.

New conversion is triggered on update event. ADC measuerement frequency is hence ADC_TIMER_FREQUENCY / ADC_TIMER_PERIOD.

Definition at line 164 of file adc_arch.c.

Referenced by adc_init_rcc().

#define ADC_TIMER_PERIOD   10000

Definition at line 155 of file adc_arch.c.

Referenced by adc_init_rcc().

#define NVIC_ADC_IRQ_PRIO   0

Definition at line 104 of file adc_arch.c.

Referenced by adc_init_irq().

#define RCC_TIM_ADC   RCC_TIM2

Definition at line 422 of file adc_arch.c.

Referenced by adc_init_rcc().

#define TIM_ADC   TIM2

Definition at line 421 of file adc_arch.c.

Referenced by adc_init_rcc().

#define USE_AD3   0

Definition at line 138 of file adc_arch.c.

Function Documentation

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:

1 struct adc_buf channel_buf;
2 adc_buf_channel(1, &channel_buf, 12);

Registers channel_buf as buffer for ADC channel 1, with max index 12 (12 samples).

Registers a buffer to be used to store the specified converted channel Usage:

Todo:
: fx a more general ADC

Definition at line 375 of file adc_arch.c.

References ADC_NUM_CHANNELS, adc_buf::av_nb_sample, MAX_AV_NB_SAMPLE, nb_adc1_channels, nb_adc2_channels, and s.

static void adc_init_irq ( void  )
inlinestatic

Configure and enable ADC interrupt.

Definition at line 463 of file adc_arch.c.

References NVIC_ADC_IRQ_PRIO.

Referenced by adc_init().

+ Here is the caller graph for this function:

static void adc_init_rcc ( void  )
inlinestatic

Configure and enable RCC for peripherals (ADC1, ADC2, Timer)

Definition at line 426 of file adc_arch.c.

References ADC_TIMER_FREQUENCY, ADC_TIMER_PERIOD, RCC_TIM_ADC, TIM_ADC, and timer_get_frequency().

Referenced by adc_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void adc_init_single ( uint32_t  adc,
uint8_t  nb_channels,
uint8_t channel_map 
)
inlinestatic

Definition at line 475 of file adc_arch.c.

References PRINT_CONFIG_MSG().

Referenced by adc_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void adc_push_sample ( struct adc_buf buf,
uint16_t  sample 
)
inlinestatic

Definition at line 558 of file adc_arch.c.

References adc_buf::av_nb_sample, adc_buf::head, adc_buf::sum, and adc_buf::values.

Variable Documentation

uint8_t nb_adc1_channels = 0
static

Definition at line 192 of file adc_arch.c.

Referenced by adc_buf_channel(), and adc_init().

uint8_t nb_adc2_channels = 0
static

Definition at line 193 of file adc_arch.c.

Referenced by adc_buf_channel(), and adc_init().

uint8_t nb_adc3_channels = 0
static

Definition at line 194 of file adc_arch.c.