sample.c

来自「RTX51 example use. Inside are example on」· C语言 代码 · 共 50 行

C
50
字号
#pragma large

#include  <Rtx51.h>               // RTX-51 Definitions
#define  PRODUCER_NBR    0        // Tasknumber for the producer task
#define  CONSUMER_NBR    1        // Tasknumber for the consumer task
#define  FIRST_MAILBOX   0        // The mailbox identification
#define  WAIT_FOREVER    0xFF     // A constant, signalling to the RTX
                                  // call, that no timeout for the call is
                                  // expected.


void  ProducerTask (void) _task_ PRODUCER_NBR
{
   unsigned int  MessageToSend = 1;

   os_create_task (CONSUMER_NBR);   // Create the Consumer-Task
   for (;;)                         // endless loop
   {
      // Send the actual value of 'send_mes' to mailbox 0
      // if the mailbox is full, wait until there is place for the message
      os_send_message (FIRST_MAILBOX, MessageToSend, WAIT_FOREVER);
      MessageToSend++;
   }
}


void  ConsumerTask (void) _task_ CONSUMER_NBR _priority_ 1
{
   unsigned int  ReceiveBuffer;

   for (;;)
   {
      // Read from mailbox FIRST_MAILBOX one message
      // Wait for a message, if the mailbox is empty
      os_wait (K_MBX + FIRST_MAILBOX, WAIT_FOREVER, &ReceiveBuffer);
      //
      // ... perform some calculations with the message
      //
   }
}


void  main (void)
{
   signed char  RtxReturnState;

   // Init the system and start the Producer-Task
   RtxReturnState = os_start_system (PRODUCER_NBR);
}

⌨️ 快捷键说明

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