Skip to content

Commit

Permalink
tests: Added HiL test for GP_LFOSC
Browse files Browse the repository at this point in the history
azonenberg committed Dec 31, 2016
1 parent 691962d commit 0f3473a
Showing 3 changed files with 148 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
@@ -25,6 +25,7 @@ add_greenpak4_bitstream(SocketTestLoopback_STQFN20 SLG46620V)

add_greenpak4_hiltest(Bargraph SLG46620V)
add_greenpak4_hiltest(Latch SLG46620V)
add_greenpak4_hiltest(LFOsc SLG46620V)
add_greenpak4_hiltest(Luts SLG46620V)
add_greenpak4_hiltest(PGA SLG46620V)

100 changes: 100 additions & 0 deletions tests/greenpak4/slg46620v/LFOsc.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, 1.8, 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 = 865;
LogVerbose("Measured LF 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 = 5;
if(abs(err) > tolerance)
{
LogError("Error is too big (more than %d Hz)\n", tolerance);
return false;
}

return true;
}
47 changes: 47 additions & 0 deletions tests/greenpak4/slg46620v/LFOsc.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/***********************************************************************************************************************
* 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_LFOSC
OUTPUTS:
Oscillator output, divided by 2 (should be ~865 Hz)
*/
module LFOsc(clkout);

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

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

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

GP_LFOSC #(
.PWRDN_EN(0),
.AUTO_PWRDN(0),
.OUT_DIV(2)
) lfosc (
.PWRDN(1'b0),
.CLKOUT(clkout)
);

endmodule

0 comments on commit 0f3473a

Please sign in to comment.