mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-980 Insert locking while checking status in PIOS_USB_CheckAvailable
+review OPReview-501
This commit is contained in:
parent
5fa73624da
commit
c340bfc294
@ -49,6 +49,9 @@ enum pios_usb_dev_magic {
|
|||||||
struct pios_usb_dev {
|
struct pios_usb_dev {
|
||||||
enum pios_usb_dev_magic magic;
|
enum pios_usb_dev_magic magic;
|
||||||
const struct pios_usb_cfg *cfg;
|
const struct pios_usb_cfg *cfg;
|
||||||
|
#ifdef PIOS_INCLUDE_FREERTOS
|
||||||
|
xSemaphoreHandle statusCheckSemaphore;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static void raiseDisconnectionCallbacks(void);
|
static void raiseDisconnectionCallbacks(void);
|
||||||
@ -71,7 +74,8 @@ static struct pios_usb_dev *PIOS_USB_alloc(void)
|
|||||||
if (!usb_dev) {
|
if (!usb_dev) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
vSemaphoreCreateBinary(usb_dev->statusCheckSemaphore);
|
||||||
|
xSemaphoreGive(usb_dev->statusCheckSemaphore);
|
||||||
usb_dev->magic = PIOS_USB_DEV_MAGIC;
|
usb_dev->magic = PIOS_USB_DEV_MAGIC;
|
||||||
return usb_dev;
|
return usb_dev;
|
||||||
}
|
}
|
||||||
@ -176,10 +180,17 @@ bool PIOS_USB_CheckAvailable(__attribute__((unused)) uint32_t id)
|
|||||||
|
|
||||||
bool status = usb_found != 0 && transfer_possible ? 1 : 0;
|
bool status = usb_found != 0 && transfer_possible ? 1 : 0;
|
||||||
|
|
||||||
if (lastStatus && !status) {
|
#ifdef PIOS_INCLUDE_FREERTOS
|
||||||
|
while(xSemaphoreTakeFromISR(usb_dev->statusCheckSemaphore, NULL) != pdTRUE);
|
||||||
|
#endif
|
||||||
|
bool reconnect = (lastStatus && !status);
|
||||||
|
lastStatus = status;
|
||||||
|
#ifdef PIOS_INCLUDE_FREERTOS
|
||||||
|
xSemaphoreGiveFromISR(usb_dev->statusCheckSemaphore, NULL);
|
||||||
|
#endif
|
||||||
|
if(reconnect) {
|
||||||
raiseDisconnectionCallbacks();
|
raiseDisconnectionCallbacks();
|
||||||
}
|
}
|
||||||
lastStatus = status;
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user