Rev 171 | Rev 195 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 171 | Rev 190 | ||
---|---|---|---|
Line 56... | Line 56... | ||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | //#include <stdio.h> |
57 | //#include <stdio.h> |
58 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
59 | #include "config.h" |
59 | #include "config.h" |
60 | #include "uart1.h" |
60 | #include "uart1.h" |
- | 61 | #include "mkprotocol.h" |
|
- | 62 | ||
- | 63 | // the tx buffer |
|
- | 64 | #define UART2_TX_BUFFER_LEN 150 |
|
- | 65 | u8 UART2_tbuffer[UART2_TX_BUFFER_LEN]; |
|
- | 66 | Buffer_t UART2_tx_buffer; |
|
Line 61... | Line 67... | ||
61 | 67 | ||
62 | /********************************************************/ |
68 | /********************************************************/ |
63 | /* Initialize UART2 */ |
69 | /* Initialize UART2 */ |
64 | /********************************************************/ |
70 | /********************************************************/ |
Line 67... | Line 73... | ||
67 | UART_InitTypeDef UART_InitStructure; |
73 | UART_InitTypeDef UART_InitStructure; |
68 | GPIO_InitTypeDef GPIO_InitStructure; |
74 | GPIO_InitTypeDef GPIO_InitStructure; |
Line 69... | Line 75... | ||
69 | 75 | ||
Line -... | Line 76... | ||
- | 76 | UART1_PutString("\r\n UART2 init..."); |
|
- | 77 | ||
- | 78 | // initialize txd buffer |
|
70 | UART1_PutString("\r\n UART2 init..."); |
79 | Buffer_Init(&UART2_tx_buffer, UART2_tbuffer, UART2_TX_BUFFER_LEN); |
Line 71... | Line 80... | ||
71 | 80 | ||
72 | SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock |
81 | SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock |
73 | 82 | ||
Line 185... | Line 194... | ||
185 | } |
194 | } |
186 | else |
195 | else |
187 | { |
196 | { |
188 | // ignore serial data from the FC |
197 | // ignore serial data from the FC |
189 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
198 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
- | 199 | { |
|
190 | UART_ReceiveData(UART2); |
200 | UART_ReceiveData(UART2); |
- | 201 | } |
|
191 | } |
202 | } |
192 | } // eof receive irq or receive timeout irq |
203 | } // eof receive irq or receive timeout irq |
193 | } |
204 | } |
- | 205 | ||
- | 206 | /**************************************************************/ |
|
- | 207 | /* Transmit tx buffer via uart2 */ |
|
- | 208 | /**************************************************************/ |
|
- | 209 | void UART2_Transmit(void) |
|
- | 210 | { |
|
- | 211 | u8 tmp_tx; |
|
- | 212 | if(DebugUART == UART2) return; // no data output if debug uart is rederected to UART2 |
|
- | 213 | // if something has to be send and the txd fifo is not full |
|
- | 214 | if((UART2_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) == RESET)) |
|
- | 215 | { |
|
- | 216 | tmp_tx = UART2_tx_buffer.pData[UART2_tx_buffer.Position++]; // read next byte from txd buffer |
|
- | 217 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
|
- | 218 | // if terminating character or end of txd buffer reached |
|
- | 219 | if((tmp_tx == '\r') || (UART2_tx_buffer.Position == UART2_tx_buffer.Size)) |
|
- | 220 | { |
|
- | 221 | Buffer_Clear(&UART2_tx_buffer); |
|
- | 222 | } |
|
- | 223 | } |
|
- | 224 | } |
|
- | 225 | ||
- | 226 | /**************************************************************/ |
|
- | 227 | /* Send the answers to incomming commands at the uart2 */ |
|
- | 228 | /**************************************************************/ |
|
- | 229 | void UART2_TransmitTxData(void) |
|
- | 230 | { |
|
- | 231 | if(DebugUART == UART2) return; |
|
- | 232 | UART2_Transmit(); // output pending bytes in tx buffer |
|
- | 233 | } |
|
- | 234 | ||
- | 235 | ||
- | 236 | void UART2_ProcessRxData(void) |
|
- | 237 | { |
|
- | 238 | ||
- | 239 | } |