1
0

stack.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-08-23 Bernard the first version
  13. */
  14. #include <rtthread.h>
  15. /**
  16. * @addtogroup STM32
  17. */
  18. /*@{*/
  19. /**
  20. * This function will initialize thread stack
  21. *
  22. * @param tentry the entry of thread
  23. * @param parameter the parameter of entry
  24. * @param stack_addr the beginning stack address
  25. * @param texit the function will be called when thread exit
  26. *
  27. * @return stack address
  28. */
  29. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  30. rt_uint8_t *stack_addr, void *texit)
  31. {
  32. unsigned long *stk;
  33. stk = (unsigned long *)stack_addr;
  34. *(stk) = 0x01000000L; /* PSR */
  35. *(--stk) = (unsigned long)tentry; /* entry point, pc */
  36. *(--stk) = (unsigned long)texit; /* lr */
  37. *(--stk) = 0; /* r12 */
  38. *(--stk) = 0; /* r3 */
  39. *(--stk) = 0; /* r2 */
  40. *(--stk) = 0; /* r1 */
  41. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  42. *(--stk) = 0; /* r11 */
  43. *(--stk) = 0; /* r10 */
  44. *(--stk) = 0; /* r9 */
  45. *(--stk) = 0; /* r8 */
  46. *(--stk) = 0; /* r7 */
  47. *(--stk) = 0; /* r6 */
  48. *(--stk) = 0; /* r5 */
  49. *(--stk) = 0; /* r4 */
  50. /* return task's current stack address */
  51. return (rt_uint8_t *)stk;
  52. }
  53. /*@}*/