1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

Merged in mindnever/librepilot/LP-495_USB_CDC_ep_status_nak_fix_F4 (pull request #403)

LP-495 F4 USB CDC: remove internal rx_active state tracking and use actual endpoint status instead (like F1)

Approved-by: Alessio Morale <alessiomorale@gmail.com>
Approved-by: Philippe Renon <philippe_renon@yahoo.fr>
Approved-by: Lalanne Laurent <f5soh@free.fr>
Approved-by: Eric Price <corvuscorax@cybertrench.com>
Approved-by: Vladimir Zidar <mr_w@mindnever.org>
This commit is contained in:
Vladimir Zidar 2017-03-30 18:02:16 +00:00 committed by Philippe Renon
commit f0457e654a
3 changed files with 12 additions and 7 deletions

View File

@ -74,4 +74,7 @@ extern void PIOS_USBHOOK_EndpointRx(uint8_t epnum, uint8_t *buf, uint16_t len);
extern void PIOS_USBHOOK_Activate(void);
extern void PIOS_USBHOOK_Deactivate(void);
extern uint32_t PIOS_USBHOOK_EndpointGetStatus(uint8_t epnum);
#endif /* PIOS_USBHOOK_H */

View File

@ -36,6 +36,7 @@
#include "pios_usb_cdc_priv.h"
#include "pios_usb_board_data.h" /* PIOS_BOARD_*_DATA_LENGTH */
#include "pios_usbhook.h" /* PIOS_USBHOOK_* */
#include "usb_core.h" /* USB_OTG_EP_RX_VALID */
/* Implement COM layer driver API */
static void PIOS_USB_CDC_RegisterTxCallback(uint32_t usbcdc_id, pios_com_callback tx_out_cb, uint32_t context);
@ -84,7 +85,6 @@ struct pios_usb_cdc_dev {
bool usb_data_if_enabled;
uint8_t rx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH] __attribute__((aligned(4)));
volatile bool rx_active;
/*
* NOTE: This is -1 as somewhat of a hack. It ensures that we always send packets
@ -191,8 +191,7 @@ int32_t PIOS_USB_CDC_Init(uint32_t *usbcdc_id, const struct pios_usb_cdc_cfg *cf
pios_usb_cdc_id = (uint32_t)usb_cdc_dev;
/* Rx and Tx are not active yet */
usb_cdc_dev->rx_active = false;
/* Tx is not active yet */
usb_cdc_dev->tx_active = false;
/* Clear stats */
@ -275,11 +274,11 @@ static void PIOS_USB_CDC_RxStart(uint32_t usbcdc_id, uint16_t rx_bytes_avail)
}
// If endpoint was stalled and there is now space make it valid
if (!usb_cdc_dev->rx_active && (rx_bytes_avail >= PIOS_USB_BOARD_CDC_DATA_LENGTH)) {
if ((PIOS_USBHOOK_EndpointGetStatus(usb_cdc_dev->cfg->data_rx_ep) != USB_OTG_EP_RX_VALID)
&& (rx_bytes_avail >= PIOS_USB_BOARD_CDC_DATA_LENGTH)) {
PIOS_USBHOOK_EndpointRx(usb_cdc_dev->cfg->data_rx_ep,
usb_cdc_dev->rx_packet_buffer,
sizeof(usb_cdc_dev->rx_packet_buffer));
usb_cdc_dev->rx_active = true;
}
}
@ -687,7 +686,6 @@ static bool PIOS_USB_CDC_DATA_EP_OUT_Callback(
if (!usb_cdc_dev->rx_in_cb) {
/* No Rx call back registered, disable the receiver */
usb_cdc_dev->rx_active = false;
return false;
}
@ -714,7 +712,6 @@ static bool PIOS_USB_CDC_DATA_EP_OUT_Callback(
rc = true;
} else {
/* Not enough room left for a message, apply backpressure */
usb_cdc_dev->rx_active = false;
rc = false;
}

View File

@ -218,6 +218,11 @@ void PIOS_USBHOOK_EndpointRx(uint8_t epnum, uint8_t *buf, uint16_t len)
DCD_EP_PrepareRx(&pios_usb_otg_core_handle, epnum, buf, len);
}
uint32_t PIOS_USBHOOK_EndpointGetStatus(uint8_t epnum)
{
return DCD_GetEPStatus(&pios_usb_otg_core_handle, epnum);
}
/*
* Device level hooks into STM USB library
*/