Skip to content

Commit

Permalink
prefix with resource
Browse files Browse the repository at this point in the history
  • Loading branch information
m-m-adams committed Jan 19, 2025
1 parent 87cb47e commit 5a82c83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
9 changes: 5 additions & 4 deletions src/OSLikeStuff/scheduler_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ typedef void (*TaskHandle)();
typedef bool (*RunCondition)();
typedef int8_t TaskID;
typedef uint32_t ResourceID;
#define NO_RESOURCE 0
#define RESOURCE_NONE 0
// for actually reading the SD
#define SD 1
#define USB 2
#define RESOURCE_SD 1
#define RESOURCE_USB 2
// for things that can't run in the SD routine
#define SD_ROUTINE 4
#define RESOURCE_SD_ROUTINE 4

/// Schedule a task that will be called at a regular interval.
///
/// The scheduler will try to run the task at a regular cadence such that the time between start of calls to the
Expand Down
8 changes: 4 additions & 4 deletions src/OSLikeStuff/task_scheduler/resource_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class ResourceChecker {
/// returns whether all resources are available. This is basically shitty priority ceiling to avoid the potential of
/// a task locking one resource and then trying to yield while it waits for another
bool checkResources() const {
if (resources_ == NO_RESOURCE) {
if (resources_ == RESOURCE_NONE) {
return true;
}
bool anythingLocked = false;
if ((resources_ & SD) != 0u) {
if ((resources_ & RESOURCE_SD) != 0u) {
anythingLocked |= currentlyAccessingCard;
}
if ((resources_ & USB) != 0u) {
if ((resources_ & RESOURCE_USB) != 0u) {
anythingLocked |= usbLock;
}
if ((resources_ & SD_ROUTINE) != 0u) {
if ((resources_ & RESOURCE_SD_ROUTINE) != 0u) {
anythingLocked |= sdRoutineLock;
}
return !anythingLocked;
Expand Down
36 changes: 18 additions & 18 deletions src/deluge/deluge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,53 +577,53 @@ void registerTasks() {

// 0-9: High priority (10 for dyn tasks)
uint8_t p = 0;
addRepeatingTask(&(AudioEngine::routine), p++, 0.00001, 16 / 44100., 24 / 44100., "audio routine", NO_RESOURCE);
addRepeatingTask(&(AudioEngine::routine), p++, 0.00001, 16 / 44100., 24 / 44100., "audio routine", RESOURCE_NONE);
// this one runs quickly and frequently to check for encoder changes
addRepeatingTask([]() { encoders::readEncoders(); }, p++, 0.0005, 0.001, 0.001, "read encoders", NO_RESOURCE);
addRepeatingTask([]() { encoders::readEncoders(); }, p++, 0.0005, 0.001, 0.001, "read encoders", RESOURCE_NONE);
// formerly part of audio routine, updates midi and clock
addRepeatingTask([]() { playbackHandler.routine(); }, p++, 2 / 44100., 16 / 44100, 32 / 44100., "playback routine",
NO_RESOURCE);
RESOURCE_NONE);
addRepeatingTask([]() { playbackHandler.midiRoutine(); }, p++, 2 / 44100., 16 / 44100, 32 / 44100.,
"playback routine", SD | USB);
"playback routine", RESOURCE_SD | RESOURCE_USB);
addRepeatingTask([]() { audioFileManager.loadAnyEnqueuedClusters(128, false); }, p++, 0.00001, 0.00001, 0.00002,
"load clusters", NO_RESOURCE);
"load clusters", RESOURCE_NONE);
// handles sd card recorders
// named "slow" but isn't actually, it handles audio recording setup
addRepeatingTask(&AudioEngine::slowRoutine, p++, 0.001, 0.005, 0.05, "audio slow", NO_RESOURCE);
addRepeatingTask(&(readButtonsAndPadsOnce), p++, 0.005, 0.005, 0.01, "buttons and pads", NO_RESOURCE);
addRepeatingTask(&AudioEngine::slowRoutine, p++, 0.001, 0.005, 0.05, "audio slow", RESOURCE_NONE);
addRepeatingTask(&(readButtonsAndPadsOnce), p++, 0.005, 0.005, 0.01, "buttons and pads", RESOURCE_NONE);

// 11-19: Medium priority (20 for dyn tasks)
p = 11;
addRepeatingTask([]() { encoders::interpretEncoders(true); }, p++, 0.005, 0.005, 0.01, "interpret encoders fast",
NO_RESOURCE);
RESOURCE_NONE);
// 30 Hz update desired?
addRepeatingTask(&doAnyPendingUIRendering, p++, 0.01, 0.01, 0.03, "pending UI", NO_RESOURCE);
addRepeatingTask(&doAnyPendingUIRendering, p++, 0.01, 0.01, 0.03, "pending UI", RESOURCE_NONE);
// this one actually actions them
addRepeatingTask([]() { encoders::interpretEncoders(false); }, p++, 0.005, 0.005, 0.01, "interpret encoders slow",
SD_ROUTINE);
RESOURCE_SD_ROUTINE);

// Check for and handle queued SysEx traffic
addRepeatingTask([]() { smSysex::handleNextSysEx(); }, p++, 0.0002, 0.0002, 0.01, "Handle pending SysEx traffic.",
SD);
RESOURCE_SD);

// 21-29: Low priority (30 for dyn tasks)
p = 21;
// these ones are actually "slow" -> file manager just checks if an sd card has been inserted, audio recorder checks
// if recordings are finished
addRepeatingTask([]() { audioFileManager.slowRoutine(); }, p++, 0.1, 0.1, 0.2, "audio file slow", SD);
addRepeatingTask([]() { audioRecorder.slowRoutine(); }, p++, 0.01, 0.1, 0.1, "audio recorder slow", NO_RESOURCE);
addRepeatingTask([]() { audioFileManager.slowRoutine(); }, p++, 0.1, 0.1, 0.2, "audio file slow", RESOURCE_SD);
addRepeatingTask([]() { audioRecorder.slowRoutine(); }, p++, 0.01, 0.1, 0.1, "audio recorder slow", RESOURCE_NONE);
// formerly part of cluster loading (why? no idea), actions undo/redo midi commands
addRepeatingTask([]() { playbackHandler.slowRoutine(); }, p++, 0.01, 0.1, 0.1, "playback routine", SD);
addRepeatingTask([]() { playbackHandler.slowRoutine(); }, p++, 0.01, 0.1, 0.1, "playback routine", RESOURCE_SD);
// 31-39: Idle priority (40 for dyn tasks)
p = 31;
addRepeatingTask(&(PIC::flush), p++, 0.001, 0.001, 0.02, "PIC flush", NO_RESOURCE);
addRepeatingTask(&(PIC::flush), p++, 0.001, 0.001, 0.02, "PIC flush", RESOURCE_NONE);
if (hid::display::have_oled_screen) {
addRepeatingTask(&(oledRoutine), p++, 0.01, 0.01, 0.02, "oled routine", NO_RESOURCE);
addRepeatingTask(&(oledRoutine), p++, 0.01, 0.01, 0.02, "oled routine", RESOURCE_NONE);
}
// needs to be called very frequently,
// handles animations and checks on the timers for any infrequent actions
// long term this should probably be made into an idle task
addRepeatingTask([]() { uiTimerManager.routine(); }, p++, 0.0001, 0.0007, 0.01, "ui routine", NO_RESOURCE);
addRepeatingTask([]() { uiTimerManager.routine(); }, p++, 0.0001, 0.0007, 0.01, "ui routine", RESOURCE_NONE);

// addRepeatingTask([]() { AudioEngine::routineWithClusterLoading(true); }, 0, 1 / 44100., 16 / 44100., 32 / 44100.,
// true); addRepeatingTask(&(AudioEngine::routine), 0, 16 / 44100., 64 / 44100., true);
Expand Down Expand Up @@ -874,7 +874,7 @@ extern "C" int32_t deluge_main(void) {
midiFollow.readDefaultsFromFile();
PadLEDs::setBrightnessLevel(FlashStorage::defaultPadBrightness);
setupBlankSong(); // we always need to do this
addConditionalTask(setupStartupSong, 100, isCardReady, "load startup song", SD | SD_ROUTINE);
addConditionalTask(setupStartupSong, 100, isCardReady, "load startup song", RESOURCE_SD | RESOURCE_SD_ROUTINE);

#ifdef TEST_VECTOR
NoteVector noteVector;
Expand Down

0 comments on commit 5a82c83

Please sign in to comment.