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

📄 os_cpu_c.lst

📁 ucos 51c的移植源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
                  ptcb = ptcb;                       /* Prevent compiler warning                                     */
C51 COMPILER V8.02   OS_CPU_C                                                              06/22/2006 12:13:15 PAGE 4   

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

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

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


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    963    ----
   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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -