//*---------------------------------------------------------------------------- //* \fn AT91F_LowLevelInit //* \brief This function performs very low level HW initialization //*---------------------------------------------------------------------------- void AT91F_LowLevelInit() { unsigned int tmp = 0; AT91PS_PMC pPmc = AT91C_BASE_PMC; // Disable watchdog *(AT91C_WDTC_WDMR) = AT91C_WDTC_WDDIS; AT91F_MATRIX_Remap_ARM(AT91C_BASE_MATRIX); // Open PIO for DBGU AT91F_DBGU_CfgPIO(); // Configure DBGU AT91F_US_Configure ( (AT91PS_USART) AT91C_BASE_DBGU, // DBGU base address AT91C_MASTER_CLOCK, AT91C_US_ASYNC_MODE, // mode Register to be programmed 115200 , // baudrate to be programmed 0); // timeguard to be programmed // Enable Transmitter AT91F_US_EnableTx((AT91PS_USART) AT91C_BASE_DBGU); AT91F_US_EnableRx((AT91PS_USART) AT91C_BASE_DBGU); }
//=============================================================================================== __inline AT91F_US_START_TRANSMITION(AT91PS_USART COM, uint8 *data, int size) { portENTER_CRITICAL(); { AT91F_US_EnableTx(COM); AT91F_US_EnableIt(COM,AT91C_US_TXEMPTY | AT91C_US_TXEN ); COM->US_TCR = 0; COM->US_TNCR = 0; COM->US_TPR = (unsigned int) data; COM->US_TCR = size; } portEXIT_CRITICAL(); }
int main() { int _row, _col; char c; U32 status; AT91PS_PIO pPioA = AT91C_BASE_PIOA; AT91PS_PMC pPMC = AT91C_BASE_PMC; AT91PS_USART pUART0 = AT91C_BASE_US0; /* Initialize the Atmel AT91SAM7X256 (watchdog, PLL clock, default interrupts, etc.) */ AT91F_LowLevel_Init(); /* Init the LCD */ InitLCD(); /* Init the UART */ AT91F_US_Configure(pUART0, MCK, AT91C_US_ASYNC_MODE, 9600L, 0 ); AT91F_PMC_EnablePeripheralClock(pPMC, 1 << AT91C_ID_US0 ); AT91F_US_EnableRx(pUART0); AT91F_US_EnableTx(pUART0); AT91F_PIO_Disable( pPioA, RXD0 | TXD0 | RTS0 | CTS0 ); AT91F_PIO_A_RegisterSelection( pPioA, RXD0 | TXD0 | RTS0 | CTS0 ); /* enable interrupts */ AT91F_Finalize_Init(); /* add your program here ... */ LCD_ClearScreen( LCD_COLOR_RED ); LCD_WriteString("UART Demo:", &Fixedsys_descriptor, 2, Fixedsys_descriptor.font_height, LCD_COLOR_WHITE, LCD_COLOR_RED); _row = 2*(Fixedsys_descriptor.font_height+2); _col = 2; /* ... and here */ while ( true ) { status = AT91F_US_RxReady(pUART0); if(status) { c = AT91F_US_GetChar(pUART0); AT91F_US_PutChar(pUART0, c); LCD_WriteChar(c, &Fixedsys_descriptor, _col, _row, LCD_COLOR_WHITE, LCD_COLOR_RED); if (_col<(128-Fixedsys_descriptor.font_width)) _col += Fixedsys_descriptor.font_width; else { _col = 2; _row += (Fixedsys_descriptor.font_height+2); if (_row>(128-Fixedsys_descriptor.font_height)) { LCD_ClearScreen( LCD_COLOR_RED ); _row = 2; //Fixedsys_descriptor.font_height; _col = 2; } } } else status = AT91F_US_TxReady(pUART0); if(status) { //AT91F_US_PutChar(pUART0, '.'); } } /* Actually, the execution never gets here */ return 0; }