board.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. */
  9. #include <rthw.h>
  10. #include <rtthread.h>
  11. #include "board.h"
  12. #include "uart.h"
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. #include "r_pdl_cgc.h"
  16. /* General RPDL function definitions */
  17. #include "r_pdl_definitions.h"
  18. #include "intrinsics.h"
  19. #include "iorx62n.h"
  20. /**
  21. * This is the timer interrupt service routine.
  22. *
  23. */
  24. #pragma vector = VECT_CMT0_CMI0
  25. __interrupt
  26. void SysTick_Handler(void)
  27. {
  28. // __enable_interrupt();
  29. /* enter interrupt */
  30. rt_interrupt_enter();
  31. rt_tick_increase();
  32. /* leave interrupt */
  33. rt_interrupt_leave();
  34. }
  35. void rt_hw_systick_init(void)
  36. {
  37. /* Enable compare match timer 0. */
  38. MSTP( CMT0 ) = 0;
  39. /* Interrupt on compare match. */
  40. CMT0.CMCR.BIT.CMIE = 1;
  41. /* Set the compare match value. */
  42. CMT0.CMCOR = ( unsigned short ) (((XTAL_FREQUENCY * PCLK_MUL) / RT_TICK_PER_SECOND)/8 -1);
  43. /* Divide the PCLK by 128. */
  44. CMT0.CMCR.BIT.CKS = 0;
  45. /* Enable the interrupt... */
  46. _IEN( _CMT0_CMI0 ) = 1;
  47. /* ...and set its priority to the application defined kernel priority. */
  48. _IPR( _CMT0_CMI0 ) = 4;
  49. /* Start the timer. */
  50. CMT.CMSTR0.BIT.STR0 = 1;
  51. }
  52. void rt_hw_system_freq_init(void)
  53. {
  54. /* Declare error flag */
  55. bool err = true;
  56. /* Modify the MCU clocks, all are based off Epson 12 MHz clock */
  57. err &= R_CGC_Set
  58. (
  59. 12E6,
  60. 96E6,
  61. 48E6,
  62. 24E6,
  63. PDL_NO_DATA
  64. );
  65. /*
  66. Clock Description Frequency
  67. ----------------------------------------
  68. Input Clock Frequency..............12MHz
  69. Internal Clock Frequency...........96MHz
  70. Peripheral Clock Frequency.........48MHz
  71. External Bus Clock Frequency.......24MHz */
  72. /* Halt in while loop when RPDL errors detected */
  73. while (!err);
  74. }
  75. /**
  76. * This function will initial rx62n board
  77. */
  78. void rt_hw_board_init()
  79. {
  80. rt_hw_system_freq_init();
  81. rt_hw_systick_init();
  82. rt_hw_uart_init();
  83. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  84. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  85. #endif
  86. }