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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [peripheral/] [test.c] - Blame information for rev 1782

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

Line No. Rev Author Line
1 970 simons
#include <stdio.h>
2 1350 nogj
 
3
#include "config.h"
4
 
5
#ifdef HAVE_INTTYPES_H
6
#include <inttypes.h>
7
#endif
8
 
9
#include "port.h"
10
#include "arch.h"
11 970 simons
#include "sim-config.h"
12
#include "abstract.h"
13
#include "except.h"
14
 
15 1361 nogj
struct test_config {
16
  uint32_t array[128];
17
  oraddr_t baseaddr;
18
};
19 970 simons
 
20
/* Test write */
21 1359 nogj
void test_write32 (oraddr_t addr, uint32_t value, void *dat)
22 970 simons
{
23 1361 nogj
  struct test_config *test = dat;
24
 
25 970 simons
  if (addr & 0x00000080)
26 1361 nogj
    test->array[addr & 0x7f] = value;
27 970 simons
  else
28
    except_handle(EXCEPT_BUSERR, cur_vadd);
29
}
30
 
31
/* Test read */
32 1359 nogj
uint32_t test_read32 (oraddr_t addr, void *dat)
33 970 simons
{
34 1361 nogj
  struct test_config *test = dat;
35
 
36 970 simons
  if (addr & 0x00000080)
37 1361 nogj
    return ~test->array[addr & 0x7f];
38 970 simons
  else
39
    except_handle(EXCEPT_BUSERR, cur_vadd);
40
    return 0x00000000;
41
}
42
 
43 1361 nogj
void test_reset (void *dat)
44 970 simons
{
45 1361 nogj
  struct test_config *test = dat;
46 970 simons
  int i;
47
 
48
  for (i = 0; i < 128; i++)
49 1361 nogj
    test->array[i] = 0x00000000;
50 970 simons
}
51 1358 nogj
 
52
/*---------------------------------------------------[ Test configuration ]---*/
53 1361 nogj
void test_baseaddr(union param_val val, void *dat)
54 1358 nogj
{
55 1361 nogj
  struct test_config *test = dat;
56
  test->baseaddr = val.addr_val;
57 1358 nogj
}
58
 
59 1361 nogj
void *test_sec_start(void)
60 1358 nogj
{
61 1361 nogj
  struct test_config *test = malloc(sizeof(struct test_config));
62
 
63
  if(!test) {
64
    fprintf(stderr, "Peripheral Test: Run out of memory\n");
65
    exit(-1);
66
  }
67
 
68
  test->baseaddr = 0;
69
 
70
  return test;
71 1358 nogj
}
72
 
73 1361 nogj
void test_sec_end(void *dat)
74
{
75
  struct test_config *test = dat;
76
  if(test->baseaddr)
77
    register_memoryarea(test->baseaddr, 256, 4, 0, test_read32, test_write32, NULL);
78
  reg_sim_reset(test_reset, dat);
79
}
80
 
81 1358 nogj
void reg_test_sec(void)
82
{
83 1361 nogj
  struct config_section *sec = reg_config_sec("test", test_sec_start,
84
                                              test_sec_end);
85 1358 nogj
 
86
  reg_config_param(sec, "baseaddr", paramt_addr, test_baseaddr);
87
}

powered by: WebSVN 2.1.0

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