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

Subversion Repositories aemb

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

Go to most recent revision | 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
void exceptionHandler()
41
{
42
  exce++; // flag the exception service routine
43
}
44
 
45
 
46
volatile void _hw_exception_handler()
47
{
48
  //exceptionHandler();
49
  exce++;
50
  asm volatile (//"lwi r15,r1,0\n"
51
                "rted r17, 0\n"
52
                "nop\n");
53
  //"addik r1,r1,28\n");
54
}
55
 
56
/**
57
EXCEPTION TEST ROUTINE
58
*/
59
 
60
int exceptionTest(int timeout)
61
{
62
  volatile int *toggle = (int *)0xFFFFFFE2;
63
  // enable exceptions
64
  asm volatile (".long 0xDEADC0DE"); // define illegal instruction (1 error)
65
  *toggle = *toggle; // test unaligned memory access (2 errors)
66
  // disable exceptions
67
  return (exce != 3) ? EXIT_FAILURE : EXIT_SUCCESS;
68
}
69
 
70 157 sybreon
volatile int intr = 0;
71 141 sybreon
 
72
void __attribute__ ((interrupt_handler)) interruptHandler()
73
{
74 157 sybreon
  int *toggle = (int *)0xFFFFFFE0;
75
  intr++; // flag the interrupt service routine
76
  *toggle = -1; // disable interrupts
77 141 sybreon
}
78
 
79 152 sybreon
/**
80
INTERRUPT TEST ROUTINE
81
*/
82
 
83 141 sybreon
int interruptTest(int timeout)
84
{
85 161 sybreon
  aembEnableInterrupts();
86
  for (int timer=0; (timer < timeout * 100); ++timer)
87
    asm volatile ("nop"); // delay loop
88 152 sybreon
  aembDisableInterrupts();
89 157 sybreon
  return (intr == 0) ? EXIT_FAILURE : EXIT_SUCCESS;
90 141 sybreon
}
91
 
92
 
93
/**
94
   FSL TEST ROUTINE
95
*/
96
 
97
int xslTest (int code)
98
{
99
  // TEST FSL1 ONLY
100
  int FSL = code;
101
 
102
  asm ("PUT %0, RFSL0" :: "r"(FSL));
103
  asm ("GET %0, RFSL0" : "=r"(FSL));
104
 
105
  if (FSL != code) return EXIT_FAILURE;
106
 
107
  asm ("PUT %0, RFSL31" :: "r"(FSL));
108
  asm ("GET %0, RFSL31" : "=r"(FSL));
109
 
110
  if (FSL != code) return EXIT_FAILURE;
111
 
112
  return EXIT_SUCCESS;
113
}
114
 
115
/**
116
   MALLOC TEST
117
   Works well with newlib malloc routine. Do some patterned tests.
118
*/
119
 
120
int memoryTest(int size)
121
{
122
  volatile void *alloc;
123
  int magic;
124
 
125
  alloc = malloc(size * sizeof(int)); // allocate 32 byte
126
  if (alloc == NULL)
127
    return EXIT_FAILURE;
128
 
129
  *(int *)alloc = MAGIC; // write to memory
130
  magic = *(int *)alloc; // read from memory
131
 
132
  return (magic == MAGIC) ? EXIT_SUCCESS : EXIT_FAILURE;
133
}
134
 
135 206 sybreon
#ifdef __cplusplus
136
}
137 141 sybreon
#endif
138
 
139 206 sybreon
#endif
140 161 sybreon
 

powered by: WebSVN 2.1.0

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