adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2003, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by Adam Dunkels. |
| 16 | * 4. The name of the author may not be used to endorse or promote |
| 17 | * products derived from this software without specific prior |
| 18 | * written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 26 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | * This file is part of the uIP TCP/IP stack. |
| 33 | * |
| 34 | * $Id: rtl8019as-drv.c,v 1.1 2003/07/04 10:54:52 adamdunkels Exp $ |
| 35 | * |
| 36 | */ |
| 37 | |
| 38 | |
| 39 | /* uip_main.c: initialization code and main event loop. */ |
| 40 | |
| 41 | #define NULL (void *)0 |
| 42 | |
| 43 | |
| 44 | |
| 45 | #include "uip.h" |
| 46 | #include "uip_arp.h" |
| 47 | #include "uip-signal.h" |
| 48 | #include "loader.h" |
| 49 | #include "rtl8019dev.h" |
| 50 | |
| 51 | #include "dispatcher.h" |
| 52 | #include "ek.h" |
| 53 | |
| 54 | #include "debug.h" |
| 55 | |
| 56 | #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) |
| 57 | |
| 58 | static u8_t i, arptimer; |
| 59 | static u16_t start, current; |
| 60 | |
| 61 | static void rtl8019_drv_idle(void); |
| 62 | static DISPATCHER_SIGHANDLER(rtl8019_drv_sighandler, s, data); |
| 63 | static struct dispatcher_proc p = |
| 64 | {DISPATCHER_PROC("TCP/IP/RTL8019 driver", rtl8019_drv_idle, |
| 65 | rtl8019_drv_sighandler, NULL)}; |
| 66 | ek_id_t id = EK_ID_NONE; |
| 67 | |
| 68 | |
| 69 | /*-----------------------------------------------------------------------------------*/ |
| 70 | static void |
| 71 | timer(void) |
| 72 | { |
| 73 | for(i = 0; i < UIP_CONNS; ++i) { |
| 74 | uip_periodic(i); |
| 75 | if(uip_len > 0) { |
| 76 | uip_arp_out(); |
| 77 | rtl8019as_send(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
| 82 | uip_udp_periodic(i); |
| 83 | /* If the above function invocation resulted in data that |
| 84 | should be sent out on the network, the global variable |
| 85 | uip_len is set to a value > 0. */ |
| 86 | if(uip_len > 0) { |
| 87 | uip_arp_out(); |
| 88 | rtl8019as_send(); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | /*-----------------------------------------------------------------------------------*/ |
| 93 | static void |
| 94 | rtl8019_drv_idle(void) |
| 95 | { |
| 96 | /* Poll Ethernet device to see if there is a frame avaliable. */ |
| 97 | uip_len = rtl8019as_poll(); |
| 98 | if(uip_len > 0) { |
| 99 | /* A frame was avaliable (and is now read into the uip_buf), so |
| 100 | we process it. */ |
| 101 | if(BUF->type == htons(UIP_ETHTYPE_IP)) { |
| 102 | /* debug_print16(uip_len);*/ |
| 103 | uip_arp_ipin(); |
| 104 | uip_len -= sizeof(struct uip_eth_hdr); |
| 105 | uip_input(); |
| 106 | /* If the above function invocation resulted in data that |
| 107 | should be sent out on the network, the global variable |
| 108 | uip_len is set to a value > 0. */ |
| 109 | if(uip_len > 0) { |
| 110 | /* debug_print(PSTR("Sending packet\n"));*/ |
| 111 | uip_arp_out(); |
| 112 | rtl8019as_send(); |
| 113 | } |
| 114 | } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { |
| 115 | uip_arp_arpin(); |
| 116 | /* If the above function invocation resulted in data that |
| 117 | should be sent out on the network, the global variable |
| 118 | uip_len is set to a value > 0. */ |
| 119 | if(uip_len > 0) { |
| 120 | rtl8019as_send(); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | /* Check the clock so see if we should call the periodic uIP |
| 125 | processing. */ |
| 126 | current = ek_clock(); |
| 127 | |
| 128 | if((current - start) >= CLK_TCK/2 || |
| 129 | (current - start) < 0) { |
| 130 | timer(); |
| 131 | start = current; |
| 132 | } |
| 133 | } |
| 134 | /*-----------------------------------------------------------------------------------*/ |
| 135 | LOADER_INIT_FUNC(rtl8019_drv_init) |
| 136 | { |
| 137 | if(id == EK_ID_NONE) { |
| 138 | id = dispatcher_start(&p); |
| 139 | |
| 140 | arptimer = 0; |
| 141 | start = ek_clock(); |
| 142 | |
| 143 | rtl8019as_init(); |
| 144 | |
| 145 | dispatcher_listen(uip_signal_uninstall); |
| 146 | } |
| 147 | } |
| 148 | /*-----------------------------------------------------------------------------------*/ |
| 149 | static |
| 150 | DISPATCHER_SIGHANDLER(rtl8019_drv_sighandler, s, data) |
| 151 | { |
| 152 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
| 153 | |
| 154 | if(s == uip_signal_uninstall) { |
| 155 | dispatcher_exit(&p); |
| 156 | id = EK_ID_NONE; |
| 157 | LOADER_UNLOAD(); |
| 158 | } |
| 159 | } |
| 160 | /*-----------------------------------------------------------------------------------*/ |