Skip to content

Commit 6dd0fb9

Browse files
author
zigam
committed
Merge remote-tracking branch 'origin/develop' into main
2 parents 7da9fe7 + 06f91b2 commit 6dd0fb9

4 files changed

Lines changed: 75 additions & 44 deletions

File tree

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ use those two get functionalities simultaniously.
2121

2222
Function "ring_buffer_get_by_index" supports two kind of access types:
2323

24-
1. NORMAL ACCESS: classical aproach, where index is a positive
24+
1. **NORMAL ACCESS: classical aproach**, where index is a positive
2525
number and simple represants buffer index. This approach
2626
has no information about time stamps of values inside buffer.
2727
Range: [0, size)
2828

29-
2. INVERS ACCESS: chronologically aproach, where index is a negative number.
29+
2. **INVERS ACCESS: chronologically aproach**, where index is a negative number.
3030
Meaning that "-1" value will always returns latest value in
3131
buffer and "-size" index value will return oldest value
32-
in buffer. This feature becomes very handy when performing
33-
digital filtering where ring buffer can represants sample
32+
in buffer. ***This feature becomes very handy when performing
33+
digital filtering (convolution) where ring buffer can represants sample
3434
window and thus easy access from oldest to latest sample
35-
can be achieved with invers access.
35+
can be achieved with invers access.***
3636
Range of index: [-size, -1]
3737

3838

@@ -41,21 +41,28 @@ Function "ring_buffer_get_by_index" supports two kind of access types:
4141

4242
This module needs only ANSI C standard libraries.
4343

44-
## API
44+
## Multientry Limitations
45+
46+
Guidance for multi-entry usage:
47+
- **It is recomented to use ring_buffer between two task/interrupts/cores in provider/consumer manner.** Meaning one task/interrupt/core is writing to ring_buffer and other task/interrupt/core is reading from it.
48+
- **It is not recommended for two or more task/interrupt/core to read/write to same ring_buffer instance!**
4549

46-
- ring_buffer_status_t **ring_buffer_init** (p_ring_buffer_t * p_ring_buffer, const uint32_t size, const ring_buffer_attr_t * const p_attr);
47-
- ring_buffer_status_t **ring_buffer_is_init** (p_ring_buffer_t buf_inst, bool * const p_is_init);
4850

49-
- ring_buffer_status_t **ring_buffer_add** (p_ring_buffer_t buf_inst, const void * const p_item);
50-
- ring_buffer_status_t **ring_buffer_get** (p_ring_buffer_t buf_inst, void * const p_item);
51-
- ring_buffer_status_t **ring_buffer_get_by_index** (p_ring_buffer_t buf_inst, void * const p_item, const int32_t idx);
52-
- ring_buffer_status_t **ring_buffer_reset** (p_ring_buffer_t buf_inst);
51+
## API
5352

54-
- ring_buffer_status_t **ring_buffer_get_name** (p_ring_buffer_t buf_inst, char * const p_name);
55-
- ring_buffer_status_t **ring_buffer_get_taken** (p_ring_buffer_t buf_inst, uint32_t * const p_taken);
56-
- ring_buffer_status_t **ring_buffer_get_free** (p_ring_buffer_t buf_inst, uint32_t * const p_free);
57-
- ring_buffer_status_t **ring_buffer_get_size** (p_ring_buffer_t buf_inst, uint32_t * const p_size);
58-
- ring_buffer_status_t **ring_buffer_get_item_size** (p_ring_buffer_t buf_inst, uint32_t * const p_item_size);
53+
| API Functions | Description | Prototype |
54+
| --- | ----------- | ----- |
55+
| **ring_buffer_init** | Initialization of ring buffer | ring_buffer_status_t ring_buffer_init(p_ring_buffer_t * p_ring_buffer, const uint32_t size, const ring_buffer_attr_t * const p_attr) |
56+
| **ring_buffer_is_init** | Get initialization flag | ring_buffer_status_t ring_buffer_is_init(p_ring_buffer_t buf_inst, bool * const p_is_init) |
57+
| **ring_buffer_add** | Add element to ring buffer in FIFO form | ring_buffer_status_t ring_buffer_add(p_ring_buffer_t buf_inst, const void * const p_item) |
58+
| **ring_buffer_get** | Get element from ring buffer in FIFO form | ring_buffer_status_t ring_buffer_get(p_ring_buffer_t buf_inst, void * const p_item) |
59+
| **ring_buffer_get_by_index** | Get element from ring buffer without any side effects. Access by index. | ring_buffer_status_t ring_buffer_get_by_index(p_ring_buffer_t buf_inst, void * const p_item, const int32_t idx) |
60+
| **ring_buffer_reset** | Reset ring buffer | ring_buffer_status_t ring_buffer_reset(p_ring_buffer_t buf_inst) |
61+
| **ring_buffer_get_name** | Get ring buffer name | ring_buffer_status_t ring_buffer_get_name(p_ring_buffer_t buf_inst, char * const p_name)|
62+
| **ring_buffer_get_taken** | Get number of taken space of elements inside a buffer | ring_buffer_status_t ring_buffer_get_taken(p_ring_buffer_t buf_inst, uint32_t * const p_taken)|
63+
| **ring_buffer_get_free** | Get number of free space of elements inside a buffer | ring_buffer_status_t ring_buffer_get_free(p_ring_buffer_t buf_inst, uint32_t * const p_free)|
64+
| **ring_buffer_get_size** | Get size of all items inside ring buffer | ring_buffer_status_t ring_buffer_get_size(p_ring_buffer_t buf_inst, uint32_t * const p_size)|
65+
| **ring_buffer_get_item_size** | Get item size in bytes | ring_buffer_status_t ring_buffer_get_item_size(p_ring_buffer_t buf_inst, uint32_t * const p_item_size)|
5966

6067

6168
NOTE: Detailed description of functions can be found in doxygen (doc/**ring_buffer_Vx_x_x.zip**)!

src/ring_buffer.c

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*@brief Ring (circular) buffer for general use
88
*@author Ziga Miklosic
99
*@date 03.02.2021
10-
*@version V2.0.1
10+
*@version V2.0.2
1111
*
1212
*@section Description
1313
*
@@ -435,39 +435,50 @@ ring_buffer_status_t ring_buffer_init(p_ring_buffer_t * p_ring_buffer, const uin
435435

436436
if ( NULL != p_ring_buffer )
437437
{
438-
// Allocate ring buffer instance space
439-
*p_ring_buffer = malloc( sizeof( ring_buffer_t ));
438+
// Check if that instance is already allocated
439+
// By meaning that this buffer instance was initialised before...
440+
if ( NULL == *p_ring_buffer )
441+
{
442+
// Allocate ring buffer instance space
443+
*p_ring_buffer = malloc( sizeof( ring_buffer_t ));
440444

441-
// Allocation success
442-
if ( NULL != *p_ring_buffer )
443-
{
444-
(*p_ring_buffer)->size_of_buffer = size;
445-
(*p_ring_buffer)->head = 0;
446-
(*p_ring_buffer)->tail = 0;
447-
(*p_ring_buffer)->is_full = false;
448-
(*p_ring_buffer)->is_empty = true;
449-
450-
// Default setup
451-
if ( NULL == p_attr )
445+
// Allocation success
446+
if ( NULL != *p_ring_buffer )
452447
{
453-
status = ring_buffer_default_setup( *p_ring_buffer, size );
454-
}
448+
(*p_ring_buffer)->size_of_buffer = size;
449+
(*p_ring_buffer)->head = 0;
450+
(*p_ring_buffer)->tail = 0;
451+
(*p_ring_buffer)->is_full = false;
452+
(*p_ring_buffer)->is_empty = true;
453+
454+
// Default setup
455+
if ( NULL == p_attr )
456+
{
457+
status = ring_buffer_default_setup( *p_ring_buffer, size );
458+
}
455459

456-
// Customize setup
457-
else
458-
{
459-
status = ring_buffer_custom_setup( *p_ring_buffer, size, p_attr );
460-
}
460+
// Customize setup
461+
else
462+
{
463+
status = ring_buffer_custom_setup( *p_ring_buffer, size, p_attr );
464+
}
461465

462-
// Setup success
463-
if ( eRING_BUFFER_OK == status )
466+
// Setup success
467+
if ( eRING_BUFFER_OK == status )
468+
{
469+
(*p_ring_buffer)->is_init = true;
470+
}
471+
}
472+
else
464473
{
465-
(*p_ring_buffer)->is_init = true;
474+
status = eRING_BUFFER_ERROR_MEM;
466475
}
467476
}
477+
478+
// Already initialised
468479
else
469480
{
470-
status = eRING_BUFFER_ERROR_MEM;
481+
status = eRING_BUFFER_ERROR_INIT;
471482
}
472483
}
473484
else

src/ring_buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*@brief Ring (circular) buffer for general use
88
*@author Ziga Miklosic
99
*@date 03.02.2021
10-
*@version V2.0.1
10+
*@version V2.0.2
1111
*/
1212
////////////////////////////////////////////////////////////////////////////////
1313
/**
@@ -37,7 +37,7 @@
3737
*/
3838
#define RING_BUFFER_VER_MAJOR ( 2 )
3939
#define RING_BUFFER_VER_MINOR ( 0 )
40-
#define RING_BUFFER_VER_DEVELOP ( 1 )
40+
#define RING_BUFFER_VER_DEVELOP ( 2 )
4141

4242
/**
4343
* Status

version.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
============================================================
2+
Version 2.0.2 (23.06.2022)
3+
============================================================
4+
5+
Features/Changes:
6+
- Added protection for multiple init calls
7+
- Added detailed description about module limitations
8+
9+
Todo:
10+
-
11+
12+
============================================================
13+
114
============================================================
215
Version 2.0.1 (25.05.2022)
316
============================================================

0 commit comments

Comments
 (0)