00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "pic24_all.h"
00034
00035
00036 #if (NUM_UART_MODS >= 1)
00037
00038
00039
00040
00041
00042
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00071 void checkRxErrorUART1(void) {
00072 uint8 u8_c;
00073
00074 if (U1STAbits.PERR) {
00075 u8_c = U1RXREG;
00076 reportError("UART1 parity error\n");
00077 }
00078 if (U1STAbits.FERR) {
00079 u8_c = U1RXREG;
00080 reportError("UART1 framing error\n");
00081 }
00082 if (U1STAbits.OERR) {
00083 U1STAbits.OERR = 0;
00084 reportError("UART1 overrun error\n");
00085 }
00086 }
00087
00088
00089
00090
00091 #ifdef UART1_TX_INTERRUPT
00092
00095 #ifndef UART1_TX_FIFO_SIZE
00096 #define UART1_TX_FIFO_SIZE 32 //choose a size
00097 #endif
00098
00099 #ifndef UART1_TX_INTERRUPT_PRIORITY
00100 #define UART1_TX_INTERRUPT_PRIORITY 1
00101 #endif
00102
00103 volatile uint8 au8_txFifo1[UART1_TX_FIFO_SIZE];
00104 volatile uint16 u16_txFifo1Head = 0;
00105 volatile uint16 u16_txFifo1Tail = 0;
00106
00111 void outChar1(uint8 u8_c) {
00112 uint16 u16_tmp;
00113
00114 u16_tmp = u16_txFifo1Head;
00115 u16_tmp++;
00116 if (u16_tmp == UART1_TX_FIFO_SIZE) u16_tmp = 0;
00117 while (u16_tmp == u16_txFifo1Tail)
00118 doHeartbeat();
00119
00120 au8_txFifo1[u16_tmp] = u8_c;
00121 u16_txFifo1Head = u16_tmp;
00122 _U1TXIE = 1;
00123 }
00124
00125 void _ISR _U1TXInterrupt (void) {
00126 if (u16_txFifo1Head == u16_txFifo1Tail) {
00127
00128 _U1TXIE = 0;
00129 } else {
00130
00131 u16_txFifo1Tail++;
00132 if (u16_txFifo1Tail == UART1_TX_FIFO_SIZE)
00133 u16_txFifo1Tail = 0;
00134 _U1TXIF = 0;
00135
00136 U1TXREG = au8_txFifo1[u16_txFifo1Tail];
00137 }
00138 }
00139
00140
00141 #else
00142
00146 void outChar1(uint8 u8_c) {
00147
00148 while (IS_TRANSMIT_BUFFER_FULL_UART1())
00149 doHeartbeat();
00150 U1TXREG = u8_c;
00151 }
00152 #endif
00153
00154 #ifdef UART1_RX_INTERRUPT
00155
00156 #ifndef UART1_RX_FIFO_SIZE
00157 #define UART1_RX_FIFO_SIZE 32 //choose a size
00158 #endif
00159
00160 #ifndef UART1_RX_INTERRUPT_PRIORITY
00161 #define UART1_RX_INTERRUPT_PRIORITY 1
00162 #endif
00163
00164 volatile uint8 au8_rxFifo1[UART1_RX_FIFO_SIZE];
00165 volatile uint16 u16_rxFifo1Head = 0;
00166 volatile uint16 u16_rxFifo1Tail = 0;
00167
00171 uint8 isCharReady1(void) {
00172 return(u16_rxFifo1Head != u16_rxFifo1Tail);
00173 }
00174
00179 uint8 inChar1(void) {
00180 while (u16_rxFifo1Head == u16_rxFifo1Tail)
00181 doHeartbeat();
00182 u16_rxFifo1Tail++;
00183 if (u16_rxFifo1Tail == UART1_RX_FIFO_SIZE) u16_rxFifo1Tail=0;
00184 return au8_rxFifo1[u16_rxFifo1Tail];
00185 }
00186
00187 void _ISR _U1RXInterrupt (void) {
00188 int8 u8_c;
00189
00190 _U1RXIF = 0;
00191 checkRxErrorUART1();
00192 u8_c = U1RXREG;
00193 u16_rxFifo1Head++;
00194 if (u16_rxFifo1Head == UART1_RX_FIFO_SIZE)
00195 u16_rxFifo1Head = 0;
00196 if (u16_rxFifo1Head == u16_rxFifo1Tail) {
00197
00198 reportError("UART1 RX Interrupt FIFO overrun!");
00199 }
00200 au8_rxFifo1[u16_rxFifo1Head] = u8_c;
00201 }
00202
00203 #else
00204
00207 uint8 isCharReady1(void) {
00208 return(IS_CHAR_READY_UART1());
00209 }
00210
00215 uint8 inChar1(void) {
00216
00217
00218
00219 while (!IS_CHAR_READY_UART1())
00220 doHeartbeat();
00221 checkRxErrorUART1();
00222 return U1RXREG;
00223 }
00224 #endif
00225
00226
00235 void configUART1(uint32 u32_baudRate) {
00236
00237
00238
00239
00240 #if defined(EXPLORER16_100P)
00241
00242 #elif (1 == 1) //change pin mappings for your device
00243 CONFIG_RP10_AS_DIG_PIN();
00244 CONFIG_U1RX_TO_RP(10);
00245 CONFIG_RP11_AS_DIG_PIN();
00246 CONFIG_U1TX_TO_RP(11);
00247 #else
00248 #warning UART1 pin mappings not defined!!! For simplicity,
00249 #warning pin mappings are identical for UARTS 1-4. If your device has more than
00250 #warning one UART, ****** CHANGE THE MAPPING ****** since
00251 #warning multiple UARTs can not share the same pins.
00252 #warning In particular:
00253 #warning 1. Change the statement #if (1 == 1) to #if 1
00254 #warning 2. Change the pin numbers in the next four lines
00255 #warning to something valid for your device.
00256 #warning If your device does not have remappable I/O,
00257 #warning (typical for >44 pin packages), skip this step --
00258 #warning the UART I/O pins are already assigned to something
00259 #warning valid.
00260 #endif
00261
00262 CONFIG_BAUDRATE_UART1(u32_baudRate);
00263 CONFIG_PDSEL_UART1(UXMODE_PDSEL_8DATA_NOPARITY);
00264 CONFIG_STOPBITS_UART1(1);
00265 #ifdef UART1_RX_INTERRUPT
00266 _U1RXIF = 0;
00267 _U1RXIP = UART1_RX_INTERRUPT_PRIORITY;
00268 _U1RXIE = 1;
00269 #endif
00270 #ifdef UART1_TX_INTERRUPT
00271
00272 _U1RXIP = UART1_TX_INTERRUPT_PRIORITY;
00273
00274 #endif
00275 ENABLE_UART1();
00276 }
00277
00278 #endif // #if (NUM_UARTS >= 1)
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 #include "pic24_all.h"
00316
00317
00318 #if (NUM_UART_MODS >= 2)
00319
00320
00321
00322
00323
00324
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00353 void checkRxErrorUART2(void) {
00354 uint8 u8_c;
00355
00356 if (U2STAbits.PERR) {
00357 u8_c = U2RXREG;
00358 reportError("UART2 parity error\n");
00359 }
00360 if (U2STAbits.FERR) {
00361 u8_c = U2RXREG;
00362 reportError("UART2 framing error\n");
00363 }
00364 if (U2STAbits.OERR) {
00365 U2STAbits.OERR = 0;
00366 reportError("UART2 overrun error\n");
00367 }
00368 }
00369
00370
00371
00372
00373 #ifdef UART2_TX_INTERRUPT
00374
00377 #ifndef UART2_TX_FIFO_SIZE
00378 #define UART2_TX_FIFO_SIZE 32 //choose a size
00379 #endif
00380
00381 #ifndef UART2_TX_INTERRUPT_PRIORITY
00382 #define UART2_TX_INTERRUPT_PRIORITY 1
00383 #endif
00384
00385 volatile uint8 au8_txFifo2[UART2_TX_FIFO_SIZE];
00386 volatile uint16 u16_txFifo2Head = 0;
00387 volatile uint16 u16_txFifo2Tail = 0;
00388
00393 void outChar2(uint8 u8_c) {
00394 uint16 u16_tmp;
00395
00396 u16_tmp = u16_txFifo2Head;
00397 u16_tmp++;
00398 if (u16_tmp == UART2_TX_FIFO_SIZE) u16_tmp = 0;
00399 while (u16_tmp == u16_txFifo2Tail)
00400 doHeartbeat();
00401
00402 au8_txFifo2[u16_tmp] = u8_c;
00403 u16_txFifo2Head = u16_tmp;
00404 _U2TXIE = 1;
00405 }
00406
00407 void _ISR _U2TXInterrupt (void) {
00408 if (u16_txFifo2Head == u16_txFifo2Tail) {
00409
00410 _U2TXIE = 0;
00411 } else {
00412
00413 u16_txFifo2Tail++;
00414 if (u16_txFifo2Tail == UART2_TX_FIFO_SIZE)
00415 u16_txFifo2Tail = 0;
00416 _U2TXIF = 0;
00417
00418 U2TXREG = au8_txFifo2[u16_txFifo2Tail];
00419 }
00420 }
00421
00422
00423 #else
00424
00428 void outChar2(uint8 u8_c) {
00429
00430 while (IS_TRANSMIT_BUFFER_FULL_UART2())
00431 doHeartbeat();
00432 U2TXREG = u8_c;
00433 }
00434 #endif
00435
00436 #ifdef UART2_RX_INTERRUPT
00437
00438 #ifndef UART2_RX_FIFO_SIZE
00439 #define UART2_RX_FIFO_SIZE 32 //choose a size
00440 #endif
00441
00442 #ifndef UART2_RX_INTERRUPT_PRIORITY
00443 #define UART2_RX_INTERRUPT_PRIORITY 1
00444 #endif
00445
00446 volatile uint8 au8_rxFifo2[UART2_RX_FIFO_SIZE];
00447 volatile uint16 u16_rxFifo2Head = 0;
00448 volatile uint16 u16_rxFifo2Tail = 0;
00449
00453 uint8 isCharReady2(void) {
00454 return(u16_rxFifo2Head != u16_rxFifo2Tail);
00455 }
00456
00461 uint8 inChar2(void) {
00462 while (u16_rxFifo2Head == u16_rxFifo2Tail)
00463 doHeartbeat();
00464 u16_rxFifo2Tail++;
00465 if (u16_rxFifo2Tail == UART2_RX_FIFO_SIZE) u16_rxFifo2Tail=0;
00466 return au8_rxFifo2[u16_rxFifo2Tail];
00467 }
00468
00469 void _ISR _U2RXInterrupt (void) {
00470 int8 u8_c;
00471
00472 _U2RXIF = 0;
00473 checkRxErrorUART2();
00474 u8_c = U2RXREG;
00475 u16_rxFifo2Head++;
00476 if (u16_rxFifo2Head == UART2_RX_FIFO_SIZE)
00477 u16_rxFifo2Head = 0;
00478 if (u16_rxFifo2Head == u16_rxFifo2Tail) {
00479
00480 reportError("UART2 RX Interrupt FIFO overrun!");
00481 }
00482 au8_rxFifo2[u16_rxFifo2Head] = u8_c;
00483 }
00484
00485 #else
00486
00489 uint8 isCharReady2(void) {
00490 return(IS_CHAR_READY_UART2());
00491 }
00492
00497 uint8 inChar2(void) {
00498
00499
00500
00501 while (!IS_CHAR_READY_UART2())
00502 doHeartbeat();
00503 checkRxErrorUART2();
00504 return U2RXREG;
00505 }
00506 #endif
00507
00508
00517 void configUART2(uint32 u32_baudRate) {
00518
00519
00520
00521
00522 #if defined(EXPLORER16_100P)
00523
00524 #elif (2 == 1) //change pin mappings for your device
00525 CONFIG_RP10_AS_DIG_PIN();
00526 CONFIG_U2RX_TO_RP(10);
00527 CONFIG_RP11_AS_DIG_PIN();
00528 CONFIG_U2TX_TO_RP(11);
00529 #else
00530 #warning UART2 pin mappings not defined!!! For simplicity,
00531 #warning pin mappings are identical for UARTS 1-4. If your device has more than
00532 #warning one UART, ****** CHANGE THE MAPPING ****** since
00533 #warning multiple UARTs can not share the same pins.
00534 #warning In particular:
00535 #warning 1. Change the statement #if (2 == 1) to #if 1
00536 #warning 2. Change the pin numbers in the next four lines
00537 #warning to something valid for your device.
00538 #warning If your device does not have remappable I/O,
00539 #warning (typical for >44 pin packages), skip this step --
00540 #warning the UART I/O pins are already assigned to something
00541 #warning valid.
00542 #endif
00543
00544 CONFIG_BAUDRATE_UART2(u32_baudRate);
00545 CONFIG_PDSEL_UART2(UXMODE_PDSEL_8DATA_NOPARITY);
00546 CONFIG_STOPBITS_UART2(1);
00547 #ifdef UART2_RX_INTERRUPT
00548 _U2RXIF = 0;
00549 _U2RXIP = UART2_RX_INTERRUPT_PRIORITY;
00550 _U2RXIE = 1;
00551 #endif
00552 #ifdef UART2_TX_INTERRUPT
00553
00554 _U2RXIP = UART2_TX_INTERRUPT_PRIORITY;
00555
00556 #endif
00557 ENABLE_UART2();
00558 }
00559
00560 #endif // #if (NUM_UARTS >= 2)
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 #include "pic24_all.h"
00598
00599
00600 #if (NUM_UART_MODS >= 3)
00601
00602
00603
00604
00605
00606
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00635 void checkRxErrorUART3(void) {
00636 uint8 u8_c;
00637
00638 if (U3STAbits.PERR) {
00639 u8_c = U3RXREG;
00640 reportError("UART3 parity error\n");
00641 }
00642 if (U3STAbits.FERR) {
00643 u8_c = U3RXREG;
00644 reportError("UART3 framing error\n");
00645 }
00646 if (U3STAbits.OERR) {
00647 U3STAbits.OERR = 0;
00648 reportError("UART3 overrun error\n");
00649 }
00650 }
00651
00652
00653
00654
00655 #ifdef UART3_TX_INTERRUPT
00656
00659 #ifndef UART3_TX_FIFO_SIZE
00660 #define UART3_TX_FIFO_SIZE 32 //choose a size
00661 #endif
00662
00663 #ifndef UART3_TX_INTERRUPT_PRIORITY
00664 #define UART3_TX_INTERRUPT_PRIORITY 1
00665 #endif
00666
00667 volatile uint8 au8_txFifo3[UART3_TX_FIFO_SIZE];
00668 volatile uint16 u16_txFifo3Head = 0;
00669 volatile uint16 u16_txFifo3Tail = 0;
00670
00675 void outChar3(uint8 u8_c) {
00676 uint16 u16_tmp;
00677
00678 u16_tmp = u16_txFifo3Head;
00679 u16_tmp++;
00680 if (u16_tmp == UART3_TX_FIFO_SIZE) u16_tmp = 0;
00681 while (u16_tmp == u16_txFifo3Tail)
00682 doHeartbeat();
00683
00684 au8_txFifo3[u16_tmp] = u8_c;
00685 u16_txFifo3Head = u16_tmp;
00686 _U3TXIE = 1;
00687 }
00688
00689 void _ISR _U3TXInterrupt (void) {
00690 if (u16_txFifo3Head == u16_txFifo3Tail) {
00691
00692 _U3TXIE = 0;
00693 } else {
00694
00695 u16_txFifo3Tail++;
00696 if (u16_txFifo3Tail == UART3_TX_FIFO_SIZE)
00697 u16_txFifo3Tail = 0;
00698 _U3TXIF = 0;
00699
00700 U3TXREG = au8_txFifo3[u16_txFifo3Tail];
00701 }
00702 }
00703
00704
00705 #else
00706
00710 void outChar3(uint8 u8_c) {
00711
00712 while (IS_TRANSMIT_BUFFER_FULL_UART3())
00713 doHeartbeat();
00714 U3TXREG = u8_c;
00715 }
00716 #endif
00717
00718 #ifdef UART3_RX_INTERRUPT
00719
00720 #ifndef UART3_RX_FIFO_SIZE
00721 #define UART3_RX_FIFO_SIZE 32 //choose a size
00722 #endif
00723
00724 #ifndef UART3_RX_INTERRUPT_PRIORITY
00725 #define UART3_RX_INTERRUPT_PRIORITY 1
00726 #endif
00727
00728 volatile uint8 au8_rxFifo3[UART3_RX_FIFO_SIZE];
00729 volatile uint16 u16_rxFifo3Head = 0;
00730 volatile uint16 u16_rxFifo3Tail = 0;
00731
00735 uint8 isCharReady3(void) {
00736 return(u16_rxFifo3Head != u16_rxFifo3Tail);
00737 }
00738
00743 uint8 inChar3(void) {
00744 while (u16_rxFifo3Head == u16_rxFifo3Tail)
00745 doHeartbeat();
00746 u16_rxFifo3Tail++;
00747 if (u16_rxFifo3Tail == UART3_RX_FIFO_SIZE) u16_rxFifo3Tail=0;
00748 return au8_rxFifo3[u16_rxFifo3Tail];
00749 }
00750
00751 void _ISR _U3RXInterrupt (void) {
00752 int8 u8_c;
00753
00754 _U3RXIF = 0;
00755 checkRxErrorUART3();
00756 u8_c = U3RXREG;
00757 u16_rxFifo3Head++;
00758 if (u16_rxFifo3Head == UART3_RX_FIFO_SIZE)
00759 u16_rxFifo3Head = 0;
00760 if (u16_rxFifo3Head == u16_rxFifo3Tail) {
00761
00762 reportError("UART3 RX Interrupt FIFO overrun!");
00763 }
00764 au8_rxFifo3[u16_rxFifo3Head] = u8_c;
00765 }
00766
00767 #else
00768
00771 uint8 isCharReady3(void) {
00772 return(IS_CHAR_READY_UART3());
00773 }
00774
00779 uint8 inChar3(void) {
00780
00781
00782
00783 while (!IS_CHAR_READY_UART3())
00784 doHeartbeat();
00785 checkRxErrorUART3();
00786 return U3RXREG;
00787 }
00788 #endif
00789
00790
00799 void configUART3(uint32 u32_baudRate) {
00800
00801
00802
00803
00804 #if defined(EXPLORER16_100P)
00805
00806 #elif (3 == 1) //change pin mappings for your device
00807 CONFIG_RP10_AS_DIG_PIN();
00808 CONFIG_U3RX_TO_RP(10);
00809 CONFIG_RP11_AS_DIG_PIN();
00810 CONFIG_U3TX_TO_RP(11);
00811 #else
00812 #warning UART3 pin mappings not defined!!! For simplicity,
00813 #warning pin mappings are identical for UARTS 1-4. If your device has more than
00814 #warning one UART, ****** CHANGE THE MAPPING ****** since
00815 #warning multiple UARTs can not share the same pins.
00816 #warning In particular:
00817 #warning 1. Change the statement #if (3 == 1) to #if 1
00818 #warning 2. Change the pin numbers in the next four lines
00819 #warning to something valid for your device.
00820 #warning If your device does not have remappable I/O,
00821 #warning (typical for >44 pin packages), skip this step --
00822 #warning the UART I/O pins are already assigned to something
00823 #warning valid.
00824 #endif
00825
00826 CONFIG_BAUDRATE_UART3(u32_baudRate);
00827 CONFIG_PDSEL_UART3(UXMODE_PDSEL_8DATA_NOPARITY);
00828 CONFIG_STOPBITS_UART3(1);
00829 #ifdef UART3_RX_INTERRUPT
00830 _U3RXIF = 0;
00831 _U3RXIP = UART3_RX_INTERRUPT_PRIORITY;
00832 _U3RXIE = 1;
00833 #endif
00834 #ifdef UART3_TX_INTERRUPT
00835
00836 _U3RXIP = UART3_TX_INTERRUPT_PRIORITY;
00837
00838 #endif
00839 ENABLE_UART3();
00840 }
00841
00842 #endif // #if (NUM_UARTS >= 3)
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879 #include "pic24_all.h"
00880
00881
00882 #if (NUM_UART_MODS >= 4)
00883
00884
00885
00886
00887
00888
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00917 void checkRxErrorUART4(void) {
00918 uint8 u8_c;
00919
00920 if (U4STAbits.PERR) {
00921 u8_c = U4RXREG;
00922 reportError("UART4 parity error\n");
00923 }
00924 if (U4STAbits.FERR) {
00925 u8_c = U4RXREG;
00926 reportError("UART4 framing error\n");
00927 }
00928 if (U4STAbits.OERR) {
00929 U4STAbits.OERR = 0;
00930 reportError("UART4 overrun error\n");
00931 }
00932 }
00933
00934
00935
00936
00937 #ifdef UART4_TX_INTERRUPT
00938
00941 #ifndef UART4_TX_FIFO_SIZE
00942 #define UART4_TX_FIFO_SIZE 32 //choose a size
00943 #endif
00944
00945 #ifndef UART4_TX_INTERRUPT_PRIORITY
00946 #define UART4_TX_INTERRUPT_PRIORITY 1
00947 #endif
00948
00949 volatile uint8 au8_txFifo4[UART4_TX_FIFO_SIZE];
00950 volatile uint16 u16_txFifo4Head = 0;
00951 volatile uint16 u16_txFifo4Tail = 0;
00952
00957 void outChar4(uint8 u8_c) {
00958 uint16 u16_tmp;
00959
00960 u16_tmp = u16_txFifo4Head;
00961 u16_tmp++;
00962 if (u16_tmp == UART4_TX_FIFO_SIZE) u16_tmp = 0;
00963 while (u16_tmp == u16_txFifo4Tail)
00964 doHeartbeat();
00965
00966 au8_txFifo4[u16_tmp] = u8_c;
00967 u16_txFifo4Head = u16_tmp;
00968 _U4TXIE = 1;
00969 }
00970
00971 void _ISR _U4TXInterrupt (void) {
00972 if (u16_txFifo4Head == u16_txFifo4Tail) {
00973
00974 _U4TXIE = 0;
00975 } else {
00976
00977 u16_txFifo4Tail++;
00978 if (u16_txFifo4Tail == UART4_TX_FIFO_SIZE)
00979 u16_txFifo4Tail = 0;
00980 _U4TXIF = 0;
00981
00982 U4TXREG = au8_txFifo4[u16_txFifo4Tail];
00983 }
00984 }
00985
00986
00987 #else
00988
00992 void outChar4(uint8 u8_c) {
00993
00994 while (IS_TRANSMIT_BUFFER_FULL_UART4())
00995 doHeartbeat();
00996 U4TXREG = u8_c;
00997 }
00998 #endif
00999
01000 #ifdef UART4_RX_INTERRUPT
01001
01002 #ifndef UART4_RX_FIFO_SIZE
01003 #define UART4_RX_FIFO_SIZE 32 //choose a size
01004 #endif
01005
01006 #ifndef UART4_RX_INTERRUPT_PRIORITY
01007 #define UART4_RX_INTERRUPT_PRIORITY 1
01008 #endif
01009
01010 volatile uint8 au8_rxFifo4[UART4_RX_FIFO_SIZE];
01011 volatile uint16 u16_rxFifo4Head = 0;
01012 volatile uint16 u16_rxFifo4Tail = 0;
01013
01017 uint8 isCharReady4(void) {
01018 return(u16_rxFifo4Head != u16_rxFifo4Tail);
01019 }
01020
01025 uint8 inChar4(void) {
01026 while (u16_rxFifo4Head == u16_rxFifo4Tail)
01027 doHeartbeat();
01028 u16_rxFifo4Tail++;
01029 if (u16_rxFifo4Tail == UART4_RX_FIFO_SIZE) u16_rxFifo4Tail=0;
01030 return au8_rxFifo4[u16_rxFifo4Tail];
01031 }
01032
01033 void _ISR _U4RXInterrupt (void) {
01034 int8 u8_c;
01035
01036 _U4RXIF = 0;
01037 checkRxErrorUART4();
01038 u8_c = U4RXREG;
01039 u16_rxFifo4Head++;
01040 if (u16_rxFifo4Head == UART4_RX_FIFO_SIZE)
01041 u16_rxFifo4Head = 0;
01042 if (u16_rxFifo4Head == u16_rxFifo4Tail) {
01043
01044 reportError("UART4 RX Interrupt FIFO overrun!");
01045 }
01046 au8_rxFifo4[u16_rxFifo4Head] = u8_c;
01047 }
01048
01049 #else
01050
01053 uint8 isCharReady4(void) {
01054 return(IS_CHAR_READY_UART4());
01055 }
01056
01061 uint8 inChar4(void) {
01062
01063
01064
01065 while (!IS_CHAR_READY_UART4())
01066 doHeartbeat();
01067 checkRxErrorUART4();
01068 return U4RXREG;
01069 }
01070 #endif
01071
01072
01081 void configUART4(uint32 u32_baudRate) {
01082
01083
01084
01085
01086 #if defined(EXPLORER16_100P)
01087
01088 #elif (4 == 1) //change pin mappings for your device
01089 CONFIG_RP10_AS_DIG_PIN();
01090 CONFIG_U4RX_TO_RP(10);
01091 CONFIG_RP11_AS_DIG_PIN();
01092 CONFIG_U4TX_TO_RP(11);
01093 #else
01094 #warning UART4 pin mappings not defined!!! For simplicity,
01095 #warning pin mappings are identical for UARTS 1-4. If your device has more than
01096 #warning one UART, ****** CHANGE THE MAPPING ****** since
01097 #warning multiple UARTs can not share the same pins.
01098 #warning In particular:
01099 #warning 1. Change the statement #if (4 == 1) to #if 1
01100 #warning 2. Change the pin numbers in the next four lines
01101 #warning to something valid for your device.
01102 #warning If your device does not have remappable I/O,
01103 #warning (typical for >44 pin packages), skip this step --
01104 #warning the UART I/O pins are already assigned to something
01105 #warning valid.
01106 #endif
01107
01108 CONFIG_BAUDRATE_UART4(u32_baudRate);
01109 CONFIG_PDSEL_UART4(UXMODE_PDSEL_8DATA_NOPARITY);
01110 CONFIG_STOPBITS_UART4(1);
01111 #ifdef UART4_RX_INTERRUPT
01112 _U4RXIF = 0;
01113 _U4RXIP = UART4_RX_INTERRUPT_PRIORITY;
01114 _U4RXIE = 1;
01115 #endif
01116 #ifdef UART4_TX_INTERRUPT
01117
01118 _U4RXIP = UART4_TX_INTERRUPT_PRIORITY;
01119
01120 #endif
01121 ENABLE_UART4();
01122 }
01123
01124 #endif // #if (NUM_UARTS >= 4)
01125
01126
01127
01128