os_cpu_c.lst

来自「ucOS移植到STC89C58RD上面的源代码」· LST 代码 · 共 384 行 · 第 1/2 页

LST
384
字号
C51 COMPILER V7.50   OS_CPU_C                                                              12/14/2005 10:55:59 PAGE 4   

 178          
 179          /*
 180          *********************************************************************************************************
 181          *                                          任务切换钩挂函数
 182          *
 183          * 描述       : 执行任务切换时调用。这允许你在上下文切换期间执行其它操作。
 184          *
 185          * 参数       : 无
 186          *
 187          * 注意       : 1) 调用期间中断被禁止
 188          *              2) 假定全局指针'OSTCBHighRdy'已经指向了将要被换入的任务控制块(即:最高优先级任务),并且
 189          *                 'OSTCBCur'指向了将被换出的任务(即:当前任务)。
 190          *********************************************************************************************************
 191          */
 192          void OSTaskSwHook (void) reentrant
 193          {
 194   1      }
 195          
 196          /*
 197          *********************************************************************************************************
 198          *                                          统计任务钩挂函数
 199          *
 200          * 描述       : 这个函数每秒钟被uC/OS-II统计任务调用。这么做使你的应用程序可以增加统计任务的功能。
 201          *
 202          * 注意       : 无
 203          *********************************************************************************************************
 204          */
 205          #if OS_TASK_STAT_EN > 0
              void OSTaskStatHook (void) reentrant
              {
              }
              #endif
 210          
 211          /*
 212          *********************************************************************************************************
 213          *                                           OSTCBInit() HOOK
 214          *
 215          * Description: This function is called by OSTCBInit() after setting up most of the TCB.
 216          *
 217          * Arguments  : ptcb    is a pointer to the TCB of the task being created.
 218          *
 219          * Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
 220          *********************************************************************************************************
 221          */
 222          #if OS_VERSION > 203
 223          void OSTCBInitHook (OS_TCB *ptcb) reentrant
 224          {
 225   1          ptcb = ptcb;                                           /* Prevent Compiler warning                 */
 226   1      }
 227          #endif
 228          
 229          /*
 230          *********************************************************************************************************
 231          *                                          定时钩挂函数
 232          *
 233          * 描述       : 本函数每一滴答被调用一次。
 234          *
 235          * 参数       : 无
 236          *
 237          * 注意       : 1) 在本调用期间中断可以或不可以使能。
 238          *********************************************************************************************************
 239          */
C51 COMPILER V7.50   OS_CPU_C                                                              12/14/2005 10:55:59 PAGE 5   

 240          void OSTimeTickHook (void) reentrant
 241          {
 242   1      }
 243          
 244          /*
 245          *********************************************************************************************************
 246          *                                             IDLE TASK HOOK
 247          *
 248          * Description: This function is called by the idle task.  This hook has been added to allow you to do  
 249          *              such things as STOP the CPU to conserve power.
 250          *
 251          * Arguments  : none
 252          *
 253          * Note(s)    : 1) Interrupts are enabled during this call.
 254          *********************************************************************************************************
 255          */
 256          #if OS_VERSION >= 251
 257          void OSTaskIdleHook (void) reentrant
 258          {
 259   1      }
 260          #endif
 261          
 262          #endif
 263          
 264          /*
 265             使用C语言的中断处理函数有助与提高程序的移植性。建议中断程序不要太长,如果长则使用信号量来与任务同步,
 266             在外部任务中实现大量的处理。
 267             中断处理例程都放在下面。
 268          */
 269          
 270          void UserTickTimer(void)
 271          {
 272   1          TH0  = 0xDB;   //定义Tick=100次/秒(即0.01秒/次),TH,TL值与CPU的频率有关(11.0592M)
 273   1          TL0  = 0xFF;  
 274   1          TR0=1;
 275   1      }
 276          
 277          /* 
 278            ucOS-II系统时钟中断处理程序
 279          */
 280          void OSTickISR(void) interrupt 1
 281          {
 282   1          OSIntEnter();                                       // Must be called first at every hardware interrupt entry point 
 283   1          UserTickTimer();                            // User functions can be called here.
 284   1              OSTimeTick();                                   // Must be called during tick isr 
 285   1              OSIntExit();                                    // Must be called finally at every hardware interupt exit point 
 286   1      }
 287          
 288          /*--------------------------------------------------------------*/
 289          /* ucOS-II的中断服务程序示例                                    */
 290          /*--------------------------------------------------------------*/
 291          #include "serial.h"
 292          
 293          void SerialISR(void) interrupt 4
 294          {
 295   1      #if OS_CRITICAL_METHOD == 3         // Allocate storage for CPU status register 
                  OS_CPU_SR  cpu_sr;
              #endif 
 298   1      
 299   1          OSIntEnter();                                       // Must be called first at every hardware interrupt entry point 
 300   1          OS_ENTER_CRITICAL();
 301   1          if(TI)
C51 COMPILER V7.50   OS_CPU_C                                                              12/14/2005 10:55:59 PAGE 6   

 302   1              {
 303   2                TI=0;
 304   2            pc_send.ptr++;
 305   2            if (pc_send.ptr < pc_send.count)
 306   2              SBUF=pc_send.buffer[pc_send.ptr];
 307   2              }
 308   1              else if(RI)
 309   1              {
 310   2                  RI=0;
 311   2      //处理输入字符
 312   2              }
 313   1          OS_EXIT_CRITICAL();
 314   1      
 315   1              OSIntExit();                    // Must be called finally at every hardware interupt exit point 
 316   1      }
 317          
 318          
 319          /*
 320            设置硬件寄存器的初始值。
 321            初始化定时器0,作为ucOS-II的系统时钟。
 322            还有其他的与硬件相关的初始化也可以放在这里。
 323          */
 324          
 325          //串口初始化  0xfd=19200,0xfa=9600,0xf4=4800,0xe8=2400,0xd0=1200
 326          void InitHardware(void) reentrant
 327          {
 328   1          AUXR = 0x01;                //   
 329   1          TMOD = 0x21;   //定时器0:模式1(16位定时器),仅受TR0控制;定时器1:波特率发生器
 330   1          TH0  = 0xDB;   //定义Tick=100次/秒(即0.01秒/次),TH,TL值与CPU的频率有关(11.0592M)
 331   1          TL0  = 0xFF;   //OS_CPU_C.C中定时器中断响应也要设置,OS_CFG.H中OS_TICKS_PER_SEC也有关系
 332   1          //ET0  = 1;    //允许T0中断(在第一个任务开始执行时才开时钟中断,否则万一中断系统进入不可知状态)
 333   1          TR0  = 1;
 334   1      
 335   1      // Setup serial communication 
 336   1      // Configure timer 2 as a baud rate generator
 337   1              PCON |= 0x80;                           // 119200
 338   1              SCON = 0x50;
 339   1      
 340   1              TH1 = 0xFD;
 341   1              TL1 = 0xFD;
 342   1              TR1 =1;
 343   1              ES = 1;
 344   1      
 345   1          //设置串口收发的初始值
 346   1          pc_send.ptr=0;
 347   1          pc_send.count=0;
 348   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    797    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      7    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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