diff --git a/c-examples/com-monolithic/com_monolithic.c b/c-examples/com-monolithic/com_monolithic.c index 8e6b478..5362d24 100644 --- a/c-examples/com-monolithic/com_monolithic.c +++ b/c-examples/com-monolithic/com_monolithic.c @@ -24,10 +24,10 @@ int main(void) { init_uart(); init_radio(); // TAB initialization - rx_cmd_buff_t rx_cmd_buff = {.size=CMD_MAX_LEN}; - clear_rx_cmd_buff(&rx_cmd_buff); - tx_cmd_buff_t tx_cmd_buff = {.size=CMD_MAX_LEN}; - clear_tx_cmd_buff(&tx_cmd_buff); + rx_cmd_buff_t uart_rx_cmd_buff = {.size=CMD_MAX_LEN}; + clear_rx_cmd_buff(&uart_rx_cmd_buff); + tx_cmd_buff_t uart_tx_cmd_buff = {.size=CMD_MAX_LEN}; + clear_tx_cmd_buff(&uart_tx_cmd_buff); rx_cmd_buff_t radio_rx_cmd_buff = {.size=CMD_MAX_LEN}; clear_rx_cmd_buff(&radio_rx_cmd_buff); @@ -36,11 +36,12 @@ int main(void) { // TAB loop while(1) { - rx_uart0(&rx_cmd_buff); // Collect command bytes - forward(&rx_cmd_buff, &radio_tx_cmd_buff, 0); + rx_uart0(&uart_rx_cmd_buff); // Collect command bytes + tx_uart0(&uart_tx_cmd_buff); radio_transceive(&radio_rx_cmd_buff, &radio_tx_cmd_buff); - forward(&radio_rx_cmd_buff, &tx_cmd_buff, 1); - tx_uart0(&tx_cmd_buff); + + route(&uart_rx_cmd_buff, &uart_tx_cmd_buff, &radio_tx_cmd_buff); + route(&radio_rx_cmd_buff, &uart_tx_cmd_buff, &radio_tx_cmd_buff); } // Should never reach this point return 0; diff --git a/c-examples/com-monolithic/support/com.c b/c-examples/com-monolithic/support/com.c index 34aded9..58cc751 100644 --- a/c-examples/com-monolithic/support/com.c +++ b/c-examples/com-monolithic/support/com.c @@ -155,15 +155,18 @@ void rx_uart0(rx_cmd_buff_t* rx_cmd_buff_o) { } // } -void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o) { +void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o, int use_uart) { if( // if rx_cmd_buff_o->state==RX_CMD_BUFF_STATE_COMPLETE && // rx_cmd is valid AND tx_cmd_buff_o->empty // tx_cmd is empty ) { // write_reply(rx_cmd_buff_o, tx_cmd_buff_o); // Execute cmd and reply - uint8_t b = pop_tx_cmd_buff(tx_cmd_buff_o); // Pop 1st TX buffer byte - uart_send(UART0,b); // Generate TXDRDY event - uart_start_tx(UART0); // Start TX session + + if (use_uart) { + uint8_t b = pop_tx_cmd_buff(tx_cmd_buff_o); // Pop 1st TX buffer byte + uart_send(UART0,b); // Generate TXDRDY event + uart_start_tx(UART0); // Start TX session + } } // } @@ -329,4 +332,36 @@ void radio_transceive(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o } break; } +} + +#define GROUND + +void route(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* uart_tx_cmd_buff_o, tx_cmd_buff_t* radio_tx_cmd_buff_o) { + // Command route is src:dst, both are nibbles + int src = (rx_cmd_buff_o->data[ROUTE_INDEX] >> 4) & 0x0f; + int dst = (rx_cmd_buff_o->data[ROUTE_INDEX] >> 0) & 0x0f; + + #ifdef GROUND + if (dst != GND) { + forward(rx_cmd_buff_o, radio_tx_cmd_buff_o, 0); + } else { + forward(rx_cmd_buff_o, uart_tx_cmd_buff_o, 1); + } + #else + switch (dst) { + case CDH: + forward(rx_cmd_buff_o, uart_tx_cmd_buff_o, 1); + break; + case GND: + forward(rx_cmd_buff_o, radio_tx_cmd_buff_o, 0); + break; + case COM: + if (src == CDH) { + reply(rx_cmd_buff_o, uart_tx_cmd_buff_o, 1); + } else { + reply(rx_cmd_buff_o, radio_tx_cmd_buff_o, 0); + } + break; + } + #endif } \ No newline at end of file diff --git a/c-examples/com-monolithic/support/com.h b/c-examples/com-monolithic/support/com.h index 30721ab..98474ec 100644 --- a/c-examples/com-monolithic/support/com.h +++ b/c-examples/com-monolithic/support/com.h @@ -59,10 +59,11 @@ void init_radio(void); // Feature functions void rx_uart0(rx_cmd_buff_t* rx_cmd_buff_o); -void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o); +void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o, int use_uart); void tx_uart0(tx_cmd_buff_t* tx_cmd_buff_o); void write_forward(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o); void forward(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o, int use_uart); void radio_transceive(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o); +void route(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* uart_tx_cmd_buff_o, tx_cmd_buff_t* radio_tx_cmd_buff_o); #endif