uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Sat Jun 14 16:02:21 2014 +0000
Revision:
0:685224d2f66d
Child:
3:a2715e9c7737
initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ban4jp 0:685224d2f66d 1 /*
ban4jp 0:685224d2f66d 2 * Copyright (c) 2001, Swedish Institute of Computer Science.
ban4jp 0:685224d2f66d 3 * All rights reserved.
ban4jp 0:685224d2f66d 4 *
ban4jp 0:685224d2f66d 5 * Redistribution and use in source and binary forms, with or without
ban4jp 0:685224d2f66d 6 * modification, are permitted provided that the following conditions
ban4jp 0:685224d2f66d 7 * are met:
ban4jp 0:685224d2f66d 8 *
ban4jp 0:685224d2f66d 9 * 1. Redistributions of source code must retain the above copyright
ban4jp 0:685224d2f66d 10 * notice, this list of conditions and the following disclaimer.
ban4jp 0:685224d2f66d 11 *
ban4jp 0:685224d2f66d 12 * 2. Redistributions in binary form must reproduce the above copyright
ban4jp 0:685224d2f66d 13 * notice, this list of conditions and the following disclaimer in the
ban4jp 0:685224d2f66d 14 * documentation and/or other materials provided with the distribution.
ban4jp 0:685224d2f66d 15 *
ban4jp 0:685224d2f66d 16 * 3. Neither the name of the Institute nor the names of its contributors
ban4jp 0:685224d2f66d 17 * may be used to endorse or promote products derived from this software
ban4jp 0:685224d2f66d 18 * without specific prior written permission.
ban4jp 0:685224d2f66d 19 *
ban4jp 0:685224d2f66d 20 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
ban4jp 0:685224d2f66d 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ban4jp 0:685224d2f66d 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ban4jp 0:685224d2f66d 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
ban4jp 0:685224d2f66d 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ban4jp 0:685224d2f66d 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ban4jp 0:685224d2f66d 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ban4jp 0:685224d2f66d 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ban4jp 0:685224d2f66d 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ban4jp 0:685224d2f66d 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ban4jp 0:685224d2f66d 30 * SUCH DAMAGE.
ban4jp 0:685224d2f66d 31 *
ban4jp 0:685224d2f66d 32 * Author: Adam Dunkels <adam@sics.se>
ban4jp 0:685224d2f66d 33 *
ban4jp 0:685224d2f66d 34 * $Id: tapdev.c,v 1.8 2006/06/07 08:39:58 adam Exp $
ban4jp 0:685224d2f66d 35 */
ban4jp 0:685224d2f66d 36
ban4jp 0:685224d2f66d 37 #include "mbed.h"
ban4jp 0:685224d2f66d 38
ban4jp 0:685224d2f66d 39 #include "enc28j60.h"
ban4jp 0:685224d2f66d 40 #include "uip.h"
ban4jp 0:685224d2f66d 41
ban4jp 0:685224d2f66d 42 #if defined(TARGET_LPC1768)
ban4jp 0:685224d2f66d 43 SPI spi(p11, p12, p13); // mosi, miso, sclk
ban4jp 0:685224d2f66d 44 ENC28J60 enc28j60(&spi, p14, p15); // cs, int
ban4jp 0:685224d2f66d 45 #elif defined(TARGET_LPC1114)
ban4jp 0:685224d2f66d 46 SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
ban4jp 0:685224d2f66d 47 ENC28J60 enc28j60(&spi, dp25, dp26); // cs, int
ban4jp 0:685224d2f66d 48 #else
ban4jp 0:685224d2f66d 49 #error no defined tapdev.
ban4jp 0:685224d2f66d 50 #endif
ban4jp 0:685224d2f66d 51
ban4jp 0:685224d2f66d 52 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 53 void
ban4jp 0:685224d2f66d 54 tapdev_init(void)
ban4jp 0:685224d2f66d 55 {
ban4jp 0:685224d2f66d 56 enc28j60.init();
ban4jp 0:685224d2f66d 57 }
ban4jp 0:685224d2f66d 58 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 59 unsigned int
ban4jp 0:685224d2f66d 60 tapdev_read(void)
ban4jp 0:685224d2f66d 61 {
ban4jp 0:685224d2f66d 62 unsigned int len;
ban4jp 0:685224d2f66d 63 len = enc28j60.packetReceive(UIP_BUFSIZE, (u8 *)uip_buf);
ban4jp 0:685224d2f66d 64 return len;
ban4jp 0:685224d2f66d 65 }
ban4jp 0:685224d2f66d 66 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 67 void
ban4jp 0:685224d2f66d 68 tapdev_send(void)
ban4jp 0:685224d2f66d 69 {
ban4jp 0:685224d2f66d 70 if(uip_len <= 40 + UIP_LLH_LEN){
ban4jp 0:685224d2f66d 71 enc28j60.packetSend(uip_len, (u8 *)uip_buf);
ban4jp 0:685224d2f66d 72 }else{
ban4jp 0:685224d2f66d 73 enc28j60.packetSend2(54, (u8 *)uip_buf, uip_len -40 - UIP_LLH_LEN, (u8 *)uip_appdata);
ban4jp 0:685224d2f66d 74 }
ban4jp 0:685224d2f66d 75 }
ban4jp 0:685224d2f66d 76 /*---------------------------------------------------------------------------*/