static void timer_test(int flags) { int x; timer_isr_handle_t inth[4]; my_timer_init(TIMER_GROUP_0, TIMER_0, 110000); my_timer_init(TIMER_GROUP_0, TIMER_1, 120000); my_timer_init(TIMER_GROUP_1, TIMER_0, 130000); my_timer_init(TIMER_GROUP_1, TIMER_1, 140000); timer_isr_register(TIMER_GROUP_0, TIMER_0, timer_isr, (void*)0, flags|ESP_INTR_FLAG_INTRDISABLED, &inth[0]); timer_isr_register(TIMER_GROUP_0, TIMER_1, timer_isr, (void*)1, flags, &inth[1]); timer_isr_register(TIMER_GROUP_1, TIMER_0, timer_isr, (void*)2, flags, &inth[2]); timer_isr_register(TIMER_GROUP_1, TIMER_1, timer_isr, (void*)3, flags, &inth[3]); timer_start(TIMER_GROUP_0, TIMER_0); timer_start(TIMER_GROUP_0, TIMER_1); timer_start(TIMER_GROUP_1, TIMER_0); timer_start(TIMER_GROUP_1, TIMER_1); for (x=0; x<4; x++) count[x]=0; printf("Interrupts allocated: %d (dis) %d %d %d\n", esp_intr_get_intno(inth[0]), esp_intr_get_intno(inth[1]), esp_intr_get_intno(inth[2]), esp_intr_get_intno(inth[3])); printf("Timer values on start: %d %d %d %d\n", count[0], count[1], count[2], count[3]); vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer values after 1 sec: %d %d %d %d\n", count[0], count[1], count[2], count[3]); TEST_ASSERT(count[0]==0); TEST_ASSERT(count[1]!=0); TEST_ASSERT(count[2]!=0); TEST_ASSERT(count[3]!=0); printf("Disabling timers 1 and 2...\n"); esp_intr_enable(inth[0]); esp_intr_disable(inth[1]); esp_intr_disable(inth[2]); for (x=0; x<4; x++) count[x]=0; vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer values after 1 sec: %d %d %d %d\n", count[0], count[1], count[2], count[3]); TEST_ASSERT(count[0]!=0); TEST_ASSERT(count[1]==0); TEST_ASSERT(count[2]==0); TEST_ASSERT(count[3]!=0); printf("Disabling other half...\n"); esp_intr_enable(inth[1]); esp_intr_enable(inth[2]); esp_intr_disable(inth[0]); esp_intr_disable(inth[3]); for (x=0; x<4; x++) count[x]=0; vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer values after 1 sec: %d %d %d %d\n", count[0], count[1], count[2], count[3]); TEST_ASSERT(count[0]==0); TEST_ASSERT(count[1]!=0); TEST_ASSERT(count[2]!=0); TEST_ASSERT(count[3]==0); printf("Done.\n"); esp_intr_free(inth[0]); esp_intr_free(inth[1]); esp_intr_free(inth[2]); esp_intr_free(inth[3]); }
esp_err_t spi_bus_free(spi_host_device_t host) { int x; SPI_CHECK(host>=SPI_HOST && host<=VSPI_HOST, "invalid host", ESP_ERR_INVALID_ARG); SPI_CHECK(spihost[host]!=NULL, "host not in use", ESP_ERR_INVALID_STATE); for (x=0; x<NO_CS; x++) { SPI_CHECK(spihost[host]->device[x]==NULL, "not all CSses freed", ESP_ERR_INVALID_STATE); } if ( spihost[host]->dma_chan > 0 ) { spicommon_dma_chan_free ( spihost[host]->dma_chan ); } #ifdef CONFIG_PM_ENABLE esp_pm_lock_delete(spihost[host]->pm_lock); #endif spihost[host]->hw->slave.trans_inten=0; spihost[host]->hw->slave.trans_done=0; esp_intr_free(spihost[host]->intr); spicommon_periph_free(host); free(spihost[host]->dmadesc_tx); free(spihost[host]->dmadesc_rx); free(spihost[host]); spihost[host]=NULL; return ESP_OK; }
static void esp_apptrace_dummy_task(void *p) { esp_apptrace_test_task_arg_t *arg = (esp_apptrace_test_task_arg_t *) p; int res, flags = 0, i; timer_isr_handle_t *inth = NULL; TickType_t tmo_ticks = arg->data.period / (1000 * portTICK_PERIOD_MS); ESP_APPTRACE_TEST_LOGI("%x: run dummy task (period %u us, %u timers)", xTaskGetCurrentTaskHandle(), arg->data.period, arg->timers_num); if (arg->timers_num > 0) { inth = pvPortMalloc(arg->timers_num * sizeof(timer_isr_handle_t)); if (!inth) { ESP_APPTRACE_TEST_LOGE("Failed to alloc timer ISR handles!"); goto on_fail; } memset(inth, 0, arg->timers_num * sizeof(timer_isr_handle_t)); for (int i = 0; i < arg->timers_num; i++) { esp_apptrace_test_timer_init(arg->timers[i].group, arg->timers[i].id, arg->timers[i].data.period); res = timer_isr_register(arg->timers[i].group, arg->timers[i].id, arg->timers[i].isr_func, &arg->timers[i], flags, &inth[i]); if (res != ESP_OK) { ESP_APPTRACE_TEST_LOGE("Failed to timer_isr_register (%d)!", res); goto on_fail; } *(uint32_t *)arg->timers[i].data.buf = (uint32_t)inth[i] | (1 << 31); ESP_APPTRACE_TEST_LOGI("%x: start timer %x period %u us", xTaskGetCurrentTaskHandle(), inth[i], arg->timers[i].data.period); res = timer_start(arg->timers[i].group, arg->timers[i].id); if (res != ESP_OK) { ESP_APPTRACE_TEST_LOGE("Failed to timer_start (%d)!", res); goto on_fail; } } } i = 0; while (!arg->stop) { ESP_APPTRACE_TEST_LOGD("%x: dummy task work %d.%d", xTaskGetCurrentTaskHandle(), xPortGetCoreID(), i++); if (tmo_ticks) { vTaskDelay(tmo_ticks); } } on_fail: if (inth) { for (int i = 0; i < arg->timers_num; i++) { timer_pause(arg->timers[i].group, arg->timers[i].id); timer_disable_intr(arg->timers[i].group, arg->timers[i].id); if (inth[i]) { esp_intr_free(inth[i]); } } vPortFree(inth); } xSemaphoreGive(arg->done); vTaskDelay(1); vTaskDelete(NULL); }
void local_timer_test() { intr_handle_t ih; esp_err_t r; r=esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, 0, int_timer_handler, NULL, &ih); TEST_ASSERT(r==ESP_OK); printf("Int timer 1 intno %d\n", esp_intr_get_intno(ih)); xthal_set_ccompare(1, xthal_get_ccount()+8000000); int_timer_ctr=0; vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer val after 1 sec: %d\n", int_timer_ctr); TEST_ASSERT(int_timer_ctr!=0); printf("Disabling int\n"); esp_intr_disable(ih); int_timer_ctr=0; vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer val after 1 sec: %d\n", int_timer_ctr); TEST_ASSERT(int_timer_ctr==0); printf("Re-enabling\n"); esp_intr_enable(ih); vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer val after 1 sec: %d\n", int_timer_ctr); TEST_ASSERT(int_timer_ctr!=0); printf("Free int, re-alloc disabled\n"); r=esp_intr_free(ih); TEST_ASSERT(r==ESP_OK); r=esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, ESP_INTR_FLAG_INTRDISABLED, int_timer_handler, NULL, &ih); TEST_ASSERT(r==ESP_OK); int_timer_ctr=0; vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer val after 1 sec: %d\n", int_timer_ctr); TEST_ASSERT(int_timer_ctr==0); printf("Re-enabling\n"); esp_intr_enable(ih); vTaskDelay(1000 / portTICK_PERIOD_MS); printf("Timer val after 1 sec: %d\n", int_timer_ctr); TEST_ASSERT(int_timer_ctr!=0); r=esp_intr_free(ih); TEST_ASSERT(r==ESP_OK); printf("Done.\n"); }
static void testthread(void *arg) { intr_handle_t handle; in_int_context=0; int_handled=0; TEST_ASSERT(!xPortInIsrContext()); xthal_set_ccompare(1, xthal_get_ccount()+8000000); esp_err_t err = esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, 0, &testint, NULL, &handle); TEST_ASSERT_EQUAL_HEX32(ESP_OK, err); vTaskDelay(100 / portTICK_PERIOD_MS); TEST_ASSERT(int_handled); TEST_ASSERT(in_int_context); TEST_ASSERT_EQUAL_HEX32( ESP_OK, esp_intr_free(handle) ); vTaskDelete(NULL); }
esp_err_t rmt_isr_deregister(rmt_isr_handle_t handle) { return esp_intr_free(handle); }
static void esp_apptrace_test_task(void *p) { esp_apptrace_test_task_arg_t *arg = (esp_apptrace_test_task_arg_t *) p; int res, flags = 0; timer_isr_handle_t *inth = NULL; TickType_t tmo_ticks = arg->data.period / (1000 * portTICK_PERIOD_MS); ESP_APPTRACE_TEST_LOGI("%x: run (period %u us, stamp mask %x, %u timers)", xTaskGetCurrentTaskHandle(), arg->data.period, arg->data.mask, arg->timers_num); if (arg->timers_num > 0) { inth = pvPortMalloc(arg->timers_num * sizeof(timer_isr_handle_t)); if (!inth) { ESP_APPTRACE_TEST_LOGE("Failed to alloc timer ISR handles!"); goto on_fail; } memset(inth, 0, arg->timers_num * sizeof(timer_isr_handle_t)); for (int i = 0; i < arg->timers_num; i++) { esp_apptrace_test_timer_init(arg->timers[i].group, arg->timers[i].id, arg->timers[i].data.period); res = timer_isr_register(arg->timers[i].group, arg->timers[i].id, arg->timers[i].isr_func, &arg->timers[i], flags, &inth[i]); if (res != ESP_OK) { ESP_APPTRACE_TEST_LOGE("Failed to timer_isr_register (%d)!", res); goto on_fail; } *(uint32_t *)arg->timers[i].data.buf = ((uint32_t)inth[i]) | (1 << 31) | (xPortGetCoreID() ? 0x1 : 0); ESP_APPTRACE_TEST_LOGI("%x: start timer %x period %u us", xTaskGetCurrentTaskHandle(), inth[i], arg->timers[i].data.period); res = timer_start(arg->timers[i].group, arg->timers[i].id); if (res != ESP_OK) { ESP_APPTRACE_TEST_LOGE("Failed to timer_start (%d)!", res); goto on_fail; } } } *(uint32_t *)arg->data.buf = (uint32_t)xTaskGetCurrentTaskHandle() | (xPortGetCoreID() ? 0x1 : 0); arg->data.wr_cnt = 0; arg->data.wr_err = 0; while (!arg->stop) { uint32_t *ts = (uint32_t *)(arg->data.buf + sizeof(uint32_t)); *ts = (uint32_t)esp_apptrace_test_ts_get(); memset(arg->data.buf + 2 * sizeof(uint32_t), arg->data.wr_cnt & arg->data.mask, arg->data.buf_sz - 2 * sizeof(uint32_t)); // ESP_APPTRACE_TEST_LOGD("%x:%x: Write chunk%d %d bytes, %x", xTaskGetCurrentTaskHandle(), *ts, arg->data.wr_cnt, arg->data.buf_sz, arg->data.wr_cnt & arg->data.mask); if (arg->nowait) { res = ESP_APPTRACE_TEST_WRITE_NOWAIT(arg->data.buf, arg->data.buf_sz); } else { res = ESP_APPTRACE_TEST_WRITE(arg->data.buf, arg->data.buf_sz); } if (res) { if (1){//arg->data.wr_err++ < ESP_APPTRACE_TEST_PRN_WRERR_MAX) { ESP_APPTRACE_TEST_LOGE("%x: Failed to write trace %d %x!", xTaskGetCurrentTaskHandle(), res, arg->data.wr_cnt & arg->data.mask); if (arg->data.wr_err == ESP_APPTRACE_TEST_PRN_WRERR_MAX) { ESP_APPTRACE_TEST_LOGE("\n"); } } } else { if (0) { ESP_APPTRACE_TEST_LOGD("%x:%x: Written chunk%d %d bytes, %x", xTaskGetCurrentTaskHandle(), *ts, arg->data.wr_cnt, arg->data.buf_sz, arg->data.wr_cnt & arg->data.mask); } arg->data.wr_err = 0; } arg->data.wr_cnt++; if (tmo_ticks) { vTaskDelay(tmo_ticks); } } on_fail: if (inth) { for (int i = 0; i < arg->timers_num; i++) { timer_pause(arg->timers[i].group, arg->timers[i].id); timer_disable_intr(arg->timers[i].group, arg->timers[i].id); if (inth[i]) { esp_intr_free(inth[i]); } } vPortFree(inth); } xSemaphoreGive(arg->done); vTaskDelay(1); vTaskDelete(NULL); }