stack.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * File : stack.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. * 2006-08-23 Bernard the first version
  13. * 2010-02-04 Magicoe Edit for LPC17xx Series
  14. * 2011-08-06 Magicoe Manded for PK40X256VLQ100
  15. */
  16. #include <rtthread.h>
  17. /**
  18. * @addtogroup PK40X256VLQ100
  19. */
  20. /*@{*/
  21. /**
  22. * This function will initialize thread stack
  23. *
  24. * @param tentry the entry of thread
  25. * @param parameter the parameter of entry
  26. * @param stack_addr the beginning stack address
  27. * @param texit the function will be called when thread exit
  28. *
  29. * @return stack address
  30. */
  31. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  32. rt_uint8_t *stack_addr, void *texit)
  33. {
  34. unsigned long *stk;
  35. stk = (unsigned long *)stack_addr;
  36. *(stk) = 0x01000000L; /* PSR */
  37. *(--stk) = (unsigned long)tentry; /* entry point, pc */
  38. *(--stk) = (unsigned long)texit; /* lr */
  39. *(--stk) = 0; /* r12 */
  40. *(--stk) = 0; /* r3 */
  41. *(--stk) = 0; /* r2 */
  42. *(--stk) = 0; /* r1 */
  43. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  44. *(--stk) = 0; /* r11 */
  45. *(--stk) = 0; /* r10 */
  46. *(--stk) = 0; /* r9 */
  47. *(--stk) = 0; /* r8 */
  48. *(--stk) = 0; /* r7 */
  49. *(--stk) = 0; /* r6 */
  50. *(--stk) = 0; /* r5 */
  51. *(--stk) = 0; /* r4 */
  52. /* return task's current stack address */
  53. return (rt_uint8_t *)stk;
  54. }
  55. /*@}*/