source: rtems/c/src/lib/libbsp/arm/edb7312/network/network.c @ 92b0eba

4.104.114.84.95
Last change on this file since 92b0eba was 92b0eba, checked in by Joel Sherrill <joel.sherrill@…>, on 06/22/07 at 14:08:24

2007-06-22 Joel Sherrill <joel.sherrill@…>

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