ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
common.h File Reference
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ARRAY_LEN(a)   (sizeof(a) / sizeof((a)[0]))
 Return compile-time element count for an array object.
 
#define RX_SHIFT_TO_LSB   (3U * CHAR_BIT)
 Bit shift used to normalize RX byte ordering to LSB position.
 
#define TX_PIO_CYCLES_PER_BIT   8U
 Number of TX PIO instructions executed per serialized bit.
 
#define US_PER_SECOND   1000000U
 The number of microseconds per second.
 
#define FLUSH_LOG_BEFORE_REBOOT_MS   200U
 Time to wait before rebooting to allow the logs to flush.
 
#define PRIu32   "u"
 
#define PRIX32   "X"
 
#define PRIu64   "lu"
 
#define UINT32_ALL_ONES   UINT32_MAX
 
#define LOG(level, fmt, ...)
 
#define LOG_PLAIN(...)   LOG(LOG_LEVEL_PLAIN, __VA_ARGS__)
 
#define LOG_ERROR(...)   LOG(LOG_LEVEL_ERROR, __VA_ARGS__)
 
#define LOG_INFO(...)   LOG(LOG_LEVEL_INFO, __VA_ARGS__)
 
#define LOG_DEBUG(...)   LOG(LOG_LEVEL_DEBUG, __VA_ARGS__)
 
#define LOG_TRACE(...)   LOG(LOG_LEVEL_TRACE, __VA_ARGS__)
 
#define PRINT_FRAME_HEX(label, payload_ptr, length)
 

Enumerations

enum  log_level_t {
  LOG_LEVEL_PLAIN , LOG_LEVEL_ERROR , LOG_LEVEL_INFO , LOG_LEVEL_DEBUG ,
  LOG_LEVEL_TRACE
}
 Log verbosity levels. More...
 

Functions

void set_loglevel (log_level_t level)
 Set current global log level.
 
log_level_t get_loglevel (void)
 Get current global log level.
 
bool log_take_emitted_flag (void)
 Atomically read and clear "log emitted" flag.
 
void log_core1_drain (void)
 
uint32_t log_take_dropped_count (void)
 
uint32_t log_get_high_water_mark (void)
 
static const char * log_level_tag (log_level_t level)
 Get printable tag for a log level.
 
void log_write (log_level_t level, const char *fmt,...)
 Emit one formatted log message if level is enabled.
 

Macro Definition Documentation

◆ ARRAY_LEN

#define ARRAY_LEN (   a)    (sizeof(a) / sizeof((a)[0]))

Return compile-time element count for an array object.

Definition at line 32 of file common.h.

◆ FLUSH_LOG_BEFORE_REBOOT_MS

#define FLUSH_LOG_BEFORE_REBOOT_MS   200U

Time to wait before rebooting to allow the logs to flush.

Definition at line 57 of file common.h.

◆ LOG

#define LOG (   level,
  fmt,
  ... 
)
Value:
do \
{ \
/* Evaluate level once to avoid double-evaluation side effects. */ \
const log_level_t _log_level = (level); \
if (get_loglevel() >= _log_level) \
{ \
log_write(_log_level, (fmt), ##__VA_ARGS__); \
} \
} while (0)
log_level_t get_loglevel(void)
Get current global log level.
Definition log.c:61
log_level_t
Log verbosity levels.
Definition common.h:87

Definition at line 151 of file common.h.

◆ LOG_DEBUG

#define LOG_DEBUG (   ...)    LOG(LOG_LEVEL_DEBUG, __VA_ARGS__)

Definition at line 165 of file common.h.

◆ LOG_ERROR

#define LOG_ERROR (   ...)    LOG(LOG_LEVEL_ERROR, __VA_ARGS__)

Definition at line 163 of file common.h.

◆ LOG_INFO

#define LOG_INFO (   ...)    LOG(LOG_LEVEL_INFO, __VA_ARGS__)

Definition at line 164 of file common.h.

◆ LOG_PLAIN

#define LOG_PLAIN (   ...)    LOG(LOG_LEVEL_PLAIN, __VA_ARGS__)

Definition at line 162 of file common.h.

◆ LOG_TRACE

#define LOG_TRACE (   ...)    LOG(LOG_LEVEL_TRACE, __VA_ARGS__)

Definition at line 166 of file common.h.

◆ PRINT_FRAME_HEX

#define PRINT_FRAME_HEX (   label,
  payload_ptr,
  length 
)
Value:
do \
{ \
LOG_DEBUG("%s", (label)); \
for (size_t _i = 0; _i < (length); _i++) \
{ \
LOG_DEBUG("%02X ", (unsigned)(payload_ptr)[_i]); \
if (_i % 16 == 15) \
{ \
LOG_DEBUG("\r\n"); \
} \
} \
LOG_DEBUG("\r\n"); \
} while (0)

Definition at line 168 of file common.h.

◆ PRIu32

#define PRIu32   "u"

Definition at line 64 of file common.h.

◆ PRIu64

#define PRIu64   "lu"

Definition at line 73 of file common.h.

◆ PRIX32

#define PRIX32   "X"

Definition at line 68 of file common.h.

◆ RX_SHIFT_TO_LSB

#define RX_SHIFT_TO_LSB   (3U * CHAR_BIT)

Bit shift used to normalize RX byte ordering to LSB position.

Definition at line 37 of file common.h.

◆ TX_PIO_CYCLES_PER_BIT

#define TX_PIO_CYCLES_PER_BIT   8U

Number of TX PIO instructions executed per serialized bit.

Definition at line 47 of file common.h.

◆ UINT32_ALL_ONES

#define UINT32_ALL_ONES   UINT32_MAX

Definition at line 81 of file common.h.

◆ US_PER_SECOND

#define US_PER_SECOND   1000000U

The number of microseconds per second.

Definition at line 52 of file common.h.

Enumeration Type Documentation

◆ log_level_t

Log verbosity levels.

Enumerator
LOG_LEVEL_PLAIN 
LOG_LEVEL_ERROR 
LOG_LEVEL_INFO 
LOG_LEVEL_DEBUG 
LOG_LEVEL_TRACE 

Definition at line 86 of file common.h.

Function Documentation

◆ get_loglevel()

log_level_t get_loglevel ( void  )

Get current global log level.

Returns
Active log level.

Definition at line 61 of file log.c.

References global_log_state_t::current_log_level, and global_logstate.

Referenced by cat_loglevel_get(), cat_loglevel_set(), event_dispatch(), and main().

Here is the caller graph for this function:

◆ log_core1_drain()

void log_core1_drain ( void  )

Definition at line 115 of file log.c.

References global_logstate, global_log_state_t::head, log_entry_t::line, LOG_QUEUE_MASK, global_log_state_t::queue, and global_log_state_t::tail.

Referenced by core1_entry().

Here is the caller graph for this function:

◆ log_get_high_water_mark()

uint32_t log_get_high_water_mark ( void  )

Definition at line 139 of file log.c.

References global_logstate, and global_log_state_t::high_water_mark.

Referenced by update_statistics().

Here is the caller graph for this function:

◆ log_level_tag()

static const char * log_level_tag ( log_level_t  level)
inlinestatic

Get printable tag for a log level.

Parameters
levelLog level.
Returns
Static tag string.

Definition at line 125 of file common.h.

References LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_PLAIN, and LOG_LEVEL_TRACE.

Referenced by cat_loglevel_get(), and cat_loglevel_set().

Here is the caller graph for this function:

◆ log_take_dropped_count()

uint32_t log_take_dropped_count ( void  )

Definition at line 132 of file log.c.

References global_log_state_t::dropped, and global_logstate.

Referenced by update_statistics().

Here is the caller graph for this function:

◆ log_take_emitted_flag()

bool log_take_emitted_flag ( void  )

Atomically read and clear "log emitted" flag.

Returns
true if any log was emitted since previous call.

Definition at line 144 of file log.c.

References global_logstate, and global_log_state_t::log_emitted.

Referenced by event_loop().

Here is the caller graph for this function:

◆ log_write()

void log_write ( log_level_t  level,
const char *  fmt,
  ... 
)

Emit one formatted log message if level is enabled.

Parameters
levelMessage level.
fmtLOG_PLAIN-style format string.
...Format arguments.

Definition at line 71 of file log.c.

References global_log_state_t::current_log_level, global_log_state_t::dropped, global_logstate, global_log_state_t::head, global_log_state_t::high_water_mark, log_entry_t::line, global_log_state_t::log_emitted, LOG_LEVEL_PLAIN, LOG_LINE_MAX, LOG_QUEUE_MASK, log_wake_core1(), global_log_state_t::queue, and global_log_state_t::tail.

Here is the call graph for this function:

◆ set_loglevel()

void set_loglevel ( log_level_t  level)

Set current global log level.

Parameters
levelNew log level.

Definition at line 66 of file log.c.

References global_log_state_t::current_log_level, and global_logstate.

Referenced by cat_loglevel_set(), and init_app().

Here is the caller graph for this function: