#include "project.h"
#define MAIN_OSC 18432000 // 크리스탈 속도
#define MAIN_CLK ((MAIN_OSC*73/14)/2) // 체배기를 거친 후 속도
#define DBGU_SPEED 115200 // 디버그 유닛 속도
void Test()
{
// Reset and disable receiver
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
// Disable interrupts
AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
// Configure PIOs for DBGU
AT91C_BASE_PIOA->PIO_ASR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
AT91C_BASE_PIOA->PIO_BSR = 0;
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
// === Configure serial link ===
// Define the baud rate divisor register [BRGR = MAIN_CLK / (115200 * 16)]
AT91C_BASE_DBGU->DBGU_BRGR = MAIN_CLK / (DBGU_SPEED * 16);
// Define the USART mode
AT91C_BASE_DBGU->DBGU_MR = AT91C_US_PAR_NONE | AT91C_US_CHMODE_NORMAL;
// Disable the RX and TX PDC transfer requests
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_RXTDIS;
AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_TXTDIS;
// Enable transmitter
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_TXEN;
}
void DBGU_Write_String(const char *cData)
{
while (0 != *cData)
{
while (0 == (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXRDY));
AT91C_BASE_DBGU->DBGU_THR = (*cData++);
}
}
int main()
{
volatile unsigned int iCount = 0;
Test();
(*(volatile unsigned int *)0xFFFFF400) = 0x0000000F;
(*(volatile unsigned int *)0xFFFFF410) = 0x0000000F;
(*(volatile unsigned int *)0xFFFFF430) = 0x00000003;
while (1)
{
for(iCount=0;1000000 >= iCount; ++iCount);
(*(volatile unsigned int *)0xFFFFF430) = 0x00000001;
DBGU_Write_String("test\n\r");
for(iCount=0;1000000 >= iCount; ++iCount);
(*(volatile unsigned int *)0xFFFFF434) = 0x00000001;
}
}