00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 00036 #ifndef _ESOS_PIC24_RS232_H 00037 #define _ESOS_PIC24_RS232_H 00038 00039 /* I N C L U D E S **********************************************************/ 00040 #include "esos.h" 00041 #include "esos_comm.h" 00042 #include "esos_pic24.h" 00043 00044 /* D E F I N I T I O N S ****************************************************/ 00045 00046 // use the same definitions as the non-ESOS pic24_uart.h/.c library but 00047 // prepend with our __ESOS_ tag 00048 #define __ESOS_UART1_TX_INTERRUPT 00049 #define __ESOS_UART1_RX_INTERRUPT 00050 #define __ESOS_UART1_TX_INTERRUPT_PRIORITY 5 00051 #define __ESOS_UART1_RX_INTERRUPT_PRIORITY 5 00052 00053 /* E X T E R N S ************************************************************/ 00054 00055 /* M A C R O S **************************************************************/ 00056 00057 /* P U B L I C P R O T O T Y P E S *****************************************/ 00058 void __esos_hw_signal_start_tx(void); 00059 void __esos_hw_signal_stop_tx(void); 00060 00061 // Documentation for this file. If the \file tag isn't present, 00062 // this file won't be documented. 00070 /* ########################################################################### */ 00074 #define DEFAULT_BAUDRATE 57600 00075 00089 static inline void CONFIG_BAUDRATE_UART1(uint32 baudRate) { 00090 uint32 brg = (FCY/baudRate/16) - 1; 00091 ASSERT(brg <= 0xFFFF); 00092 U1MODEbits.BRGH = 0; 00093 U1BRG = brg; 00094 } 00095 00096 00100 #define UXMODE_PDSEL_8DATA_NOPARITY 0 00101 #define UXMODE_PDSEL_8DATA_EVENPARITY 1 00102 #define UXMODE_PDSEL_8DATA_ODDPARITY 2 00103 #define UXMODE_PDSEL_9DATA_NOPARITY 3 00105 00106 00110 inline static void CONFIG_PDSEL_UART1(uint8 u8_pdsel) { 00111 ASSERT(u8_pdsel <= UXMODE_PDSEL_9DATA_NOPARITY); 00112 U1MODEbits.PDSEL = u8_pdsel; 00113 } 00114 00119 inline static void CONFIG_STOPBITS_UART1(uint8 u8_numStopbits) { 00120 ASSERT(u8_numStopbits <= 2); 00121 U1MODEbits.STSEL = u8_numStopbits - 1; 00122 } 00123 00125 static inline void ENABLE_UART1() { 00126 U1MODEbits.UEN = 0b00; // UxTX and UxRX pins are enabled and used; no flow control pins 00127 U1MODEbits.UARTEN = 1; // enable UART RX/TX 00128 U1STAbits.UTXEN = 1; //Enable the transmitter 00129 } 00130 00135 #define IS_CHAR_READY_UART1() U1STAbits.URXDA 00136 00141 #define IS_TRANSMIT_BUFFER_FULL_UART1() U1STAbits.UTXBF 00142 00148 #define IS_TRANSMIT_COMPLETE_UART1() U1STAbits.TRMT 00149 00150 // communications commands used outside of ESOS tasks (like user_init routine) 00151 // these routines/macros should almost never be used. 00152 void __esos_hw_PutUint8(uint8 u8_c); 00153 void __esos_hw_PutString(uint8* psz_in); 00154 uint8 __esos_hw_GetUint8(void); 00155 00156 00157 void configUART1(uint32 u32_baudRate); 00158 void __esos_hw_InitCommSystem(void); 00159 00160 00162 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART1() { 00163 while (!IS_TRANSMIT_COMPLETE_UART1()) 00164 doHeartbeat(); 00165 } 00166 00167 00168 00169 #endif // end ESOS_PIC24_RS232_H