void user_init(void) { lastTick = xTaskGetTickCount(); startMem = lastMem = xPortGetFreeHeapSize(); sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); // enable file system esp_spiffs_init(); esp_spiffs_mount(); // disable buffering setbuf(stdin, NULL); setbuf(stdout, NULL); // this doesn't have enough stack! //lispTask(NULL); return; // for now run in a task, in order to allocate a bigger stack // 1024 --> (fibo 13) // 2048 --> (fibo 30) ??? xTaskCreate(lispTask, (signed char *)"lispTask", 2048, NULL, 2, NULL); }
void play_task(void *pvParameters) { esp_spiffs_init(); if (esp_spiffs_mount() != SPIFFS_OK) { printf("Error mount SPIFFS\n"); } int fd = open("sample.wav", O_RDONLY); if (fd < 0) { printf("Error opening file\n"); return; } dumb_wav_header_t wav_header; read(fd, (void*)&wav_header, sizeof(wav_header)); printf("Number of channels: %d\n", wav_header.num_channels); printf("Bits per sample: %d\n", wav_header.bits_per_sample); printf("Sample rate: %d\n", wav_header.sample_rate); printf("Data size: %d\n", wav_header.data_size); if (wav_header.bits_per_sample != 16) { printf("Only 16 bit per sample is supported\n"); return; } if (wav_header.num_channels != 2) { printf("Only 2 channels is supported\n"); return; } i2s_clock_div_t clock_div = i2s_get_clock_div( wav_header.sample_rate * 2 * 16); printf("i2s clock dividers, bclk=%d, clkm=%d\n", clock_div.bclk_div, clock_div.clkm_div); i2s_pins_t i2s_pins = {.data = true, .clock = true, .ws = true}; i2s_dma_init(dma_isr_handler, clock_div, i2s_pins); while (1) { init_descriptors_list(); i2s_dma_start(dma_block_list); lseek(fd, sizeof(dumb_wav_header_t), SEEK_SET); while (play_data(fd)) {}; i2s_dma_stop(); vQueueDelete(dma_queue); printf("underrun counter: %d\n", underrun_counter); vTaskDelay(1000 / portTICK_PERIOD_MS); } close(fd); } void user_init(void) { uart_set_baud(0, 115200); xTaskCreate(play_task, "test_task", 1024, NULL, 2, NULL); }