#pragma once /* This file contains functions to enable logging from realtime functions. * Actual log writing happens in the FreeRTOS idle task. */ #include "FreeRTOS.h" #include "queue.h" typedef struct { const char *format; unsigned arg1; unsigned arg2; } syslog_entry_t; extern xQueueHandle syslog_queue; // Send a log message through the syslog queue. // The message may contain up to 2 unsigned arguments, allowing printf // formatting to be offloaded to the logging thread. // The format string must be in ROM. // This function will never block. static inline void syslog(const char *format, unsigned arg1, unsigned arg2) { syslog_entry_t entry = {format, arg1, arg2}; xQueueSend(syslog_queue, &entry, 0); } // Atomic event counters. The idle task will check these periodically // and log any counts. #define counter_inc(x) __sync_fetch_and_add(&(x), 1) #define counter_get_and_zero(x) __sync_fetch_and_and(&(x), 0) #define COUNTERS_XMACRO \ X(COUNTER_io_cli_errors) \ X(COUNTER_io_gsm_errors) #define X(cnt) extern volatile unsigned cnt; COUNTERS_XMACRO #undef X void syslog_init(); void syslog_poll(); void syslog_task(void *pvParameters);