board.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2010-11-13 weety first version
  23. */
  24. #include <rtthread.h>
  25. #include <rthw.h>
  26. #include <mmu.h>
  27. #include "board.h"
  28. /**
  29. * @addtogroup dm365
  30. */
  31. /*@{*/
  32. extern void rt_hw_clock_init(void);
  33. extern void rt_hw_uart_init(void);
  34. static struct mem_desc dm365_mem_desc[] = {
  35. { 0x80000000, 0x88000000-1, 0x80000000, SECT_RW_CB, 0, SECT_MAPPED }, /* 128M cached SDRAM memory */
  36. { 0xA0000000, 0xA8000000-1, 0x80000000, SECT_RW_NCNB, 0, SECT_MAPPED }, /* 128M No cached SDRAM memory */
  37. { 0xFFFF0000, 0xFFFF1000-1, 0x80000000, SECT_TO_PAGE, PAGE_RO_CB, PAGE_MAPPED }, /* isr vector table */
  38. { 0x01C00000, 0x02000000-1, 0x01C00000, SECT_RW_NCNB, 0, SECT_MAPPED }, /* CFG BUS peripherals */
  39. { 0x02000000, 0x0A000000-1, 0x02000000, SECT_RW_NCNB, 0, SECT_MAPPED }, /* AEMIF */
  40. };
  41. /**
  42. * This function will handle rtos timer
  43. */
  44. void rt_timer_handler(int vector, void *param)
  45. {
  46. rt_tick_increase();
  47. }
  48. /**
  49. * This function will init timer0 for system ticks
  50. */
  51. void rt_hw_timer_init()
  52. {
  53. /* timer0, input clocks 24MHz */
  54. volatile timer_regs_t *regs =
  55. (volatile timer_regs_t*)DAVINCI_TIMER1_BASE;//DAVINCI_TIMER0_BASE;
  56. /*disable timer*/
  57. regs->tcr &= ~(0x3UL << 6);
  58. //TIMMODE 32BIT UNCHAINED MODE
  59. regs->tgcr |=(0x1UL << 2);
  60. /*not in reset timer */
  61. regs->tgcr |= (0x1UL << 0);
  62. //regs->tgcr &= ~(0x1UL << 1);
  63. /* set Period Registers */
  64. regs->prd12 = 24000000/RT_TICK_PER_SECOND;
  65. regs->tim12 = 0;
  66. /* Set enable mode */
  67. regs->tcr |= (0x2UL << 6); //period mode
  68. /* install interrupt handler */
  69. rt_hw_interrupt_install(IRQ_DM365_TINT2, rt_timer_handler,
  70. RT_NULL, "timer1_12");//IRQ_DM365_TINT0_TINT12
  71. rt_hw_interrupt_umask(IRQ_DM365_TINT2);//IRQ_DM365_TINT2
  72. }
  73. /**
  74. * This function will init dm365 board
  75. */
  76. void rt_hw_board_init()
  77. {
  78. psc_change_state(DAVINCI_DM365_LPSC_TIMER0, 3);
  79. psc_change_state(DAVINCI_DM365_LPSC_TIMER1, 3);
  80. /* initialize the system clock */
  81. //rt_hw_clock_init();
  82. davinci_clk_init();
  83. /* initialize uart */
  84. rt_hw_uart_init();
  85. #ifdef RT_USING_CONSOLE
  86. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  87. #endif
  88. /* initialize mmu */
  89. rt_hw_mmu_init(dm365_mem_desc, sizeof(dm365_mem_desc)/sizeof(dm365_mem_desc[0]));
  90. /* initialize timer0 */
  91. rt_hw_timer_init();
  92. }
  93. /*@}*/