board.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * 2011-02-14 aozima first implementation for Nios II.
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdio.h>
  13. #include "system.h"
  14. #include "sys/alt_irq.h"
  15. #include "altera_avalon_timer_regs.h"
  16. #include "uart.h"
  17. extern int alt_irq_register (alt_u32 id,
  18. void* context,
  19. void (*alt_isr_func)(void* isr_context, alt_u32 id) );
  20. /**
  21. * @addtogroup NIOS_II
  22. */
  23. /*@{*/
  24. /**
  25. * This is the timer interrupt service routine.
  26. *
  27. */
  28. void rt_hw_timer_handler(void * context,unsigned long id)
  29. {
  30. void* base = (void*)TIMER_BASE;
  31. /* clear the interrupt */
  32. IOWR_ALTERA_AVALON_TIMER_STATUS (base, 0);
  33. /* enter interrupt */
  34. rt_interrupt_enter();
  35. rt_tick_increase();
  36. /* leave interrupt */
  37. rt_interrupt_leave();
  38. }
  39. void sysTick_config(void)
  40. {
  41. void* base = (void*)TIMER_BASE;
  42. IOWR_ALTERA_AVALON_TIMER_CONTROL (base,
  43. ALTERA_AVALON_TIMER_CONTROL_ITO_MSK |
  44. ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
  45. ALTERA_AVALON_TIMER_CONTROL_START_MSK);
  46. alt_irq_register (TIMER_IRQ, NULL, rt_hw_timer_handler);
  47. }
  48. static void rt_hw_show_info(void)
  49. {
  50. rt_kprintf("\r\n\r\n---------- board info ----------\r\n");
  51. rt_kprintf("ALT_DEVICE_FAMILY: %s\r\n",ALT_DEVICE_FAMILY);
  52. rt_kprintf("ALT_CPU_ARCHITECTURE: %s\r\n",ALT_CPU_ARCHITECTURE);
  53. rt_kprintf("ALT_CPU_CPU_FREQ: %uMHz\r\n",ALT_CPU_CPU_FREQ/1000000UL);
  54. rt_kprintf("memory size: at 0x%08X 0x%08X byte\r\n",SDRAM_BASE,SDRAM_SPAN);
  55. }
  56. void rt_hw_board_init(void)
  57. {
  58. rt_hw_uart_init();
  59. rt_console_set_device("uart");
  60. rt_hw_show_info();
  61. sysTick_config();
  62. }
  63. /*@}*/