Commit 7de04dbe authored by natalie's avatar natalie 💜
Browse files

loader buffering improvements

parent 66b3f8c4
/*
* todo
* watch driver queue
*/
#include "loader.h"
#include "esp_log.h"
#include "driver.h"
......@@ -11,6 +6,7 @@
#include "dacstream.h"
#include "userled.h"
#include "player.h"
#include "taskmgr.h"
static const char* TAG = "Loader";
......@@ -81,6 +77,7 @@ uint8_t running = false;
bool Loader_EndReached = false;
uint8_t Loader_PcmBuf[FREAD_LOCAL_BUF];
uint16_t Loader_PcmBufUsed = FREAD_LOCAL_BUF;
static uint32_t adjustedprio = false;
void Loader_Main() {
ESP_LOGI(TAG, "Task start");
while (1) {
......@@ -110,14 +107,26 @@ void Loader_Main() {
} else if (spaces < DRIVER_QUEUE_SIZE/3 || Loader_EndReached) {
xEventGroupSetBits(Loader_BufStatus, LOADER_BUF_OK);
xEventGroupClearBits(Loader_BufStatus, 0xff ^ LOADER_BUF_OK);
} else if (spaces >= DRIVER_QUEUE_SIZE/2) {
} else {
xEventGroupSetBits(Loader_BufStatus, LOADER_BUF_LOW);
xEventGroupClearBits(Loader_BufStatus, 0xff ^ LOADER_BUF_LOW);
}
if (adjustedprio) {
vTaskPrioritySet(Taskmgr_Handles[TASK_LOADER], LOADER_TASK_PRIO_NORM);
ESP_LOGW(TAG, "Returning to normal priority");
adjustedprio = false;
}
if (!Loader_EndReached && (spaces > DRIVER_QUEUE_SIZE/8)) {
UserLedMgr_DiskState[DISKSTATE_VGM] = true;
UserLedMgr_Notify();
while (running && uxQueueSpacesAvailable(Driver_CommandQueue)) {
if (uxQueueSpacesAvailable(Driver_CommandQueue) > (DRIVER_QUEUE_SIZE/3)) {
if (!adjustedprio) {
ESP_LOGW(TAG, "Switching to high priority");
vTaskPrioritySet(Taskmgr_Handles[TASK_LOADER], LOADER_TASK_PRIO_HIGH);
adjustedprio = true;
}
}
uint8_t d = 0x00;
LOADER_BUF_READ(d);
if (Loader_Pending == 0) {
......@@ -223,10 +232,11 @@ void Loader_Main() {
}
UserLedMgr_DiskState[DISKSTATE_VGM] = false;
UserLedMgr_Notify();
vTaskDelay(pdMS_TO_TICKS(75)); //just filled, big delay now
} else {
vTaskDelay(pdMS_TO_TICKS(25)); //keep an eye on queue spaces
}
}
vTaskDelay(pdMS_TO_TICKS(75));
}
}
......
......@@ -30,11 +30,11 @@ void Taskmgr_CreateTasks() {
Taskmgr_Handles[i] = NULL;
}
xTaskCreatePinnedToCore(BatteryMgr_Main, "BatMgr", 2048, NULL, 3, &Taskmgr_Handles[TASK_BATTERYMGR], 0);
xTaskCreatePinnedToCore(Loader_Main, "Loader", 4096, NULL, 10, &Taskmgr_Handles[TASK_LOADER], 0);
xTaskCreatePinnedToCore(Loader_Main, "Loader", 4096, NULL, LOADER_TASK_PRIO_NORM, &Taskmgr_Handles[TASK_LOADER], 0);
xTaskCreatePinnedToCore(IoExp_Main, "IoExp ", 2048, NULL, 19, &Taskmgr_Handles[TASK_IOEXP], 0);
xTaskCreatePinnedToCore(KeyMgr_Main, "KeyMgr", 2048, NULL, 19, &Taskmgr_Handles[TASK_KEYMGR], 0);
xTaskCreatePinnedToCore(DacStream_FindTask, "DsFind", 4096, NULL, 9, &Taskmgr_Handles[TASK_DACSTREAM_FIND], 0);
xTaskCreatePinnedToCore(DacStream_FillTask, "DsFill", 4096, NULL, 11, &Taskmgr_Handles[TASK_DACSTREAM_FILL], 0);
xTaskCreatePinnedToCore(DacStream_FillTask, "DsFill", 4096, NULL, 14, &Taskmgr_Handles[TASK_DACSTREAM_FILL], 0);
xTaskCreatePinnedToCore(Player_Main, "Player", 4096, NULL, 5, &Taskmgr_Handles[TASK_PLAYER], 0);
xTaskCreatePinnedToCore(ChannelMgr_Main, "ChnMgr", 1024, NULL, 18, &Taskmgr_Handles[TASK_CHANNELMGR], 0);
xTaskCreatePinnedToCore(Ui_Main, "Ui ", 3000, NULL, 12, &Taskmgr_Handles[TASK_UI], 0);
......
......@@ -23,6 +23,10 @@ enum Tasks {
TASK_COUNT
};
#define LOADER_TASK_PRIO_NORM 10
#define LOADER_TASK_PRIO_HIGH 12
#define LOADER_TASK_PRIO_MEGA 13
extern TaskHandle_t Taskmgr_Handles[TASK_COUNT];
void Taskmgr_CreateTasks();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment