board.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009 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. * 2006-03-24 Bernard first implementation
  13. * 2006-05-05 Bernard add DATA_COUNT definition
  14. * 2006-10-05 Alsor.Z for s3c2410x porting
  15. * 2007-11-20 Yi.Qiu add lcd,touch,console
  16. */
  17. #include <rtthread.h>
  18. #include <rthw.h>
  19. #include "board.h"
  20. #include "led.h"
  21. /**
  22. * @addtogroup mini2440
  23. */
  24. /*@{*/
  25. extern rt_uint32_t PCLK, FCLK, HCLK, UCLK;
  26. extern void rt_hw_clock_init(void);
  27. extern void rt_hw_mmu_init(void);
  28. extern void rt_hw_get_clock(void);
  29. extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn);
  30. extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv);
  31. #define UART0 ((struct uartport *)&U0BASE)
  32. struct serial_int_rx uart0_int_rx;
  33. struct serial_device uart0 =
  34. {
  35. UART0,
  36. &uart0_int_rx,
  37. RT_NULL
  38. };
  39. struct rt_device uart0_device;
  40. #define UART2 ((struct uartport *)&U2BASE)
  41. struct serial_int_rx uart2_int_rx;
  42. struct serial_device uart2 =
  43. {
  44. UART2,
  45. &uart2_int_rx,
  46. RT_NULL
  47. };
  48. struct rt_device uart2_device;
  49. /**
  50. * This function will handle rtos timer
  51. */
  52. static void rt_timer_handler(int vector, void *param)
  53. {
  54. rt_tick_increase();
  55. }
  56. /**
  57. * This function will handle serial
  58. */
  59. static void rt_serial0_handler(int vector, void *param)
  60. {
  61. INTSUBMSK |= (BIT_SUB_RXD0);
  62. rt_hw_serial_isr(&uart0_device);
  63. SUBSRCPND |= BIT_SUB_RXD0;
  64. /* Unmask sub interrupt (RXD0) */
  65. INTSUBMSK &=~(BIT_SUB_RXD0);
  66. }
  67. /**
  68. * This function will handle serial
  69. */
  70. static void rt_serial2_handler(int vector, void *param)
  71. {
  72. INTSUBMSK |= (BIT_SUB_RXD2);
  73. rt_hw_serial_isr(&uart2_device);
  74. SUBSRCPND |= BIT_SUB_RXD2;
  75. /* Unmask sub interrupt (RXD0) */
  76. INTSUBMSK &=~(BIT_SUB_RXD2);
  77. }
  78. /**
  79. * This function will handle init uart
  80. */
  81. static void rt_hw_uart_init(void)
  82. {
  83. int i;
  84. /* UART0 port configure */
  85. GPHCON |= 0xAA;
  86. /* PULLUP is disable */
  87. GPHUP |= 0xF;
  88. /* FIFO enable, Tx/Rx FIFO clear */
  89. uart0.uart_device->ufcon = 0x0;
  90. /* disable the flow control */
  91. uart0.uart_device->umcon = 0x0;
  92. /* Normal,No parity,1 stop,8 bit */
  93. uart0.uart_device->ulcon = 0x3;
  94. /*
  95. * tx=level,rx=edge,disable timeout int.,enable rx error int.,
  96. * normal,interrupt or polling
  97. */
  98. uart0.uart_device->ucon = 0x245;
  99. /* Set uart0 bps */
  100. uart0.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1;
  101. /* output PCLK to UART0/1, PWMTIMER */
  102. CLKCON |= 0x0D00;
  103. /* FIFO enable, Tx/Rx FIFO clear */
  104. uart2.uart_device->ufcon = 0x0;
  105. /* disable the flow control */
  106. uart2.uart_device->umcon = 0x0;
  107. /* Normal,No parity,1 stop,8 bit */
  108. uart2.uart_device->ulcon = 0x3;
  109. /*
  110. * tx=level,rx=edge,disable timeout int.,enable rx error int.,
  111. * normal,interrupt or polling
  112. */
  113. uart2.uart_device->ucon = 0x245;
  114. /* Set uart0 bps */
  115. uart2.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1;
  116. for (i = 0; i < 100; i++);
  117. /* install uart0 isr */
  118. INTSUBMSK &= ~(BIT_SUB_RXD0);
  119. /* install uart2 isr */
  120. INTSUBMSK &= ~(BIT_SUB_RXD2);
  121. rt_hw_interrupt_install(INTUART0, rt_serial0_handler, RT_NULL, "UART0");
  122. rt_hw_interrupt_umask(INTUART0);
  123. rt_hw_interrupt_install(INTUART2, rt_serial2_handler, RT_NULL, "UART2");
  124. rt_hw_interrupt_umask(INTUART2);
  125. }
  126. /**
  127. * This function will init timer4 for system ticks
  128. */
  129. static void rt_hw_timer_init(void)
  130. {
  131. /* timer4, pre = 15+1 */
  132. TCFG0 &= 0xffff00ff;
  133. TCFG0 |= 15 << 8;
  134. /* all are interrupt mode,set Timer 4 MUX 1/4 */
  135. TCFG1 &= 0xfff0ffff;
  136. TCFG1 |= 0x00010000;
  137. TCNTB4 = (rt_int32_t)(PCLK / (4 *16* RT_TICK_PER_SECOND)) - 1;
  138. /* manual update */
  139. TCON = TCON & (~(0x0f<<20)) | (0x02<<20);
  140. /* install interrupt handler */
  141. rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL, "tick");
  142. rt_hw_interrupt_umask(INTTIMER4);
  143. /* start timer4, reload */
  144. TCON = TCON & (~(0x0f<<20)) | (0x05<<20);
  145. }
  146. /**
  147. * This function will init s3ceb2410 board
  148. */
  149. void rt_hw_board_init(void)
  150. {
  151. /* initialize the system clock */
  152. rt_hw_clock_init();
  153. /* Get the clock */
  154. rt_hw_get_clock();
  155. /* initialize led port */
  156. rt_hw_led_init();
  157. /* initialize uart */
  158. rt_hw_uart_init();
  159. /* initialize mmu */
  160. rt_hw_mmu_init();
  161. /* initialize timer4 */
  162. rt_hw_timer_init();
  163. }
  164. /*@}*/