OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [orpmon/] [cmds/] [memory.c] - Rev 1771

Go to most recent revision | Compare with Previous | Blame | View Log

#include "common.h"
#include "support.h"
#include "spr_defs.h"
 
#define printf(...)
//#define strtoul(x) 0
#define register_command(...)
 
void show_mem(int start, int stop)
{
  unsigned long i;
  getc();
  if (((i = start) & 0xf) != 0x0)
    printf ("\n%08lx: ", i);
  for(; i<=stop; i += 4){
    if ((i & 0xf) == 0x0)
      printf ("\n%08lx: ", i);
 
    /* Read one word */
    printf ("%08lx ", REG32(i));
  }
  printf ("\n");
}
 
void testram (unsigned long start_addr, unsigned long stop_addr, unsigned long testno)
{
  unsigned long addr;
  unsigned long err_addr = 0;
  unsigned long err_no = 0;
 
  /* Test 1: Write locations with their addresses */
  if ((testno == 1) || (testno == 0))
  {
    printf ("\n1. Writing locations with their addresses: ");
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      REG32(addr) = addr;
 
    /* Verify */
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      if (REG32(addr) != addr)
      {
        err_no++;
        err_addr = addr;
      }
    if (err_no)
    {
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
    } else
      printf ("Passed");
    err_no = 0;
  }
 
  /* Test 2: Write locations with their inverse address */
  if ((testno == 2) || (testno == 0))
  {
    printf ("\n2. Writing locations with their inverse addresses: "); 
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      REG32(addr) = ~addr;
 
    /* Verify */
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      if (REG32(addr) != ~addr)
      {
        err_no++;
        err_addr = addr;
      }
    if (err_no)
    {
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
    } else
      printf ("Passed");
    err_no = 0;
  }
 
  /* Test 3: Write locations with walking ones */
  if ((testno == 3) || (testno == 0))
  {
    printf ("\n3. Writing locations with walking ones: ");
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      REG32(addr) = 1 << (addr >> 2);
 
    /* Verify */
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      if (REG32(addr) != (1 << (addr >> 2)))
      {
        err_no++;
        err_addr = addr;
      }
    if (err_no)
    {
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
    } else
      printf ("Passed");
    err_no = 0;
  }
 
  /* Test 4: Write locations with walking zeros */
  if ((testno == 4) || (testno == 0))
  {
    printf ("\n4. Writing locations with walking zeros: ");
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      REG32(addr) = ~(1 << (addr >> 2));
 
    /* Verify */
    for (addr = start_addr; addr <= stop_addr; addr += 4)
      if (REG32(addr) != ~(1 << (addr >> 2)))
      {
        err_no++;
        err_addr = addr;
      }
    if (err_no)
    {
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
    } else
      printf ("Passed");
    err_no = 0;
  }
}
 
int dm_cmd (int argc, char *argv[])
{
	if (argc ==	1) show_mem (strtoul (argv[0]), strtoul (argv[0]));
	else if	(argc	== 2) show_mem (strtoul (argv[0]), strtoul (argv[1]));
	else return -1;
	return 0;
}
 
int pm_cmd (int argc, char *argv[])
{
  if ((argc	== 3)	|| (argc ==	2)) {
	  unsigned long	addr = strtoul (argv[0]);
	  unsigned long	stop_addr	=	strtoul (argv[1]);
	  unsigned long	value	=	strtoul (argv[2]);
 
	  if (argc ==	2) {
	 	  stop_addr	=	strtoul (argv[0]);
		  value	=	strtoul (argv[1]);
	  }
 
	  for (; addr <= stop_addr; addr += 4) REG32(addr)	=	value;
	  show_mem(strtoul (argv[0]),	stop_addr);
	}	else return -1;
	return 0;
}
 
int ram_test_cmd (int argc, char *argv[])
{
  if (argc == 2) testram(strtoul (argv[0]), strtoul (argv[1]), 0);
  else if (argc == 3) testram(strtoul (argv[0]), strtoul (argv[1]), strtoul (argv[2]));
  else return -1;
  return 0;
}
 
void module_memory_init (void)
{
  register_command ("dm", "<start addr> [<end addr>]", "display memory location 32-bit", dm_cmd);
  register_command ("pm", "<addr> [<stop_addr>] <value>", "patch memory location 32-bit", pm_cmd);
  register_command ("ram_test", "<start_addr> <stop_addr> [<test_no>]", "run a simple RAM test\n", ram_test_cmd); 
}
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.