|
| 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 | +} |
0 commit comments