📄 boardtest.c
字号:
/*
//====================================================================
// File Name : boardtest.c
// Function : DM642 Video Board Test Main Menu
// Programer : Zengyi
// Company : CATlab Fudan university
// Date : Sep 28, 2005
// Version : 0.1
// History
// 0.0 : Programming start (Sep 20,2004) -> Cat
// 0.1 : Add SDRAM ,CPLD, FLash Test
//====================================================================
*/
#include <stdio.h>
#include <std.h>
#include <sys.h>
#include <evmdm642.h>
#include <evmdm642_flash.h>
#include <evmdm642_uart.h>
#include <evmdm642_led>
//#define DEBUG
void InitEMIF(); // 初始化EMIF
Int16 MEM_fill(Uint32 start, Uint32 len, Uint32 val)
{
Uint32 i, end;
Uint32 value;
/* Calculate end of range */
end = start + len;
/* Fill a range with a value */
for (i = start; i < end; i+=4)
{
*((Uint32 *)i) = val;
}
/* Verify the data */
for (i = start; i < end; i+=4)
{
value=*((Uint32 *)i);
if (value !=val)
return 1;
}
return 0;
}
Int16 MEM_addr(Uint32 start, Uint32 len)
{
Uint32 i, end, err_count;
Uint8 bias;
err_count = 0;
/* Calculate end of range */
end = start + len;
/* Fill the range with its address */
for (bias = 0; bias < 0x1; bias++)
{
for (i = start; i < end; i+=4)
{
*((Uint32 *)i) = i+bias;
}
/* Verify the data */
for (i = start; i < end; i+=4)
if (*((Uint32 *)i) != i+bias)
err_count++;
}
return err_count;
}
Int16 MEM_addrInv(Uint32 start, Uint32 len)
{
Uint32 i, end, err_count;
Uint8 bias;
err_count = 0;
/* Calculate end of range */
end = start + len;
/* Fill the range with its address */
for (bias = 0; bias < 0x01; bias++)
{
for (i = start; i < end; i+=4)
{
*((Uint32 *)i) = ~(i+bias);
}
/* Verify the data */
for (i = start; i < end; i+=4)
if (*((Uint32 *)i) != (~(i+bias)))
err_count++;
}
return err_count;
}
Int16 MEM_test(Uint32 start, Uint32 len, Int16 patterntype)
{
Int16 status = 0;
if (!patterntype)
{
/* Run the fill tests */
status |= MEM_fill(start, len, 0x00000000);
status |= MEM_fill(start, len, 0x55555555);
status |= MEM_fill(start, len, 0xAAAAAAAA);
status |= MEM_fill(start, len, 0xFFFFFFFF);
} else
{
/* Run the address tests */
status |= MEM_addr(start, len);
status |= MEM_addrInv(start, len);
}
return status;
}
/*
* POST tests
*/
Int16 TEST_intMem()
{
Int16 status = 0;
/* Check internal memory (byte 0x20000 to byte 0x40000) */
status |= MEM_test(0x20000, 0x20000, 0);
status |= MEM_test(0x20000, 0x20000, 1);
return status;
}
Int16 TEST_extMem()
{
Int16 status = 0;
/* Check external memory (byte 0x80000000 to byte 0x82000000) */
status |= MEM_test(0x80000000, 0x02000000, 0);
status |= MEM_test(0x80000000, 0x02000000, 1);
return status;
}
Int16 TEST_flashID()
{
Uint8 MfgId,DevId1,DevId2,DevId3;
Int16 i;
/* Reset flash */
*((Uint8 *)EVMDM642_FLASH_BASE) = 0xf0;
/* Configure to read manufacturer ID */
*((Uint8 *)EVMDM642_FLASH_BASE+0xAAA) = 0xaa;
*((Uint8 *)EVMDM642_FLASH_BASE+0x555) = 0x55;
*((Uint8 *)EVMDM642_FLASH_BASE+0xAAA) = 0x90;
//*((Uint8 *)EVMDM642_FLASH_BASE+0x00) = 0x01;
/* Insert small delay for device to respond */
for (i = 0; i < 10; i++);
/* Read IDs */
MfgId = *((Uint8 *)EVMDM642_FLASH_BASE);
DevId1 = *((Uint8 *)EVMDM642_FLASH_BASE + 0x02);
DevId2 = *((Uint8 *)EVMDM642_FLASH_BASE + 0x1C);
DevId3 = *((Uint8 *)EVMDM642_FLASH_BASE + 0x1E);
/* Reset flash */
*((Uint8 *)EVMDM642_FLASH_BASE) = 0xf0;
/* Check IDs */
if ((MfgId != 0x01) || (DevId1 != 0x7E) || (DevId2 != 0x1A) || (DevId3 != 0x00))
return 1;
/* Test passed */
return 0;
}
Int16 TEST_FlashWrite()
{
Uint32 i,flash_waddr,psrc_start,readb_start,length;
psrc_start=0x80000000;
readb_start=psrc_start+0x00100000;
length=0x00020000;
flash_waddr=EVMDM642_FLASH_BASE+0x00010000;
//constructing orig data
for (i = psrc_start; i < (psrc_start+length); i+=4) {
*((Uint32 *)i) = i;
}
//reset Flash
EVMDM642_rset(EVMDM642_CPLD_RESET,0xFB);
EVMDM642_waitusec(10);
//bring back from Reset
EVMDM642_rset(EVMDM642_CPLD_RESET,0xFF);
//erase used sectors
EVMDM642_FLASH_erase(flash_waddr,length,TRUE);
EVMDM642_FLASH_write(psrc_start,flash_waddr,length);
EVMDM642_FLASH_read(flash_waddr,readb_start,length);
for(i=0;i < length; i+=4) {
if(*(Uint32 *)psrc_start != *(Uint32 *)readb_start)
return 1;
psrc_start+=4;
readb_start+=4;
}
return 0;
}
/* ------------------ End Debug Code --------------------------------*/
void TEST_execute(Int16 (*funchandle)(), char *testname, Int16 ledmask, Int16 insertdelay)
{
Int16 status;
/* Display test ID */
#ifdef DEBUG
printf("%02d Testing %s...\n", ledmask, testname);
#endif
/* Call test function */
status = funchandle();
/* Check for test fail */
if (status > 0)
{
/* Print error message */
#ifdef DEBUG
printf(" FAIL... error code %d... quitting\n", status, testname);
#endif
/* Software breakpoint */
asm(" .long 0x10000000");
} else
{
/* Print error message */
#ifdef DEBUG
printf(" PASS\n", testname);
#endif
}
}
//Test LED
void LED_binary(Int16 ledmask)
{
Int16 i, bit;
/* Walk through the bits in num setting corresponding LEDs */
bit = 1;
for (i = 0; i < 8; i++)
{
if (ledmask & bit)
EVMDM642_LED_on(i);
else
EVMDM642_LED_off(i);
bit = bit << 1;
}
}
Int16 TEST_led()
{
Uint32 i;
EVMDM642_LED_init();
for (i = 0; i < 10; i++)
{
LED_binary(0xaa);
EVMDM642_waitusec(500000);
LED_binary(0x55);
EVMDM642_waitusec(500000);
}
LED_binary(0xff);
return 0;
}
Int16 TEST_version()
{
Uint8 boardversion,cpldversion;
boardversion=EVMDM642_rget(EVMDM642_CPLD_BOARDVER);
cpldversion=EVMDM642_rget(EVMDM642_CPLD_CPLDVER);
if(boardversion == 0x03 && cpldversion == 0x02) {
#ifdef DEBUG
printf("BoardVersion is 0.%d, CPLD Version is 0.%d\n",boardversion,cpldversion);
#endif
return 0;
}
else
return 1;
}
Int16 TEST_uartA(void)
{
Uint16 rev_char;
EVMDM642_UART_Handle uartA_Handle;
EVMDM642_UART_Config *uartA_config=(void*)malloc(sizeof(EVMDM642_UART_Config));
uartA_config->regs[0]=0x00; //EVMDM642_UART_IER
uartA_config->regs[1]=0x57; //EVMDM642_UART_FCR
uartA_config->regs[2]=0x03; //EVMDM642_UART_LCR
uartA_config->regs[3]=0x00; //EVMDM642_UART_MCR
EVMDM642_UART_reset(); //reset uart
uartA_Handle=EVMDM642_UART_open(0,EVMDM642_UART_BAUD115200,uartA_config);
while((rev_char=EVMDM642_UART_getChar(uartA_Handle))!=0xff) {
EVMDM642_UART_putChar(uartA_Handle,rev_char);
}
return 0;
}
main()
{
/* Call BSL init */
EVMDM642_init();
InitEMIF();
#ifdef DEBUG
printf("Now Let's Begin Board Test\n");
#endif
EVMDM642_waitusec(1000);
/* Run the tests sequentially */
TEST_execute(TEST_version, "Versions", 1, 0);
//TEST_execute(TEST_led, "LEDs", 2, 0);
//TEST_execute(TEST_extMem, "SDRAM", 3, 0);
//TEST_execute(TEST_flashID, "Flash ID", 4, 1);
TEST_execute(TEST_FlashWrite, "Flash Write", 5, 1);
//TEST_execute(TEST_uartA, "Uart A" ,6 ,0);
while(1){};
}
// 初始化EMIF接口
void InitEMIF()
{
#define EMIFA_GCTL 0x01800000
#define EMIFA_CE0 0x01800008
#define EMIFA_CE1 0x01800004
#define EMIFA_CE2 0x01800010
#define EMIFA_SDRAMCTL 0x01800018
#define EMIFA_SDRAMTIM 0x0180001c
#define EMIFA_SDRAMEXT 0x01800020
#define EMIFA_CE0SECCTL 0x01800048
/* EMIFA */
*(int *)EMIFA_GCTL = 0x00052078; /* Global Control Register GBLCTL */
*(int *)EMIFA_CE0 = 0xffffffd3; /* CE0 SDRAM */
*(int *)EMIFA_CE1 = 0x73a28e01; /* CE1 Flash + CPLD */
*(int *)EMIFA_SDRAMTIM = 0x0000081b; /* SDRAM 刷新时序 */
*(int *)EMIFA_SDRAMEXT = 0x001faf4d; /* SDRAM 扩展控制 */
*(int *)EMIFA_CE0SECCTL= 0x00000003; /* CE0 第二控制寄存器 */
*(int *)EMIFA_SDRAMCTL = 0x57115000; /* SDRAM 控制 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -