-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.c
164 lines (146 loc) · 3.82 KB
/
log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* error.c
*
* Created on: Sep 6, 2013
* Author: nizinski_w
*/
#include <stdarg.h>
#include <stdio.h>
#include <config.h>
#include <globals.h>
#include <lib/hal_lcd.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <tools.h>
#ifdef __GNUC__
/*
* format (archetype, string-index, first-to-check)
*
* The parameter archetype determines how the format string is interpreted, and should be printf, scanf, strftime or strfmon.
* (You can also use __printf__, __scanf__, __strftime__ or __strfmon__.)
* The parameter string-index specifies which argument is the format string argument (starting from 1),
* while first-to-check is the number of the first argument to check against the format string.
* For functions where the arguments are not available to be checked (such as vprintf),
* specify the third parameter as zero. In this case the compiler only checks the format string for consistency.
* For strftime formats, the third parameter is required to be zero.
* Since non-static C++ methods have an implicit this argument,
* the arguments of such methods should be counted from two, not one, when giving values for string-index and first-to-check.
*/
extern void LOG_Log_P (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
#endif
/**
* Log printf like message with format string from PROGRAM MEMORY
* NOTE: only format string (argument one) is taken from PGMEM
* @param format
*/
extern void LOG_Log_P (const char *format, ...)
{
va_list args;
va_start (args, format);
// printf_P (PSTR("LOG: "));
vfprintf_P (stdout, format, args);
// LCD_vClrScr();
// LCD_vPuts_P(PSTR("LOG:"));
// LCD_vGotoXY(0,1);
// LCD_vPrintf_P("%s", message);
va_end (args);
// wdt_reset();
// int_delay_ms(500);
// wdt_reset();
// LCD_vClrScr();
}
#ifdef __GNUC__
extern void LOG_Log (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
#endif
/**
* Log printf like message with format string from normal RAM
* @param format
*/
extern void LOG_Log (const char *format, ...)
{
va_list args;
va_start (args, format);
// printf_P (PSTR("LOG: "));
vprintf (format, args);
// LCD_vClrScr();
// LCD_vPuts_P(PSTR("LOG:"));
// LCD_vGotoXY(0,1);
// LCD_vPrintf_P("%s", message);
va_end (args);
// wdt_reset();
// int_delay_ms(500);
// wdt_reset();
// LCD_vClrScr();
}
#ifdef __GNUC__
void LOG_Reset (const char * message) __attribute__ ((format (printf, 1, 0)));
#endif
void LOG_Reset (const char * message)
{
unsigned char ucCount;
printf_P (PSTR("RESET:\n"));
puts(message);
LCD_LO_vInit();
LCD_LO_vClrScr();
LCD_LO_vPuts_P(PSTR("RESET:"));
LCD_LO_vGotoXY(0,1);
LCD_LO_vPuts (message);
cli(); // TODO
for (ucCount=100 ; ucCount>0 ; ucCount--)
{
wdt_reset();
LCD_BL_ALTER;
_delay_ms(500);
}
for (;;); // real reset
}
#ifdef __GNUC__
void LOG_Reset_P (const char * message) __attribute__ ((format (printf, 1, 0)));
#endif
void LOG_Reset_P (const char * message)
{
unsigned char ucCount;
printf_P (PSTR("RESET:\n"));
puts_P (message);
LCD_LO_vInit();
LCD_LO_vClrScr();
LCD_LO_vPuts_P(PSTR("RESET:"));
LCD_LO_vGotoXY(0,1);
LCD_LO_vPuts_P (message);
cli(); // TODO
for (ucCount=100 ; ucCount>0 ; ucCount--)
{
wdt_reset();
LCD_BL_ALTER;
_delay_ms(500);
}
for (;;); // real reset
}
/**
* Print content of memory block in HEX block
* @param ptr
* @param size
*/
void LOG_vMemDump(void *ptr, UCHAR size)
{
UCHAR ucCol=0;
UCHAR *pucMem = (UCHAR*) ptr;
while (size--)
{
LOG_Log_P(PSTR("%02X "), *pucMem++);
ucCol++;
if (ucCol > 7)
{
ucCol=0;
LOG_NL
}
}
LOG_NL
LOG_NL
}
void LOG_vNL (void)
{
LOG_Log_P(PSTR("\n"));
}