board.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2011 RT-Thread Develop 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. * 2011-02-24 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #include "mb9bf506r.h"
  18. #include "core_cm3.h"
  19. extern const uint32_t SystemFrequency;
  20. #define UART0 FM3_MFS0_UART
  21. struct serial_int_rx uart0_int_rx;
  22. struct serial_device uart0 =
  23. {
  24. UART0,
  25. &uart0_int_rx,
  26. RT_NULL
  27. };
  28. struct rt_device uart0_device;
  29. #define UART2 FM3_MFS2_UART
  30. struct serial_int_rx uart2_int_rx;
  31. struct serial_device uart2 =
  32. {
  33. UART2,
  34. &uart2_int_rx,
  35. RT_NULL
  36. };
  37. struct rt_device uart2_device;
  38. /**
  39. * @addtogroup FM3
  40. */
  41. /*@{*/
  42. /**
  43. * This is the timer interrupt service routine.
  44. *
  45. */
  46. void rt_hw_timer_handler(void)
  47. {
  48. /* enter interrupt */
  49. rt_interrupt_enter();
  50. rt_tick_increase();
  51. /* leave interrupt */
  52. rt_interrupt_leave();
  53. }
  54. void rt_hw_uart2_rx_handler(void)
  55. {
  56. #ifdef RT_USING_UART2
  57. extern struct rt_device uart2_device;
  58. extern void rt_hw_serial_isr(struct rt_device *device);
  59. /* enter interrupt */
  60. rt_interrupt_enter();
  61. rt_hw_serial_isr(&uart2_device);
  62. /* leave interrupt */
  63. rt_interrupt_leave();
  64. #endif
  65. }
  66. /**
  67. * This function will handle init uart
  68. */
  69. static void rt_hw_uart_init(void)
  70. {
  71. /* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
  72. FM3_GPIO->PFR2 = FM3_GPIO->PFR2 | 0x0030;
  73. FM3_GPIO->EPFR07 = FM3_GPIO->EPFR07 | 0x000a0000;
  74. uart2.uart_device->SMR = SMR_MD_UART | SMR_SOE;;
  75. uart2.uart_device->BGR = (40000000UL + (BPS/2))/BPS - 1;
  76. uart2.uart_device->ESCR = ESCR_DATABITS_8;
  77. uart2.uart_device->SCR = SCR_RXE | SCR_TXE | SCR_RIE;
  78. UART_ENABLE_IRQ(MFS2RX_IRQn);
  79. UART_ENABLE_IRQ(MFS2TX_IRQn);
  80. }
  81. /**
  82. * This function will initial FM3 Easy Kit board.
  83. */
  84. void rt_hw_board_init()
  85. {
  86. /* init systick */
  87. SysTick_Config(SystemFrequency/RT_TICK_PER_SECOND - 1);
  88. rt_hw_uart_init();
  89. }
  90. /*@}*/