This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

tms570 isr code in rtos.

Other Parts Discussed in Thread: HALCOGEN

 

i use halcogen generate all the peripheral code include freertos.

but the isr does not link to freertos isr process,

i think, must be package the naked isr code in freertos, then i fill s_vim_init[] in sys_startup.c with xxx_ISREntry(),

follow is my packed isr asm code, is right? if it's some errors, please correct it, thanks a lot!

os_portISR.asm:

 .text
 .state32

;-------------------------------------------------------------------------------
; Restore Context

    .def     osPortRestoreContext
    .def     osPortSaveContext
    .ref     pxCurrentTCB
    .ref     ulCriticalNesting
    .def     xcurTCB
    .def     ulcritNest
    .asmfunc

osPortRestoreContext:
        ldr  r0,          xcurTCB
        ldr  r0,          [r0]
        ldr  lr,          [r0]
        ldr  r0,          ulcritNest
        ldmfd lr!,         {r1}
        str  r1,          [r0]
   
    .if __TI_VFPV3D16_SUPPORT__ = 1
        ldmfd   lr!,         {r0,r1}
        fldmiad lr!,         {d0-d15}
        fmxr    fpscr,       r1
    .else
        ldmfd   lr!,         {r0}
    .endif
   
        msr  spsr_cf,     r0
        ldmfd lr,          {r0-r14}^
        ldr  lr,          [lr, #0x3C]
        subs pc,          lr,         #4

    .endasmfunc

;-------------------------------------------------------------------------------
; Save context
 
 .asmfunc
 
osPortSaveContext:
        stmfd   sp!,         {r0}
        stmfd   sp,          {sp}^
        sub     sp,          sp,         #4
        ldmfd   sp!,         {r0}
       
        stmfd   r0!,         {lr}
        mov     lr,          r0
        ldmfd   sp!,         {r0}
        stmfd   lr,          {r0-lr}^
        sub     lr,          lr,         #0x3C
   
    .if __TI_VFPV3D16_SUPPORT__ = 1
        fstmdbd lr!,         {d0-d15}
        mrs     r0,          spsr
        fmrx    r1,          fpscr
        stmfd   lr!,         {r0,r1}
    .else
        mrs     r0,          spsr
        stmfd   lr!,         {r0}
    .endif
   
        ldr     r0,   ulcritNest
        ldr     r0,         [r0]
        stmfd   lr!,        {r0}
        ldr     r0,         xcurTCB
        ldr     r0,         [r0]
        str     lr,         [r0]
   
 .endasmfunc

;-------------------------------------------------------------------------------
; Global Definitions

xcurTCB:    .word pxCurrentTCB
ulcritNest: .word ulCriticalNesting


;------------------------------------------------------------------------------
 .ref rtiCompare0Interrupt
 .global rtiCompare0_ISREntry
 
vrtiCompare0Interrupt .word rtiCompare0Interrupt
 
 .asmfunc
 
rtiCompare0_ISREntry:
 
 ; Save the context of the interrupted task.
 b osPortSaveContext   
 
 ; Call the C handler function - defined within *.c.
 LDR R0, vrtiCompare0Interrupt
 MOV LR, PC
 BX  R0
 
 ; Finish off by restoring the context of the task that has been chosen to
 ; run next - which might be a different task to that which was originally
 ; interrupted.
 b osPortRestoreContext
 
 .endasmfunc

;------------------------------------------------------------------------------
 .ref can1HighLevelInterrupt
 .global can1HighLevel_ISREntry
 
vcan1HighLevelInterrupt .word can1HighLevelInterrupt
 
 .asmfunc
 
can1HighLevel_ISREntry:
 
 ; Save the context of the interrupted task.
 b osPortSaveContext   
 
 ; Call the C handler function - defined within *.c.
 LDR R0, vcan1HighLevelInterrupt
 MOV LR, PC
 BX  R0
 
 ; Finish off by restoring the context of the task that has been chosen to
 ; run next - which might be a different task to that which was originally
 ; interrupted.
 b osPortRestoreContext
 
 .endasmfunc
 

 

  • Hi Yang Gunglun

    Your query is been forwarded to our Halcogen expert.
    We will get back to you as soon as possible. 

    Thanks!!!

  •  ok, thanks.

    on the other hand,  does the tms570 isr code still need  statement such as  #pragma INTERRUPT(rtiCompare0Interrupt, FIQ) ?

    or does not need statement  "#pragma INTERRUPT(rtiCompare0Interrupt, FIQ)", because of the osPortSaveContext () and osPortRestoreContext()

    in freertos xxx_ISREntry() ?

    #pragma INTERRUPT(rtiCompare0Interrupt, FIQ)

    void rtiCompare0Interrupt(void)
    {
    /* USER CODE BEGIN (39) */
    /* USER CODE END */

        rtiREG1->INTFLAG = 1U;
        rtiNotification(rtiNOTIFICATION_COMPARE0);

    /* USER CODE BEGIN (40) */
    /* USER CODE END */
    }

  • i think,i already solved  a  part  of problem by test, and  the freertos is running ok on my design generated by halcogen.

    1.  the interrupt do not need '#pragma INTERRUPT(xxxInterrupt, FIQ)' in freertos interrupt

    2. must be use PortSaveContext() and PortRestoreContext() to save and restore the freertos isr.

    but have two question:

    (1) Does the FIQ and IRQ need different PortSaveContext()  and PortRestoreContext() ?

     halcogen does not provid two version function such as  irqPortSaveContext()  fiqPortSaveContext() , irqPortRestoreContext(), fiqPortRestoreContext(),

    i use the same process in our design.

     (2) Does the freertos packed isr  such as  xxx__ISREntry()  need be decorated with ' #pragma INTERRUPT(rtiCompare0Interrupt, FIQ)'?

    i don't use '#pragma INTERRUPT'()' and it seems working well.

     

    below is my rti isr  example,

    rtiCompare0_ISREntry:
     
     ; Save the context of the interrupted task.
     macroPortSaveContext xcurTCB,ulcritNest    
     
     ; Call the C handler function - defined within *.c.
     LDR R0, vrtiCompare0Interrupt
     MOV LR, PC
     BX  R0
     
     ; Finish off by restoring the context of the task that has been chosen to
     ; run next - which might be a different task to that which was originally
     ; interrupted.
     macroPortRestoreContext xcurTCB,ulcritNest
     
     .endasmfunc

     

    void rtiCompare0Interrupt(void)
    {
    /* USER CODE BEGIN (39) */

     vTaskIncrementTick(); 
      portEXIT_SWITCHING_ISR( 1 );


    /* USER CODE END */

        rtiREG1->INTFLAG = 1U;
        rtiNotification(rtiNOTIFICATION_COMPARE0);

    /* USER CODE BEGIN (40) */
    /* USER CODE END */
    }