stack.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /******************************************************************//**
  2. * @file stack.c
  3. * @brief This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. * @author Bernard, onelife
  6. * @version 0.4 beta
  7. **********************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file LICENSE in this
  10. * distribution or at http://www.rt-thread.org/license/LICENSE
  11. **********************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2006-08-23 Bernard first version
  15. * 2011-02-14 onelife Modify for EFM32
  16. *********************************************************************/
  17. /******************************************************************//**
  18. * @addtogroup cortex-m3
  19. * @{
  20. *********************************************************************/
  21. /* Includes -------------------------------------------------------------------*/
  22. #include <rtthread.h>
  23. /* Private typedef -------------------------------------------------------------*/
  24. /* Private define --------------------------------------------------------------*/
  25. /* Private macro --------------------------------------------------------------*/
  26. /* Private variables ------------------------------------------------------------*/
  27. /* Private function prototypes ---------------------------------------------------*/
  28. /* Private functions ------------------------------------------------------------*/
  29. /**
  30. * This function will initialize thread stack
  31. *
  32. * @param tentry the entry of thread
  33. * @param parameter the parameter of entry
  34. * @param stack_addr the beginning stack address
  35. * @param texit the function will be called when thread exit
  36. *
  37. * @return stack address
  38. */
  39. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  40. rt_uint8_t *stack_addr, void *texit)
  41. {
  42. unsigned long *stk;
  43. stk = (unsigned long *)stack_addr;
  44. *(stk) = 0x01000000L; /* PSR */
  45. *(--stk) = (unsigned long)tentry; /* entry point, pc */
  46. *(--stk) = (unsigned long)texit; /* lr */
  47. *(--stk) = 0; /* r12 */
  48. *(--stk) = 0; /* r3 */
  49. *(--stk) = 0; /* r2 */
  50. *(--stk) = 0; /* r1 */
  51. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  52. *(--stk) = 0; /* r11 */
  53. *(--stk) = 0; /* r10 */
  54. *(--stk) = 0; /* r9 */
  55. *(--stk) = 0; /* r8 */
  56. *(--stk) = 0; /* r7 */
  57. *(--stk) = 0; /* r6 */
  58. *(--stk) = 0; /* r5 */
  59. *(--stk) = 0; /* r4 */
  60. /* return task's current stack address */
  61. return (rt_uint8_t *)stk;
  62. }
  63. /******************************************************************//**
  64. * @}
  65. *********************************************************************/