Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / mcu / libs / enc28j60 /

enc28j60_eth.c

   1  /*******************************************************************************
   2  
   3     Copyright (C) 2010 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Martin Musil <xmusil34 AT fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  *******************************************************************************/
  44  #include "enc28j60_ip.h"
  45  #include "enc28j60_arp.h"
  46  #include "enc28j60_eth.h"
  47  #include "enc28j60_spi.h"
  48  
  49  #include "enc28j60_string.h"
  50  
  51  extern unsigned int tx_end_ptr;
  52  extern char enc_initialized;
  53  //defaultni MAC adresa
  54  unsigned char local_mac[MAC_LEN] = {0x00,0x23,0x8B,0x6B,0x38,0x64};
  55  unsigned char broadcast_mac[MAC_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  56  
  57  
  58  /**
  59  
  60   **/
  61  void ENC28J60_idle(){
  62  
  63  	if(read_reg8(EIR,NO_DUMMY) & EIR_PKTIF){		//paket v rx bufferu
  64  		eth_recv();
  65  	}
  66  
  67  return;
  68  }
  69  
  70  
  71  /**
  72  
  73   **/
  74  void eth_recv(){
  75  
  76  	struct eth_h eth_header;
  77  
  78  	if(rx_init() < 0){
  79  		return;
  80  	}
  81  
  82  	rx_read(&eth_header, ETH_HEADER_LEN);
  83  
  84  	switch(eth_header.type_len){
  85  
  86  		case HTONS(ETH_PROTO_IP):
  87  			ip_recv();
  88  			break;
  89  
  90  		case HTONS(ETH_PROTO_ARP):
  91  			arp_recv();
  92  			break;
  93  	}
  94  
  95  	rx_free();
  96  
  97  return;
  98  }
  99  
 100  /**
 101  
 102   **/
 103  char eth_send(unsigned char* dest_addr,unsigned int type){
 104  
 105  	struct eth_h eth_header;
 106  
 107  	enc_memcpy(&eth_header.dest_addr, dest_addr, MAC_LEN);
 108  	enc_memcpy(&eth_header.src_addr, &local_mac, MAC_LEN);
 109  	eth_header.type_len = HTONS(type);
 110  
 111  	tx_seek(CTRL);
 112  	tx_putc(CTRL_BYTE);
 113  	tx_write(&eth_header,ETH_HEADER_LEN);
 114  
 115  return tx_send();
 116  }
 117  
 118  /**
 119  
 120  
 121   **/
 122  inline char set_mac(unsigned char* mac_ptr){
 123  
 124  	if(enc_initialized == 0){
 125  		enc_memcpy(&local_mac,mac_ptr, MAC_LEN);
 126  		return 1;
 127  	}
 128  return 0;
 129  }
 130  
 131  
Zobrazeno: 683855x Naposledy: 5.7.2022 05:37:47