error: fix compilation
[aversive.git] / modules / debug / error / error.c
1 /*
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: error.c,v 1.10.4.3 2007-12-31 16:25:00 zer0 Exp $
19  *
20  */
21
22
23 #include <string.h>
24
25 #ifndef HOST_VERSION
26 #include <avr/io.h>
27 #endif
28
29 #include <aversive.h>
30 #include <aversive/error.h>
31
32 struct error_fct g_error_fct;
33
34 /** All fcts pointers to NULL */
35 void error_init(void)
36 {
37         uint8_t flags;
38         IRQ_LOCK(flags);
39         memset(&g_error_fct, 0, sizeof(g_error_fct));
40         IRQ_UNLOCK(flags);
41 }
42
43
44 struct error error_generate(uint8_t num, uint8_t severity, PGM_P t,
45                             PGM_P f, uint16_t l)
46 {
47         struct error e;
48
49         (void)f;
50         (void)l;
51
52         e.err_num = num;
53         e.severity = severity;
54 #ifdef ERROR_DUMP_TEXTLOG
55         e.text = t;
56 #else
57         e.text = PSTR("");
58 #endif
59 #ifdef ERROR_DUMP_FILE_LINE
60         e.file = f;
61         e.line = l;
62 #else
63         e.file = PSTR("");
64         e.line = 0;
65 #endif
66         return e;
67 }
68
69
70 /** Register log function for EMERG level */
71 void error_register_emerg(void (*f)(struct error *, ...))
72 {
73         uint8_t flags;
74         IRQ_LOCK(flags);
75         g_error_fct.emerg = f;
76         IRQ_UNLOCK(flags);
77 }
78
79 /** Register log function for ERROR level */
80 void error_register_error(void (*f)(struct error *, ...))
81 {
82         uint8_t flags;
83         IRQ_LOCK(flags);
84         g_error_fct.error = f;
85         IRQ_UNLOCK(flags);
86 }
87
88 /** Register log function for WARNING level */
89 void error_register_warning(void (*f)(struct error *, ...))
90 {
91         uint8_t flags;
92         IRQ_LOCK(flags);
93         g_error_fct.warning = f;
94         IRQ_UNLOCK(flags);
95 }
96
97 /** Register log function for NOTICE level */
98 void error_register_notice(void (*f)(struct error *, ...))
99 {
100         uint8_t flags;
101         IRQ_LOCK(flags);
102         g_error_fct.notice = f;
103         IRQ_UNLOCK(flags);
104 }
105
106 /** Register log function for DEBUG level */
107 void error_register_debug(void (*f)(struct error *, ...))
108 {
109         uint8_t flags;
110         IRQ_LOCK(flags);
111         g_error_fct.debug = f;
112         IRQ_UNLOCK(flags);
113 }
114