Commit 4b603735 authored by Ulrich Huber's avatar Ulrich Huber Committed by Oliver Horst
Browse files

[fix] Atomically output log to console

parent f5edcfa6
......@@ -21,6 +21,11 @@ find_package(
REQUIRED
)
find_package(
freertos-headers 10.0.0
REQUIRED
)
add_library(
toki-syslog
......@@ -33,6 +38,7 @@ target_link_libraries(
toki-syslog
PUBLIC toki-syslog-headers
PRIVATE toki-libc-repl
PRIVATE freertos-headers
)
......
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
extern volatile uint64_t ullPortInterruptNesting;
void toki_log(const char* severity, const char* facility, const char* format, ...) {
// TODO print time information - We are currently still missing the syscall for this feature
......@@ -10,6 +15,13 @@ void toki_log(const char* severity, const char* facility, const char* format, ..
* printf(%ld.%06ld\t", (long int) tval.tv_sec, (long int)tval.tv_usec);
*/
UBaseType_t was_masked_before;
if (ullPortInterruptNesting > 0) {
was_masked_before = taskENTER_CRITICAL_FROM_ISR();
} else {
taskENTER_CRITICAL();
}
// Print the facility and severity
printf("%s\t %s ", facility, severity);
......@@ -22,7 +34,7 @@ void toki_log(const char* severity, const char* facility, const char* format, ..
* Normalize newline at end of log message (required for many components as they output
* log messages with missing new-line or missing return-character skewing our formatting)
*/
int format_len = strlen(format);
unsigned long format_len = strlen(format);
if (format_len >= 2 && format[format_len - 2] != '\r' && format[format_len - 1] != '\r')
{
printf("\r");
......@@ -33,4 +45,10 @@ void toki_log(const char* severity, const char* facility, const char* format, ..
}
va_end(va);
if (ullPortInterruptNesting > 0) {
taskEXIT_CRITICAL_FROM_ISR(was_masked_before);
} else {
taskEXIT_CRITICAL();
}
}
......@@ -4,6 +4,7 @@ include(CMakeFindDependencyMacro)
find_dependency(toki-syslog-headers)
find_dependency(toki-libc-repl)
find_dependency(freertos-headers)
# Import targets
include(${CMAKE_CURRENT_LIST_DIR}/toki-syslog-targets.cmake)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment