1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
27
28
32
33
34
35
36
37
45
46
47
48
49
50
55
61
62
67
68
69
70
71
80
81
82
86
87
88
89
92
93
/* ... */
#include "k_log.h"
#include "k_module.h"
#include "k_mem.h"
#include <stdio.h>
/* ... */
/* ... */
Includes
#define LOG_DEPTH (4 * 512)
#ifdef __GNUC__
/* ... */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
/* ... */#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif Private macros
uint8_t *pLOG_CacheBuffer;
uint32_t LOG_IN_ptr = 0;
/* ... */
void k_LogInit(void)
{
pLOG_CacheBuffer = (uint8_t *)k_malloc(LOG_DEPTH);
memset (pLOG_CacheBuffer, 0, LOG_DEPTH);
LOG_IN_ptr = 0;
}{ ... }
/* ... */
PUTCHAR_PROTOTYPE
{
uint32_t cnt = 0;
if( LOG_IN_ptr++ >= LOG_DEPTH)
{
for (cnt = 1; cnt < LOG_DEPTH; cnt ++)
{
pLOG_CacheBuffer[cnt -1 ] = pLOG_CacheBuffer[cnt];
}for (cnt = 1; cnt < LOG_DEPTH; cnt ++) { ... }
LOG_IN_ptr = LOG_DEPTH;
}if (LOG_IN_ptr++ >= LOG_DEPTH) { ... }
pLOG_CacheBuffer [LOG_IN_ptr - 1] = ch;
if(ch == '\n')
{
k_UpdateLog ((char *)pLOG_CacheBuffer);
}if (ch == '\n') { ... }
return ch;
...}
/* ... */
/* ... */