Add (manual) switch for TX and RX mode.
Add code for configuring TX mode. TODO: Consolidate lots of repetitive code.
This commit is contained in:
@ -38,6 +38,12 @@
|
|||||||
#include "usb_descriptor.h"
|
#include "usb_descriptor.h"
|
||||||
#include "usb_standard_request.h"
|
#include "usb_standard_request.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TRANSCEIVER_MODE_RX,
|
||||||
|
TRANSCEIVER_MODE_TX,
|
||||||
|
} transceiver_mode_t;
|
||||||
|
static transceiver_mode_t transceiver_mode = TRANSCEIVER_MODE_TX;
|
||||||
|
|
||||||
uint8_t* const usb_bulk_buffer = (uint8_t*)0x20004000;
|
uint8_t* const usb_bulk_buffer = (uint8_t*)0x20004000;
|
||||||
static volatile uint32_t usb_bulk_buffer_offset = 0;
|
static volatile uint32_t usb_bulk_buffer_offset = 0;
|
||||||
static const uint32_t usb_bulk_buffer_mask = 32768 - 1;
|
static const uint32_t usb_bulk_buffer_mask = 32768 - 1;
|
||||||
@ -202,13 +208,16 @@ bool usb_set_configuration(
|
|||||||
// hard-coding, this whole function can move into a shared/reusable
|
// hard-coding, this whole function can move into a shared/reusable
|
||||||
// library.
|
// library.
|
||||||
if( device->configuration && (device->configuration->number == 1) ) {
|
if( device->configuration && (device->configuration->number == 1) ) {
|
||||||
usb_endpoint_init(&usb_endpoint_bulk_in);
|
if( transceiver_mode == TRANSCEIVER_MODE_RX ) {
|
||||||
usb_endpoint_init(&usb_endpoint_bulk_out);
|
sgpio_configure_for_rx_deep();
|
||||||
|
usb_endpoint_init(&usb_endpoint_bulk_in);
|
||||||
|
} else {
|
||||||
|
sgpio_configure_for_tx_deep();
|
||||||
|
usb_endpoint_init(&usb_endpoint_bulk_out);
|
||||||
|
}
|
||||||
|
|
||||||
usb_init_buffers_bulk();
|
usb_init_buffers_bulk();
|
||||||
|
|
||||||
sgpio_configure_for_rx_deep();
|
|
||||||
|
|
||||||
nvic_set_priority(NVIC_M4_SGPIO_IRQ, 0);
|
nvic_set_priority(NVIC_M4_SGPIO_IRQ, 0);
|
||||||
nvic_enable_irq(NVIC_M4_SGPIO_IRQ);
|
nvic_enable_irq(NVIC_M4_SGPIO_IRQ);
|
||||||
SGPIO_SET_EN_1 = (1 << SGPIO_SLICE_A);
|
SGPIO_SET_EN_1 = (1 << SGPIO_SLICE_A);
|
||||||
@ -237,14 +246,25 @@ void sgpio_irqhandler() {
|
|||||||
SGPIO_CLR_STATUS_1 = 0xFFFFFFFF;
|
SGPIO_CLR_STATUS_1 = 0xFFFFFFFF;
|
||||||
|
|
||||||
uint32_t* const p = (uint32_t*)&usb_bulk_buffer[usb_bulk_buffer_offset];
|
uint32_t* const p = (uint32_t*)&usb_bulk_buffer[usb_bulk_buffer_offset];
|
||||||
p[7] = SGPIO_REG_SS(SGPIO_SLICE_A);
|
if( transceiver_mode == TRANSCEIVER_MODE_RX ) {
|
||||||
p[6] = SGPIO_REG_SS(SGPIO_SLICE_I);
|
p[7] = SGPIO_REG_SS(SGPIO_SLICE_A);
|
||||||
p[5] = SGPIO_REG_SS(SGPIO_SLICE_E);
|
p[6] = SGPIO_REG_SS(SGPIO_SLICE_I);
|
||||||
p[4] = SGPIO_REG_SS(SGPIO_SLICE_J);
|
p[5] = SGPIO_REG_SS(SGPIO_SLICE_E);
|
||||||
p[3] = SGPIO_REG_SS(SGPIO_SLICE_C);
|
p[4] = SGPIO_REG_SS(SGPIO_SLICE_J);
|
||||||
p[2] = SGPIO_REG_SS(SGPIO_SLICE_K);
|
p[3] = SGPIO_REG_SS(SGPIO_SLICE_C);
|
||||||
p[1] = SGPIO_REG_SS(SGPIO_SLICE_F);
|
p[2] = SGPIO_REG_SS(SGPIO_SLICE_K);
|
||||||
p[0] = SGPIO_REG_SS(SGPIO_SLICE_L);
|
p[1] = SGPIO_REG_SS(SGPIO_SLICE_F);
|
||||||
|
p[0] = SGPIO_REG_SS(SGPIO_SLICE_L);
|
||||||
|
} else {
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_A) = p[7];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_I) = p[6];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_E) = p[5];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_J) = p[4];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_C) = p[3];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_K) = p[2];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_F) = p[1];
|
||||||
|
SGPIO_REG_SS(SGPIO_SLICE_L) = p[0];
|
||||||
|
}
|
||||||
|
|
||||||
usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask;
|
usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask;
|
||||||
}
|
}
|
||||||
@ -291,12 +311,35 @@ int main(void) {
|
|||||||
ssp1_set_mode_max5864();
|
ssp1_set_mode_max5864();
|
||||||
max5864_xcvr();
|
max5864_xcvr();
|
||||||
|
|
||||||
while(true) {
|
// TODO: If this turns out to be the same code, simplify.
|
||||||
while( usb_bulk_buffer_offset < 16384 );
|
if( transceiver_mode == TRANSCEIVER_MODE_RX ) {
|
||||||
usb_endpoint_schedule_no_int(&usb_endpoint_bulk_in, &usb_td_bulk[0]);
|
while(true) {
|
||||||
|
// Wait until buffer 0 is received.
|
||||||
|
while( usb_bulk_buffer_offset < 16384 );
|
||||||
|
|
||||||
while( usb_bulk_buffer_offset >= 16384 );
|
// Set up IN transfer to send buffer 0.
|
||||||
usb_endpoint_schedule_no_int(&usb_endpoint_bulk_in, &usb_td_bulk[1]);
|
usb_endpoint_schedule_no_int(&usb_endpoint_bulk_in, &usb_td_bulk[0]);
|
||||||
|
|
||||||
|
// Wait until buffer 1 is received.
|
||||||
|
while( usb_bulk_buffer_offset >= 16384 );
|
||||||
|
|
||||||
|
// Set up IN transfer to send buffer 1.
|
||||||
|
usb_endpoint_schedule_no_int(&usb_endpoint_bulk_in, &usb_td_bulk[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while(true) {
|
||||||
|
// Wait until buffer 0 is transmitted.
|
||||||
|
while( usb_bulk_buffer_offset < 16384 );
|
||||||
|
|
||||||
|
// Set up OUT transfer to fill buffer 0.
|
||||||
|
usb_endpoint_schedule_no_int(&usb_endpoint_bulk_out, &usb_td_bulk[0]);
|
||||||
|
|
||||||
|
// Wait until buffer 1 is transmitted.
|
||||||
|
while( usb_bulk_buffer_offset >= 16384 );
|
||||||
|
|
||||||
|
// Set up OUT transfer to fill buffer 1.
|
||||||
|
usb_endpoint_schedule_no_int(&usb_endpoint_bulk_out, &usb_td_bulk[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user