1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +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

@ -36,6 +36,34 @@
*/ */
#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 #endif // PIOS_HELPERS_H

View File

@ -181,7 +181,9 @@ 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;
#ifdef PIOS_INCLUDE_FREERTOS #ifdef PIOS_INCLUDE_FREERTOS
while(xSemaphoreTakeFromISR(usb_dev->statusCheckSemaphore, NULL) != pdTRUE); while (xSemaphoreTakeFromISR(usb_dev->statusCheckSemaphore, NULL) != pdTRUE) {
;
}
#endif #endif
bool reconnect = (lastStatus && !status); bool reconnect = (lastStatus && !status);
lastStatus = status; lastStatus = status;

View File

@ -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) { if (!usb_hid_dev->tx_out_cb) {
return false; return false;
} }
WRITE_MEMORY_BARRIER(); READ_MEMORY_BARRIER();
bool need_yield = false; bool need_yield = false;
#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE #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, 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; usb_hid_dev->rx_active = false;
return 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 */ /* The first byte is report ID (not checked), the second byte is the valid data length */
uint16_t headroom; uint16_t headroom;
bool need_yield = false; bool need_yield = false;