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

OP-980 Fix usb reconnection issue for Revolution target.

step 2: check for cable disconnection (vbus) and issue a SW reconnection
This commit is contained in:
Alessio Morale 2013-06-05 00:04:26 +02:00
parent 14b87383b9
commit ce2bce353f
3 changed files with 50 additions and 12 deletions

View File

@ -37,7 +37,7 @@ extern int32_t PIOS_USB_Reenumerate();
extern int32_t PIOS_USB_ChangeConnectionState(bool connected);
extern bool PIOS_USB_CableConnected(uint8_t id);
extern bool PIOS_USB_CheckAvailable(uint32_t id);
extern void PIOS_USB_RegisterDisconnectionCallback(void (*disconnectionCB)(void));
#endif /* PIOS_USB_H */
/**

View File

@ -34,12 +34,14 @@
#include "usb_core.h"
#include "pios_usb_board_data.h"
#include "pios_usb_priv.h"
#include <pios_usb_priv.h>
#include <pios_helpers.h>
/* Rx/Tx status */
static uint8_t transfer_possible = 0;
static void (*disconnection_cb_list[3])(void);
enum pios_usb_dev_magic {
PIOS_USB_DEV_MAGIC = 0x17365904,
};
@ -49,6 +51,8 @@ struct pios_usb_dev {
const struct pios_usb_cfg *cfg;
};
static void raiseDisconnectionCallbacks(void);
/**
* @brief Validate the usb device structure
* @returns true if valid device or false otherwise
@ -162,15 +166,43 @@ uint32_t usb_found;
bool PIOS_USB_CheckAvailable(__attribute__((unused)) uint32_t id)
{
struct pios_usb_dev *usb_dev = (struct pios_usb_dev *)pios_usb_id;
static bool lastStatus = false;
if (!PIOS_USB_validate(usb_dev)) {
return false;
}
usb_found = ((usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin) != 0) ^ usb_dev->cfg->vsense_active_low;
return usb_found;
return usb_found != 0 && transfer_possible ? 1 : 0;
bool status = usb_found != 0 && transfer_possible ? 1 : 0;
if(lastStatus && !status){
raiseDisconnectionCallbacks();
}
lastStatus = status;
return status;
}
/*
*
* Register a physical disconnection callback
*
*/
void PIOS_USB_RegisterDisconnectionCallback(void (*disconnectionCB)(void)){
PIOS_Assert(disconnectionCB);
for(uint32_t i = 0; i < NELEMENTS(disconnection_cb_list); i++){
if(disconnection_cb_list[i] == NULL){
disconnection_cb_list[i] = disconnectionCB;
return;
}
}
PIOS_Assert(0);
}
static void raiseDisconnectionCallbacks(void){
uint32_t i = 0;
while(i < NELEMENTS(disconnection_cb_list) && disconnection_cb_list[i] != NULL){
(disconnection_cb_list[i++])();
}
}
/*

View File

@ -46,6 +46,8 @@
#include "usbd_req.h" /* USBD_CtlError */
#include "usb_dcd_int.h" /* USBD_OTG_ISR_Handler */
static void reconnect(void);
/*
* External API
*/
@ -82,6 +84,9 @@ static USBD_Usr_cb_TypeDef user_callbacks;
void PIOS_USBHOOK_Activate(void)
{
PIOS_USB_RegisterDisconnectionCallback(&reconnect);
USBD_Init(&pios_usb_otg_core_handle,
USB_OTG_FS_CORE_ID,
&device_callbacks,
@ -271,12 +276,7 @@ static USBD_DEVICE device_callbacks = {
static void PIOS_USBHOOK_USR_Init(void)
{
PIOS_USB_ChangeConnectionState(false);
#if 1
/* Force a physical disconnect/reconnect */
DCD_DevDisconnect(&pios_usb_otg_core_handle);
DCD_DevConnect(&pios_usb_otg_core_handle);
#endif
reconnect();
}
static void PIOS_USBHOOK_USR_DeviceReset(__attribute__((unused)) uint8_t speed)
@ -483,4 +483,10 @@ static USBD_Class_cb_TypeDef class_callbacks = {
#endif /* USB_SUPPORT_USER_STRING_DESC */
};
static void reconnect(void){
/* Force a physical disconnect/reconnect */
DCD_DevDisconnect(&pios_usb_otg_core_handle);
DCD_DevConnect(&pios_usb_otg_core_handle);
}
#endif /* PIOS_INCLUDE_USB */