Ask Help! Porting uCOS to H8S2218

I am porting

the ucos II 2.52 to H8S2218,

I use HEW ro debug my program, when the program run to _OSCtxSw 's RTE, the program run away. as below is my program, please help.

=====================================================

;********************************************************************************************************
;                                               uC/OS-II
;
;                                           H8S Specific code
;                                           (ADVANCED mode)
;
;
; File : OS_CPU_A.SRC
;********************************************************************************************************
       
          .EXPORT _OSStartHighRdy      ; Public functions
          .EXPORT _OSCtxSw
          .EXPORT _OSIntCtxSw
          .EXPORT _OSTickISR

          .IMPORT _OSIntEnter          ; External functions
          .IMPORT _OSIntExit
          .IMPORT _OSTimeTick
          .IMPORT _OSTaskSwHook
         
          .IMPORT _OSTCBCur            ; External variables (uC/OS-II)
          .IMPORT _OSTCBHighRdy
          .IMPORT _OSPrioCur
          .IMPORT _OSPrioHighRdy
          .IMPORT _OSIntNesting
          .IMPORT _OSRunning
          .IMPORT _TickClr
                                            ; the OS tick source

_OSStartHighRdy:
          JSR      @_OSTaskSwHook         ; Execute task switch hook
;
          MOV.B    #1,  R6L              ; Set OSRunning to TRUE
          MOV.B    R6L, @_OSRunning
;
          MOV.L    @_OSTCBHighRdy, ER0    ; SP = OSTCBHighRdy->OSTCBStkPtr
          MOV.L    #_OSTCBCur,ER1
          MOV.L    ER0,  @ER1
          MOV.L    @ER0, ER7
;         

          POP.L    ER6
          POP.L    ER5
          POP.L    ER4
          POP.L    ER3
          POP.L    ER2
          POP.L    ER1
          POP.L    ER0
 
;         
          RTE

_OSCtxSw:       
          PUSH.L   ER0
          PUSH.L   ER1
          PUSH.L   ER2
          PUSH.L   ER3
          PUSH.L   ER4
          PUSH.L   ER5
          PUSH.L   ER6
;
          MOV.L    @_OSTCBCur, ER6        ; Save current task's SP into its TCB
          MOV.L    ER7, @ER6
;         
          JSR      @_OSTaskSwHook         ; Execute task switch hook
;
          MOV.B    @_OSPrioHighRdy, R1L   ; OSPrioCur = OSPrioHighRdy
          MOV.B    R1L, @_OSPrioCur
;         
          MOV.L    @_OSTCBHighRdy, ER6    ; Get new task's SP from its TCB
          MOV.L    ER6,  @_OSTCBCur       ; OSTCBCur = OSTCBHighRdy
          MOV.L    @ER6, ER7
;         
          POP.L    ER6
          POP.L    ER5
          POP.L    ER4
          POP.L    ER3
          POP.L    ER2
          POP.L    ER1
          POP.L    ER0
;         
          RTE                            ; Return to task

_OSIntCtxSw:
          JSR      @_OSTaskSwHook         ; Execute task switch hook
;
          MOV.B    @_OSPrioHighRdy, R1L   ; OSPrioCur = OSPrioHighRdy
          MOV.B    R1L, @_OSPrioCur
;         
          MOV.L    @_OSTCBHighRdy, ER6    ; Get new task's SP from its TCB
          MOV.L    ER6, @_OSTCBCur        ; OSTCBCur = OSTCBHighRdy
          MOV.L    @ER6, ER7
;         

         POP.L    ER6
          POP.L    ER5
          POP.L    ER4
          POP.L    ER3
          POP.L    ER2
          POP.L    ER1
          POP.L    ER0
;         
          RTE

   
_OSTickISR:
          PUSH.L   ER0
          PUSH.L   ER1
          PUSH.L   ER2
          PUSH.L   ER3
          PUSH.L   ER4
          PUSH.L   ER5
          PUSH.L   ER6

          MOV.B    @_OSIntNesting, R6L    ; tell uC/OS-II we're in an ISR
          INC.B    R6L
          MOV.B    R6L, @_OSIntNesting

          CMP.B    #1,R6L                ; if (OSNesting == 1)
          BNE      _OSTickISR1
          MOV.L    @_OSTCBCur, ER6        ;     Save current task's SP into its TCB
          MOV.L    ER7, @ER6
_OSTickISR1:

          JSR      @_TickClr              ; Notify uC/OS-II about Tick
          JSR      @_OSTimeTick
          JSR      @_OSIntExit            ; Notify uC/OS-II about end of ISR

    

          POP.L    ER6
          POP.L    ER5
          POP.L    ER4
          POP.L    ER3
          POP.L    ER2
          POP.L    ER1
          POP.L    ER0 

          RTE

        .END
      

  • this is the closest port I have to what you're looking at. Take a look at the vector sections and the TickISR.

    attachments.zip
  • I did many ports of uC/OS-II to SH2 , H8, H8S and H8SX devices from Renesas.

    For me... it seems, that the stack of the task to switch on, which holds the return address is not valid. Unfortunately, your posted code does not help here.

  • Thanks  ckgrier & Wini,

    I found the point which cause the program run away is the Interrupt Control Mode, When I use Interrupt Control Mode 0 , Program run normal & uCOS work. But When I change the Interrupt Mode to 2,

    The program will run away.

  • Ok... The return stack looks different for interrupt mode 0 and 2. That causes the crash of your implementation. You should have a look into the software or hardware manual for more information.