IRPyro messaging application
Communications program between IRPyro and IRPyro evaluation tool
queue_handle.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file queue_handle.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 *
10 * @verbatim
11  ===============================================================================
12  ##### Description #####
13  ===============================================================================
14  [..]
15  [..]
16  @endverbatim
17  ******************************************************************************
18  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
19  @verbatim
20  Copyright (c) 2018, _KEMET, Ltd
21  All rights reserved.
22 
23  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
24  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
27  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  @endverbatim
34 
35  ******************************************************************************
36  */
37 /* Includes ------------------------------------------------------------------*/
38 #include "queue_handle.h"
39 /*=============================BEGIN QUEUE HANDLING===========================*/
40 /* Variables ---------------------------------------------------------*/
41 static volatile struct Queue Uart_Rx_Buffer= {0,0,{0}};
42 static volatile struct Queue Uart_Tx_Buffer= {0,0,{0}};
43 static volatile int TxPrimed = 0;
44 static volatile int RxOverflow = 0;
45 /** @defgroup Queue_Handler Queue Handler
46  * @ingroup eevt_main
47  * @brief Access and handling of circular queues
48  * @verbatim
49  *
50  * @endverbatim
51  * @note
52  * @{
53  */
54 /** @defgroup queue_handle Queue Handle
55  * @brief USART IRQ, Get and Put char into reception and transmission queues
56  * @verbatim
57  *
58  * @endverbatim
59  * @note
60  * @{
61  */
62 /*------------------------- MESSAGE HANDLE INTERFACE ----------------------------*/
63 /* manages the USART (PC communications) input buffer as described above */
64 /**
65 * @brief interrupt handler for USART 2
66 * @verbatim
67 * Uart_Rx_Buffer and Uart_Tx_Buffer are the two queue affected by this function
68 * On a hardware interrupt a byte will be queued into Uart_Rx_Buffer
69 * On a software interrupt a byte will be queued into Uart_Tx_Buffer
70 * @endverbatim
71 */
72 void queue_get_data(void)
73 {
74  uint8_t data;
75  // buffer the data (or toss it if there 's no room
76  // Flow control will prevent this
77  USART_ITConfig(USART2,USART_IT_RXNE,DISABLE) ;
78  data = USART_ReceiveData(USART2) & 0xff;
79  if (!message_enqueue(&Uart_Rx_Buffer, data))
80  {
81  RxOverflow = 1;
82  }
83  USART_ClearFlag(USART2, USART_FLAG_RXNE);
84  USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
85 }
86 void queue_send_data(void)
87 {
88  uint8_t data;
89  /* Write one byte to the transmit data register */
90  if(message_dequeue(&Uart_Tx_Buffer, &data))
91  {
92  USART_SendData(USART2 , data);
93  }
94  else
95  {
96  // if we have nothing to send , disable the interrupt
97  // and wait for a kick
98  USART_ITConfig(USART2 , USART_IT_TXE , DISABLE);
99  TxPrimed = 0;
100  }
101 }
103 {
104  USART_callback send_data_to_gui_fn = queue_send_data;
105  USART_callback get_data_from_gui_fn = queue_get_data;
106  USART_Callback_Tx_Setup( send_data_to_gui_fn);
107  USART_Callback_Rx_Setup( get_data_from_gui_fn);
108 }
109 /**
110 * @brief Gets a character from the receive queue
111 * @param c pointer to a byte
112 * @return 0 no data / 1 data
113 */
114 uint8_t message_getchar(uint8_t *c)
115 {
116  uint8_t op_result=0;
118  return op_result;
119 }
120 /**
121 * @brief sends a character to the transmission queue and enables TX interrupt
122 * @param c byte to the transmission queue
123 * @param go_flag signals transmission can begin
124 */
125 void message_putchar(uint8_t c, uint8_t go_flag)
126 {
127  if (go_flag)
128  {
129  TxPrimed = 1;
130  USART_ITConfig(USART2 , USART_IT_TXE , ENABLE);
131  }
132  else
133  {
135  }
136 }
137 /** end of queue handle
138  * @}
139  */
140 /** end of Queue handler
141  * @}
142  */
143 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
Uart_Tx_Buffer
static volatile struct Queue Uart_Tx_Buffer
Definition: queue_handle.c:42
message_dequeue
int message_dequeue(volatile struct Queue *q, uint8_t *data)
Obtains one byte from the circular buffer.
Definition: queue.c:95
Uart_Rx_Buffer
static volatile struct Queue Uart_Rx_Buffer
Definition: queue_handle.c:41
Queue
Definition: queue.h:39
RxOverflow
static volatile int RxOverflow
Definition: queue_handle.c:44
queue_get_data
void queue_get_data(void)
interrupt handler for USART 2
Definition: queue_handle.c:72
queue_handle_enable
void queue_handle_enable(void)
Definition: queue_handle.c:102
op_result
decode_result_type op_result
Definition: message_unpack.c:153
queue_handle.h
Manages message queues from the GUI to sensor and sensor to GUI.
message_enqueue
int message_enqueue(volatile struct Queue *q, uint8_t data)
Adds a byte to the circular buffer.
Definition: queue.c:72
message_putchar
void message_putchar(uint8_t c, uint8_t go_flag)
sends a character to the transmission queue and enables TX interrupt
Definition: queue_handle.c:125
queue_send_data
void queue_send_data(void)
Definition: queue_handle.c:86
message_getchar
uint8_t message_getchar(uint8_t *c)
Gets a character from the receive queue.
Definition: queue_handle.c:114
TxPrimed
static volatile int TxPrimed
Definition: queue_handle.c:43