Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2136 | - | 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 | * Error handling functions |
||
28 | */ |
||
29 | |||
30 | //############################################################################ |
||
31 | //# HISTORY error.c |
||
32 | //# |
||
33 | //# 16.04.2013 Cebra |
||
34 | //# - chg: PROGMEM angepasst auf neue avr-libc und GCC, prog_char depreciated |
||
35 | //# |
||
36 | //########################################################################## |
||
37 | |||
38 | |||
39 | |||
40 | #include <stdbool.h> |
||
41 | #include <avr/pgmspace.h> |
||
42 | #include "error_driver.h" |
||
43 | #include "../main.h" |
||
44 | #ifdef DEBUG |
||
45 | //-------------------------------------------------------------- |
||
46 | inline void _send_msg(const char *msg) |
||
47 | { |
||
48 | for (uint8_t i=0; i<255 && msg[i]!='\0'; i++) |
||
49 | { |
||
50 | errordriver_write_c(msg[i]); |
||
51 | } |
||
52 | errordriver_write_c('\n'); |
||
53 | } |
||
54 | |||
55 | |||
56 | //-------------------------------------------------------------- |
||
57 | void send_pgm(const char *msg) |
||
58 | { |
||
59 | uint8_t myByte; |
||
60 | myByte = pgm_read_byte(msg); |
||
61 | for(int i = 1; myByte != '\0'; i++) |
||
62 | { |
||
63 | errordriver_write_c(myByte); |
||
64 | myByte = pgm_read_byte(msg+i); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | |||
69 | |||
70 | |||
71 | //-------------------------------------------------------------- |
||
72 | void error_init(void) |
||
73 | { |
||
74 | error_driver_Init(); |
||
75 | } |
||
76 | |||
77 | |||
78 | //-------------------------------------------------------------- |
||
79 | void error_putc(const char c) |
||
80 | { |
||
81 | errordriver_write_c(c); |
||
82 | } |
||
83 | |||
84 | |||
85 | //-------------------------------------------------------------- |
||
86 | void assert (bool condition, const char *msg) |
||
87 | { |
||
88 | if (!condition) |
||
89 | { |
||
90 | send_pgm(PSTR("ASS:")); |
||
91 | _send_msg(msg); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | |||
96 | //-------------------------------------------------------------- |
||
97 | void info (const char *msg) |
||
98 | { |
||
99 | send_pgm(PSTR("INF:")); |
||
100 | _send_msg(msg); |
||
101 | } |
||
102 | |||
103 | |||
104 | //-------------------------------------------------------------- |
||
105 | void warn (const char *msg) |
||
106 | { |
||
107 | send_pgm(PSTR("WARN:")); |
||
108 | _send_msg(msg); |
||
109 | } |
||
110 | |||
111 | |||
112 | //-------------------------------------------------------------- |
||
113 | void debug (const char *msg) |
||
114 | { |
||
115 | send_pgm(PSTR("DBG:")); |
||
116 | _send_msg(msg); |
||
117 | } |
||
118 | |||
119 | |||
120 | //-------------------------------------------------------------- |
||
121 | void Error (const char *msg) |
||
122 | { |
||
123 | send_pgm(PSTR("ERR:")); |
||
124 | _send_msg(msg); |
||
125 | } |
||
126 | #endif |
||
127 | |||
128 | #ifdef DEBUG |
||
129 | |||
130 | //-------------------------------------------------------------- |
||
131 | void assert_pgm(bool condition, const prog_char *msg) |
||
132 | { |
||
133 | if (condition) { |
||
134 | send_pgm(PSTR("ASS:")); |
||
135 | send_pgm(msg); |
||
136 | errordriver_write_c('\n'); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | |||
141 | //-------------------------------------------------------------- |
||
142 | void info_pgm(const prog_char *msg) |
||
143 | { |
||
144 | send_pgm(PSTR("INF:")); |
||
145 | send_pgm(msg); |
||
146 | errordriver_write_c('\n'); |
||
147 | } |
||
148 | |||
149 | |||
150 | //-------------------------------------------------------------- |
||
151 | void warn_pgm(const prog_char *msg) |
||
152 | { |
||
153 | send_pgm(PSTR("WARN:")); |
||
154 | send_pgm(msg); |
||
155 | errordriver_write_c('\n'); |
||
156 | errordriver_write_c('\r'); |
||
157 | } |
||
158 | |||
159 | |||
160 | //-------------------------------------------------------------- |
||
161 | void error_pgm(const prog_char *msg) |
||
162 | { |
||
163 | send_pgm(PSTR("ERR:")); |
||
164 | send_pgm(msg); |
||
165 | errordriver_write_c('\n'); |
||
166 | errordriver_write_c('\r'); |
||
167 | } |
||
168 | |||
169 | |||
170 | //-------------------------------------------------------------- |
||
171 | void debug_pgm(const prog_char *msg) |
||
172 | { |
||
173 | send_pgm(PSTR("DBG:")); |
||
174 | send_pgm(msg); |
||
175 | errordriver_write_c('\n'); |
||
176 | errordriver_write_c('\r'); |
||
177 | } |
||
178 | |||
179 | |||
180 | ////-------------------------------------------------------------- |
||
181 | //void print_hex(uint8_t num) |
||
182 | //{ |
||
183 | // if (num<10) |
||
184 | // error_putc(num+48); |
||
185 | // else |
||
186 | // { |
||
187 | // switch (num) |
||
188 | // { |
||
189 | // case 10: |
||
190 | // error_putc('A'); break; |
||
191 | // case 11: |
||
192 | // error_putc('B'); break; |
||
193 | // case 12: |
||
194 | // error_putc('C'); break; |
||
195 | // case 13: |
||
196 | // error_putc('D'); break; |
||
197 | // case 14: |
||
198 | // error_putc('E'); break; |
||
199 | // case 15: |
||
200 | // error_putc('F'); break; |
||
201 | // default: |
||
202 | // error_putc('#'); break; |
||
203 | // } |
||
204 | // } |
||
205 | //} |
||
206 | // |
||
207 | // |
||
208 | ////-------------------------------------------------------------- |
||
209 | //void byte_to_hex(uint8_t byte) |
||
210 | //{ |
||
211 | // uint8_t b2 = (byte & 0x0F); |
||
212 | // uint8_t b1 = ((byte & 0xF0)>>4); |
||
213 | // print_hex(b1); |
||
214 | // print_hex(b2); |
||
215 | //} |
||
216 | |||
217 | #endif |
||
218 |