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

4.104.11
Last change on this file since c193baad was c193baad, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Apr 9, 2010 at 8:24:57 PM

unify irq data types and code, merge s3c2400/s3c2410 support

  • Property mode set to 100644
File size: 3.1 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;
11void cs8900_isr(rtems_irq_hdl_param unused);
12rtems_irq_connect_data cs8900_isr_data = {LPC22xx_INTERRUPT_EINT2,
13                                         (rtems_irq_hdl)cs8900_isr,
14                                          NULL,
15                                          NULL,
16                                          NULL,
17                                          NULL};
18
19char g_enetbuf[1520];
20
21void cs8900_isr(rtems_irq_hdl_param unused)
22{
23    cs8900_interrupt(LPC22xx_INTERRUPT_EINT2, 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.