📄 mem_lib.c
字号:
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* source\mem_lib.c 1.0 */
/* */
/* DESCRIPTION */
/* */
/* DIAGNOSTIC CODE for S3C4510B0 */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* FUNCTIONS : memory test routine and library */
/* */
/* DEPENDENCIES */
/* */
/* */
/* NAME: Nicolas Park */
/* The last Modification date: 18-April-2002 */
/* REMARKS: Created initial version 1.0 */
/* */
/* Copyright (C) 2002 AIJISYSTEM CO.,LTD */
/*************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "s3c4510b0.h"
#include "uart.h"
#include "isr.h"
#include "std.h"
#include "memory.h"
#include "pollio.h"
#include "sysconf.h"
extern char Image$$RW$$Limit[];
void *mallocPt=Image$$RW$$Limit;
void *nmallocPt = (void *)AllocNonCacheAreaBase ;
void MemoryPartTest(void)
{
char TestItemSel ;
do {
Print("\n") ;
Print("\n##############################################\r") ;
Print("\n# Memory Test #\r") ;
Print("\n##############################################\r") ;
Print("\n# 1. Memory Copy Test - [C] #\r") ;
Print("\n# 2. Memory Dump - [R] #\r") ;
Print("\n# 3. Memory Pattern Fill - [F] #\r") ;
Print("\n# 4. Memory Pattern Search - [S] #\r") ;
Print("\n# 5. External I/O Bank Test - [E] #\r") ;
Print("\n# Quit - [Q] #\r") ;
Print("\n##############################################\r") ;
Print("\n\rSelect Test Item : ") ;
TestItemSel = get_byte() ;
switch(TestItemSel)
{
case 'C' : case 'c' :case '1' : MemoryTest() ; break ;
case 'R' : case 'r' :case '2' : MemoryDump() ; break ;
case 'F' : case 'f' :case '3' : MemPatternFill() ; break ;
case 'S' : case 's' :case '4' : MemPatternSearch(); break ;
case 'E' : case 'e' :case '5' : ExtIOBankTest(); break ;
case 'Q' : case 'q' : break ;
default : Print("\n\nInvalid Test Item Selected") ;
break ;
}
Print("\n\n Press Any Key To Continue ....") ; get_byte() ;
} while ( (TestItemSel != 'Q') && (TestItemSel != 'q') ) ;
IOPDATA = 0x0F ;
}
void MemoryDump(void)
{
U32 DumpInitAdd, DumpSize ;
U32 *base; // Dump Memory base address
U32 *end; // Dump Memory end address
Print("\n\n >> Input Memory Dump Base Address (0x1000000) : 0x") ;
DumpInitAdd = get_num() ;
if (DumpInitAdd==0) DumpInitAdd=0x1000000 ;
Print("\n\r >> Input Memory Dump Size (0x100) : 0x") ;
DumpSize = get_num() ;
if (DumpSize==0) DumpSize=0x100 ;
base = (U32 *)DumpInitAdd;
end = (U32 *)(DumpInitAdd + DumpSize) ;
Print("\n\nMemory Dump from %x to %x",base, end) ;
MemDump(base, end);
}
void MemDump(U32 *base, U32 *end)
{
int i;
int j;
int k;
int Range;
U32 *DumpBase;
U32 *DumpEnd ;
DumpBase = base;
DumpEnd = end;
Range=DumpEnd-DumpBase ;
k=0; j=0;
for (i=0;i < Range+4;i+=j)
if (k==20) {
Print("\n\nPress Any Key");
get_byte();k=0;}
else {
k++;
{
Print("\n\r%8x : ",DumpBase) ;
j=0;
for (j=0; j<4 ; j++)
{
Print(" %08x ",*DumpBase) ;
DumpBase++ ;
}
}
}
}
void MemClear(U32 *startaddr, U32 *endaddr)
{
int cnt ;
cnt = (int)(endaddr - startaddr) ;
while(cnt--) *startaddr++ = 0x00000000 ;
}
void MemPatternFill(void)
{
U32 *StartAddr, *EndAddr ;
U32 Pattern ;
int cnt ;
Print("\n\n >>> Memory Pattern Fill <<< ") ;
Print("\n\r $$ Memory Pattern Fill Start Address : 0x") ;
StartAddr = (U32 *)get_num() ;
Print("\n\r $$ Memory Pattern Fill End Address : 0x") ;
EndAddr = (U32 *)get_num() ;
Print("\n\r $$ Memor Fill Pattern : 0x") ;
Pattern = get_num() ;
cnt = (int)(EndAddr - StartAddr) ;
Print("\n\n >> Memory Fill %x to %x, Pattern : %x",\
StartAddr, EndAddr,Pattern) ;
while(cnt--) *StartAddr++ = Pattern ;
}
void MemPatternSearch(void)
{
U32 *StartAddr, *EndAddr ;
U32 Pattern ;
int cnt ;
Print("\n >>> Memory Pattern Search <<< ") ;
Print("\n\r $$ Memory Pattern Search Start Address : 0x") ;
StartAddr = (U32 *)get_num() ;
Print("\n\r $$ Memory Pattern Search End Address : 0x") ;
EndAddr = (U32 *)get_num() ;
Print("\n\r $$ Memory Search Pattern : 0x") ;
Pattern = get_num() ;
cnt = (int)(EndAddr - StartAddr) ;
Print("\n\n >> Memory Pattern Search 0x%x to 0x%x, Pattern : %x\n", \
StartAddr, EndAddr,Pattern) ;
while(cnt--)
{
if (*StartAddr == Pattern)
Print("\n\r +-- Pattern is Searched : %x (%x)",\
StartAddr, *StartAddr);
StartAddr++ ;
}
}
void MemoryTest(void)
{
U32 MemCopyDest ; // Input Memory Test Address
U32 MemTestSize ; // Input Memory Test Size
U32 *src; // Memory source address
U32 *dst; // Memory destination address
int tsize; // Memory Test size
int lsize; // memory test loop size
Print("\n\n >> Input Memory Test Location(0x1200000) : 0x") ;
MemCopyDest = get_num() ;
if (MemCopyDest==0) MemCopyDest=0x1200000 ;
Print("\n\n >> Input Memory Test Size(0x10000) : 0x") ;
MemTestSize = get_num() ;
if (MemTestSize==0) MemTestSize=0x10000 ;
Print("\n\n >> Input Memory Test repeat number(0x10000) : 0x") ;
lsize = get_num();
if (lsize==0) lsize=(int)MemTestLoop;
src = (U32 *)MemCopySrc;
dst = (U32 *)MemCopyDest;
tsize = (int)MemTestSize;
Print("\n\n - Source Memory Location : 0x%08x",src) ;
Print("\n\r - Destination Memory Location : 0x%08x",dst) ;
Print("\n\r - Memory Test Size : 0x%08x",tsize) ;
Print("\n\r - Memory Test Loop Count : %d\r",lsize) ;
if (!MemTest(src,dst,tsize,lsize))
Print("\n\n $$$ Memory Test Fail !!! ") ;
else Print("\n\n $$$ Memory Test Success !!! ") ;
}
int MemTest(U32 *src,U32 *dst,int tsize,int lsize)
{
int i;
int j;
Print("\n\r ++ Memory Test (Long) .... ");
for (i=0 ; i < lsize ; i++)
{
for (j=0 ; j < 4 ; j++)
{
MemTestInit(src, tsize);
if ( !WordCopyTest(src, dst, tsize) )
{
Print("\n Fail !!") ;
return MemTestFail ;
}
}
}
Print("\nOk") ;
Print("\n\r ++ Memory Test (Short) ... ") ;
for (i=0 ; i < lsize ; i++)
{
for (j=0 ; j < 4 ; j++)
{
MemTestInit(src, tsize);
if ( !SWordCopyTest(src, dst, tsize) )
{
Print("\n Fail !!") ;
return MemTestFail ;
}
}
}
Print("\nOk") ;
Print("\n\r ++ Memory Test (Byte) .... ") ;
for (i=0 ; i < lsize ; i++)
{
for (j=0 ; j < 4 ; j++)
{
MemTestInit(src, tsize);
if ( !ByteCopyTest(src, dst, tsize) )
{
Print("\n Fail !!") ;
return MemTestFail ;
}
}
}
Print("\nOk") ;
return MemTestOk ;
}
void MemTestInit(U32 *src, int tsize)
{
U32 *InitSrcAddr;
int cnt ;
int pat ;
InitSrcAddr = src ;
cnt = tsize ;
pat = 0;
while(cnt--) {
*InitSrcAddr++ = (U32)PatternGen(pat++);
}
}
int ByteCopyTest(U32 *src,U32 *dst,int tsize)
{
bcopy(src, dst, tsize) ;
if (!bcomp(src, dst, tsize)) return MemTestFail ;
return MemTestOk ;
}
int SWordCopyTest(U32 *src,U32 *dst,int tsize)
{
scopy(src, dst, tsize) ;
if (!scomp(src, dst, tsize)) return MemTestFail ;
return MemTestOk ;
}
int WordCopyTest(U32 *src,U32 *dst,int tsize)
{
wcopy(src, dst, tsize) ;
if (!wcomp(src, dst, tsize)) return MemTestFail ;
return MemTestOk ;
}
void bcopy(void *src, void *dst, int tsize)
{
U8 *SrcAddr;
U8 *DstAddr;
int cnt ;
SrcAddr = (U8 *)src ;
DstAddr = (U8 *)dst ;
cnt = tsize;
while(cnt--)
*DstAddr++ = *SrcAddr++ ;
}
void scopy(void *src, void *dst, int tsize)
{
U16 *SrcAddr;
U16 *DstAddr;
int cnt ;
SrcAddr = (U16 *)src;
DstAddr = (U16 *)dst;
cnt = tsize ;
while(cnt--)
*DstAddr++ = *SrcAddr++ ;
}
void wcopy(void *src, void *dst, int tsize)
{
U32 *SrcAddr;
U32 *DstAddr;
int cnt ;
SrcAddr = (U32 *)src ;
DstAddr = (U32 *)dst ;
cnt = tsize ;
while(cnt--)
*DstAddr++ = *SrcAddr++ ;
}
int bcomp(void *src, void *dst, int tsize)
{
U8 *SrcAddr;
U8 *DstAddr;
int cnt ;
SrcAddr = (U8 *)src ;
DstAddr = (U8 *)dst ;
cnt = tsize ;
while(cnt--)
{
if ( *DstAddr != *SrcAddr )
{
Print("\n\rMemory Byte Test Error") ;
Print("\n\rSource Data is %02x at Addr %08x",*SrcAddr,SrcAddr) ;
Print("\n\rDestin Data is %02x at Addr %08x",*DstAddr,DstAddr) ;
return MemTestFail ;
}
DstAddr++;
SrcAddr++;
}
return MemTestOk ;
}
int scomp(void *src, void *dst, int tsize)
{
U16 *SrcAddr;
U16 *DstAddr;
int cnt ;
SrcAddr = (U16 *)src ;
DstAddr = (U16 *)dst ;
cnt = tsize ;
while(cnt--)
{
if ( *DstAddr != *SrcAddr )
{
Print("\n\rMemory Short Test Error") ;
Print("\n\rSource Data is %04x at Addr %08x",*SrcAddr,SrcAddr) ;
Print("\n\rDestin Data is %04x at Addr %08x",*DstAddr,DstAddr) ;
return MemTestFail ;
}
DstAddr++;
SrcAddr++;
}
return MemTestOk ;
}
int wcomp(void *src, void *dst, int tsize)
{
U32 *SrcAddr;
U32 *DstAddr;
int cnt ;
SrcAddr = (U32 *)src ;
DstAddr = (U32 *)dst ;
cnt = tsize ;
while(cnt--)
{
if ( *DstAddr != *SrcAddr )
{
Print("\n\rMemory Long Test Error") ;
Print("\n\rSource Data is %08x at Addr %08x",*SrcAddr,SrcAddr) ;
Print("\n\rDestin Data is %08x at Addr %08x",*DstAddr,DstAddr) ;
return MemTestFail ;
}
DstAddr++;
SrcAddr++;
}
return MemTestOk ;
}
void ExtIOBankTest(void)
{
U32 *ExtIoBase0, *ExtIoBase1, *ExtIoBase2, *ExtIoBase3 ;
U32 *src ;
U32 ExtIoTestSize = 0xFF0 ;
int lsize = 5 ; // Ext IO test loop count
char TestBankSel ;
EXTACON0 = TCOS0 | TACS0 | TCOH0 | TACC0 ;
EXTACON0 |= TCOS1 | TACS1 | TCOH1 | TACC1 ;
EXTACON1 = TCOS2 | TACS2 | TCOH2 | TACC2 ;
EXTACON1 |= TCOS3 | TACS3 | TCOH3 | TACC3 ;
Print("\n >> External I/O Bank Test <<") ;
ExtIoBase0 = (U32 *)EXTIOBASE ;
ExtIoBase1 = ExtIoBase0 + 4096 ;
ExtIoBase2 = ExtIoBase1 + 4096 ;
ExtIoBase3 = ExtIoBase2 + 4096 ;
Print("\n\r +- External I/O Bank #0 Base Addr : 0x%x",ExtIoBase0) ;
Print("\n\r +- External I/O Bank #1 Base Addr : 0x%x",ExtIoBase1) ;
Print("\n\r +- External I/O Bank #2 Base Addr : 0x%x",ExtIoBase2) ;
Print("\n\r +- External I/O Bank #3 Base Addr : 0x%x",ExtIoBase3) ;
src = (U32 *)MemCopySrc;
Print("\n $$ Select Test External I/O Bank (0,1,2,3,Q) ? ") ;
TestBankSel = get_byte() ;
if (TestBankSel == '0' )
{
Print("\n <<>> External I/O Bank #0 Test ") ;
MemTest(src,ExtIoBase0,ExtIoTestSize,lsize);
}
else if (TestBankSel == '1' )
{
Print("\n <<>> External I/O Bank #1 Test ") ;
MemTest(src,ExtIoBase1,ExtIoTestSize,lsize);
}
else if (TestBankSel == '2' )
{
Print("\n <<>> External I/O Bank #2 Test ") ;
MemTest(src,ExtIoBase2,ExtIoTestSize,lsize);
}
else if (TestBankSel == '3' )
{
Print("\n <<>> External I/O Bank #3 Test ") ;
MemTest(src,ExtIoBase3,ExtIoTestSize,lsize);
}
else Print("\n\r +- Invalid External I/O Bank Selected") ;
}
int PatternGen(unsigned int seed)
{
if(!(seed%0x100)) srand(seed);
return(rand());
}
void *nmalloc(unsigned nbyte)
{
void *returnPt=nmallocPt;
nmallocPt= (int *)nmallocPt+nbyte/4+((nbyte%4)>0);
if( (int)nmallocPt > AllocNonCacheAreaEnd)return NULL;
return returnPt;
}
void *malloc(unsigned nbyte)
{
void *returnPt=mallocPt;
mallocPt= (int *)mallocPt+nbyte/4+((nbyte%4)>0);
if( (int)mallocPt > HEAPEND)return NULL;
return returnPt;
}
void free(void *pt)
{
mallocPt=pt;
}
void nmfree(void *pt)
{
nmallocPt=pt;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -