1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2006-08-23     Bernard      first implementation
9  */
10 
11 #include <rthw.h>
12 #include <rtthread.h>
13 
14 #include "lpc214x.h"
15 #include "board.h"
16 
17 /**
18  * @addtogroup LPC2148
19  */
20 /*@{*/
21 
22 /**
23  * This is the timer interrupt service routine.
24  * @param vector the irq number for timer
25  */
rt_hw_timer_handler(int vector,void * param)26 void rt_hw_timer_handler(int vector, void *param)
27 {
28     rt_tick_increase();
29 
30     /* clear interrupt flag */
31     T0IR |= 0x01;
32 
33     /* acknowledge Interrupt */
34     VICVectAddr = 0;
35 }
36 
37 /**
38  * This function is used to display a string on console, normally, it's
39  * invoked by rt_kprintf
40  *
41  * @param str the displayed string
42  */
rt_hw_console_output(const char * str)43 void rt_hw_console_output(const char* str)
44 {
45     while (*str)
46     {
47         if (*str=='\n')
48         {
49             while (!(U0LSR & 0x20));
50             U0THR = '\r';
51         }
52 
53         while (!(U0LSR & 0x20));
54         U0THR = *str;
55 
56         str ++;
57     }
58 }
59 
60 #define BAUD_RATE   115200
61 #define U0PINS      0x05
rt_hw_console_init()62 void rt_hw_console_init()
63 {
64     /* Enable RxD and TxD pins */
65     PINSEL0 = U0PINS;
66 
67     /* 8 bits, no Parity, 1 Stop bit */
68     U0LCR = 0x83;
69 
70     /* Setup Baudrate */
71     U0DLL = (PCLK/16/BAUD_RATE) & 0xFF;
72     U0DLM = ((PCLK/16/BAUD_RATE) >> 8) & 0xFF;
73 
74     /* DLAB = 0 */
75     U0LCR = 0x03;
76 }
77 
78 /**
79  * This function will initial sam7x256 board.
80  */
rt_hw_board_init(void)81 void rt_hw_board_init(void)
82 {
83     /* console init */
84     rt_hw_console_init();
85 
86     /* prescaler = 0*/
87     T0PR = 0;
88     T0PC = 0;
89 
90     /* reset and enable MR0 interrupt */
91     T0MCR = 0x3;
92     T0MR0 = PCLK / RT_TICK_PER_SECOND;
93 
94     /* enable timer 0 */
95     T0TCR = 1;
96 
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);
100 }
101 
102 /*@}*/
103