1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
|
/**
UART1 Generated Driver API Header File
@Company
Microchip Technology Inc.
@File Name
uart1.h
@Summary
This is the generated header file for the UART1 driver using PIC32MX MCUs
@Description
This header file provides APIs for driver for UART1.
Generation Information :
Product Revision : PIC32MX MCUs - pic32mx : v1.35
Device : PIC32MX470F512H
Driver Version : 0.5
The generated drivers are tested against the following:
Compiler : XC32 1.42
MPLAB : MPLAB X 3.55
*/
/*
(c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
software and any derivatives exclusively with Microchip products.
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
TERMS.
*/
#ifndef _UART1_H
#define _UART1_H
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: Included Files
*/
#include <xc.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/attribs.h>
/**
Section: Data Types
*/
/** UART1 Driver Hardware Flags
@Summary
Specifies the status of the hardware receive or transmit
@Description
This type specifies the status of the hardware receive or transmit.
More than one of these values may be OR'd together to create a complete
status value. To test a value of this type, the bit of interest must be
AND'ed with value and checked to see if the result is non-zero.
*/
typedef enum
{
/* Indicates that Receive buffer has data, at least one more character can be read */
UART1_RX_DATA_AVAILABLE
/*DOM-IGNORE-BEGIN*/ = (1 << 0) /*DOM-IGNORE-END*/,
/* Indicates that Receive buffer has overflowed */
UART1_RX_OVERRUN_ERROR
/*DOM-IGNORE-BEGIN*/ = (1 << 1) /*DOM-IGNORE-END*/,
/* Indicates that Framing error has been detected for the current character */
UART1_FRAMING_ERROR
/*DOM-IGNORE-BEGIN*/ = (1 << 2) /*DOM-IGNORE-END*/,
/* Indicates that Parity error has been detected for the current character */
UART1_PARITY_ERROR
/*DOM-IGNORE-BEGIN*/ = (1 << 3) /*DOM-IGNORE-END*/,
/* Indicates that Receiver is Idle */
UART1_RECEIVER_IDLE
/*DOM-IGNORE-BEGIN*/ = (1 << 4) /*DOM-IGNORE-END*/,
/* Indicates that the last transmission has completed */
UART1_TX_COMPLETE
/*DOM-IGNORE-BEGIN*/ = (1 << 8) /*DOM-IGNORE-END*/,
/* Indicates that Transmit buffer is full */
UART1_TX_FULL
/*DOM-IGNORE-BEGIN*/ = (1 << 9) /*DOM-IGNORE-END*/
}UART1_STATUS;
/** UART1 Driver Transfer Flags
@Summary
Specifies the status of the receive or transmit
@Description
This type specifies the status of the receive or transmit operation.
More than one of these values may be OR'd together to create a complete
status value. To test a value of this type, the bit of interest must be
AND'ed with value and checked to see if the result is non-zero.
*/
typedef enum
{
/* Indicates that the core driver buffer is full */
UART1_TRANSFER_STATUS_RX_FULL
/*DOM-IGNORE-BEGIN*/ = (1 << 0) /*DOM-IGNORE-END*/,
/* Indicates that at least one byte of Data has been received */
UART1_TRANSFER_STATUS_RX_DATA_PRESENT
/*DOM-IGNORE-BEGIN*/ = (1 << 1) /*DOM-IGNORE-END*/,
/* Indicates that the core driver receiver buffer is empty */
UART1_TRANSFER_STATUS_RX_EMPTY
/*DOM-IGNORE-BEGIN*/ = (1 << 2) /*DOM-IGNORE-END*/,
/* Indicates that the core driver transmitter buffer is full */
UART1_TRANSFER_STATUS_TX_FULL
/*DOM-IGNORE-BEGIN*/ = (1 << 3) /*DOM-IGNORE-END*/,
/* Indicates that the core driver transmitter buffer is empty */
UART1_TRANSFER_STATUS_TX_EMPTY
/*DOM-IGNORE-BEGIN*/ = (1 << 4) /*DOM-IGNORE-END*/
} UART1_TRANSFER_STATUS;
/**
Section: UART1 Driver Routines
*/
void _UART_1(void);
/**
@Summary
Initializes the UART instance : 1
@Description
This routine initializes the UART driver instance for : 1
index.0x8008
This routine must be called before any other UART routine is called.
@Preconditions
None.
@Returns
None.
@Param
None.
@Comment
@Example
<code>
const uint8_t writeBuffer[35] = "1234567890ABCDEFGHIJKLMNOP\n" ;
unsigned int numBytes = 0;
int writebufferLen = strlen((char *)writeBuffer);
UART1_Initialize();
while(numBytes < writebufferLen)
{
int bytesToWrite = UART1_TransmitBufferSizeGet();
numBytes = UART1_WriteBuffer ( writeBuffer+numBytes, bytesToWrite) ;
UART1_TasksTransmit ( );
if (!UART1_TransmitBufferisFull())
{
//continue other operation
}
}
</code>
*/
void UART1_Initialize(void);
/**
@Summary
Read a byte of data from the UART1
@Description
This routine reads a byte of data from the UART1.
@Preconditions
UART1_Initializer function should have been called
before calling this function. The transfer status should be checked to see
if the receiver is not empty before calling this function.
@Param
None.
@Returns
A data byte received by the driver.
@Example
<code>
char myBuffer[MY_BUFFER_SIZE];
unsigned int numBytes;
numBytes = 0;
do
{
if( UART1_TRANSFER_STATUS_RX_DATA_PRESENT & UART1_TransferStatusGet() )
{
myBuffer[numBytes++] = UART1_Read();
}
// Do something else...
} while( numBytes < MY_BUFFER_SIZE);
</code>
*/
uint8_t UART1_Read( void);
/**
@Summary
Returns the number of bytes read by the UART1 peripheral
@Description
This routine returns the number of bytes read by the Peripheral and fills the
application read buffer with the read data.
@Preconditions
UART1_Initializer function should have been called
before calling this function
@Param
buffer - Buffer into which the data read from the UART1
@Param
numbytes - Total number of bytes that need to be read from the UART1
(must be equal to or less than the size of the buffer)
@Returns
Number of bytes actually copied into the caller's buffer or -1 if there
is an error.
@Example
<code>
char myBuffer[MY_BUFFER_SIZE];
unsigned int numBytes;
UART1_TRANSFER_STATUS status ;
// Pre-initialize myBuffer with MY_BUFFER_SIZE bytes of valid data.
numBytes = 0;
while( numBytes < MY_BUFFER_SIZE);
{
status = UART1_TransferStatusGet ( ) ;
if (status & UART1_TRANSFER_STATUS_RX_FULL)
{
numBytes += UART1_ReadBuffer( myBuffer + numBytes, MY_BUFFER_SIZE - numBytes ) ;
if(numBytes < readbufferLen)
{
continue;
}
else
{
break;
}
}
else
{
continue;
}
// Do something else...
}
</code>
*/
unsigned int UART1_ReadBuffer( uint8_t *buffer , const unsigned int numbytes);
/**
@Summary
Writes a byte of data to the UART1
@Description
This routine writes a byte of data to the UART1.
@Preconditions
UART1_Initializer function should have been called
before calling this function. The transfer status should be checked to see if
transmitter is not full before calling this function.
@Param
byte - Data byte to write to the UART1
@Returns
None.
@Example
<code>
char myBuffer[MY_BUFFER_SIZE];
unsigned int numBytes;
// Pre-initialize myBuffer with MY_BUFFER_SIZE bytes of valid data.
numBytes = 0;
while( numBytes < MY_BUFFER_SIZE);
{
if( !(UART1_TRANSFER_STATUS_TX_FULL & UART1_TransferStatusGet()) )
{
UART1_Write(handle, myBuffer[numBytes++]);
}
// Do something else...
}
</code>
*/
void UART1_Write( const uint8_t byte);
/**
@Summary
Returns the number of bytes written into the internal buffer
@Description
This API transfers the data from application buffer to internal buffer and
returns the number of bytes added in that queue
@Preconditions
UART1_Initializer function should have been called
before calling this function
@Example
<code>
char myBuffer[MY_BUFFER_SIZE];
unsigned int numBytes;
UART1_TRANSFER_STATUS status ;
// Pre-initialize myBuffer with MY_BUFFER_SIZE bytes of valid data.
numBytes = 0;
while( numBytes < MY_BUFFER_SIZE);
{
status = UART1_TransferStatusGet ( ) ;
if (status & UART1_TRANSFER_STATUS_TX_EMPTY)
{
numBytes += UART1_WriteBuffer ( myBuffer + numBytes, MY_BUFFER_SIZE - numBytes ) ;
if(numBytes < writebufferLen)
{
continue;
}
else
{
break;
}
}
else
{
continue;
}
// Do something else...
}
</code>
*/
unsigned int UART1_WriteBuffer( const uint8_t *buffer , const unsigned int numbytes );
/**
@Summary
Returns the transmitter and receiver transfer status
@Description
This returns the transmitter and receiver transfer status.The returned status
may contain a value with more than one of the bits
specified in the UART1_TRANSFER_STATUS enumeration set.
The caller should perform an "AND" with the bit of interest and verify if the
result is non-zero (as shown in the example) to verify the desired status
bit.
@Preconditions
UART1_Initializer function should have been called
before calling this function
@Param
None.
@Returns
A UART1_TRANSFER_STATUS value describing the current status
of the transfer.
@Example
Refer to UART1_ReadBuffer and UART1_WriteBuffer for example
*/
UART1_TRANSFER_STATUS UART1_TransferStatusGet (void );
/**
@Summary
Returns the character in the read sequence at the offset provided, without
extracting it
@Description
This routine returns the character in the read sequence at the offset provided,
without extracting it
@Param
None.
@Example
<code>
const uint8_t readBuffer[5];
unsigned int data, numBytes = 0;
unsigned int readbufferLen = sizeof(readBuffer);
UART1_Initializer();
while(numBytes < readbufferLen)
{
UART1_TasksReceive ( );
//Check for data at a particular place in the buffer
data = UART1_Peek(3);
if(data == 5)
{
//discard all other data if byte that is wanted is received.
//continue other operation
numBytes += UART1_ReadBuffer ( readBuffer + numBytes , readbufferLen ) ;
}
else
{
break;
}
}
</code>
*/
uint8_t UART1_Peek(uint16_t offset);
/**
@Summary
Returns the size of the receive buffer
@Description
This routine returns the size of the receive buffer.
@Param
None.
@Returns
Size of receive buffer.
@Example
<code>
const uint8_t readBuffer[5];
unsigned int size, numBytes = 0;
unsigned int readbufferLen = sizeof(readBuffer);
UART1__Initializer();
while(size < readbufferLen)
{
UART1_TasksReceive ( );
size = UART1_ReceiveBufferSizeGet();
}
numBytes = UART1_ReadBuffer ( readBuffer , readbufferLen ) ;
</code>
*/
unsigned int UART1_ReceiveBufferSizeGet(void);
/**
@Summary
Returns the size of the transmit buffer
@Description
This routine returns the size of the transmit buffer.
@Param
None.
@Returns
Size of transmit buffer.
@Example
Refer to UART1_Initializer(); for example.
*/
unsigned int UART1_TransmitBufferSizeGet(void);
/**
@Summary
Returns the status of the receive buffer
@Description
This routine returns if the receive buffer is empty or not.
@Param
None.
@Returns
True if the receive buffer is empty
False if the receive buffer is not empty
@Example
<code>
char myBuffer[MY_BUFFER_SIZE];
unsigned int numBytes;
UART1_TRANSFER_STATUS status ;
// Pre-initialize myBuffer with MY_BUFFER_SIZE bytes of valid data.
numBytes = 0;
while( numBytes < MY_BUFFER_SIZE);
{
status = UART1_TransferStatusGet ( ) ;
if (!UART1_ReceiveBufferIsEmpty())
{
numBytes += UART1_ReadBuffer( myBuffer + numBytes, MY_BUFFER_SIZE - numBytes ) ;
if(numBytes < readbufferLen)
{
continue;
}
else
{
break;
}
}
else
{
continue;
}
// Do something else...
}
</code>
*/
bool UART1_ReceiveBufferIsEmpty (void);
/**
@Summary
Returns the status of the transmit buffer
@Description
This routine returns if the transmit buffer is full or not.
@Param
None.
@Returns
True if the transmit buffer is full
False if the transmit buffer is not full
@Example
Refer to UART1_Initializer() for example.
*/
bool UART1_TransmitBufferIsFull (void);
/**
@Summary
Returns the transmitter and receiver status
@Description
This returns the transmitter and receiver status. The returned status may
contain a value with more than one of the bits
specified in the UART1_STATUS enumeration set.
The caller should perform an "AND" with the bit of interest and verify if the
result is non-zero (as shown in the example) to verify the desired status
bit.
@Preconditions
UART1_Initializer function should have been called
before calling this function
@Param
None.
@Returns
A UART1_STATUS value describing the current status
of the transfer.
@Example
<code>
while(!(UART1_StatusGet & UART1_TX_COMPLETE ))
{
// Wait for the tranmission to complete
}
</code>
*/
UART1_STATUS UART1_StatusGet (void );
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif // _UART1_H
/*
End of File
*/
|