Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
wip 2
  • Loading branch information
mndza committed May 9, 2024
1 parent 628bc46 commit eaff5bc
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 8 deletions.
1 change: 0 additions & 1 deletion firmware/src/boards/cynthion_d11/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ void trigger_fpga_reconfiguration(void)
gpio_set_pin_level(FPGA_PROGRAM, true);
gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_IN);


// Update internal state.
fpga_online = true;
}
17 changes: 15 additions & 2 deletions firmware/src/boards/cynthion_d11/fpga_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdbool.h>
#include "fpga_adv.h"
#include "usb_switch.h"
#include "apollo_board.h"
Expand Down Expand Up @@ -111,7 +112,7 @@ void fpga_adv_task(void)
{
#ifdef BOARD_HAS_USB_SWITCH
// Take over USB after timeout
if (board_millis() - last_phy_adv >= TIMEOUT) {
if (fpga_requesting_port() == false) {
take_over_usb();
} else if (defer_hand_off) {
hand_off_usb();
Expand All @@ -126,14 +127,26 @@ void fpga_adv_task(void)
void honor_fpga_adv(void)
{
#ifdef BOARD_HAS_USB_SWITCH
if (board_millis() - last_phy_adv < TIMEOUT) {
if (fpga_requesting_port()) {
hand_off_usb();
} else {
defer_hand_off = true;
}
#endif
}

/**
* True if we received an advertisement message within the last time window.
*/
bool fpga_requesting_port(void)
{
#ifdef BOARD_HAS_USB_SWITCH
return board_millis() - last_phy_adv < TIMEOUT;
#else
return false;
#endif
}


#ifdef BOARD_HAS_USB_SWITCH
/**
Expand Down
17 changes: 14 additions & 3 deletions firmware/src/boards/cynthion_d11/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@


#include "led.h"
#include "fpga.h"
#include "fpga_adv.h"
#include "usb_switch.h"


/** Store the current LED blink pattern. */
Expand Down Expand Up @@ -153,10 +156,18 @@ void heartbeat_task(void)

switch (blink_pattern) {

// Standard blink pattern for when the device is idle.
// Indicates that the device's JTAG lines are un-pulled.
// When the device is idle, use the following scheme for LEDs:
// - LED A: power indication (always on in Apollo)
// - LED B: FPGA allowed online (indicates PROGRAM toggle)
// - LED C: FPGA has requested CONTROL port
// - LED D: USB switched to FPGA
// - LED E: flashing patterns (e.g. fault indication)
case BLINK_IDLE:
led_toggle(LED_E);
led_set(LED_A, true);
led_set(LED_B, fpga_is_online());
led_set(LED_C, fpga_requesting_port());
led_set(LED_D, fpga_controls_usb_port());
led_set(LED_E, false);
break;

// Blink patterns for when the device is being used for JTAG
Expand Down
9 changes: 9 additions & 0 deletions firmware/src/boards/cynthion_d21/fpga_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (c) 2023 Great Scott Gadgets <[email protected]>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdbool.h>

/**
* Initialize FPGA_ADV receive-only serial port
Expand All @@ -27,3 +28,11 @@ void fpga_adv_task(void)
void honor_fpga_adv(void)
{
}

/**
* True if we received an advertisement message within the last time window.
*/
bool fpga_requesting_port(void)
{
return false;
}
9 changes: 9 additions & 0 deletions firmware/src/boards/daisho/fpga_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (c) 2023 Great Scott Gadgets <[email protected]>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdbool.h>

/**
* Initialize FPGA_ADV receive-only serial port
Expand All @@ -27,3 +28,11 @@ void fpga_adv_task(void)
void honor_fpga_adv(void)
{
}

/**
* True if we received an advertisement message within the last time window.
*/
bool fpga_requesting_port(void)
{
return false;
}
9 changes: 9 additions & 0 deletions firmware/src/boards/qtpy/fpga_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (c) 2023 Great Scott Gadgets <[email protected]>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdbool.h>

/**
* Initialize FPGA_ADV receive-only serial port
Expand All @@ -27,3 +28,11 @@ void fpga_adv_task(void)
void honor_fpga_adv(void)
{
}

/**
* True if we received an advertisement message within the last time window.
*/
bool fpga_requesting_port(void)
{
return false;
}
9 changes: 9 additions & 0 deletions firmware/src/boards/samd11_xplained/fpga_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (c) 2023 Great Scott Gadgets <[email protected]>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdbool.h>

/**
* Initialize FPGA_ADV receive-only serial port
Expand All @@ -27,3 +28,11 @@ void fpga_adv_task(void)
void honor_fpga_adv(void)
{
}

/**
* True if we received an advertisement message within the last time window.
*/
bool fpga_requesting_port(void)
{
return false;
}
4 changes: 4 additions & 0 deletions firmware/src/fpga_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ void fpga_adv_task(void);
*/
void honor_fpga_adv(void);

/**
* True if we received an advertisement message within the last time window.
*/
bool fpga_requesting_port(void);

#endif
14 changes: 13 additions & 1 deletion firmware/src/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@
* with different semantic meanings.
*/
typedef enum {
BLINK_IDLE = 500,
BLINK_IDLE = 0,
BLINK_JTAG_CONNECTED = 150,
BLINK_JTAG_UPLOADING = 50,

BLINK_FLASH_CONNECTED = 130,
} blink_pattern_t;


/**
* LED events.
*
* Predefined events that can be handled with board-specific code.
*/
typedef enum {
EVENT_POWER,
EVENT_FPGA_ALLOWED_ONLINE,
EVENT_FPGA_REQUESTED_PORT,
EVENT_FPGA_HAS_PORT,
} led_event_t;


/**
* Sets the active LED blink pattern.
Expand Down
13 changes: 13 additions & 0 deletions firmware/src/usb_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ void take_over_usb(void)
switch_state = SWITCH_MCU;
#endif
}


/**
* True if the USB switch handed over the port to the FPGA.
*/
bool fpga_controls_usb_port(void)
{
#ifdef BOARD_HAS_USB_SWITCH
return switch_state == SWITCH_FPGA;
#else
return false;
#endif
}
6 changes: 5 additions & 1 deletion firmware/src/usb_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef __USB_SWITCH_H__
#define __USB_SWITCH_H__

#include <stdbool.h>

/**
* Hand off shared USB port to FPGA.
Expand All @@ -21,5 +22,8 @@ void hand_off_usb(void);
*/
void take_over_usb(void);


/**
* True if the USB switch handed over the port to the FPGA.
*/
bool fpga_controls_usb_port(void);
#endif

0 comments on commit eaff5bc

Please sign in to comment.