⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tasksw.s.svn-base

📁 我们自己开发的一个OSEK操作系统!不知道可不可以?
💻 SVN-BASE
字号:
.include "os_cpu_a.inc"
.global OSStartHighRdy
.global OSCtxSw

/*********************************************************************************************************
 *                                 START HIGHEST PRIORITY TASK READY-TO-RUN
 *
 * Description : This function is called by OSStart() to start the highest priority task that was created
 *               by the application before calling OSStart().
 *
 * Arguments   : none
 *
 * Note(s)     : 1) OSStartHighRdy() MUST:
 *                   a) Call OSTaskSwHook() then,
 *                   b) Set OSRunning to TRUE,
 *                   c) Switch to the highest priority task by loading the stack pointer of the highest
 *                      priority task into the SP register and execute an rfi instruction.
 */




    .align  4
OSStartHighRdy:                             
                                        
    li      r0,  1                                   /*# Set OSRunning to 1*/
    lis     r11, OSRunning@ha            
    stb     r0,  OSRunning@l(r11)          
                                        
    lis     r11, OSTCBHighRdy@ha                     /*# Get pointer to ready task TCB*/
    lwz     r11, OSTCBHighRdy@l(r11)      
                                        
    lis     r12, OSTCBCur@ha                         /*/# Save as current task TCB ptr.*/
    stw     r11, OSTCBCur@l(r12)          
                                        
    lwz     r30,  0(r11)                              /*//# Get new stack pointer*/
                                        
    epilogue                                       /*/ # Restore context*/
                                        
    rfi                                            /*/ # run task*/


/*********************************************************************************************************
 *                                         TASK LEVEL CONTEXT SWITCH
 *
 * Description : This function is called when a task makes a higher priority task ready-to-run.
 *
 * Arguments   : none
 *
 * 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
 */

    .align  4
OSCtxSw:       
    prologue                                       /*/ # Save context*/

    lis     r11,OSTCBCur@ha                       /*/  # Get pointer to current TCB*/
    lwz     r11,OSTCBCur@l(r11)
    stw     r30, 0(r11)                            /*/  # Save stack pointer in current TCB*/

    lis     r11,OSTCBHighRdy@ha                    /*/ # Get pointer to ready task TCB*/
    lwz     r11,OSTCBHighRdy@l(r11)

    lis     r12,OSTCBCur@ha                        /*/ # Save as current task TCB ptr.*/
    stw     r11,OSTCBCur@l(r12)

    lis     r12,OSPrioHighRdy@ha                  /*/  # Get High Ready Priority*/
    lbz     r10,OSPrioHighRdy@l(r12)

    lis     r12,OSPrioCur@ha                      /*/  # Save as Current Priority*/
    stb     r10,OSPrioCur@l(r12)

    lwz     r30, 0(r11)                           /*/   # Get new stack pointer from TCB*/

    epilogue                                      /*/  # Restore context*/

    rfi                                           /*/  # run task*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -