ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
13#include <libtock-sync/services/alarm.h>
14#include <stdbool.h>
15#include <ulog.h>
16
21#define LOG_LINE_SIZE 240
22
29static void microsd_log_output(ulog_event* ev, void* arg) {
30 (void)arg;
31
32 // Guard against recursion. If anything reached from ControllerMicroSDLog()
33 // ever logs, that log would re-enter this handler and recurse forever.
34 static bool busy = false;
35 if (busy) {
36 return;
37 }
38 busy = true;
39
40 // static to keep 128 bytes off the stack, matching microlog's own examples.
41 // Safe despite being shared state because the busy guard above prevents
42 // re-entry.
43 static char line[LOG_LINE_SIZE];
44 if (ulog_event_to_cstr(ev, line, sizeof(line)) == ULOG_STATUS_OK) {
45 ControllerMicroSDLog(line, "example_log");
46 }
47
48 busy = false;
49}
50
51int main(void) {
52 ulog_info("=== microSD log example ===");
53
54 // Allocates the tx/rx buffers used by ControllerMicroSDLog(). Must happen
55 // before the output is registered, otherwise the first forwarded line
56 // encodes into a NULL buffer.
58
59 // Give the esp32 a moment to be ready to accept i2c traffic.
60 libtocksync_alarm_delay_ms(100);
61
62 ulog_output_id sd_output =
63 ulog_output_add(microsd_log_output, NULL, ULOG_LEVEL_INFO);
64 if (sd_output == ULOG_OUTPUT_INVALID) {
65 // Almost always means ULOG_BUILD_EXTRA_OUTPUTS was not set when microlog
66 // was compiled, see embedded/external/microlog/Makefile.
67 ulog_error("Could not register microSD log output");
68 return 1;
69 }
70
71 // This one goes to the console AND to /stm32.log on the card.
72 ulog_info("hello world");
73
75
76 return 0;
77}
int main()
Definition main.c:4
Controller module for stm32.
#define LOG_LINE_SIZE
Definition main.c:21
void ControllerDeinit(void)
Shared deinitialize for all esp32 modules.
Definition controller.c:41
void ControllerInit(void)
Shared initialization for all esp32 modules.
Definition controller.c:14
uint32_t ControllerMicroSDLog(const char *msg, const char *base)
Append a line of plain text to the log file on the microSD card.
Definition microsd.c:155
MicroSD interface implementation with the esp32.