Skip to content

Commit

Permalink
Halt FPGA if PROGRAM button held at start-up
Browse files Browse the repository at this point in the history
Manipulate INITN only at start-up
  • Loading branch information
mossmann committed Oct 6, 2023
1 parent 660f438 commit 515e9c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
28 changes: 13 additions & 15 deletions firmware/src/boards/cynthion_d11/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@

#include <apollo_board.h>

/**
* Sets up the I/O pins needed to configure the FPGA.
*/
void fpga_io_init(void)
{
// By default, keep PROGRAM_N from being driven.
gpio_set_pin_level(FPGA_PROGRAM, true);
gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_IN);
}

/*
* Allows or disallows the FPGA from configuring from flash. When disallowed,
* Allows or disallows the FPGA from configuring. When disallowed,
* initialization (erasing of configuration memory) takes place, but the FPGA
* does not proceed to the configuration phase.
*/
Expand All @@ -45,12 +35,22 @@ void permit_fpga_configuration(bool enable)
}

/**
* Requests that the FPGA clear its configuration and try to reconfigure.
* Sets up the I/O pins needed to configure the FPGA.
*/
void trigger_fpga_reconfiguration(void)
void fpga_io_init(void)
{
// By default, keep PROGRAM_N from being driven.
gpio_set_pin_level(FPGA_PROGRAM, true);
gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_IN);

permit_fpga_configuration(true);
}

/**
* Requests that the FPGA clear its configuration and try to reconfigure.
*/
void trigger_fpga_reconfiguration(void)
{
gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_OUT);
gpio_set_pin_level(FPGA_PROGRAM, false);

Expand All @@ -65,8 +65,6 @@ void trigger_fpga_reconfiguration(void)
*/
void force_fpga_offline(void)
{
permit_fpga_configuration(false);

gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_OUT);
gpio_set_pin_level(FPGA_PROGRAM, false);
}
1 change: 0 additions & 1 deletion firmware/src/boards/cynthion_d11/usb_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ void take_over_usb(void)
void switch_control_task(void)
{
if (gpio_get_pin_level(PROGRAM_BUTTON) == false) {
force_fpga_offline();
take_over_usb();
}
}
6 changes: 4 additions & 2 deletions firmware/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ int main(void)
// Trigger an FPGA reconfiguration; so the FPGA automatically
// configures itself from its SPI ROM on reset. This effectively
// makes the RESET button reset both the uC and the FPGA.
// Only reconfigure the FPGA if the PROGRAM button is not being
// pressed.
if (gpio_get_pin_level(PROGRAM_BUTTON) == true) {
trigger_fpga_reconfiguration();
} else {
// If PROGRAM button is held down at start-up, halt the FPGA
// instead of configuring it.
force_fpga_offline();
}

while (1) {
Expand Down

0 comments on commit 515e9c0

Please sign in to comment.