rtt-f030/bsp/imxrt1052-evk/applications/mem_test.c

104 lines
2.7 KiB
C

#include <stdint.h>
#include <rthw.h>
#include <rtthread.h>
void mem_test(uint32_t address, uint32_t size )
{
uint32_t i;
rt_kprintf("memtest,address: 0x%08X size: 0x%08X\r\n", address, size);
/**< 8bit test */
{
uint8_t * p_uint8_t = (uint8_t *)address;
for(i=0; i<size/sizeof(uint8_t); i++)
{
*p_uint8_t++ = (uint8_t)i;
}
p_uint8_t = (uint8_t *)address;
for(i=0; i<size/sizeof(uint8_t); i++)
{
if( *p_uint8_t != (uint8_t)i )
{
rt_kprintf("8bit test fail @ 0x%08X\r\nsystem halt!!!!!",(uint32_t)p_uint8_t);
while(1);
}
p_uint8_t++;
}
rt_kprintf("8bit test pass!!\r\n");
}
/**< 16bit test */
{
uint16_t * p_uint16_t = (uint16_t *)address;
for(i=0; i<size/sizeof(uint16_t); i++)
{
*p_uint16_t++ = (uint16_t)i;
}
p_uint16_t = (uint16_t *)address;
for(i=0; i<size/sizeof(uint16_t); i++)
{
if( *p_uint16_t != (uint16_t)i )
{
rt_kprintf("16bit test fail @ 0x%08X\r\nsystem halt!!!!!",(uint32_t)p_uint16_t);
while(1);
}
p_uint16_t++;
}
rt_kprintf("16bit test pass!!\r\n");
}
/**< 32bit test */
{
uint32_t * p_uint32_t = (uint32_t *)address;
for(i=0; i<size/sizeof(uint32_t); i++)
{
*p_uint32_t++ = (uint32_t)i;
}
p_uint32_t = (uint32_t *)address;
for(i=0; i<size/sizeof(uint32_t); i++)
{
if( *p_uint32_t != (uint32_t)i )
{
rt_kprintf("32bit test fail @ 0x%08X\r\nsystem halt!!!!!",(uint32_t)p_uint32_t);
while(1);
}
p_uint32_t++;
}
rt_kprintf("32bit test pass!!\r\n");
}
/**< 32bit Loopback test */
{
uint32_t * p_uint32_t = (uint32_t *)address;
for(i=0; i<size/sizeof(uint32_t); i++)
{
*p_uint32_t = (uint32_t)p_uint32_t;
p_uint32_t++;
}
p_uint32_t = (uint32_t *)address;
for(i=0; i<size/sizeof(uint32_t); i++)
{
if( *p_uint32_t != (uint32_t)p_uint32_t )
{
rt_kprintf("32bit Loopback test fail @ 0x%08X", (uint32_t)p_uint32_t);
rt_kprintf(" data:0x%08X \r\n", (uint32_t)*p_uint32_t);
rt_kprintf("system halt!!!!!",(uint32_t)p_uint32_t);
while(1);
}
p_uint32_t++;
}
rt_kprintf("32bit Loopback test pass!!\r\n");
}
}
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT(mem_test, mem_test(0xA0000000, 0x00100000) );
#endif