Added new RingBuffer_GetFreeCount() function to the library miscellaneous RingBuffer...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 11 Jul 2011 05:51:35 +0000 (05:51 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 11 Jul 2011 05:51:35 +0000 (05:51 +0000)
LUFA/Drivers/Misc/RingBuffer.h

index c953638..937cb4a 100644 (file)
@@ -29,7 +29,7 @@
 */\r
 \r
 /** \file\r
 */\r
 \r
 /** \file\r
- *  \brief Lightweight ring buffer, for fast insertion/deletion of bytes.\r
+ *  \brief Lightweight ring (circular) 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
  *\r
  *  Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of\r
  *  different sizes to suit different needs.\r
                 *  \param[out] DataPtr  Pointer to a global array that will hold the data stored into the ring buffer.\r
                 *  \param[out] Size     Maximum number of bytes that can be stored in the underlying data array.\r
                 */\r
                 *  \param[out] DataPtr  Pointer to a global array that will hold the data stored into the ring buffer.\r
                 *  \param[out] Size     Maximum number of bytes that can be stored in the underlying data array.\r
                 */\r
-               static inline void RingBuffer_InitBuffer(RingBuffer_t* Buffer, uint8_t* const DataPtr, const uint16_t Size)\r
+               static inline void RingBuffer_InitBuffer(RingBuffer_t* const Buffer, uint8_t* const DataPtr, const uint16_t Size)\r
                {\r
                        GCC_FORCE_POINTER_ACCESS(Buffer);\r
 \r
                {\r
                        GCC_FORCE_POINTER_ACCESS(Buffer);\r
 \r
                        SetGlobalInterruptMask(CurrentGlobalInt);\r
                }\r
 \r
                        SetGlobalInterruptMask(CurrentGlobalInt);\r
                }\r
 \r
-               /** Retrieves the minimum number of bytes stored in a particular buffer. This value is computed\r
-                *  by entering an atomic lock on the buffer while the IN and OUT locations are fetched, so that\r
-                *  the buffer cannot be modified while the computation takes place. This value should be cached\r
-                *  when reading out the contents of the buffer, so that as small a time as possible is spent\r
-                *  in an atomic lock.\r
+               /** Retrieves the free space in a particular buffer. This value is computed by entering an atomic lock\r
+                *  on the buffer, so that the buffer cannot be modified while the computation takes place.\r
+                *\r
+                *  \note The value returned by this function is guaranteed to only be the maximum number of bytes\r
+                *        free in the given buffer; this value may change as other threads write new data, thus\r
+                *        the returned number should be used only to determine how many successive writes may safely\r
+                *        be performed on the buffer when there is a single writer thread.\r
+                *\r
+                *  \param[in] Buffer  Pointer to a ring buffer structure whose free count is to be computed.\r
+                *\r
+                *  \return Number of free bytes in the buffer.\r
+                */\r
+               static inline uint16_t RingBuffer_GetFreeCount(RingBuffer_t* const Buffer)\r
+               {\r
+                       return (Buffer->Size - RingBuffer_GetCount(Buffer));\r
+               }\r
+\r
+               /** Retrieves the current number of bytes stored in a particular buffer. This value is computed\r
+                *  by entering an atomic lock on the buffer, so that the buffer cannot be modified while the\r
+                *  computation takes place. This value should be cached when reading out the contents of the buffer,\r
+                *  so that as small a time as possible is spent in an atomic lock.\r
                 *\r
                 *  \note The value returned by this function is guaranteed to only be the minimum number of bytes\r
                 *\r
                 *  \note The value returned by this function is guaranteed to only be the minimum number of bytes\r
-                *        stored in the given buffer; this value may change as other threads write new data and so\r
+                *        stored in the given buffer; this value may change as other threads write new data, thus\r
                 *        the returned number should be used only to determine how many successive reads may safely\r
                 *        be performed on the buffer.\r
                 *\r
                 *  \param[in] Buffer  Pointer to a ring buffer structure whose count is to be computed.\r
                 *        the returned number should be used only to determine how many successive reads may safely\r
                 *        be performed on the buffer.\r
                 *\r
                 *  \param[in] Buffer  Pointer to a ring buffer structure whose count is to be computed.\r
+                *\r
+                *  \return Number of bytes currently stored in the buffer.\r
                 */\r
                static inline uint16_t RingBuffer_GetCount(RingBuffer_t* const Buffer)\r
                {\r
                 */\r
                static inline uint16_t RingBuffer_GetCount(RingBuffer_t* const Buffer)\r
                {\r