kdgepei 发表于 2010-4-9 21:52:55

uC/OS-ii 移植到Atmeg128 编译环境为ICCV7 编译通过但是不能正常运行

下面是所有的代码,uC/OS移植好几天了,移植一直都不成功,哪位大侠给分析下,谢谢。
所有的代码ourdev_545050.rar(文件大小:281K) (原文件名:myOS.rar)

ba_wang_mao 发表于 2010-4-12 11:24:27

移植函数有问题.

   
   ;********************************************************************************************************
;                                             uC/OS-II
;                                       The Real-Time Kernel
;
;                                       ATmega128Specific code
;
;
; File   : OS_CPU_A.S
; By       : Ole Saether
;            Jean J. Labrosse
;********************************************************************************************************
;                                           I/O PORT ADDRESSES
;********************************************************************************************************

BIT00   = 0x01
BIT01   = 0x02
BIT02   = 0x04
BIT03   = 0x08
BIT04   = 0x10
BIT05   = 0x20
BIT06   = 0x40
BIT07   = 0x80

SREG    = 0x3F
SPH   = 0x3E
SPL   = 0x3D
RAMPZ   = 0x3B

;********************************************************************************************************
;                                       MACROS
;********************************************************************************************************

                .macroPUSH_ALL                            ; Save all registers
                ST      -Y,R0
                ST      -Y,R1
                ST      -Y,R2
                ST      -Y,R3
                ST      -Y,R4
                ST      -Y,R5
                ST      -Y,R6
                ST      -Y,R7
                ST      -Y,R8
                ST      -Y,R9
                ST      -Y,R10
                ST      -Y,R11
                ST      -Y,R12
                ST      -Y,R13
                ST      -Y,R14
                ST      -Y,R15
                ST      -Y,R16
                ST      -Y,R17
                ST      -Y,R18
                ST      -Y,R19
                ST      -Y,R20
                ST      -Y,R21
                ST      -Y,R22
                ST      -Y,R23
                ST      -Y,R24
                ST      -Y,R25
                ST      -Y,R26
                ST      -Y,R27
                ST      -Y,R30
                ST      -Y,R31
                .endmacro

                .macroPOP_ALL                           ; Restore all registers
                LD      R31,Y+
                LD      R30,Y+
                LD      R27,Y+
                LD      R26,Y+
                LD      R25,Y+
                LD      R24,Y+
                LD      R23,Y+
                LD      R22,Y+
                LD      R21,Y+
                LD      R20,Y+
                LD      R19,Y+
                LD      R18,Y+
                LD      R17,Y+
                LD      R16,Y+
                LD      R15,Y+
                LD      R14,Y+
                LD      R13,Y+
                LD      R12,Y+
                LD      R11,Y+
                LD      R10,Y+
                LD      R9,Y+
                LD      R8,Y+
                LD      R7,Y+
                LD      R6,Y+
                LD      R5,Y+
                LD      R4,Y+
                LD      R3,Y+
                LD      R2,Y+
                LD      R1,Y+
                LD      R0,Y+
                .endmacro

                .macroPUSH_SP                           ; Save stack pointer
                IN      R16,SPH
                ST      -Y,R16
                IN      R16,SPL
                ST      -Y,R16
                .endmacro

                .macroPOP_SP                              ; Restore stack pointer
                LD      R16,Y+
                OUT   SPL,R16
                LD      R16,Y+
                OUT   SPH,R16
                .endmacro

                .macroPUSH_SREG                           ; Save status register
                IN      R16,SREG
                ST      -Y,R16
                .endmacro

                .macroPOP_SREG                            ; Restore status registers
                LD      R16,Y+
                OUT   SREG,R16
                .endmacro

                .area   text(rel)

;/*$PAGE*/.
;********************************************************************************************************
;                            DISABLE/ENABLE INTERRUPTS USING OS_CRITICAL_METHOD #3
;
; Description : These functions are used to disable and enable interrupts using OS_CRITICAL_METHOD #3.
;
;               OS_CPU_SROSCPUSaveSR (void)
;                     Get current value of SREG
;                     Disable interrupts
;                     Return original value of SREG
;
;               voidOSCPURestoreSR (OS_CPU_SR cpu_sr)
;                     Set SREG to cpu_sr
;                     Return
;********************************************************************************************************

_OS_CPU_SR_Save::
                IN      R16,SREG                  ; Get current state of interrupts disable flag
                CLI                                 ; Disable interrupts
                RET                                 ; Return original SREG value in R16


_OS_CPU_SR_Restore::
                OUT   SREG,R16                  ; Restore SREG
                RET                                 ; Return

;/*$PAGE*/.
;********************************************************************************************************
;                               START HIGHEST PRIORITY TASK READY-TO-RUN
;
; Description : This function is called by OSStart() to start the highest priority task that was created
;               by your application before calling OSStart().
;
; Note(s)   : 1) The (data)stack frame is assumed to look as follows:
;
;                  OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer         (Low memory)
;                                                SPH of (return) stack pointer
;                                                Flags to load in status register
;                                                R31
;                                                R30
;                                                R27
;                                                .
;                                                .
;                                                R0
;                                                PCH
;                                                PCL                                     (High memory)
;
;                  where the stack pointer points to the task start address.
;
;
;               2) OSStartHighRdy() MUST:
;                      a) Call OSTaskSwHook() then,
;                      b) Set OSRunning to TRUE,
;                      c) Switch to the highest priority task.
;********************************************************************************************************

_OSStartHighRdy::
                CALL    _OSTaskSwHook               ; Invoke user defined context switch hook
                LDS   R16,_OSRunning            ; Indicate that we are multitasking
                INC   R16                         ;
                STS   _OSRunning,R16            ;

                LDS   R30,_OSTCBHighRdy         ; Let Z point to TCB of highest priority task
                LDS   R31,_OSTCBHighRdy+1         ; ready to run
                LD      R28,Z+                      ; Load Y (R29:R28) pointer
                LD      R29,Z+                      ;

                POP_SP                              ; Restore stack pointer
                POP_SREG                            ; Restore status register
                POP_ALL                           ; Restore all registers
                RET                                 ; Start task

;/*$PAGE*/.
;********************************************************************************************************
;                                       TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; Note(s)   : 1) Upon entry,
;                  OSTCBCur   points to the OS_TCB of the task to suspend
;                  OSTCBHighRdy points to the OS_TCB of the task to resume
;
;               2) The stack frame of the task to suspend looks as follows:
;
;                                       SP+0 --> LSB of task code address
;                                       +1   MSB of task code address                (High memory)
;
;               3) The saved context of the task to resume looks as follows:
;
;                  OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer         (Low memory)
;                                                SPH of (return) stack pointer
;                                                Flags to load in status register
;                                                R31
;                                                R30
;                                                R27
;                                                .
;                                                .
;                                                R0
;                                                PCH
;                                                PCL                                     (High memory)
;********************************************************************************************************

_OSCtxSw::
                PUSH_ALL                            ; Save current task's context
                PUSH_SREG
                PUSH_SP

                LDS   R30,_OSTCBCur               ; Z = OSTCBCur->OSTCBStkPtr
                LDS   R31,_OSTCBCur+1             ;
                ST      Z+,R28                      ; Save Y (R29:R28) pointer
                ST      Z+,R29                      ;

                CALL    _OSTaskSwHook               ; Call user defined task switch hook

                LDS   R16,_OSPrioHighRdy          ; OSPrioCur = OSPrioHighRdy
                STS   _OSPrioCur,R16

                LDS   R30,_OSTCBHighRdy         ; Let Z point to TCB of highest priority task
                LDS   R31,_OSTCBHighRdy+1         ; ready to run
                STS   _OSTCBCur,R30               ; OSTCBCur = OSTCBHighRdy
                STS   _OSTCBCur+1,R31             ;

                LD      R28,Z+                      ; Restore Y pointer
                LD      R29,Z+                      ;

                POP_SP                              ; Restore stack pointer
                POP_SREG                            ; Restore status register
                POP_ALL                           ; Restore all registers

                RET

;/*$PAGE*/.
;*********************************************************************************************************
;                              INTERRUPT LEVEL CONTEXT SWITCH
;
; Description : This function is called by OSIntExit() to perform a context switch to a task that has
;               been made ready-to-run by an ISR.
;
; Note(s)   : 1) Upon entry,
;                  OSTCBCur   points to the OS_TCB of the task to suspend
;                  OSTCBHighRdy points to the OS_TCB of the task to resume
;
;               2) The stack frame of the task to suspend looks as follows:
;
;                  OSTCBCur->OSTCBStkPtr ------> SPL of (return) stack pointer         (Low memory)
;                                                SPH of (return) stack pointer
;                                                Flags to load in status register
;                                                R31
;                                                R30
;                                                R27
;                                                .
;                                                .
;                                                R0
;                                                PCH
;                                                PCL                                     (High memory)
;
;               3) The saved context of the task to resume looks as follows:
;
;                  OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer         (Low memory)
;                                                SPH of (return) stack pointer
;                                                Flags to load in status register
;                                                R31
;                                                R30
;                                                R27
;                                                .
;                                                .
;                                                R0
;                                                PCH
;                                                PCL                                     (High memory)
;*********************************************************************************************************

_OSIntCtxSw::
                CALL    _OSTaskSwHook               ; Call user defined task switch hook

                LDS   R16,_OSPrioHighRdy          ; OSPrioCur = OSPrioHighRdy
                STS   _OSPrioCur,R16            ;

                LDS   R30,_OSTCBHighRdy         ; Z = OSTCBHighRdy->OSTCBStkPtr
                LDS   R31,_OSTCBHighRdy+1         ;
                STS   _OSTCBCur,R30               ; OSTCBCur = OSTCBHighRdy
                STS   _OSTCBCur+1,R31             ;

                LD      R28,Z+                      ; Restore Y pointer
                LD      R29,Z+                      ;

                POP_SP                              ; Restore stack pointer
                POP_SREG                            ; Restore status register
                POP_ALL                           ; Restore all registers
                RET

;/*$PAGE*/.
;********************************************************************************************************
;                                           SYSTEM TICK ISR
;
; Description : This function is the ISR used to notify uC/OS-II that a system tick has occurred.
;
;               The following C-like pseudo-code describe the operation being performed in the code below.
;
;               Save all registers on the current task's stack:
;                      Use the PUSH_ALL macro
;                      Get the SREG, set Bit #7 and save onto the task's stack using -Y addressing
;                      Use the PUSH_SP macro to save the task's hardware stack pointer onto the current task's stack
;               OSIntNesting++;
;               if (OSIntNesting == 1) {
;                  OSTCBCur->OSTCBStkPtr = SP
;               }
;               Clear the interrupt;                  Not needed for the timer we used.
;               OSTimeTick();                         Notify uC/OS-II that a tick has occured
;               OSIntExit();                        Notify uC/OS-II about end of ISR
;               Restore all registers that were save on the current task's stack:
;                      Use the POP_SP macro to restore the task's hardware stack pointer
;                      Use the POP_SREG macro to restore the SREG register
;                      Use the POP_ALL macro to restore the remaining registers
;               Return (DO NOT use a RETI instruction);
;********************************************************************************************************

_OSTickISR::
                PUSH_ALL                            ; Save all registers and status register
                IN      R16,SREG                  ; Save the SREG but with interrupts enabled
                SBR   R16,BIT07                  
                ST      -Y,R16
                PUSH_SP                           ; Save the task's hardware stack pointer onto task's stack

                LDS   R16,_OSIntNesting         ; Notify uC/OS-II of ISR
                INC   R16                         ;
                STS   _OSIntNesting,R16         ;

                CPI   R16,1                     ; if (OSIntNesting == 1) {
                BRNE    OSTickISR_1

                LDS   R30,_OSTCBCur               ;   OSTCBCur->OSTCBStkPtr = Y
                LDS   R31,_OSTCBCur+1
                ST      Z+,R28
                ST      Z+,R29                      ; }

OSTickISR_1:
                CALL    _OSTickISR_Handler          ; Handle the tick ISR

                CALL    _OSIntExit                  ; Notify uC/OS-II about end of ISR

                POP_SP                              ; Restore the hardware stack pointer from task's stack
                POP_SREG                            ; Restore the SREG register
                POP_ALL                           ; Restore all registers

                RET                                 ; Note: RET instead of RETI

ba_wang_mao 发表于 2010-4-12 11:26:48

以下是OS_CPU_C.C

/*
*********************************************************************************************************
*                                              uC/OS-II
*                                        The Real-Time Kernel
*
*                                       ATmega128 Specific code
*
* File   : OS_CPU_C.C
* By       : Ole Saether
*            Jean J. Labrosse
*********************************************************************************************************
*/

#defineOS_CPU_GLOBALS
#include <includes.h>

/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                          (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments: none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
voidOSInitHookBegin (void)
{
}
#endif

/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                             (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments: none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
voidOSInitHookEnd (void)
{
}
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                          TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments: ptcb   is a pointer to the task control block of the task being created.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
voidOSTaskCreateHook (OS_TCB *ptcb)
{
#ifdef OS_VIEW_MODULE
    OSView_TaskCreateHook(ptcb);
#else
    ptcb = ptcb;                     /* Prevent compiler warning                                     */
#endif
}
#endif


/*
*********************************************************************************************************
*                                           TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments: ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
voidOSTaskDelHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                     /* Prevent compiler warning                                     */
}
#endif

/*
*********************************************************************************************************
*                                             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)    : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
voidOSTaskIdleHook (void)
{
}
#endif

/*
*********************************************************************************************************
*                                           STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task.This allows your
*            application to add functionality to the statistics task.
*
* Arguments: none
*********************************************************************************************************
*/

#if OS_CPU_HOOKS_EN > 0
voidOSTaskStatHook (void)
{
}
#endif

/*$PAGE*/
/*
**********************************************************************************************************
*                                       INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
*            stack frame of the task being created. This function is highly processor specific.
*
* Arguments: task          is a pointer to the task code
*
*            p_arg         is a pointer to a user supplied data area that will be passed to the task
*                            when the task first executes.
*
*            ptos          is a pointer to the top of stack. It is assumed that 'ptos' points to the
*                            highest valid address on the stack.
*
*            opt         specifies options that can be used to alter the behavior of OSTaskStkInit().
*                            (see uCOS_II.H for OS_TASK_OPT_???).
*
* 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)    : Interrupts are enabled when your task starts executing. You can change this by setting the
*            SREG to 0x00 instead. In this case, interrupts would be disabled upon task startup. The
*            application code would be responsible for enabling interrupts at the beginning of the task
*            code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable interrupts.
*            Failure to do this will make your system crash!
*
*            The AVR return stack is placed OS_TASK_HARD_STK_SIZE bytes before the bottom of the task's
*            stack.
*
*            (1) IMPORTANT: The ICC compiler handles function pointers by actually passing the pointer
*                           to a location in Flash that actually contains the pointer to the function.
**********************************************************************************************************
*/

OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt){
   
        INT8U*stk;
    INT8U*stks;                // Temp. variable used for setting up AVR hardware stack
    INT16U tmp;


    opt   = opt;                        // 'opt' is not used, prevent warning
    stk   = (INT8U *)ptos;                // Wandlung von ptos in Bytezeiger
        // AVR return stack ("hardware stack")
    stks    = (INT8U *)(ptos)-(OS_TASK_STK_SIZE-32);

        // the function address has an extra level of indirection. Fetch the
    // actual address.
    //   
    tmp = *(INT16U const *)task;
   
        // 36 Bytes
    *stks-- = (INT8U)tmp;        //Put task start address on top of hardware stack
    *stks-- = (INT8U)(tmp >> 8);

    *stk-- = (INT8U)0x00;                // R0= 0x00
    *stk-- = (INT8U)0x01;
    *stk-- = (INT8U)0x02;
    *stk-- = (INT8U)0x03;
    *stk-- = (INT8U)0x04;
    *stk-- = (INT8U)0x05;
    *stk-- = (INT8U)0x06;
    *stk-- = (INT8U)0x07;
    *stk-- = (INT8U)0x08;
    *stk-- = (INT8U)0x09;
    *stk-- = (INT8U)0x10;
    *stk-- = (INT8U)0x11;
    *stk-- = (INT8U)0x12;
    *stk-- = (INT8U)0x13;
    *stk-- = (INT8U)0x14;
    *stk-- = (INT8U)0x15;
    tmp    = (INT16U)pdata;
    *stk-- = (INT8U)tmp;        //Simulate call to function with argument
    *stk-- = (INT8U)(tmp >> 8);
    *stk-- = (INT8U)0x18;
    *stk-- = (INT8U)0x19;
    *stk-- = (INT8U)0x20;
    *stk-- = (INT8U)0x21;
    *stk-- = (INT8U)0x22;
    *stk-- = (INT8U)0x23;
    *stk-- = (INT8U)0x24;
    *stk-- = (INT8U)0x25;
    *stk-- = (INT8U)0x26;
    *stk-- = (INT8U)0x27;
        // the heap pointer Y=R29:R28 will not be stored
    *stk-- = (INT8U)0x30;
    *stk-- = (INT8U)0x31;
//    *stk-- = (INT8U)0x3B;
    *stk-- = (INT8U)0x80;        //SREG = Interrupts enabled

    tmp    = (INT16U)(stks);
    *stk-- = (INT8U)(tmp >> 8);
    *stk   = (INT8U)(tmp);
    return ((void *)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 'OSTCBHighRdy' points to the TCB of the task that
*               will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
*               task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TASK_SW_HOOK_EN > 0)
voidOSTaskSwHook (void)
{
#ifdef OS_VIEW_MODULE
    OSView_TaskSwHook();
#endif
}
#endif

/*
*********************************************************************************************************
*                                           OS_TCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
*
* Arguments: ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
voidOSTCBInitHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                                           /* Prevent Compiler warning               */
}
#endif


/*
*********************************************************************************************************
*                                             TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments: none
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TIME_TICK_HOOK_EN > 0)
voidOSTimeTickHook (void)
{
#ifdef OS_VIEW_MODULE
    OSView_TickHook();
#endif
}
#endif

/*
*********************************************************************************************************
*                                        SETUP THE TICK RATE
*********************************************************************************************************
*/
voidOSTickISR_Handler (void)
{
    OSTimeTick();
}

/*
*********************************************************************************************************
*                                        SETUP THE TICK RATE
*********************************************************************************************************
*/
voidOSTickISR_Init (void)
{
        CLI();
        TCNT0   =   0x00;                   /*清零Timer0计数器*/
           OCR0    =   107;//OS_SYS_TIME;        /*每逢1ms产生一次匹配中断*/
           TCCR0A   =   0x05;                   /*工作于输出比较匹配模式,不连接OC0端口,时钟32预分频*/
           TIFR0   |=   0x02;                   /*清除输出比较匹配中断标志位*/
           TIMSK0|=   0x02;                   /*使能输出比较匹配中断*/
   /*       
           TCNT0   =   0x00;                   //清零Timer0计数器
           OCR0    =   OS_SYS_TIME;        //每逢1ms产生一次匹配中断
           TCCR0   =   0x03;                   //工作于输出比较匹配模式,不连接OC0端口,时钟32预分频
           TIFR1   |=   0x02;                   //清除输出比较匹配中断标志位
           TIMSK1|=   0x02;                   //使能输出比较匹配中断
           */
}

huanghaiming 发表于 2010-4-12 19:30:55

我QQ327741577,能不能加Q交流?
页: [1]
查看完整版本: uC/OS-ii 移植到Atmeg128 编译环境为ICCV7 编译通过但是不能正常运行