[3d6669cc] | 1 | #include <rtems.h> |
---|
| 2 | #include <sys/mbuf.h> |
---|
| 3 | #include <irq.h> |
---|
| 4 | #include <libchip/cs8900.h> |
---|
| 5 | |
---|
| 6 | #define CS8900_BASE 0x20000300 |
---|
| 7 | unsigned int bsp_cs8900_io_base = 0; |
---|
| 8 | unsigned int bsp_cs8900_memory_base = 0; |
---|
| 9 | cs8900_device *g_cs; |
---|
| 10 | rtems_irq_hdl cs8900_isr(rtems_vector_number v); |
---|
| 11 | rtems_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 | |
---|
| 19 | char g_enetbuf[1520]; |
---|
| 20 | |
---|
[aff9de8] | 21 | rtems_isr cs8900_isr(rtems_vector_number v) |
---|
[3d6669cc] | 22 | { |
---|
| 23 | cs8900_interrupt(v, g_cs); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | /* cs8900_io_set_reg - set one of the I/O addressed registers */ |
---|
| 27 | void cs8900_io_set_reg (int dev, 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 */ |
---|
| 39 | unsigned short cs8900_io_get_reg (int dev, 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 | */ |
---|
| 53 | void cs8900_mem_set_reg (int dev, unsigned long reg, unsigned short data) |
---|
| 54 | { |
---|
| 55 | /* works the same for all values of dev */ |
---|
| 56 | cs8900_io_set_reg(dev, CS8900_IO_PACKET_PAGE_PTR, reg); |
---|
| 57 | cs8900_io_set_reg(dev, CS8900_IO_PP_DATA_PORT0, data); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /* cs8900_mem_get_reg - reads one of the registers mapped through |
---|
| 61 | * PacketPage |
---|
| 62 | */ |
---|
| 63 | unsigned short cs8900_mem_get_reg (int dev, unsigned long reg) |
---|
| 64 | { |
---|
| 65 | /* works the same for all values of dev */ |
---|
| 66 | cs8900_io_set_reg(dev, CS8900_IO_PACKET_PAGE_PTR, reg); |
---|
| 67 | return cs8900_io_get_reg(dev, CS8900_IO_PP_DATA_PORT0); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void cs8900_get_mac_addr (int dev, unsigned char *mac_address) |
---|
| 71 | { |
---|
| 72 | mac_address[0] = 0x08; |
---|
| 73 | mac_address[1] = 0x00; |
---|
| 74 | mac_address[2] = 0x3e; |
---|
| 75 | mac_address[3] = 0x21; |
---|
| 76 | mac_address[4] = 0xc7; |
---|
| 77 | mac_address[5] = 0xf7; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | void cs8900_attach_interrupt (int dev, cs8900_device *cs) |
---|
| 81 | { |
---|
| 82 | g_cs = cs; |
---|
| 83 | BSP_install_rtems_irq_handler(&cs8900_isr_data); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void cs8900_detach_interrupt (int dev) |
---|
| 87 | { |
---|
| 88 | BSP_remove_rtems_irq_handler(&cs8900_isr_data); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | unsigned short cs8900_get_data_block (int dev, unsigned char *data) |
---|
| 92 | { |
---|
| 93 | int len; |
---|
| 94 | int i; |
---|
| 95 | |
---|
| 96 | len = cs8900_mem_get_reg(dev, CS8900_PP_RxLength); |
---|
| 97 | |
---|
| 98 | for (i = 0; i < ((len + 1) / 2); i++) { |
---|
| 99 | ((short *)data)[i] = cs8900_io_get_reg(dev, |
---|
| 100 | CS8900_IO_RX_TX_DATA_PORT0); |
---|
| 101 | } |
---|
| 102 | return len; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void cs8900_tx_load (int dev, struct mbuf *m) |
---|
| 106 | { |
---|
| 107 | int len; |
---|
| 108 | short *data; |
---|
| 109 | int i; |
---|
| 110 | |
---|
| 111 | len = 0; |
---|
| 112 | |
---|
| 113 | do { |
---|
| 114 | memcpy(&g_enetbuf[len], mtod(m, const void *), m->m_len); |
---|
| 115 | len += m->m_len; |
---|
| 116 | m = m->m_next; |
---|
| 117 | } while (m != 0); |
---|
| 118 | |
---|
| 119 | data = (unsigned short *) &g_enetbuf[0]; |
---|
| 120 | for (i = 0; i < ((len + 1) / 2); i++) { |
---|
| 121 | cs8900_io_set_reg(dev, |
---|
| 122 | CS8900_IO_RX_TX_DATA_PORT0, |
---|
| 123 | data[i]); |
---|
| 124 | } |
---|
| 125 | } |
---|