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

Subversion Repositories igor

[/] [igor/] [trunk/] [avr/] [src/] [enc28j60-uip.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 atypic
#include "dev/enc28j60.h"
2
#include <avr/io.h>
3
#include <util/delay.h>
4
#include "uip/uipopt.h"
5
#include "uip/uip.h"
6
 
7
/*
8
* This is the interface between the ENC28J60 driver and the uIP TCP/IP stack.
9
* The code was lifted from http://code.google.com/p/avr-uip/
10
*/
11
 
12
//Read a packet from the controller and place it in the uIP buffer.
13
//The length of the packet is returned, 0 if no packet was waiting.
14
unsigned int network_read(void){
15
        uint16_t len;
16
        len=enc28j60PacketReceive(UIP_BUFSIZE, (uint8_t *)uip_buf);
17
        return len;
18
}
19
 
20
//Send a packet from the uIP buffer
21
void network_send(void){
22
        if(uip_len <= UIP_LLH_LEN + 40){
23
                enc28j60PacketSendTwo(uip_len, (uint8_t *)uip_buf, 0, 0);
24
        }else{
25
                enc28j60PacketSendTwo(54, (uint8_t *)uip_buf , uip_len - UIP_LLH_LEN - 40, (uint8_t*)uip_appdata);
26
        }
27
}
28
 
29
//Initialize ethernet controller
30
void network_init(void)
31
{
32
        //Initialise the device
33
        enc28j60Init();
34
 
35
        //Configure leds
36
        enc28j60PhyWrite(PHLCON,0x476);
37
}
38
 
39
void network_get_MAC(uint8_t* macaddr)
40
{
41
        // read MAC address registers
42
        // NOTE: MAC address in ENC28J60 is byte-backward
43
        *macaddr++ = enc28j60Read(MAADR5);
44
        *macaddr++ = enc28j60Read(MAADR4);
45
        *macaddr++ = enc28j60Read(MAADR3);
46
        *macaddr++ = enc28j60Read(MAADR2);
47
        *macaddr++ = enc28j60Read(MAADR1);
48
        *macaddr++ = enc28j60Read(MAADR0);
49
}
50
 
51
void network_set_MAC(uint8_t* macaddr)
52
{
53
        // write MAC address
54
        // NOTE: MAC address in ENC28J60 is byte-backward
55
        enc28j60Write(MAADR5, *macaddr++);
56
        enc28j60Write(MAADR4, *macaddr++);
57
        enc28j60Write(MAADR3, *macaddr++);
58
        enc28j60Write(MAADR2, *macaddr++);
59
        enc28j60Write(MAADR1, *macaddr++);
60
        enc28j60Write(MAADR0, *macaddr++);
61
}
62
 

powered by: WebSVN 2.1.0

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