board.c 1.9 KB

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