board.c 1.6 KB
Newer Older
B
bernard.xiong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * File      : board.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Develop Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2010-06-25     Bernard      first version
 */

#include <rtthread.h>
#include <rthw.h>

#include "board.h"
#include "uart.h"
20
#include <jz4755.h>
B
bernard.xiong 已提交
21 22 23 24 25 26 27 28 29

/**
 * @addtogroup JZ47xx
 */
/*@{*/

/**
 * This is the timer interrupt service routine.
 */
B
Bernard Xiong 已提交
30
void rt_hw_timer_handler(int vector, void* param)
B
bernard.xiong 已提交
31
{
32
	/* increase a OS tick */
B
bernard.xiong 已提交
33 34
	rt_tick_increase();

35 36 37 38 39 40 41
	/* clear flag */
	TCU_TFCR = TCU_TFCR_OSTFLAG;
}

/**
 * This function will initial OS timer
 */
42
void rt_hw_timer_init(void)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
{
	rt_uint32_t val;

	/* disable TCU clock */
	CPM_CLKGR &= ~CPM_CLKGR_TCU;
	TCU_TECR = TCU_TECR_OSTCL;

	/* set */
	OST_DR = RT_TICK_PER_SECOND * 0xcffff;
	/* clear counter */
	OST_CNT = 0;

#ifdef RTC_SRC_EXTAL
	OST_CSR = (val | OST_TCSR_EXT_EN);
#else
	OST_CSR = (val | OST_TCSR_PCLK_EN);
#endif

	TCU_TFCR = TCU_TFCR_OSTFLAG;
	TCU_TMCR = TCU_TMCR_OSTMCL;
	TCU_TESR = TCU_TESR_OSTST;

B
Bernard Xiong 已提交
65
	rt_hw_interrupt_install(IRQ_TCU0, rt_hw_timer_handler, RT_NULL, "tick");
66
	rt_hw_interrupt_umask  (IRQ_TCU0);
B
bernard.xiong 已提交
67 68 69 70 71 72 73 74 75 76 77
}

/**
 * This function will initial sam7s64 board.
 */
void rt_hw_board_init()
{
#ifdef RT_USING_UART
	/* init hardware UART device */
	rt_hw_uart_init();
#endif
78

B
bernard.xiong 已提交
79 80 81 82
#ifdef RT_USING_CONSOLE
	/* set console device */
	rt_console_set_device("uart");
#endif
83 84 85

	/* init operating system timer */
	rt_hw_timer_init();
B
bernard.xiong 已提交
86 87
}
/*@}*/