Replace blind interface descriptor search in the incomplete AndroidAccessoryHost...
[pub/USBasp.git] / LUFA / Drivers / Misc / RingBuffer.h
index 9319f11..c953638 100644 (file)
@@ -29,7 +29,7 @@
 */\r
 \r
 /** \file\r
- *  \brief Lightweight ring buffer, for fast insertion/deletion.\r
+ *  \brief Lightweight ring buffer, for fast insertion/deletion of bytes.\r
  *\r
  *  Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of\r
  *  different sizes to suit different needs.\r
@@ -41,7 +41,8 @@
  */\r
  \r
 /** \ingroup Group_MiscDrivers\r
- *  @defgroup Group_RingBuff Generic Byte Ring Buffer - LUFA/Drivers/Misc/RingBuffer.h\r
+ *  \defgroup Group_RingBuff Generic Byte Ring Buffer - LUFA/Drivers/Misc/RingBuffer.h\r
+ *  \brief Lightweight ring buffer, for fast insertion/deletion of bytes.\r
  *\r
  *  \section Sec_Dependencies Module Source Dependencies\r
  *  The following files must be built with any user project that uses this module:\r
@@ -65,7 +66,7 @@
  *      RingBuffer_t Buffer;\r
  *      uint8_t      BufferData[128];\r
  *\r
- *      // Initialise the buffer with the created storage array\r
+ *      // Initialize the buffer with the created storage array\r
  *      RingBuffer_InitBuffer(&Buffer, BufferData, sizeof(BufferData));\r
  *\r
  *      // Insert some data into the buffer\r
 #define __RING_BUFFER_H__\r
 \r
        /* Includes: */\r
-               #include <util/atomic.h>\r
-               #include <stdint.h>\r
-               #include <stdbool.h>\r
-\r
                #include "../../Common/Common.h"\r
 \r
+       /* Enable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       extern "C" {\r
+               #endif\r
+\r
        /* Type Defines: */\r
                /** \brief Ring Buffer Management Structure.\r
                 *\r
                 */\r
                typedef struct\r
                {\r
-                       uint8_t* In; /**< Current storage location in the circular buffer */\r
-                       uint8_t* Out; /**< Current retrieval location in the circular buffer */\r
-                       uint8_t* Start; /**< Pointer to the start of the buffer's underlying storage array */\r
-                       uint8_t* End; /**< Pointer to the end of the buffer's underlying storage array */\r
-                       uint8_t  Size; /**< Size of the buffer's underlying storage array */\r
-                       uint16_t Count; /**< Number of bytes currently stored in the buffer */\r
+                       uint8_t* In; /**< Current storage location in the circular buffer. */\r
+                       uint8_t* Out; /**< Current retrieval location in the circular buffer. */\r
+                       uint8_t* Start; /**< Pointer to the start of the buffer's underlying storage array. */\r
+                       uint8_t* End; /**< Pointer to the end of the buffer's underlying storage array. */\r
+                       uint8_t  Size; /**< Size of the buffer's underlying storage array. */\r
+                       uint16_t Count; /**< Number of bytes currently stored in the buffer. */\r
                } RingBuffer_t;\r
 \r
        /* Inline Functions: */\r
                {\r
                        GCC_FORCE_POINTER_ACCESS(Buffer);\r
 \r
-                       ATOMIC_BLOCK(ATOMIC_RESTORESTATE)\r
-                       {       \r
-                               Buffer->In     = DataPtr;\r
-                               Buffer->Out    = DataPtr;\r
-                               Buffer->Start  = &DataPtr[0];\r
-                               Buffer->End    = &DataPtr[Size];\r
-                               Buffer->Size   = Size;\r
-                               Buffer->Count  = 0;\r
-                       }\r
+                       uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();\r
+                       GlobalInterruptDisable();\r
+       \r
+                       Buffer->In     = DataPtr;\r
+                       Buffer->Out    = DataPtr;\r
+                       Buffer->Start  = &DataPtr[0];\r
+                       Buffer->End    = &DataPtr[Size];\r
+                       Buffer->Size   = Size;\r
+                       Buffer->Count  = 0;\r
+\r
+                       SetGlobalInterruptMask(CurrentGlobalInt);\r
                }\r
 \r
                /** Retrieves the minimum number of bytes stored in a particular buffer. This value is computed\r
                {\r
                        uint16_t Count;\r
 \r
-                       ATOMIC_BLOCK(ATOMIC_RESTORESTATE)\r
-                       {\r
-                               Count = Buffer->Count;\r
-                       }\r
+                       uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();\r
+                       GlobalInterruptDisable();\r
+                       \r
+                       Count = Buffer->Count;\r
 \r
+                       SetGlobalInterruptMask(CurrentGlobalInt);\r
                        return Count;\r
                }\r
 \r
                        if (++Buffer->In == Buffer->End)\r
                          Buffer->In = Buffer->Start;\r
 \r
-                       ATOMIC_BLOCK(ATOMIC_RESTORESTATE)\r
-                       {\r
-                               Buffer->Count++;\r
-                       }\r
+                       uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();\r
+                       GlobalInterruptDisable();\r
+                       \r
+                       Buffer->Count++;\r
+\r
+                       SetGlobalInterruptMask(CurrentGlobalInt);\r
                }\r
 \r
                /** Removes an element from the ring buffer.\r
                        if (++Buffer->Out == Buffer->End)\r
                          Buffer->Out = Buffer->Start;\r
 \r
-                       ATOMIC_BLOCK(ATOMIC_RESTORESTATE)\r
-                       {\r
-                               Buffer->Count--;\r
-                       }\r
+                       uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();\r
+                       GlobalInterruptDisable();\r
+                       \r
+                       Buffer->Count--;\r
+\r
+                       SetGlobalInterruptMask(CurrentGlobalInt);\r
 \r
                        return Data;\r
                }\r
                        return *Buffer->Out;\r
                }\r
 \r
+       /* Disable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       }\r
+               #endif\r
+\r
 #endif\r
 \r
 /** @} */\r