mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-09 14:28:37 +00:00
[feat][adc] add overrun and underrun event
This commit is contained in:
parent
e63cf769fb
commit
2bdacbc638
2 changed files with 27 additions and 9 deletions
|
@ -24,7 +24,7 @@
|
||||||
#define __HAL_ADC__H__
|
#define __HAL_ADC__H__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "hal_common.h"
|
#include "hal_common.h"
|
||||||
|
@ -126,12 +126,16 @@ typedef enum {
|
||||||
} adc_pga_gain_t;
|
} adc_pga_gain_t;
|
||||||
|
|
||||||
enum adc_event_type {
|
enum adc_event_type {
|
||||||
|
ADC_EVENT_UNDERRUN,
|
||||||
|
ADC_EVENT_OVERRUN,
|
||||||
ADC_EVENT_FIFO,
|
ADC_EVENT_FIFO,
|
||||||
UART_EVENT_UNKNOWN
|
ADC_EVENT_UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
enum adc_it_type {
|
enum adc_it_type {
|
||||||
ADC_FIFO_IT = 1 << 0,
|
ADC_UNDERRUN_IT = 1 << 2,
|
||||||
|
ADC_OVERRUN_IT = 1 << 3,
|
||||||
|
ADC_FIFO_IT = 1 << 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
@ -165,17 +165,31 @@ int adc_control(struct device *dev, int cmd, void *args)
|
||||||
uint8_t rlt = 0;
|
uint8_t rlt = 0;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case DEVICE_CTRL_SET_INT /* constant-expression */:
|
case DEVICE_CTRL_SET_INT /* constant-expression */: {
|
||||||
ADC_IntMask(ADC_INT_FIFO_READY, UNMASK);
|
uint32_t offset = __builtin_ctz((uint32_t)args);
|
||||||
|
while ((2 <= offset) && (offset < 6)) {
|
||||||
|
if ((uint32_t)args & (1 << offset)) {
|
||||||
|
ADC_IntMask(offset, UNMASK);
|
||||||
|
}
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
CPU_Interrupt_Enable(GPADC_DMA_IRQn);
|
CPU_Interrupt_Enable(GPADC_DMA_IRQn);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DEVICE_CTRL_CLR_INT /* constant-expression */:
|
case DEVICE_CTRL_CLR_INT /* constant-expression */: {
|
||||||
ADC_IntMask(ADC_INT_FIFO_READY, MASK);
|
uint32_t offset = __builtin_ctz((uint32_t)args);
|
||||||
|
while ((2 <= offset) && (offset < 6)) {
|
||||||
|
if ((uint32_t)args & (1 << offset)) {
|
||||||
|
ADC_IntMask(offset, UNMASK);
|
||||||
|
}
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
CPU_Interrupt_Disable(GPADC_DMA_IRQn);
|
CPU_Interrupt_Disable(GPADC_DMA_IRQn);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DEVICE_CTRL_GET_INT /* constant-expression */:
|
case DEVICE_CTRL_GET_INT /* constant-expression */:
|
||||||
/* code */
|
/* code */
|
||||||
|
@ -340,12 +354,12 @@ void adc_isr(adc_device_t *handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ADC_GetIntStatus(ADC_INT_FIFO_UNDERRUN) == SET && ADC_IntGetMask(ADC_INT_FIFO_UNDERRUN) == UNMASK) {
|
if (ADC_GetIntStatus(ADC_INT_FIFO_UNDERRUN) == SET && ADC_IntGetMask(ADC_INT_FIFO_UNDERRUN) == UNMASK) {
|
||||||
//handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_UNDERRUN);
|
handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_UNDERRUN);
|
||||||
ADC_IntClr(ADC_INT_FIFO_UNDERRUN);
|
ADC_IntClr(ADC_INT_FIFO_UNDERRUN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ADC_GetIntStatus(ADC_INT_FIFO_OVERRUN) == SET && ADC_IntGetMask(ADC_INT_FIFO_OVERRUN) == UNMASK) {
|
if (ADC_GetIntStatus(ADC_INT_FIFO_OVERRUN) == SET && ADC_IntGetMask(ADC_INT_FIFO_OVERRUN) == UNMASK) {
|
||||||
//handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_OVERRUN);
|
handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_OVERRUN);
|
||||||
ADC_IntClr(ADC_INT_FIFO_OVERRUN);
|
ADC_IntClr(ADC_INT_FIFO_OVERRUN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue