I want to stop continue ADC sampling after 1min.
1、config gpio
hw_gpio_set_pin_function(HW_GPIO_PORT_1,
HW_GPIO_PIN_3,
HW_GPIO_MODE_INPUT,
HW_GPIO_FUNC_ADC);
2、config dma
DMA_setup dma_conf = {
.channel_number = HW_DMA_CHANNEL_0,
.bus_width = HW_DMA_BW_HALFWORD,
.irq_enable = false,
.irq_nr_of_trans= 1,
.dreq_mode = HW_DMA_DREQ_TRIGGERED,
.a_inc = HW_DMA_AINC_FALSE,
.b_inc = HW_DMA_BINC_TRUE,
.circular = HW_DMA_MODE_CIRCULAR,
.dma_prio = HW_DMA_PRIO_7,
.dma_idle = HW_DMA_IDLE_BLOCKING_MODE,
.dma_init = HW_DMA_INIT_AX_BX_AY_BY,
.dma_req_mux = HW_DMA_TRIG_ADC,
.src_address = (uint32_t)(&GPADC->GP_ADC_RESULT_REG),
.dest_address = (uint32_t)mg_ad_samp_ret_buf,
.length = 60,
};
hw_dma_channel_initialization(&dma_conf);
hw_dma_channel_enable(HW_DMA_CHANNEL_0, HW_DMA_STATE_ENABLED);
3、config gpadc
source_handle = ad_gpadc_open(MY_GPADC);
ad_gpadc_acquire();
hw_gpadc_reset();
hw_gpadc_set_clock(HW_GPADC_CLOCK_DIGITAL);
hw_gpadc_set_input_mode(HW_GPADC_INPUT_MODE_SINGLE_ENDED);
hw_gpadc_set_input(MG_CFG_SAMP_PW_GPADC);
hw_gpadc_set_sample_time(7);
hw_gpadc_set_oversampling (2);
hw_gpadc_set_continuous(true);
hw_gpadc_set_interval(8);
hw_gpadc_set_input_attenuator_state(false);
hw_gpadc_set_chopping(true);
hw_gpadc_set_ldo_constant_current(true);
hw_gpadc_set_ldo_dynamic_current(true);
hw_gpadc_set_ldo_delay(100);
REG_SETF(GPADC, GP_ADC_CTRL2_REG, GP_ADC_DMA_EN, true);
hw_gpadc_enable();
hw_gpadc_start();
4、config os_timer
tmr_handle = OS_TIMER_CREATE("myTimer", OS_MS_2_TICKS(60000), pdFALSE, NULL, my_timer_cb);
ASSERT_ERROR(tmr_handle );
OS_TIMER_RESET(tmr_handle , OS_TIMER_FOREVER);
……
static void my_timer_cb(OS_TIMER timer_handle)
{
OS_TASK_NOTIFY_FROM_ISR(my_task_handle, MY_TASK_NOTIFY_TIMER, OS_NOTIFY_SET_BITS);
}
1+2+3: The timer doesn't work.
1 + 2:蒂姆er can operate properly.
Hi song,
Please be aware that the SDK doesn't support adc functionallity with the DMA and the adapters, apart from that i dont think that the timer has to do anything with the setting up of the ADC, you mention that the timer doesn't work, you mean that the callback that you ve set it never occurs ?
As far i can tell from the code that you have pasted, you are using the the adc adapter functions and then you are using the Low Level drivers in order to set up the ADC functionallity which is not a good practice, and i am not aware what will happen if you do that, you should either use the LLDs or the Adapters. Additionally dont use the OS_TASK_NOTIFY_FROM_ISR in order to notify your task just use the plain OS_TASK_NOTIFY. Since you are using the DMA and there is no adapter that will include the DMA functionallity you will have to also take care the cases where the device is going to sleep and wake up, since there is no DMA there will be no one stopping the device when it goes to sleep.
Thansk MT_dialog