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