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

📄 memory.c

📁 ~{WwU_J9SC5D~}ucos~{T4Bk#,1`RkA4=S5wJT>y?IRT#,4x~}uart~{2bJT~}
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/*      memory.c                   KS32C5000, KS32C50100   : version 1.0 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      Evaluation & debugging utility for memory.                       */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      hbahn           09-15-1998      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "netstart.h"
#include "uart.h"
#include "isr.h"
#include "memory.h"

#ifdef CBUILDER_TEST
extern char Image_Limit[];
void *mallocPt=Image_Limit;
#else
//extern char Image$$RW$$Limit[];
//void *mallocPt=Image$$RW$$Limit;
#endif
//#define HEAPEND 0x13fffff    /* DATA Area:0x1000000~0x13fffff */

void *nmallocPt = (void *)AllocNonCacheAreaBase ;

// Memory Test 
void MemoryPartTest(void) 
{
	char TestItemSel ;
	IOPDATA = 0x0 ; // All LED On

	do {

	Print("\n+---------------------------------------------------+\r") ;
	Print("|          >>>>>    Memory Test    <<<<<            |\r") ;
        Print("|          Rev 0.0 (by hbahn, 1998.03.05)           |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("| Memory Copy Test                            - [C] |\r") ;
	Print("| Memory Dump                                 - [R] |\r") ;
	Print("| Memory Pattern Fill                         - [F] |\r") ;
	Print("| Memory Pattern Search                       - [S] |\r") ;
	Print("| External I/O Bank  Test                     - [E] |\r") ;
	Print("| Quit                                        - [Q] |\r") ;
	Print("+---------------------------------------------------+\r") ;

	Print("\rSelect Test Item : ") ;
	TestItemSel = get_byte() ;
	
	switch(TestItemSel)
	{
		case 'C' : case 'c' : MemoryTest() ; break ;
		case 'R' : case 'r' : MemoryDump() ; break ;
		case 'F' : case 'f' : MemPatternFill() ; break ;
		case 'S' : case 's' : MemPatternSearch(); break ;
		case 'E' : case 'e' : ExtIOBankTest(); break ;
		case 'Q' : case 'q' : break ;
		default : Print("\nInvalid Test Item Selected") ; 
				break ;
	}
	Print("\n Press Any Key To Continue ....") ; get_byte() ;

	} while  ( (TestItemSel != 'Q') && (TestItemSel != 'q') ) ;
	IOPDATA = 0x0F ; 
}

// Memory Dump top function
void MemoryDump(void)
{
     U32 DumpInitAdd, DumpSize ;
     U32 *base;  // Dump Memory base address
     U32 *end;   // Dump Memory end address
   
     Print("\n >> Input Memory Dump Base Address (0x1000000) : 0x") ;	
     DumpInitAdd = get_num() ;
     if (DumpInitAdd==0) DumpInitAdd=0x1000000 ;

     Print("\r >> Input Memory Dump Size (0x100) : 0x") ;	
     DumpSize = get_num() ;
     if (DumpSize==0) DumpSize=0x100 ;

     base = (U32 *)DumpInitAdd;
     end = (U32 *)(DumpInitAdd + DumpSize) ;

     Print("\nMemory Dump from %x to %x",base, end) ;
     MemDump(base, end);
}



/*
 * Memory dump program
 * ~~~~~~~~~~~~~~~~~~~~
 */
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("\nPress Any Key"); 
		get_byte();k=0;}
	  else { 
		k++;
		{
			Print("\r%8x : ",DumpBase) ;
			j=0;

			for (j=0; j<4 ; j++)
				{
				Print(" %08x ",*DumpBase) ;
				DumpBase++ ;
				}
		}
	  }
}

/* 
 *  Memory Clear
 *  ~~~~~~~~~~~~~~~~~~~
 */
void MemClear(U32 *startaddr, U32 *endaddr) 
{
	int cnt ;
	cnt = (int)(endaddr - startaddr) ;
	while(cnt--) *startaddr++ = 0x00000000 ;
}

/* 
 *  Memory Pattern Fill
 *  ~~~~~~~~~~~~~~~~~~~
 */
void MemPatternFill(void) 
{
	U32 *StartAddr, *EndAddr ;
	U32 Pattern ;
	int cnt ;

     	Print("\n >>> Memory Pattern Fill  <<< ") ;

     	Print("\r $$ Memory Pattern Fill Start Address : 0x") ;	
     	StartAddr = (U32 *)get_num() ;
     	Print("\r $$ Memory Pattern Fill End Address : 0x") ;	
     	EndAddr = (U32 *)get_num() ;
     	Print("\r $$ Memor Fill Pattern : 0x") ;	
     	Pattern = get_num() ;

	cnt = (int)(EndAddr - StartAddr) ;

	Print("\n >> Memory Fill %x to %x, Pattern : %x",\
		StartAddr, EndAddr,Pattern) ;

	while(cnt--) *StartAddr++ = Pattern ;
}

/* 
 *  Memory Pattern Search
 *  ~~~~~~~~~~~~~~~~~~~~~
 */
void MemPatternSearch(void)
{
	U32 *StartAddr, *EndAddr ;
	U32 Pattern ;
	int cnt ;

     	Print("\n >>> Memory Pattern Search  <<< ") ;

     	Print("\r $$ Memory Pattern Search Start Address : 0x") ;	
     	StartAddr = (U32 *)get_num() ;
     	Print("\r $$ Memory Pattern Search End Address : 0x") ;	
     	EndAddr = (U32 *)get_num() ;
     	Print("\r $$ Memory Search Pattern : 0x") ;	
     	Pattern = get_num() ;

	cnt = (int)(EndAddr - StartAddr) ;

	Print("\n >> Memory Pattern Search 0x%x to 0x%x, Pattern : %x\n", \
		StartAddr, EndAddr,Pattern) ;

	while(cnt--) 
	{
	if (*StartAddr == Pattern) 
		Print("\r +-- Pattern is Searched : %x (%x)",\
				StartAddr, *StartAddr);
	StartAddr++ ;
	}
}

/* 
 *  Memory Test Top Program
 *  ~~~~~~~~~~~~~~~~~~~~~~~~
 */
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 >> Input Memory Test Location(0x1200000) : 0x") ;
	MemCopyDest = get_num() ;
	if (MemCopyDest==0) MemCopyDest=0x1200000 ;

	Print("\n >> Input Memory Test Size(0x10000) : 0x") ;
	MemTestSize = get_num() ;
	if (MemTestSize==0) MemTestSize=0x10000 ;

	Print("\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 - Source Memory Location      : 0x%08x",src) ;
	Print("\r - Destination Memory Location : 0x%08x",dst) ;
	Print("\r - Memory Test Size            : 0x%08x",tsize) ;
	Print("\r - Memory Test Loop Count      : %d\r",lsize) ;

        if (!MemTest(src,dst,tsize,lsize)) 
			Print("\n $$$ Memory Test Fail !!! ") ;
	else Print("\n $$$ Memory Test Success !!! ") ;
}


/* 
 *  Memory  word, halfword, byte copy & Compare test
 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
int MemTest(U32 *src,U32 *dst,int tsize,int lsize)
{
	int i;
	int j;

	// Word Test
	Print("\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(" Fail !!") ;
				return MemTestFail ;
				}
			PrintMemTestStatus(j) ;
		}
	}
	Print("Ok") ;

	// Half Word Test
	Print("\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(" Fail !!") ;
				return MemTestFail ;
				}
			PrintMemTestStatus(j) ;
		}
	}
	Print("Ok") ;

	// Byte Test
	Print("\r ++   Memory Test (Byte) ....    ") ;

⌨️ 快捷键说明

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