bsp.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * File : bsp.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-04-09 fify the first version
  13. *
  14. * For : Renesas M16C
  15. * Toolchain : IAR's EW for M16C v3.401
  16. */
  17. #include "iom16c62p.h"
  18. #include "bsp.h"
  19. #include "rtconfig.h"
  20. void led_init(void)
  21. {
  22. PUR3.BIT.PU37 = 1;
  23. PD11.BIT.PD11_0 = 1;
  24. led_off();
  25. }
  26. void led_on(void)
  27. {
  28. P11.BIT.P11_0 = 0;
  29. }
  30. void led_off(void)
  31. {
  32. P11.BIT.P11_0 = 1;
  33. }
  34. static void mcu_init(void)
  35. {
  36. volatile rt_uint32_t count;
  37. /* Configure clock for divide by 1 mode */
  38. PRCR.BYTE |= 0x01; /* Enable access to clock registers PRCR.PRC0 = 1 */
  39. CM1.BYTE = 0x20; /* Set CM16, CM17 divide ratio to 1: */
  40. /* ... main clock on in high drive no PLL */
  41. CM0.BYTE &= ~0x40; /* Set divide ratio to 1 CM0.CM06 = 0 */
  42. /* Configure main PLL */
  43. PRCR.BYTE |= 0x02; /* Allow writing to processor mode register PRCR.PRC0 = 1 */
  44. PM2.BYTE |= 0x01; /* Set SFR access to 2 wait, which is required for */
  45. /* ... operation greater than 16 MHz PM2.PM20 = 1 */
  46. PRCR.BYTE &= ~0x02; /* Protect processor mode register PRCR.PRC0 = 0 */
  47. PLC0.BYTE = 0x91; /* Enable and turn on PLL */
  48. count = 20000; /* Delay while PLL stabilizes */
  49. while (count > 0) {
  50. count--;
  51. }
  52. CM1.BYTE |= 0x02; /* Switch to PLL CM1.CM11 = 1 */
  53. PRCR.BYTE &= ~0x01; /* Protect clock control register PRCR.PRC0 = 0 */
  54. PRCR.BYTE |= 0x02; /* Allow writing to processor mode register PRCR.PRC0 = 1 */
  55. PM1.BYTE |= 0x01; /* Enable data flash area PM1.PM10 = 1 */
  56. PRCR.BYTE &= ~0x02; /* Protect processor mode register PRCR.PRC0 = 0 */
  57. }
  58. /*
  59. *********************************************************************************************************
  60. * TICKER INITIALIZATION
  61. *
  62. * Description : This function is called to initialize rt-thread's tick source (typically a timer generating
  63. * interrupts every 1 to 100 mS).
  64. *
  65. * We decided to use Timer #B0 as the tick interrupt source.
  66. *
  67. * Arguments : none
  68. *
  69. * Returns :
  70. *
  71. * Notes : (1) Timer B channel 0 is setup as a periodic timer, generating an interrupt
  72. * OS_TICKS_PER_SEC times per second. The timer counts down and generates an interrupt
  73. * when it underflows.
  74. *
  75. * (2) The timer ISR handler, rt_hw_timer_handler(), is placed into the vector table in vectors.s34.
  76. *********************************************************************************************************
  77. */
  78. static void timer_tick_init(void)
  79. {
  80. /* Set timer to timer mode */
  81. /* Set count source as PLL clock / 8 (f8) */
  82. TB0MR.BYTE = 0x40;
  83. /* Assign timer value and reload value */
  84. TB0 = (CPU_CLK_FREQ / 8) / RT_TICK_PER_SECOND;
  85. /* Set timer B channel 0 interrupt level = 7 */
  86. /* Clear interrupt request */
  87. TB0IC.BYTE = 0x07;
  88. TABSR.BYTE |= 0x20; /* Start timer */
  89. }
  90. void system_init(void)
  91. {
  92. mcu_init();
  93. led_init(); /* Initialize the I/Os for the LED controls */
  94. timer_tick_init(); /* Initialize the rt-thread tick interrupt */
  95. }