From cca7320fe499d0f09237aa157cc3c6ad40a79bef Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 24 Dec 2021 15:55:49 +0000 Subject: [PATCH] Add a wait mode for the M0. In wait mode, the byte counter is advanced, but no SGPIO read/writes are done. This mode is intended to be used for implementing timed operations. --- firmware/hackrf_usb/m0_state.h | 7 +++-- firmware/hackrf_usb/sgpio_m0.s | 41 +++++++++++++++++++++++----- host/hackrf-tools/src/hackrf_debug.c | 2 +- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/firmware/hackrf_usb/m0_state.h b/firmware/hackrf_usb/m0_state.h index b0c558ea..ca6f057d 100644 --- a/firmware/hackrf_usb/m0_state.h +++ b/firmware/hackrf_usb/m0_state.h @@ -38,9 +38,10 @@ struct m0_state { enum m0_mode { M0_MODE_IDLE = 0, - M0_MODE_RX = 1, - M0_MODE_TX_START = 2, - M0_MODE_TX_RUN = 3, + M0_MODE_WAIT = 1, + M0_MODE_RX = 2, + M0_MODE_TX_START = 3, + M0_MODE_TX_RUN = 4, }; /* Address of m0_state is set in ldscripts. If you change the name of this diff --git a/firmware/hackrf_usb/sgpio_m0.s b/firmware/hackrf_usb/sgpio_m0.s index 2a5eb31a..646738ca 100644 --- a/firmware/hackrf_usb/sgpio_m0.s +++ b/firmware/hackrf_usb/sgpio_m0.s @@ -122,9 +122,10 @@ registers and fixed memory addresses. // Operating modes. .equ MODE_IDLE, 0 -.equ MODE_RX, 1 -.equ MODE_TX_START, 2 -.equ MODE_TX_RUN, 3 +.equ MODE_WAIT, 1 +.equ MODE_RX, 2 +.equ MODE_TX_START, 3 +.equ MODE_TX_RUN, 4 // Our slice chain is set up as follows (ascending data age; arrows are reversed for flow): // L -> F -> K -> C -> J -> E -> I -> A @@ -239,6 +240,8 @@ buf_ptr .req r4 cmp new_mode, #MODE_RX // if new_mode == RX: // 1 beq rx_loop // goto rx_loop // 1 thru, 3 taken bgt tx_loop // elif new_mode > RX: goto tx_loop // 1 thru, 3 taken + cmp new_mode, #MODE_WAIT // if new_mode == WAIT: // 1 + beq wait_loop // goto wait_loop // 1 thru, 3 taken b idle // goto idle // 3 .endm @@ -331,10 +334,12 @@ idle: // Wait for RX or TX mode to be set. mode .req r3 ldr mode, [state, #MODE] // mode = state.mode // 2 - cmp mode, #MODE_RX // if mode == RX: // 1 - bgt tx_start // if mode > RX: goto tx_start // 1 thru, 3 taken - blt idle // elif mode < RX: goto idle // 1 thru, 3 taken - b rx_start // goto rx_start // 3 + cmp mode, #MODE_WAIT // if mode < WAIT: // 1 + blt idle // goto idle // 1 thru, 3 taken + beq wait_start // elif mode == WAIT: goto wait_start // 1 thru, 3 taken + cmp mode, #MODE_RX // if mode > RX: // 1 + bgt tx_start // goto tx_start // 1 thru, 3 taken + b rx_start // goto rx_start // 3 tx_zeros: @@ -439,6 +444,28 @@ tx_write: // Jump to next mode if threshold reached, or back to TX loop start. jump_next_mode tx // jump_next_mode() // 13 +wait_start: + + // Reset counts. + reset_counts // reset_counts() // 10 + +wait_loop: + + // Wait for and clear SGPIO interrupt. + await_sgpio wait // await_sgpio() // 34 + + // Load mode, and return to idle if requested. + mode .req r3 + ldr mode, [state, #MODE] // mode = state.mode // 2 + cmp mode, #MODE_IDLE // if mode == IDLE: // 1 + beq idle // goto idle // 1 thru, 3 taken + + // Update counts. + update_counts // update_counts() // 4 + + // Jump to next mode if threshold reached, or back to wait loop start. + jump_next_mode wait // jump_next_mode() // 15 + rx_start: // Reset counts. diff --git a/host/hackrf-tools/src/hackrf_debug.c b/host/hackrf-tools/src/hackrf_debug.c index c1f1b90c..4cb5b41f 100644 --- a/host/hackrf-tools/src/hackrf_debug.c +++ b/host/hackrf-tools/src/hackrf_debug.c @@ -378,7 +378,7 @@ int write_register(hackrf_device* device, uint8_t part, } static const char * mode_name(uint32_t mode) { - const char *mode_names[] = {"IDLE", "RX", "TX_START", "TX_RUN"}; + const char *mode_names[] = {"IDLE", "WAIT", "RX", "TX_START", "TX_RUN"}; const uint32_t num_modes = sizeof(mode_names) / sizeof(mode_names[0]); if (mode < num_modes) return mode_names[mode];