board.c 1.8 KB

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