Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lufa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
lufa
Commits
87ea060a
Commit
87ea060a
authored
13 years ago
by
Dean Camera
Browse files
Options
Downloads
Patches
Plain Diff
Added new RingBuffer_GetFreeCount() function to the library miscellaneous RingBuffer driver.
parent
6c4f7367
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
LUFA/Drivers/Misc/RingBuffer.h
+26
-8
26 additions, 8 deletions
LUFA/Drivers/Misc/RingBuffer.h
with
26 additions
and
8 deletions
LUFA/Drivers/Misc/RingBuffer.h
+
26
−
8
View file @
87ea060a
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
*/
*/
/** \file
/** \file
* \brief Lightweight ring buffer, for fast insertion/deletion of bytes.
* \brief Lightweight ring
(circular)
buffer, for fast insertion/deletion of bytes.
*
*
* Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of
* Lightweight ring buffer, for fast insertion/deletion. Multiple buffers can be created of
* different sizes to suit different needs.
* different sizes to suit different needs.
...
@@ -126,7 +126,7 @@
...
@@ -126,7 +126,7 @@
* \param[out] DataPtr Pointer to a global array that will hold the data stored into the ring buffer.
* \param[out] DataPtr Pointer to a global array that will hold the data stored into the ring buffer.
* \param[out] Size Maximum number of bytes that can be stored in the underlying data array.
* \param[out] Size Maximum number of bytes that can be stored in the underlying data array.
*/
*/
static
inline
void
RingBuffer_InitBuffer
(
RingBuffer_t
*
Buffer
,
uint8_t
*
const
DataPtr
,
const
uint16_t
Size
)
static
inline
void
RingBuffer_InitBuffer
(
RingBuffer_t
*
const
Buffer
,
uint8_t
*
const
DataPtr
,
const
uint16_t
Size
)
{
{
GCC_FORCE_POINTER_ACCESS
(
Buffer
);
GCC_FORCE_POINTER_ACCESS
(
Buffer
);
...
@@ -143,18 +143,36 @@
...
@@ -143,18 +143,36 @@
SetGlobalInterruptMask
(
CurrentGlobalInt
);
SetGlobalInterruptMask
(
CurrentGlobalInt
);
}
}
/** Retrieves the minimum number of bytes stored in a particular buffer. This value is computed
/** Retrieves the free space in a particular buffer. This value is computed by entering an atomic lock
* by entering an atomic lock on the buffer while the IN and OUT locations are fetched, so that
* on the buffer, so that the buffer cannot be modified while the computation takes place.
* the buffer cannot be modified while the computation takes place. This value should be cached
*
* when reading out the contents of the buffer, so that as small a time as possible is spent
* \note The value returned by this function is guaranteed to only be the maximum number of bytes
* in an atomic lock.
* free in the given buffer; this value may change as other threads write new data, thus
* the returned number should be used only to determine how many successive writes may safely
* be performed on the buffer when there is a single writer thread.
*
* \param[in] Buffer Pointer to a ring buffer structure whose free count is to be computed.
*
* \return Number of free bytes in the buffer.
*/
static
inline
uint16_t
RingBuffer_GetFreeCount
(
RingBuffer_t
*
const
Buffer
)
{
return
(
Buffer
->
Size
-
RingBuffer_GetCount
(
Buffer
));
}
/** Retrieves the current number of bytes stored in a particular buffer. This value is computed
* by entering an atomic lock on the buffer, so that the buffer cannot be modified while the
* computation takes place. This value should be cached when reading out the contents of the buffer,
* so that as small a time as possible is spent in an atomic lock.
*
*
* \note The value returned by this function is guaranteed to only be the minimum number of bytes
* \note The value returned by this function is guaranteed to only be the minimum number of bytes
* stored in the given buffer; this value may change as other threads write new data
and so
* stored in the given buffer; this value may change as other threads write new data
, thus
* the returned number should be used only to determine how many successive reads may safely
* the returned number should be used only to determine how many successive reads may safely
* be performed on the buffer.
* be performed on the buffer.
*
*
* \param[in] Buffer Pointer to a ring buffer structure whose count is to be computed.
* \param[in] Buffer Pointer to a ring buffer structure whose count is to be computed.
*
* \return Number of bytes currently stored in the buffer.
*/
*/
static
inline
uint16_t
RingBuffer_GetCount
(
RingBuffer_t
*
const
Buffer
)
static
inline
uint16_t
RingBuffer_GetCount
(
RingBuffer_t
*
const
Buffer
)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment