+static void bsb_check_reply(void)
+{
+ // Match received frame in bsb_rx_status_and_frame to expected replies
+ // and set the status in byte 0.
+
+ byte *frame = bsb_rx_status_and_frame + 1;
+ // XXX: This might be executed too fast, so we can still be in TX_STATE_SENT
+ if (bsb.tx_state == TX_STATE_WAITING_FOR_REPLY || bsb.tx_state == TX_STATE_SENT) {
+ if (frame[BF_DEST] == BSB_ADDR_GATEWAY &&
+ frame[BF_SRC] == bsb.tx_buf[BF_DEST] ^ 0x80 &&
+ frame[BF_OP] < 32 &&
+ bsb.reply_type_mask & (1 << frame[BF_OP])) {
+ debug_printf("BSB: Matched reply\n");
+ bsb.tx_state = TX_STATE_OFF;
+ bsb_stats.tx_ok_replied++;
+ bsb_rx_status_and_frame[0] = TX_RESULT_OK;
+ gpio_set(GPIOB, GPIO0); // Turn the TX LED off
+ return;
+ }
+ }
+
+ bsb_rx_status_and_frame[0] = TX_RESULT_NONE;
+}
+