board.c 4.4 KB

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