Newer
Older
tree-os / src / kernel / task / osTasks.c
@lukas lukas on 1 Jan 2022 885 bytes code cleanup: lists
#include <_stdio.h>
#include <alloc.h>
#include <osTasks.h>
#include <stdint.h>
#include <task.h>
#include <terminal.h>

Task mainTask;
Task printerTask;
Task *keyboardConsumer = &mainTask;

void printLoop() {
    while (1) {
        Message *message = popBeginning(&printerTask.messages);
        if (message == 0) {
            yield();
            continue;
        }
        for (uint16_t i = 0; i < message->size; i++) {
            writeChar(((char *)(message->data))[i]);
        }
        free(message->data);
        free(message);
    }
}

void initOSTasks() {
    setRunningTask(&mainTask);
    keyboardConsumer = &mainTask;
    createTask(&printerTask, (uint32_t)printLoop, 0x0, 0x0);
    schedule(&printerTask);
    // more tasks . . .
    yields();
}

inline Task *getPrinterTask() { return &printerTask; }
inline Task *getKeyboardConsumer() { return keyboardConsumer; }