1 |
/** |
---|
2 |
EUSART Generated Driver API Header File |
---|
3 |
|
---|
4 |
@Company |
---|
5 |
Microchip Technology Inc. |
---|
6 |
|
---|
7 |
@File Name |
---|
8 |
eusart.h |
---|
9 |
|
---|
10 |
@Summary |
---|
11 |
This is the generated header file for the EUSART driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs |
---|
12 |
|
---|
13 |
@Description |
---|
14 |
This header file provides APIs for driver for EUSART. |
---|
15 |
Generation Information : |
---|
16 |
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2 |
---|
17 |
Device : PIC16F1579 |
---|
18 |
Driver Version : 2.01 |
---|
19 |
The generated drivers are tested against the following: |
---|
20 |
Compiler : XC8 1.45 |
---|
21 |
MPLAB : MPLAB X 4.15 |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
/* |
---|
25 |
(c) 2018 Microchip Technology Inc. and its subsidiaries. |
---|
26 |
|
---|
27 |
Subject to your compliance with these terms, you may use Microchip software and any |
---|
28 |
derivatives exclusively with Microchip products. It is your responsibility to comply with third party |
---|
29 |
license terms applicable to your use of third party software (including open source software) that |
---|
30 |
may accompany Microchip software. |
---|
31 |
|
---|
32 |
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER |
---|
33 |
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY |
---|
34 |
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS |
---|
35 |
FOR A PARTICULAR PURPOSE. |
---|
36 |
|
---|
37 |
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, |
---|
38 |
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND |
---|
39 |
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP |
---|
40 |
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO |
---|
41 |
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL |
---|
42 |
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT |
---|
43 |
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS |
---|
44 |
SOFTWARE. |
---|
45 |
*/ |
---|
46 |
|
---|
47 |
#ifndef EUSART_H |
---|
48 |
#define EUSART_H |
---|
49 |
|
---|
50 |
/** |
---|
51 |
Section: Included Files |
---|
52 |
*/ |
---|
53 |
|
---|
54 |
#include <xc.h> |
---|
55 |
#include <stdbool.h> |
---|
56 |
#include <stdint.h> |
---|
57 |
|
---|
58 |
#ifdef __cplusplus // Provide C++ Compatibility |
---|
59 |
|
---|
60 |
extern "C" { |
---|
61 |
|
---|
62 |
#endif |
---|
63 |
|
---|
64 |
|
---|
65 |
/** |
---|
66 |
Section: Macro Declarations |
---|
67 |
*/ |
---|
68 |
|
---|
69 |
#define EUSART_DataReady (EUSART_is_rx_ready()) |
---|
70 |
|
---|
71 |
/** |
---|
72 |
Section: Data Type Definitions |
---|
73 |
*/ |
---|
74 |
|
---|
75 |
/** |
---|
76 |
Section: Global variables |
---|
77 |
*/ |
---|
78 |
extern volatile uint8_t eusartTxBufferRemaining; |
---|
79 |
extern volatile uint8_t eusartRxCount; |
---|
80 |
|
---|
81 |
/** |
---|
82 |
Section: EUSART APIs |
---|
83 |
*/ |
---|
84 |
|
---|
85 |
void (*EUSART_TxDefaultInterruptHandler)(void); |
---|
86 |
void (*EUSART_RxDefaultInterruptHandler)(void); |
---|
87 |
|
---|
88 |
/** |
---|
89 |
@Summary |
---|
90 |
Initialization routine that takes inputs from the EUSART GUI. |
---|
91 |
|
---|
92 |
@Description |
---|
93 |
This routine initializes the EUSART driver. |
---|
94 |
This routine must be called before any other EUSART routine is called. |
---|
95 |
|
---|
96 |
@Preconditions |
---|
97 |
None |
---|
98 |
|
---|
99 |
@Param |
---|
100 |
None |
---|
101 |
|
---|
102 |
@Returns |
---|
103 |
None |
---|
104 |
|
---|
105 |
@Comment |
---|
106 |
|
---|
107 |
*/ |
---|
108 |
void EUSART_Initialize(void); |
---|
109 |
|
---|
110 |
/** |
---|
111 |
@Summary |
---|
112 |
Checks if the EUSART transmitter is ready |
---|
113 |
|
---|
114 |
@Description |
---|
115 |
This routine checks if EUSART transmitter is empty and ready |
---|
116 |
for next transmission |
---|
117 |
|
---|
118 |
@Preconditions |
---|
119 |
EUSART_Initialize() function should have been called |
---|
120 |
before calling this function. |
---|
121 |
EUSART transmitter should be enabled before calling |
---|
122 |
this function |
---|
123 |
|
---|
124 |
@Param |
---|
125 |
None |
---|
126 |
|
---|
127 |
@Returns |
---|
128 |
The number of available bytes that EUSART has remaining in |
---|
129 |
its transmit buffer |
---|
130 |
|
---|
131 |
@Example |
---|
132 |
<code> |
---|
133 |
void main(void) |
---|
134 |
{ |
---|
135 |
volatile uint8_t rxData; |
---|
136 |
|
---|
137 |
// Initialize the device |
---|
138 |
SYSTEM_Initialize(); |
---|
139 |
|
---|
140 |
// Enable the Global Interrupts |
---|
141 |
INTERRUPT_GlobalInterruptEnable(); |
---|
142 |
|
---|
143 |
// Enable the Peripheral Interrupts |
---|
144 |
INTERRUPT_PeripheralInterruptEnable(); |
---|
145 |
|
---|
146 |
while(1) |
---|
147 |
{ |
---|
148 |
// Logic to echo received data |
---|
149 |
if(EUSART_is_rx_ready()) |
---|
150 |
{ |
---|
151 |
rxData = UART1_Read(); |
---|
152 |
if(EUSART_is_tx_ready()) |
---|
153 |
{ |
---|
154 |
EUSART_Write(rxData); |
---|
155 |
} |
---|
156 |
} |
---|
157 |
} |
---|
158 |
} |
---|
159 |
</code> |
---|
160 |
*/ |
---|
161 |
uint8_t EUSART_is_tx_ready(void); |
---|
162 |
|
---|
163 |
/** |
---|
164 |
@Summary |
---|
165 |
Checks if EUSART receiver is empty |
---|
166 |
|
---|
167 |
@Description |
---|
168 |
This routine returns the available number of bytes to be read |
---|
169 |
from EUSART receiver |
---|
170 |
|
---|
171 |
@Preconditions |
---|
172 |
EUSART_Initialize() function should be called |
---|
173 |
before calling this function |
---|
174 |
EUSART receiver should be enabled before calling this |
---|
175 |
function |
---|
176 |
|
---|
177 |
@Param |
---|
178 |
None |
---|
179 |
|
---|
180 |
@Returns |
---|
181 |
The number of bytes EUSART has available for reading |
---|
182 |
|
---|
183 |
@Example |
---|
184 |
<code> |
---|
185 |
void main(void) |
---|
186 |
{ |
---|
187 |
volatile uint8_t rxData; |
---|
188 |
|
---|
189 |
// Initialize the device |
---|
190 |
SYSTEM_Initialize(); |
---|
191 |
|
---|
192 |
// Enable the Global Interrupts |
---|
193 |
INTERRUPT_GlobalInterruptEnable(); |
---|
194 |
|
---|
195 |
// Enable the Peripheral Interrupts |
---|
196 |
INTERRUPT_PeripheralInterruptEnable(); |
---|
197 |
|
---|
198 |
while(1) |
---|
199 |
{ |
---|
200 |
// Logic to echo received data |
---|
201 |
if(EUSART_is_rx_ready()) |
---|
202 |
{ |
---|
203 |
rxData = UART1_Read(); |
---|
204 |
if(EUSART_is_tx_ready()) |
---|
205 |
{ |
---|
206 |
EUSARTT_Write(rxData); |
---|
207 |
} |
---|
208 |
} |
---|
209 |
} |
---|
210 |
} |
---|
211 |
</code> |
---|
212 |
*/ |
---|
213 |
uint8_t EUSART_is_rx_ready(void); |
---|
214 |
|
---|
215 |
/** |
---|
216 |
@Summary |
---|
217 |
Checks if EUSART data is transmitted |
---|
218 |
|
---|
219 |
@Description |
---|
220 |
This function return the status of transmit shift register |
---|
221 |
|
---|
222 |
@Preconditions |
---|
223 |
EUSART_Initialize() function should be called |
---|
224 |
before calling this function |
---|
225 |
EUSART transmitter should be enabled and EUSART_Write |
---|
226 |
should be called before calling this function |
---|
227 |
|
---|
228 |
@Param |
---|
229 |
None |
---|
230 |
|
---|
231 |
@Returns |
---|
232 |
Status of EUSART receiver |
---|
233 |
TRUE: Data completely shifted out if the USART shift register |
---|
234 |
FALSE: Data is not completely shifted out of the shift register |
---|
235 |
|
---|
236 |
@Example |
---|
237 |
<code> |
---|
238 |
void main(void) |
---|
239 |
{ |
---|
240 |
volatile uint8_t rxData; |
---|
241 |
|
---|
242 |
// Initialize the device |
---|
243 |
SYSTEM_Initialize(); |
---|
244 |
|
---|
245 |
while(1) |
---|
246 |
{ |
---|
247 |
if(EUSART_is_tx_ready()) |
---|
248 |
{ |
---|
249 |
LED_0_SetHigh(); |
---|
250 |
EUSARTWrite(rxData); |
---|
251 |
} |
---|
252 |
if(EUSART_is_tx_done() |
---|
253 |
{ |
---|
254 |
LED_0_SetLow(); |
---|
255 |
} |
---|
256 |
} |
---|
257 |
} |
---|
258 |
</code> |
---|
259 |
*/ |
---|
260 |
bool EUSART_is_tx_done(void); |
---|
261 |
|
---|
262 |
/** |
---|
263 |
@Summary |
---|
264 |
Read a byte of data from the EUSART. |
---|
265 |
|
---|
266 |
@Description |
---|
267 |
This routine reads a byte of data from the EUSART. |
---|
268 |
|
---|
269 |
@Preconditions |
---|
270 |
EUSART_Initialize() function should have been called |
---|
271 |
before calling this function. The transfer status should be checked to see |
---|
272 |
if the receiver is not empty before calling this function. |
---|
273 |
|
---|
274 |
@Param |
---|
275 |
None |
---|
276 |
|
---|
277 |
@Returns |
---|
278 |
A data byte received by the driver. |
---|
279 |
*/ |
---|
280 |
uint8_t EUSART_Read(void); |
---|
281 |
|
---|
282 |
/** |
---|
283 |
@Summary |
---|
284 |
Writes a byte of data to the EUSART. |
---|
285 |
|
---|
286 |
@Description |
---|
287 |
This routine writes a byte of data to the EUSART. |
---|
288 |
|
---|
289 |
@Preconditions |
---|
290 |
EUSART_Initialize() function should have been called |
---|
291 |
before calling this function. The transfer status should be checked to see |
---|
292 |
if transmitter is not busy before calling this function. |
---|
293 |
|
---|
294 |
@Param |
---|
295 |
txData - Data byte to write to the EUSART |
---|
296 |
|
---|
297 |
@Returns |
---|
298 |
None |
---|
299 |
*/ |
---|
300 |
void EUSART_Write(uint8_t txData); |
---|
301 |
|
---|
302 |
/** |
---|
303 |
@Summary |
---|
304 |
Maintains the driver's transmitter state machine and implements its ISR. |
---|
305 |
|
---|
306 |
@Description |
---|
307 |
This routine is used to maintain the driver's internal transmitter state |
---|
308 |
machine.This interrupt service routine is called when the state of the |
---|
309 |
transmitter needs to be maintained in a non polled manner. |
---|
310 |
|
---|
311 |
@Preconditions |
---|
312 |
EUSART_Initialize() function should have been called |
---|
313 |
for the ISR to execute correctly. |
---|
314 |
|
---|
315 |
@Param |
---|
316 |
None |
---|
317 |
|
---|
318 |
@Returns |
---|
319 |
None |
---|
320 |
*/ |
---|
321 |
void EUSART_Transmit_ISR(void); |
---|
322 |
|
---|
323 |
/** |
---|
324 |
@Summary |
---|
325 |
Maintains the driver's receiver state machine and implements its ISR |
---|
326 |
|
---|
327 |
@Description |
---|
328 |
This routine is used to maintain the driver's internal receiver state |
---|
329 |
machine.This interrupt service routine is called when the state of the |
---|
330 |
receiver needs to be maintained in a non polled manner. |
---|
331 |
|
---|
332 |
@Preconditions |
---|
333 |
EUSART_Initialize() function should have been called |
---|
334 |
for the ISR to execute correctly. |
---|
335 |
|
---|
336 |
@Param |
---|
337 |
None |
---|
338 |
|
---|
339 |
@Returns |
---|
340 |
None |
---|
341 |
*/ |
---|
342 |
void EUSART_Receive_ISR(void); |
---|
343 |
|
---|
344 |
/** |
---|
345 |
@Summary |
---|
346 |
Sets the transmit handler function to be called by the interrupt service |
---|
347 |
|
---|
348 |
@Description |
---|
349 |
Calling this function will set a new custom function that will be |
---|
350 |
called when the transmit interrupt needs servicing. |
---|
351 |
|
---|
352 |
@Preconditions |
---|
353 |
EUSART_Initialize() function should have been called |
---|
354 |
for the ISR to execute correctly. |
---|
355 |
|
---|
356 |
@Param |
---|
357 |
A pointer to the new function |
---|
358 |
|
---|
359 |
@Returns |
---|
360 |
None |
---|
361 |
*/ |
---|
362 |
void EUSART_SetTxInterruptHandler(void (* interruptHandler)(void)); |
---|
363 |
|
---|
364 |
/** |
---|
365 |
@Summary |
---|
366 |
Sets the receive handler function to be called by the interrupt service |
---|
367 |
|
---|
368 |
@Description |
---|
369 |
Calling this function will set a new custom function that will be |
---|
370 |
called when the receive interrupt needs servicing. |
---|
371 |
|
---|
372 |
@Preconditions |
---|
373 |
EUSART_Initialize() function should have been called |
---|
374 |
for the ISR to execute correctly. |
---|
375 |
|
---|
376 |
@Param |
---|
377 |
A pointer to the new function |
---|
378 |
|
---|
379 |
@Returns |
---|
380 |
None |
---|
381 |
*/ |
---|
382 |
void EUSART_SetRxInterruptHandler(void (* interruptHandler)(void)); |
---|
383 |
|
---|
384 |
#ifdef __cplusplus // Provide C++ Compatibility |
---|
385 |
|
---|
386 |
} |
---|
387 |
|
---|
388 |
#endif |
---|
389 |
|
---|
390 |
#endif // EUSART_H |
---|
391 |
/** |
---|
392 |
End of File |
---|
393 |
*/ |
---|