cpuport.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * File : cpuport.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2011, RT-Thread Development 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. * 2011-06-15 aozima the first version for lpc214x
  13. */
  14. #include <rtthread.h>
  15. #include "lpc214x.h"
  16. #define MAX_HANDLERS 32
  17. #define SVCMODE 0x13
  18. extern rt_uint32_t rt_interrupt_nest;
  19. /**
  20. * @addtogroup LPC214x
  21. */
  22. /*@{*/
  23. /**
  24. * This function will initialize thread stack
  25. *
  26. * @param tentry the entry of thread
  27. * @param parameter the parameter of entry
  28. * @param stack_addr the beginning stack address
  29. * @param texit the function will be called when thread exit
  30. *
  31. * @return stack address
  32. */
  33. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  34. rt_uint8_t *stack_addr, void *texit)
  35. {
  36. unsigned long *stk;
  37. stk = (unsigned long *)stack_addr;
  38. *(stk) = (unsigned long)tentry; /* entry point */
  39. *(--stk) = (unsigned long)texit; /* lr */
  40. *(--stk) = 0; /* r12 */
  41. *(--stk) = 0; /* r11 */
  42. *(--stk) = 0; /* r10 */
  43. *(--stk) = 0; /* r9 */
  44. *(--stk) = 0; /* r8 */
  45. *(--stk) = 0; /* r7 */
  46. *(--stk) = 0; /* r6 */
  47. *(--stk) = 0; /* r5 */
  48. *(--stk) = 0; /* r4 */
  49. *(--stk) = 0; /* r3 */
  50. *(--stk) = 0; /* r2 */
  51. *(--stk) = 0; /* r1 */
  52. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  53. *(--stk) = SVCMODE; /* cpsr */
  54. *(--stk) = SVCMODE; /* spsr */
  55. /* return task's current stack address */
  56. return (rt_uint8_t *)stk;
  57. }
  58. /* exception and interrupt handler table */
  59. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  60. rt_uint32_t rt_thread_switch_interrput_flag;
  61. void rt_hw_interrupt_handler(int vector)
  62. {
  63. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  64. }
  65. /**
  66. * This function will initialize hardware interrupt
  67. */
  68. void rt_hw_interrupt_init()
  69. {
  70. rt_base_t index;
  71. rt_uint32_t *vect_addr, *vect_ctl;
  72. /* initialize VIC*/
  73. VICIntEnClr = 0xffffffff;
  74. VICVectAddr = 0;
  75. /* set all to IRQ */
  76. VICIntSelect = 0;
  77. for (index = 0; index < MAX_HANDLERS; index ++)
  78. {
  79. vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + (index << 2));
  80. vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (index << 2));
  81. *vect_addr = (rt_uint32_t)rt_hw_interrupt_handler;
  82. *vect_ctl = 0xF;
  83. }
  84. /* init interrupt nest, and context in thread sp */
  85. rt_interrupt_nest = 0;
  86. rt_interrupt_from_thread = 0;
  87. rt_interrupt_to_thread = 0;
  88. rt_thread_switch_interrput_flag = 0;
  89. }
  90. /**
  91. * This function will mask a interrupt.
  92. * @param vector the interrupt number
  93. */
  94. void rt_hw_interrupt_mask(int vector)
  95. {
  96. VICIntEnClr = (1 << vector);
  97. }
  98. /**
  99. * This function will un-mask a interrupt.
  100. * @param vector the interrupt number
  101. */
  102. void rt_hw_interrupt_umask(int vector)
  103. {
  104. VICIntEnable = (1 << vector);
  105. }
  106. /**
  107. * This function will install a interrupt service routine to a interrupt.
  108. * @param vector the interrupt number
  109. * @param new_handler the interrupt service routine to be installed
  110. * @param old_handler the old interrupt service routine
  111. */
  112. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  113. {
  114. if(vector >= 0 && vector < MAX_HANDLERS)
  115. {
  116. /* get VIC address */
  117. rt_uint32_t* vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + (vector << 2));
  118. rt_uint32_t* vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (vector << 2));
  119. /* assign IRQ slot and enable this slot */
  120. *vect_ctl = 0x20 | (vector & 0x1F);
  121. if (old_handler != RT_NULL) *old_handler = (rt_isr_handler_t) *vect_addr;
  122. if (new_handler != RT_NULL) *vect_addr = (rt_uint32_t) new_handler;
  123. }
  124. }
  125. /**
  126. * this function will reset CPU
  127. *
  128. */
  129. void rt_hw_cpu_reset()
  130. {
  131. }
  132. /**
  133. * this function will shutdown CPU
  134. *
  135. */
  136. void rt_hw_cpu_shutdown()
  137. {
  138. rt_kprintf("shutdown...\n");
  139. while (1);
  140. }
  141. void rt_hw_trap_irq()
  142. {
  143. rt_isr_handler_t isr_func;
  144. isr_func = (rt_isr_handler_t) VICVectAddr;
  145. isr_func(0);
  146. /* acknowledge Interrupt */
  147. // VICVectAddr = 0;
  148. }
  149. void rt_hw_trap_fiq()
  150. {
  151. rt_kprintf("fast interrupt request\n");
  152. }
  153. /*@}*/