⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_eeprom.c

📁 EEPROM测试程序
💻 C
字号:


/*
 *  ======== test.c ========

 *  Index   Description
 *    1     SDRAM
 *    2     I2C EEPROM
 */


#include "test_eepromcfg.h"

#include <stdio.h>
#include <std.h>
#include <sys.h>
#include <csl.h>
#include <csl_mcbsp.h>
#include <csl_timer.h>
#include <csl_edma.h>
#include <csl_vic.h>
#include <csl_mcasp.h>
#include <csl_gpio.h>
#include <csl_pci.h>

#include <csl_emifa.h>
#include <csl_cache.h>

#include "evmdm642.h"
#include "evmdm642_led.h"
#include "evmdm642_aic23.h"
#include "evmdm642_flash.h"
#include "evmdm642_eeprom.h"
#include "evmdm642_uart.h"
#include "evmdm642_apll.h"
#include "evmdm642_pci.h"

#define N                16
Uint16 src[N], dst[N], buffer[256];

/*
 *  Memory functions
 */
 
Int16 MEM_fill(Uint32 start, Uint32 len, Uint32 val)
{
    Uint32 i, end;
    
    /* 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)
    {	
        if (*((Uint32 *)i) != val)
        {
        	printf("error addr %x rdata %x wdata %x \n", i, val ,*((Uint32 *)i) );
        	//return 1;
        }
    }
    return 0;
}

Int16 MEM_addr(Uint32 start, Uint32 len)
{
    Uint32 i, end;
    
    /* Calculate end of range */
    end = start + len;
    
    /* Fill the range with its address */
    for (i = start; i < end; i+=4)
    {
        *((Uint32 *)i) = i;
    }

    /* Verify the data */
    for (i = start; i < end; i+=4)
    {
        if (*((Uint32 *)i) != i)
        {
        	printf("     error addr %x data %x\n", i,*((Uint32 *)i) );
        //    return 2;
        }
    }
    return 0;
}

Int16 MEM_addrInv(Uint32 start, Uint32 len)
{
    Uint32 i, end;
    
    /* Calculate end of range */
    end = start + len;
    
    /* Fill the range with its address */
    for (i = start; i < end; i+=4)
    {
        *((Uint32 *)i) = ~i;
    }

    /* Verify the data */
    for (i = start; i < end; i+=4)
        if (*((Uint32 *)i) != (~i))
            return 4;
    
    return 0;
}

Int16 MEM_walking(Uint32 add)
{
    Int16 i;
    Uint32 mask, *pdata;
    
    pdata = (Uint32 *)add;

    /* Walking ones and zeros */
    mask = 1;
    for (i = 0; i < 32; i++)
    {
        /* Test one in bit position i */
        *pdata = mask;
        
        /* Do a dummy write to Flash to clear bus */
        *((Uint8 *)EVMDM642_FLASH_BASE) = 0xf0;
        
        /* Check data */
        if (*pdata != mask)
            return 1;
            
        /* Test zero in bit position i */
        *pdata = ~mask;
        
        /* Do a dummy write to Flash to clear bus */
        *((Uint8 *)EVMDM642_FLASH_BASE) = 0xf0;

        /* Check data */
        if (*pdata != (~mask))
            return 8;
            
        mask = mask << 1;
    }
    
    return 0;
}

Int16 MEM_bytestrobe(Uint32 add)
{
    Uint32 *pdata;
    Uint8 *pcheck;
    
    /* Write pattern */
    pdata = (Uint32 *)add;
    *pdata = 0x12345678;
    
    /* Do dummy write */
    pdata = (Uint32 *)EVMDM642_FLASH_BASE;
    *pdata = 0x80808080;
    
    /* Check pattern */
    pcheck = (Uint8 *)add;
    if (*pcheck++ != 0x78)
        return 0x10;
    if (*pcheck++ != 0x56)
        return 0x20;
    if (*pcheck++ != 0x34)
        return 0x40;
    if (*pcheck++ != 0x12)
        return 0x80;
        
    return 0;
}

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);
//    status |= MEM_walking(0x20000);
      
    return status;
}

Int16 TEST_extMem()
{
    Int16 status = 0;
    
    /* Check external memory (byte 0x80000000 to byte 0x82000000) */
    status |= MEM_test(0x80000000, 0x02000000, 0);//test fill
//    status |= MEM_test(0x80000000, 0x02000000, 1);//test address
//    status |= MEM_walking(0x80000000);
//    status |= MEM_bytestrobe(0x80000000);
         
    return status;
}


Int16 TEST_eeprom()
{
    Uint16 page, i;
    Uint8 *pdata;
    
    /* Write a pattern */
    for (page = 0; page < 4; page++)
    {
        pdata = (Uint8 *)buffer;
        for (i = 0; i < 64; i++)
            *pdata++ = (page + i) & 0xff;
        EVMDM642_EEPROM_write((Uint32)buffer, page << 6, 64);
    }
    
    /* Verify the pattern */
    for (page = 0; page < 4; page++)
    {
        EVMDM642_EEPROM_read(page << 6, (Uint32)buffer, 64);
        pdata = (Uint8 *)buffer;
        for (i = 0; i < 64; i++)
            if (*pdata++ != (page + i) & 0xff)
                return 1;  // Fail
    }
    
    return 0;
}


/* ------------------ Start Debug Code -------------------------------*/

void DEBUG_memLoop()
{
    volatile Uint8 *pdata, data;
    
    pdata = (Uint8 *)0x90080000;
    while(1)
    {
        data = *pdata;
    }
}

/* ------------------  End Debug Code --------------------------------*/

void TEST_execute(Int16 (*funchandle)(), char *testname, Int16 ledmask, Int16 insertdelay)
{
    Int16 status;
    
    /* Display test ID */
    printf("%02d  Testing %s...\n", ledmask, testname);
    
    /* Call test function */
    status = funchandle();
    
    /* Check for test fail */
    if (status > 0)
    {
        /* Print error message */
        printf("     FAIL... error code %d... quitting\n", status, testname);
        
        /* Software breakpoint */
        asm(" .long 0x10000000");
    } else
    {
        /* Print error message */
        printf("    PASS\n", testname);
    }
}


main()
{
    /* Call BSL init */
    CSL_init();
    printf("\n*** Hello ***\n");
    
    /* Run the tests sequentially */
    TEST_execute(TEST_extMem,    "SDRAM",           1, 0);
    //TEST_execute(TEST_eeprom,    "I2C EEPROM",      2, 0);

    /* Success */
    printf("\n*** All tests PASS ***\n");
    
    /* Disable interrupts */
    IRQ_globalDisable();

    /* Software breakpoint */
    asm(" .long 0x10000000");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -