Midnight Sun Firmware
Loading...
Searching...
No Matches
log.h
1#pragma once
2
3/************************************************************************************************
4 * @file log.h
5 *
6 * @brief Header file for the logging library used to debug all modules
7 *
8 * @date 2024-11-02
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdio.h>
14#include <stdlib.h>
15
16/* Inter-component Headers */
17#include "FreeRTOS.h"
18#include "task.h"
19
20/* Intra-component Headers */
21#include "semaphore.h"
22#include "tasks.h"
23#include "uart.h"
24
31#define MAX_LOG_SIZE (size_t)200
32#define LOG_TIMEOUT_MS 10
33
34#define UARTPORT UART_PORT_1
35#define TX_PIN 6
36#define RX_PIN 7
37
38#ifndef IN_ORDER_LOGS
39#define IN_ORDER_LOGS 1
40#endif
41
42typedef enum {
47} LogLevel;
48
49extern char g_log_buffer[MAX_LOG_SIZE];
50extern Mutex s_log_mutex;
51extern UartSettings log_uart_settings;
52
53#define LOG_DEBUG(fmt, ...) LOG(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
54#define LOG_WARN(fmt, ...) LOG(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
55#define LOG_CRITICAL(fmt, ...) LOG(LOG_LEVEL_CRITICAL, fmt, ##__VA_ARGS__)
56
57#define log_init() \
58 { uart_init(UART_PORT_1, &log_uart_settings); }
59
60#ifdef MS_PLATFORM_X86
61#define LOG(level, fmt, ...) printf("[%u] %s:%u: " fmt, (level), __FILE__, __LINE__, ##__VA_ARGS__)
62#else
63#define LOG(level, fmt, ...) \
64 do { \
65 if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) { \
66 size_t msg_size = (size_t)snprintf(g_log_buffer, MAX_LOG_SIZE, "\r[%u] %s:%u: " fmt, (level), __FILE__, __LINE__, ##__VA_ARGS__); \
67 uart_tx(UART_PORT_1, (uint8_t *)g_log_buffer, msg_size); \
68 } \
69 } while (0)
70#endif
71
LogLevel
Definition: log.h:42
@ LOG_LEVEL_CRITICAL
Definition: log.h:45
@ NUM_LOG_LEVELS
Definition: log.h:46
@ LOG_LEVEL_DEBUG
Definition: log.h:43
@ LOG_LEVEL_WARN
Definition: log.h:44
Semaphore object with handle and buffer.
Definition: semaphore.h:32
UART Settings.
Definition: uart.h:53