board.c 1.7 KB
Newer Older
1
/*
2
 * Copyright (c) 2006-2018, RT-Thread Development Team
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
5 6 7 8 9 10 11
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-08-23     Bernard      first implementation
 */

#include <rthw.h>
M
Ming, Bai 已提交
12
#include <rtthread.h>
13

M
Ming, Bai 已提交
14 15
#include "lpc214x.h"
#include "board.h"
16 17 18 19 20 21 22 23 24 25

/**
 * @addtogroup LPC2148
 */
/*@{*/

/**
 * This is the timer interrupt service routine.
 * @param vector the irq number for timer
 */
26
void rt_hw_timer_handler(int vector, void *param)
M
Ming, Bai 已提交
27 28 29 30 31 32 33 34
{
	rt_tick_increase();

	/* clear interrupt flag */
	T0IR |= 0x01;

	/* acknowledge Interrupt */
	VICVectAddr = 0;
35 36 37 38 39 40 41 42 43
}

/**
 * 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)
M
Ming, Bai 已提交
44
{
45 46
	while (*str)
	{
M
Ming, Bai 已提交
47 48 49 50 51
		if (*str=='\n')
		{
			while (!(U0LSR & 0x20));
			U0THR = '\r';
		}
52

M
Ming, Bai 已提交
53 54
		while (!(U0LSR & 0x20));
		U0THR = *str;
55

M
Ming, Bai 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
		str ++;
	}
}

#define BAUD_RATE	115200
#define U0PINS		0x05
void rt_hw_console_init()
{
	/* Enable RxD and TxD pins */
  	PINSEL0 = U0PINS;

	/* 8 bits, no Parity, 1 Stop bit */
	U0LCR = 0x83;

	/* Setup Baudrate */
	U0DLL = (PCLK/16/BAUD_RATE) & 0xFF;
	U0DLM = ((PCLK/16/BAUD_RATE) >> 8) & 0xFF;

	/* DLAB = 0 */
	U0LCR = 0x03;
}

78 79 80
/**
 * This function will initial sam7x256 board.
 */
81
void rt_hw_board_init(void)
M
Ming, Bai 已提交
82 83 84
{
	/* console init */
	rt_hw_console_init();
85

M
Ming, Bai 已提交
86 87 88 89 90 91 92
	/* prescaler = 0*/
   	T0PR = 0;
   	T0PC = 0;

	/* reset and enable MR0 interrupt */
	T0MCR = 0x3;
	T0MR0 = PCLK / RT_TICK_PER_SECOND;
93

M
Ming, Bai 已提交
94 95 96
	/* enable timer 0 */
	T0TCR = 1;

97
	/* install timer handler */
98
	rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL, "TIMER0");
99
	rt_hw_interrupt_umask(TIMER0_INT);
M
Ming, Bai 已提交
100
}
101 102

/*@}*/