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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [corefunc.hh] - Blame information for rev 209

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 161 sybreon
/* $Id: corefunc.hh,v 1.4 2008-05-11 13:51:50 sybreon Exp $
2 141 sybreon
**
3
** AEMB Function Verification C++ Testbench
4
** Copyright (C) 2004-2008 Shawn Tan 
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17
**
18
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see .
20
*/
21
/**
22
AEMB Software Verification
23
@file corefunc.hh
24
 
25
These are custom functions written to test certain hardware functions
26
that cannot be tested through numerical algorithms.
27
*/
28
 
29
#ifndef COREFUNC_HH
30
#define COREFUNC_HH
31
 
32 206 sybreon
#ifdef __cplusplus
33
extern "C" {
34
#endif
35 141 sybreon
 
36 206 sybreon
#define MAGIC 0xAE63AE63 // magic number
37
 
38
volatile int exce = 0;
39
 
40 209 sybreon
volatile void _hw_exception_handler()
41 206 sybreon
{
42 209 sybreon
  int resr;
43
  asm volatile ("mfs %0, resr" : "=r"(resr));
44 206 sybreon
 
45 209 sybreon
  switch (resr)
46
    {
47
    case 1: // unaligned
48
      --exce;
49
      break;
50
    case 2: // illegal
51
      ++exce;
52
      break;
53
    default:
54
      exce = 0;
55
      break;
56
    }
57
 
58
  asm volatile ("rted r17, 0\n"
59 206 sybreon
                "nop\n");
60
}
61 209 sybreon
 
62
  /**
63 206 sybreon
EXCEPTION TEST ROUTINE
64
*/
65
 
66
int exceptionTest(int timeout)
67
{
68
  volatile int *toggle = (int *)0xFFFFFFE2;
69 209 sybreon
 
70 206 sybreon
  // enable exceptions
71
  asm volatile (".long 0xDEADC0DE"); // define illegal instruction (1 error)
72 209 sybreon
 
73 206 sybreon
  *toggle = *toggle; // test unaligned memory access (2 errors)
74
  // disable exceptions
75 209 sybreon
 
76
  return (exce != -1) ? EXIT_FAILURE : EXIT_SUCCESS;
77 206 sybreon
}
78
 
79 157 sybreon
volatile int intr = 0;
80 141 sybreon
 
81
void __attribute__ ((interrupt_handler)) interruptHandler()
82
{
83 157 sybreon
  int *toggle = (int *)0xFFFFFFE0;
84
  intr++; // flag the interrupt service routine
85
  *toggle = -1; // disable interrupts
86 141 sybreon
}
87
 
88 152 sybreon
/**
89
INTERRUPT TEST ROUTINE
90
*/
91
 
92 141 sybreon
int interruptTest(int timeout)
93
{
94 161 sybreon
  aembEnableInterrupts();
95
  for (int timer=0; (timer < timeout * 100); ++timer)
96
    asm volatile ("nop"); // delay loop
97 152 sybreon
  aembDisableInterrupts();
98 157 sybreon
  return (intr == 0) ? EXIT_FAILURE : EXIT_SUCCESS;
99 141 sybreon
}
100
 
101
 
102
/**
103
   FSL TEST ROUTINE
104
*/
105
 
106
int xslTest (int code)
107
{
108
  // TEST FSL1 ONLY
109
  int FSL = code;
110
 
111
  asm ("PUT %0, RFSL0" :: "r"(FSL));
112
  asm ("GET %0, RFSL0" : "=r"(FSL));
113
 
114
  if (FSL != code) return EXIT_FAILURE;
115
 
116
  asm ("PUT %0, RFSL31" :: "r"(FSL));
117
  asm ("GET %0, RFSL31" : "=r"(FSL));
118
 
119
  if (FSL != code) return EXIT_FAILURE;
120
 
121
  return EXIT_SUCCESS;
122
}
123
 
124
/**
125
   MALLOC TEST
126
   Works well with newlib malloc routine. Do some patterned tests.
127
*/
128
 
129
int memoryTest(int size)
130
{
131
  volatile void *alloc;
132
  int magic;
133
 
134
  alloc = malloc(size * sizeof(int)); // allocate 32 byte
135
  if (alloc == NULL)
136
    return EXIT_FAILURE;
137
 
138
  *(int *)alloc = MAGIC; // write to memory
139
  magic = *(int *)alloc; // read from memory
140
 
141
  return (magic == MAGIC) ? EXIT_SUCCESS : EXIT_FAILURE;
142
}
143
 
144 206 sybreon
#ifdef __cplusplus
145
}
146 141 sybreon
#endif
147
 
148 206 sybreon
#endif
149 161 sybreon
 

powered by: WebSVN 2.1.0

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