blob: c8fe25325c2ce7a630df71a21953015635c28bb7 [file] [log] [blame]
adamdunkelscd499282003-07-30 22:40:36 +00001/*
2 * Copyright (c) 2001, 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: rrnet-drv.c,v 1.1 2003/07/30 22:40:36 adamdunkels Exp $
35 *
36 */
37
38#define NULL (void *)0
39
40#include "uip.h"
41#include "uip_arp.h"
42#include "uip-signal.h"
43#include "loader.h"
44#include "cs8900a.h"
45
46#include "dispatcher.h"
47#include "ek.h"
48
49#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
50
51static u8_t i, arptimer;
52static u16_t start, current;
53
54static void rrnet_drv_idle(void);
55static DISPATCHER_SIGHANDLER(rrnet_drv_sighandler, s, data);
56static struct dispatcher_proc p =
57 {DISPATCHER_PROC("TCP/IP/RR-Net driver", rrnet_drv_idle,
58 rrnet_drv_sighandler, NULL)};
59static ek_id_t id;
60
61
62
63
64/*-----------------------------------------------------------------------------------*/
65static void
66timer(void)
67{
68 for(i = 0; i < UIP_CONNS; ++i) {
69 uip_periodic(i);
70 if(uip_len > 0) {
71 uip_arp_out();
72 cs8900a_send();
73 }
74 }
75
76 for(i = 0; i < UIP_UDP_CONNS; i++) {
77 uip_udp_periodic(i);
78 /* If the above function invocation resulted in data that
79 should be sent out on the network, the global variable
80 uip_len is set to a value > 0. */
81 if(uip_len > 0) {
82 uip_arp_out();
83 cs8900a_send();
84 }
85 }
86}
87/*-----------------------------------------------------------------------------------*/
88static void
89rrnet_drv_idle(void)
90{
91 /* Poll Ethernet device to see if there is a frame avaliable. */
92 uip_len = cs8900a_poll();
93 if(uip_len > 0) {
94 /* A frame was avaliable (and is now read into the uip_buf), so
95 we process it. */
96 if(BUF->type == htons(UIP_ETHTYPE_IP)) {
97 uip_arp_ipin();
98 uip_len -= sizeof(struct uip_eth_hdr);
99 uip_input();
100 /* If the above function invocation resulted in data that
101 should be sent out on the network, the global variable
102 uip_len is set to a value > 0. */
103 if(uip_len > 0) {
104 uip_arp_out();
105 cs8900a_send();
106 }
107 } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
108 uip_arp_arpin();
109 /* If the above function invocation resulted in data that
110 should be sent out on the network, the global variable
111 uip_len is set to a value > 0. */
112 if(uip_len > 0) {
113 cs8900a_send();
114 }
115 }
116 }
117 /* Check the clock so see if we should call the periodic uIP
118 processing. */
119 current = ek_clock();
120
121 if((current - start) >= CLK_TCK/2) {
122 timer();
123 start = current;
124 }
125}
126/*-----------------------------------------------------------------------------------*/
127LOADER_INIT_FUNC(rrnet_drv_init)
128{
129 if(id == EK_ID_NONE) {
130 id = dispatcher_start(&p);
131
132 arptimer = 0;
133 start = ek_clock();
134
135 asm("lda #1");
136 asm("ora $de01");
137 asm("sta $de01");
138 cs8900a_init();
139
140 dispatcher_listen(uip_signal_uninstall);
141 }
142}
143/*-----------------------------------------------------------------------------------*/
144static
145DISPATCHER_SIGHANDLER(rrnet_drv_sighandler, s, data)
146{
147 DISPATCHER_SIGHANDLER_ARGS(s, data);
148
149 if(s == uip_signal_uninstall) {
150 dispatcher_exit(&p);
151 id = EK_ID_NONE;
152 LOADER_UNLOAD();
153 }
154}
155/*-----------------------------------------------------------------------------------*/