board.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * 2008-12-11 xuxinming first version
  13. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include <LPC24xx.h>
  17. #include "board.h"
  18. /* #define RT_BOARD_DEBUG */
  19. #define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */
  20. /**
  21. * @addtogroup LPC2478
  22. */
  23. /*@{*/
  24. void rt_timer_handler(int vector)
  25. {
  26. #ifdef BOARD_DEBUG
  27. rt_kprintf("timer handler, increase a tick\n");
  28. #endif
  29. T0IR |= 0x01; /* clear interrupt flag */
  30. rt_tick_increase();
  31. VICVectAddr = 0; /* Acknowledge Interrupt */
  32. }
  33. /**
  34. * This function is used to display a string on console, normally, it's
  35. * invoked by rt_kprintf
  36. *
  37. * @param str the displayed string
  38. */
  39. void rt_hw_console_output(const char* str)
  40. {
  41. while (*str)
  42. {
  43. if (*str=='\n')
  44. {
  45. while (!(U0LSR & 0x20));
  46. U0THR = '\r';
  47. }
  48. while (!(U0LSR & 0x20));
  49. U0THR = *str;
  50. str ++;
  51. }
  52. }
  53. #define BAUD_RATE 115200
  54. #define U0PINS 0x50
  55. void rt_hw_console_init()
  56. {
  57. rt_uint32_t fdiv;
  58. /* Enable RxD and TxD pins */
  59. PINSEL0 = U0PINS;
  60. /* 8 bits, no Parity, 1 Stop bit */
  61. U0LCR = 0x83;
  62. /* Setup Baudrate */
  63. fdiv = ( PCLK / 16 ) / BAUD_RATE ; /*baud rate */
  64. U0DLM = fdiv / 256;
  65. U0DLL = fdiv % 256;
  66. U0FCR = 0x00; /* Enable and reset TX and RX FIFO. */
  67. U0LCR = 0x03; /* DLAB = 0 */
  68. /* DLAB = 0 */
  69. U0LCR = 0x03;
  70. }
  71. /**
  72. * This function will init LPC2478 board
  73. */
  74. void rt_hw_board_init()
  75. {
  76. /* init console for rt_kprintf function */
  77. rt_hw_console_init();
  78. T0IR = 0xff;
  79. T0TC = 0;
  80. T0MCR = 0x03;
  81. T0MR0 = (DATA_COUNT);
  82. rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL);
  83. rt_hw_interrupt_umask(TIMER0_INT);
  84. T0TCR = 0x01; //enable timer0 counter
  85. }
  86. /*@}*/