threads: add master skeleton

This commit is contained in:
Vasily Davydov
2023-04-05 00:09:58 +03:00
parent 9fb78d03ff
commit 6cfe14b3fe
4 changed files with 84 additions and 51 deletions

View File

@@ -4,38 +4,14 @@
#include "task.h"
#include <cr_section_macros.h>
#include "FreeRTOSCPP/Kernel.hpp"
#include "FreeRTOSCPP/Task.hpp"
class LedTask : public FreeRTOS::Task {
public:
LedTask(const UBaseType_t priority, const char* name)
: FreeRTOS::Task(priority, configMINIMAL_STACK_SIZE, name) {}
void taskFunction() final;
private:
int led;
};
// Task to be created.
void LedTask::taskFunction() {
bool LedState = false;
for (;;) {
Board_LED_Set(led, LedState);
LedState = (bool) !LedState;
led++;
if(led > 2){
led = 0;
}
vTaskDelay(configTICK_RATE_HZ / 2);
}
}
#include "threads/master/Master.h"
int main(void)
{
SystemCoreClockUpdate();
Board_Init();
// Create a task before starting the kernel.
LedTask task1((tskIDLE_PRIORITY + 1UL), "vTaskLed1");
Master master;
// Start the real time kernel with preemption.
FreeRTOS::Kernel::startScheduler();

View File

@@ -0,0 +1,22 @@
/*
* Master.cpp
*
* Created on: 4 Apr 2023
* Author: tylen
*/
#include "Master.h"
void Master::taskFunction() {
bool LedState = true;
for (;;) {
Board_LED_Set(led, LedState);
LedState = (bool) !LedState;
led++;
if(led > 2){
led = 0;
}
vTaskDelay(1000);
}
}

View File

@@ -0,0 +1,34 @@
/*
* Master.h
*
* Created on: 4 Apr 2023
* Author: tylen
*/
#ifndef THREADS_MASTER_MASTER_H_
#define THREADS_MASTER_MASTER_H_
#include "chip.h"
#include "board.h"
#include "FreeRTOSCPP/Task.hpp"
#include "FreeRTOSCPP/Kernel.hpp"
#include "task.h"
class Master : public FreeRTOS::Task {
public:
Master(): FreeRTOS::Task((tskIDLE_PRIORITY + 1UL),
configMINIMAL_STACK_SIZE * 10,
"master"){};
virtual ~Master() = default;
Master(Master&&) noexcept = default;
Master& operator=(Master&&) noexcept = default;
void taskFunction();
private:
int led;
};
#endif /* THREADS_MASTER_MASTER_H_ */