board.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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-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. /**
  21. * @addtogroup mini2440
  22. */
  23. /*@{*/
  24. extern rt_uint32_t PCLK, FCLK, HCLK, UCLK;
  25. extern rt_uint8_t asc16_font[];
  26. extern rt_uint16_t _rt_hw_framebuffer[];
  27. extern void rt_hw_lcd_init(void);
  28. extern void rt_hw_mmu_init(void);
  29. extern void rt_hw_touch_init(void);
  30. extern void rt_kbd_init(void);
  31. extern void rt_console_init(rt_uint8_t*, rt_uint8_t*, rt_uint8_t);
  32. extern void rt_hw_get_clock(void);
  33. extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn);
  34. extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv);
  35. static rt_uint32_t timer_load_val = 0;
  36. #define UART0 ((struct uartport *)U0BASE)
  37. struct serial_int_rx uart0_int_rx;
  38. struct serial_device uart0 =
  39. {
  40. UART0,
  41. &uart0_int_rx,
  42. RT_NULL
  43. };
  44. struct rt_device uart0_device;
  45. /**
  46. * This function will handle rtos timer
  47. */
  48. void rt_timer_handler(int vector)
  49. {
  50. /* reset TDATA0 */
  51. TCNTB4 = timer_load_val;
  52. rt_tick_increase();
  53. }
  54. /**
  55. * This function will handle serial
  56. */
  57. void rt_serial_handler(int vector)
  58. {
  59. INTSUBMSK |= (BIT_SUB_RXD0);
  60. rt_hw_serial_isr(&uart0_device);
  61. SUBSRCPND |= BIT_SUB_RXD0;
  62. /* Unmask sub interrupt (RXD0) */
  63. INTSUBMSK &=~(BIT_SUB_RXD0);
  64. }
  65. /**
  66. * This function will handle init uart
  67. */
  68. void rt_hw_uart_init(void)
  69. {
  70. int i;
  71. GPHCON |= 0xa0;
  72. /*PULLUP is enable */
  73. GPHUP |= 0x0c;
  74. /* FIFO enable, Tx/Rx FIFO clear */
  75. uart0.uart_device->ufcon = 0x1;
  76. /* disable the flow control */
  77. uart0.uart_device->umcon = 0x0;
  78. /* Normal,No parity,1 stop,8 bit */
  79. uart0.uart_device->ulcon = 0x3;
  80. /*
  81. * tx=level,rx=edge,disable timeout int.,enable rx error int.,
  82. * normal,interrupt or polling
  83. */
  84. uart0.uart_device->ucon = 0x245;
  85. /* output PCLK to UART0/1, PWMTIMER */
  86. CLKCON |= 0x0D00;
  87. for (i = 0; i < 100; i++);
  88. /* install uart isr */
  89. INTSUBMSK &= ~(BIT_SUB_RXD0);
  90. rt_hw_interrupt_install(INTUART0, rt_serial_handler, RT_NULL);
  91. rt_hw_interrupt_umask(INTUART0);
  92. }
  93. /**
  94. * This function will init s3ceb2410 board
  95. */
  96. void rt_hw_board_init()
  97. {
  98. /* FCLK = 304.8M */
  99. #define MDIV 68
  100. #define PDIV 1
  101. #define SDIV 1
  102. //rt_hw_set_clock(SDIV, PDIV, MDIV);
  103. /* HCLK = PCLK = FCLK */
  104. //rt_hw_set_dividor(0, 0);
  105. /* use PWM Timer 4 because it has no output */
  106. /* prescaler for Timer 4 is 16 */
  107. TCFG0 = 0x0f00;
  108. /* all divider = 1/2 */
  109. TCFG1 = 0x0;
  110. rt_hw_get_clock();
  111. if (timer_load_val == 0)
  112. {
  113. /*
  114. * for 10 ms clock period @ PCLK with 4 bit divider = 1/2
  115. * (default) and prescaler = 16. Should be 10390
  116. * @33.25MHz and 15625 @ 50 MHz
  117. */
  118. timer_load_val = PCLK/(2 * 16 * 100);
  119. }
  120. /* load value for 10 ms timeout */
  121. TCNTB4 = timer_load_val;
  122. /* auto load, manual update of Timer 4 */
  123. TCON = (TCON & ~0x0700000) | 0x600000;
  124. /* auto load, start Timer 4 */
  125. TCON = (TCON & ~0x0700000) | 0x500000 | 0x3;
  126. /*Enable NAND, USBD, PWM TImer, UART0,1 and GPIO clock,*/
  127. CLKCON = 0xfffff0;
  128. /* initialize uart */
  129. rt_hw_uart_init();
  130. /* initialize mmu */
  131. rt_hw_mmu_init();
  132. /* initialize console */
  133. //rt_console_init(&_rt_hw_framebuffer[0], &asc16_font[0], 2);
  134. #ifdef RT_USING_RTGUI
  135. rt_hw_touch_init();
  136. #endif
  137. /* install interrupt handler */
  138. rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL);
  139. rt_hw_interrupt_umask(INTTIMER4);
  140. /* stop timer */
  141. /* TCON = 0x0; */
  142. }
  143. /*@}*/