Stefan Schuermans commited on 2012-03-24 19:05:42
Showing 5 changed files, with 22 additions and 58 deletions.
... | ... |
@@ -23,21 +23,3 @@ void cyc_cnt_delay(unsigned int cyc) |
23 | 23 |
/* wait */; |
24 | 24 |
} |
25 | 25 |
|
26 |
-/** |
|
27 |
- * @brief delay for a number of microseconds |
|
28 |
- * @param[in] us number of microseconds |
|
29 |
- */ |
|
30 |
-void cyc_cnt_delay_us(unsigned int us) |
|
31 |
-{ |
|
32 |
- cyc_cnt_delay(us * 50); |
|
33 |
-} |
|
34 |
- |
|
35 |
-/** |
|
36 |
- * @brief delay for a number of milliseconds |
|
37 |
- * @param[in] ms number of milliseconds |
|
38 |
- */ |
|
39 |
-void cyc_cnt_delay_ms(unsigned int ms) |
|
40 |
-{ |
|
41 |
- cyc_cnt_delay_us(ms * 1000); |
|
42 |
-} |
|
43 |
- |
... | ... |
@@ -1,6 +1,9 @@ |
1 | 1 |
#ifndef CYC_CNT_H |
2 | 2 |
#define CYC_CNT_H |
3 | 3 |
|
4 |
+#define CYC_CNT_US (50) ///< cycles per microsecond |
|
5 |
+#define CYC_CNT_MS (50*1000) ///< cycles per millisecond |
|
6 |
+ |
|
4 | 7 |
/** |
5 | 8 |
* @brief read cycle counter |
6 | 9 |
* @return cycle counter value |
... | ... |
@@ -13,17 +16,5 @@ unsigned int cyc_cnt_read(void); |
13 | 16 |
*/ |
14 | 17 |
void cyc_cnt_delay(unsigned int cyc); |
15 | 18 |
|
16 |
-/** |
|
17 |
- * @brief delay for a number of microseconds |
|
18 |
- * @param[in] us number of microseconds |
|
19 |
- */ |
|
20 |
-void cyc_cnt_delay_us(unsigned int us); |
|
21 |
- |
|
22 |
-/** |
|
23 |
- * @brief delay for a number of milliseconds |
|
24 |
- * @param[in] ms number of milliseconds |
|
25 |
- */ |
|
26 |
-void cyc_cnt_delay_ms(unsigned int ms); |
|
27 |
- |
|
28 | 19 |
#endif /* #ifndef CYC_CNT_H */ |
29 | 20 |
|
... | ... |
@@ -47,25 +47,25 @@ void lcd_set4bit(void) |
47 | 47 |
lcd_set_e(0); |
48 | 48 |
lcd_set_rs(0); |
49 | 49 |
lcd_set_rw(0); |
50 |
- cyc_cnt_delay_ms(15); |
|
50 |
+ cyc_cnt_delay(15 * CYC_CNT_MS); |
|
51 | 51 |
lcd_set_data(0x3F); |
52 | 52 |
lcd_set_e(1); |
53 | 53 |
cyc_cnt_delay(12); |
54 | 54 |
lcd_set_e(0); |
55 |
- cyc_cnt_delay_us(4100); |
|
55 |
+ cyc_cnt_delay(4100 * CYC_CNT_US); |
|
56 | 56 |
lcd_set_e(1); |
57 | 57 |
cyc_cnt_delay(12); |
58 | 58 |
lcd_set_e(0); |
59 |
- cyc_cnt_delay_us(100); |
|
59 |
+ cyc_cnt_delay(100 * CYC_CNT_US); |
|
60 | 60 |
lcd_set_e(1); |
61 | 61 |
cyc_cnt_delay(12); |
62 | 62 |
lcd_set_e(0); |
63 |
- cyc_cnt_delay_us(40); |
|
63 |
+ cyc_cnt_delay(40 * CYC_CNT_US); |
|
64 | 64 |
lcd_set_data(0x2F); |
65 | 65 |
lcd_set_e(1); |
66 | 66 |
cyc_cnt_delay(12); |
67 | 67 |
lcd_set_e(0); |
68 |
- cyc_cnt_delay_us(40); |
|
68 |
+ cyc_cnt_delay(40 * CYC_CNT_US); |
|
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
/** |
... | ... |
@@ -82,12 +82,12 @@ void lcd_byte(unsigned char data, unsigned char byte) |
82 | 82 |
lcd_set_e(1); |
83 | 83 |
cyc_cnt_delay(12); |
84 | 84 |
lcd_set_e(0); |
85 |
- cyc_cnt_delay_us(1); |
|
85 |
+ cyc_cnt_delay(1 * CYC_CNT_US); |
|
86 | 86 |
lcd_set_data(byte << 4 | 0x0F); |
87 | 87 |
lcd_set_e(1); |
88 | 88 |
cyc_cnt_delay(12); |
89 | 89 |
lcd_set_e(0); |
90 |
- cyc_cnt_delay_us(40); |
|
90 |
+ cyc_cnt_delay(40 * CYC_CNT_US); |
|
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
/** initialize LCD */ |
... | ... |
@@ -98,7 +98,7 @@ void lcd_init(void) |
98 | 98 |
lcd_byte(0, 0x06); |
99 | 99 |
lcd_byte(0, 0x0C); |
100 | 100 |
lcd_byte(0, 0x01); |
101 |
- cyc_cnt_delay_us(1640); |
|
101 |
+ cyc_cnt_delay(1640 * CYC_CNT_US); |
|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
/** |
... | ... |
@@ -31,17 +31,14 @@ void switches(void) |
31 | 31 |
lcd_chr(1, 15, '0' + (cnt & 0x7)); |
32 | 32 |
} |
33 | 33 |
|
34 |
-void leds_uart(void) |
|
34 |
+void uart(void) |
|
35 | 35 |
{ |
36 | 36 |
unsigned short chr; |
37 | 37 |
|
38 | 38 |
while (uart_can_rx()) { |
39 | 39 |
chr = uart_rx(); |
40 |
- if (uart_is_err(chr)) |
|
41 |
- leds_val = 0; |
|
42 |
- else |
|
43 |
- leds_val = chr; |
|
44 |
- leds_set_state(leds_val); |
|
40 |
+ if (!uart_is_err(chr)) |
|
41 |
+ uart_tx(chr); |
|
45 | 42 |
} |
46 | 43 |
} |
47 | 44 |
|
... | ... |
@@ -49,14 +46,9 @@ void eth_task(void) |
49 | 46 |
{ |
50 | 47 |
void *vptr; |
51 | 48 |
unsigned int sz, i; |
52 |
- unsigned char *ptr; |
|
53 | 49 |
|
54 |
- while (eth_rx(&vptr, &sz)) { |
|
55 |
- ptr = vptr; |
|
56 |
- for (i = 0; i < sz; ++i) |
|
57 |
- uart_tx(ptr[i]); |
|
50 |
+ while (eth_rx(&vptr, &sz)) |
|
58 | 51 |
ethernet_recv(vptr, sz); |
59 |
- } |
|
60 | 52 |
|
61 | 53 |
i = eth_rx_get_cnt(); |
62 | 54 |
lcd_chr(0, 11, '0' + (i >> 3 & 0x7)); |
... | ... |
@@ -69,7 +61,7 @@ void eth_task(void) |
69 | 61 |
void tasks(void) |
70 | 62 |
{ |
71 | 63 |
switches(); |
72 |
- leds_uart(); |
|
64 |
+ uart(); |
|
73 | 65 |
eth_task(); |
74 | 66 |
} |
75 | 67 |
|
... | ... |
@@ -89,7 +81,7 @@ void tick200(void) |
89 | 81 |
|
90 | 82 |
int main() |
91 | 83 |
{ |
92 |
- unsigned int i; |
|
84 |
+ unsigned int start_cyc; |
|
93 | 85 |
|
94 | 86 |
leds_set_state(0x01); |
95 | 87 |
|
... | ... |
@@ -125,10 +117,9 @@ int main() |
125 | 117 |
leds_set_state(0x10); |
126 | 118 |
|
127 | 119 |
while (1) { |
128 |
- for (i = 0; i < 20; ++i) { |
|
120 |
+ start_cyc = cyc_cnt_read(); |
|
121 |
+ while (cyc_cnt_read() - start_cyc < 200 * CYC_CNT_MS) |
|
129 | 122 |
tasks(); |
130 |
- cyc_cnt_delay_ms(10); |
|
131 |
- } |
|
132 | 123 |
tick200(); |
133 | 124 |
} |
134 | 125 |
|
... | ... |
@@ -65,7 +65,7 @@ ARCHITECTURE a_testbed OF e_testbed IS |
65 | 65 |
SIGNAL s_clk: std_logic; |
66 | 66 |
SIGNAL s_leds: std_logic_vector(7 DOWNTO 0); |
67 | 67 |
SIGNAL s_lcd: t_io_lcd_pins; |
68 |
- SIGNAL s_uart_loopback: std_logic; |
|
68 |
+ SIGNAL s_uart: std_logic; |
|
69 | 69 |
SIGNAL s_eth_clk: std_logic; |
70 | 70 |
SIGNAL s_eth_rxd_d: std_logic_vector(3 DOWNTO 0); |
71 | 71 |
SIGNAL s_eth_rxd: std_logic_vector(4 DOWNTO 0); |
... | ... |
@@ -81,8 +81,8 @@ BEGIN |
81 | 81 |
pin_o_leds => s_leds, |
82 | 82 |
pin_o_lcd => s_lcd, |
83 | 83 |
pin_i_switches => (sw => (OTHERS => '0'), OTHERS => '0'), |
84 |
- pin_i_uart_rx => s_uart_loopback, |
|
85 |
- pin_o_uart_tx => s_uart_loopback, |
|
84 |
+ pin_i_uart_rx => '1', |
|
85 |
+ pin_o_uart_tx => s_uart, |
|
86 | 86 |
pin_i_eth_rx_clk => s_eth_clk, |
87 | 87 |
pin_i_eth_rxd => s_eth_rxd, |
88 | 88 |
pin_i_eth_rx_dv => s_eth_rx_dv, |
89 | 89 |