FreeCalypso > hg > fc-magnetite
comparison src/cs/drivers/drv_app/ffs/board/ffstrace.c @ 0:945cf7f506b2
src/cs: chipsetsw import from tcs211-fcmodem
binary blobs and LCD demo files have been excluded,
all line endings are LF only
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 25 Sep 2016 22:50:11 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:945cf7f506b2 |
---|---|
1 /****************************************************************************** | |
2 * Flash File System (ffs) | |
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com | |
4 * | |
5 * ffs deprecated testing | |
6 * | |
7 * $Id: ffstrace.c 1.32.1.10 Thu, 18 Dec 2003 10:50:52 +0100 tsj $ | |
8 * | |
9 ******************************************************************************/ | |
10 | |
11 #ifndef TARGET | |
12 #include "ffs.cfg" | |
13 #endif | |
14 | |
15 #include "ffs/ffs.h" | |
16 #include "ffs/board/drv.h" | |
17 #include "ffs/board/ffstrace.h" | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <stdarg.h> | |
22 #include <string.h> | |
23 | |
24 /****************************************************************************** | |
25 * LED control | |
26 *****************************************************************************/ | |
27 | |
28 #if (TARGET == 1) | |
29 | |
30 #include "rvf/rvf_api.h" | |
31 #include "rv/rv_general.h" | |
32 #include "rvm/rvm_use_id_list.h" | |
33 | |
34 static uint8 led_state = 0; | |
35 static uint8 led_countbits = 0; // number of counter bits | |
36 static uint8 led_mask = 0x0; // mask containing the counter bits | |
37 | |
38 // configure the number of counter bits in the leds | |
39 void led_config(unsigned char n) | |
40 { | |
41 led_countbits = (n <= 8 ? n : 0); | |
42 led_mask = (n <= 8 ? (1 << n) - 1 : 0); | |
43 } | |
44 | |
45 // just set the bits, no checking whatsoever | |
46 void led_set(unsigned char n) | |
47 { | |
48 *(char *) 0x2800000 = led_state = n; | |
49 } | |
50 | |
51 void led_counter(unsigned char n) | |
52 { | |
53 *(char *) 0x2800000 = led_state = led_state & ~led_mask | (n & led_mask); | |
54 } | |
55 | |
56 void led_on(unsigned char n) | |
57 { | |
58 *(char *) 0x2800000 = led_state = led_state | (1 << (led_countbits + n)); | |
59 } | |
60 | |
61 void led_off(unsigned char n) | |
62 { | |
63 *(char *) 0x2800000 = led_state = led_state & ~(1 << (led_countbits + n)); | |
64 } | |
65 // FIXME | |
66 void led_toggle(unsigned char n) | |
67 { | |
68 *(char *) 0x2700000 = led_state = led_state ^ (1 << (led_countbits + n)); | |
69 } | |
70 #endif | |
71 | |
72 | |
73 /****************************************************************************** | |
74 * Target Tracing | |
75 *****************************************************************************/ | |
76 | |
77 #if (TARGET == 1) | |
78 | |
79 static unsigned int ttr_mask = TTrFatal | TTrTest; | |
80 | |
81 void ttr_init(unsigned int mask) | |
82 { | |
83 ttr_mask = mask | TTrFatal | TTrTest; | |
84 } | |
85 | |
86 void ttr(unsigned int mask, char *format, ...) | |
87 { | |
88 va_list args; | |
89 static char buf[256]; | |
90 | |
91 if (ttr_mask & mask) | |
92 { | |
93 // build string ala tr() then call str() | |
94 va_start(args, format); | |
95 vsprintf(buf, format, args); | |
96 str(mask, buf); | |
97 va_end(args); | |
98 } | |
99 } | |
100 | |
101 void str(unsigned mask, char *string) | |
102 { | |
103 if (ttr_mask & mask) { | |
104 rvf_send_trace(string, strlen(string), NULL_PARAM, | |
105 RV_TRACE_LEVEL_WARNING, FFS_USE_ID); | |
106 rvf_delay(5); | |
107 } | |
108 } | |
109 | |
110 | |
111 /****************************************************************************** | |
112 ** PC side Tracing and logging | |
113 *****************************************************************************/ | |
114 | |
115 #else // (TARGET == 0) | |
116 | |
117 static int tr_mask; // bitmask of which modules to trace | |
118 | |
119 static int tr_spaces; // number of spaces to indent per level | |
120 static FILE *tr_fd; // unused; file descriptor of file to write traces to | |
121 | |
122 | |
123 void tr_init(unsigned int mask, int spaces, char *filename) | |
124 { | |
125 tr_mask = mask; | |
126 tr_spaces = spaces; | |
127 | |
128 if (filename == NULL) { | |
129 tr_fd = stdout; | |
130 } | |
131 else { | |
132 if ( !(tr_fd = fopen(filename, "a+b")) ) { | |
133 fprintf(stderr, "failed to open logfile: %s for append\n", filename); | |
134 exit(1); | |
135 } | |
136 } | |
137 } | |
138 | |
139 // Trace/Log the printf-like string if abs(level) > tr_level. If level is | |
140 // negative, the sematics are the same except that no indentation will occur | |
141 void tr(int type, unsigned int mask, char *format, ...) | |
142 { | |
143 va_list args; | |
144 int indent; | |
145 static int indent_level = 0; | |
146 static char buf[1024]; | |
147 const char spaces[] = | |
148 " " | |
149 " " | |
150 " " | |
151 " "; | |
152 | |
153 if ((mask & tr_mask) == 0) | |
154 return; | |
155 | |
156 // If tracing/debugging trace system | |
157 if ((tr_mask & TrTrace) && (type & TR_END)) | |
158 fprintf(tr_fd, "END(%d)\n", indent_level); | |
159 | |
160 if (type & TR_END) | |
161 indent_level--; | |
162 | |
163 indent = (type & TR_NULL ? 0 : indent_level); | |
164 | |
165 if (strlen(format) > 0) | |
166 { | |
167 va_start(args, format); | |
168 vsprintf(buf, format, args); | |
169 | |
170 indent = tr_spaces * indent; | |
171 if (indent < 0) { | |
172 fprintf(tr_fd, "WARNING: tr() indenting too left (%d)\n", | |
173 indent_level); | |
174 indent = 0; | |
175 } | |
176 if (indent > sizeof(spaces) - 1) { | |
177 fprintf(tr_fd, "WARNING: tr() indenting too right (%d)\n", | |
178 indent_level); | |
179 indent = sizeof(spaces) - 1; | |
180 } | |
181 fprintf(tr_fd, "%s%s", &spaces[sizeof(spaces) - 1 - indent], buf); | |
182 fflush(tr_fd); | |
183 } | |
184 if (type & TR_BEGIN) | |
185 indent_level++; | |
186 | |
187 // If tracing/debugging trace system | |
188 if ((tr_mask & TrTrace) && (type & TR_BEGIN)) | |
189 fprintf(tr_fd, "BEGIN(%d)\n", indent_level); | |
190 } | |
191 | |
192 #endif // (TARGET == 0) | |
193 | |
194 | |
195 /****************************************************************************** | |
196 ** Common Tracing and logging | |
197 *****************************************************************************/ | |
198 | |
199 int tr_query(int mask) | |
200 { | |
201 #if (TARGET == 1) | |
202 return (ttr_mask & mask); | |
203 #else | |
204 return (tr_mask & mask); | |
205 #endif | |
206 } |