Replace TX flag with a mode setting.
This is to let us start adding new operatin modes for the M0.
This commit is contained in:
@ -26,9 +26,14 @@
|
||||
#include <usb_request.h>
|
||||
|
||||
struct m0_state {
|
||||
uint32_t mode;
|
||||
uint32_t m0_count;
|
||||
uint32_t m4_count;
|
||||
uint32_t tx;
|
||||
};
|
||||
|
||||
enum m0_mode {
|
||||
M0_MODE_RX = 0,
|
||||
M0_MODE_TX = 1,
|
||||
};
|
||||
|
||||
/* Address of m0_state is set in ldscripts. If you change the name of this
|
||||
|
@ -108,9 +108,13 @@ registers and fixed memory addresses.
|
||||
.equ STATE_BASE, 0x20007000
|
||||
|
||||
// Offsets into the state structure.
|
||||
.equ M0_COUNT, 0x00
|
||||
.equ M4_COUNT, 0x04
|
||||
.equ TX, 0x08
|
||||
.equ MODE, 0x00
|
||||
.equ M0_COUNT, 0x04
|
||||
.equ M4_COUNT, 0x08
|
||||
|
||||
// Operating modes.
|
||||
.equ MODE_RX, 0
|
||||
.equ MODE_TX, 1
|
||||
|
||||
// Our slice chain is set up as follows (ascending data age; arrows are reversed for flow):
|
||||
// L -> F -> K -> C -> J -> E -> I -> A
|
||||
@ -159,9 +163,9 @@ main:
|
||||
// Initialise state.
|
||||
zero .req r0
|
||||
mov zero, #0 // zero = 0 // 1
|
||||
str zero, [state, #MODE] // state.mode = zero // 2
|
||||
str zero, [state, #M0_COUNT] // state.m0_count = zero // 2
|
||||
str zero, [state, #M4_COUNT] // state.m4_count = zero // 2
|
||||
str zero, [state, #TX] // state.tx = zero // 2
|
||||
|
||||
loop:
|
||||
// The worst case timing is assumed to occur when reading the interrupt
|
||||
@ -200,14 +204,13 @@ loop:
|
||||
and buf_ptr, count // buf_ptr &= count // 1
|
||||
add buf_ptr, buf_base // buf_ptr += buf_base // 1
|
||||
|
||||
tx .req r0
|
||||
|
||||
// Load direction (TX or RX)
|
||||
ldr tx, [state, #TX] // tx = state.tx // 2
|
||||
// Load mode.
|
||||
mode .req r0
|
||||
ldr mode, [state, #MODE] // mode = state.mode // 2
|
||||
|
||||
// TX?
|
||||
lsr tx, #1 // tx >>= 1 // 1
|
||||
bcc direction_rx // if !carry: goto direction_rx // 1 thru, 3 taken
|
||||
cmp mode, #MODE_RX // if mode == RX: // 1
|
||||
beq direction_rx // goto direction_rx // 1 thru, 3 taken
|
||||
|
||||
direction_tx:
|
||||
|
||||
|
@ -269,7 +269,7 @@ void transceiver_shutdown(void)
|
||||
led_off(LED2);
|
||||
led_off(LED3);
|
||||
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_OFF);
|
||||
m0_state.tx = false;
|
||||
m0_state.mode = M0_MODE_RX;
|
||||
}
|
||||
|
||||
void transceiver_startup(const transceiver_mode_t mode) {
|
||||
@ -282,13 +282,13 @@ void transceiver_startup(const transceiver_mode_t mode) {
|
||||
led_off(LED3);
|
||||
led_on(LED2);
|
||||
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_RX);
|
||||
m0_state.tx = false;
|
||||
m0_state.mode = M0_MODE_RX;
|
||||
break;
|
||||
case TRANSCEIVER_MODE_TX:
|
||||
led_off(LED2);
|
||||
led_on(LED3);
|
||||
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_TX);
|
||||
m0_state.tx = true;
|
||||
m0_state.mode = M0_MODE_TX;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -378,10 +378,16 @@ int write_register(hackrf_device* device, uint8_t part,
|
||||
}
|
||||
|
||||
static void print_state(hackrf_m0_state *state) {
|
||||
const char *mode_names[] = {"RX", "TX"};
|
||||
const uint32_t num_modes = sizeof(mode_names) / sizeof(mode_names[0]);
|
||||
printf("M0 state:\n");
|
||||
printf("Mode: %u (%s)\n",
|
||||
state->mode,
|
||||
state->mode < num_modes ?
|
||||
mode_names[state->mode] :
|
||||
"UNKNOWN");
|
||||
printf("M0 count: %u bytes\n", state->m0_count);
|
||||
printf("M4 count: %u bytes\n", state->m4_count);
|
||||
printf("TX: %u\n", state->tx);
|
||||
}
|
||||
|
||||
static void usage() {
|
||||
|
@ -157,12 +157,12 @@ typedef struct {
|
||||
|
||||
/** State of the SGPIO loop running on the M0 core. */
|
||||
typedef struct {
|
||||
/** Operating mode. */
|
||||
uint32_t mode;
|
||||
/** Number of bytes transferred by the M0. */
|
||||
uint32_t m0_count;
|
||||
/** Number of bytes transferred by the M4. */
|
||||
uint32_t m4_count;
|
||||
/** TX flag. */
|
||||
uint32_t tx;
|
||||
} hackrf_m0_state;
|
||||
|
||||
struct hackrf_device_list {
|
||||
|
Reference in New Issue
Block a user