Work in progress.

This commit is contained in:
Richard Barry 2009-05-28 20:40:12 +00:00
parent 25194d5918
commit b42009def0
6 changed files with 67 additions and 53 deletions

View file

@ -43,16 +43,18 @@ static unsigned short SwapBytes(unsigned short Data)
void write_PHY (int PhyReg, int Value)
{
unsigned int tout;
const unsigned int uiMaxTime = 10;
MAC_MADR = DP83848C_DEF_ADR | PhyReg;
MAC_MWTD = Value;
/* Wait utill operation completed */
tout = 0;
for (tout = 0; tout < MII_WR_TOUT; tout++) {
for (tout = 0; tout < uiMaxTime; tout++) {
if ((MAC_MIND & MIND_BUSY) == 0) {
break;
}
vTaskDelay( 2 );
}
}
@ -61,16 +63,18 @@ void write_PHY (int PhyReg, int Value)
unsigned short read_PHY (unsigned char PhyReg)
{
unsigned int tout;
const unsigned int uiMaxTime = 10;
MAC_MADR = DP83848C_DEF_ADR | PhyReg;
MAC_MCMD = MCMD_READ;
/* Wait until operation completed */
tout = 0;
for (tout = 0; tout < MII_RD_TOUT; tout++) {
for (tout = 0; tout < uiMaxTime; tout++) {
if ((MAC_MIND & MIND_BUSY) == 0) {
break;
}
vTaskDelay( 2 );
}
MAC_MCMD = 0;
return (MAC_MRDD);
@ -135,15 +139,15 @@ portBASE_TYPE xReturn = pdPASS;
PINSEL3 = (PINSEL3 & ~0x0000000F) | 0x00000005;
/* Power Up the EMAC controller. */
PCONP |= 0x40000000;
vTaskDelay( 1 );
PCONP |= PCONP_PCENET;
vTaskDelay( 2 );
/* Reset all EMAC internal modules. */
MAC_MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | MAC1_SIM_RES | MAC1_SOFT_RES;
MAC_COMMAND = CR_REG_RES | CR_TX_RES | CR_RX_RES;
MAC_COMMAND = CR_REG_RES | CR_TX_RES | CR_RX_RES | CR_PASS_RUNT_FRM;
/* A short delay after reset. */
vTaskDelay( 1 );
vTaskDelay( 2 );
/* Initialize MAC control registers. */
MAC_MAC1 = MAC1_PASS_ALL;
@ -157,9 +161,10 @@ portBASE_TYPE xReturn = pdPASS;
/* Reset Reduced MII Logic. */
MAC_SUPP = SUPP_RES_RMII;
vTaskDelay( 2 );
MAC_SUPP = 0;
/* Put the DP83848C in reset mode */
/* Put the PHY in reset mode */
write_PHY (PHY_REG_BMCR, 0x8000);
write_PHY (PHY_REG_BMCR, 0x8000);
@ -173,6 +178,21 @@ portBASE_TYPE xReturn = pdPASS;
}
}
/* Set the Ethernet MAC Address registers */
MAC_SA0 = (emacETHADDR0 << 8) | emacETHADDR1;
MAC_SA1 = (emacETHADDR2 << 8) | emacETHADDR3;
MAC_SA2 = (emacETHADDR4 << 8) | emacETHADDR5;
/* Initialize Tx and Rx DMA Descriptors */
rx_descr_init ();
tx_descr_init ();
/* Receive Broadcast and Perfect Match Packets */
MAC_RXFILTERCTRL = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;
/* Create the semaphore used ot wake the uIP task. */
vSemaphoreCreateBinary( xEMACSemaphore );
/* Check if this is a DP83848C PHY. */
id1 = read_PHY (PHY_REG_IDR1);
id2 = read_PHY (PHY_REG_IDR2);
@ -235,21 +255,6 @@ portBASE_TYPE xReturn = pdPASS;
MAC_SUPP = SUPP_SPEED;
}
/* Set the Ethernet MAC Address registers */
MAC_SA0 = (emacETHADDR0 << 8) | emacETHADDR1;
MAC_SA1 = (emacETHADDR2 << 8) | emacETHADDR3;
MAC_SA2 = (emacETHADDR4 << 8) | emacETHADDR5;
/* Initialize Tx and Rx DMA Descriptors */
rx_descr_init ();
tx_descr_init ();
/* Receive Broadcast and Perfect Match Packets */
MAC_RXFILTERCTRL = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;
/* Create the semaphore used ot wake the uIP task. */
vSemaphoreCreateBinary( xEMACSemaphore );
/* Reset all interrupts */
MAC_INTCLEAR = 0xFFFF;

View file

@ -72,20 +72,6 @@
#include "core_cm3.h"
/*-----------------------------------------------------------*/
/* MAC address configuration. */
#define uipMAC_ADDR0 0x00
#define uipMAC_ADDR1 0x12
#define uipMAC_ADDR2 0x13
#define uipMAC_ADDR3 0x10
#define uipMAC_ADDR4 0x15
#define uipMAC_ADDR5 0x11
/* IP address configuration. */
#define uipIP_ADDR0 192
#define uipIP_ADDR1 168
#define uipIP_ADDR2 0
#define uipIP_ADDR3 200
/* How long to wait before attempting to connect the MAC again. */
#define uipINIT_WAIT 100
@ -150,8 +136,10 @@ extern void ( vEMAC_ISR_Wrapper )( void );
timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
uip_init();
uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
uip_sethostaddr( xIPAddr );
uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
uip_setnetmask( xIPAddr );
httpd_init();
/* Initialise the MAC. */
@ -277,12 +265,12 @@ static void prvSetMACAddress( void )
struct uip_eth_addr xAddr;
/* Configure the MAC address in the uIP stack. */
xAddr.addr[ 0 ] = uipMAC_ADDR0;
xAddr.addr[ 1 ] = uipMAC_ADDR1;
xAddr.addr[ 2 ] = uipMAC_ADDR2;
xAddr.addr[ 3 ] = uipMAC_ADDR3;
xAddr.addr[ 4 ] = uipMAC_ADDR4;
xAddr.addr[ 5 ] = uipMAC_ADDR5;
xAddr.addr[ 0 ] = configMAC_ADDR0;
xAddr.addr[ 1 ] = configMAC_ADDR1;
xAddr.addr[ 2 ] = configMAC_ADDR2;
xAddr.addr[ 3 ] = configMAC_ADDR3;
xAddr.addr[ 4 ] = configMAC_ADDR4;
xAddr.addr[ 5 ] = configMAC_ADDR5;
uip_setethaddr( xAddr );
}
/*-----------------------------------------------------------*/