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]); }
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"); }
esp_err_t spi_slave_queue_trans(spi_host_device_t host, const spi_slave_transaction_t *trans_desc, TickType_t ticks_to_wait) { BaseType_t r; SPI_CHECK(VALID_HOST(host), "invalid host", ESP_ERR_INVALID_ARG); SPI_CHECK(spihost[host], "host not slave", ESP_ERR_INVALID_ARG); SPI_CHECK(trans_desc->length <= spihost[host]->max_transfer_sz * 8, "data transfer > host maximum", ESP_ERR_INVALID_ARG); r = xQueueSend(spihost[host]->trans_queue, (void *)&trans_desc, ticks_to_wait); if (!r) return ESP_ERR_TIMEOUT; esp_intr_enable(spihost[host]->intr); return ESP_OK; }
/** * @brief EXPERIMENTAL */ void I2S::cameraMode(dma_config_t config, int desc_count, int sample_count) { ESP_LOGD(LOG_TAG, ">> cameraMode"); ESP32CPP::GPIO::setInput(config.pin_d0); ESP32CPP::GPIO::setInput(config.pin_d1); ESP32CPP::GPIO::setInput(config.pin_d2); ESP32CPP::GPIO::setInput(config.pin_d3); ESP32CPP::GPIO::setInput(config.pin_d4); ESP32CPP::GPIO::setInput(config.pin_d5); ESP32CPP::GPIO::setInput(config.pin_d6); ESP32CPP::GPIO::setInput(config.pin_d7); //ESP32CPP::GPIO::setInput(config.pin_xclk); ESP32CPP::GPIO::setInput(config.pin_vsync); ESP32CPP::GPIO::setInput(config.pin_href); ESP32CPP::GPIO::setInput(config.pin_pclk); //ESP32CPP::GPIO::setOutput(config.pin_reset); const uint32_t const_high = 0x38; gpio_matrix_in(config.pin_d0, I2S0I_DATA_IN0_IDX, false); gpio_matrix_in(config.pin_d1, I2S0I_DATA_IN1_IDX, false); gpio_matrix_in(config.pin_d2, I2S0I_DATA_IN2_IDX, false); gpio_matrix_in(config.pin_d3, I2S0I_DATA_IN3_IDX, false); gpio_matrix_in(config.pin_d4, I2S0I_DATA_IN4_IDX, false); gpio_matrix_in(config.pin_d5, I2S0I_DATA_IN5_IDX, false); gpio_matrix_in(config.pin_d6, I2S0I_DATA_IN6_IDX, false); gpio_matrix_in(config.pin_d7, I2S0I_DATA_IN7_IDX, false); gpio_matrix_in(config.pin_vsync, I2S0I_V_SYNC_IDX, true); gpio_matrix_in(config.pin_href, I2S0I_H_SYNC_IDX, false); // gpio_matrix_in(const_high, I2S0I_V_SYNC_IDX, false); // gpio_matrix_in(const_high, I2S0I_H_SYNC_IDX, false); gpio_matrix_in(const_high, I2S0I_H_ENABLE_IDX, false); gpio_matrix_in(config.pin_pclk, I2S0I_WS_IN_IDX, false); // Enable and configure I2S peripheral periph_module_enable(PERIPH_I2S0_MODULE); // Toggle some reset bits in LC_CONF register // Toggle some reset bits in CONF register // Enable slave mode (sampling clock is external) i2s_conf_reset(); // Switch on Slave mode. // I2S_CONF_REG -> I2S_RX_SLAVE_MOD // Set to 1 to enable slave mode. I2S0.conf.rx_slave_mod = 1; // Enable parallel mode // I2S_CONF2_REG -> I2S_LCD_END // Set to 1 to enable LCD mode. I2S0.conf2.lcd_en = 1; // Use HSYNC/VSYNC/HREF to control sampling // I2S_CONF2_REG -> I2S_CAMERA_EN // Set to 1 to enable camera mode. I2S0.conf2.camera_en = 1; // Configure clock divider I2S0.clkm_conf.clkm_div_a = 1; I2S0.clkm_conf.clkm_div_b = 0; I2S0.clkm_conf.clkm_div_num = 2; // I2S_FIFO_CONF_REG -> I2S_DSCR_EN // FIFO will sink data to DMA I2S0.fifo_conf.dscr_en = 1; // FIFO configuration // I2S_FIFO_CONF_REG -> RX_FIFO_MOD I2S0.fifo_conf.rx_fifo_mod = 1; // 0-3??? // I2S_FIFO_CONF_REG -> RX_FIFO_MOD_FORCE_EN I2S0.fifo_conf.rx_fifo_mod_force_en = 1; // I2S_CONF_CHAN_REG -> I2S_RX_CHAN_MOD I2S0.conf_chan.rx_chan_mod = 1; // Clear flags which are used in I2S serial mode // I2S_SAMPLE_RATE_CONF_REG -> I2S_RX_BITS_MOD I2S0.sample_rate_conf.rx_bits_mod = 0; // I2S_CONF_REG -> I2S_RX_RIGHT_FIRST I2S0.conf.rx_right_first = 0; //I2S0.conf.rx_right_first = 0; // I2S_CONF_REG -> I2S_RX_MSB_RIGHT I2S0.conf.rx_msb_right = 0; //I2S0.conf.rx_msb_right = 1; // I2S_CONF_REG -> I2S_RX_MSB_SHIFT I2S0.conf.rx_msb_shift = 0; //I2S0.conf.rx_msb_shift = 1; // I2S_CONF_REG -> I2S_RX_MSB_MONO I2S0.conf.rx_mono = 0; // I2S_CONF_REG -> I2S_RX_SHORT_SYNC I2S0.conf.rx_short_sync = 0; I2S0.timing.val = 0; ESP_LOGD(LOG_TAG, "Initializing %d descriptors", desc_count); DMABuffer* pFirst = new DMABuffer(); // TODO: POTENTIAL LEAK DMABuffer* pLast = pFirst; for (int i = 1; i < desc_count; i++) { DMABuffer* pNewDMABuffer = new DMABuffer(); // TODO: POTENTIAL LEAK pLast->setNext(pNewDMABuffer); pLast = pNewDMABuffer; } pLast->setNext(pFirst); pCurrentDMABuffer = pFirst; // I2S_RX_EOF_NUM_REG I2S0.rx_eof_num = sample_count; // I2S_IN_LINK_REG -> I2S_INLINK_ADDR I2S0.in_link.addr = (uint32_t) pFirst; // I2S_IN_LINK_REG -> I2S_INLINK_START I2S0.in_link.start = 1; I2S0.int_clr.val = I2S0.int_raw.val; I2S0.int_ena.val = 0; I2S0.int_ena.in_done = 1; // Register the interrupt handler. esp_intr_alloc( ETS_I2S0_INTR_SOURCE, ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_LEVEL1 | ESP_INTR_FLAG_IRAM, &i2s_isr, this, &i2s_intr_handle); m_dmaSemaphore.take(); // Start the interrupt handler esp_intr_enable(i2s_intr_handle); I2S0.conf.rx_start = 1; /* while(1) { m_dmaSemaphore.wait(); uint32_t dataLength = pLastDMABuffer->getLength(); ESP_LOGD(LOG_TAG, "Got a DMA buffer; length=%d", dataLength); //pLastDMABuffer->dump(); uint8_t *pData = new uint8_t[dataLength]; pLastDMABuffer->getData(pData, dataLength); GeneralUtils::hexDump(pData, dataLength); delete[] pData; m_dmaSemaphore.take(); } */ ESP_LOGD(LOG_TAG, "<< cameraMode"); }
static void IRAM_ATTR spi_slave_restart_after_dmareset(void *arg) { spi_slave_t *host = (spi_slave_t *)arg; esp_intr_enable(host->intr); }