[BSP][at91sam9260] Support rt_hw_console_output function.

This commit is contained in:
weety 2017-10-21 17:38:22 +08:00
parent ecc8db0cd6
commit ab7d4fd665
1 changed files with 94 additions and 4 deletions

View File

@ -150,18 +150,108 @@ static void at91sam926x_pit_init(void)
writel(0xffff, AT91SAM9260_BASE_TC0 + AT91_TC_CV);
}
#define RXRDY 0x01
#define TXRDY (1 << 1)
#define BPS 115200 /* serial baudrate */
typedef struct uartport
{
volatile rt_uint32_t CR;
volatile rt_uint32_t MR;
volatile rt_uint32_t IER;
volatile rt_uint32_t IDR;
volatile rt_uint32_t IMR;
volatile rt_uint32_t CSR;
volatile rt_uint32_t RHR;
volatile rt_uint32_t THR;
volatile rt_uint32_t BRGR;
volatile rt_uint32_t RTOR;
volatile rt_uint32_t TTGR;
volatile rt_uint32_t reserved0[5];
volatile rt_uint32_t FIDI;
volatile rt_uint32_t NER;
volatile rt_uint32_t reserved1;
volatile rt_uint32_t IFR;
volatile rt_uint32_t reserved2[44];
volatile rt_uint32_t RPR;
volatile rt_uint32_t RCR;
volatile rt_uint32_t TPR;
volatile rt_uint32_t TCR;
volatile rt_uint32_t RNPR;
volatile rt_uint32_t RNCR;
volatile rt_uint32_t TNPR;
volatile rt_uint32_t TNCR;
volatile rt_uint32_t PTCR;
volatile rt_uint32_t PTSR;
}uartport;
#define CIDR FIDI
#define EXID NER
#define FNR reserved1
#define DBGU ((struct uartport *)AT91SAM9260_BASE_DBGU)
static void at91_usart_putc(char c)
{
while (!(DBGU->CSR & TXRDY));
DBGU->THR = c;
}
/**
* This function is used to display a string on console, normally, it's
* invoked by rt_kprintf
*
* @param str the displayed string
*/
void rt_hw_console_output(const char* str)
{
while (*str)
{
if (*str=='\n')
{
at91_usart_putc('\r');
}
at91_usart_putc(*str++);
}
}
static void rt_hw_console_init(void)
{
int div;
int mode = 0;
DBGU->CR = AT91_US_RSTTX | AT91_US_RSTRX |
AT91_US_RXDIS | AT91_US_TXDIS;
mode |= AT91_US_USMODE_NORMAL | AT91_US_USCLKS_MCK |
AT91_US_CHMODE_NORMAL;
mode |= AT91_US_CHRL_8;
mode |= AT91_US_NBSTOP_1;
mode |= AT91_US_PAR_NONE;
DBGU->MR = mode;
div = (clk_get_rate(clk_get("mck")) / 16 + BPS/2) / BPS;
DBGU->BRGR = div;
DBGU->CR = AT91_US_RXEN | AT91_US_TXEN;
}
/**
* This function will init at91sam9260 board
*/
void rt_hw_board_init()
{
/* initialize mmu */
rt_hw_mmu_init(at91_mem_desc, sizeof(at91_mem_desc)/sizeof(at91_mem_desc[0]));
/* initialize hardware interrupt */
rt_hw_interrupt_init();
/* initialize the system clock */
rt_hw_clock_init();
/* initialize console */
rt_hw_console_init();
/* initialize mmu */
rt_hw_mmu_init(at91_mem_desc, sizeof(at91_mem_desc)/sizeof(at91_mem_desc[0]));
/* initialize hardware interrupt */
rt_hw_interrupt_init();
/* initialize early device */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();