Files
luban-lite/kernel/common/debug/aic_memtest_cmd.c
刘可亮 564e22b32f v0.7.5
2023-08-28 09:48:01 +08:00

169 lines
4.0 KiB
C

/*
* Copyright (c) 2022, ArtInChip Technology Co., Ltd
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <rtconfig.h>
#ifdef RT_USING_FINSH
#include <rthw.h>
#include <rtthread.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <finsh.h>
#include "aic_osal.h"
#define printf rt_kprintf
struct memtest_para
{
long address;
u32 size;
char thread_name[32];
};
u8 do_mem_test(long address, u32 size)
{
u32 i;
/**< 8bit test */
{
u8 * p_u8 = (u8 *)address;
for(i=0; i<size/sizeof(u8); i++)
{
*p_u8++ = (u8)i;
}
p_u8 = (u8 *)address;
for(i=0; i<size/sizeof(u8); i++)
{
if( *p_u8 != (u8)i )
{
printf("8bit test fail @ 0x%08X\r\nsystem halt!!!!!",(long)p_u8);
return 1;
}
p_u8++;
}
}
/**< 16bit test */
{
u16 * p_u16 = (u16 *)address;
for(i=0; i<size/sizeof(u16); i++)
{
*p_u16++ = (u16)i;
}
p_u16 = (u16 *)address;
for(i=0; i<size/sizeof(u16); i++)
{
if( *p_u16 != (u16)i )
{
printf("16bit test fail @ 0x%08X\r\nsystem halt!!!!!",(long)p_u16);
return 1;
}
p_u16++;
}
}
/**< 32bit test */
{
u32 * p_u32 = (u32 *)address;
for(i=0; i<size/sizeof(u32); i++)
{
*p_u32++ = (u32)i;
}
p_u32 = (u32 *)address;
for(i=0; i<size/sizeof(u32); i++)
{
if( *p_u32 != (u32)i )
{
printf("32bit test fail @ 0x%08X\r\nsystem halt!!!!!",(long)p_u32);
return 1;
}
p_u32++;
}
}
/**< 32bit Loopback test */
{
u32 * p_u32 = (u32 *)address;
for(i=0; i<size/sizeof(u32); i++)
{
*p_u32 = (long)p_u32;
p_u32++;
}
p_u32 = (u32 *)address;
for(i=0; i<size/sizeof(u32); i++)
{
if( *p_u32 != (long)p_u32 )
{
printf("32bit Loopback test fail @ 0x%08X", (long)p_u32);
printf(" data:0x%08X \r\n", (u32)*p_u32);
printf("system halt!!!!!",(long)p_u32);
return 1;
}
p_u32++;
}
}
return 0;
}
static void memtest_thread(void *arg)
{
struct memtest_para para;
memset(&para, 0, sizeof(struct memtest_para));
memcpy(&para, arg, sizeof(struct memtest_para));
long loop_times = 0;
u8 ret = 0;
printf("memtest,address: 0x%08X size: 0x%08X\r\n", para.address, para.size);
do{
loop_times ++;
ret = do_mem_test(para.address, para.size);
if (ret) {
printf("[failed] %s, loop_times=%d\n", para.thread_name, loop_times);
break;
}
aicos_msleep(1000);
printf("[success] %s, loop_times=%d\n", para.thread_name, loop_times);
}while(1);
printf("%s finish \n", para.thread_name);
}
static void cmd_mem_test(int argc, char **argv)
{
u32 address;
u32 size;
rt_thread_t thid;
char thread_name[32]={0};
struct memtest_para para;
memset(&para, 0, sizeof(struct memtest_para));
char *str_tmp;
if (argc < 3) {
printf("Invalid parameter\n");
return ;
}
address = strtol(argv[1], &str_tmp, 16);
size = strtol(argv[2], &str_tmp, 16);
sprintf(thread_name, "memtest_0x%x-0x%x\n", address, address + size);
sprintf(para.thread_name, "memtest_0x%x-0x%x", address, address + size);
para.address = address;
para.size = size;
thid = aicos_thread_create(thread_name, 4096, 10, memtest_thread, &para);
if (thid == NULL) {
printf("Failed to create \"memtest_0x%lx-0x%lx\" thread\n", address, address + size);
return ;
}
return ;
}
MSH_CMD_EXPORT_ALIAS(cmd_mem_test, mem_test, memory test: mem_test address_hex size_hex);
#endif /* RT_USING_FINSH */