Skip to content

Commit

Permalink
eb-reset: add (untested) force option '-f' for command 'fpgareset'
Browse files Browse the repository at this point in the history
  • Loading branch information
dietrichb committed Jul 24, 2024
1 parent 4de94ed commit d26480a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
62 changes: 34 additions & 28 deletions tools/eb-reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* created : 2017
* author : Dietrich Beck, GSI-Darmstadt
* version : 02-Jun-2021
* version : 25-Jul-2024
*
* Command-line interface for resetting a FPGA. This forces a restart using the image stored
* in the local flash of the timing receiver.
Expand Down Expand Up @@ -36,7 +36,7 @@
* For all questions and ideas contact: d.beck@gsi.de
* Last update: 01-December-2017
********************************************************************************************/
#define EBRESET_VERSION "1.3.0"
#define EBRESET_VERSION "1.3.1"

// standard includes
#include <unistd.h> // getopt
Expand Down Expand Up @@ -71,6 +71,8 @@ static void help(void) {
fprintf(stderr, "\n");
fprintf(stderr, " -e display etherbone version\n");
fprintf(stderr, " -p<t> after FPGA reset, wait for the specified time [s] and probe device\n");
fprintf(stderr, " -f force 'fpgareset' of FPGA with incompatible FPGA gateware\n");
fprintf(stderr, " use the 'force' option at your own risk: this might brick your device\n");
fprintf(stderr, " -h display this help and exit\n");
fprintf(stderr, "\n");
fprintf(stderr, " wddisable disables the watchdog (preventing automated FPGA reset permanently)\n");
Expand Down Expand Up @@ -104,12 +106,13 @@ int main(int argc, char** argv) {

const char* devName;
const char* command;
int cmdExecuted=0;
int cmdExecuted = 0;

int getEBVersion=0;
int probeAfterReset=0;
int waitTime=1;
int exitCode=0;
int getEBVersion = 0;
int flagForce = 0;
int probeAfterReset = 0;
int waitTime = 1;
int exitCode = 0;
uint32_t nCPU;
uint64_t i;

Expand All @@ -121,29 +124,32 @@ int main(int argc, char** argv) {

program = argv[0];

while ((opt = getopt(argc, argv, "p:eh")) != -1) {
while ((opt = getopt(argc, argv, "p:feh")) != -1) {
switch (opt) {
case 'p' :
probeAfterReset=1;
waitTime = strtol(optarg, &tail, 0);
if (*tail != 0) {
fprintf(stderr, "Specify a proper number, not '%s'!\n", optarg);
exit(1);
} // if *tail
break;
case 'e':
getEBVersion=1;
break;
case 'h':
help();
return 0;
case 'p' :
probeAfterReset=1;
waitTime = strtol(optarg, &tail, 0);
if (*tail != 0) {
fprintf(stderr, "Specify a proper number, not '%s'!\n", optarg);
exit(1);
} // if *tail
break;
case 'e':
getEBVersion = 1;
break;
case 'f':
flagForce = 1;
break;
case 'h':
help();
return 0;
case ':':
case '?':
error = 1;
break;
default:
fprintf(stderr, "%s: bad getopt result\n", program);
return 1;
break;
default:
fprintf(stderr, "%s: bad getopt result\n", program);
return 1;
} // switch opt
} // while opt

Expand Down Expand Up @@ -186,8 +192,8 @@ int main(int argc, char** argv) {
cmdExecuted = 1;

// depending on the device, the etherbone cycle either completes or times out
status = wb_wr_reset(device, devIndex, 0xdeadbeef);
if ((status != EB_TIMEOUT) && (status != EB_OK)) die("RESET FPGA", status);
status = wb_wr_reset(device, devIndex, 0xdeadbeef, flagForce);
if ((status != EB_TIMEOUT) && (status != EB_OK) && (status != EB_ABI)) die("RESET FPGA", status);

if (probeAfterReset) {
//close, wait and reopen socket, try to read a property (here: ip) from the device
Expand Down
8 changes: 5 additions & 3 deletions tools/wb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// created : Apr 10, 2013
// author : Dietrich Beck, GSI-Darmstadt
// version : 22-Jun-2023
// version : 24-Jul-2024
//
// Api for wishbone devices for timing receiver nodes. This is not a timing receiver API,
// but only a temporary solution.
Expand Down Expand Up @@ -833,7 +833,7 @@ eb_status_t wb_1wire_get_temp(eb_device_t device, int devIndex, unsigned int bus
} // wb_1wire_get_temp


eb_status_t wb_wr_reset(eb_device_t device, int devIndex, uint32_t value)
eb_status_t wb_wr_reset(eb_device_t device, int devIndex, uint32_t value, int flagForce)
{
eb_data_t data;
eb_address_t address;
Expand All @@ -844,7 +844,9 @@ eb_status_t wb_wr_reset(eb_device_t device, int devIndex, uint32_t value)
return EB_OK;
#endif

if ((status = wb_check_device(device, FPGA_RESET_VENDOR, FPGA_RESET_PRODUCT, FPGA_RESET_VMAJOR, FPGA_RESET_VMINOR, devIndex, &reset_addr)) != EB_OK) return status;
status = wb_check_device(device, FPGA_RESET_VENDOR, FPGA_RESET_PRODUCT, FPGA_RESET_VMAJOR, FPGA_RESET_VMINOR, devIndex, &reset_addr);
if ((status != EB_OK) && (status != EB_ABI)) return status;
if ((status == EB_ABI) && !flagForce) return status;

address = reset_addr + FPGA_RESET_RESET;
data = (eb_data_t)value;
Expand Down
5 changes: 3 additions & 2 deletions tools/wb_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// -- Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
// version : 21-Jun-2023
//
#define WB_API_VERSION "0.16.0"
#define WB_API_VERSION "0.17.0"
//
// Api for wishbone devices for timing receiver nodes. This is not a timing receiver API.
//
Expand Down Expand Up @@ -211,7 +211,8 @@ eb_status_t wb_1wire_get_temp(eb_device_t device, // EB device
// reset the FPGA, reload new image from flash
eb_status_t wb_wr_reset(eb_device_t device, // EB device
int devIndex, // 0,1,2... - there may be more than 1 device on the WB bus
uint32_t value // value to be written to the reset controller
uint32_t value, // value to be written to the reset controller
int flagForce // 1: force reset even with incompatible gateware; 0: don't force reset
);

// disable or enable the watchdog for automated FPGA reset
Expand Down

0 comments on commit d26480a

Please sign in to comment.