board.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 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. * 2009-01-05 Bernard first implementation
  13. * 2013-07-12 aozima update for auto initial.
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "nds32.h"
  18. #include "bsp_hal.h"
  19. #include "ae210p.h"
  20. #include "debug.h"
  21. //#include "uart/uart.h"
  22. #include "uart_dev.h"
  23. #include "board.h"
  24. #include "rtconfig.h"
  25. /**
  26. * This is the timer interrupt service routine.
  27. *
  28. */
  29. void SysTick_Handler(void)
  30. {
  31. /* clean timer device pending*/
  32. hal_timer_irq_clear(1);
  33. /* enter interrupt */
  34. rt_interrupt_enter();
  35. rt_tick_increase();
  36. /* leave interrupt */
  37. rt_interrupt_leave();
  38. }
  39. /***********************************************************
  40. * Set timer 1 as system tick by default
  41. ***********************************************************/
  42. void BSP_Tmr_TickInit(uint32_t tmrId, uint32_t period, uint32_t vecId, void *isr)
  43. {
  44. /* set tick period */
  45. hal_timer_set_period(tmrId, period);
  46. /* enable timer1 interrupt */
  47. hal_timer_irq_control(tmrId, 1);
  48. /******************************
  49. * tick ISR init
  50. ******************************/
  51. /* init trigger mode */
  52. /* Set edge trigger, falling edge */
  53. hal_intc_irq_config(vecId, 1, 0);
  54. /* clean pending */
  55. hal_intc_irq_clean(vecId);
  56. /* enable timer interrupt */
  57. hal_intc_irq_enable(vecId);
  58. if (isr)
  59. OS_CPU_Vector_Table[vecId] = isr;
  60. else
  61. DEBUG(1, 1, "Invalid tick handler!!\r\n");
  62. /* start timer */
  63. hal_timer_start(tmrId);
  64. }
  65. /*
  66. * Setup system tick for OS required.
  67. */
  68. void bsp_init(void)
  69. {
  70. /* disable interrupt first */
  71. rt_hw_interrupt_disable();
  72. // drv_uart_init();
  73. rt_hw_usart_init();
  74. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  75. /* System tick init */
  76. BSP_Tmr_TickInit(0x1, (MB_PCLK / RT_TICK_PER_SECOND), IRQ_SYS_TICK_VECTOR, SysTick_Handler);
  77. }
  78. /*@}*/