board.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-08-23 Bernard first implementation
  13. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include <sep4020.h>
  17. #include "board.h"
  18. #include "serial.h"
  19. /**
  20. * @addtogroup sep4020
  21. */
  22. /*@{*/
  23. extern rt_uint32_t rt_hw_get_clock(void);
  24. /* uart0 */
  25. #define UART0 ((struct uartport *)UART0BASE)
  26. struct serial_int_rx uart0_int_rx;
  27. struct serial_device uart0 =
  28. {
  29. UART0,
  30. &uart0_int_rx,
  31. RT_NULL
  32. };
  33. struct rt_device uart0_device;
  34. /**
  35. * This is the timer interrupt service routine.
  36. * @param vector the irq number for timer
  37. */
  38. void rt_hw_timer_handler(int vector)
  39. {
  40. /* clear interrupt */
  41. TIMER_T1ISCR;
  42. /* increase a tick */
  43. rt_tick_increase();
  44. }
  45. /**
  46. * This is the uart0 interrupt service routine.
  47. * @param vector the irq number for uart0
  48. */
  49. void rt_serial_handler(int vector)
  50. {
  51. rt_hw_serial_isr(&uart0_device);
  52. }
  53. /**
  54. * This function will handle init uart.
  55. */
  56. void rt_hw_uart_init(void)
  57. {
  58. rt_uint32_t baud;
  59. rt_uint32_t sysclock;
  60. sysclock = rt_hw_get_clock();
  61. /* caculate baud rate register */
  62. baud = sysclock/16/BR;
  63. /* LCR */
  64. uart0.uart_device->lcr = 0x83;
  65. /* DLBH, IER */
  66. uart0.uart_device->dlbh_ier = (baud>>8)&0xff;;
  67. /* DLBL */
  68. uart0.uart_device->dlbl_rxfifo_txfifo = baud&0xff;
  69. /* LCR */
  70. uart0.uart_device->lcr = 0x03;
  71. /* IER */
  72. uart0.uart_device->dlbh_ier = 0x01;
  73. /* FCR */
  74. uart0.uart_device->iir_fcr = 0x00;
  75. rt_hw_serial_register(&uart0_device, "uart0",
  76. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
  77. &uart0);
  78. /* install uart isr */
  79. INTC_IER |= (1<<INT_UART0);
  80. rt_hw_interrupt_install(INT_UART0, rt_serial_handler, RT_NULL);
  81. rt_hw_interrupt_umask(INT_UART0);
  82. }
  83. /**
  84. * This function will init led on the board
  85. */
  86. static void rt_hw_board_led_init(void)
  87. {
  88. /* PE3 PE4 PE5 for led */
  89. GPIO_PORTE_SEL |=0x38; /* GPIO */
  90. GPIO_PORTE_DIR &= ~0x38; /* output*/
  91. GPIO_PORTE_DATA &= ~0x38; /* low */
  92. }
  93. /**
  94. * This function will init timer1 for system ticks
  95. */
  96. static void rt_hw_timer_init(void)
  97. {
  98. TIMER_T1CR = 0x06; /* reload mode and interrupt enable */
  99. TIMER_T1LCR = 0xAFC80; /* 10ms under 72MHz 0xAFC80=720000 */
  100. INTC_IER |= (1<<INT_TIMER1); /* interrupt enable */
  101. rt_hw_interrupt_install(INT_TIMER1, rt_hw_timer_handler, RT_NULL);
  102. rt_hw_interrupt_umask(INT_TIMER1);
  103. TIMER_T1CR |= 0x01; /* enable the timer 1 */
  104. }
  105. /**
  106. * This function will initial sam7x board.
  107. */
  108. void rt_hw_board_init()
  109. {
  110. /* init hardware uart */
  111. rt_hw_uart_init();
  112. rt_console_set_device("uart0");
  113. /* init led */
  114. rt_hw_board_led_init();
  115. /* init timer for tick */
  116. rt_hw_timer_init();
  117. }
  118. /*@}*/