bsp.c 5.0 KB
Newer Older
D
dzzxzz 已提交
1 2 3 4 5 6 7 8 9 10 11
/*
 * File      : bsp.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2009, RT-Thread Development 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
12
 * 2010-04-09     fify         the first version
D
dzzxzz 已提交
13 14 15
 *
 * For       : Renesas M16C
 * Toolchain : IAR's EW for M16C v3.401
16
 */
D
dzzxzz 已提交
17 18 19 20 21 22 23

#include "iom16c62p.h"
#include "bsp.h"
#include "rtconfig.h"

void led_init(void)
{
24 25
    PUR3.BIT.PU37 = 1;
    PD11.BIT.PD11_0 = 1;
D
dzzxzz 已提交
26 27 28 29 30 31

    led_off();
}

void led_on(void)
{
32
    P11.BIT.P11_0 = 0;
D
dzzxzz 已提交
33 34 35 36
}

void led_off(void)
{
37
    P11.BIT.P11_0 = 1;
D
dzzxzz 已提交
38 39 40 41 42 43
}

static void mcu_init(void)
{
	volatile  rt_uint32_t  count;
	                                                            /* Configure clock for divide by 1 mode                     */
44 45
	PRCR.BYTE      |= 0x01;                                     /* Enable access to clock registers           PRCR.PRC0 = 1 */
	CM1.BYTE             = 0x20;                                     /* Set CM16, CM17 divide ratio to 1:                        */
D
dzzxzz 已提交
46
									                            /*  ... main clock on in high drive no PLL                  */
47
	CM0.BYTE            &= ~0x40;                                    /* Set divide ratio to 1                      CM0.CM06  = 0 */			
D
dzzxzz 已提交
48 49

                                                                /* Configure main PLL                                       */
50 51
	PRCR.BYTE           |= 0x02;                                     /* Allow writing to processor mode register   PRCR.PRC0 = 1 */
	PM2.BYTE            |= 0x01;                                     /* Set SFR access to 2 wait, which is required for          */
D
dzzxzz 已提交
52
   									                            /*  ... operation greater than 16 MHz         PM2.PM20  = 1 */
53 54
	PRCR.BYTE           &= ~0x02;                                    /* Protect processor mode register            PRCR.PRC0 = 0 */
	PLC0.BYTE            = 0x91;                                     /* Enable and turn on PLL                                   */
D
dzzxzz 已提交
55 56 57 58 59 60

    count           = 20000;                                    /* Delay while PLL stabilizes                               */
	while (count > 0) {
        count--;
    }

61 62
    CM1.BYTE            |= 0x02;                                     /* Switch to PLL                              CM1.CM11  = 1 */
    PRCR.BYTE           &= ~0x01;                                    /* Protect clock control register             PRCR.PRC0 = 0 */
D
dzzxzz 已提交
63
	
64 65 66
	PRCR.BYTE           |= 0x02;                                     /* Allow writing to processor mode register   PRCR.PRC0 = 1 */
	PM1.BYTE            |= 0x01;                                     /* Enable data flash area                     PM1.PM10  = 1 */
	PRCR.BYTE           &= ~0x02;                                    /* Protect processor mode register            PRCR.PRC0 = 0 */
D
dzzxzz 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
}

/*
*********************************************************************************************************
*                                         TICKER INITIALIZATION
*
* Description : This function is called to initialize rt-thread's tick source (typically a timer generating
*               interrupts every 1 to 100 mS).
*
*               We decided to use Timer #B0 as the tick interrupt source.
*
* Arguments   : none
*
* Returns     :
*
* Notes       : (1) Timer B channel 0 is setup as a periodic timer, generating an interrupt
*                   OS_TICKS_PER_SEC times per second.  The timer counts down and generates an interrupt
*                   when it underflows.
*
*               (2) The timer ISR handler, rt_hw_timer_handler(), is placed into the vector table in vectors.s34.
*********************************************************************************************************
*/

static void timer_tick_init(void)
{
	                                                            /* Set timer to timer mode                                  */
                                                                /* Set count source as PLL clock / 8 (f8)                   */
94
	TB0MR.BYTE = 0x40;
D
dzzxzz 已提交
95
                                                                /* Assign timer value and reload value                      */
96
	TB0        = (CPU_CLK_FREQ / 8) / RT_TICK_PER_SECOND;
D
dzzxzz 已提交
97 98
	                                                            /* Set timer B channel 0 interrupt level = 7                */
	                                                            /* Clear interrupt request                                  */
99 100
    TB0IC.BYTE = 0x07;
	TABSR.BYTE |= 0x20;                             /* Start timer                                              */
D
dzzxzz 已提交
101 102 103 104 105 106 107 108
}

void system_init(void)
{
    mcu_init();
    led_init();                                                 /* Initialize the I/Os for the LED controls                 */
    timer_tick_init();                                          /* Initialize the rt-thread tick interrupt                   */
}