Skip to content

Commit

Permalink
v1.4: added q_getRemainingCount inline & added example sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
SMFSW committed May 26, 2018
1 parent a352a77 commit 2ed8f7b
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ WARN_IF_DOC_ERROR = YES
# parameter documentation, but not about the absence of documentation.
# The default value is: NO.

WARN_NO_PARAMDOC = YES
WARN_NO_PARAMDOC = NO

# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
# a warning is encountered.
Expand Down Expand Up @@ -2010,15 +2010,15 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

WARN_NO_PARAMDOC = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
# EXPAND_AS_DEFINED tags.
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_ONLY_PREDEF = NO
EXPAND_ONLY_PREDEF = YES

# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
Expand Down Expand Up @@ -2061,7 +2061,7 @@ PREDEFINED = ARDUINO=10506 \
# definition found in the source code.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_AS_DEFINED =
EXPAND_AS_DEFINED = __attribute__(x)

# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all references to function-like macros that are alone on a line, have
Expand Down
8 changes: 4 additions & 4 deletions Doxyfile.auto
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ WARN_IF_DOC_ERROR = YES
# parameter documentation, but not about the absence of documentation.
# The default value is: NO.

WARN_NO_PARAMDOC = YES
WARN_NO_PARAMDOC = NO

# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
# a warning is encountered.
Expand Down Expand Up @@ -2010,15 +2010,15 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

WARN_NO_PARAMDOC = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
# EXPAND_AS_DEFINED tags.
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_ONLY_PREDEF = NO
EXPAND_ONLY_PREDEF = YES

# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
Expand Down Expand Up @@ -2061,7 +2061,7 @@ PREDEFINED = ARDUINO=10506 \
# definition found in the source code.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_AS_DEFINED =
EXPAND_AS_DEFINED = __attribute__(x)

# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all references to function-like macros that are alone on a line, have
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ Port of Queue has been made to work with STM32 code written in plain c.
- `q_isEmpty(Queue_t * q)`: `true` if full, `false` otherwise
- `q_isFull(Queue_t * q)`: `true` if empty, `false` otherwise
- `q_sizeof(Queue_t * q)`: queue size in bytes (returns 0 in case queue allocation failed)
- `q_getCount(Queue_t * q)` or `q_nbRecs(Queue_t * q)`: number of records in the queue
- `q_getCount(Queue_t * q)` or `q_nbRecs(Queue_t * q)`: number of records stored in the queue
- `q_getRemainingCount(Queue_t * q)`: number of records left in the queue
- `q_clean(Queue_t * q)` or `q_flush(Queue_t * q)`: remove all items in the queue

## Examples included

- [SimpleQueue.ino](examples/SimpleQueue/SimpleQueue.ino): Simple queue example (both LIFO FIFO implementations can be tested)
- [PointersQueue.ino](examples/PointersQueue/PointersQueue.ino): Queue of function pointers performing queued actions
- [RolloverTest.ino](examples/RolloverTest/RolloverTest.ino): Simple test to test queue rollover (for lib testing purposes mainly)
- [LibTst.ino](examples/LibTst/LibTst.ino): flexible test (for lib testing purposes mainly)

Expand Down
5 changes: 4 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ Feel free to share your thoughts @ xgarmanboziax@gmail.com about:

** Actual:

v1.4 3 May 2018:
v1.4 26 May 2018:
- Added q_sizeOf inline to check full queue size in byte (may also be used to check if queue has been allocated properly)
- Added q_getRemainingCount inline returning how much records are left in the queue
- Adding support for unit tests and doxygen documentation generation with Travis CI
- Updated README.md
- Added more example sketches & updated LibTst example using latest inlines additions

v1.3 14 March 2018:
- Init control value set back to 0 when queue is killed (prevents failure if killing twice the same queue)
Expand Down
Binary file removed cQueue_v1_3.pdf
Binary file not shown.
Binary file added cQueue_v1_4.pdf
Binary file not shown.
4 changes: 3 additions & 1 deletion examples/LibTst/LibTst.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This example code is in the public domain.
created 14 July 2017
modified 21 May 2018
modified 26 May 2018
by SMFSW
*/

Expand Down Expand Up @@ -60,6 +60,8 @@ void loop() {
Serial.print(rec.entry2, HEX);
Serial.print(" Count ");
Serial.print(q_getCount(&q));
Serial.print(" Remaining ");
Serial.print(q_getRemainingCount(&q));
Serial.print(" Full? ");
Serial.println(q_isFull(&q));
}
Expand Down
70 changes: 70 additions & 0 deletions examples/PointersQueue/PointersQueue.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Pointers Queue
Pointers queue demonstration
This example code is in the public domain.
created 26 May 2018
by SMFSW
*/

#include <cQueue.h>

typedef void (* f_act)(int *); //!< Function pointer typedef for easier use


Queue_t q; // Queue declaration

void action1(int * v) { *v+=2; Serial.print("Action 1 Called (+2), val="); Serial.println(*v); }
void action2(int * v) { *v*=2; Serial.print("Action 2 Called (*2), val="); Serial.println(*v); }
void action3(int * v) { *v-=1; Serial.print("Action 3 Called (-1), val="); Serial.println(*v); }

int val = 8; // Value passed to function pointer for processing


// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);

q_init(&q, sizeof(f_act), 5, FIFO, false);

for (unsigned int i = 0 ; i < 5 ; i++)
{
f_act Act = 0;

switch (i)
{
case 0:
Act = action1;
break;
case 1:
Act = action2;
break;
case 2:
Act = action3;
break;
case 3:
Act = action2;
break;
case 4:
Act = action1;
break;
}

q_push(&q, &Act);
}
}

// the loop function runs over and over again forever
void loop() {
Serial.print("Value before processing = ");
Serial.println(val);
for (unsigned int i = 0 ; i < 5 ; i++)
{
f_act Act = 0;
q_pop(&q, &Act);
Act(&val);
}

while(1);
}
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ q_isFull KEYWORD2
q_sizeof KEYWORD2
q_getCount KEYWORD2
q_nbRecs KEYWORD2
q_getRemainingCount KEYWORD2
q_push KEYWORD2
q_pop KEYWORD2
q_pull KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version=1.4
author=SMFSW <xgarmanboziax@gmail.com>
maintainer=SMFSW <xgarmanboziax@gmail.com>
sentence=Queue handling library (written in plain c)
paragraph=Queue handling library (written in plain c). May be compiled without change with gcc for other purporses/targets
paragraph=May be compiled without change with gcc for other purporses/targets
category=Data Storage
url=/~https://github.com/SMFSW/cQueue
architectures=*
2 changes: 1 addition & 1 deletion src/cQueue.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file cQueue.c
** \author SMFSW
** \date 2018/05/21
** \date 2018/05/26
** \copyright BSD 3-Clause License (c) 2017-2018, SMFSW
** \brief Queue handling library (designed in c on STM32)
** \details Queue handling library (designed in c on STM32)
Expand Down
11 changes: 9 additions & 2 deletions src/cQueue.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file cQueue.h
** \author SMFSW
** \date 2018/05/21
** \date 2018/05/26
** \copyright BSD 3-Clause License (c) 2017-2018, SMFSW
** \brief Queue handling library (designed in c on STM32)
** \details Queue handling library (designed in c on STM32)
Expand Down Expand Up @@ -111,11 +111,18 @@ inline uint32_t __attribute__((always_inline)) q_sizeof(const Queue_t * q) {

/*! \brief get number of records in the queue
** \param [in] q - pointer of queue to handle
** \return Number of records left in the queue
** \return Number of records stored in the queue
**/
inline uint16_t __attribute__((always_inline)) q_getCount(const Queue_t * q) {
return q->cnt; }

/*! \brief get number of records left in the queue
** \param [in] q - pointer of queue to handle
** \return Number of records left in the queue
**/
inline uint16_t __attribute__((always_inline)) q_getRemainingCount(const Queue_t * q) {
return q->rec_nb - q->cnt; }

/*! \brief Push record to queue
** \warning If using q_push, q_pop, q_peek and/or q_drop in both interrupts and main application,
** you shall disable interrupts in main application when using these functions
Expand Down

0 comments on commit 2ed8f7b

Please sign in to comment.