IRPyro messaging application
Communications program between IRPyro and IRPyro evaluation tool
queue.c
Go to the documentation of this file.
1
/**
2
******************************************************************************
3
* @file queue.c
4
* @author _KEMET, Ltd
5
* @date March 2018
6
* @version Release 1.0.6
7
* @copyright (c) 2018 _KEMET, Ltd
8
* @brief IRPyro evaluation tool with API integration.
9
* @verbatim
10
===============================================================================
11
##### Description #####
12
===============================================================================
13
[..]
14
[..]
15
@endverbatim
16
******************************************************************************
17
@attention <h2><center>© COPYRIGHT 2018 _KEMET, Ltd</center></h2>
18
@verbatim
19
Copyright (c) 2018, _KEMET, Ltd
20
All rights reserved.
21
22
THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
23
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
26
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
@endverbatim
33
34
******************************************************************************
35
*/
36
/* Includes ------------------------------------------------------------------*/
37
#include "
queue.h
"
38
/**
39
* @addtogroup Queue_Handler
40
* @{
41
*/
42
/** @defgroup queue Queue
43
* Queue structure definition. Adds and removes elements.
44
* @brief Circular queue functions
45
* @verbatim
46
*
47
* @endverbatim
48
* @note
49
* @{
50
*/
51
/**
52
* @brief Checks is the queue is full
53
* @param q Circular buffer
54
*/
55
int
message_queue_full
(
volatile
struct
Queue
*q)
56
{
57
return
(((q->
pWR
+ 1) %
QUEUE_SIZE
) == q->
pRD
);
58
}
59
/**
60
* @brief Checks if the queue is empty
61
* @param q Circular buffer
62
*/
63
int
message_queue_empty
(
volatile
struct
Queue
*q)
64
{
65
return
(q->
pWR
== q->
pRD
);
66
}
67
/**
68
* @brief Adds a byte to the circular buffer
69
* @param q Circular buffer
70
* @param data Byte to be added to the queue
71
*/
72
int
message_enqueue
(
volatile
struct
Queue
*q, uint8_t data)
73
{
74
if
(
message_queue_full
(q))
75
return
0;
76
else
77
{
78
q->
q
[q->
pWR
] = data;
79
if
((q->
pWR
+ 1) ==
QUEUE_SIZE
)
80
{
81
q->
pWR
= 0;
82
}
83
else
84
{
85
++ q->
pWR
;
86
}
87
}
88
return
1;
89
}
90
/**
91
* @brief Obtains one byte from the circular buffer
92
* @param q Circular buffer
93
* @param data Byte to be removed from the queue
94
*/
95
int
message_dequeue
(
volatile
struct
Queue
*q, uint8_t *data)
96
{
97
if
(
message_queue_empty
(q))
98
return
0;
99
else
100
{
101
*data = q->
q
[q->
pRD
];
102
if
((q->
pRD
+ 1) ==
QUEUE_SIZE
)
103
{
104
q->
pRD
= 0;
105
}
106
else
107
{
108
++ q->
pRD
;
109
}
110
}
111
return
1;
112
}
113
/** end defgroup queue
114
* @}
115
*/
116
/** end of addtogroup Queue_Handler
117
* @}
118
*/
119
/* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
Queue::pWR
uint8_t pWR
Definition:
queue.h:40
message_dequeue
int message_dequeue(volatile struct Queue *q, uint8_t *data)
Obtains one byte from the circular buffer.
Definition:
queue.c:95
QUEUE_SIZE
#define QUEUE_SIZE
Definition:
queue.h:36
Queue
Definition:
queue.h:39
message_queue_empty
int message_queue_empty(volatile struct Queue *q)
Checks if the queue is empty.
Definition:
queue.c:63
Queue::q
uint8_t q[QUEUE_SIZE]
Definition:
queue.h:41
queue.h
Operates a circular queue.
message_enqueue
int message_enqueue(volatile struct Queue *q, uint8_t data)
Adds a byte to the circular buffer.
Definition:
queue.c:72
Queue::pRD
uint8_t pRD
Definition:
queue.h:40
message_queue_full
int message_queue_full(volatile struct Queue *q)
Checks is the queue is full.
Definition:
queue.c:55
source
IRPyro_API_messaging_application
src
queue.c
Generated on Thu Jul 2 2020 16:22:16 for IRPyro messaging application by
1.8.18