board.c 3.4 KB

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