src: test: update main() to c++ version of freeRTOS

This commit is contained in:
Vasily Davydov 2023-03-28 20:30:22 +03:00
parent f331222b3c
commit 532b132e66

View File

@ -1,90 +1,44 @@
/*
===============================================================================
Name : main.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
===============================================================================
*/
#include "chip.h" #include "chip.h"
#include "board.h" #include "board.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include <cr_section_macros.h> #include <cr_section_macros.h>
#include "FreeRTOSCPP/Kernel.hpp"
#include "FreeRTOSCPP/Task.hpp"
/* Sets up system hardware */ class LedTask : public FreeRTOS::Task {
static void prvSetupHardware(void) public:
{ LedTask(const UBaseType_t priority, const char* name)
SystemCoreClockUpdate(); : FreeRTOS::Task(priority, configMINIMAL_STACK_SIZE, name) {}
Board_Init(); void taskFunction() final;
} private:
int led;
};
/* LED0 toggle thread */ // Task to be created.
static void vLEDTask0(void *pvParameters) { void LedTask::taskFunction() {
bool LedState = false; bool LedState = false;
while (1) { for (;;) {
Board_LED_Set(0, LedState); Board_LED_Set(led, LedState);
LedState = (bool) !LedState; LedState = (bool) !LedState;
led++;
if(led > 2){
led = 0;
}
vTaskDelay(configTICK_RATE_HZ / 2); vTaskDelay(configTICK_RATE_HZ / 2);
} }
} }
/* LED1 toggle thread */
static void vLEDTask1(void *pvParameters) {
bool LedState = false;
while (1) {
Board_LED_Set(1, LedState);
LedState = (bool) !LedState;
vTaskDelay(configTICK_RATE_HZ * 2);
}
}
/* LED2 toggle thread */
static void vLEDTask2(void *pvParameters) {
bool LedState = false;
while (1) {
Board_LED_Set(2, LedState);
LedState = (bool) !LedState;
vTaskDelay(configTICK_RATE_HZ);
}
}
/*****************************************************************************
* Public functions
****************************************************************************/
/**
* @brief main routine for FreeRTOS blinky example
* @return Nothing, function should not exit
*/
int main(void) int main(void)
{ {
prvSetupHardware(); SystemCoreClockUpdate();
Board_Init();
// Create a task before starting the kernel.
LedTask task1((tskIDLE_PRIORITY + 1UL), "vTaskLed1");
/* LED1 toggle thread */ // Start the real time kernel with preemption.
xTaskCreate(vLEDTask1, "vTaskLed1", FreeRTOS::Kernel::startScheduler();
configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
(xTaskHandle *) NULL);
/* LED2 toggle thread */ return 1;
xTaskCreate(vLEDTask2, "vTaskLed2",
configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
(xTaskHandle *) NULL);
/* LED0 toggle thread */
xTaskCreate(vLEDTask0, "vTaskLed0",
configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
(xTaskHandle *) NULL);
/* Start the scheduler */
vTaskStartScheduler();
/* Should never arrive here */
return 1;
} }