1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP-980 Extended the memory barrier macros and fixed barrier kind in pios_usb_hid

+review OPReview-501
This commit is contained in:
Alessio Morale 2013-06-06 10:15:15 +02:00
parent c340bfc294
commit ee7887c406
3 changed files with 38 additions and 8 deletions

View File

@ -34,8 +34,36 @@
* @return number of elements in x.
*
*/
#define NELEMENTS(x) (sizeof(x) / sizeof((x)[0]))
#define NELEMENTS(x) (sizeof(x) / sizeof((x)[0]))
#define WRITE_MEMORY_BARRIER() asm volatile("":::"memory")
/**
* @brief Compiler barrier: Disables compiler load/store reordering across the barrier
*
*/
#define COMPILER_BARRIER() asm volatile ("" ::: "memory")
// Memory barriers:
// Note that on single core Cortex M3 & M4, the is generally no need to use a processor memory barrier instruction such as DMB.
// See http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
// However, it makes sense to use these if we want to reduce issues if we ever port to a multicore processor in the future.
// An important exception for STM32 is when setting up the DMA engine - see the above reference for details.
/**
* @brief Read Acquire memory barrier
*/
#define READ_MEMORY_BARRIER() COMPILER_BARRIER()
/**
* @brief Write Release memory barrier
*/
#define WRITE_MEMORY_BARRIER() COMPILER_BARRIER()
/**
* @brief Full fence memory barrier
*/
#define MEMORY_BARRIER() COMPILER_BARRIER()
// For future multicore ARM v7 or later:
// The above three macros would be replaced with: asm volatile("dmb":::"memory")
#endif // PIOS_HELPERS_H

View File

@ -181,14 +181,16 @@ bool PIOS_USB_CheckAvailable(__attribute__((unused)) uint32_t id)
bool status = usb_found != 0 && transfer_possible ? 1 : 0;
#ifdef PIOS_INCLUDE_FREERTOS
while(xSemaphoreTakeFromISR(usb_dev->statusCheckSemaphore, NULL) != pdTRUE);
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) {
if (reconnect) {
raiseDisconnectionCallbacks();
}
return status;

View File

@ -68,10 +68,10 @@ struct pios_usb_hid_dev {
bool usb_if_enabled;
uint8_t rx_packet_buffer[PIOS_USB_BOARD_HID_DATA_LENGTH] __attribute__((aligned(4)));
volatile bool rx_active;
volatile bool rx_active;
uint8_t tx_packet_buffer[PIOS_USB_BOARD_HID_DATA_LENGTH] __attribute__((aligned(4)));
volatile bool tx_active;
volatile bool tx_active;
uint32_t rx_dropped;
uint32_t rx_oversize;
@ -187,7 +187,7 @@ static bool PIOS_USB_HID_SendReport(struct pios_usb_hid_dev *usb_hid_dev)
if (!usb_hid_dev->tx_out_cb) {
return false;
}
WRITE_MEMORY_BARRIER();
READ_MEMORY_BARRIER();
bool need_yield = false;
#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
@ -510,7 +510,7 @@ static bool PIOS_USB_HID_EP_OUT_Callback(uint32_t usb_hid_id, __attribute__((unu
usb_hid_dev->rx_active = false;
return false;
}
WRITE_MEMORY_BARRIER();
READ_MEMORY_BARRIER();
/* The first byte is report ID (not checked), the second byte is the valid data length */
uint16_t headroom;
bool need_yield = false;