Contiki 2.5
rtl8019-drv.c
1 /*-----------------------------------------------------------------------------------*/
2 /*
3  * Copyright (c) 2001-2004, Adam Dunkels.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  * products derived from this software without specific prior
16  * written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This file is part of the uIP TCP/IP stack.
31  *
32  * $Id: rtl8019-drv.c,v 1.3 2010/10/19 18:29:04 adamdunkels Exp $
33  *
34  */
35 
36 #include "contiki-net.h"
37 #include "dev/rtl8019dev.h"
38 #include "net/uip-neighbor.h"
39 
40 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
41 
42 PROCESS(rtl8019_process, "RTL8019 driver");
43 
44 /*---------------------------------------------------------------------------*/
45 u8_t
46 rtl8019_output(void)
47 {
48  uip_arp_out();
49  RTL8019dev_send();
50 
51  return 0;
52 }
53 /*---------------------------------------------------------------------------*/
54 static void
55 pollhandler(void)
56 {
57  process_poll(&rtl8019_process);
58  uip_len = RTL8019dev_poll();
59 
60  if(uip_len > 0) {
61 #if UIP_CONF_IPV6
62  if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) {
63  uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
64  tcpip_input();
65  } else
66 #endif /* UIP_CONF_IPV6 */
67  if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) {
68  uip_len -= sizeof(struct uip_eth_hdr);
69  tcpip_input();
70  } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) {
71  uip_arp_arpin();
72  /* If the above function invocation resulted in data that
73  should be sent out on the network, the global variable
74  uip_len is set to a value > 0. */
75  if(uip_len > 0) {
76  RTL8019dev_send();
77  }
78  }
79  }
80 }
81 /*---------------------------------------------------------------------------*/
82 PROCESS_THREAD(rtl8019_process, ev, data)
83 {
84  PROCESS_POLLHANDLER(pollhandler());
85 
86  PROCESS_BEGIN();
87 
88  RTL8019dev_init();
89 
90  tcpip_set_outputfunc(rtl8019_output);
91 
92  process_poll(&rtl8019_process);
93 
94  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);
95 
96  RTL8019dev_exit();
97 
98  PROCESS_END();
99 }
100 /*---------------------------------------------------------------------------*/