Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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)
 Link between ChibiOS ADC drivers and Paparazzi adc_buffers. 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

◆ ADC_TIMER_FREQUENCY

#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 168 of file adc_arch.c.

◆ ADC_TIMER_PERIOD

#define ADC_TIMER_PERIOD   10000

Definition at line 159 of file adc_arch.c.

◆ NVIC_ADC_IRQ_PRIO

#define NVIC_ADC_IRQ_PRIO   0

Definition at line 104 of file adc_arch.c.

◆ RCC_TIM_ADC

#define RCC_TIM_ADC   RCC_TIM2

Definition at line 426 of file adc_arch.c.

◆ TIM_ADC

#define TIM_ADC   TIM2

Definition at line 425 of file adc_arch.c.

◆ USE_AD3

#define USE_AD3   0

Definition at line 142 of file adc_arch.c.

Function Documentation

◆ adc_buf_channel()

void adc_buf_channel ( uint8_t  adc_channel,
struct adc_buf s,
uint8_t  av_nb_sample 
)

Link between ChibiOS ADC drivers and Paparazzi adc_buffers.

Registers a buffer to be used to store the specified converted channel
Usage:
struct adc_buf channel_buf;
adc_buf_channel(1, &channel_buf, 12);
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition: adc_arch.c:312

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

Todo:
: fx a more general ADC

Definition at line 379 of file adc_arch.c.

References adc1_buffers, nb_adc1_channels, nb_adc2_channels, nb_adc3_channels, and s.

◆ adc_init()

void adc_init ( void  )

◆ adc_init_irq()

static void adc_init_irq ( void  )
inlinestatic

Configure and enable ADC interrupt.

Definition at line 469 of file adc_arch.c.

References NVIC_ADC_IRQ_PRIO.

Referenced by adc_init().

+ Here is the caller graph for this function:

◆ adc_init_rcc()

static void adc_init_rcc ( void  )
inlinestatic

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

Definition at line 430 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:

◆ adc_init_single()

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

Definition at line 481 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:

◆ adc_push_sample()

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

Definition at line 564 of file adc_arch.c.

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

Variable Documentation

◆ nb_adc1_channels

uint8_t nb_adc1_channels = 0
static

Definition at line 196 of file adc_arch.c.

Referenced by adc_buf_channel(), and adc_init().

◆ nb_adc2_channels

uint8_t nb_adc2_channels = 0
static

Definition at line 197 of file adc_arch.c.

Referenced by adc_buf_channel(), and adc_init().

◆ nb_adc3_channels

uint8_t nb_adc3_channels = 0
static

Definition at line 198 of file adc_arch.c.

Referenced by adc_buf_channel(), and adc_init().