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

📄 mk_sche.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
                  */
                  begin_time = xmk_NOW();
                #endif
                #ifdef XMK_ADD_CQUERY_PROCESS
                  xmk_ProcessProfiles [ RUN_PROC ].LastTime = 0 ;
                #endif
              #endif

              #ifdef XMK_USE_PREEMPTIVE
                #ifdef XMK_ADD_TSYS_SHOWPRIO
                  /*
                  **    Show Prio Level on MSC if wanted ...
                  */
                  xmk_tsys_ShowPrioLevel (CurrentPrioLevel);
                #endif /* ... XMK_ADD_TSYS_SHOWPRIO */
              #endif /* ... XMK_USE_PREEMPTIVE */

              #ifdef XMK_USE_BANKSW
                /*
                **   Bank-switching
                */
                XMK_SWITCH_BANK(EPIDTYPE(xRunPID));
              #endif

              #if defined(XMK_ADD_MICRO_TESTER) && defined(XMK_ADD_PSC_TRACE)    
                /*
                ** Fill the PSC Info Structure and send it to the host
                */
                PSCTrace.time    = xmk_NOW();
                PSCTrace.process = xRunPID;
                PSCTrace.flag    = XMK_TRUE;
 
                xmk_Cod_Encode (XMK_MICRO_TRACER, CMD_TPSC_TRACE, (char*)&PSCTrace, sizeof( xmk_T_CMD_TPSC_TRACE) );
 
              #endif

              /*
              **   Execute transitionfunction
              */
              #ifdef XMK_USE_PREEMPTIVE
                NextState = TransitionFunction (TmpSymbolNr) ;
              #else
                /*
                ** xmk_SymbolNrVar set appropriate in function entry ...
                */
                NextState = TransitionFunction ( ) ;
              #endif

              #if defined(XMK_ADD_MICRO_TESTER) && defined(XMK_ADD_PSC_TRACE)
                /* 
                ** Fill the PSC Info Structure and send it to the host 
                */ 
                PSCTrace.time    = xmk_NOW();
                PSCTrace.process = xRunPID; 
                PSCTrace.flag    = XMK_FALSE;
                xmk_Cod_Encode (XMK_MICRO_TRACER, CMD_TPSC_TRACE, (char*)&PSCTrace, sizeof( xmk_T_CMD_TPSC_TRACE) );
              #endif

              #ifndef XMK_USE_PREEMPTIVE
                #if defined(XMK_USE_CHECK_TRANS_TIME) || defined(XMK_ADD_CQUERY_PROCESS)
                  /*
                  **   get current system-time
                  */
                  end_time = xmk_NOW();
                #endif

                #ifdef  XMK_USE_CHECK_TRANS_TIME
                  /*
                  **   compare duration of transition with predefined value and call
                  **   error-handling routine if transition duration was too long
                  */
                  if (end_time - begin_time > XMK_TRANS_TIME)
                        ErrorHandler (ERR_N_TRANS_TIME);
                #endif
                 
                #ifdef XMK_ADD_CQUERY_PROCESS
                  xmk_ProcessProfiles[ RUN_PROC ].LastTime = end_time - begin_time ;
                  if (xmk_ProcessProfiles[ RUN_PROC ].LastTime >
                      xmk_ProcessProfiles[ RUN_PROC ].MaxTime)
                  {
                    xmk_ProcessProfiles[ RUN_PROC ].MaxTime = xmk_ProcessProfiles[ RUN_PROC ].LastTime ;
                  }
                #endif
              #endif

              /*
              **   if process-state hasn't changed
              */
              if( NextState != XDASHSTATE )
              {
                XMK_BEGIN_CRITICAL_PATH;
                /*
                **   save nextstate
                */
                p_ReceiverProcess->ProcessStateTable [EPIDINST(xRunPID)] = NextState;
                XMK_END_CRITICAL_PATH;
              }

              /*
              **   remove current signal from the queue
              */
              xmk_RemoveCurrentSignal () ;

              #ifdef XMK_USED_DYNAMIC_STOP
                /*
                **   if receiving instance has performed an SDL-STOP
                */
                if( NextState == XDORMANT )
                {
                  #ifdef XMK_USED_TIMER
                    /*
                    **
                    */
                    xmk_ResetAllTimer( xRunPID) ;
                  #endif
                  /*
                  **   remove all the signals from the queue, that were
                  **   directed to the stopped instance
                  */
                  xmk_RemoveSignalsByProcessID ( xRunPID ) ;

                  /*
                   * Dynamic instance data:
                   * A process instance is being deleted, so we free
                   * the instance data that was allocated to it,
                   * and set the pointer to NULL.
                   */
#ifndef XMK_USED_ONLY_X_1
                  OSConnectorFree (((unsigned char **)(p_ReceiverProcess->pInstanceData))[EPIDINST (xRunPID)]);
                  ((unsigned char **)p_ReceiverProcess->pInstanceData)[EPIDINST (xRunPID)] = 0;
#else
                  OSConnectorFree (p_ReceiverProcess->pInstanceData);
                  p_ReceiverProcess->pInstanceData = 0;
#endif
                } /* END IF */
              #endif /* ... XMK_USED_DYNAMIC_STOP */

              #ifdef XMK_ADD_TSTATE
                /*
                ** Trace the next state operation ...
                */
                xmk_TSDL_State (NextState);
              #endif

              #ifdef XMK_USE_DEBUGGING
                #ifdef XMK_ADD_CBREAK_LOGIC
                  if (NextState == XDASHSTATE)
                    NextState = p_ReceiverProcess->ProcessStateTable [EPIDINST(xRunPID)];

                  /*
                  **  Check whether the current system state is a breakpoint
                  */
                  if (xmk_CheckIfBreakpointTrue(xRunPID, XMK_NO_SIGNAL,
                                                NextState, &BreakHitDescr))
                  {
                    XMK_BEGIN_CRITICAL_PATH;
                      xmk_SystemState |= XMK_BREAKPOINT_HIT;
                    XMK_END_CRITICAL_PATH;

                    #ifdef XMK_ADD_PRINTF_ADDITIONAL
                      PRINTF(("\n\n Breakpoint NextState was hit \n\n"));
                    #endif

                    #ifdef XMK_ADD_MICRO_COMMAND
                      (void) xmk_HandleHostCmd (CMD_BREAK_HIT_IND,
                                                (xmk_U_CMDS *) &BreakHitDescr);
                    #endif
                    return;
                  }
                #endif /* ... XMK_ADD_CBREAK_LOGIC */
              #endif /* ... XMK_USE_DEBUGGING */

              #if defined(XMK_USE_DEBUGGING) || defined(XMK_USE_MICRO_COMMAND) || defined(LAUTERBACH)
                /*
                ** Set xRunPID no longer active, relevant only for
                ** debug, trace and command interface
                */
                xRunPID = xNULLPID;
                #ifdef XMK_USE_PREEMPTIVE
                  CurrentPrioLevel = MAX_PRIO_LEVELS;
                #endif
              #endif

              #ifdef XMK_USE_PREEMPTIVE
                #ifdef XMK_USED_TIMER
                  #ifdef XMK_USE_DEBUGGING
                    /*
                    **  Timer expired check is only to be done
                    **  if timers aren't disabled
                    */
                    if (!(xmk_SystemState & XMK_TIMER_DISABLED))
                  #endif
                      xmk_ChkTimer();
                #endif

                #ifdef XMK_USE_xInEnv
                  xInEnv();
                  #if defined(XMK_USE_DEBUGGING) && (defined(XMK_ADD_CREINIT) || defined(XMK_ADD_CSHUTDOWN))
                    if (xmk_SystemState & (XMK_REINIT_SYSTEM | XMK_SYSTEM_SHUTDOWN) )
                    {
                      XMK_SUPPRESS(xmk_SystemState);
                      return ;
                    }
                  #endif /* ... XMK_ADD_CREINIT */
                #endif
                p_Message = xmk_FirstSignal ();
              #else
                /*
                **   leave signal-handling (leave while - loop)
                */
                p_Message = NULL ;
                break ;
              #endif
            } /* END DEFAULT */
          } /* END SWITCH */
        } /* END IF */
      } /* END WHILE */

  #ifdef XMK_USE_DEBUGGING
    }
  #endif

  #ifdef XMK_ADD_PRINTF_SCHEDULER
    XMK_TRACE_EXIT("*SI*ProcessSignal");
  #endif

  #undef CurrentState
  #undef NextState

} /* END OF FUNCTION */

#if defined(XMK_USED_DYNAMIC_CREATE) || defined(XMK_ADD_CCREATE_PROCESS)

/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
|  Functionname : *SI*CreateProcess                                            |
|  Author       : S&P Media GmbH Germany                                       |
+------------------------------------------------------------------------------+
|                                                                              |
|  Description  :                                                              |
|                                                                              |
|  This function tries to create an instance of the given process-type.        |
|  This can fail, either if there is no allocatable <create-signal>, or        |
|  if there is no free <process-instance> of that type (no instance is         |
|  "DORMANT").                                                                 |
|                                                                              |
|  Parameter    : ProcessID - ID of the processtype                            |
|                                                                              |
|  Return       : ID of the newly created instance (0 .... NMax - 1 )          |
|                 xNULLINST                                                    |
|                    it wasn't possible to create a new instance               |
|                                                                              |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/

/*+FDEF E*/

#ifndef XNOPROTO
  xmk_T_INSTANCE xmk_CreateProcess ( xmk_T_PROCESS ProcessTypeID )
#else
  xmk_T_INSTANCE xmk_CreateProcess ( ProcessTypeID )
  xmk_T_PROCESS ProcessTypeID ;
#endif

/*-FDEF E*/

{
  /*
  **   Defines
  */
  xmk_T_MESSAGE      xmk_RAM_ptr p_CreMsg;     
                                     /* Create-message                      */
  xmk_T_INSTANCE      InstanceID;    /* ID of the created instance          */
  XCONST XPDTBL       xmk_ROM_ptr pProcessType;  
                                     /* pointer to global process           */
                                     /* description table                   */
  xmk_T_BOOL          found;         /* internal value for local search     */
  #ifdef XMK_USED_OFFSPRING
    xPIDTable        xmk_RAM_ptr pCurrentProcessPIDTable ; 
                                                /* Ptr to xPID-table of the */
                                                /* Creating process         */
  #endif

  #ifdef XMK_ADD_PRINTF_SCHEDULER
    XMK_FUNCTION("*SI*CreateProcess");
  #endif

  #if defined(XMK_USE_MAX_ERR_CHECK) && defined(XMK_ADD_CCREATE_PROCESS)
    /*
    ** This error check is unnecessary for generated C code,
    ** but might be necessary if users want to create processes in
    ** their C code.
    **
    ** CAUTION !
    ** ==========
    ** The use of the possibility to create processes in C code is 
    ** not recommended.
    */
    if (! xmk_IfExist ( ProcessTypeID ))
    {  
      ErrorHandler(ERR_N_PID_INDEX);
      return (xNULLINST);
    }  
  #endif /* ... XMK_USE_MAX_ERR_CHECK && XMK_ADD_CCREATE_PROCESS */

  /*
  **   load pointer with process-description-table of current processtype
  */
  pProcessType = xPDTBL [ ProcessTypeID ] ;

  /*
  **   search for a DORMANT-instance
  */
  found = XMK_FALSE;
  for( InstanceID = 0; InstanceID < pProcessType->MaxInstances; InstanceID++ )
  {
    if( pProcessType->ProcessStateTable [ InstanceID ] == XDORMANT )
    {
      found = XMK_TRUE;
      break ;
    } /* END IF */
  } /* END FOR */

  /*
  **   if there is a DORMANT-instance
  */
  if( found )
  {
    /*
    **   try to allocate a create-signal
    */
    p_CreMsg = xmk_AllocSignal () ;

    /*
    **   if allocation failed
    */
    if( p_CreMsg == NULL )
    {
      /*
      **   call error-handling routine
      */
      ErrorHandler (ERR_N_CREATE_NO_MEM);

      /*
      **   prepare return-value to indicate that creation failed

⌨️ 快捷键说明

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