Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: azonenberg/openfpga
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a7e7e464c586
Choose a base ref
...
head repository: azonenberg/openfpga
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d0676007b23f
Choose a head ref
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on Oct 21, 2016

  1. doc: silenced latex so it doesn't hide errors/warnings from other com…

    …pile steps with all the spam
    azonenberg committed Oct 21, 2016
    Copy the full SHA
    af8a9f3 View commit details
  2. Copy the full SHA
    293817f View commit details
  3. Copy the full SHA
    893f3bb View commit details
  4. gp4prog/gpdevboard: Moved some common initialization into gpdevboard …

    …so we can use it in HiL tests
    azonenberg committed Oct 21, 2016
    Copy the full SHA
    d067600 View commit details
Showing with 212 additions and 77 deletions.
  1. +2 −2 doc/CMakeLists.txt
  2. +2 −73 src/gp4prog/main.cpp
  3. +1 −0 src/gpdevboard/CMakeLists.txt
  4. +6 −0 src/gpdevboard/gpdevboard.h
  5. +111 −0 src/gpdevboard/utils.cpp
  6. +55 −2 tests/greenpak4/CMakeLists.txt
  7. +35 −0 tests/greenpak4/HIL_PGA.cpp
4 changes: 2 additions & 2 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gp4-hdl.pdf
COMMAND pdflatex -halt-on-error ${CMAKE_CURRENT_SOURCE_DIR}/gp4-hdl.tex
COMMAND pdflatex -halt-on-error ${CMAKE_CURRENT_SOURCE_DIR}/gp4-hdl.tex
COMMAND pdflatex -halt-on-error ${CMAKE_CURRENT_SOURCE_DIR}/gp4-hdl.tex > /dev/null
COMMAND pdflatex -halt-on-error ${CMAKE_CURRENT_SOURCE_DIR}/gp4-hdl.tex > /dev/null
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gp4-hdl.tex
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM)
75 changes: 2 additions & 73 deletions src/gp4prog/main.cpp
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ const char *BitFunction(SilegoPart part, size_t bitno);

bool SocketTest(hdevice hdev, SilegoPart part);
bool TrimOscillator(hdevice hdev, SilegoPart part, double voltage, unsigned freq, uint8_t &ftw);
bool CheckStatus(hdevice hdev);

enum class BitstreamKind {
UNRECOGNIZED,
@@ -255,50 +254,10 @@ int main(int argc, char* argv[])
if(console_verbosity >= Severity::NOTICE)
ShowVersion();

//Set up libusb
if(!USBSetup())
return 1;

// Try opening the board in "orange" mode
LogNotice("\nSearching for developer board\n");
hdevice hdev = OpenDevice(0x0f0f, 0x0006);
//Open the dev board
hdevice hdev = OpenBoard();
if(!hdev)
{
// Try opening the board in "white" mode
hdev = OpenDevice(0x0f0f, 0x8006);
if(!hdev)
{
LogError("No device found, giving up\n");
return 1;
}

// Change the board into "orange" mode
LogVerbose("Switching developer board from bootloader mode\n");
if(!SwitchMode(hdev))
return 1;

// Takes a while to switch and re-enumerate
usleep(1200 * 1000);

// Try opening the board in "orange" mode again
hdev = OpenDevice(0x0f0f, 0x0006);
if(!hdev)
{
LogError("Could not switch mode, giving up\n");
return 1;
}
}

//Get string descriptors
string name, vendor;
if(!GetStringDescriptor(hdev, 1, name) || //board name
!GetStringDescriptor(hdev, 2, vendor)) //manufacturer
{
return 1;
}
LogNotice("Found: %s %s\n", vendor.c_str(), name.c_str());
//string 0x80 is 02 03 for this board... what does that mean? firmware rev or something?
//it's read by emulator during startup but no "2" and "3" are printed anywhere...

//If we're run with no bitstream and no reset flag, stop now without changing board configuration
if(downloadFilename.empty() && uploadFilename.empty() && voltage == 0.0 && nets.empty() &&
@@ -308,12 +267,6 @@ int main(int argc, char* argv[])
return 0;
}

//Check that we're in good standing
if(!CheckStatus(hdev)) {
LogError("Fault condition detected during initial check, exiting\n");
return 1;
}

//Light up the status LED
if(!SetStatusLED(hdev, 1))
return 1;
@@ -710,30 +663,6 @@ const char *BitFunction(SilegoPart part, size_t bitno)
return bitFunction;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Status check

bool CheckStatus(hdevice hdev)
{
LogDebug("Requesting board status\n");

BoardStatus status;
if(!GetStatus(hdev, status))
return false;
LogVerbose("Board voltages: A = %.3f V, B = %.3f V\n", status.voltageA, status.voltageB);

if(status.externalOverCurrent)
LogError("Overcurrent condition detected on external supply\n");
if(status.internalOverCurrent)
LogError("Overcurrent condition detected on internal supply\n");
if(status.internalUnderVoltage)
LogError("Undervoltage condition detected on internal supply\n");

return !(status.externalOverCurrent &&
status.internalOverCurrent &&
status.internalUnderVoltage);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Socket test

1 change: 1 addition & 0 deletions src/gpdevboard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_library(gpdevboard STATIC
usb.cpp
utils.cpp
protocol.cpp)

target_include_directories(gpdevboard
6 changes: 6 additions & 0 deletions src/gpdevboard/gpdevboard.h
Original file line number Diff line number Diff line change
@@ -244,4 +244,10 @@ bool MeasureOscillatorFrequency(hdevice hdev, unsigned &freq);

bool GetStatus(hdevice hdev, BoardStatus &status);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// High-level command helpers

bool CheckStatus(hdevice hdev);
hdevice OpenBoard();

#endif
111 changes: 111 additions & 0 deletions src/gpdevboard/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/***********************************************************************************************************************
* 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>

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Status check

bool CheckStatus(hdevice hdev)
{
LogDebug("Requesting board status\n");

BoardStatus status;
if(!GetStatus(hdev, status))
return false;
LogVerbose("Board voltages: A = %.3f V, B = %.3f V\n", status.voltageA, status.voltageB);

if(status.externalOverCurrent)
LogError("Overcurrent condition detected on external supply\n");
if(status.internalOverCurrent)
LogError("Overcurrent condition detected on internal supply\n");
if(status.internalUnderVoltage)
LogError("Undervoltage condition detected on internal supply\n");

return !(status.externalOverCurrent &&
status.internalOverCurrent &&
status.internalUnderVoltage);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Initialization

/**
@brief Connect to the board, but don't change anything
*/
hdevice OpenBoard()
{
//Set up libusb
if(!USBSetup())
return NULL;

//Try opening the board in "orange" mode
LogNotice("\nSearching for developer board\n");
hdevice hdev = OpenDevice(0x0f0f, 0x0006);
if(!hdev)
{
//Try opening the board in "white" mode
hdev = OpenDevice(0x0f0f, 0x8006);
if(!hdev)
{
LogError("No device found, giving up\n");
return NULL;
}

//Change the board into "orange" mode
LogVerbose("Switching developer board from bootloader mode\n");
if(!SwitchMode(hdev))
return NULL;

//Takes a while to switch and re-enumerate
usleep(1200 * 1000);

//Try opening the board in "orange" mode again
hdev = OpenDevice(0x0f0f, 0x0006);
if(!hdev)
{
LogError("Could not switch mode, giving up\n");
return NULL;
}
}

//Get string descriptors
string name, vendor;
if(!GetStringDescriptor(hdev, 1, name) || //board name
!GetStringDescriptor(hdev, 2, vendor)) //manufacturer
{
return NULL;
}
LogNotice("Found: %s %s\n", vendor.c_str(), name.c_str());
//string 0x80 is 02 03 for this board... what does that mean? firmware rev or something?
//it's read by emulator during startup but no "2" and "3" are printed anywhere...

//Check that we're in good standing
if(!CheckStatus(hdev))
{
LogError("Fault condition detected during initial check, exiting\n");
return NULL;
}

//Done
return hdev;
}
57 changes: 55 additions & 2 deletions tests/greenpak4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
function(add_greenpak4_test name)
########################################################################################################################
# Synthesize an HDL file for GP4 (TODO specify device family as arg?)
function(add_greenpak4_netlist name)

add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.json"
COMMAND "${YOSYS_COMMAND}" -q
@@ -9,6 +12,40 @@ function(add_greenpak4_test name)
COMMENT "Synthesizing Verilog file ${CMAKE_CURRENT_SOURCE_DIR}/${name}"
VERBATIM)

endfunction()

########################################################################################################################
# PAR an HDL file

function(add_greenpak4_bitstream name)

add_greenpak4_netlist(${name})

add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt"
COMMAND gp4par "--stdout-only"
--usercode 41
--output "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt"
--logfile "${CMAKE_CURRENT_BINARY_DIR}/${name}-par.log"
"${CMAKE_CURRENT_BINARY_DIR}/${name}.json"
"--quiet"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${name}.json"
DEPENDS gp4par
COMMENT "Place and route netlist ${CMAKE_CURRENT_BINARY_DIR}/${name}.json"
VERBATIM)

add_custom_target(bitstream-gp4-${name}
ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt")

endfunction()

########################################################################################################################
# Run PAR as a test

function(add_greenpak4_test name)
add_greenpak4_netlist(${name})

add_custom_target(testcase-gp4-${name}
ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${name}.json")
@@ -23,6 +60,9 @@ function(add_greenpak4_test name)
"--debug")
endfunction()

########################################################################################################################
# Run all of the PAR-only tests

add_greenpak4_test(Bargraph)
add_greenpak4_test(Blinky)
add_greenpak4_test(Dac)
@@ -31,7 +71,20 @@ add_greenpak4_test(Ethernet)
add_greenpak4_test(Inverters)
add_greenpak4_test(Location)
add_greenpak4_test(Loop)
add_greenpak4_test(PGA)
add_greenpak4_test(POR)
add_greenpak4_test(Tristate)
add_greenpak4_test(Vector)

########################################################################################################################
# Compile bitstreams for HiL tests

add_greenpak4_bitstream(PGA)

########################################################################################################################
# Compile binaries for HiL tests (no install required here)

add_executable(HIL_PGA
HIL_PGA.cpp)

target_link_libraries(HIL_PGA
gpdevboard)
35 changes: 35 additions & 0 deletions tests/greenpak4/HIL_PGA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/***********************************************************************************************************************
* 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>

using namespace std;

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

//expect one arg: the bitstream
if(argc != 2)
LogFatal("Usage: [testcase] bitstream.txt");

//

return 0;
}