📄 main.c
字号:
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
pEbootCFG->delay = atoi(szCount);
if (pEbootCFG->delay > 255)
{
pEbootCFG->delay = 255;
}
else if (pEbootCFG->delay < 1)
{
pEbootCFG->delay = 1;
}
}
}
void SetSMSCMACAddress()
{
char szDottedD[24]; // The string used to collect the dotted masks
WORD cwNumChars = 0;
UINT16 InChar = 0;
USHORT MacAddr[3];
USHORT MacAddrTemp[3];
XllpEthernetSWInit((void *)SMSC_ETHERNET_BASE_U_VIRTUAL);
if (XllpEthernetHWSetup((P_XLLP_UINT16_T) MacAddr, TRUE, TRUE, XLLP_ETHERNET_LOOPBACK_DISABLE) == 0)
{
EdbgOutputDebugString ( "\r\nEnter new MAC address (nnn.nnn.nnn.nnn.nnn.nnn): ");
while (!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string
if (InChar == '.' || (InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 23)
{
szDottedD[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
CvtMAC(MacAddr, szDottedD );
EdbgOutputDebugString ( "\r\n");
XllpEthernetStoreEEPROMMACAddress((P_XLLP_UINT16_T) MacAddr);
XllpEthernetStoreMACAddress((P_XLLP_UINT16_T) MacAddr);
XllpEthernetGetEEPROMMACAddress((P_XLLP_UINT16_T) MacAddrTemp);
if ( (MacAddr[0] != MacAddrTemp[0]) &&
(MacAddr[1] != MacAddrTemp[1]) &&
(MacAddr[2] != MacAddrTemp[2]) )
{
EdbgOutputDebugString ( "\r\nMAC address programming failure!\r\n");
EdbgOutputDebugString("Requested address: %d.%d.%d.%d.%d.%d\r\n",
MacAddr[0] & 0x00FF, MacAddr[0] >> 8,
MacAddr[1] & 0x00FF, MacAddr[1] >> 8,
MacAddr[2] & 0x00FF, MacAddr[2] >> 8);
EdbgOutputDebugString("SMSC controller returned: %d.%d.%d.%d.%d.%d\r\n",
MacAddrTemp[0] & 0x00FF, MacAddrTemp[0] >> 8,
MacAddrTemp[1] & 0x00FF, MacAddrTemp[1] >> 8,
MacAddrTemp[2] & 0x00FF, MacAddrTemp[2] >> 8);
}
else
{
EdbgOutputDebugString ( "\r\nMAC address programming complete.\r\n");
}
}
}
else
{
EdbgOutputDebugString("LAN91C111 Ethernet controller failed to initialize.\n");
EdbgOutputDebugString("Unable to program MAC address.\n");
}
}
// This routine will convert a dotted decimal MAC address into a binary version
void CvtMAC(USHORT MacAddr[3], char *pszDottedD )
{
DWORD cBytes;
char *pszLastNum;
int atoi (const char *s);
int i=0;
BYTE *p = (BYTE *)MacAddr;
// Replace the dots with NULL terminators
pszLastNum = pszDottedD;
for ( cBytes = 0; cBytes < 6; cBytes++ )
{
while (*pszDottedD != '.' && *pszDottedD != '\0')
pszDottedD++;
if (pszDottedD == '\0' && cBytes != 5)
{
// zero out the rest of MAC address
while (i++ < 6)
{
*p++ = 0;
}
break;
}
*pszDottedD = '\0';
*p++ = (atoi(pszLastNum) & 0xFF);
i++;
pszLastNum = ++pszDottedD;
}
}
int DetectFlashDevice(void)
{
volatile DWORD *pdwFlash;
int MfgCode = 0;
int DeviceID = 0;
pdwFlash = (volatile DWORD *)(BOOT_FLASH_BASE_U_VIRTUAL);
// Put flash into query mode
*pdwFlash = 0x00980098;
MfgCode = *(pdwFlash + 0) & 0x0000FFFF; // offset 0 for MfgCode
DeviceID = *(pdwFlash + 1) & 0x0000FFFF; // offset 1 for DeviceID
// Put Flash into read mode.
*pdwFlash = 0x00FF00FF;
if ((MfgCode == 0x00000089) && ((DeviceID >= 0x0000880C) && (DeviceID <= 0x0000880F)))
return L18;
if ((MfgCode == 0x00000089) && ((DeviceID >= 0x00008812) && (DeviceID <= 0x00008815)))
return L30;
if ((MfgCode == 0x00000089) && ((DeviceID >= 0x00008801) && (DeviceID <= 0x00008803)))
return K3;
if ((MfgCode == 0x00000089) && ((DeviceID >= 0x00008805) && (DeviceID <= 0x00008807)))
return K18;
if ((MfgCode == 0x00000089) && ((DeviceID >= 0x00000016) && (DeviceID <= 0x00000018)))
return J3;
return 0;
}
/*
void TestLCD()
{
XLLP_LCD_T XllpLCD;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh0fd1=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh0fd2=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh1=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorPalette=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorTemp=NULL;
volatile LCD_PALETTE *v_pPaletteBuffer=NULL;
__int16 c = 0;
int i = 0;
int x1,x2,y1,y2;
frameDescriptorCh0fd1 = (volatile LCD_FRAME_DESCRIPTOR *)(DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_VIRTUAL);
frameDescriptorCh0fd2 = (volatile LCD_FRAME_DESCRIPTOR *)(DMA_CHANNEL_0_ALT_FRAME_DESCRIPTOR_BASE_VIRTUAL);
frameDescriptorCh1 = (volatile LCD_FRAME_DESCRIPTOR *)(DMA_CHANNEL_1_FRAME_DESCRIPTOR_BASE_VIRTUAL);
frameDescriptorPalette = (volatile LCD_FRAME_DESCRIPTOR *)(PALETTE_FRAME_DESCRIPTOR_BASE_VIRTUAL);
v_pPaletteBuffer=(volatile LCD_PALETTE *)(PALETTE_BUFFER_BASE_VIRTUAL);
XllpLCD.GPIO = (XLLP_VUINT32_T *) GPIO_BASE_U_VIRTUAL;
XllpLCD.CLKMan = (XLLP_VUINT32_T *) (PERIF_BASE_U_VIRTUAL + CLK_OFFSET);
XllpLCD.LCDC = (XLLP_VUINT32_T *) LCD_BASE_U_VIRTUAL;
XllpLCD.DisplayType = LTM04C380K;
XllpLCD.FrameBufferWidth = 640;
XllpLCD.FrameBufferHeight = 480;
XllpLCD.BPP = BPP_16;
XllpLCD.PixelDataFormat = PDFOR_00;
XllpLCD._FRAME_BUFFER_BASE_PHYSICAL = FRAME_BUFFER_0_BASE_PHYSICAL;
XllpLCD._PALETTE_BUFFER_BASE_PHYSICAL = PALETTE_BUFFER_BASE_PHYSICAL;
XllpLCD._DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD._DMA_CHANNEL_1_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_1_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD._DMA_CHANNEL_0_ALT_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_0_ALT_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD._PALETTE_FRAME_DESCRIPTOR_BASE_PHYSICAL = PALETTE_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD.frameDescriptorCh0fd1 = frameDescriptorCh0fd1;
XllpLCD.frameDescriptorCh0fd2 = frameDescriptorCh0fd2;
XllpLCD.frameDescriptorCh1 = frameDescriptorCh1;
XllpLCD.frameDescriptorPalette = frameDescriptorPalette;
XllpLCD.frameDescriptorTemp = frameDescriptorTemp;
// Initialize the LCD Controller
XllpLCDInit(&XllpLCD);
// Clear the display
ClearFrameBuffer(TRUE);
// Draw the pattern to the display
c = 0x1f;
y1 = 240;
x2 = 320;
for(x1=80,y2=240;y2>0;x1+=10,y2-=10)
{
line(x1,y1,x2,y2,c);
}
y1 = 240;
x2 = 320;
for(x1=80,y2=240;y2<480;x1+=10,y2+=10)
{
line(x1,y1,x2,y2,c);
}
y1 = 240;
x2 = 320;
for(x1=560,y2=240;y2>0;x1-=10,y2-=10)
{
line(x1,y1,x2,y2,c);
}
y1 = 240;
x2 = 320;
for(x1=560,y2=240;y2<480;x1-=10,y2+=10)
{
line(x1,y1,x2,y2,c);
}
}
#define abs(x) ((x)>0?(x):-(x))
void line(int ox1, int oy1, int ox2, int oy2, __int16 c)
{
int i,j;
int idy;
int idx;
int off;
int x,y;
int x1, x2, y1, y2;
__int16 *fbp;
fbp=(__int16 *)FRAME_BUFFER_0_BASE_VIRTUAL;
if(abs(ox2-ox1) > abs(oy2 - oy1)){
if(ox2<ox1){
x1 = ox2;
x2 = ox1;
y1 = oy2;
y2 = oy1;
} else {
x1 = ox1;
x2 = ox2;
y1 = oy1;
y2 = oy2;
}
} else {
if(oy2<oy1){
x1 = ox2;
x2 = ox1;
y1 = oy2;
y2 = oy1;
} else {
x1 = ox1;
x2 = ox2;
y1 = oy1;
y2 = oy2;
}
}
if(x2-x1 > y2 - y1)
{
if(y2 == y1)
{
idx = 0; //draw horiz line
hline(x1, y1, x2, c);
}
else
{
idy = (65536 * (y2 - y1)) / (x2 - x1);
off = y1 * 640;
y = y1 << 16;
for(i=x1;i<x2;i++)
{
*(fbp+i+(y>>16)*640) = (__int16)c;
y += idy;
}
}
} else
{
if(x2 == x1)
{
idx = 0; //vertical
vline(x1, y1, y2, c);
} else
{
idx = (65536 * (x2 - x1)) / (y2 - y1 );
off = y1 * 640;
x= x1 << 16;
for(j=y1;j<y2;j++)
{
*(fbp+(x>>16)+off) = (__int16)c;
x += idx;
off+=640;
}
}
}
}
void hline(int x1, int y1, int x2,__int16 c)
{
int i,j;
__int16 *fbp;
fbp=(__int16 *)FRAME_BUFFER_0_BASE_VIRTUAL;
i = y1 * 640 + x1;
for(j = i; j < x2+i; j++)
{
*(fbp+j) = (__int16)c;
}
}
void vline(int x1, int y1, int y2, __int16 c)
{
int i,j,k;
__int16 *fbp;
fbp=(__int16 *)FRAME_BUFFER_0_BASE_VIRTUAL;
i = y1 * 640 + x1;
k = 640;
for(j =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -