示例#1
0
/******************************************************************************
 * Function:        unsigned int SOCKETGetTxPointer() 
 *
 * PreCondition:    none
 *
 * Input:           None
 *
 * Output:          TX pointer location
 *
 * Side Effects:    None
 *
 * Overview:        Retrieves TX pointer location
 *
 * Note:            None
 *****************************************************************************/
unsigned int SOCKETGetTxPointer() 
{
    unsigned int addrTmp;
    addrTmp = enc28j60Read(EWRPTL);
    addrTmp |= enc28j60Read(EWRPTH) << 8;
    return addrTmp;
}
示例#2
0
void enc28j60PowerDown() 
{
  enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_RXEN);
  while(enc28j60Read(ESTAT) & ESTAT_RXBUSY);
  while(enc28j60Read(ECON1) & ECON1_TXRTS);
  enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PWRSV);
}
/**
  * @}
  */
void EXTI0_IRQHandler(void)
{
    uint8_t EIR_dat = 0x00;

    EIR_dat = enc28j60Read(EIR);

    if(EXTI_GetITStatus(EXTI_Line0) != RESET)				  //判别是否有数据包到达
    {
        if(EIR_dat&0x40) {	//检测PKTIF中断请求标志位,接收中断
            ETH_INT=1;
            //printf("PKTIF\n");
        }
        else if(EIR_dat&0x01) {	//检测RXERIF中断请求标志位,接收错误中断
            ETH_INT=1;
            //printf("RXERIF\n");
        }
        else if(EIR_dat&0x10) {
            //链路状态改变中断需要读取PHIR清除中断标志位
            //printf("link state changed\n");
            if(enc28j60PhyRead(PHIR)&0x14) {
                if(enc28j60PhyRead(PHSTAT2)&0x0400) {
                    printf("link activate\n");
                }
                else {
                    printf("link invalid\n");
                    //enc28j60WriteOp(ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
                }
            }
        }
        //ethernetif_input(网口名);								  //设置接收完成标志
        EXTI_ClearITPendingBit(EXTI_Line0);					  //清除中断请求标志
    }
}
示例#4
0
static void _eth_spi_configure() {
  DBG(D_ETH, D_DEBUG, "ethspi spigen init\n");
  SPI_DEV_GEN_init(
      &_enc28j60_spi_dev,
      SPIDEV_CONFIG_CPHA_1E |
      SPIDEV_CONFIG_CPOL_LO |
      SPIDEV_CONFIG_FBIT_MSB |
      SPIDEV_CONFIG_SPEED_9M,
      _SPI_BUS(1),
      SPI_ETH_GPIO_PORT, SPI_ETH_GPIO_PIN);
  DBG(D_ETH, D_DEBUG, "ethspi spigen open\n");
  SPI_DEV_GEN_open(&_enc28j60_spi_dev);
  DBG(D_ETH, D_DEBUG, "ethspi enc28j60 init\n");
  enc28j60Init(mac_address, EIE_PKTIE | EIE_TXIE | EIE_RXERIE | EIE_TXERIE);

  DBG(D_ETH, D_DEBUG, "ethspi enc28j60 init done, chip rev %02x\n", enc28j60getrev());
  DBG(D_ETH, D_DEBUG, "ethspi mac readback: %02x:%02x:%02x:%02x:%02x:%02x\n",
      enc28j60Read(MAADR5), enc28j60Read(MAADR4), enc28j60Read(MAADR3),
      enc28j60Read(MAADR2), enc28j60Read(MAADR1), enc28j60Read(MAADR0)
      );

  SYS_hardsleep_ms(20);
  enc28j60PhyWrite(PHLCON,0x476);
  SYS_hardsleep_ms(20);

  // init eth/ip layer
  init_ip_arp_udp_tcp(mac_address, ip_address, 80);

  DBG(D_ETH, D_INFO, "ethspi setup finished, ip %i.%i.%i.%i @ mac %02x.%02x.%02x.%02x.%02x.%02x\n",
      ip_address[0], ip_address[1], ip_address[2], ip_address[3], mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]);
}
示例#5
0
void network_get_MAC(uint8_t* macaddr)
{
	*macaddr++ = enc28j60Read(MAADR5);
	*macaddr++ = enc28j60Read(MAADR4);
	*macaddr++ = enc28j60Read(MAADR3);
	*macaddr++ = enc28j60Read(MAADR2);
	*macaddr++ = enc28j60Read(MAADR1);
	*macaddr++ = enc28j60Read(MAADR0);
}
示例#6
0
文件: network.c 项目: jaseg/avr-uip
void network_get_MAC(u08* macaddr)
{
	// read MAC address registers
	// NOTE: MAC address in ENC28J60 is byte-backward
	*macaddr++ = enc28j60Read(MAADR5);
	*macaddr++ = enc28j60Read(MAADR4);
	*macaddr++ = enc28j60Read(MAADR3);
	*macaddr++ = enc28j60Read(MAADR2);
	*macaddr++ = enc28j60Read(MAADR1);
	*macaddr++ = enc28j60Read(MAADR0);
}
示例#7
0
//Documentation in header file
uint8_t dhcp_requestIP(uint16_t timeout_ms)
{
	//Get a timer
	int8_t timer = timer_get();
	timer_set(timer,timeout_ms);
	
	//Send dhcp discover packet
	dhcp_sendDiscover();

	do
	{
		//Wait for a packet to arrive
		//If no packets arrive in time, return 0
		while(enc28j60Read(EPKTCNT) == 0)
			if(timer_check(timer) == TIMER_EXPIRED)
			{
				//Release the timer
				timer_release(timer);
				return 0;
			}				
				
		//Receive packet
		ns.plength = enc28j60PacketReceive(ns.pbuf, ns.pbuf_size);
		
		//Check if packet is DHCP!
		if(ns.plength > 0)
			if(getPacketType() == DHCP)
				dhcp_handlePacket();
						
	}
	while(ns.ipAcquired == 0);	
	
	//Release the timer
	timer_release(timer);	
	
	//Return success		
	return ns.ipAcquired;
}
示例#8
0
/******************************************************************************
 * Function:        BOOL IsDMACopyDone(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Returns true if DMA flag was cleared
 *
 * Side Effects:    None
 *
 * Overview:        Check for DMA flag
 *
 * Note:            None
 *****************************************************************************/
BOOL IsDMACopyDone(void)
{
    return !((enc28j60Read(ECON1) & ECON1_DMAST) == ECON1_DMAST);
}
示例#9
0
/******************************************************************************
 * Function:        BOOL IsMACSendTx(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Returns true if TX send flag was cleared
 *
 * Side Effects:    None
 *
 * Overview:        Check for Send Tx flag
 *
 * Note:            None
 *****************************************************************************/
BOOL IsMACSendTx(void)
{
    return !((enc28j60Read(ECON1) & ECON1_TXRTS) == ECON1_TXRTS);
}
示例#10
0
/******************************************************************************
 * Function:        unsigned char MACGetPacketCount(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Check EPKTCNT to know how many packets arrived
 *
 * Note:            None
 *****************************************************************************/
unsigned char MACGetPacketCount(void)
{
    return enc28j60Read(EPKTCNT);
}
示例#11
0
/******************************************************************************
 * Function:        unsigned char MACHardwareRevision(void)
 *
 * PreCondition:    Must call MACOpen() first
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Returns hardware revision
 *
 * Note:            None
 *****************************************************************************/
unsigned char MACHardwareRevision(void)
{
    return enc28j60Read(EREVID);
}
示例#12
0
void enc28j60PowerUp() 
{
  enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON2, ECON2_PWRSV);
  while(!enc28j60Read(ESTAT) & ESTAT_CLKRDY);
}
示例#13
0
uint8_t EtherShield::ES_enc28j60Read( uint8_t address ) {
	return enc28j60Read( address );
}