Skip to content

Commit cb820ab

Browse files
committed
v1.1: controlling queue allocation succesfulness
1 parent 1d947ac commit cb820ab

File tree

7 files changed

+39
-26
lines changed

7 files changed

+39
-26
lines changed

Doxyfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ PROJECT_NAME = cQueue
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 1.0
41+
PROJECT_NUMBER = 1.1
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a
4545
# quick idea about the purpose of the project. Keep the description short.
4646

47-
PROJECT_BRIEF = "Queue handling library"
47+
PROJECT_BRIEF = "Queue handling library (written in plain c)"
4848

4949
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
5050
# in the documentation. The maximum height of the logo should not exceed 55
@@ -1617,7 +1617,7 @@ EXTRA_SEARCH_MAPPINGS =
16171617
# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
16181618
# The default value is: YES.
16191619

1620-
GENERATE_LATEX = NO
1620+
GENERATE_LATEX = YES
16211621

16221622
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
16231623
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
@@ -1727,7 +1727,7 @@ LATEX_EXTRA_FILES =
17271727
# The default value is: YES.
17281728
# This tag requires that the tag GENERATE_LATEX is set to YES.
17291729

1730-
PDF_HYPERLINKS = NO
1730+
PDF_HYPERLINKS = YES
17311731

17321732
# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
17331733
# the PDF file directly from the LaTeX files. Set this option to YES, to get a
@@ -2010,7 +2010,7 @@ ENABLE_PREPROCESSING = YES
20102010
# The default value is: NO.
20112011
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
20122012

2013-
MACRO_EXPANSION = NO
2013+
MACRO_EXPANSION = YES
20142014

20152015
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
20162016
# the macro expansion is limited to the macros specified with the PREDEFINED and
@@ -2051,7 +2051,8 @@ INCLUDE_FILE_PATTERNS = *.h
20512051
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
20522052

20532053
PREDEFINED = ARDUINO=10506 \
2054-
DOXY=1
2054+
DOXY=1 \
2055+
__attribute__(x)=
20552056

20562057
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
20572058
# tag can be used to specify a list of macro names that should be expanded. The

Release Notes.txt renamed to Release Notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ Feel free to share your thoughts @ [email protected] about:
1010

1111
** Actual:
1212

13+
v1.1 16 August 2017:
14+
- Queue init function now returns queue address (enabling check for queue allocation success)
15+
- q_pull & q_flush alias created for earlier versions and purists respectively
16+
1317
v1.0 14 July 2017:
1418
- First release

cQueue_v1_1.pdf

322 KB
Binary file not shown.

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Queue_t KEYWORD1
1313
#######################################
1414
q_init KEYWORD2
1515
q_clean KEYWORD2
16+
q_flush KEYWORD2
1617
q_isEmpty KEYWORD2
1718
q_isFull KEYWORD2
1819
q_nbRecs KEYWORD2

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=cQueue
2-
version=1.0
2+
version=1.1
33
author=SMFSW <[email protected]>
44
maintainer=SMFSW <[email protected]>
55
sentence=Queue handling library (written in plain c)

src/cQueue.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!\file cQueue.c
22
** \author SMFSW
3-
** \version 1.0
4-
** \date 2017/07/14
3+
** \version 1.1
4+
** \date 2017/08/16
55
** \copyright BSD 3-Clause License (c) 2017, SMFSW
66
** \brief Queue handling library (designed in c on STM32)
77
** \details Queue handling library (designed in c on STM32)
@@ -13,6 +13,7 @@
1313

1414
#include "cQueue.h"
1515

16+
#define QUEUE_INITIALIZED 0x5AA5 //!< Queue initialized control value
1617

1718
#define INC_IDX(ctr, end, start) if (ctr < (end-1)) { ctr++; } \
1819
else { ctr = start; } //!< Increments buffer index \b cnt rolling back to \b start when limit \b end is reached
@@ -21,24 +22,25 @@
2122
else { ctr = end-1; } //!< Decrements buffer index \b cnt rolling back to \b end when limit \b start is reached
2223

2324

24-
void q_init(Queue_t * q, uint16_t size_rec, uint16_t nb_recs, QueueType type, bool overwrite)
25+
void * q_init(Queue_t * q, uint16_t size_rec, uint16_t nb_recs, QueueType type, bool overwrite)
2526
{
2627
q->rec_nb = nb_recs;
2728
q->rec_sz = size_rec;
2829
q->impl = type;
2930
q->ovw = overwrite;
3031

31-
if (q->init == 0x5AA5) { q_kill(q); } // Free existing data (if any)
32+
q_kill(q); // Free existing data (if any)
3233
q->queue = (uint8_t *) malloc(nb_recs * size_rec);
33-
34-
q->init = 0x5AA5;
35-
34+
if (q->queue == NULL) { return 0; } // Return here if Queue not allocated
35+
q->init = QUEUE_INITIALIZED;
3636
q_clean(q);
37+
38+
return q->queue; // return NULL when queue not allocated, Queue address otherwise
3739
}
3840

3941
void q_kill(Queue_t * q)
4042
{
41-
free(q->queue);
43+
if (q->init == QUEUE_INITIALIZED) { free(q->queue); } // Free existing data (if already initialized)
4244
}
4345

4446

src/cQueue.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!\file cQueue.h
22
** \author SMFSW
3-
** \version 1.0
4-
** \date 2017/07/14
3+
** \version 1.1
4+
** \date 2017/08/16
55
** \copyright BSD 3-Clause License (c) 2017, SMFSW
66
** \brief Queue handling library (designed in c on STM32)
77
** \details Queue handling library (designed in c on STM32)
@@ -39,24 +39,28 @@ typedef struct Queue_t {
3939
} Queue_t;
4040

4141

42-
/*! \brief Queue constructor
43-
** \param [in] q - pointer of queue to handle
42+
#define q_init_def(q, sz) q_init(q, sz, 20, FIFO, false) //!< Some kind of average default for queue initialization
43+
44+
#define q_pull q_pop //!< As pull was already used in SMFSW libs, alias is made to keep compatibility with earlier versions
45+
#define q_flush q_clean //!< As flush is a common keyword, alias is made to empty queue
46+
47+
/*! \brief Queue initialization
48+
** \param [in,out] q - pointer of queue to handle
4449
** \param [in] size_rec - size of a record in the queue
4550
** \param [in] nb_recs - number of records in the queue
4651
** \param [in] type - Queue implementation type: FIFO, LIFO
4752
** \param [in] overwrite - Overwrite previous records when queue is full
48-
** \return nothing
53+
** \return NULL when allocation not possible, Queue tab address when successful
4954
**/
50-
void q_init(Queue_t * q, uint16_t size_rec, uint16_t nb_recs, QueueType type, bool overwrite);
51-
52-
#define q_init_def(q, sz) q_init(q, sz, 20, FIFO, false)
55+
void * q_init(Queue_t * q, uint16_t size_rec, uint16_t nb_recs, QueueType type, bool overwrite);
5356

5457
/*! \brief Queue desructor: release dynamically allocated queue
55-
** \param [in] q - pointer of queue to handle
58+
** \param [in,out] q - pointer of queue to handle
5659
**/
5760
void q_kill(Queue_t * q);
5861

5962
/*! \brief Clean queue, restarting from empty queue
63+
** \param [in,out] q - pointer of queue to handle
6064
**/
6165
void q_clean(Queue_t * q);
6266

@@ -89,7 +93,7 @@ inline uint16_t __attribute__((always_inline)) q_nbRecs(Queue_t * q) {
8993
}
9094

9195
/*! \brief Push record to queue
92-
** \param [in] q - pointer of queue to handle
96+
** \param [in,out] q - pointer of queue to handle
9397
** \param [in] record - pointer to record to be pushed into queue
9498
** \return Push status
9599
** \retval true if succefully pushed into queue
@@ -116,13 +120,14 @@ bool q_pop(Queue_t * q, void * record);
116120
bool q_peek(Queue_t * q, void * record);
117121

118122
/*! \brief Drop current record from queue
119-
** \param [in] q - pointer of queue to handle
123+
** \param [in,out] q - pointer of queue to handle
120124
** \return drop status
121125
** \retval true if succefully dropped from queue
122126
** \retval false if queue is empty
123127
**/
124128
bool q_drop(Queue_t * q);
125129

130+
126131
#ifdef __cplusplus
127132
}
128133
#endif

0 commit comments

Comments
 (0)