source: rtems/c/src/lib/libbsp/arm/rtl22xx/network/network.c @ f4392b88

4.104.114.84.95
Last change on this file since f4392b88 was f4392b88, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 25, 2007 at 12:50:25 PM

2007-04-25 Ray Xu <xr@…>

  • Makefile.am, README, bsp_specs, configure.ac, console/lpc22xx_uart.h, console/uart.c, include/bsp.h, network/network.c: New (Initial submission).
  • Property mode set to 100644
File size: 3.4 KB
Line 
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
8unsigned int bsp_cs8900_io_base = 0;
9unsigned int bsp_cs8900_memory_base = 0;
10cs8900_device *g_cs;
11rtems_isr cs8900_isr(rtems_vector_number v);
12rtems_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
20char g_enetbuf[1520];
21
22rtems_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 */
28void 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 */
40unsigned 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 */
54void 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 */
64unsigned 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
71void cs8900_get_mac_addr (cs8900_device *cs, unsigned char *mac_address)
72{
73    mac_address[0] = 0x08;
74    mac_address[1] = 0x00;
75    mac_address[2] = 0x3e;
76    mac_address[3] = 0x21;
77    mac_address[4] = 0xc7;
78    mac_address[5] = 0xf7;
79}
80
81void cs8900_attach_interrupt (cs8900_device *cs)
82{
83    g_cs = cs;
84    BSP_install_rtems_irq_handler(&cs8900_isr_data);
85}
86
87void cs8900_detach_interrupt (cs8900_device *cs)
88{
89    BSP_remove_rtems_irq_handler(&cs8900_isr_data);
90}
91
92unsigned 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
106void 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}
Note: See TracBrowser for help on using the repository browser.