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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_39/] [or1ksim/] [peripheral/] [test.c] - Diff between revs 1403 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1403 Rev 1765
#include <stdio.h>
#include <stdio.h>
 
 
#include "config.h"
#include "config.h"
 
 
#ifdef HAVE_INTTYPES_H
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#include <inttypes.h>
#endif
#endif
 
 
#include "port.h"
#include "port.h"
#include "arch.h"
#include "arch.h"
#include "sim-config.h"
#include "sim-config.h"
#include "abstract.h"
#include "abstract.h"
#include "except.h"
#include "except.h"
 
 
struct test_config {
struct test_config {
  uint32_t array[128];
  uint32_t array[128];
  oraddr_t baseaddr;
  oraddr_t baseaddr;
};
};
 
 
/* Test write */
/* Test write */
void test_write32 (oraddr_t addr, uint32_t value, void *dat)
void test_write32 (oraddr_t addr, uint32_t value, void *dat)
{
{
  struct test_config *test = dat;
  struct test_config *test = dat;
 
 
  if (addr & 0x00000080)
  if (addr & 0x00000080)
    test->array[addr & 0x7f] = value;
    test->array[addr & 0x7f] = value;
  else
  else
    except_handle(EXCEPT_BUSERR, cur_vadd);
    except_handle(EXCEPT_BUSERR, cur_vadd);
}
}
 
 
/* Test read */
/* Test read */
uint32_t test_read32 (oraddr_t addr, void *dat)
uint32_t test_read32 (oraddr_t addr, void *dat)
{
{
  struct test_config *test = dat;
  struct test_config *test = dat;
 
 
  if (addr & 0x00000080)
  if (addr & 0x00000080)
    return ~test->array[addr & 0x7f];
    return ~test->array[addr & 0x7f];
  else
  else
    except_handle(EXCEPT_BUSERR, cur_vadd);
    except_handle(EXCEPT_BUSERR, cur_vadd);
    return 0x00000000;
    return 0x00000000;
}
}
 
 
void test_reset (void *dat)
void test_reset (void *dat)
{
{
  struct test_config *test = dat;
  struct test_config *test = dat;
  int i;
  int i;
 
 
  for (i = 0; i < 128; i++)
  for (i = 0; i < 128; i++)
    test->array[i] = 0x00000000;
    test->array[i] = 0x00000000;
}
}
 
 
/*---------------------------------------------------[ Test configuration ]---*/
/*---------------------------------------------------[ Test configuration ]---*/
void test_baseaddr(union param_val val, void *dat)
void test_baseaddr(union param_val val, void *dat)
{
{
  struct test_config *test = dat;
  struct test_config *test = dat;
  test->baseaddr = val.addr_val;
  test->baseaddr = val.addr_val;
}
}
 
 
void *test_sec_start(void)
void *test_sec_start(void)
{
{
  struct test_config *test = malloc(sizeof(struct test_config));
  struct test_config *test = malloc(sizeof(struct test_config));
 
 
  if(!test) {
  if(!test) {
    fprintf(stderr, "Peripheral Test: Run out of memory\n");
    fprintf(stderr, "Peripheral Test: Run out of memory\n");
    exit(-1);
    exit(-1);
  }
  }
 
 
  test->baseaddr = 0;
  test->baseaddr = 0;
 
 
  return test;
  return test;
}
}
 
 
void test_sec_end(void *dat)
void test_sec_end(void *dat)
{
{
  struct test_config *test = dat;
  struct test_config *test = dat;
  if(test->baseaddr)
  if(test->baseaddr)
    register_memoryarea(test->baseaddr, 256, 4, 0, test_read32, test_write32, NULL);
    register_memoryarea(test->baseaddr, 256, 4, 0, test_read32, test_write32, NULL);
  reg_sim_reset(test_reset, dat);
  reg_sim_reset(test_reset, dat);
}
}
 
 
void reg_test_sec(void)
void reg_test_sec(void)
{
{
  struct config_section *sec = reg_config_sec("test", test_sec_start,
  struct config_section *sec = reg_config_sec("test", test_sec_start,
                                              test_sec_end);
                                              test_sec_end);
 
 
  reg_config_param(sec, "baseaddr", paramt_addr, test_baseaddr);
  reg_config_param(sec, "baseaddr", paramt_addr, test_baseaddr);
}
}
 
 

powered by: WebSVN 2.1.0

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