agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
debug_console.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 ykat UG (haftungsbeschraenkt) - All Rights Reserved
3  *
4  * Permission for non-commercial use is hereby granted,
5  * free of charge, without warranty of any kind.
6  */
7 #ifndef ZRTOS_DEBUG_CONSOLE_H
8 #define ZRTOS_DEBUG_CONSOLE_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #ifdef ZRTOS_DEBUG__CFG_ENABLED
14 
15 #include <zrtos/types.h>
16 #include <zrtos/str.h>
17 
18 #define ZRTOS_DEBUG_CONSOLE__INIT(name,length)\
19  uint8_t name##_buffer[length];\
20  zrtos_debug_console_t name = {\
21  .buffer = name##_buffer\
22  ,.ptr = name##_buffer\
23  ,.buffer_length = sizeof(name##_buffer)/sizeof(name##_buffer[0])\
24  };
25 
26 typedef struct _zrtos_debug_console_t{
27  uint8_t *buffer;
28  uint8_t *ptr;
29  size_t buffer_length;
30 }zrtos_debug_console_t;
31 
32 void zrtos_debug_console__put_char(zrtos_debug_console_t *thiz,char c){
33  if(thiz->ptr > thiz->buffer + thiz->buffer_length){
34  thiz->ptr = thiz->buffer;
35  }
36  *thiz->ptr++ = c;
37 }
38 
39 static void zrtos_debug_console__printf_callback(void *args,char c){
40  zrtos_debug_console__put_char((zrtos_debug_console_t *)args,c);
41 }
42 
43 void zrtos_debug_console__printf(
44  zrtos_debug_console_t *thiz
45  ,char const *fmt
46  ,...
47 ){
48  va_list arg;
49  va_start(arg, fmt);
51  zrtos_debug_console__printf_callback
52  ,(void*)thiz
53  ,fmt
54  ,arg
55  );
56  va_end(arg);
57 }
58 
59 #endif
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 #endif
static uint8_t
Definition: mcp2515.h:159
static void zrtos_str__vsnprintf_internal(void(*putc)(void *args, char c), void *putc_args, char const *fmt, va_list arg)
Definition: str.h:95