Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / apps / buf_ram_test.c
1 /*
2  * Copyright 2007 Free Software Foundation, Inc.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "u2_init.h"
19 #include "memory_map.h"
20 #include "bool.h"
21 #include "nonstdio.h"
22 #include "hal_io.h"
23 #include "mdelay.h"
24
25
26 static void
27 write_bufs(void)
28 {
29   int   i, n;
30   int   counter = 0;
31
32   for (n = 0; n < NBUFFERS; n++){
33     volatile int *p = buffer_ram(n);
34     for (i = 0; i < BP_NLINES; i++)
35       p[i] = counter++;
36   }
37 }
38
39 // return number of errors detected
40 static int
41 check_bufs(void)
42 {
43   int   i, n;
44   int   counter = 0;
45   int   nerrors = 0;
46
47   for (n = 0; n < NBUFFERS; n++){
48     volatile int *p = buffer_ram(n);
49     for (i = 0; i < BP_NLINES; i++, counter++){
50       int rd = p[i];
51       if (rd != counter){
52         putchar('b');
53         putchar(n + '0');
54         putchar('[');
55         puthex16(i);
56         putstr("] exp: ");
57         puthex32(counter);
58         putstr(" got: ");
59         puthex32_nl(rd);
60         nerrors++;
61       }
62     }
63   }
64   return nerrors;
65 }
66
67
68 int
69 main(void)
70 {
71   u2_init();
72
73   output_regs->leds = 0;
74
75   write_bufs();
76   int nerrors = check_bufs();
77
78   if (nerrors == 0){
79     output_regs->leds = 0x3;            // leds on  -> PASS
80     putstr("PASS\n");
81   }
82   else {
83     output_regs->leds = 0x0;            // leds off -> FAIL
84     putstr("FAIL\n");
85   }
86
87   hal_finish();
88   return 0;
89 }