Stefan Schuermans commited on 2012-04-05 21:31:40
Showing 6 changed files, with 158 additions and 57 deletions.
... | ... |
@@ -0,0 +1,54 @@ |
1 |
+#include "debug.h" |
|
2 |
+#include "format.h" |
|
3 |
+#include "macros.h" |
|
4 |
+#include "uart.h" |
|
5 |
+ |
|
6 |
+/** |
|
7 |
+ * @brief print a character to debug output |
|
8 |
+ * @param[in] chr character to print |
|
9 |
+ */ |
|
10 |
+void debug_chr(char chr) |
|
11 |
+{ |
|
12 |
+ uart_tx((unsigned char)chr); |
|
13 |
+} |
|
14 |
+ |
|
15 |
+/** |
|
16 |
+ * @brief print a string to debug output |
|
17 |
+ * @param[in] str string to print |
|
18 |
+ */ |
|
19 |
+void debug_str(const char *str) |
|
20 |
+{ |
|
21 |
+ while (*str) |
|
22 |
+ debug_chr(*str++); |
|
23 |
+} |
|
24 |
+ |
|
25 |
+/** |
|
26 |
+ * @brief print an unsigned integer in decimal to debug output |
|
27 |
+ * @param[in] uint unsigned integer value |
|
28 |
+ * @param[in] cnt number of digits |
|
29 |
+ */ |
|
30 |
+void debug_uint_dec(unsigned int uint, unsigned int cnt) |
|
31 |
+{ |
|
32 |
+ char buf[11]; |
|
33 |
+ if (cnt > count(buf) - 1) |
|
34 |
+ cnt = count(buf) - 1; |
|
35 |
+ format_uint2dec(uint, cnt, buf); |
|
36 |
+ buf[cnt] = 0; |
|
37 |
+ debug_str(buf); |
|
38 |
+} |
|
39 |
+ |
|
40 |
+/** |
|
41 |
+ * @brief print an unsigned integer in hexdecimal to debug output |
|
42 |
+ * @param[in] uint unsigned integer value |
|
43 |
+ * @param[in] cnt number of digits |
|
44 |
+ */ |
|
45 |
+void debug_uint_hex(unsigned int uint, unsigned int cnt) |
|
46 |
+{ |
|
47 |
+ char buf[9]; |
|
48 |
+ if (cnt > count(buf) - 1) |
|
49 |
+ cnt = count(buf) - 1; |
|
50 |
+ format_uint2hex(uint, cnt, buf); |
|
51 |
+ buf[cnt] = 0; |
|
52 |
+ debug_str(buf); |
|
53 |
+} |
|
54 |
+ |
... | ... |
@@ -0,0 +1,31 @@ |
1 |
+#ifndef DEBUG_H |
|
2 |
+#define DEBUG_H |
|
3 |
+ |
|
4 |
+/** |
|
5 |
+ * @brief print a character to debug output |
|
6 |
+ * @param[in] chr character to print |
|
7 |
+ */ |
|
8 |
+void debug_chr(char chr); |
|
9 |
+ |
|
10 |
+/** |
|
11 |
+ * @brief print a string to debug output |
|
12 |
+ * @param[in] str string to print |
|
13 |
+ */ |
|
14 |
+void debug_str(const char *str); |
|
15 |
+ |
|
16 |
+/** |
|
17 |
+ * @brief print an unsigned integer in decimal to debug output |
|
18 |
+ * @param[in] uint unsigned integer value |
|
19 |
+ * @param[in] cnt number of digits |
|
20 |
+ */ |
|
21 |
+void debug_uint_dec(unsigned int uint, unsigned int cnt); |
|
22 |
+ |
|
23 |
+/** |
|
24 |
+ * @brief print an unsigned integer in hexdecimal to debug output |
|
25 |
+ * @param[in] uint unsigned integer value |
|
26 |
+ * @param[in] cnt number of digits |
|
27 |
+ */ |
|
28 |
+void debug_uint_hex(unsigned int uint, unsigned int cnt); |
|
29 |
+ |
|
30 |
+#endif /* #ifndef DEBUG_H */ |
|
31 |
+ |
... | ... |
@@ -0,0 +1,35 @@ |
1 |
+#include "format.h" |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * @brief convert unsigned integer to decimal |
|
5 |
+ * @param[in] uint unsigned integer value |
|
6 |
+ * @param[in] cnt number of digits |
|
7 |
+ * @param[out] digits value as decimal digits |
|
8 |
+ */ |
|
9 |
+void format_uint2dec(unsigned int uint, unsigned int cnt, char digits[]) |
|
10 |
+{ |
|
11 |
+ while (cnt > 0) { |
|
12 |
+ --cnt; |
|
13 |
+ digits[cnt] = '0' + uint % 10; |
|
14 |
+ uint /= 10; |
|
15 |
+ } |
|
16 |
+} |
|
17 |
+ |
|
18 |
+/** |
|
19 |
+ * @brief convert unsigned integer to hexadecimal |
|
20 |
+ * @param[in] uint unsigned integer value |
|
21 |
+ * @param[in] cnt number of digits |
|
22 |
+ * @param[out] digits value as decimal hexadigits |
|
23 |
+ */ |
|
24 |
+void format_uint2hex(unsigned int uint, unsigned int cnt, char digits[]) |
|
25 |
+{ |
|
26 |
+ unsigned int val; |
|
27 |
+ |
|
28 |
+ while (cnt > 0) { |
|
29 |
+ --cnt; |
|
30 |
+ val = uint & 15; |
|
31 |
+ digits[cnt] = val < 10 ? '0' + val : 'A' - 10 + val; |
|
32 |
+ uint >>= 4; |
|
33 |
+ } |
|
34 |
+} |
|
35 |
+ |
... | ... |
@@ -0,0 +1,21 @@ |
1 |
+#ifndef FORMAT_H |
|
2 |
+#define FORMAT_H |
|
3 |
+ |
|
4 |
+/** |
|
5 |
+ * @brief convert unsigned integer to decimal |
|
6 |
+ * @param[in] uint unsigned integer value |
|
7 |
+ * @param[in] cnt number of digits |
|
8 |
+ * @param[out] digits value as decimal digits |
|
9 |
+ */ |
|
10 |
+void format_uint2dec(unsigned int uint, unsigned int cnt, char digits[]); |
|
11 |
+ |
|
12 |
+/** |
|
13 |
+ * @brief convert unsigned integer to hexadecimal |
|
14 |
+ * @param[in] uint unsigned integer value |
|
15 |
+ * @param[in] cnt number of digits |
|
16 |
+ * @param[out] digits value as decimal hexadigits |
|
17 |
+ */ |
|
18 |
+void format_uint2hex(unsigned int uint, unsigned int cnt, char digits[]); |
|
19 |
+ |
|
20 |
+#endif // #ifdef FORMAT_H |
|
21 |
+ |
... | ... |
@@ -1,5 +1,6 @@ |
1 | 1 |
#include "arp.h" |
2 | 2 |
#include "cyc_cnt.h" |
3 |
+#include "debug.h" |
|
3 | 4 |
#include "dhcp.h" |
4 | 5 |
#include "eth.h" |
5 | 6 |
#include "ip.h" |
... | ... |
@@ -54,31 +55,22 @@ void tick200(void) |
54 | 55 |
|
55 | 56 |
int main() |
56 | 57 |
{ |
57 |
- unsigned int start_cyc; |
|
58 |
- |
|
59 | 58 |
leds_set_state(0x01); |
60 | 59 |
|
61 |
- menu_init(); |
|
60 |
+ uart_cfg_scale(62); /* 115200 */ |
|
61 |
+ uart_cfg_bits(8); |
|
62 |
+ uart_cfg_stop(1); |
|
63 |
+ debug_str("MIPS I\r\n"); |
|
62 | 64 |
|
63 | 65 |
leds_set_state(0x02); |
64 | 66 |
|
65 |
- eth_mac_init(); |
|
66 |
- eth_rx_init(); |
|
67 |
- eth_tx_init(); |
|
67 |
+ menu_init(); |
|
68 | 68 |
|
69 | 69 |
leds_set_state(0x04); |
70 | 70 |
|
71 |
- uart_cfg_scale(62); /* 115200 */ |
|
72 |
- uart_cfg_bits(8); |
|
73 |
- uart_cfg_stop(1); |
|
74 |
- uart_tx('M'); |
|
75 |
- uart_tx('I'); |
|
76 |
- uart_tx('P'); |
|
77 |
- uart_tx('S'); |
|
78 |
- uart_tx(' '); |
|
79 |
- uart_tx('I'); |
|
80 |
- uart_tx('\r'); |
|
81 |
- uart_tx('\n'); |
|
71 |
+ eth_mac_init(); |
|
72 |
+ eth_rx_init(); |
|
73 |
+ eth_tx_init(); |
|
82 | 74 |
|
83 | 75 |
leds_set_state(0x08); |
84 | 76 |
|
... | ... |
@@ -88,7 +80,7 @@ int main() |
88 | 80 |
leds_set_state(0x10); |
89 | 81 |
|
90 | 82 |
while (1) { |
91 |
- start_cyc = cyc_cnt_read(); |
|
83 |
+ unsigned int start_cyc = cyc_cnt_read(); |
|
92 | 84 |
while (cyc_cnt_read() - start_cyc < 200 * CYC_CNT_MS) |
93 | 85 |
tasks(); |
94 | 86 |
tick200(); |
... | ... |
@@ -1,5 +1,6 @@ |
1 | 1 |
#include "config.h" |
2 | 2 |
#include "eth.h" |
3 |
+#include "format.h" |
|
3 | 4 |
#include "lcd.h" |
4 | 5 |
#include "macros.h" |
5 | 6 |
#include "menu.h" |
... | ... |
@@ -14,39 +15,6 @@ static int menu_cur_screen = 0; |
14 | 15 |
/// current content on screen |
15 | 16 |
static char menu_cur_content[16]; |
16 | 17 |
|
17 |
-/** |
|
18 |
- * @brief convert unsigned integer to decimal |
|
19 |
- * @param[in] uint unsigned integer value |
|
20 |
- * @param[in] cnt number of digits |
|
21 |
- * @param[out] digits value as decimal digits |
|
22 |
- */ |
|
23 |
-void menu_uint2dec(unsigned int uint, unsigned int cnt, char digits[]) |
|
24 |
-{ |
|
25 |
- while (cnt > 0) { |
|
26 |
- --cnt; |
|
27 |
- digits[cnt] = '0' + uint % 10; |
|
28 |
- uint /= 10; |
|
29 |
- } |
|
30 |
-} |
|
31 |
- |
|
32 |
-/** |
|
33 |
- * @brief convert unsigned integer to hexadecimal |
|
34 |
- * @param[in] uint unsigned integer value |
|
35 |
- * @param[in] cnt number of digits |
|
36 |
- * @param[out] digits value as decimal hexadigits |
|
37 |
- */ |
|
38 |
-void menu_uint2hex(unsigned int uint, unsigned int cnt, char digits[]) |
|
39 |
-{ |
|
40 |
- unsigned int val; |
|
41 |
- |
|
42 |
- while (cnt > 0) { |
|
43 |
- --cnt; |
|
44 |
- val = uint & 15; |
|
45 |
- digits[cnt] = val < 10 ? '0' + val : 'A' - 10 + val; |
|
46 |
- uint >>= 4; |
|
47 |
- } |
|
48 |
-} |
|
49 |
- |
|
50 | 18 |
/** |
51 | 19 |
* @brief update screen content |
52 | 20 |
* @param[in] str new content to display |
... | ... |
@@ -103,8 +71,8 @@ static void menu_screen_eth(void) |
103 | 71 |
{ |
104 | 72 |
char buf[] = "RX 0000 TX 0000"; |
105 | 73 |
|
106 |
- menu_uint2dec(eth_rx_get_cnt(), 4, &buf[3]); |
|
107 |
- menu_uint2dec(eth_tx_get_cnt(), 4, &buf[11]); |
|
74 |
+ format_uint2dec(eth_rx_get_cnt(), 4, &buf[3]); |
|
75 |
+ format_uint2dec(eth_tx_get_cnt(), 4, &buf[11]); |
|
108 | 76 |
|
109 | 77 |
menu_update_content(buf); |
110 | 78 |
} |
... | ... |
@@ -116,7 +84,7 @@ static void menu_screen_mac(void) |
116 | 84 |
char buf[] = "000000000000"; |
117 | 85 |
|
118 | 86 |
for (i = 0; i < 6; ++i) |
119 |
- menu_uint2hex(config_mac.mac[i], 2, &buf[i * 2]); |
|
87 |
+ format_uint2hex(config_mac.mac[i], 2, &buf[i * 2]); |
|
120 | 88 |
|
121 | 89 |
menu_update_content(buf); |
122 | 90 |
} |
... | ... |
@@ -128,7 +96,7 @@ static void menu_screen_ip(void) |
128 | 96 |
char buf[] = "000.000.000.000"; |
129 | 97 |
|
130 | 98 |
for (i = 0; i < 4; ++i) |
131 |
- menu_uint2dec(config_ip.ip[i], 3, &buf[i * 4]); |
|
99 |
+ format_uint2dec(config_ip.ip[i], 3, &buf[i * 4]); |
|
132 | 100 |
|
133 | 101 |
menu_update_content(buf); |
134 | 102 |
} |
... | ... |
@@ -140,7 +108,7 @@ static void menu_screen_netmask(void) |
140 | 108 |
char buf[] = "000.000.000.000"; |
141 | 109 |
|
142 | 110 |
for (i = 0; i < 4; ++i) |
143 |
- menu_uint2dec(config_ip.mask[i], 3, &buf[i * 4]); |
|
111 |
+ format_uint2dec(config_ip.mask[i], 3, &buf[i * 4]); |
|
144 | 112 |
|
145 | 113 |
menu_update_content(buf); |
146 | 114 |
} |
... | ... |
@@ -152,7 +120,7 @@ static void menu_screen_gateway(void) |
152 | 120 |
char buf[] = "000.000.000.000"; |
153 | 121 |
|
154 | 122 |
for (i = 0; i < 4; ++i) |
155 |
- menu_uint2dec(config_ip.gw[i], 3, &buf[i * 4]); |
|
123 |
+ format_uint2dec(config_ip.gw[i], 3, &buf[i * 4]); |
|
156 | 124 |
|
157 | 125 |
menu_update_content(buf); |
158 | 126 |
} |
159 | 127 |