|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-1-15 13:11:26
|
显示全部楼层
测试代码:略去UDP报文数据部分(太长)
#include "../../../inc/hw_ints.h"
#include "../../../inc/hw_memmap.h"
#include "../../../inc/hw_nvic.h"
#include "../../../inc/hw_types.h"
#include "../../../inc/hw_ethernet.h"
#include "../../../driverlib/sysctl.h"
#include "../../../driverlib/gpio.h"
#include "../../../driverlib/ethernet.h"
static unsigned char nMACAddr[] = {0x00, 0x07, 0x63, 0x04, 0xF9, 0x30, 0x00, 0x00};
static unsigned char nSendData[] = {
/*Length = 1066 - 14 = 1052(0x041c)*/
0x1c, 0x04,
/*Frame*/
/*0000*/ 0x00, 0x14, 0x2a, 0x6c, 0xae, 0xa8, 0x00, 0x07, 0x63, 0x04, 0xf9, 0x30, 0x08, 0x00, 0x45, 0x00,
// 此处略去若干行
// ......
//
/*Pads*/
0x00, 0x00//, 0x00, 0x00
};
int main(void)
{
unsigned long* pS;
unsigned long nEthClk, ulTemp;
int i;
// Set the clocking to run at 50MHz from the PLL.
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
// Enable and Reset the Ethernet Controller.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);
// Enable Port F for Ethernet LEDs.
// LED0 Bit 3 Output
// LED1 Bit 2 Output
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_HW);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
// Intialize the Ethernet Controller and disable all Ethernet Controller
// interrupt sources.
EthernetIntDisable(ETH_BASE, (ETH_INT_PHY | ETH_INT_MDIO | ETH_INT_RXER | ETH_INT_RXOF | ETH_INT_TX | ETH_INT_TXER | ETH_INT_RX));
ulTemp = EthernetIntStatus(ETH_BASE, false);
EthernetIntClear(ETH_BASE, ulTemp);
// Initialize the Ethernet controller for operation
nEthClk = SysCtlClockGet();
EthernetInitExpClk(ETH_BASE, nEthClk);
// Configure the Ethernet controller for normal operation
// Enable TX Duplex Mode
// Enable TX Padding
EthernetConfigSet(ETH_BASE, (ETH_CFG_TX_DPLXEN | ETH_CFG_TX_PADEN | ETH_CFG_TX_CRCEN));
HWREG(ETH_BASE + MAC_O_THR) = 0x0;
// Program the MAC Address (01-23-45-67-89-AB)
EthernetMACAddrSet(ETH_BASE, nMACAddr);
// Enable the Ethernet controller
EthernetEnable(ETH_BASE);
// Send
while(1)
{
// Wait for current packet (if any) to complete.
while(HWREG(ETH_BASE + MAC_O_TR) & MAC_TR_NEWTX)
{
}
// Copy data to FIFO
pS = (unsigned long*)nSendData;
for ( i = 0; i < sizeof(nSendData) / 4; i++ )
HWREG(ETH_BASE + MAC_O_DATA) = *pS++;
// Activate the transmitter
// HWREG(ETH_BASE + MAC_O_TR) = MAC_TR_NEWTX;
}
} |
|