Skip to content

Commit

Permalink
tests: Added HiL test for ring oscillator
Browse files Browse the repository at this point in the history
azonenberg committed Dec 31, 2016
1 parent d56da5b commit b43cb6c
Showing 3 changed files with 150 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/greenpak4/slg46620v/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ add_greenpak4_hiltest(Latch SLG46620V)
add_greenpak4_hiltest(LFOsc SLG46620V)
add_greenpak4_hiltest(Luts SLG46620V)
add_greenpak4_hiltest(PGA SLG46620V)
add_greenpak4_hiltest(RingOsc SLG46620V)

########################################################################################################################
# Cosimulation tests
100 changes: 100 additions & 0 deletions tests/greenpak4/slg46620v/RingOsc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/***********************************************************************************************************************
* Copyright (C) 2016 Andrew Zonenberg and contributors *
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General *
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License along with this program; if not, you may *
* find one here: *
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt *
* or you may search the http://www.gnu.org website for the version 2.1 license, or you may write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
**********************************************************************************************************************/

#include <log.h>
#include <gpdevboard.h>
#include <unistd.h>
#include <math.h>

using namespace std;

bool RunTest(hdevice hdev);

int main(int argc, char* argv[])
{
g_log_sinks.emplace(g_log_sinks.begin(), new STDLogSink(Severity::VERBOSE));

//expect one arg: the bitstream
if(argc != 2)
{
LogNotice("Usage: [testcase] bitstream.txt\n");
return 1;
}

//Set up the test
hdevice hdev = MultiBoardTestSetup(argv[1], 25000, 3.3, SilegoPart::SLG46620V);
if(!hdev)
{
LogError("Failed to open board\n");
return 1;
}

//Run the actual test case
LogNotice("\n");
LogNotice("Running application test case\n");
if(!RunTest(hdev))
{
SetStatusLED(hdev, 0);
Reset(hdev);
return 1;
}

//Turn off the LED before declaring success
LogVerbose("\n");
LogVerbose("Test complete, resetting board\n");
SetStatusLED(hdev, 0);
ResetAllSiggens(hdev);
Reset(hdev);
USBCleanup(hdev);
return 0;
}

/**
@brief The actual application-layer test
*/
bool RunTest(hdevice hdev)
{
LogIndenter li;

//Set up the I/O config we need for this test
IOConfig ioConfig;
for(size_t i = 2; i <= 20; i++)
ioConfig.driverConfigs[i] = TP_RESET;
if(!SetIOConfig(hdev, ioConfig))
return false;

//Measure the oscillator frequency
unsigned int freq;
if(!MeasureOscillatorFrequency(hdev, freq))
return false;

unsigned int expected = 13500000;
LogVerbose("Measured ring oscillator frequency (with divide-by-2): %u Hz (expected %u)\n",
freq, expected);

int err = freq - expected;
LogVerbose(" Error: %d Hz\n", err);
int tolerance = 5000;
if(abs(err) > tolerance)
{
LogError("Error is too big (more than %d Hz)\n", tolerance);
return false;
}

return true;
}
49 changes: 49 additions & 0 deletions tests/greenpak4/slg46620v/RingOsc.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/***********************************************************************************************************************
* Copyright (C) 2016 Andrew Zonenberg and contributors *
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General *
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License along with this program; if not, you may *
* find one here: *
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt *
* or you may search the http://www.gnu.org website for the version 2.1 license, or you may write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
**********************************************************************************************************************/

`default_nettype none

/**
@brief HiL test case for GP_RINGOSC
OUTPUTS:
Oscillator output, divided by 2 (should be ~13.5 MHz)
*/
module RingOsc(clkout);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// I/O declarations

(* LOC = "P13" *)
output wire clkout;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// The oscillator

GP_RINGOSC #(
.PWRDN_EN(1),
.AUTO_PWRDN(0),
.HARDIP_DIV(1),
.FABRIC_DIV(2)
) ringosc (
.PWRDN(1'b0),
.CLKOUT_HARDIP(),
.CLKOUT_FABRIC(clkout)
);

endmodule

0 comments on commit b43cb6c

Please sign in to comment.