void main(void) { struct device *adc; struct nano_timer timer; uint32_t data[2] = {0, 0}; DBG("ADC sample started on %s\n", ADC_DEVICE_NAME); adc = device_get_binding(ADC_DEVICE_NAME); if (!adc) { DBG("Cannot get adc controller\n"); return; } nano_timer_init(&timer, data); adc_enable(adc); while (1) { if (adc_read(adc, &table) != DEV_OK) { DBG("Sampling could not proceed, an error occurred\n"); } else { DBG("Sampling is done\n"); _print_sample_in_hex(seq_buffer, BUFFER_SIZE); } nano_timer_start(&timer, SLEEPTICKS); nano_timer_test(&timer, TICKS_UNLIMITED); } adc_disable(adc); }
static void adc_test(void) { int result = TC_FAIL; struct device *adc; unsigned int loops = 10; unsigned int bufi0 = ~0, bufi; adc = device_get_binding(ADC_DEVICE_NAME); zassert_not_null(adc, "Cannot get adc controller\n"); adc_enable(adc); while (loops--) { bufi = loops & 0x1; /* .buffer should be void * ... */ sample.buffer = (void *) seq_buffer[bufi]; result = adc_read(adc, &table); zassert_equal(result, 0, "Sampling could not proceed, " "an error occurred\n"); printk("loop %u: sampling done to buffer #%u\n", loops, bufi); _print_sample_in_hex(seq_buffer[bufi], BUFFER_SIZE); if (bufi0 != ~0) { unsigned int cnt; long delta; for (cnt = 0; cnt < BUFFER_SIZE; cnt++) { delta = _abs((long)seq_buffer[bufi][cnt] - seq_buffer[bufi0][cnt]); printk("loop %u delta %u = %ld\n", loops, cnt, delta); } } k_sleep(SLEEPTIME); bufi0 = bufi; } adc_disable(adc); }