OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [eth/] [v2_0/] [src/] [lwip/] [eth_drv.c] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      src/lwip/eth_drv.c
4
//
5
//      Hardware independent ethernet driver for lwIP
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    Jani Monoses <jani@iv.ro>
44
// Contributors: 
45
// Date:         2002-04-05
46
// Purpose:      Hardware independent ethernet driver
47
// Description:  Based on the standalone driver for RedBoot.
48
//               
49
//      TODO:
50
//              support more than 1 lowlevel device
51
//              play nice with RedBoot too
52
//
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
 
57
#include <pkgconf/system.h>
58
#include <pkgconf/io_eth_drivers.h>
59
 
60
#include <cyg/infra/cyg_type.h>
61
#include <cyg/hal/hal_arch.h>
62
#include <cyg/infra/diag.h>
63
#include <cyg/hal/drv_api.h>
64
#include <cyg/hal/hal_if.h>
65
#include <cyg/io/eth/eth_drv.h>
66
#include <cyg/io/eth/netdev.h>
67
#include <string.h>
68
 
69
#include <cyg/hal/hal_tables.h>
70
#include <cyg/kernel/kapi.h>
71
 
72
// Define table boundaries
73
CYG_HAL_TABLE_BEGIN( __NETDEVTAB__, netdev );
74
CYG_HAL_TABLE_END( __NETDEVTAB_END__, netdev );
75
 
76
// Interfaces exported to drivers
77
 
78
static void eth_drv_init(struct eth_drv_sc *sc, unsigned char *enaddr);
79
static void eth_drv_recv(struct eth_drv_sc *sc, int total_len);
80
static void eth_drv_tx_done(struct eth_drv_sc *sc, CYG_ADDRWORD key, int status);
81
 
82
struct eth_drv_funs eth_drv_funs = {eth_drv_init, eth_drv_recv, eth_drv_tx_done};
83
 
84
struct eth_drv_sc *__local_enet_sc;
85
 
86
//this is where lwIP keeps hw address
87
unsigned char *lwip_hw_addr;
88
 
89
cyg_sem_t delivery;
90
 
91
//lwIP callback to pass received data to
92
typedef void (*lwip_input_t)(char *,int);
93
static lwip_input_t lwip_input;
94
void input_thread(void * arg)
95
{
96
        struct eth_drv_sc * sc;
97
        //sc = (struct eth_drv_sc *)arg;
98
        sc = __local_enet_sc;
99
        for(;;) {
100
        cyg_semaphore_wait(&delivery);
101
        (sc->funs->deliver)(sc);
102
        }
103
 
104
}
105
 
106
void
107
eth_drv_dsr(cyg_vector_t vector,
108
            cyg_ucount32 count,
109
            cyg_addrword_t data)
110
{
111
        //  struct eth_drv_sc *sc = (struct eth_drv_sc *)data;
112
        //  sc->state |= ETH_DRV_NEEDS_DELIVERY;
113
        cyg_semaphore_post(&delivery);
114
}
115
 
116
 
117
 
118
//Called from lwIP init code to init the hw devices
119
//and pass the lwip input callback address 
120
void init_hw_drivers(unsigned char *hw_addr,lwip_input_t input)
121
{
122
    cyg_netdevtab_entry_t *t;
123
 
124
    lwip_hw_addr = hw_addr;
125
    lwip_input   = input;
126
 
127
// Initialize all network devices
128
    for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
129
        if (t->init(t)) {
130
            t->status = CYG_NETDEVTAB_STATUS_AVAIL;
131
        } else {
132
            // What to do if device init fails?
133
            t->status = 0;  // Device not [currently] available
134
        }
135
    }
136
}
137
 
138
//
139
// This function is called during system initialization to register a
140
// network interface with the system.
141
//
142
static void
143
eth_drv_init(struct eth_drv_sc *sc, unsigned char *enaddr)
144
{
145
    // enaddr == 0 -> hardware init was incomplete (no ESA)
146
    if (enaddr != 0) {
147
        // Set up hardware address
148
        memcpy(&sc->sc_arpcom.esa, enaddr, ETHER_ADDR_LEN);
149
        memcpy(lwip_hw_addr, enaddr, ETHER_ADDR_LEN);
150
        __local_enet_sc = sc;
151
        // Perform any hardware initialization
152
        (sc->funs->start)(sc, (unsigned char *)&sc->sc_arpcom.esa, 0);
153
    }
154
    cyg_semaphore_init(&delivery,0);
155
}
156
 
157
//
158
// Send a packet of data to the hardware
159
//
160
cyg_sem_t  packet_sent;
161
 
162
void
163
eth_drv_write(char *eth_hdr, char *buf, int len)
164
{
165
    struct eth_drv_sg sg_list[MAX_ETH_DRV_SG];
166
    struct eth_drv_sc *sc = __local_enet_sc;
167
    int sg_len = 1;
168
 
169
    while (!(sc->funs->can_send)(sc)) {
170
        cyg_thread_delay(1);
171
    }
172
 
173
    sg_list[0].buf = (CYG_ADDRESS)buf;
174
    sg_list[0].len = len;
175
//    cyg_semaphore_init(&packet_sent,0);
176
    (sc->funs->send)(sc, sg_list, sg_len, len, (CYG_ADDRWORD)&packet_sent);
177
 
178
//    cyg_semaphore_wait(&packet_sent);
179
}
180
 
181
//
182
// This function is called from the hardware driver when an output operation
183
// has completed - i.e. the packet has been sent.
184
//
185
static void
186
eth_drv_tx_done(struct eth_drv_sc *sc, CYG_ADDRWORD key, int status)
187
{
188
#if 0   
189
    CYGARC_HAL_SAVE_GP();
190
    if (key == (CYG_ADDRWORD)&packet_sent) {
191
//      cyg_semaphore_post((cyg_sem_t *)&packet_sent);
192
    }
193
    CYGARC_HAL_RESTORE_GP();
194
#endif    
195
}
196
 
197
 
198
#define MAX_ETH_MSG 1540
199
//
200
// This function is called from a hardware driver to indicate that an input
201
// packet has arrived.  The routine will set up appropriate network resources
202
// to hold the data and call back into the driver to retrieve the data.
203
//
204
static void
205
eth_drv_recv(struct eth_drv_sc *sc, int total_len)
206
{
207
    struct eth_drv_sg sg_list[MAX_ETH_DRV_SG];
208
    int               sg_len = 0;
209
    unsigned char buf[MAX_ETH_MSG];
210
    CYGARC_HAL_SAVE_GP();
211
 
212
    if ((total_len > MAX_ETH_MSG) || (total_len < 0)) {
213
        total_len = MAX_ETH_MSG;
214
    }
215
 
216
    sg_list[0].buf = (CYG_ADDRESS)buf;
217
    sg_list[0].len = total_len;
218
    sg_len = 1;
219
 
220
    (sc->funs->recv)(sc, sg_list, sg_len);
221
    (lwip_input)((char*)sg_list[0].buf,total_len);
222
    CYGARC_HAL_RESTORE_GP();
223
}
224
 
225
 
226
// EOF src/lwip/eth_drv.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.