Go to the documentation of this file.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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 #include "board.h"
00092
00093 #include <stdbool.h>
00094 #include <stdio.h>
00095 #include <string.h>
00096
00097
00098
00099
00100 #define BASE_UART UART4
00101 #define BASE_ID ID_UART4
00102 #define BASE_IRQ UART4_IRQn
00103
00104 #define RX_SIZE 30
00105
00106
00107
00108
00109 const Pin BASE_UART_PINS[] = {PINS_UART4};
00110
00111 static UartDma Uartd;
00112 static UartChannel UartTx, UartRx;
00113 static sXdmad dmad;
00114
00115 uint8_t pTxBuffer[] = {"This is UART Tx Buffer.........\n\r"};
00116 uint8_t pRxBuffer[RX_SIZE];
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 void UART4_Handler()
00128 {
00129 uint32_t Status = UART_GetStatus(BASE_UART);
00130
00131 if(Status & (UART_SR_OVRE | UART_SR_FRAME | UART_SR_PARE)) {
00132 BASE_UART->UART_CR = UART_CR_RSTSTA;
00133 printf("Error \n\r");
00134 }
00135
00136 printf("%c", (char)BASE_UART->UART_RHR);
00137 }
00138
00139
00140
00141
00142
00143
00144 void XDMAC_Handler(void)
00145 {
00146 XDMAD_Handler(&dmad);
00147 }
00148
00149
00150
00151
00152 static void DisplayMenu( void )
00153 {
00154 printf( "\n\rMenu :\n\r" );
00155 printf( "========================\n\r" );
00156 printf( " UART is Configured in : LoopBack\n\r" ) ;
00157 printf( " I: Perform UART transfer with interrupt\n\r" ) ;
00158 printf( " D: Perform UART DMA transfer in local loopback\n\r" ) ;
00159 printf( " H: Display menu \n\r\n\r" ) ;
00160 printf( "========================\n\r" );
00161 }
00162
00163
00164
00165
00166 static void UartTransfer(void)
00167 {
00168 uint8_t *pBuffer = &pTxBuffer[0];
00169
00170 PMC_EnablePeripheral(BASE_ID);
00171 UART_Configure(BASE_UART, ( UART_MR_PAR_NO | UART_MR_CHMODE_LOCAL_LOOPBACK ),
00172 115200, BOARD_MCK);
00173
00174 NVIC_ClearPendingIRQ(BASE_IRQ);
00175 NVIC_SetPriority( BASE_IRQ ,1);
00176
00177
00178 UART_SetTransmitterEnabled ( BASE_UART , 1);
00179 UART_SetReceiverEnabled ( BASE_UART , 1);
00180
00181 UART_EnableIt(BASE_UART, (UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME
00182 | UART_IER_PARE));
00183
00184 NVIC_EnableIRQ(BASE_IRQ);
00185
00186 while(*pBuffer != '\0') {
00187 UART_PutChar(BASE_UART, *pBuffer);
00188 pBuffer++;
00189 }
00190 UART_PutChar(BASE_UART, *pBuffer);
00191 }
00192
00193
00194
00195
00196 static void _UartdConfigLB(void)
00197 {
00198 uint32_t mode = 0
00199 | UART_MR_PAR_NO
00200 | UART_MR_BRSRCCK_PERIPH_CLK
00201 | UART_MR_CHMODE_LOCAL_LOOPBACK ;
00202
00203 dmad.pXdmacs = XDMAC;
00204
00205 memset(&UartTx, 0, sizeof(UartChannel));
00206 memset(&UartRx, 0, sizeof(UartChannel));
00207 UartTx.BuffSize = 25;
00208 UartTx.pBuff = pTxBuffer;
00209 UartRx.BuffSize= 25;
00210 UartRx.pBuff = pRxBuffer;
00211 UartTx.sempaphore = 1;
00212 UartRx.sempaphore = 1;
00213
00214 Uartd.pRxChannel = &UartRx;
00215 Uartd.pTxChannel = &UartTx;
00216 Uartd.pXdmad = &dmad;
00217 PMC_EnablePeripheral(BASE_ID);
00218 UARTD_Configure(&Uartd, BASE_ID, mode, 115200, BOARD_MCK);
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 extern int main( void )
00230 {
00231 uint8_t ucKey ;
00232
00233
00234 WDT_Disable( WDT ) ;
00235
00236
00237 printf( "-- UART Example %s --\n\r", SOFTPACK_VERSION ) ;
00238 printf( "-- %s\n\r", BOARD_NAME ) ;
00239 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00240
00241
00242 SCB_EnableICache();
00243 SCB_EnableDCache();
00244
00245
00246 DisplayMenu() ;
00247
00248 while ( 1 )
00249 {
00250 ucKey = DBG_GetChar() ;
00251
00252 switch ( ucKey ) {
00253 case 'h' :
00254 DisplayMenu() ;
00255 break ;
00256 case 'i' :case 'I' :
00257 printf("\n\rSending Tx Buffer.. \n\r");
00258 UartTransfer() ;
00259 break;
00260
00261 case 'd':case 'D':
00262 memset(pRxBuffer,'X' ,30);
00263 pRxBuffer[28] = '\n';
00264 pRxBuffer[29] = '\r';
00265 printf("\n\rRx Buffer before transfer is \n\r");
00266 puts((char*)pRxBuffer);
00267 _UartdConfigLB();
00268 UARTD_EnableRxChannels(&Uartd, &UartRx);
00269 UARTD_EnableTxChannels(&Uartd, &UartTx);
00270 UARTD_RcvData(&Uartd);
00271 UARTD_SendData(&Uartd);
00272
00273 printf("\n\rRx Buffer after transfer is \n\r");
00274 puts((char*)pRxBuffer);
00275 UARTD_DisableRxChannels(&Uartd, &UartRx);
00276 UARTD_DisableTxChannels(&Uartd, &UartTx);
00277 break ;
00278
00279 default :
00280 break ;
00281 }
00282 }
00283 }
00284