ini
[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         struct error e;      
47
48         e.err_num = num;
49         e.severity = severity;
50 #ifdef ERROR_DUMP_TEXTLOG
51         e.text = t;
52 #else
53         e.text = PSTR("");
54 #endif
55 #ifdef ERROR_DUMP_FILE_LINE
56         e.file = f;
57         e.line = l;
58 #else
59         e.file = PSTR("");
60         e.line = 0;
61 #endif
62         return e;
63 }
64
65
66 /** Register log function for EMERG level */
67 void error_register_emerg(void (*f)(struct error *, ...))
68 {
69         uint8_t flags;
70         IRQ_LOCK(flags);
71         g_error_fct.emerg = f;
72         IRQ_UNLOCK(flags);
73 }
74
75 /** Register log function for ERROR level */
76 void error_register_error(void (*f)(struct error *, ...))
77 {
78         uint8_t flags;
79         IRQ_LOCK(flags);
80         g_error_fct.error = f;
81         IRQ_UNLOCK(flags);
82 }
83
84 /** Register log function for WARNING level */
85 void error_register_warning(void (*f)(struct error *, ...))
86 {
87         uint8_t flags;
88         IRQ_LOCK(flags);
89         g_error_fct.warning = f;
90         IRQ_UNLOCK(flags);
91 }
92
93 /** Register log function for NOTICE level */
94 void error_register_notice(void (*f)(struct error *, ...))
95 {
96         uint8_t flags;
97         IRQ_LOCK(flags);
98         g_error_fct.notice = f;
99         IRQ_UNLOCK(flags);
100 }
101
102 /** Register log function for DEBUG level */
103 void error_register_debug(void (*f)(struct error *, ...))
104 {
105         uint8_t flags;
106         IRQ_LOCK(flags);
107         g_error_fct.debug = f;
108         IRQ_UNLOCK(flags);
109 }
110