comparison services/ffs/ffstrace.c @ 0:75a11d740a02

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