rotary: init task [#9]

This commit is contained in:
Vasily Davydov
2023-04-26 16:54:50 +03:00
parent e4885adbc9
commit 809358b341
6 changed files with 92 additions and 36 deletions

View File

@@ -5,6 +5,7 @@
#include <cr_section_macros.h>
#include "ThreadCommon.h"
#include "Master.h"
#include "Rotary.h"
int main(void)
@@ -17,20 +18,15 @@ int main(void)
qmanager->createQueue(100,
sizeof(Event),
ThreadCommon::QueueManager::master_event_all);
//Creating tasks
manager->createTask(master_thread, "master",
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
static_cast<void*>(qmanager));
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
static_cast<void*>(qmanager));
manager->createTask(rotary_thread, "rotary",
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
static_cast<void*>(qmanager));
//<Queue_test>
Event* e = new Event(Event::Rotary, 1);
qmanager->send<Event>(ThreadCommon::QueueManager::master_event_all, e, 1000);
//</Queue_test>
// Start the real time kernel with preemption.
//FreeRTOS::Kernel::startScheduler();
vTaskStartScheduler ();
return 1;

View File

@@ -18,6 +18,13 @@
namespace ThreadCommon
{
enum RotaryAction
{
Right,
Left,
Press,
Idle
};
class ThreadManager
{
public:

View File

@@ -18,7 +18,7 @@ void Master::taskFunction() {
bool LedState = true;
for (;;) {
_qm->receive<Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
if(data.getDataOf(Event::Rotary) == 1){
if(data.getDataOf(Event::Rotary) == ThreadCommon::RotaryAction::Idle){
Board_LED_Set(led, LedState);
}
}

View File

@@ -0,0 +1,26 @@
/*
* Rotary.cpp
*
* Created on: 26 Apr 2023
* Author: tylen
*/
#include "Rotary.h"
Rotary::Rotary(ThreadCommon::QueueManager* qm) : _qm(qm) {}
Rotary::~Rotary() {}
void Rotary::taskFunction()
{
Event data(Event::Null, 0);
Event* e = new Event(Event::Rotary, ThreadCommon::RotaryAction::Idle);
_qm->send<Event>(ThreadCommon::QueueManager::master_event_all, e, 10);
for (;;) {}
}
void rotary_thread(void* pvParams)
{
Rotary r(static_cast<ThreadCommon::QueueManager*>(pvParams));
r.taskFunction();
}

View File

@@ -0,0 +1,26 @@
/*
* Rotary.h
*
* Created on: 26 Apr 2023
* Author: tylen
*/
#ifndef THREADS_ROTARY_ROTARY_H_
#define THREADS_ROTARY_ROTARY_H_
#include "Event.h"
#include "ThreadCommon.h"
class Rotary {
public:
Rotary(ThreadCommon::QueueManager* qm);
virtual ~Rotary();
void taskFunction();
private:
Event* message;
ThreadCommon::QueueManager* _qm;
};
void rotary_thread(void* pvParams);
#endif /* THREADS_ROTARY_ROTARY_H_ */