amobbs.com 阿莫电子技术论坛

标题: 移植ucos2 到 STMF4 支持浮点,一点心得 [打印本页]

作者: njwjn66    时间: 2012-2-11 20:45
标题: 移植ucos2 到 STMF4 支持浮点,一点心得
以前都是现成移植好的UCOS拿来就用,这次研究stm32f4,就想自己移植一下,以前就大概知道点原理,这次自己动手才知道原来懂得少了,移植过程中找到这份资料,其中这幅图对于移植还是比较有用~~~就是M4下使用FPU的堆栈模式图:

stm32f4  cortex-m4 with fpu stack model (原文件名:stm32 堆栈模式.jpg)

移植好的代码还要测试下稳定性,就暂时不上传了
作者: i55x    时间: 2012-2-11 21:08
官网有K60的port,拿来直接就能在STM32F4上面跑,何苦自己移植呢?
作者: clingos    时间: 2012-2-12 15:16
k60的port好象也没浮点寄存器保存!
作者: i55x    时间: 2012-2-12 15:32
回复【2楼】clingos
k60的port好象也没浮点寄存器保存!
-----------------------------------------------------------------------

现下了2.92/k60/iar6.1的port,果然没有保存浮点寄存器,micrium这个大骗子!
作者: zf8848    时间: 2012-2-12 17:18
ucos 中要保存浮点,建议看看 ucos-iii
作者: clingos    时间: 2012-2-13 12:38
回复【4楼】zf8848  
-----------------------------------------------------------------------

micrium好像目前还没有推出M4的相关ports!
作者: lileistone    时间: 2012-2-13 16:13
回复【3楼】i55x
回复【2楼】clingos  
k60的port好象也没浮点寄存器保存!
-----------------------------------------------------------------------
现下了2.92/k60/iar6.1的port,果然没有保存浮点寄存器,micrium这个大骗子!
-----------------------------------------------------------------------

K60不是所有型号都有浮点单元的,早期的MK60DN512之类就是整数机器,那个TOWER-K60N512就是用的这个。
后期MK6xFNxxx的才是有浮点的
作者: i55x    时间: 2012-2-13 17:03
回复【6楼】lileistone 三块石头
回复【3楼】i55x  
回复【2楼】clingos   
k60的port好象也没浮点寄存器保存!  
-----------------------------------------------------------------------  
现下了2.92/k60/iar6.1的port,果然没有保存浮点寄存器,micrium这个大骗子!
-----------------------------------------------------------------------
k60不是所有型号都有浮点单元的,早期的mk60dn512之类就是整数机器,那个tower-k60n512就是用的这个。
后期mk6xfnxxx的才是有浮点的
-----------------------------------------------------------------------

没浮点单元的不就是M3嘛?为啥FreeScale舔着脸说是M4?
作者: adce    时间: 2012-2-14 09:28
FreeRTOS保留了
__asm void xPortPendSVHandler( void )
{
        extern uxCriticalNesting;
        extern pxCurrentTCB;
        extern vTaskSwitchContext;

        PRESERVE8

        mrs r0, psp                                               
       
        /* Get the location of the current TCB. */
        ldr        r3, =pxCurrentTCB                       
        ldr        r2, [r3]                                               

        /* Is the task using the FPU context?  If so, push high vfp registers. */
        tst r14, #0x10
        it eq
        vstmdbeq r0!, {s16-s31}

        /* Save the core registers. */
        stmdb r0!, {r4-r11, r14}                               
....


其实不保留也有道理....有硬件整数除法速度已经不错了....
真正能用到浮点的是DSP运算....
2个线程都用DSP运算的需求很难想象......

错主要是错在KEIL的优化上...
作者: ganker    时间: 2012-7-18 16:47
这个怎么没有人讨论下去了。我觉得写一下移植的细节很有意义
作者: mfkiwl    时间: 2012-7-19 05:13
看了LZ的博文,顶一下
作者: GNMXD    时间: 2012-7-19 07:54
看看。。。
作者: kaoyanfor2010    时间: 2013-2-19 08:34
很好的工作,有意义,只有自己走一遍才能学得更好
作者: 20061002838    时间: 2013-2-19 12:24
i55x 发表于 2012-2-13 17:03 回复【6楼】lileistone 三块石头 回复【3楼】i55x 回复【2楼】clingos

M4的浮点单元本身就是可选的。
作者: ZWzw007aa    时间: 2013-4-12 17:23
ganker 发表于 2012-7-18 16:47
这个怎么没有人讨论下去了。我觉得写一下移植的细节很有意义

是啊   移植修改了哪些地方 这才是重点啊  
作者: ganker    时间: 2013-4-12 18:49
参考TI的Richard Ma 版本 http://www.deyisupport.com/question_answer/f/57/t/8798.aspx 根据这个我已经完成了带FPU的移植了。
作者: roguebear2012    时间: 2013-4-25 15:35
        while(1)
        {
                c = 0;
                s1 = 0.12;
                s2 = 0.099;
                for(i = 0; i < 100000; i++)
                {
                        c += s1*s2;
                        s1 += 0.0000002f;
                }



                OSTimeDly((OS_TICK)1,(OS_OPT)OS_OPT_TIME_DLY,&err);        //1S
                if(err != OS_ERR_NONE)
                {
                        return;
                }



任务切换就进入hardfault





;
;********************************************************************************************************
;                                                uC/OS-III
;                                          The Real-Time Kernel
;
;
;                              (c) Copyright 2010; Micrium, Inc.; Weston, FL
;                    All rights reserved.  Protected by international copyright laws.
;
;                                           ARM Cortex-M4 Port
;
; File      : OS_CPU_A.ASM
; Version   : V3.01.2
; By        : JJL
;             BAN
;
; For       : ARMv7 Cortex-M4
; Mode      : Thumb-2 ISA
; Toolchain : RealView Development Suite
;             RealView Microcontroller Development Kit (MDK)
;             ARM Developer Suite (ADS)
;             Keil uVision
;********************************************************************************************************
;

;********************************************************************************************************
;                                          PUBLIC FUNCTIONS
;********************************************************************************************************

    IMPORT  OSRunning                                           ; External references
    IMPORT  OSPrioCur
    IMPORT  OSPrioHighRdy
    IMPORT  OSTCBCurPtr
    IMPORT  OSTCBHighRdyPtr
    IMPORT  OSIntExit
    IMPORT  OSTaskSwHook
    IMPORT  OS_CPU_ExceptStkBase


    EXPORT  OSStartHighRdy                                      ; Functions declared in this file
    EXPORT  OSCtxSw
    EXPORT  OSIntCtxSw
    EXPORT  PendSV_Handler

;PAGE
;********************************************************************************************************
;                                               EQUATES
;********************************************************************************************************

NVIC_INT_CTRL   EQU     0xE000ED04                              ; Interrupt control state register.
NVIC_SYSPRI14   EQU     0xE000ED22                              ; System priority register (priority 14).
NVIC_PENDSV_PRI EQU           0xFF                              ; PendSV priority value (lowest).
NVIC_PENDSVSET  EQU     0x10000000                              ; Value to trigger PendSV exception.


;********************************************************************************************************
;                                     CODE GENERATION DIRECTIVES
;********************************************************************************************************

    PRESERVE8
    THUMB

    AREA CODE, CODE, READONLY


;PAGE
;********************************************************************************************************
;                                         START MULTITASKING
;                                      void OSStartHighRdy(void)
;
; Note(s) : 1) This function triggers a PendSV exception (essentially, causes a context switch) to cause
;              the first task to start.
;
;           2) OSStartHighRdy() MUST:
;              a) Setup PendSV exception priority to lowest;
;              b) Set initial PSP to 0, to tell context switcher this is first run;
;              c) Set the main stack to OS_CPU_ExceptStkBase
;              d) Trigger PendSV exception;
;              e) Enable interrupts (tasks will run with interrupts enabled).
;********************************************************************************************************

OSStartHighRdy
    LDR     R0, =NVIC_SYSPRI14                                  ; Set the PendSV exception priority
    LDR     R1, =NVIC_PENDSV_PRI
    STRB    R1, [R0]

    MOVS    R0, #0                                              ; Set the PSP to 0 for initial context switch call
    MSR     PSP, R0

    LDR     R0, =OS_CPU_ExceptStkBase                           ; Initialize the MSP to the OS_CPU_ExceptStkBase
    LDR     R1, [R0]
    MSR     MSP, R1   

    LDR     R0, =NVIC_INT_CTRL                                  ; Trigger the PendSV exception (causes context switch)
    LDR     R1, =NVIC_PENDSVSET
    STR     R1, [R0]
   
    CPSIE   I                                                   ; Enable interrupts at processor level

OSStartHang
    B       OSStartHang                                         ; Should never get here


;PAGE
;********************************************************************************************************
;                       PERFORM A CONTEXT SWITCH (From task level) - OSCtxSw()
;
; Note(s) : 1) OSCtxSw() is called when OS wants to perform a task context switch.  This function
;              triggers the PendSV exception which is where the real work is done.
;********************************************************************************************************

OSCtxSw
    LDR     R0, =NVIC_INT_CTRL                                  ; Trigger the PendSV exception (causes context switch)
    LDR     R1, =NVIC_PENDSVSET
    STR     R1, [R0]
    BX      LR


;PAGE
;********************************************************************************************************
;                   PERFORM A CONTEXT SWITCH (From interrupt level) - OSIntCtxSw()
;
; Note(s) : 1) OSIntCtxSw() is called by OSIntExit() when it determines a context switch is needed as
;              the result of an interrupt.  This function simply triggers a PendSV exception which will
;              be handled when there are no more interrupts active and interrupts are enabled.
;********************************************************************************************************

OSIntCtxSw
    LDR     R0, =NVIC_INT_CTRL                                  ; Trigger the PendSV exception (causes context switch)
    LDR     R1, =NVIC_PENDSVSET
    STR     R1, [R0]
    BX      LR


;PAGE
;********************************************************************************************************
;                                       HANDLE PendSV EXCEPTION
;                                   void OS_CPU_PendSVHandler(void)
;
; Note(s) : 1) PendSV is used to cause a context switch.  This is a recommended method for performing
;              context switches with Cortex-M3.  This is because the Cortex-M3 auto-saves half of the
;              processor context on any exception, and restores same on return from exception.  So only
;              saving of R4-R11 is required and fixing up the stack pointers.  Using the PendSV exception
;              this way means that context saving and restoring is identical whether it is initiated from
;              a thread or occurs due to an interrupt or exception.
;
;           2) Pseudo-code is:
;              a) Get the process SP, if 0 then skip (goto d) the saving part (first context switch);
;              b) Save remaining regs r4-r11 on process stack;
;              c) Save the process SP in its TCB, OSTCBCurPtr->OSTCBStkPtr = SP;
;              d) Call OSTaskSwHook();
;              e) Get current high priority, OSPrioCur = OSPrioHighRdy;
;              f) Get current ready thread TCB, OSTCBCurPtr = OSTCBHighRdyPtr;
;              g) Get new process SP from TCB, SP = OSTCBHighRdyPtr->OSTCBStkPtr;
;              h) Restore R4-R11 from new process stack;
;              i) Perform exception return which will restore remaining context.
;
;           3) On entry into PendSV handler:
;              a) The following have been saved on the process stack (by processor):
;                 xPSR, PC, LR, R12, R0-R3
;              b) Processor mode is switched to Handler mode (from Thread mode)
;              c) Stack is Main stack (switched from Process stack)
;              d) OSTCBCurPtr      points to the OS_TCB of the task to suspend
;                 OSTCBHighRdyPtr  points to the OS_TCB of the task to resume
;
;           4) Since PendSV is set to lowest priority in the system (by OSStartHighRdy() above), we
;              know that it will only be run when no other exception or interrupt is active, and
;              therefore safe to assume that context being switched out was using the process stack (PSP).
;********************************************************************************************************

PendSV_Handler
    CPSID   I                                                   ; Prevent interruption during context switch
    MRS     R0, PSP                                             ; PSP is process stack pointer
    CBZ     R0, OS_CPU_PendSVHandler_nosave                     ; Skip register save the first time
   
        ;Is the task using the FPU context? If so, push high vfp registers.
        tst r14, #0x10
        it eq
        vstmdbeq r0!, {s16-s31}



    SUBS    R0, R0, #0x20                                       ; Save remaining regs r4-11 on process stack
    STM     R0, {R4-R11}

    LDR     R1, =OSTCBCurPtr                                    ; OSTCBCurPtr->OSTCBStkPtr = SP;
    LDR     R1, [R1]
    STR     R0, [R1]                                            ; R0 is SP of process being switched out

                                                                ; At this point, entire context of process has been saved
OS_CPU_PendSVHandler_nosave
    PUSH    {R14}                                               ; Save LR exc_return value
    LDR     R0, =OSTaskSwHook                                   ; OSTaskSwHook();
    BLX     R0
    POP     {R14}

    LDR     R0, =OSPrioCur                                      ; OSPrioCur   = OSPrioHighRdy;
    LDR     R1, =OSPrioHighRdy
    LDRB    R2, [R1]
    STRB    R2, [R0]

    LDR     R0, =OSTCBCurPtr                                    ; OSTCBCurPtr = OSTCBHighRdyPtr;
    LDR     R1, =OSTCBHighRdyPtr
    LDR     R2, [R1]
    STR     R2, [R0]

    LDR     R0, [R2]                                            ; R0 is new process SP; SP = OSTCBHighRdyPtr->StkPtr;
    LDM     R0, {R4-R11}                                        ; Restore r4-11 from new process stack
    ADDS    R0, R0, #0x20
   
   
        ;Is the task using the FPU context? If so, pop the high vfp registers too.
        tst r14, #0x10
        it eq
        vldmiaeq r0!, {s16-s31}



   
    MSR     PSP, R0                                             ; Load PSP with new process SP
    ORR     LR, LR, #0x04                                       ; Ensure exception return uses process stack
    CPSIE   I
    BX      LR                                                  ; Exception return will restore remaining context

    END












/*
*********************************************************************************************************
*                                                uC/OS-III
*                                          The Real-Time Kernel
*
*
*                           (c) Copyright 2009-2010; Micrium, Inc.; Weston, FL
*                    All rights reserved.  Protected by international copyright laws.
*
*                                           ARM Cortex-M4 Port
*
* File      : OS_CPU_C.C
* Version   : V3.01.2
* By        : JJL
*             BAN
*
* LICENSING TERMS:
* ---------------
*           uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or
*           for peaceful research.  If you plan or intend to use uC/OS-III in a commercial application/
*           product then, you need to contact Micrium to properly license uC/OS-III for its use in your
*           application/product.   We provide ALL the source code for your convenience and to help you
*           experience uC/OS-III.  The fact that the source is provided does NOT mean that you can use
*           it commercially without paying a licensing fee.
*
*           Knowledge of the source code may NOT be used to develop a similar product.
*
*           Please help us continue to provide the embedded community with the finest software available.
*           Your honesty is greatly appreciated.
*
*           You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036.
*
* For       : ARMv7 Cortex-M4
* Mode      : Thumb-2 ISA
* Toolchain : RealView
*********************************************************************************************************
*/

#define   OS_CPU_GLOBALS

#ifdef VSC_INCLUDE_SOURCE_FILE_NAMES
const  CPU_CHAR  *os_cpu_c__c = "$Id: $";
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#include  <os.h>

/*
*********************************************************************************************************
*                                           IDLE TASK HOOK
*
* Description: This function is called by the idle task.  This hook has been added to allow you to do
*              such things as STOP the CPU to conserve power.
*
* Arguments  : None.
*
* Note(s)    : None.
*********************************************************************************************************
*/

void  OSIdleTaskHook (void)
{
#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppIdleTaskHookPtr != (OS_APP_HOOK_VOID)0) {
        (*OS_AppIdleTaskHookPtr)();
    }
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments  : None.
*
* Note(s)    : None.
*********************************************************************************************************
*/

void  OSInitHook (void)
{
                                                                    /* 8-byte align the ISR stack.                            */   
    OS_CPU_ExceptStkBase = (CPU_STK *)(OSCfg_ISRStkBasePtr + OSCfg_ISRStkSize);
    OS_CPU_ExceptStkBase = (CPU_STK *)((CPU_STK)(OS_CPU_ExceptStkBase) & 0xFFFFFFF8);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                         STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-III's statistics task.  This allows your
*              application to add functionality to the statistics task.
*
* Arguments  : None.
*
* Note(s)    : None.
*********************************************************************************************************
*/

void  OSStatTaskHook (void)
{
#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppStatTaskHookPtr != (OS_APP_HOOK_VOID)0) {
        (*OS_AppStatTaskHookPtr)();
    }
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                          TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments  : p_tcb        Pointer to the task control block of the task being created.
*
* Note(s)    : None.
*********************************************************************************************************
*/

void  OSTaskCreateHook (OS_TCB  *p_tcb)
{
#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppTaskCreateHookPtr != (OS_APP_HOOK_TCB)0) {
        (*OS_AppTaskCreateHookPtr)(p_tcb);
    }
#else
    (void)p_tcb;                                            /* Prevent compiler warning                               */
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                           TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments  : p_tcb        Pointer to the task control block of the task being deleted.
*
* Note(s)    : None.
*********************************************************************************************************
*/

void  OSTaskDelHook (OS_TCB  *p_tcb)
{
#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppTaskDelHookPtr != (OS_APP_HOOK_TCB)0) {
        (*OS_AppTaskDelHookPtr)(p_tcb);
    }
#else
    (void)p_tcb;                                            /* Prevent compiler warning                               */
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                            TASK RETURN HOOK
*
* Description: This function is called if a task accidentally returns.  In other words, a task should
*              either be an infinite loop or delete itself when done.
*
* Arguments  : p_tcb        Pointer to the task control block of the task that is returning.
*
* Note(s)    : None.
*********************************************************************************************************
*/

void  OSTaskReturnHook (OS_TCB  *p_tcb)
{
#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppTaskReturnHookPtr != (OS_APP_HOOK_TCB)0) {
        (*OS_AppTaskReturnHookPtr)(p_tcb);
    }
#else
    (void)p_tcb;                                            /* Prevent compiler warning                               */
#endif
}


/*$PAGE*/
/*
**********************************************************************************************************
*                                       INITIALIZE A TASK'S STACK
*
* Description: This function is called by OS_Task_Create() or OSTaskCreateExt() to initialize the stack
*              frame of the task being created. This function is highly processor specific.
*
* Arguments  : p_task       Pointer to the task entry point address.
*
*              p_arg        Pointer to a user supplied data area that will be passed to the task
*                               when the task first executes.
*
*              p_stk_base   Pointer to the base address of the stack.
*
*              stk_size     Size of the stack, in number of CPU_STK elements.
*
*              opt          Options used to alter the behavior of OS_Task_StkInit().
*                            (see OS.H for OS_TASK_OPT_xxx).
*
* Returns    : Always returns the location of the new top-of-stack' once the processor registers have
*              been placed on the stack in the proper order.
*
* Note(s)    : 1) Interrupts are enabled when task starts executing.
*
*              2) All tasks run in Thread mode, using process stack.
**********************************************************************************************************
*/

CPU_STK  *OSTaskStkInit (OS_TASK_PTR    p_task,
                         void          *p_arg,
                         CPU_STK       *p_stk_base,
                         CPU_STK       *p_stk_limit,
                         CPU_STK_SIZE   stk_size,
                         OS_OPT         opt)
{
    CPU_STK  *p_stk;


    (void)opt;                                              /* Prevent compiler warning                               */

    p_stk = &p_stk_base[stk_size];                          /* Load stack pointer                                     */
                                                                /* Align the stack to 8-bytes.                            */
    p_stk = (CPU_STK *)((CPU_STK)(p_stk) & 0xFFFFFFF8);
                                                            /* Registers stacked as if auto-saved on exception        */
       
       
       
       
                #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
                *--p_stk = (CPU_STK)0x00000000u;                        /* No Name Register                         */
                *--p_stk = (CPU_STK)0x00001000L; //FPSCR
                *--p_stk = (CPU_STK)0x00000015L; //s15
                *--p_stk = (CPU_STK)0x00000014L; //s14
                *--p_stk = (CPU_STK)0x00000013L; //s13
                *--p_stk = (CPU_STK)0x00000012L; //s12
                *--p_stk = (CPU_STK)0x00000011L; //s11
                *--p_stk = (CPU_STK)0x00000010L; //s10
                *--p_stk = (CPU_STK)0x00000009L; //s9
                *--p_stk = (CPU_STK)0x00000008L; //s8
                *--p_stk = (CPU_STK)0x00000007L; //s7
                *--p_stk = (CPU_STK)0x00000006L; //s6
                *--p_stk = (CPU_STK)0x00000005L; //s5
                *--p_stk = (CPU_STK)0x00000004L; //s4
                *--p_stk = (CPU_STK)0x00000003L; //s3
                *--p_stk = (CPU_STK)0x00000002L; //s2
                *--p_stk = (CPU_STK)0x00000001L; //s1
                *--p_stk = (CPU_STK)0x00000000L; //s0       
                #endif
       
       
       
       
       
       
       
       
       
    *--p_stk = (CPU_STK)0x01000000u;                        /* xPSR                                                   */
    *--p_stk = (CPU_STK)p_task;                             /* Entry Point                                            */
    *--p_stk = (CPU_STK)OS_TaskReturn;                      /* R14 (LR)                                               */
    *--p_stk = (CPU_STK)0x12121212u;                        /* R12                                                    */
    *--p_stk = (CPU_STK)0x03030303u;                        /* R3                                                     */
    *--p_stk = (CPU_STK)0x02020202u;                        /* R2                                                     */
    *--p_stk = (CPU_STK)p_stk_limit;                        /* R1                                                     */
    *--p_stk = (CPU_STK)p_arg;                              /* R0 : argument                                          */
                                                            /* Remaining registers saved on process stack             */
                                                                                                                                                                                                                                               
                #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    *--p_stk = (CPU_STK)0x31313131u;                        /* S31                                                    */
    *--p_stk = (CPU_STK)0x30303030u;                        /* S30                                                    */
    *--p_stk = (CPU_STK)0x29292929u;                        /* S29                                                    */
    *--p_stk = (CPU_STK)0x28282828u;                        /* S28                                                    */
    *--p_stk = (CPU_STK)0x27272727u;                        /* S27                                                    */
    *--p_stk = (CPU_STK)0x26262626u;                        /* S26                                                    */
    *--p_stk = (CPU_STK)0x25252525u;                        /* S25                                                    */
    *--p_stk = (CPU_STK)0x24242424u;                        /* S24                                                    */
    *--p_stk = (CPU_STK)0x23232323u;                        /* S23                                                    */
    *--p_stk = (CPU_STK)0x22222222u;                        /* S22                                                    */
    *--p_stk = (CPU_STK)0x21212121u;                        /* S21                                                    */
    *--p_stk = (CPU_STK)0x20202020u;                        /* S20                                                    */
    *--p_stk = (CPU_STK)0x19191919u;                        /* S19                                                    */
    *--p_stk = (CPU_STK)0x18181818u;                        /* S18                                                    */
    *--p_stk = (CPU_STK)0x17171717u;                        /* S17                                                    */
    *--p_stk = (CPU_STK)0x16161616u;                        /* S16                                                    */
    #endif                                                                                                                                                                                                                                               



    *--p_stk = (CPU_STK)0x11111111u;                        /* R11                                                    */
    *--p_stk = (CPU_STK)0x10101010u;                        /* R10                                                    */
    *--p_stk = (CPU_STK)0x09090909u;                        /* R9                                                     */
    *--p_stk = (CPU_STK)0x08080808u;                        /* R8                                                     */
    *--p_stk = (CPU_STK)0x07070707u;                        /* R7                                                     */
    *--p_stk = (CPU_STK)0x06060606u;                        /* R6                                                     */
    *--p_stk = (CPU_STK)0x05050505u;                        /* R5                                                     */
    *--p_stk = (CPU_STK)0x04040404u;                        /* R4                                                     */

    return (p_stk);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This allows you to perform other
*              operations during a context switch.
*
* Arguments  : None.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdyPtr' points to the TCB of the task
*                 that will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCurPtr' points
*                 to the task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/

void  OSTaskSwHook (void)
{
#if OS_CFG_TASK_PROFILE_EN > 0u
    CPU_TS  ts;
#endif
#ifdef  CPU_CFG_INT_DIS_MEAS_EN
    CPU_TS  int_dis_time;
#endif



#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppTaskSwHookPtr != (OS_APP_HOOK_VOID)0) {
        (*OS_AppTaskSwHookPtr)();
    }
#endif

#if OS_CFG_TASK_PROFILE_EN > 0u
    ts = OS_TS_GET();
    if (OSTCBCurPtr != OSTCBHighRdyPtr) {
        OSTCBCurPtr->CyclesDelta  = ts - OSTCBCurPtr->CyclesStart;
        OSTCBCurPtr->CyclesTotal += (OS_CYCLES)OSTCBCurPtr->CyclesDelta;
    }

    OSTCBHighRdyPtr->CyclesStart = ts;
#endif

#ifdef  CPU_CFG_INT_DIS_MEAS_EN
    int_dis_time = CPU_IntDisMeasMaxCurReset();             /* Keep track of per-task interrupt disable time          */
    if (OSTCBCurPtr->IntDisTimeMax < int_dis_time) {
        OSTCBCurPtr->IntDisTimeMax = int_dis_time;
    }
#endif

#if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u
                                                            /* Keep track of per-task scheduler lock time             */
    if (OSTCBCurPtr->SchedLockTimeMax < OSSchedLockTimeMaxCur) {
        OSTCBCurPtr->SchedLockTimeMax = OSSchedLockTimeMaxCur;
    }
    OSSchedLockTimeMaxCur = (CPU_TS)0;                      /* Reset the per-task value                               */
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                              TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments  : None.
*
* Note(s)    : 1) This function is assumed to be called from the Tick ISR.
*********************************************************************************************************
*/

void  OSTimeTickHook (void)
{
#if OS_CFG_APP_HOOKS_EN > 0u
    if (OS_AppTimeTickHookPtr != (OS_APP_HOOK_VOID)0) {
        (*OS_AppTimeTickHookPtr)();
    }
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                          SYS TICK HANDLER
*
* Description: Handle the system tick (SysTick) interrupt, which is used to generate the uC/OS-II tick
*              interrupt.
*
* Arguments  : None.
*
* Note(s)    : 1) This function MUST be placed on entry 15 of the Cortex-M3 vector table.
*********************************************************************************************************
*/

void  OS_CPU_SysTickHandler (void)
{
    CPU_SR_ALLOC();


    CPU_CRITICAL_ENTER();
    OSIntNestingCtr++;                                      /* Tell uC/OS-III that we are starting an ISR             */
    CPU_CRITICAL_EXIT();

    OSTimeTick();                                           /* Call uC/OS-III's OSTimeTick()                          */

    OSIntExit();                                            /* Tell uC/OS-III that we are leaving the ISR             */
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                         INITIALIZE SYS TICK
*
* Description: Initialize the SysTick.
*
* Arguments  : cnts         Number of SysTick counts between two OS tick interrupts.
*
* Note(s)    : 1) This function MUST be called after OSStart() & after processor initialization.
*********************************************************************************************************
*/

void  OS_CPU_SysTickInit (CPU_INT32U  cnts)
{
    CPU_INT32U  prio;


    CPU_REG_NVIC_ST_RELOAD = cnts - 1u;

                                                            /* Set SysTick handler prio.                              */
    prio                   = CPU_REG_NVIC_SHPRI3;
    prio                  &= DEF_BIT_FIELD(24, 0);
    prio                  |= DEF_BIT_MASK(OS_CPU_CFG_SYSTICK_PRIO, 24);

    CPU_REG_NVIC_SHPRI3    = prio;

                                                            /* Enable timer.                                          */
    CPU_REG_NVIC_ST_CTRL  |= CPU_REG_NVIC_ST_CTRL_CLKSOURCE |
                             CPU_REG_NVIC_ST_CTRL_ENABLE;
                                                            /* Enable timer interrupt.                                */
    CPU_REG_NVIC_ST_CTRL  |= CPU_REG_NVIC_ST_CTRL_TICKINT;
}


作者: c382671878    时间: 2013-7-17 16:42
roguebear2012 发表于 2013-4-25 15:35
while(1)
        {
                c = 0;

你的问题解决了么?我也遇到了
作者: jisaowang    时间: 2013-7-17 17:34
只要你的程序选项里打开了浮点,就需要保存浮点寄存器。不论这个线程是不是用了浮点。。。keil的编译器会用浮点寄存器来改善整数程序可能的溅出所造成的性能损失。。。。
作者: hongyancl    时间: 2014-3-21 16:03
roguebear2012 发表于 2013-4-25 15:35
while(1)
        {
                c = 0;

你在http://www.amobbs.com/thread-5400648-1-1.html这个帖子里提到的问题解决了吗?我现在也碰到了同样的情况。
作者: Eric2013    时间: 2014-3-21 16:23
hongyancl 发表于 2014-3-21 16:03
你在http://www.amobbs.com/thread-5400648-1-1.html这个帖子里提到的问题解决了吗?我现在也碰到了同样 ...

这个问题好解决,前几天已经被我完全攻克。此方案在 MDK4.54、4.73、5.10以及IAR6.3、6.7上面测试均通过。
地址
[attach]177690[/attach]
作者: roguebear2012    时间: 2014-3-25 10:32
Eric2013 发表于 2014-3-21 16:23
这个问题好解决,前几天已经被我完全攻克。此方案在 MDK4.54、4.73、5.10以及IAR6.3、6.7上面测试均通过 ...

看了 改了 非常好。   另外 里面的ucosview 3.03 那个非常好 。。。 能否在坛子里提供下? 我现在都是开堆栈开很大 没优化
作者: kalo425    时间: 2014-3-25 21:50
支持流弊 的 龙猫``
作者: hpdell    时间: 2015-8-24 16:31
Eric2013 发表于 2014-3-21 16:23
这个问题好解决,前几天已经被我完全攻克。此方案在 MDK4.54、4.73、5.10以及IAR6.3、6.7上面测试均通过 ...

你好,请问 你这个资料能否发上来共享一下啊 ??




欢迎光临 amobbs.com 阿莫电子技术论坛 (https://www.amobbs.com/) Powered by Discuz! X3.4