1 /* 2 * File : stack.c 3 * This file is part of RT-Thread RTOS 4 * COPYRIGHT (C) 2010, 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 * 2010-03-30 Kyle First version 13 */ 14 #include <rtthread.h> 15 16 /** 17 * @addtogroup AVR32UC3 18 */ 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 */ rt_hw_stack_init(void * tentry,void * parameter,rt_uint8_t * stack_addr,void * texit)31rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint8_t *stack_addr, void *texit) 32 { 33 unsigned long *stk; 34 35 stk = (unsigned long *)stack_addr; 36 *(stk) = 0; /* r8 */ 37 *(--stk) = 0; /* r9 */ 38 *(--stk) = 0; /* r10 */ 39 *(--stk) = 0; /* r11 */ 40 *(--stk) = 0; /* r12 */ 41 *(--stk) = (unsigned long)texit; /* lr */ 42 *(--stk) = (unsigned long)tentry; /* entry point, pc */ 43 *(--stk) = 0x00600000; /* sr */ 44 *(--stk) = 0; /* r0 */ 45 *(--stk) = 0; /* r1 */ 46 *(--stk) = 0; /* r2 */ 47 *(--stk) = 0; /* r3 */ 48 *(--stk) = 0; /* r4 */ 49 *(--stk) = 0; /* r5 */ 50 *(--stk) = 0; /* r6 */ 51 *(--stk) = 0; /* r7 */ 52 53 /* return task's current stack address */ 54 return (rt_uint8_t *)stk; 55 } 56 57 /*@}*/ 58