1 | /*Note: this file is copy from 7312 BSP, and untested yet*/ |
---|
2 | |
---|
3 | #define __INSIDE_RTEMS_BSD_TCPIP_STACK__ |
---|
4 | |
---|
5 | #include <rtems.h> |
---|
6 | #include <sys/param.h> |
---|
7 | #include <sys/mbuf.h> |
---|
8 | #include <bsp/irq.h> |
---|
9 | #include <libchip/cs8900.h> |
---|
10 | #include <assert.h> |
---|
11 | |
---|
12 | #define CS8900_BASE 0x20000300 |
---|
13 | unsigned int bsp_cs8900_io_base = 0; |
---|
14 | unsigned int bsp_cs8900_memory_base = 0; |
---|
15 | static void cs8900_isr(void *); |
---|
16 | |
---|
17 | char g_enetbuf[1520]; |
---|
18 | |
---|
19 | static void cs8900_isr(void *arg) |
---|
20 | { |
---|
21 | cs8900_interrupt(LPC22xx_INTERRUPT_EINT2, arg); |
---|
22 | } |
---|
23 | |
---|
24 | /* cs8900_io_set_reg - set one of the I/O addressed registers */ |
---|
25 | void cs8900_io_set_reg (cs8900_device *cs, unsigned short reg, unsigned short data) |
---|
26 | { |
---|
27 | /* works the same for all values of dev */ |
---|
28 | /* |
---|
29 | printf("cs8900_io_set_reg: reg: %#6x, val %#6x\n", |
---|
30 | CS8900_BASE + reg, |
---|
31 | data); |
---|
32 | */ |
---|
33 | *(unsigned short *)(CS8900_BASE + reg) = data; |
---|
34 | } |
---|
35 | |
---|
36 | /* cs8900_io_get_reg - reads one of the I/O addressed registers */ |
---|
37 | unsigned short cs8900_io_get_reg (cs8900_device *cs, unsigned short reg) |
---|
38 | { |
---|
39 | unsigned short val; |
---|
40 | /* works the same for all values of dev */ |
---|
41 | val = *(unsigned short *)(CS8900_BASE + reg); |
---|
42 | /* |
---|
43 | printf("cs8900_io_get_reg: reg: %#6x, val %#6x\n", reg, val); |
---|
44 | */ |
---|
45 | return val; |
---|
46 | } |
---|
47 | |
---|
48 | /* cs8900_mem_set_reg - sets one of the registers mapped through |
---|
49 | * PacketPage |
---|
50 | */ |
---|
51 | void cs8900_mem_set_reg (cs8900_device *cs, unsigned long reg, unsigned short data) |
---|
52 | { |
---|
53 | /* works the same for all values of dev */ |
---|
54 | cs8900_io_set_reg(cs, CS8900_IO_PACKET_PAGE_PTR, reg); |
---|
55 | cs8900_io_set_reg(cs, CS8900_IO_PP_DATA_PORT0, data); |
---|
56 | } |
---|
57 | |
---|
58 | /* cs8900_mem_get_reg - reads one of the registers mapped through |
---|
59 | * PacketPage |
---|
60 | */ |
---|
61 | unsigned short cs8900_mem_get_reg (cs8900_device *cs, unsigned long reg) |
---|
62 | { |
---|
63 | /* works the same for all values of dev */ |
---|
64 | cs8900_io_set_reg(cs, CS8900_IO_PACKET_PAGE_PTR, reg); |
---|
65 | return cs8900_io_get_reg(cs, CS8900_IO_PP_DATA_PORT0); |
---|
66 | } |
---|
67 | |
---|
68 | void cs8900_attach_interrupt (cs8900_device *cs) |
---|
69 | { |
---|
70 | rtems_status_code status = RTEMS_SUCCESSFUL; |
---|
71 | status = rtems_interrupt_handler_install( |
---|
72 | LPC22xx_INTERRUPT_EINT2, |
---|
73 | "Network", |
---|
74 | RTEMS_INTERRUPT_UNIQUE, |
---|
75 | cs8900_isr, |
---|
76 | cs |
---|
77 | ); |
---|
78 | assert(status == RTEMS_SUCCESSFUL); |
---|
79 | } |
---|
80 | |
---|
81 | void cs8900_detach_interrupt (cs8900_device *cs) |
---|
82 | { |
---|
83 | rtems_status_code status = RTEMS_SUCCESSFUL; |
---|
84 | status = rtems_interrupt_handler_remove( |
---|
85 | LPC22xx_INTERRUPT_EINT2, |
---|
86 | cs8900_isr, |
---|
87 | cs |
---|
88 | ); |
---|
89 | assert(status == RTEMS_SUCCESSFUL); |
---|
90 | } |
---|
91 | |
---|
92 | unsigned short cs8900_get_data_block (cs8900_device *cs, unsigned char *data) |
---|
93 | { |
---|
94 | int len; |
---|
95 | int i; |
---|
96 | |
---|
97 | len = cs8900_mem_get_reg(cs, CS8900_PP_RxLength); |
---|
98 | |
---|
99 | for (i = 0; i < ((len + 1) / 2); i++) { |
---|
100 | ((short *)data)[i] = cs8900_io_get_reg(cs, |
---|
101 | CS8900_IO_RX_TX_DATA_PORT0); |
---|
102 | } |
---|
103 | return len; |
---|
104 | } |
---|
105 | |
---|
106 | void cs8900_tx_load (cs8900_device *cs, struct mbuf *m) |
---|
107 | { |
---|
108 | int len; |
---|
109 | unsigned short *data; |
---|
110 | int i; |
---|
111 | |
---|
112 | len = 0; |
---|
113 | |
---|
114 | do { |
---|
115 | memcpy(&g_enetbuf[len], mtod(m, const void *), m->m_len); |
---|
116 | len += m->m_len; |
---|
117 | m = m->m_next; |
---|
118 | } while (m != 0); |
---|
119 | |
---|
120 | data = (unsigned short *) &g_enetbuf[0]; |
---|
121 | for (i = 0; i < ((len + 1) / 2); i++) { |
---|
122 | cs8900_io_set_reg(cs, |
---|
123 | CS8900_IO_RX_TX_DATA_PORT0, |
---|
124 | data[i]); |
---|
125 | } |
---|
126 | } |
---|