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

📄 applmain.c

📁 实时多重作业操作系统内核(RTMK)。简单实时多重作业操作系统内核源程序。RTMK支持消息和事件
💻 C
字号:
/************************************************************************
*
*  Module name         : APPLMAIN.C
*
*  Module description  :
*     Test
*
*  Project             : RTMK
*
*  Target platform     : DOS
*
*  Compiler & Library  : BC++ 3.1
*
*  Author              : Richard Shen
*
*  Creation date       : August, 1995
*
************************************************************************/
#include <rtmk.h>
#include <errors.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <conio.h>
#include <string.h>
#include <signal.h>
#include <kbint.h>

#ifdef __cplusplus
   typedef void      (*ftpr)(int);
#else
   typedef void      (*ftpr)(void);
#endif /* __cplusplus */

#define EV_QUIT      0x8000
#define EV_START     0x0001
#define ANY_EVENT    0xffff

void BreakHandler(void);
bool CheckKey(int key);

void Process1(void);
void ApplMain(void);

static PROCESS    applMain;
static PROCESS    process1;

jmp_buf           sysContext;

int main(void)
{
   SetKeyboardInt();
   ApplKeyHitCheck(CheckKey);
   signal(SIGINT, (ftpr )BreakHandler);
   if (RtmkRun() == SUCCESSFUL)
   {
      if (RtmkStartTask(&applMain, ApplMain, 512) != SUCCESSFUL)
      {
         printf("Cannot create ApplMain\n");
         return(0);
      } /* end of if */
      if (!setjmp(sysContext))
         Process1();
   } /* end of if */

   return(0);
} /* main() */

void BreakHandler(void)
{
   RestoreKeyboardInt();
   longjmp(sysContext, 1);
} /* BreakHandler() */

void ApplMain(void)
{
   uint  retVal;
   uint  evMask     = 0x0001;
   char  message[8]  = "MESSAGE";

   /* Wait for Process1 to start */
   retVal = RtmkWait(EV_START);
   RtmkSend(process1, EV_START);
   retVal = 0;
   while (TRUE)
   {
      printf("\nApplMain waiting for event %x ...\n", evMask);
      retVal = RtmkWait(evMask);
      printf("ApplMain received event %x\n", retVal);
      RtmkClear(retVal);
      evMask <<= 1;
      if ((retVal & EV_QUIT))
         break;
      printf("ApplMain sends event %x to Process1\n", evMask);
      RtmkSend(process1, evMask);
   } /* end of while */

   RtmkPut(process1, message);

   while (TRUE)
   {
      if ((retVal = RtmkWait(ANY_EVENT)) == 0)
      {
         RtmkGet(message);
         printf("ApplMain receives message: %s\n", message);
         raise(SIGINT);          /* Quit application */
      } /* end of if */

      printf("ApplMain receives Process1 key hit event: %c\n", (char )retVal);
      RtmkSend(process1, EV_START);
      RtmkClear(ANY_EVENT);
   } /* end of while */
} /* ApplMain() */

void Process1(void)
{
   uint  retVal = 0;
   char  message[8];
   int   c;

   process1 = RtmkCurrent();
   RtmkChangePriority(process1, 10);

   RtmkSend(applMain, EV_START);

   while ((retVal & EV_QUIT) == 0)
   {
      retVal = RtmkWait(0xffff);
      printf("Process1 received event %x\n", retVal);
      RtmkClear(retVal);
      printf("Process1 sends event %x to ApplMain\n", retVal);
      RtmkSend(applMain, retVal);
   } /* end of while */

   while (TRUE)
   {
      while (RtmkEmpty() == FALSE)
      {
#if 0
         if (kbhit())
         {
            c = getch();
            switch (c)
            {
            case 'x':
/*             RtmkChangePriority(1, 4); */
               strcpy(message, "QUIT");
               RtmkPut(applMain, message);
               RtmkWait(0xffff);
               break;
            default:
               RtmkSend(applMain, (uint )c);
               RtmkClear(ANY_EVENT);
               break;
            } /* end of switch */
         } /* end of if */
#else
         SetKeyHitEvent(process1, 1);
         RtmkWait(1);
         raise(SIGINT);
#endif
      } /* end of while */

      RtmkGet(message);
      printf("Process1 received message: %s\n", message);
   } /* end of while */
} /* Process1() */

#pragma argsused
bool CheckKey(int key)
{
   return(TRUE);
} /* CheckKey() */

⌨️ 快捷键说明

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