diff --git a/flight/pios/common/pios_com.c b/flight/pios/common/pios_com.c index 9a4b83f60..db7d85f60 100644 --- a/flight/pios/common/pios_com.c +++ b/flight/pios/common/pios_com.c @@ -338,7 +338,7 @@ static int32_t PIOS_COM_SendBufferNonBlockingInternal(struct pios_com_dev *com_d { PIOS_Assert(com_dev); PIOS_Assert(com_dev->has_tx); - if (com_dev->driver->available && !com_dev->driver->available(com_dev->lower_id)) { + if (com_dev->driver->available && !(com_dev->driver->available(com_dev->lower_id) & COM_AVAILABLE_TX)) { /* * Underlying device is down/unconnected. * Dump our fifo contents and act like an infinite data sink. @@ -625,18 +625,26 @@ check_again: * used to check a link is established even if the device * is valid. */ -bool PIOS_COM_Available(uint32_t com_id) +uint32_t PIOS_COM_Available(uint32_t com_id) { struct pios_com_dev *com_dev = (struct pios_com_dev *)com_id; if (!PIOS_COM_validate(com_dev)) { - return false; + return COM_AVAILABLE_NONE; } // If a driver does not provide a query method assume always // available if valid if (com_dev->driver->available == NULL) { - return true; + if (com_dev->has_rx && com_dev->has_tx) { + return COM_AVAILABLE_RXTX; + } else if (com_dev->has_rx) { + return COM_AVAILABLE_RX; + } else if (com_dev->has_tx) { + return COM_AVAILABLE_TX; + } + + return COM_AVAILABLE_NONE; /* can this really happen? */ } return (com_dev->driver->available)(com_dev->lower_id); diff --git a/flight/pios/common/pios_rfm22b_com.c b/flight/pios/common/pios_rfm22b_com.c index 964cee585..1669e1095 100644 --- a/flight/pios/common/pios_rfm22b_com.c +++ b/flight/pios/common/pios_rfm22b_com.c @@ -40,7 +40,7 @@ static void PIOS_RFM22B_COM_RegisterRxCallback(uint32_t rfm22b_id, pios_com_call static void PIOS_RFM22B_COM_RegisterTxCallback(uint32_t rfm22b_id, pios_com_callback tx_out_cb, uint32_t context); static void PIOS_RFM22B_COM_TxStart(uint32_t rfm22b_id, uint16_t tx_bytes_avail); static void PIOS_RFM22B_COM_RxStart(uint32_t rfm22b_id, uint16_t rx_bytes_avail); -static bool PIOS_RFM22B_COM_Available(uint32_t rfm22b_com_id); +static uint32_t PIOS_RFM22B_COM_Available(uint32_t rfm22b_com_id); /* Local variables */ const struct pios_com_driver pios_rfm22b_com_driver = { @@ -135,9 +135,9 @@ static void PIOS_RFM22B_COM_RegisterTxCallback(uint32_t rfm22b_id, pios_com_call * @param[in] rfm22b_dev The device ID. * @return True of the device is available. */ -static bool PIOS_RFM22B_COM_Available(uint32_t rfm22b_id) +static uint32_t PIOS_RFM22B_COM_Available(uint32_t rfm22b_id) { - return PIOS_RFM22B_LinkStatus(rfm22b_id); + return PIOS_RFM22B_LinkStatus(rfm22b_id) ? COM_AVAILABLE_RXTX : COM_AVAILABLE_NONE; } #endif /* PIOS_INCLUDE_RFM22B_COM */ diff --git a/flight/pios/inc/pios_com.h b/flight/pios/inc/pios_com.h index b2591e4f0..cf209c2ba 100644 --- a/flight/pios/inc/pios_com.h +++ b/flight/pios/inc/pios_com.h @@ -39,15 +39,15 @@ typedef uint16_t (*pios_com_callback)(uint32_t context, uint8_t *buf, uint16_t b typedef void (*pios_com_callback_ctrl_line)(uint32_t context, uint32_t mask, uint32_t state); struct pios_com_driver { - void (*init)(uint32_t id); - void (*set_baud)(uint32_t id, uint32_t baud); - void (*set_ctrl_line)(uint32_t id, uint32_t mask, uint32_t state); - void (*tx_start)(uint32_t id, uint16_t tx_bytes_avail); - void (*rx_start)(uint32_t id, uint16_t rx_bytes_avail); - void (*bind_rx_cb)(uint32_t id, pios_com_callback rx_in_cb, uint32_t context); - void (*bind_tx_cb)(uint32_t id, pios_com_callback tx_out_cb, uint32_t context); - void (*bind_ctrl_line_cb)(uint32_t id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context); - bool (*available)(uint32_t id); + void (*init)(uint32_t id); + void (*set_baud)(uint32_t id, uint32_t baud); + void (*set_ctrl_line)(uint32_t id, uint32_t mask, uint32_t state); + void (*tx_start)(uint32_t id, uint16_t tx_bytes_avail); + void (*rx_start)(uint32_t id, uint16_t rx_bytes_avail); + void (*bind_rx_cb)(uint32_t id, pios_com_callback rx_in_cb, uint32_t context); + void (*bind_tx_cb)(uint32_t id, pios_com_callback tx_out_cb, uint32_t context); + void (*bind_ctrl_line_cb)(uint32_t id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context); + uint32_t (*available)(uint32_t id); }; /* Control line definitions */ @@ -68,7 +68,12 @@ extern int32_t PIOS_COM_SendString(uint32_t com_id, const char *str); extern int32_t PIOS_COM_SendFormattedStringNonBlocking(uint32_t com_id, const char *format, ...); extern int32_t PIOS_COM_SendFormattedString(uint32_t com_id, const char *format, ...); extern uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms); -extern bool PIOS_COM_Available(uint32_t com_id); +extern uint32_t PIOS_COM_Available(uint32_t com_id); + +#define COM_AVAILABLE_NONE (0) +#define COM_AVAILABLE_RX (1 << 0) +#define COM_AVAILABLE_TX (1 << 1) +#define COM_AVAILABLE_RXTX (COM_AVAILABLE_RX | COM_AVAILABLE_TX) #endif /* PIOS_COM_H */ diff --git a/flight/pios/osx/inc/pios_com.h b/flight/pios/osx/inc/pios_com.h index edac1e181..e10247bd4 100644 --- a/flight/pios/osx/inc/pios_com.h +++ b/flight/pios/osx/inc/pios_com.h @@ -35,13 +35,13 @@ typedef uint16_t (*pios_com_callback)(uint32_t context, uint8_t *buf, uint16_t buf_len, uint16_t *headroom, bool *task_woken); struct pios_com_driver { - void (*init)(uint32_t id); - void (*set_baud)(uint32_t id, uint32_t baud); - void (*tx_start)(uint32_t id, uint16_t tx_bytes_avail); - void (*rx_start)(uint32_t id, uint16_t rx_bytes_avail); - void (*bind_rx_cb)(uint32_t id, pios_com_callback rx_in_cb, uint32_t context); - void (*bind_tx_cb)(uint32_t id, pios_com_callback tx_out_cb, uint32_t context); - bool (*available)(uint32_t id); + void (*init)(uint32_t id); + void (*set_baud)(uint32_t id, uint32_t baud); + void (*tx_start)(uint32_t id, uint16_t tx_bytes_avail); + void (*rx_start)(uint32_t id, uint16_t rx_bytes_avail); + void (*bind_rx_cb)(uint32_t id, pios_com_callback rx_in_cb, uint32_t context); + void (*bind_tx_cb)(uint32_t id, pios_com_callback tx_out_cb, uint32_t context); + uint32_t (*available)(uint32_t id); }; /* Public Functions */ @@ -56,7 +56,12 @@ extern int32_t PIOS_COM_SendString(uint32_t com_id, const char *str); extern int32_t PIOS_COM_SendFormattedStringNonBlocking(uint32_t com_id, const char *format, ...); extern int32_t PIOS_COM_SendFormattedString(uint32_t com_id, const char *format, ...); extern uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms); -extern bool PIOS_COM_Available(uint32_t com_id); +extern uint32_t PIOS_COM_Available(uint32_t com_id); + +#define COM_AVAILABLE_NONE (0) +#define COM_AVAILABLE_RX (1 << 0) +#define COM_AVAILABLE_TX (1 << 1) +#define COM_AVAILABLE_RXTX (COM_AVAILABLE_RX | COM_AVAILABLE_TX) #endif /* PIOS_COM_H */ diff --git a/flight/pios/osx/osx/pios_com.c b/flight/pios/osx/osx/pios_com.c index 8eab84a4e..8cd754055 100644 --- a/flight/pios/osx/osx/pios_com.c +++ b/flight/pios/osx/osx/pios_com.c @@ -509,18 +509,26 @@ check_again: * used to check a link is established even if the device * is valid. */ -bool PIOS_COM_Available(uint32_t com_id) +uint32_t PIOS_COM_Available(uint32_t com_id) { struct pios_com_dev *com_dev = PIOS_COM_find_dev(com_id); if (!PIOS_COM_validate(com_dev)) { - return false; + return COM_AVAILABLE_NONE; } // If a driver does not provide a query method assume always // available if valid if (com_dev->driver->available == NULL) { - return true; + if (com_dev->has_rx && com_dev->has_tx) { + return COM_AVAILABLE_RXTX; + } else if (com_dev->has_rx) { + return COM_AVAILABLE_RX; + } else if (com_dev->has_tx) { + return COM_AVAILABLE_TX; + } + + return COM_AVAILABLE_NONE; /* can this really happen? */ } return (com_dev->driver->available)(com_dev->lower_id); diff --git a/flight/pios/posix/pios_com.c b/flight/pios/posix/pios_com.c index 8eab84a4e..8cd754055 100644 --- a/flight/pios/posix/pios_com.c +++ b/flight/pios/posix/pios_com.c @@ -509,18 +509,26 @@ check_again: * used to check a link is established even if the device * is valid. */ -bool PIOS_COM_Available(uint32_t com_id) +uint32_t PIOS_COM_Available(uint32_t com_id) { struct pios_com_dev *com_dev = PIOS_COM_find_dev(com_id); if (!PIOS_COM_validate(com_dev)) { - return false; + return COM_AVAILABLE_NONE; } // If a driver does not provide a query method assume always // available if valid if (com_dev->driver->available == NULL) { - return true; + if (com_dev->has_rx && com_dev->has_tx) { + return COM_AVAILABLE_RXTX; + } else if (com_dev->has_rx) { + return COM_AVAILABLE_RX; + } else if (com_dev->has_tx) { + return COM_AVAILABLE_TX; + } + + return COM_AVAILABLE_NONE; /* can this really happen? */ } return (com_dev->driver->available)(com_dev->lower_id); diff --git a/flight/pios/stm32f10x/pios_usb_cdc.c b/flight/pios/stm32f10x/pios_usb_cdc.c index e7c3c1fda..4b45cbeff 100644 --- a/flight/pios/stm32f10x/pios_usb_cdc.c +++ b/flight/pios/stm32f10x/pios_usb_cdc.c @@ -43,7 +43,7 @@ static void PIOS_USB_CDC_RegisterTxCallback(uint32_t usbcdc_id, pios_com_callbac static void PIOS_USB_CDC_RegisterRxCallback(uint32_t usbcdc_id, pios_com_callback rx_in_cb, uint32_t context); static void PIOS_USB_CDC_TxStart(uint32_t usbcdc_id, uint16_t tx_bytes_avail); static void PIOS_USB_CDC_RxStart(uint32_t usbcdc_id, uint16_t rx_bytes_avail); -static bool PIOS_USB_CDC_Available(uint32_t usbcdc_id); +static uint32_t PIOS_USB_CDC_Available(uint32_t usbcdc_id); const struct pios_com_driver pios_usb_cdc_com_driver = { .tx_start = PIOS_USB_CDC_TxStart, @@ -353,7 +353,7 @@ RESULT PIOS_USB_CDC_SetControlLineState(void) return USB_SUCCESS; } -static bool PIOS_USB_CDC_Available(uint32_t usbcdc_id) +static uint32_t PIOS_USB_CDC_Available(uint32_t usbcdc_id) { struct pios_usb_cdc_dev *usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id; @@ -361,8 +361,8 @@ static bool PIOS_USB_CDC_Available(uint32_t usbcdc_id) PIOS_Assert(valid); - return PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id) && - (control_line_state & USB_CDC_CONTROL_LINE_STATE_DTE_PRESENT); + return (PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id) && + (control_line_state & USB_CDC_CONTROL_LINE_STATE_DTE_PRESENT)) ? COM_AVAILABLE_RXTX : COM_AVAILABLE_NONE; } static struct usb_cdc_line_coding line_coding = { diff --git a/flight/pios/stm32f10x/pios_usb_hid.c b/flight/pios/stm32f10x/pios_usb_hid.c index 532a78a7c..6b1e9d81b 100644 --- a/flight/pios/stm32f10x/pios_usb_hid.c +++ b/flight/pios/stm32f10x/pios_usb_hid.c @@ -43,13 +43,14 @@ static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbhid_id, pios_com_callbac static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbhid_id, pios_com_callback rx_in_cb, uint32_t context); static void PIOS_USB_HID_TxStart(uint32_t usbhid_id, uint16_t tx_bytes_avail); static void PIOS_USB_HID_RxStart(uint32_t usbhid_id, uint16_t rx_bytes_avail); +static uint32_t PIOS_USB_HID_Available(uint32_t usbhid_id); const struct pios_com_driver pios_usb_hid_com_driver = { .tx_start = PIOS_USB_HID_TxStart, .rx_start = PIOS_USB_HID_RxStart, .bind_tx_cb = PIOS_USB_HID_RegisterTxCallback, .bind_rx_cb = PIOS_USB_HID_RegisterRxCallback, - .available = PIOS_USB_CheckAvailable, + .available = PIOS_USB_HID_Available, }; enum pios_usb_hid_dev_magic { @@ -370,4 +371,9 @@ static void PIOS_USB_HID_EP_OUT_Callback(void) #endif /* PIOS_INCLUDE_FREERTOS */ } +static uint32_t PIOS_USB_HID_Available(uint32_t usbhid_id) +{ + return PIOS_USB_CheckAvailable(usbhid_id) ? COM_AVAILABLE_RXTX : COM_AVAILABLE_NONE; +} + #endif /* PIOS_INCLUDE_USB_HID */ diff --git a/flight/pios/stm32f4xx/pios_usb_cdc.c b/flight/pios/stm32f4xx/pios_usb_cdc.c index 277165af2..830b26bad 100644 --- a/flight/pios/stm32f4xx/pios_usb_cdc.c +++ b/flight/pios/stm32f4xx/pios_usb_cdc.c @@ -43,7 +43,7 @@ static void PIOS_USB_CDC_RegisterRxCallback(uint32_t usbcdc_id, pios_com_callbac static void PIOS_USB_CDC_RegisterCtrlLineCallback(uint32_t usbcdc_id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context); static void PIOS_USB_CDC_TxStart(uint32_t usbcdc_id, uint16_t tx_bytes_avail); static void PIOS_USB_CDC_RxStart(uint32_t usbcdc_id, uint16_t rx_bytes_avail); -static bool PIOS_USB_CDC_Available(uint32_t usbcdc_id); +static uint32_t PIOS_USB_CDC_Available(uint32_t usbcdc_id); const struct pios_com_driver pios_usb_cdc_com_driver = { .tx_start = PIOS_USB_CDC_TxStart, @@ -445,7 +445,7 @@ static bool PIOS_USB_CDC_CTRL_IF_Setup(uint32_t usb_cdc_id, struct usb_setup_req return true; } -static bool PIOS_USB_CDC_Available(uint32_t usbcdc_id) +static uint32_t PIOS_USB_CDC_Available(uint32_t usbcdc_id) { struct pios_usb_cdc_dev *usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id; @@ -453,8 +453,8 @@ static bool PIOS_USB_CDC_Available(uint32_t usbcdc_id) PIOS_Assert(valid); - return PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id) && - (control_line_state & USB_CDC_CONTROL_LINE_STATE_DTE_PRESENT); + return (PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id) && + (control_line_state & USB_CDC_CONTROL_LINE_STATE_DTE_PRESENT)) ? COM_AVAILABLE_NONE : COM_AVAILABLE_RXTX; } /** diff --git a/flight/pios/stm32f4xx/pios_usb_hid.c b/flight/pios/stm32f4xx/pios_usb_hid.c index f80c3a567..0d1e7928c 100644 --- a/flight/pios/stm32f4xx/pios_usb_hid.c +++ b/flight/pios/stm32f4xx/pios_usb_hid.c @@ -41,13 +41,14 @@ static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbhid_id, pios_com_callbac static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbhid_id, pios_com_callback rx_in_cb, uint32_t context); static void PIOS_USB_HID_TxStart(uint32_t usbhid_id, uint16_t tx_bytes_avail); static void PIOS_USB_HID_RxStart(uint32_t usbhid_id, uint16_t rx_bytes_avail); +static uint32_t PIOS_USB_HID_Available(uint32_t usbhid_id); const struct pios_com_driver pios_usb_hid_com_driver = { .tx_start = PIOS_USB_HID_TxStart, .rx_start = PIOS_USB_HID_RxStart, .bind_tx_cb = PIOS_USB_HID_RegisterTxCallback, .bind_rx_cb = PIOS_USB_HID_RegisterRxCallback, - .available = PIOS_USB_CheckAvailable, + .available = PIOS_USB_HID_Available, }; enum pios_usb_hid_dev_magic { @@ -549,4 +550,9 @@ static bool PIOS_USB_HID_EP_OUT_Callback(uint32_t usb_hid_id, __attribute__((unu return rc; } +static uint32_t PIOS_USB_HID_Available(uint32_t usbhid_id) +{ + return PIOS_USB_CheckAvailable(usbhid_id) ? COM_AVAILABLE_RXTX : COM_AVAILABLE_NONE; +} + #endif /* PIOS_INCLUDE_USB_HID */