Skip to content

Commit b43cb6c

Browse files
committedDec 31, 2016
tests: Added HiL test for ring oscillator
1 parent d56da5b commit b43cb6c

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
 

‎tests/greenpak4/slg46620v/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_greenpak4_hiltest(Latch SLG46620V)
2828
add_greenpak4_hiltest(LFOsc SLG46620V)
2929
add_greenpak4_hiltest(Luts SLG46620V)
3030
add_greenpak4_hiltest(PGA SLG46620V)
31+
add_greenpak4_hiltest(RingOsc SLG46620V)
3132

3233
########################################################################################################################
3334
# Cosimulation tests

‎tests/greenpak4/slg46620v/RingOsc.cpp

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***********************************************************************************************************************
2+
* Copyright (C) 2016 Andrew Zonenberg and contributors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General *
5+
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) *
6+
* any later version. *
7+
* *
8+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
9+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
10+
* more details. *
11+
* *
12+
* You should have received a copy of the GNU Lesser General Public License along with this program; if not, you may *
13+
* find one here: *
14+
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt *
15+
* or you may search the http://www.gnu.org website for the version 2.1 license, or you may write to the Free Software *
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17+
**********************************************************************************************************************/
18+
19+
#include <log.h>
20+
#include <gpdevboard.h>
21+
#include <unistd.h>
22+
#include <math.h>
23+
24+
using namespace std;
25+
26+
bool RunTest(hdevice hdev);
27+
28+
int main(int argc, char* argv[])
29+
{
30+
g_log_sinks.emplace(g_log_sinks.begin(), new STDLogSink(Severity::VERBOSE));
31+
32+
//expect one arg: the bitstream
33+
if(argc != 2)
34+
{
35+
LogNotice("Usage: [testcase] bitstream.txt\n");
36+
return 1;
37+
}
38+
39+
//Set up the test
40+
hdevice hdev = MultiBoardTestSetup(argv[1], 25000, 3.3, SilegoPart::SLG46620V);
41+
if(!hdev)
42+
{
43+
LogError("Failed to open board\n");
44+
return 1;
45+
}
46+
47+
//Run the actual test case
48+
LogNotice("\n");
49+
LogNotice("Running application test case\n");
50+
if(!RunTest(hdev))
51+
{
52+
SetStatusLED(hdev, 0);
53+
Reset(hdev);
54+
return 1;
55+
}
56+
57+
//Turn off the LED before declaring success
58+
LogVerbose("\n");
59+
LogVerbose("Test complete, resetting board\n");
60+
SetStatusLED(hdev, 0);
61+
ResetAllSiggens(hdev);
62+
Reset(hdev);
63+
USBCleanup(hdev);
64+
return 0;
65+
}
66+
67+
/**
68+
@brief The actual application-layer test
69+
*/
70+
bool RunTest(hdevice hdev)
71+
{
72+
LogIndenter li;
73+
74+
//Set up the I/O config we need for this test
75+
IOConfig ioConfig;
76+
for(size_t i = 2; i <= 20; i++)
77+
ioConfig.driverConfigs[i] = TP_RESET;
78+
if(!SetIOConfig(hdev, ioConfig))
79+
return false;
80+
81+
//Measure the oscillator frequency
82+
unsigned int freq;
83+
if(!MeasureOscillatorFrequency(hdev, freq))
84+
return false;
85+
86+
unsigned int expected = 13500000;
87+
LogVerbose("Measured ring oscillator frequency (with divide-by-2): %u Hz (expected %u)\n",
88+
freq, expected);
89+
90+
int err = freq - expected;
91+
LogVerbose(" Error: %d Hz\n", err);
92+
int tolerance = 5000;
93+
if(abs(err) > tolerance)
94+
{
95+
LogError("Error is too big (more than %d Hz)\n", tolerance);
96+
return false;
97+
}
98+
99+
return true;
100+
}

‎tests/greenpak4/slg46620v/RingOsc.v

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***********************************************************************************************************************
2+
* Copyright (C) 2016 Andrew Zonenberg and contributors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General *
5+
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) *
6+
* any later version. *
7+
* *
8+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
9+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
10+
* more details. *
11+
* *
12+
* You should have received a copy of the GNU Lesser General Public License along with this program; if not, you may *
13+
* find one here: *
14+
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt *
15+
* or you may search the http://www.gnu.org website for the version 2.1 license, or you may write to the Free Software *
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17+
**********************************************************************************************************************/
18+
19+
`default_nettype none
20+
21+
/**
22+
@brief HiL test case for GP_RINGOSC
23+
24+
OUTPUTS:
25+
Oscillator output, divided by 2 (should be ~13.5 MHz)
26+
*/
27+
module RingOsc(clkout);
28+
29+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30+
// I/O declarations
31+
32+
(* LOC = "P13" *)
33+
output wire clkout;
34+
35+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36+
// The oscillator
37+
38+
GP_RINGOSC #(
39+
.PWRDN_EN(1),
40+
.AUTO_PWRDN(0),
41+
.HARDIP_DIV(1),
42+
.FABRIC_DIV(2)
43+
) ringosc (
44+
.PWRDN(1'b0),
45+
.CLKOUT_HARDIP(),
46+
.CLKOUT_FABRIC(clkout)
47+
);
48+
49+
endmodule

0 commit comments

Comments
 (0)
Please sign in to comment.