board.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 rt_uint8_t asc16_font[];
  27. extern rt_uint16_t _rt_hw_framebuffer[];
  28. extern void rt_hw_clock_init(void);
  29. extern void rt_hw_lcd_init(void);
  30. extern void rt_hw_mmu_init(void);
  31. extern void rt_hw_touch_init(void);
  32. extern void rt_kbd_init(void);
  33. extern void rt_console_init(rt_uint8_t*, rt_uint8_t*, rt_uint8_t);
  34. extern void rt_hw_get_clock(void);
  35. extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn);
  36. extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv);
  37. #define UART0 ((struct uartport *)U0BASE)
  38. struct serial_int_rx uart0_int_rx;
  39. struct serial_device uart0 =
  40. {
  41. UART0,
  42. &uart0_int_rx,
  43. RT_NULL
  44. };
  45. struct rt_device uart0_device;
  46. /**
  47. * This function will handle rtos timer
  48. */
  49. void rt_timer_handler(int vector)
  50. {
  51. rt_tick_increase();
  52. }
  53. /**
  54. * This function will handle serial
  55. */
  56. void rt_serial_handler(int vector)
  57. {
  58. INTSUBMSK |= (BIT_SUB_RXD0);
  59. rt_hw_serial_isr(&uart0_device);
  60. SUBSRCPND |= BIT_SUB_RXD0;
  61. /* Unmask sub interrupt (RXD0) */
  62. INTSUBMSK &=~(BIT_SUB_RXD0);
  63. }
  64. /**
  65. * This function will handle init uart
  66. */
  67. void rt_hw_uart_init(void)
  68. {
  69. int i;
  70. /* UART0 port configure */
  71. GPHCON |= 0xAA;
  72. /* PULLUP is disable */
  73. GPHUP |= 0xF;
  74. /* FIFO enable, Tx/Rx FIFO clear */
  75. uart0.uart_device->ufcon = 0x0;
  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. /* Set uart0 bps */
  86. uart0.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1;
  87. /* output PCLK to UART0/1, PWMTIMER */
  88. CLKCON |= 0x0D00;
  89. for (i = 0; i < 100; i++);
  90. /* install uart isr */
  91. INTSUBMSK &= ~(BIT_SUB_RXD0);
  92. rt_hw_interrupt_install(INTUART0, rt_serial_handler, RT_NULL);
  93. rt_hw_interrupt_umask(INTUART0);
  94. }
  95. /**
  96. * This function will init timer4 for system ticks
  97. */
  98. void rt_hw_timer_init()
  99. {
  100. /* timer4, pre = 15+1 */
  101. TCFG0 &= 0xffff00ff;
  102. TCFG0 |= 15 << 8;
  103. /* all are interrupt mode,set Timer 4 MUX 1/4 */
  104. TCFG1 &= 0xfff0ffff;
  105. TCFG1 |= 0x00010000;
  106. TCNTB4 = (rt_int32_t)(PCLK / (4 *16* RT_TICK_PER_SECOND)) - 1;
  107. /* manual update */
  108. TCON = TCON & (~(0x0f<<20)) | (0x02<<20);
  109. /* install interrupt handler */
  110. rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL);
  111. rt_hw_interrupt_umask(INTTIMER4);
  112. /* start timer4, reload */
  113. TCON = TCON & (~(0x0f<<20)) | (0x05<<20);
  114. }
  115. /**
  116. * This function will init s3ceb2410 board
  117. */
  118. void rt_hw_board_init()
  119. {
  120. /* initialize the system clock */
  121. rt_hw_clock_init();
  122. /* Get the clock */
  123. rt_hw_get_clock();
  124. /* initialize led port */
  125. rt_hw_led_init();
  126. /* initialize uart */
  127. rt_hw_uart_init();
  128. /* initialize mmu */
  129. rt_hw_mmu_init();
  130. /* initialize timer4 */
  131. rt_hw_timer_init();
  132. }
  133. /*@}*/