rt-thread-official/bsp/nxp/lpc/lpc2148/drivers/board.c

103 lines
1.8 KiB
C
Raw Normal View History

/*
2021-03-17 02:26:35 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2006-08-23 Bernard first implementation
*/
#include <rthw.h>
2013-01-08 22:40:58 +08:00
#include <rtthread.h>
2013-01-08 22:40:58 +08:00
#include "lpc214x.h"
#include "board.h"
/**
* @addtogroup LPC2148
*/
/*@{*/
/**
* This is the timer interrupt service routine.
* @param vector the irq number for timer
*/
void rt_hw_timer_handler(int vector, void *param)
2013-01-08 22:40:58 +08:00
{
2021-03-17 02:26:35 +08:00
rt_tick_increase();
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* clear interrupt flag */
T0IR |= 0x01;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* acknowledge Interrupt */
VICVectAddr = 0;
}
/**
* 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)
2013-01-08 22:40:58 +08:00
{
2021-03-17 02:26:35 +08:00
while (*str)
{
if (*str=='\n')
{
while (!(U0LSR & 0x20));
U0THR = '\r';
}
while (!(U0LSR & 0x20));
U0THR = *str;
str ++;
}
2013-01-08 22:40:58 +08:00
}
2021-03-17 02:26:35 +08:00
#define BAUD_RATE 115200
#define U0PINS 0x05
2013-01-08 22:40:58 +08:00
void rt_hw_console_init()
{
2021-03-17 02:26:35 +08:00
/* Enable RxD and TxD pins */
PINSEL0 = U0PINS;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* 8 bits, no Parity, 1 Stop bit */
U0LCR = 0x83;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* Setup Baudrate */
U0DLL = (PCLK/16/BAUD_RATE) & 0xFF;
U0DLM = ((PCLK/16/BAUD_RATE) >> 8) & 0xFF;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* DLAB = 0 */
U0LCR = 0x03;
2013-01-08 22:40:58 +08:00
}
/**
* This function will initial sam7x256 board.
*/
void rt_hw_board_init(void)
2013-01-08 22:40:58 +08:00
{
2021-03-17 02:26:35 +08:00
/* console init */
rt_hw_console_init();
2021-03-17 02:26:35 +08:00
/* prescaler = 0*/
T0PR = 0;
T0PC = 0;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* reset and enable MR0 interrupt */
T0MCR = 0x3;
T0MR0 = PCLK / RT_TICK_PER_SECOND;
2021-03-17 02:26:35 +08:00
/* enable timer 0 */
T0TCR = 1;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* install timer handler */
rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL, "TIMER0");
rt_hw_interrupt_umask(TIMER0_INT);
2013-01-08 22:40:58 +08:00
}
/*@}*/