Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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