Experiments with gpio pins, for hardware sync

This commit is contained in:
Mike Davis
2016-12-10 18:47:38 +02:00
parent 242f73efb1
commit 3672f38b27
3 changed files with 47 additions and 5 deletions

View File

@ -86,10 +86,16 @@ static struct gpio_t gpio_rffc5072_clock = GPIO(5, 6);
static struct gpio_t gpio_rffc5072_data = GPIO(3, 3);
static struct gpio_t gpio_rffc5072_reset = GPIO(2, 14);
/*
static struct gpio_t gpio_sync_in_a = GPIO(3, 8);
static struct gpio_t gpio_sync_in_b = GPIO(3, 9);
static struct gpio_t gpio_sync_out_a = GPIO(3, 10);
static struct gpio_t gpio_sync_out_b = GPIO(3, 11);
*/
static struct gpio_t gpio_sync_in_a = GPIO(3, 10);
static struct gpio_t gpio_sync_in_b = GPIO(3, 11);
static struct gpio_t gpio_sync_out_a = GPIO(3, 8);
static struct gpio_t gpio_sync_out_b = GPIO(3, 9);
#endif
/* RF LDO control */
@ -846,6 +852,12 @@ void pin_setup(void) {
/* Safe state: start with VAA turned off: */
disable_rf_power();
gpio_input(&gpio_sync_in_a);
gpio_input(&gpio_sync_in_b);
gpio_output(&gpio_sync_out_a);
gpio_output(&gpio_sync_out_b);
#endif
/* enable input on SCL and SDA pins */
@ -897,6 +909,24 @@ void hw_sync_start() {
gpio_set(&gpio_sync_out_b);
}
void hw_sync_stop() {
gpio_clear(&gpio_sync_out_a);
gpio_clear(&gpio_sync_out_b);
}
void hw_sync_copy_state() {
if(gpio_read(&gpio_sync_in_a)) {
gpio_set(&gpio_sync_out_a);
} else {
gpio_clear(&gpio_sync_out_a);
}
if(gpio_read(&gpio_sync_in_b)) {
gpio_set(&gpio_sync_out_b);
} else {
gpio_clear(&gpio_sync_out_b);
}
}
bool hw_sync_ready() {
return (gpio_read(&gpio_sync_in_a) && gpio_read(&gpio_sync_in_b));
}

View File

@ -272,7 +272,10 @@ void led_off(const led_t led);
void led_toggle(const led_t led);
void hw_sync_start();
void hw_sync_stop();
bool hw_sync_ready();
void hw_sync_copy_state();
#ifdef __cplusplus
}

View File

@ -252,20 +252,27 @@ int main(void) {
int hw_sync_count = 0;
unsigned int phase = 0;
hw_sync_start();
while(true) {
// Check whether we need to initiate a CPLD update
if (start_cpld_update)
cpld_update();
hw_sync_copy_state();
// check for hardware sync
if(hw_sync_ready()) {
synced = true;
hw_sync_start();
} /*else if(hw_sync_count++ > 1000) {
//hw_sync_start();
} else if(hw_sync_count++ > 1000000) {
//hw_sync_stop();
led_toggle(LED3);
hw_sync_count = 0;
}*/
} else if(hw_sync_count == 500000) {
//hw_sync_start();
}
//int gpio_sync_in_flag = gpio_get(gpio_sync_in);
@ -276,7 +283,8 @@ int main(void) {
usb_transfer_schedule_block(
(transceiver_mode() == TRANSCEIVER_MODE_RX)
? &usb_endpoint_bulk_in : &usb_endpoint_bulk_out,
synced ? &usb_bulk_buffer[0x0000] : &usb_dummy_buffer[0x0000],
//synced ? &usb_bulk_buffer[0x0000] : &usb_dummy_buffer[0x0000],
&usb_bulk_buffer[0x0000],
0x4000,
NULL, NULL
);
@ -290,7 +298,8 @@ int main(void) {
usb_transfer_schedule_block(
(transceiver_mode() == TRANSCEIVER_MODE_RX)
? &usb_endpoint_bulk_in : &usb_endpoint_bulk_out,
synced ? &usb_bulk_buffer[0x4000] : &usb_dummy_buffer[0x4000],
//synced ? &usb_bulk_buffer[0x4000] : &usb_dummy_buffer[0x4000],
&usb_bulk_buffer[0x4000],
0x4000,
NULL, NULL
);