| Mobil_surveillance_system 1 | 
00001 #ifndef UART1_H_ 00002 #define UART1_H_ 00003 00005 00012 #include <string.h> // due to: using predefinition of NULL 00013 #include <stdlib.h> // due to: calloc function 00014 00015 #include "msp430f2617.h" 00016 #include "Bitmanip.h" // due to: the bit manipulations macros 00017 #include "FIFO.h" // due to: uart1 rx and tx buffer 00018 #include "Interrupts.h" // due to: Interrupts_setUSCI1RX_ISRCallbackFunction and Interrupts_setUSCI1TX_ISRCallbackFunction 00019 00020 /******************************************************************************************************** 00021 * UART calculations: 00022 * 00023 * UART speed is 9600 baud = 1/9600 =9.6*10^-6 = 10us (The elapsed time between two received bit) 00024 * Byte contains 10 bit with the stop and start bit so ~100 us the elapsed time between 2 received byte) 00025 * MCU clk = 16 MHz = 16 * 10^6 intsuction in one sec 00026 * -> 1 instruction time is = 0.0625 * 10^-6 = 62.5 * 10^-9 -> 62.5 ns 00027 * 00028 * Consecvencies 00029 * 00030 * 100*10^3 / 62.5 = 1600 instructions can be done bye the MCU between two character has been received. 00031 * 00032 * 00033 * ******************************************************************************************************/ 00034 00035 //***************************************************************************** 00036 // 00037 // Types and Definitions 00038 // 00039 //***************************************************************************** 00040 00041 // Size definitions of the used uart receive and transfer buffer 00042 #define UART1_RX_BUFFER_SIZE 16 00043 #define UART1_TX_BUFFER_SIZE 16 00044 00045 00046 #ifndef DEFINE_TBOOLEAN // define unsigned char as tBoolean in only that case when it hasn't been defined yet somewhere else in the scope 00047 00049 typedef unsigned char tBoolean; // use as bool 00050 #define DEFINE_TBOOLEAN 00051 00052 #endif // DEFINE_TBOOLEAN 00053 00054 00056 typedef void (*tpfUART1AppendResponseCallbackFunction) (const char*); 00057 00058 //***************************************************************************** 00059 // 00060 // Globale variables 00061 // 00062 //***************************************************************************** 00063 00065 extern tBoolean ge_tbUART1RXITFLAG; 00066 00068 extern tBoolean ge_tbUART1TXITFLAG; 00069 00070 //***************************************************************************** 00071 // 00072 // Macros to determine number of free and used bytes in the transmit buffer. 00073 // 00074 //***************************************************************************** 00075 00077 #define UART1_TX_BUFFER_USED (FIFO_getBufferCount(&g_uiUart1TxReadIndex,\ 00078 &g_uiUart1TxWriteIndex,\ 00079 UART1_TX_BUFFER_SIZE)) 00080 00082 #define UART1_TX_BUFFER_FREE (UART1_TX_BUFFER_SIZE - UART1_TX_BUFFER_USED) 00083 00084 00086 #define UART1_TX_BUFFER_EMPTY (FIFO_isBufferEmpty(&g_uiUart1TxReadIndex,\ 00087 &g_uiUart1TxWriteIndex)) 00088 00090 #define UART1_TX_BUFFER_FULL (FIFO_isBufferFull(&g_uiUart1TxReadIndex,\ 00091 &g_uiUart1TxWriteIndex,\ 00092 UART1_TX_BUFFER_SIZE)) 00093 00095 #define UART1_ADVANCE_TX_BUFFER_INDEX(Index) ((Index) = ((Index) + 1) % UART1_TX_BUFFER_SIZE) 00096 00097 00098 //***************************************************************************** 00099 // 00100 // Macros to determine number of free and used bytes in the receive buffer. 00101 // 00102 //***************************************************************************** 00103 00105 #define UART1_RX_BUFFER_USED (FIFO_getBufferCount(&g_uiUart1RxReadIndex,\ 00106 &g_uiUart1RxWriteIndex,\ 00107 UART1_RX_BUFFER_SIZE)) 00108 00110 #define UART1_RX_BUFFER_FREE (UART1_RX_BUFFER_SIZE - UART1_RX_BUFFER_USED) 00111 00112 00114 #define UART1_RX_BUFFER_EMPTY (FIFO_isBufferEmpty(&g_uiUart1RxReadIndex,\ 00115 &g_uiUart1RxWriteIndex)) 00116 00118 #define UART1_RX_BUFFER_FULL (FIFO_isBufferFull(&g_uiUart1RxReadIndex,\ 00119 &g_uiUart1RxWriteIndex, \ 00120 UART1_RX_BUFFER_SIZE)) 00121 00123 #define UART1_ADVANCE_RX_BUFFER_INDEX(Index) ((Index) = ((Index) + 1) % UART1_RX_BUFFER_SIZE) 00124 00125 //***************************************************************************** 00126 // 00127 // Function declarations 00128 // 00129 //***************************************************************************** 00130 00134 void UART1_rxHandler( void ); 00135 00136 00140 void UART1_txHandler( void ); 00141 00142 00146 void UART1_initUART1( void ); 00147 00148 00152 int UART1_read( void ); 00153 00154 00159 int UART1_write( char* pcBuffer, unsigned int uiLength ); 00160 00161 00165 void UART1_sendChar( void ); 00166 00167 00171 tBoolean UART1_isWritingDone( void ); 00172 00173 00177 void UART1_primeTransmit( void ); 00178 00179 00183 void UART1_flushRx( void ); 00184 00185 00189 void UART1_flushTx( void ); 00190 00191 00195 void UART1_setAppendResponseCallbackFunction( tpfUART1AppendResponseCallbackFunction pfCallbackAppendResponse ); 00196 00197 00198 #endif /*UART1_H_*/
 1.7.4
 1.7.4