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

Subversion Repositories pavr

[/] [pavr/] [trunk/] [test/] [waves/] [waves.c] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 doru
// Project
2
//    pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
3
//    AVR core, but about 3x faster in terms of both clock frequency and MIPS.
4
//    The increase in speed comes from a relatively deep pipeline. The original
5
//    AVR core has only two pipeline stages (fetch and execute), while pAVR has
6
//    6 pipeline stages:
7
//       1. PM    (read Program Memory)
8
//       2. INSTR (load Instruction)
9
//       3. RFRD  (decode Instruction and read Register File)
10
//       4. OPS   (load Operands)
11
//       5. ALU   (execute ALU opcode or access Unified Memory)
12
//       6. RFWR  (write Register File)
13
// Version
14
//    0.32
15
// Date
16
//    2002 August 07
17
// Author
18
//    Doru Cuturela, doruu@yahoo.com
19
// License
20
//    This program is free software; you can redistribute it and/or modify
21
//    it under the terms of the GNU General Public License as published by
22
//    the Free Software Foundation; either version 2 of the License, or
23
//    (at your option) any later version.
24
//    This program is distributed in the hope that it will be useful,
25
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
26
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
//    GNU General Public License for more details.
28
//    You should have received a copy of the GNU General Public License
29
//    along with this program; if not, write to the Free Software
30
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
 
32
 
33
 
34
// About this file...
35
//    This is a pAVR test that simulates waves on the surface of a liquid.
36
//    This uses floating point numbers.
37
//    Checking the result is done by simulating this program on pAVR, and
38
//       comparing the final mesh (read directly from Data Memory) against
39
//       the reference final mesh obtained by running this program on a PC.
40
//       To switch between the two situations, #define or not REF (see below).
41
 
42
 
43
 
44
//#include <stdio.h>
45
//#include <stdlib.h>
46
//#include <string.h>
47
//#include <sfr2313.h>
48
//#include <sfr8515.h>
49
#include <float.h>
50
 
51
#define NR_OX 5
52
#define NR_OY 5
53
#define NR_IT 5
54
 
55
// Define this when running reference test on host PC.
56
// Don't define this when running pAVR test simulation.
57
#define REF
58
 
59
 
60
#ifdef REF
61
   #include <stdio.h>
62
   #include <stdlib.h>
63
   #include <string.h>
64
#endif
65
 
66
void main() {
67
   #ifdef REF
68
   FILE *f1;
69
   char txt[100];
70
   #endif
71
 
72
   static float zData[NR_OX][NR_OY], vzData[NR_OX][NR_OY];
73
   static float tmp1, tmp2, tmp3, tmp4;
74
   static char cData[NR_OX][NR_OY];
75
   int ix, iy, it;
76
 
77
   for (ix=0; ix<NR_OX; ix++) {
78
      for (iy=0; iy<NR_OY; iy++) {
79
         zData[ix][iy] = 0.0;
80
         vzData[ix][iy] = 0.0;
81
      }
82
   }
83
   zData[1][1]=0.9;
84
 
85
//*
86
   for (it=0; it<NR_IT; it++) {
87
      for (ix=0; ix<NR_OX; ix++) {
88
         for (iy=0; iy<NR_OY; iy++) {
89
            if ((ix==0)||(iy==0)||(ix==NR_OX-1)||(iy==NR_OY-1)) {
90
               // Boundary conditions
91
               zData[ix][iy] = 0.0;
92
               vzData[ix][iy] = 0.0;
93
            }
94
            else {
95
               vzData[ix][iy] = 0.90*vzData[ix][iy] - 0.0333*(6.0*zData[ix][iy]
96
                                                              - (zData[ix-1][iy] + zData[ix+1][iy] + zData[ix][iy-1] + zData[ix][iy+1])
97
                                                              - 0.5 * (zData[ix-1][iy-1] + zData[ix-1][iy+1] + zData[ix+1][iy-1] + zData[ix+1][iy+1]));
98
               zData[ix][iy] = zData[ix][iy] + vzData[ix][iy];
99
 
100
            }
101
         }
102
      }
103
   }
104
//*/
105
 
106
   for (ix=0; ix<NR_OX; ix++) {
107
      for (iy=0; iy<NR_OY; iy++) {
108
         cData[ix][iy] = (char) (zData[ix][iy]*128.0);
109
//         if (zData[ix][iy]>=1) cData[ix][iy] =  127;
110
//         if (zData[ix][iy]<-1) cData[ix][iy] = -128;
111
      }
112
   }
113
 
114
 
115
   #ifdef REF
116
   // Write results
117
   f1 = fopen("results.dat", "wb+");
118
   if (f1!=NULL) {
119
      for (ix=0; ix<NR_OX; ix++) {
120
         for (iy=0; iy<NR_OY; iy++) {
121
            itoa(cData[ix][iy], txt, 10);
122
            strcat(txt, "\n");
123
            fwrite(txt, strlen(txt), 1, f1);
124
            fflush(f1);
125
         }
126
      }
127
   }
128
   else {
129
      printf("Could not write file.\n");
130
   }
131
   fclose(f1);
132
   #endif
133
 
134
 
135
 
136
 
137
 
138
//*/
139
   #ifndef REF
140
   while (1) {
141
   }
142
   #endif
143
}
144
 
145
 

powered by: WebSVN 2.1.0

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