- added IODevice support

- fixed some issues with the logger and stack sizes

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@216 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-09-26 11:11:33 +00:00
parent 7bcde7ff5d
commit 1bcb4809db
48 changed files with 1033 additions and 11740 deletions

View File

@@ -11,9 +11,9 @@
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: 167 $
/// $Author: mmi $
/// $Date: 2017-09-12 13:09:10 +0200 (di, 12 sep 2017) $
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
@@ -26,6 +26,7 @@
// -----------------------------------------------------------------------------
#include <FreeRTOSFixes.h>
#include "FreeRTOS.h"
#include "Logger.h"
#include "semphr.h"
@@ -42,9 +43,9 @@
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define LOGQUEUE_SIZE (64)
#define LOGQUEUE_SIZE (16)
#define LOGGER_STACK_SIZE (512)
#define LOGGER_TASK_PRIORITY (1)
#define LOGGER_TASK_PRIORITY (2)
// Makefile compile options:
// ENABLE_SERIAL_LOGGING: Use the serial port for logging.
@@ -64,7 +65,7 @@
// File-scope variables
// -----------------------------------------------------------------------------
static struct Uart* loggerInterface;
static struct IODevice* loggerDevice;
static xQueueHandle logQueue;
@@ -90,34 +91,35 @@ static void loggerTask(void* parameters);
* ---------------------*
*/
void Logger_initialize(void* const interface)
ErrorStatus Logger_construct(struct IODevice* const device)
{
ErrorStatus returnValue = SUCCESS;
if(!initialized)
{
ErrorStatus errorStatus = SUCCESS;
///TODO This is currently hardcoded into the UART - there must be a way for more generic usage
loggerInterface = (struct Uart* const) interface;
loggerDevice = device;
if(errorStatus == SUCCESS)
if(returnValue == SUCCESS)
{
logQueue = xQueueCreate(LOGQUEUE_SIZE, sizeof(struct LogQueueItem));
if(logQueue == 0)
{
errorStatus = ERROR;
returnValue = ERROR;
}
}
if(errorStatus == SUCCESS)
if(returnValue == SUCCESS)
{
if(xTaskCreate(loggerTask, (const char*)"loggerTask", LOGGER_STACK_SIZE, NULL, LOGGER_TASK_PRIORITY, &loggerTaskHandle) != pdPASS)
{
errorStatus = ERROR;
returnValue = ERROR;
}
}
if(errorStatus == SUCCESS)
if(returnValue == SUCCESS)
{
initialized = true;
LOGGER_INFO("Logger started");
@@ -127,6 +129,11 @@ void Logger_initialize(void* const interface)
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void Logger_terminate(void)
@@ -135,6 +142,15 @@ void Logger_terminate(void)
}
ErrorStatus Logger_logModuleInfo(void)
{
ErrorStatus errorStatus = SUCCESS;
OS_logTaskInfo(loggerTaskHandle);
return errorStatus;
}
void Logger_log(const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...)
{
if(initialized)
@@ -174,7 +190,7 @@ void Logger_log(const char* fileName, const char* functionName, int lineNumber,
vsnprintf(str, sizeof(str) / sizeof(str[0]), format, ap);
va_end(ap);
composeLogQueueItem(&logQueueItem, __FILE__, __func__, __LINE__, logType, str);
composeLogQueueItem(&logQueueItem, fileName, functionName, lineNumber, logType, str);
(void)xQueueSend(logQueue, &logQueueItem, 0);
}
else
@@ -254,7 +270,7 @@ static void loggerTask(void* parameters)
{
// Raw print
#if defined(ENABLE_SERIAL_LOGGING)
Uart_Write(loggerInterface, (const uint8_t*)logQueueItem.context, strlen(logQueueItem.context));
IODevice_write(loggerDevice, logQueueItem.context, strlen(logQueueItem.context));
#endif
}
@@ -310,7 +326,7 @@ static void loggerTask(void* parameters)
#endif
#if defined(ENABLE_SERIAL_LOGGING)
Uart_Write(loggerInterface, (const uint8_t*)str, strlen(str));
IODevice_write(loggerDevice, str, strlen(str));
#endif
}

View File

@@ -25,11 +25,13 @@
// Include files
// -----------------------------------------------------------------------------
#include <FreeRTOSFixes.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include "freeRTOSFixes.h"
#include "Logger.h"
#include "led.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
@@ -65,12 +67,12 @@ void OS_logTaskInfo(xTaskHandle taskHandle)
unsigned portBASE_TYPE highWaterMark;
char text[128];
snprintf(text, sizeof(text), "Task %s\n", pcTaskGetTaskName(taskHandle));
// Shell_sendString(text);
snprintf(text, sizeof(text), "***** Task %s", pcTaskGetTaskName(taskHandle));
LOGGER_INFO(text);
highWaterMark = uxTaskGetStackHighWaterMark(taskHandle);
snprintf(text, sizeof(text), "Stack high water mark : %lu long words\n", highWaterMark);
// Shell_sendString(text);
snprintf(text, sizeof(text), "***** Stack high water mark : %lu long words", highWaterMark);
LOGGER_INFO(text);
}
// Implementation for libc, needed for printf related functions.
@@ -93,7 +95,8 @@ caddr_t _sbrk(int incr)
// Stack overflow hook
void vApplicationStackOverflowHook(xTaskHandle xTask, signed portCHAR* pcTaskName)
{
// Logger_fatal(FATALCODE_STACKOVERFLOW);
LED_turnOn(ledGreen);
LOGGER_ERROR("STACK OVERFLOW IN TASK %s", pcTaskName);
}
// Malloc failed hook

View File

@@ -25,16 +25,19 @@
// Include files
// -----------------------------------------------------------------------------
#include <FreeRTOSFixes.h>
#include <stdio.h>
// FreeRTOS includes
#include "FreeRTOS.h"
#include "task.h"
#include "freeRTOSFixes.h"
#include "Logger.h"
#include "misc.h"
#include "stm32f10x_rcc.h"
#include "nhd0420.h"
#include "keypadMatrix.h"
#include "platform.h"
#include "led.h"
@@ -69,11 +72,13 @@ unsigned long ulRunTimeStatsClock = 0UL;
static struct LedTaskArguments ledTaskArguments;
static xTaskHandle initTaskHandle;
static xTaskHandle ledTaskHandle;
static xTaskHandle sysTaskHandle;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus systeminfoCommandHandler(void);
static void initTask(void* parameters);
static void ledBlinkTask(void* parameters);
// -----------------------------------------------------------------------------
@@ -91,10 +96,7 @@ int main (void)
ledTaskArguments.led = ledOrange;
ledTaskArguments.frequency = 2;
xTaskCreate(initTask, (const char* const)"initTask", 1024, NULL, 0, &initTaskHandle);
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 1024, &ledTaskArguments, 0, &ledTaskHandle);
LOGGER_INFO("Starting the scheduler");
xTaskCreate(initTask, (const char* const)"initTask", 1024, NULL, 5, &initTaskHandle);
/* Start the scheduler. */
vTaskStartScheduler();
@@ -113,11 +115,44 @@ void vApplicationTickHook ()
}
static void printSystemInfoTask(void* parameters)
{
while (1)
{
systeminfoCommandHandler();
vTaskDelay(60000);
}
}
static ErrorStatus systeminfoCommandHandler(void)
{
ErrorStatus errorStatus = SUCCESS;
size_t freeMemory;
char text[128];
freeMemory = xPortGetFreeHeapSize();
snprintf(text, sizeof(text), "Free heap memory: %d bytes", freeMemory);
LOGGER_INFO(text);
errorStatus &= Logger_logModuleInfo();
vTaskDelay(100);
errorStatus &= Keypad_logModuleInfo();
vTaskDelay(100);
OS_logTaskInfo(ledTaskHandle);
vTaskDelay(100);
OS_logTaskInfo(sysTaskHandle);
return errorStatus;
}
static void initTask(void* parameters)
{
initPlatform();
Logger_initialize(uart1);
Logger_construct(&uart1->device);
Keypad_construct();
NHD0420_construct(spiDisplay);
@@ -133,10 +168,13 @@ static void initTask(void* parameters)
vTaskDelay(1000);
NHD0420_setCursorToHome();
vTaskDelay(1000);
NHD0420_sendData("Hallo Welt", 10);
vTaskDelay(1);
NHD0420_setCursorToPosition(4, 5);
NHD0420_sendData("Koetjeboe", 9);
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 40, &ledTaskArguments, 0, &ledTaskHandle);
xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 1, &sysTaskHandle);
// Delete this init task
vTaskDelete(NULL);
}

View File

@@ -11,9 +11,9 @@
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
@@ -31,6 +31,9 @@
#include "semphr.h"
#include "stm32f10x_it.h"
#include "Logger.h"
#include "stm32f10x_exti.h"
#include "led.h"
#include "platform.h"
@@ -264,3 +267,48 @@ void SPI3_IRQHandler (void)
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
void EXTI4_IRQHandler(void)
{
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
LOGGER_INFO_ISR("EXT4 ISR");
EXTI_ClearITPendingBit(EXTI_Line4);
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
void EXTI9_5_IRQHandler (void)
{
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
{
LOGGER_INFO_ISR("EXT5 ISR");
EXTI_ClearITPendingBit(EXTI_Line5);
}
else if (EXTI_GetITStatus(EXTI_Line6) != RESET)
{
LOGGER_INFO_ISR("EXT6 ISR");
EXTI_ClearITPendingBit(EXTI_Line6);
}
else if (EXTI_GetITStatus(EXTI_Line7) != RESET)
{
LOGGER_INFO_ISR("EXT7 ISR");
EXTI_ClearITPendingBit(EXTI_Line7);
}
else if (EXTI_GetITStatus(EXTI_Line8) != RESET)
{
LOGGER_INFO_ISR("EXT8 ISR");
EXTI_ClearITPendingBit(EXTI_Line8);
}
else if (EXTI_GetITStatus(EXTI_Line9) != RESET)
{
LOGGER_INFO_ISR("EXT9 ISR");
EXTI_ClearITPendingBit(EXTI_Line9);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}