mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-02 05:17:03 +08:00
[adc] add support for analog watchdog (stm32f4) with callback
This commit is contained in:
@@ -181,6 +181,13 @@ static struct adc_buf * adc2_buffers[4];
|
|||||||
static struct adc_buf * adc3_buffers[4];
|
static struct adc_buf * adc3_buffers[4];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if USE_ADC_WATCHDOG
|
||||||
|
// watchdog structure with adc bank and callback
|
||||||
|
static struct {
|
||||||
|
uint32_t adc;
|
||||||
|
adc_watchdog_callback cb;
|
||||||
|
} adc_watchdog;
|
||||||
|
#endif
|
||||||
|
|
||||||
/***************************************/
|
/***************************************/
|
||||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||||
@@ -327,6 +334,10 @@ void adc_init( void ) {
|
|||||||
|
|
||||||
adc_new_data_trigger = FALSE;
|
adc_new_data_trigger = FALSE;
|
||||||
|
|
||||||
|
#if USE_ADC_WATCHDOG
|
||||||
|
adc_watchdog.cb = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_buf_channel(uint8_t adc_channel, struct adc_buf * s, uint8_t av_nb_sample)
|
void adc_buf_channel(uint8_t adc_channel, struct adc_buf * s, uint8_t av_nb_sample)
|
||||||
@@ -352,6 +363,20 @@ void adc_buf_channel(uint8_t adc_channel, struct adc_buf * s, uint8_t av_nb_samp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_ADC_WATCHDOG
|
||||||
|
void register_adc_watchdog(uint32_t adc, uint8_t chan, uint16_t low, uint16_t high, adc_watchdog_callback cb) {
|
||||||
|
adc_watchdog.adc = adc;
|
||||||
|
adc_watchdog.cb = cb;
|
||||||
|
|
||||||
|
// activated adc watchdog of a single injected channel with interrupt
|
||||||
|
adc_set_watchdog_low_threshold(adc, low);
|
||||||
|
adc_set_watchdog_high_threshold(adc, high);
|
||||||
|
adc_enable_analog_watchdog_injected(adc);
|
||||||
|
adc_enable_analog_watchdog_on_selected_channel(adc, chan);
|
||||||
|
adc_enable_awd_interrupt(adc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**************************************/
|
/**************************************/
|
||||||
/*** PRIVATE FUNCTION DEFINITIONS ***/
|
/*** PRIVATE FUNCTION DEFINITIONS ***/
|
||||||
/**************************************/
|
/**************************************/
|
||||||
@@ -543,6 +568,15 @@ void adc1_2_isr(void)
|
|||||||
uint16_t value = 0;
|
uint16_t value = 0;
|
||||||
struct adc_buf * buf;
|
struct adc_buf * buf;
|
||||||
|
|
||||||
|
#if USE_ADC_WATCHDOG
|
||||||
|
if (adc_watchdog.cb != NULL) {
|
||||||
|
if (adc_awd(adc_watchdog.adc)) {
|
||||||
|
ADC_SR(adc_watchdog.adc) &= ~ADC_SR_AWD; // clear int flag
|
||||||
|
adc_watchdog.cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if USE_AD1
|
#if USE_AD1
|
||||||
// Clear Injected End Of Conversion
|
// Clear Injected End Of Conversion
|
||||||
if (ADC_SR(ADC1) & ADC_SR_JEOC){
|
if (ADC_SR(ADC1) & ADC_SR_JEOC){
|
||||||
|
|||||||
@@ -76,4 +76,21 @@ enum adc_channels {
|
|||||||
NB_ADC
|
NB_ADC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if USE_ADC_WATCHDOG
|
||||||
|
|
||||||
|
/* Watchdog callback type definition
|
||||||
|
*/
|
||||||
|
typedef void (*adc_watchdog_callback)(void);
|
||||||
|
|
||||||
|
/* Watchdog register function
|
||||||
|
*
|
||||||
|
* @param adc adc bank to monitor
|
||||||
|
* @param chan adc channel to monitor
|
||||||
|
* @param low low threshhold for callback trigger
|
||||||
|
* @param high high threshhold for callback trigger
|
||||||
|
*/
|
||||||
|
extern void register_adc_watchdog(uint32_t adc, uint8_t chan, uint16_t low, uint16_t high, adc_watchdog_callback cb);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ADC_ARCH_H */
|
#endif /* ADC_ARCH_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user