bsp.c 4.8 KB

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