cpuport.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * File : cpu.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, 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. * 2009-01-05 Bernard first version
  13. * 2010-02-04 Magicoe Edit for LPC17xx Series
  14. * 2011-10-14 aozima merge all of C source code into cpuport.c
  15. */
  16. #include <rtthread.h>
  17. /**
  18. * @addtogroup LPC17xx
  19. */
  20. /*@{*/
  21. struct stack_contex
  22. {
  23. rt_uint32_t r0;
  24. rt_uint32_t r1;
  25. rt_uint32_t r2;
  26. rt_uint32_t r3;
  27. rt_uint32_t r12;
  28. rt_uint32_t lr;
  29. rt_uint32_t pc;
  30. rt_uint32_t psr;
  31. };
  32. /* exception and interrupt handler table */
  33. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  34. rt_uint32_t rt_thread_switch_interrupt_flag;
  35. /**
  36. * This function will initialize thread stack
  37. *
  38. * @param tentry the entry of thread
  39. * @param parameter the parameter of entry
  40. * @param stack_addr the beginning stack address
  41. * @param texit the function will be called when thread exit
  42. *
  43. * @return stack address
  44. */
  45. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  46. rt_uint8_t *stack_addr, void *texit)
  47. {
  48. unsigned long *stk;
  49. stk = (unsigned long *)stack_addr;
  50. *(stk) = 0x01000000L; /* PSR */
  51. *(--stk) = (unsigned long)tentry; /* entry point, pc */
  52. *(--stk) = (unsigned long)texit; /* lr */
  53. *(--stk) = 0; /* r12 */
  54. *(--stk) = 0; /* r3 */
  55. *(--stk) = 0; /* r2 */
  56. *(--stk) = 0; /* r1 */
  57. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  58. *(--stk) = 0; /* r11 */
  59. *(--stk) = 0; /* r10 */
  60. *(--stk) = 0; /* r9 */
  61. *(--stk) = 0; /* r8 */
  62. *(--stk) = 0; /* r7 */
  63. *(--stk) = 0; /* r6 */
  64. *(--stk) = 0; /* r5 */
  65. *(--stk) = 0; /* r4 */
  66. /* return task's current stack address */
  67. return (rt_uint8_t *)stk;
  68. }
  69. extern void list_thread(void);
  70. extern rt_thread_t rt_current_thread;
  71. void rt_hw_hard_fault_exception(struct stack_contex* contex)
  72. {
  73. rt_kprintf("psr: 0x%08x\n", contex->psr);
  74. rt_kprintf(" pc: 0x%08x\n", contex->pc);
  75. rt_kprintf(" lr: 0x%08x\n", contex->lr);
  76. rt_kprintf("r12: 0x%08x\n", contex->r12);
  77. rt_kprintf("r03: 0x%08x\n", contex->r3);
  78. rt_kprintf("r02: 0x%08x\n", contex->r2);
  79. rt_kprintf("r01: 0x%08x\n", contex->r1);
  80. rt_kprintf("r00: 0x%08x\n", contex->r0);
  81. rt_kprintf("hard fault on thread: %s\n", rt_current_thread->name);
  82. #ifdef RT_USING_FINSH
  83. list_thread();
  84. #endif
  85. while (1);
  86. }
  87. /*@}*/