Skip to content

Commit d7b680a

Browse files
committedDec 31, 2016
Added Luts HiL test
1 parent 1b4f7ed commit d7b680a

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed
 

‎tests/greenpak4/slg46620v/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_greenpak4_bitstream(SocketTestLoopback_STQFN20 SLG46620V)
2525

2626
add_greenpak4_hiltest(Bargraph SLG46620V)
2727
add_greenpak4_hiltest(Latch SLG46620V)
28+
add_greenpak4_hiltest(Luts SLG46620V)
2829
add_greenpak4_hiltest(PGA SLG46620V)
2930

3031
########################################################################################################################

‎tests/greenpak4/slg46620v/Luts.cpp

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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, 1.8, 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+
//Loop over all values for the 4 inputs and see what we get
82+
bool ok = true;
83+
for(int i=0; i<16; i++)
84+
{
85+
bool a = (i & 1) ? true : false;
86+
bool b = (i & 2) ? true : false;
87+
bool c = (i & 4) ? true : false;
88+
bool d = (i & 8) ? true : false;
89+
90+
bool nand1_expected = !a;
91+
bool nand2_expected = !(a & b);
92+
bool nand3_expected = !(a & b & c);
93+
bool nand4_expected = !(a & b & c & d);
94+
95+
bool expected[8] =
96+
{
97+
nand1_expected, nand2_expected, nand3_expected, nand4_expected,
98+
nand1_expected, nand2_expected, nand3_expected, nand4_expected
99+
};
100+
101+
//Drive the inputs
102+
LogVerbose("Testing %d %d %d %d\n", a, b, c, d);
103+
LogVerbose("Expected: %d %d %d %d\n", nand1_expected, nand2_expected, nand3_expected, nand4_expected);
104+
ioConfig.driverConfigs[2] = a ? TP_VDD : TP_GND;
105+
ioConfig.driverConfigs[3] = b ? TP_VDD : TP_GND;
106+
ioConfig.driverConfigs[4] = c ? TP_VDD : TP_GND;
107+
ioConfig.driverConfigs[5] = d ? TP_VDD : TP_GND;
108+
if(!SetIOConfig(hdev, ioConfig))
109+
return false;
110+
111+
//Read the outputs
112+
int pin_nums[8] = {6, 7, 8, 9, 12, 13, 14, 15};
113+
bool results[8];
114+
for(int i=0; i<8; i++)
115+
{
116+
double value;
117+
if(!SingleReadADC(hdev, pin_nums[i], value))
118+
return false;
119+
results[i] = (value > 0.5);
120+
}
121+
122+
//Sanity check the results
123+
for(int j=0; j<8; j++)
124+
{
125+
if(expected[j] != results[j])
126+
{
127+
LogError("input (%d %d %d %d), output pin %d, got %d instead of %d\n",
128+
a, b, c, d,
129+
pin_nums[j],
130+
results[j],
131+
expected[j]);
132+
ok = false;
133+
}
134+
}
135+
}
136+
137+
return ok;
138+
}

‎tests/greenpak4/slg46620v/Luts.v

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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_INV, GP_LUTx
23+
24+
OUTPUTS:
25+
Bitwise NAND of inputs (1 to 4 bits wide)
26+
*/
27+
module Luts(din, dout_instantiated, dout_inferred);
28+
29+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30+
// I/O declarations
31+
32+
(* LOC = "P2 P3 P4 P5" *)
33+
input wire[3:0] din;
34+
35+
(* LOC = "P6 P7 P8 P9" *)
36+
output wire[3:0] dout_instantiated;
37+
38+
(* LOC = "P12 P13 P14 P15" *)
39+
output wire[3:0] dout_inferred;
40+
41+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42+
// LUTs created from direct instantiation
43+
44+
GP_INV inv_inst (
45+
.IN(din[0]), .OUT(dout_instantiated[0]));
46+
GP_2LUT #(.INIT(4'hB)) lut2_inst (
47+
.IN0(din[0]), .IN1(din[1]), .OUT(dout_instantiated[1]));
48+
GP_3LUT #(.INIT(8'h7F)) lut3_inst (
49+
.IN0(din[0]), .IN1(din[1]), .IN2(din[2]), .OUT(dout_instantiated[2]));
50+
GP_4LUT #(.INIT(16'h7FFF)) lut4_inst (
51+
.IN0(din[0]), .IN1(din[1]), .IN2(din[2]), .IN3(din[3]), .OUT(dout_instantiated[3]));
52+
53+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54+
// LUTs created from inference
55+
56+
assign dout_inferred[0] = ~din[0];
57+
assign dout_inferred[1] = ~(din[0] & din[1]);
58+
assign dout_inferred[2] = ~(din[0] & din[1] & din[2]);
59+
assign dout_inferred[3] = ~(din[0] & din[1] & din[2] & din[3]);
60+
61+
endmodule

0 commit comments

Comments
 (0)
Please sign in to comment.