News:

Let's find out together what makes a PIC Tick!

Main Menu

Internal VAR name changes??

Started by JohnB, Aug 31, 2021, 10:37 AM

Previous topic - Next topic

JohnB

I have just been testing Positron Studio for a new update and I tried to compile my PRTOS24 demo.  I am now getting errors with my context save/restore code.  Because I have to adjust the stack in my Interrupt routine I have extracted the assembler generated by the compiler and inserted it as ASM in my code with the necessary changes.  I am now getting the following errors

PBP_VAR0 not found
PBP_VAR1 not found

This is my code below...

OS_Timer Interrupt Service Routine

' Sets a tick flag which is cleared by scheduler and increments the OSTickCount
        $if OSTICK_SOURCE = T1
          $define ClrTmrflg IFS0bits_T1IF  = 0        ' Clear Timer1 interrupt flag
          $define EnTmrIntr IEC0bits_T1IE  = 1        ' Enable the Timer1 interrupt
          Isr T1Interrupt, UnHandled
        $endif
        $if OSTICK_SOURCE = T2
          $define ClrTmrflg IFS0bits_T2IF  = 0        ' Clear Timer2 interrupt flag
          $define EnTmrIntr IEC0bits_T2IE  = 1        ' Enable the Timer2 interrupt
          Isr T2Interrupt UnHandled
        $endif

        Dim TaskPtr  As OSPW1
        Dim TmpWrd   As WREG4
        Dim NextTask As WREG5

        'Save Context
        Disi #0x3fff
        Push STATUS
        Push RCOUNT
        Push CORCON
        Push.w W14
        Mov.w #0x00,W14
        mRepeat #13
        Mov.w [W14++],[W15++]
        $if _type = "_PIC24E" Or _type = "_PIC33E"
        $define _OFFSET 48
        Push DSRPAG
        Push DSWPAG
        $else
        $define _OFFSET 46
        Push PSVPAG
        $endif
        Push PBP_VAR0
        Push PBP_VAR1
        Disi #0x01
       
        High PORTB.8                                  ' debug to Virtual Scope

        ClrTmrflg                                     ' Clear Timer interrupt flag
        $if OSTICK_CTR_SIZE > 0
          Inc OSTickCount                             ' increment the tick count
          $if OSTICK_CTR_EVENT = True
            If OSTickCount = OSTickCtrEventVal Then   ' if Tick Count reached event value
              OSSignalSemaphore_ISR(e_TCTREvent)      ' Signal Tick Counter event
            EndIf
          $endif
        $endif

        $if OSENABLE_TIMEOUTS = True
          If LastTask <> OSNO_TASK Then
            TaskPtr = 0
            NextTask = 0
            Do                                ' run through all tasks for events and timers/Timeouts
            If Tasks[TaskPtr] <> OSNO_TASK Then       ' Skip any Unused slots
              If Tasks[TaskPtr] & $2 = $2 Then        ' If Task Delayed, Waiting or CycTmr Running
                TmpWrd = Tasks[TaskPtr + _Timer]      ' Get the timer
                If TmpWrd > 0 Then                    ' Timer decrements to 0
                  Dec TmpWrd                          ' Still +ve so decrement it
                  Tasks[TaskPtr + _Timer] = TmpWrd    ' and save it back in the TCB
                  If TmpWrd = 0 Then                  ' If it has reached 0 time to act
                    Select Tasks[TaskPtr]
                    Case OSTCB_TASK_DELAYED           ' if it was delayed task it is time to
                      Tasks[TaskPtr] = OSTCB_TASK_ELIGIBLE ' make it eligible to run again
                      $ifdef OSENABLE_EVENTS
                      Case OSTCB_TASK_WAITING         ' if waiting task then has timed out
                        Tasks[TaskPtr + _Misc] = Tasks[TaskPtr + _Misc] | mi_SET_TIMEOUT' set timeout flag
                        Tasks[TaskPtr] = OSTCB_TASK_ELIGIBLE ' and make eligible to run again.
                      $endif
                      $if OSENABLE_CYCLIC_TIMERS = True
                      Case OSTCB_CYCTMR_WAITING
                        Tasks[TaskPtr] = OSTCB_CYCTMR_ELIGIBLE ' Update the timer
                      $endif
                    EndSelect
                  EndIf
                EndIf
              EndIf
            EndIf
            Inc NextTask
            TaskPtr = NextTask * TCBSize              ' Step on to next task
            Loop Until NextTask > LastTask            ' Loop through all tasks
          EndIf
        $endif
        $ifdef OSWATCHDOG_TIMEOUT
          If OSWatchdog > 0 Then
            Dec OSWatchdog                            ' Decrement the watchdog each OS Tick
          Else                                        ' if Watchdog has timed out
            LastError.HighByte = OSSCHEDULER_TIMEOUT  ' Set up the error code and
            LastError.LowByte = CurrentTask.LowByte   ' the task ID of the timed out task
            Tasks[CurrTaskPtr] = OSTCB_TASK_STOPPED   ' Stop hung task
            ' locate return address in the stack and replace it with Scheduler address
            TaskPtr = t_Error * TCBSize               ' Point to the Error Task and
            Tasks[TaskPtr] = OSTCB_TASK_ELIGIBLE      ' set it to run on next Select_Run_Task
            OSTmpDW = AddressOf(Select_Run_Task)      ' Get the address of the scheduler and
            WREG14 = WREG15                           ' Load WREG14 with the stack Pointer           
            WREG14 = WREG14 - _OFFSET                 ' Adjust pointer to LSWord of the ISR Return
            WREG13 = OSTmpDW.LowWord                  ' Get Low Word of the error routine and
            Mov.w W13, [W14++]                        ' place in ISR return value low word
            WREG13 = OSTmpDW.HighWord                 ' Get High Word of error routine
            Mov.w W13, [W14++]                        ' place in ISR Return value high word
          EndIf
        $endif
        EnTmrIntr                                     ' enable timer Interrupt

        Low PORTB.8                                   ' debug to Virtual Scope

        ' Restore Context - This equates to 44/46 decrements of the stack
        Disi #0x3fff
        Pop PBP_VAR1
        Pop PBP_VAR0
        $if _type = "_PIC24E" Or _type = "_PIC33E"
        Pop DSWPAG
        Pop DSRPAG
        $else
        Pop PSVPAG
        $endif
        Mov.w #0x1a,W14
        mRepeat #13
        Mov.w [--W15],[W14--]
        Pop.w W14
        Pop CORCON
        Pop RCOUNT
        Pop STATUS
        Disi #0x01
        EndIsr        ' and return

What should these vars be called now?
JohnB

JohnB

I should add that the device is 24FJ64GA002
JohnB