board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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-08-23 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "lpc214x.h"
  17. #include "board.h"
  18. /**
  19. * @addtogroup LPC2148
  20. */
  21. /*@{*/
  22. /**
  23. * This is the timer interrupt service routine.
  24. * @param vector the irq number for timer
  25. */
  26. void rt_hw_timer_handler(int vector, void *param)
  27. {
  28. rt_tick_increase();
  29. /* clear interrupt flag */
  30. T0IR |= 0x01;
  31. /* acknowledge Interrupt */
  32. VICVectAddr = 0;
  33. }
  34. /**
  35. * This function is used to display a string on console, normally, it's
  36. * invoked by rt_kprintf
  37. *
  38. * @param str the displayed string
  39. */
  40. void rt_hw_console_output(const char* str)
  41. {
  42. while (*str)
  43. {
  44. if (*str=='\n')
  45. {
  46. while (!(U0LSR & 0x20));
  47. U0THR = '\r';
  48. }
  49. while (!(U0LSR & 0x20));
  50. U0THR = *str;
  51. str ++;
  52. }
  53. }
  54. #define BAUD_RATE 115200
  55. #define U0PINS 0x05
  56. void rt_hw_console_init()
  57. {
  58. /* Enable RxD and TxD pins */
  59. PINSEL0 = U0PINS;
  60. /* 8 bits, no Parity, 1 Stop bit */
  61. U0LCR = 0x83;
  62. /* Setup Baudrate */
  63. U0DLL = (PCLK/16/BAUD_RATE) & 0xFF;
  64. U0DLM = ((PCLK/16/BAUD_RATE) >> 8) & 0xFF;
  65. /* DLAB = 0 */
  66. U0LCR = 0x03;
  67. }
  68. /**
  69. * This function will initial sam7x256 board.
  70. */
  71. void rt_hw_board_init(void)
  72. {
  73. /* console init */
  74. rt_hw_console_init();
  75. /* prescaler = 0*/
  76. T0PR = 0;
  77. T0PC = 0;
  78. /* reset and enable MR0 interrupt */
  79. T0MCR = 0x3;
  80. T0MR0 = PCLK / RT_TICK_PER_SECOND;
  81. /* enable timer 0 */
  82. T0TCR = 1;
  83. /* install timer handler */
  84. rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL, "TIMER0");
  85. rt_hw_interrupt_umask(TIMER0_INT);
  86. }
  87. /*@}*/