原创 keil中RTXtiny的学习(3)

2007-11-8 00:17 1840 5 5 分类: MCU/ 嵌入式

/******************************************************************************/
/*                                                                            */
/*   Task 0:  Create other Tasks and Count up Every 5 ticks                   */
/*                                                                            */
/******************************************************************************/


#include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */


unsigned long counter0;               /* counter for task 0                   */


/******************************************************************************/
/*       Task 0 'job0':  RTX-51 tiny starts execution with task 0            */
/******************************************************************************/
void job0 (void) _task_ 0  {                 
  os_create_task (1);                 /* start task 1                         */
  os_create_task (2);                 /* start task 2                         */
  os_create_task (3);                 /* start task 3                         */


  while (1)  {                        /* endless loop                         */
    counter0++;                       /* increment counter 0                  */
    os_wait (K_TMO, 5, 0);            /* wait for timeout: 5 ticks            */
  }
}


 


/******************************************************************************/
/*                                                                            */
/*   Task 1:  Count up Every 2 ticks                                          */
/*                                                                            */
/******************************************************************************/


#include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */


unsigned long counter1;               /* counter for task 1                   */


/******************************************************************************/
/*   Task 1 'job1':  RTX-51 tiny starts this task with os_create_task (1)     */
/******************************************************************************/
void job1 (void) _task_ 1  {
  while (1)  {                        /* endless loop                         */
    counter1++;                       /* increment counter 1                  */
    os_wait (K_TMO, 2, 0);            /* wait for timeout: 2 ticks            */
  }
}


 


/******************************************************************************/
/*                                                                            */
/*   Task 2:  Count as fast as possible and Signal Overflow to Task 3         */
/*                                                                            */
/******************************************************************************/


#include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */


unsigned long counter2;               /* counter for task 2                   */



/******************************************************************************/
/*    Task 2 'job2':  RTX-51 tiny starts this task with os_create_task (2)    */
/******************************************************************************/
void job2 (void) _task_ 2  {
  while (1)  {                        /* endless loop                         */
    counter2++;                       /* increment counter 1                  */
    if ((counter2 & 0x0F) == 0)  {    /* every 16 counts:                    */
      os_switch_task ();              /* give other tasks CPU time            */


           //每16个计数,就放弃一次task()


    }
    if ((counter2 & 0xFFFF) == 0)  {  /* if counter overflows,                */
 
     os_set_ready (3);               /* set run flag of task 3               */


//void os_set_ready   (unsigned char taskid);
  //void isr_set_ready  (unsigned char taskid);
    }
  }
}


 


/******************************************************************************/
/*                                                                            */
/*   Task 3:  Process Overflow from Task 2                                    */
/*                                                                            */
/******************************************************************************/


#include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */


unsigned long counter3;               /* counter for task 3                   */



/******************************************************************************/
/*    Task 3 'job3':  RTX-51 tiny starts this task with os_create_task (3)    */
/******************************************************************************/
void job3 (void) _task_ 3  {
  while (1)  {                        /* endless loop                         */
    os_wait1 (0);                     /* wait for RDY                         */


//??????????????????????????????????????????????????????????????
    counter3++;                       /* process overflow from counter 2      */
  }
}

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /1 下一条