GPS Device
Loading...
Searching...
No Matches
Log Public APIs

Functions

ERR_te log_init (LOG_HANDLE_ts *log_handle)
 Initializes the log subsystem.
ERR_te log_deinit ()
 Deinitializes the log subsystem.
ERR_te log_print (MODULES_te subsys, LOG_LEVEL_te subsys_log_level, LOG_LEVEL_te log_level, char *msg,...)
 Prints a formatted message to the serial terminal if the severity threshold is met.
ERR_te log_get_level_name (LOG_LEVEL_te log_level, char *str)
 Converts a LOG_LEVEL_te value to its lowercase string name.
ERR_te log_level_to_int (char const *str, LOG_LEVEL_te *log_level)
 Converts a log level name string to its LOG_LEVEL_te value.
ERR_te log_set_force_disable (bool bool_status)
 Enables or disables forced suppression of all log output.

Detailed Description

Function Documentation

◆ log_init()

ERR_te log_init ( LOG_HANDLE_ts * log_handle)

Initializes the log subsystem.

See also
log_init

Definition at line 56 of file log.c.

56 {
57 if(internal_state.initialized) {
59 }
60
61 internal_state.usart_instance = log_handle->usart_instance;
62
63 init_rtc();
64
65 GPIO_CFG_ts log_tx_pin = { 0 };
66 log_tx_pin.port = log_handle->gpio_port;
67 log_tx_pin.pin = log_handle->gpio_pin;
69 log_tx_pin.alternate_function = log_handle->gpio_alternate_function;
70 gpio_init(&log_tx_pin);
71
72 USART_CFG_ts log_usart = { 0 };
73 log_usart.instance = log_handle->usart_instance;
74 log_usart.baud_rate = log_handle->usart_baud_rate;
75 usart_init(&log_usart);
76
78
79 internal_state.initialized = true;
80
81 return ERR_OK;
82}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
@ ENABLE
Definition common.h:100
@ ERR_OK
Definition err.h:36
@ ERR_MODULE_ALREADY_INITIALIZED
Definition err.h:54
ERR_te init_rtc(void)
Initializes the RTC peripheral and sets a default calendar and time.
Definition init.c:72
void gpio_init(GPIO_CFG_ts *gpio_cfg)
Initializes a GPIO pin according to the given configuration.
@ GPIO_MODE_ALTERNATE_FUNCTION
void usart_init(USART_CFG_ts *usart_cfg)
Initializes the USART peripheral with the given configuration.
void usart_set_transmission(USART_REGDEF_ts *usart_instance, EN_STATUS_te en_status)
Enables or disables the USART transmitter (TE bit).
Configuration structure for initializing a GPIO pin.
GPIO_REGDEF_ts * port
GPIO_ALTERNATE_FUNCTION_te alternate_function
GPIO_PIN_te pin
GPIO_MODE_te mode
GPIO_REGDEF_ts * gpio_port
Definition log.h:88
GPIO_ALTERNATE_FUNCTION_te gpio_alternate_function
Definition log.h:94
USART_BAUD_RATE_te usart_baud_rate
Definition log.h:85
USART_REGDEF_ts * usart_instance
Definition log.h:82
GPIO_PIN_te gpio_pin
Definition log.h:91
Configuration structure for initializing a USART peripheral.
USART_BAUD_RATE_te baud_rate
USART_REGDEF_ts * instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_deinit()

ERR_te log_deinit ( void )

Deinitializes the log subsystem.

See also
log_deinit

Definition at line 85 of file log.c.

85 {
86 if(internal_state.usart_instance == (void*)0) {
88 }
89
90 usart_deinit(internal_state.usart_instance);
91
92 internal_state.usart_instance = 0;
93 internal_state.force_disable = 0;
94
95 return ERR_OK;
96}
@ ERR_UNINITIALZIED_OBJECT
Definition err.h:42
void usart_deinit(USART_REGDEF_ts const *usart_instance)
Deinitializes the USART peripheral, disables its NVIC interrupt, and disables its clock.
Here is the call graph for this function:

◆ log_print()

ERR_te log_print ( MODULES_te subsys,
LOG_LEVEL_te subsys_log_level,
LOG_LEVEL_te log_level,
char * msg,
... )

Prints a formatted message to the serial terminal if the severity threshold is met.

See also
log_print

Definition at line 99 of file log.c.

99 {
100 if (log_level >= subsys_log_level && internal_state.force_disable == false) {
101 va_list args;
102 va_start(args, msg);
103
104 log_print_prologue(subsys, log_level);
105
106 while (*msg != '\0') {
107 if (*msg == '%') {
108 msg++;
109
110 if (*msg == 'd') {
111 int32_t num = va_arg(args, int);
112 char num_buf[12];
113 int_to_str(num, num_buf);
114 usart_send(internal_state.usart_instance, (uint8_t*)num_buf, get_str_len(num_buf));
115 }
116 else if (*msg == 's') {
117 char *str = va_arg(args, char*);
118 usart_send(internal_state.usart_instance, (uint8_t*)str, get_str_len(str));
119 }
120 else if(*msg == '.') {
121 msg++;
122
123 char dec_places_str[2];
124 dec_places_str[0] = *msg; // There can be no more than 9 decimal places
125 dec_places_str[1] = '\0';
126
127 msg++;
128
129 if(*msg == 'f') {
130 double num = va_arg(args, double);
131 char num_buf[20] = { 0 };
132 double_to_str(num, num_buf, str_to_int(dec_places_str));
133 usart_send(internal_state.usart_instance, (uint8_t*)num_buf, get_str_len(num_buf));
134 }
135 }
136 }
137 else {
138 usart_send(internal_state.usart_instance, (uint8_t*)msg, 1);
139 }
140
141 msg++;
142 }
143
144 va_end(args);
145
146 usart_send(internal_state.usart_instance, (uint8_t*)"\r\n", 2);
147 }
148
149 return ERR_OK;
150}
int str_to_int(const char *str)
Converts a decimal string to an integer.
Definition common.c:69
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
Definition common.c:22
void double_to_str(double num, char *str, int8_t frac_digits)
Converts a double to a decimal string with a fixed number of fractional digits.
Definition common.c:102
void int_to_str(int num, char *str)
Converts an integer to its decimal string representation.
Definition common.c:33
static ERR_te log_print_prologue(MODULES_te subsys, LOG_LEVEL_te log_level)
Prints the log message prologue: timestamp, severity, and subsystem name.
Definition log.c:248
void usart_send(USART_REGDEF_ts *usart_instance, uint8_t *tx_buffer, uint32_t len)
Blocking USART transmit. Sends len bytes from tx_buffer.
Here is the call graph for this function:

◆ log_get_level_name()

ERR_te log_get_level_name ( LOG_LEVEL_te log_level,
char * str )

Converts a LOG_LEVEL_te value to its lowercase string name.

See also
log_get_level_name

Definition at line 153 of file log.c.

153 {
154 char const *name;
155
156 switch(log_level) {
157 case LOG_LEVEL_NONE:
158 name = "none";
159 break;
160
161 case LOG_LEVEL_INFO:
162 name = "info";
163 break;
164
165 case LOG_LEVEL_DEBUG:
166 name = "debug";
167 break;
168
170 name = "warning";
171 break;
172
173 case LOG_LEVEL_ERROR:
174 name = "error";
175 break;
176
178 name = "critical";
179 break;
180
181 default:
182 return ERR_UNKNOWN;
183 break;
184 }
185
186 str_cpy(str, name, get_str_len(name) + 1);
187
188 return ERR_OK;
189}
int str_cpy(char *str_to, const char *str_from, uint32_t len)
Copies a null-terminated string into a destination buffer.
Definition common.c:333
@ ERR_UNKNOWN
Definition err.h:37
@ LOG_LEVEL_CRITICAL
Definition log.h:68
@ LOG_LEVEL_DEBUG
Definition log.h:65
@ LOG_LEVEL_ERROR
Definition log.h:67
@ LOG_LEVEL_WARNING
Definition log.h:66
@ LOG_LEVEL_NONE
Definition log.h:69
@ LOG_LEVEL_INFO
Definition log.h:64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_level_to_int()

ERR_te log_level_to_int ( char const * str,
LOG_LEVEL_te * log_level )

Converts a log level name string to its LOG_LEVEL_te value.

See also
log_level_to_int

Definition at line 192 of file log.c.

192 {
193 if(str_cmp(str, "none") == true) {
194 *log_level = LOG_LEVEL_NONE;
195 }
196 else if(str_cmp(str, "info") == true) {
197 *log_level = LOG_LEVEL_INFO;
198 }
199 else if(str_cmp(str, "debug") == true) {
200 *log_level = LOG_LEVEL_DEBUG;
201 }
202 else if(str_cmp(str, "warning") == true) {
203 *log_level = LOG_LEVEL_WARNING;
204 }
205 else if(str_cmp(str, "error") == true) {
206 *log_level = LOG_LEVEL_ERROR;
207 }
208 else if(str_cmp(str, "critical") == true) {
209 *log_level = LOG_LEVEL_CRITICAL;
210 }
211 else {
212 *log_level = LOG_LEVEL_NONE;
213 }
214
215 return ERR_OK;
216}
bool str_cmp(const char *str1, const char *str2)
Compares two null-terminated strings for equality.
Definition common.c:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_set_force_disable()

ERR_te log_set_force_disable ( bool bool_status)

Enables or disables forced suppression of all log output.

See also
log_set_force_disable

Definition at line 219 of file log.c.

219 {
220 internal_state.force_disable = bool_status;
221
222 return ERR_OK;
223}
Here is the caller graph for this function: