📄 main.c
字号:
/*
###############################################################################
File Name : Main.C
Version : 1.0
Programmer(s) : KIM WOO YOUL
Created : 2002/10/25
Description : Direct Interface of W3100A Test Program with 8051 MCU
<HOW TO TEST>
1. Test common registers except COMMAND regs, Regs associated with interrupt, and 4Byte regs(rd,wr,ack pointer reg).
2. Test TX and RX Memory of W3100A.
3. Test shadow regs and 4Byte regs(rd,wr,ack pointer reg).
4. initialize W3100A and Configure network, and then write command of 0 channel to 0x01.
5. Test occurrence of interrupt.
5-1. After interrupt is occurred, check value of interrupt register.
5-2. If the lowest bit(0) of interrupt register is set, read interrupt status register of the lowest channel(0).
5-3. Check the read value of interrupt register of the lowest channel(0) to be equal to 0x01.
5-4. After Read value of interrupt register of the lowest channel again, Check the value to be equal to zero.
5-5. After write Interrupt register to 0xFF, read the value and then check the value to be equal to zero.
6. Using Dos-command prompt, pinging to your target board
Modified History :
Modified :
Programmer :
Description :
###############################################################################
*/
/*
###############################################################################
Include Part
###############################################################################
*/
#include <reg51.h> // 8051's SFR
#include "type.h" // type definition
#include "socket.h" // w3100a definition
#include "serial.h" // rs232c
/*
###############################################################################
Define Part
###############################################################################
*/
/*
###############################################################################
Grobal Variable 急攫 Part
###############################################################################
*/
sfr CKCON = 0x8F;
char IsISROK = 0; // if interrupt occurred then 1
/*
###############################################################################
Local Variable 急攫 Part
###############################################################################
*/
/*
###############################################################################
Function Implementation Part
###############################################################################
*/
void Init8051();
void Delay(u_int delay);
/*
Description : Interrupt service routine
Argument : NOne.
Return Value : None.
Note :
*/
void int0() interrupt 0
{
char int_status;
EX0 = 0;
IsISROK = 1;
PutString("\tInterrupt Occurred : Interrupt register value = ");PutHTOA(INT_REG);PutStringLn("");
if(INT_REG & 0x01)
{
int_status = INT_STATUS(0); // When you read Interrupt status register, Value of Interrupt status register is cleared.
if(int_status & 0x01)
PutStringLn("\t\tINIT_OK Interrupt occurred");
else
{
PutString("\t\tUnknown Interrupt status : Value of INT_STATUS(0) = ");PutHTOA(int_status);PutStringLn("");
}
INT_REG = 0x01; // Interrupt register clear
}
else
{
PutStringLn("\t\tUnknown Interrupt occurred");
INT_REG = 0xFF; // clear all bit of interrupt status register
}
EX0 = 1;
}
/*
Description : Main function of direct interface test
Argument : NOne.
Return Value : None.
Note :
*/
void main()
{
int i;
u_char val;
char ptr[4];
char IsVerifyOK = 1;
Init8051(); // Initialize 8051
PutStringLn("\r\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
PutString (" Interface Test of W3100A (Direct Mode) - Created Date : ");PutLTOA(0x20021028); PutStringLn("");
PutStringLn(" - Created By : WIZnet, Inc.");
PutStringLn(" - Flatform : 8051 EVB V3.0");
PutStringLn("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\r\n");
/* Common register Test */
PutStringLn("TEST 1. COMMON REGISTERS - 0x80 ~ 0xFF");
PutStringLn("\tWrite common regs with 0x80 ~ 0xFF");
for(i=0x80; i < 0x100;i++) *((u_char xdata*)(I2CHIP_BASE+i)) = i;
PutStringLn("\tVerify common regs");
for(i=0x80; i < 0x100; i++)
{
val = *((u_char xdata*)(I2CHIP_BASE+i));
if(val != i)
{
PutString("\t Verify fail at 0x");PutHTOA(i);PutString("-regs : ");
PutString("Write Value = 0x");PutHTOA(i);PutString(", Read Value = 0x");
PutHTOA(val);PutStringLn("");
IsVerifyOK = 0;
}
}
if(IsVerifyOK) PutStringLn("\tVerify OK - common register");
else PutStringLn("\tVerify Fail - common register");
/* TX and RX Memory Test */
IsVerifyOK = 1;
COMMAND(1) = 0x80; // Set Memory Test Mode
PutStringLn("\r\nTEST 2. TX,RX MEMORY");
PutStringLn("\tWrite Tx Memory with 0x00 ~ 0xFF");
for(i = 0; i < 8192 ; i++) *((u_char xdata*)(SEND_DATA_BUF+i)) = i % 0x100;
PutStringLn("\tVerify Tx Memory");
for(i = 8191; i > -1 ; i--)
{
val = *((u_char xdata*)(SEND_DATA_BUF+i));
if(val != (u_char)(i % 0x100))
{
PutString("\t Verify fail at 0x");PutITOA(0x4000+i);
PutString(" : Write Value = 0x");PutHTOA(i%0x100);PutString(", Read Value = 0x");
PutHTOA(val);PutStringLn("");
IsVerifyOK = 0;
}
}
if(IsVerifyOK) PutStringLn("\tVerify OK - TX Memory");
else PutStringLn("\tVerify Fail - TX Memory");
IsVerifyOK = 1;
PutStringLn("\tWrite Rx Memory with 0x00 ~ 0xFF");
for(i = 0; i < 8192 ; i++) *((u_char xdata*)(RECV_DATA_BUF+i)) = i % 0x100;
PutStringLn("\tVerify Tx Memory");
for(i = 8191; i > -1 ; i--)
{
val = *((u_char xdata*)(RECV_DATA_BUF+i));
if(val != (u_char)(i % 0x100))
{
PutString("\t Verify fail at 0x");PutITOA(0x4000+i);
PutString(" : Write Value = 0x");PutHTOA(i%0x100);PutString(", Read Value = 0x");
PutHTOA(val);PutStringLn("");
IsVerifyOK = 0;
}
}
if(IsVerifyOK) PutStringLn("\tVerify OK - RX Memory");
else PutStringLn("\tVerify Fail - RX Memory");
COMMAND(1) = 0x80; // Clear Memory Test Mode
/* Test shadow regs and pointer regs */
IsVerifyOK = 1;
PutStringLn("\r\nTEST 3. SHADOWS AND POINTERS");
PutStringLn("\tWrite pointer registes to a number");
for(i = 0; i < MAX_SOCK_NUM; i++)
{
// Write rx_wr_ptr register to a number
*RX_WR_PTR(i) = 0xF0;
*(RX_WR_PTR(i)+1) = 0xDC;
*(RX_WR_PTR(i)+2) = 0xBA;
*(RX_WR_PTR(i)+3) = 0x90+i;
Delay(2); // When you write pointer-regisers continuously, wait over 1.6us
// Write wr_rx_ptr register
*RX_RD_PTR(i) = 0xF0;
*(RX_RD_PTR(i)+1) = 0xDC;
*(RX_RD_PTR(i)+2) = 0xBA;
*(RX_RD_PTR(i)+3) = 0x90+i+4;
Delay(2); // When you write pointer-regisers continuously, wait over 1.6us
// Write tx_wr_ptr register
*TX_WR_PTR(i) = 0xF1;
*(TX_WR_PTR(i)+1) = 0xDC;
*(TX_WR_PTR(i)+2) = 0xBA;
*(TX_WR_PTR(i)+3) = 0x90+i;
Delay(2); // When you write pointer-regisers continuously, wait over 1.6us
// Write tx_rd_ptr register
*TX_WR_PTR(i) = 0xF1;
*(TX_RD_PTR(i)+1) = 0xDC;
*(TX_RD_PTR(i)+2) = 0xBA;
*(TX_RD_PTR(i)+3) = 0x90+i+4;
Delay(2); // When you write pointer-regisers continuously, wait over 1.6us
// Write tx_ack_ptr register
*TX_ACK_PTR(i) = 0xF1;
*(TX_ACK_PTR(i)+1) = 0xDC;
*(TX_ACK_PTR(i)+2) = 0xBA;
*(TX_ACK_PTR(i)+3) = 0x90+i+8;
}
PutStringLn("\tVerify pointer registes");
for(i = 0 ; i < MAX_SOCK_NUM ; i++)
{
// Verify rx_wr_ptr register
val = *SHADOW_RXWR_PTR(i); // To read 4byte pointer registers, first you must read its shadow register.
Delay(2); // After you read shadow register, wait over 1.6us
ptr[0] = *RX_WR_PTR(i); // Read rx_wr_ptr;
ptr[1] = *(RX_WR_PTR(i)+1);
ptr[2] = *(RX_WR_PTR(i)+2);
ptr[3] = *(RX_WR_PTR(i)+3);
if(*((long*)ptr) != 0xF0DCBA90+i)
{
PutString("\t Verify fail at RX_WR_PTR(");PutHTOA(i);
PutString(") : Write = 0x");PutLTOA(0xF0DCBA90+i);PutString(", Read = 0x");
PutLTOA(*((long*)ptr));PutStringLn("");
IsVerifyOK = 0;
}
// Verify rx_rd_ptr register
val = *SHADOW_RXRD_PTR(i);
Delay(2);
ptr[0] = *RX_RD_PTR(i);
ptr[1] = *(RX_RD_PTR(i)+1);
ptr[2] = *(RX_RD_PTR(i)+2);
ptr[3] = *(RX_RD_PTR(i)+3);
if(*((long*)ptr) != 0xF0DCBA90+i+4)
{
PutString("\t Verify fail at RX_RD_PTR(");PutHTOA(i);
PutString(") : Write = 0x");PutLTOA(0xF0DCBA90+i+4);PutString(", Read = 0x");
PutLTOA(*((long*)ptr));PutStringLn("");
IsVerifyOK = 0;
}
// Verify tx_wr_ptr register
val = *SHADOW_TXWR_PTR(i);
Delay(2);
ptr[0] = *TX_WR_PTR(i);
ptr[1] = *(TX_WR_PTR(i)+1);
ptr[2] = *(TX_WR_PTR(i)+2);
ptr[3] = *(TX_WR_PTR(i)+3);
if(*((long*)ptr) != 0xF1DCBA90+i)
{
PutString("\t Verify fail at TX_WR_PTR(");PutHTOA(i);
PutString(") : Write = 0x");PutLTOA(0xF1DCBA90+i);PutString(", Read = 0x");
PutLTOA(*((long*)ptr));PutStringLn("");
IsVerifyOK = 0;
}
// Verify tx_rd_ptr register
val = *SHADOW_TXRD_PTR(i);
Delay(2);
ptr[0] = *TX_WR_PTR(i);
ptr[1] = *(TX_RD_PTR(i)+1);
ptr[2] = *(TX_RD_PTR(i)+2);
ptr[3] = *(TX_RD_PTR(i)+3);
if(*((long*)ptr) != 0xF1DCBA90+i+4)
{
PutString("\t Verify fail at TX_RD_PTR(");PutHTOA(i);
PutString(") : Write = 0x");PutLTOA(0xF1DCBA90+i+4);PutString(", Read = 0x");
PutLTOA(*((long*)ptr));PutStringLn("");
IsVerifyOK = 0;
}
// Verify tx_ack_ptr register
val = *SHADOW_TXACK_PTR(i);
Delay(2);
ptr[0] = *TX_ACK_PTR(i);
ptr[1] = *(TX_ACK_PTR(i)+1);
ptr[2] = *(TX_ACK_PTR(i)+2);
ptr[3] = *(TX_ACK_PTR(i)+3);
if(*((long*)ptr) != 0xF1DCBA90+i+8)
{
PutString("\t Verify fail at TX_ACK_PTR(");PutHTOA(i);
PutString(") : Write = 0x");PutLTOA(0xF1DCBA90+i+8);PutString(", Read = 0x");
PutLTOA(*((long*)ptr));PutStringLn("");
IsVerifyOK = 0;
}
}
if(IsVerifyOK) PutStringLn("\tVerify OK - SHADOW and POINTER regs");
else PutStringLn("\tVerify Fail - SHADOW and POINTER regs");
/* Configure network to satisfy yours */
PutStringLn("\r\nTEST 4. Initialize W3100A and configure network, and command sys_init");
COMMAND(0) = 0x80; // Initialize W3100A
*GATEWAY_PTR = 192; // Set Gateway IP address
*(GATEWAY_PTR+1) = 168;
*(GATEWAY_PTR+2) = 0;
*(GATEWAY_PTR+3) = 1;
*(SUBNET_MASK_PTR) = 255; // Set subnet mask
*(SUBNET_MASK_PTR+1) = 255;
*(SUBNET_MASK_PTR+2) = 255;
*(SUBNET_MASK_PTR+3) = 0;
*SRC_HA_PTR = 0x00; // Set MAC Address
*(SRC_HA_PTR+1)= 0x08;
*(SRC_HA_PTR+2)= 0xDC;
*(SRC_HA_PTR+3)= 0x00;
*(SRC_HA_PTR+4)= 0x00;
*(SRC_HA_PTR+5)= 0x00;
*SRC_IP_PTR = 192; // Set Source IP Address
*(SRC_IP_PTR+1) = 168;
*(SRC_IP_PTR+2) = 0;
*(SRC_IP_PTR+3) = 2;
i = 0;
PutStringLn("\r\nTEST 5. OCCURRENCE OF INTERRUPT.");
COMMAND(0) = 0x01;
while(!IsISROK )if(i++==0xFFFF) break;
if(IsISROK)
{
if(INT_REG != 0)
PutStringLn("\tInterrupt register is not cleared.");
else
PutStringLn("\tInterrupt register is cleared.");
if(INT_STATUS(0) != 0)
PutStringLn("\tInterrupt status register is not cleared.");
else
PutStringLn("\tInterrupt status register is cleared.");
PutStringLn("\r\nTEST 6. using dos-command prompt, pinging your target board");
}
else
{
PutStringLn("Verify fail : Interrupt is not occurred.");
}
while(1);
}
/*
********************************************************************************
* 8051 Initialization Function
*
* Description:
* Arguments : None.
* Returns : None.
* Note :
********************************************************************************
*/
void Init8051(void)
{
EA = 0; // Disable all interrupts
CKCON = 0x01; // X2 Mode
IT0 = 0; // interrupt level trigger
EX0 = 1; // INT 0 enable
EX1 = 0; // INT 1 disable
EA = 1; // Enable all interrupts
InitSerial(); // Initialize serial port (Refer to serial.c)
}
/*
********************************************************************************
* Delay function
*
* Description:
* Arguments : delay - loop count
* Returns : None.
* Note :
********************************************************************************
*/
void Delay(u_int delay)
{
for(; delay > 0; delay--);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -