logging: don't ask...
This commit is contained in:
parent
398030afe8
commit
2c3e1a8dc8
@ -53,6 +53,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/shoh/src/threads/user_interface}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/threads/rotary}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/threads/manager}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/threads/logging}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/shoh/src/peripherals}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.cpp.misc.dialect.4036734" name="Language standard" superClass="com.crt.advproject.cpp.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.cpp17" valueType="enumerated"/>
|
||||
@ -86,6 +87,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/shoh/src/threads/master}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/shoh/src/threads/user_interface}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/shoh/src/peripherals}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/shoh/src/threads/logging}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.c.misc.dialect.82852045" name="Language standard" superClass="com.crt.advproject.c.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c17" valueType="enumerated"/>
|
||||
<inputType id="com.crt.advproject.compiler.input.765511076" superClass="com.crt.advproject.compiler.input"/>
|
||||
|
||||
@ -7,50 +7,21 @@
|
||||
|
||||
#include "ThreadCommon.h"
|
||||
#include "Master.h"
|
||||
#include "Rotary.h"
|
||||
#include "Manager.h"
|
||||
#include "UserInterface.h"
|
||||
#include "Log.h"
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
LOG_INFO("Starting system init");
|
||||
SystemCoreClockUpdate();
|
||||
Board_Init();
|
||||
|
||||
retarget_init();
|
||||
|
||||
LOG_INFO("System init done");
|
||||
|
||||
ThreadCommon::ThreadManager* manager = new ThreadCommon::ThreadManager;
|
||||
ThreadCommon::QueueManager* qmanager = new ThreadCommon::QueueManager;
|
||||
LOG_INFO("Creating queues");
|
||||
qmanager->createQueue(100,
|
||||
sizeof(Event),
|
||||
ThreadCommon::QueueManager::master_event_all);
|
||||
qmanager->createQueue(20,
|
||||
sizeof(Event),
|
||||
ThreadCommon::QueueManager::manager_event_master);
|
||||
qmanager->createQueue(20,
|
||||
sizeof(UserInterface::InterfaceWithData),
|
||||
ThreadCommon::QueueManager::ui_event_manager);
|
||||
|
||||
LOG_INFO("Creating tasks");
|
||||
manager->createTask(thread_master, "master",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(qmanager));
|
||||
manager->createTask(thread_manager, "manager",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(qmanager));
|
||||
manager->createTask(thread_rotary, "rotary",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(qmanager));
|
||||
manager->createTask(thread_user_interface, "user_interface",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(qmanager));
|
||||
|
||||
LOG_INFO("Start the real time kernel with preemption");
|
||||
ThreadCommon::CommonManagers manager = {new ThreadCommon::ThreadManager,
|
||||
new ThreadCommon::QueueManager};
|
||||
manager.tm->createTask(thread_master, "master",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(&manager));
|
||||
vTaskStartScheduler ();
|
||||
|
||||
return 1;
|
||||
|
||||
@ -13,14 +13,11 @@ ThreadCommon::QueueManager::QueueManager() {}
|
||||
bool ThreadCommon::QueueManager::createQueue(size_t queue_length, size_t item_size, Queue_id qid)
|
||||
{
|
||||
QueueHandle_t queue_to_create;
|
||||
LOG_DEBUG("Creating queue with id %d", qid);
|
||||
if ((queue_to_create = xQueueCreate(queue_length, item_size)))
|
||||
{
|
||||
LOG_DEBUG("Queue with id %d has been created", qid);
|
||||
queues.insert({qid, queue_to_create});
|
||||
return true;
|
||||
}
|
||||
LOG_ERROR("Failed to cerate queue with id %d", qid);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
namespace ThreadCommon
|
||||
{
|
||||
|
||||
enum RotaryAction
|
||||
{
|
||||
Right,
|
||||
@ -45,7 +46,8 @@ namespace ThreadCommon
|
||||
master_event_all,
|
||||
relay_event_master,
|
||||
manager_event_master,
|
||||
ui_event_manager
|
||||
ui_event_manager,
|
||||
logging_message_all
|
||||
};
|
||||
QueueManager();
|
||||
~QueueManager() = default;
|
||||
@ -70,6 +72,12 @@ namespace ThreadCommon
|
||||
std::map <Queue_id, QueueHandle_t> queues;
|
||||
};
|
||||
|
||||
typedef struct _CommonManagers
|
||||
{
|
||||
ThreadManager * tm;
|
||||
QueueManager * qm;
|
||||
} CommonManagers;
|
||||
|
||||
/* global variables */
|
||||
/* 'receiver'_'what'_'sender'_q */
|
||||
/*
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "ThreadCommon.h"
|
||||
#include "Log.h"
|
||||
|
||||
|
||||
ThreadCommon::ThreadManager::ThreadManager(){}
|
||||
@ -11,18 +10,12 @@ bool ThreadCommon::ThreadManager::createTask(void (*task_func)(void*),
|
||||
void* parameters)
|
||||
{
|
||||
const char * t_name = name.c_str();
|
||||
LOG_DEBUG("Creating task [name: %s, priority: %ld, stack: %ld]",
|
||||
t_name, priority, stack_size);
|
||||
BaseType_t taskCreated = xTaskCreate(task_func,
|
||||
t_name,
|
||||
stack_size,
|
||||
parameters,
|
||||
priority,
|
||||
NULL);
|
||||
if (!(taskCreated == pdPASS))
|
||||
{
|
||||
LOG_ERROR("Failed to create a task [name: %s, priority: %ld, stack: %ld]",
|
||||
t_name, priority, stack_size)
|
||||
}
|
||||
assert(taskCreated == pdPASS);
|
||||
return (taskCreated == pdPASS);
|
||||
}
|
||||
|
||||
@ -5,13 +5,11 @@
|
||||
#include "board.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
|
||||
/*
|
||||
This simlpe logging framework is dependant
|
||||
on std lib's multithread support, thus
|
||||
if needed on different platforms, please
|
||||
wrap it with mutexes.
|
||||
*/
|
||||
extern QueueHandle_t logging_queue;
|
||||
|
||||
/* ================= Settings ================== */
|
||||
#define LOG_COLORED_OUTPUT
|
||||
@ -44,7 +42,9 @@
|
||||
|
||||
#define _LOG_STREAMOUT(message, message_length) \
|
||||
INT_ASSERT(message_length > 0); \
|
||||
printf("%.*s\n", message_length, message); \
|
||||
if (logging_queue) { \
|
||||
xQueueSend(logging_queue, (void*)message, portMAX_DELAY); \
|
||||
}
|
||||
|
||||
static void create_log_line(const char * _status,
|
||||
const char * _location,
|
||||
@ -69,20 +69,20 @@ static void create_log_line(const char * _status,
|
||||
}
|
||||
|
||||
#define LOG_INFO(fmt, ...) \
|
||||
create_log_line(C_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
create_log_line(C_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__);
|
||||
|
||||
#define LOG_WARNING(fmt, ...) \
|
||||
create_log_line(C_WARN, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
create_log_line(C_WARN, __FILE__, __LINE__, fmt, ##__VA_ARGS__);
|
||||
|
||||
#define LOG_ERROR(fmt, ...) \
|
||||
create_log_line(C_ERROR, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
create_log_line(C_ERROR, __FILE__, __LINE__, fmt, ##__VA_ARGS__);
|
||||
|
||||
#if LOG_DEBUG_MESSAGES
|
||||
#define LOG_DEBUG(fmt, ...) \
|
||||
create_log_line(C_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
create_log_line(C_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__);
|
||||
#else
|
||||
#define LOG_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __THREAD_COMMON_LOG_H_ */
|
||||
#endif /* __THREAD_COMMON_LOG_H_ */
|
||||
35
source/shoh/src/threads/logging/Logging.cpp
Normal file
35
source/shoh/src/threads/logging/Logging.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Logging.cpp
|
||||
*
|
||||
* Created on: 12 May 2023
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#include "Logging.h"
|
||||
#include "ThreadCommon.h"
|
||||
#include "Log.h"
|
||||
#include "queue.h"
|
||||
|
||||
Logging::Logging(ThreadCommon::QueueManager * qm) : _qm(qm) {
|
||||
q = _qm->getQueue(ThreadCommon::QueueManager::logging_message_all);
|
||||
}
|
||||
|
||||
Logging::~Logging() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void Logging::taskFunction()
|
||||
{
|
||||
char data[LOG_BUFFER_MAX_CAP] = {0};
|
||||
xQueueReceive(q, static_cast<char*>(data), portMAX_DELAY);
|
||||
mutex.lock();
|
||||
printf("%s\n", data);
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void thread_logging(void* pvParams)
|
||||
{
|
||||
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
||||
Logging log(manager->qm);
|
||||
log.taskFunction();
|
||||
}
|
||||
27
source/shoh/src/threads/logging/Logging.h
Normal file
27
source/shoh/src/threads/logging/Logging.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Logging.h
|
||||
*
|
||||
* Created on: 12 May 2023
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#ifndef THREADS_LOGGING_LOGGING_H_
|
||||
#define THREADS_LOGGING_LOGGING_H_
|
||||
|
||||
#include "Fmutex.h"
|
||||
#include "ThreadCommon.h"
|
||||
|
||||
class Logging {
|
||||
public:
|
||||
Logging(ThreadCommon::QueueManager * qm);
|
||||
virtual ~Logging();
|
||||
void taskFunction();
|
||||
private:
|
||||
ThreadCommon::QueueManager * _qm;
|
||||
QueueHandle_t q;
|
||||
Fmutex mutex;
|
||||
};
|
||||
|
||||
void thread_logging(void* pvParams);
|
||||
|
||||
#endif /* THREADS_LOGGING_LOGGING_H_ */
|
||||
@ -52,6 +52,7 @@ void Manager::taskFunction()
|
||||
|
||||
void thread_manager(void* pvParams)
|
||||
{
|
||||
Manager m(static_cast<ThreadCommon::QueueManager*>(pvParams));
|
||||
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
||||
Manager m(manager->qm);
|
||||
m.taskFunction();
|
||||
}
|
||||
|
||||
@ -7,6 +7,13 @@
|
||||
|
||||
#include "Master.h"
|
||||
#include "Log.h"
|
||||
#include "ThreadCommon.h"
|
||||
#include "Rotary.h"
|
||||
#include "Manager.h"
|
||||
#include "Logging.h"
|
||||
#include "UserInterface.h"
|
||||
#include "queue.h"
|
||||
#include "Logging.h"
|
||||
|
||||
static const char* rotary_direction[] =
|
||||
{
|
||||
@ -16,6 +23,8 @@ static const char* rotary_direction[] =
|
||||
"Idle"
|
||||
};
|
||||
|
||||
QueueHandle_t logging_queue;
|
||||
|
||||
Master::Master(ThreadCommon::QueueManager* qm) : _qm(qm)
|
||||
{
|
||||
LOG_DEBUG("Creating Master");
|
||||
@ -75,6 +84,44 @@ void Master::taskFunction() {
|
||||
|
||||
|
||||
void thread_master(void* pvParams) {
|
||||
Master m(static_cast<ThreadCommon::QueueManager*>(pvParams));
|
||||
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
||||
|
||||
manager->qm->createQueue(50,
|
||||
LOG_BUFFER_MAX_CAP,
|
||||
ThreadCommon::QueueManager::logging_message_all);
|
||||
logging_queue = manager->qm->getQueue(ThreadCommon::QueueManager::logging_message_all);
|
||||
manager->tm->createTask(thread_logging, "logging",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(manager));
|
||||
|
||||
LOG_INFO("Logging Active");
|
||||
LOG_INFO("Started the real time kernel with preemption");
|
||||
LOG_INFO("Master Started");
|
||||
Master m(manager->qm);
|
||||
LOG_INFO("Master is creating queues");
|
||||
manager->qm->createQueue(100,
|
||||
sizeof(Event),
|
||||
ThreadCommon::QueueManager::master_event_all);
|
||||
manager->qm->createQueue(20,
|
||||
sizeof(Event),
|
||||
ThreadCommon::QueueManager::manager_event_master);
|
||||
manager->qm->createQueue(20,
|
||||
sizeof(UserInterface::InterfaceWithData),
|
||||
ThreadCommon::QueueManager::ui_event_manager);
|
||||
|
||||
|
||||
LOG_INFO("Master is creating tasks");
|
||||
manager->tm->createTask(thread_master, "master",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(manager));
|
||||
manager->tm->createTask(thread_manager, "manager",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(manager));
|
||||
manager->tm->createTask(thread_rotary, "rotary",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(manager));
|
||||
manager->tm->createTask(thread_user_interface, "user_interface",
|
||||
configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL,
|
||||
static_cast<void*>(manager));
|
||||
m.taskFunction();
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "ThreadCommon.h"
|
||||
#include "Event.h"
|
||||
#include "task.h"
|
||||
|
||||
@ -86,6 +86,7 @@ void thread_rotary(void* pvParams)
|
||||
QueueHandle_t rotary_isr_q = xQueueCreate(15, sizeof(char));
|
||||
p_rotary_isr_q = &rotary_isr_q;
|
||||
|
||||
Rotary r(static_cast<ThreadCommon::QueueManager*>(pvParams));
|
||||
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
||||
Rotary r(manager->qm);
|
||||
r.taskFunction();
|
||||
}
|
||||
|
||||
@ -60,11 +60,11 @@ void UserInterface::handleEvent(InterfaceWithData* ui_data)
|
||||
void UserInterface::handleLCD(LiquidCrystal *lcd, const char *str)
|
||||
{
|
||||
//Interpret empty string as clear.
|
||||
if(!strlen(str))
|
||||
if(!strlen(str)){
|
||||
lcd->clear();
|
||||
LOG_INFO("Clear up LCD");
|
||||
//Print the text otherwise.
|
||||
else
|
||||
}else
|
||||
{
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->print(str);
|
||||
@ -97,6 +97,7 @@ void UserInterface::initLCD1()
|
||||
|
||||
void thread_user_interface(void* pvParams)
|
||||
{
|
||||
UserInterface ui(static_cast<ThreadCommon::QueueManager*>(pvParams));
|
||||
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
||||
UserInterface ui(manager->qm);
|
||||
ui.taskFunction();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user