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

📄 ttkernel.h

📁 一个很棒的网络控制系统仿真软件
💻 H
字号:
#ifndef __TT_KERNEL_H__#define __TT_KERNEL_H__#include "mex.h"#include <string.h>#include <math.h>#include "linkedlist.cpp"#include "job.h"#include "blockdata.h"#include "task.h"#include "handler.h"#include "monitor.h"#include "event.h"#include "trigger.h"#include "timer.h"#include "mailbox.h"#include "ttnetwork.h"#include "network.h"#include "mexhelp.h"#define EPS 1.0E-10  // Numerical precision#define INF 1000000.0enum { FP, RM, DM, EDF };enum { RELEASE, START, SUSPEND, RESUME, FINISH };#define FINISHED -1.0    void init(void);void cleanup(void);class RTsys { public:  bool initialize; // false when the simulation is running  bool error;      // true if simulation should stop    int nbrOfInputs;  int nbrOfOutputs;  int nbrOfTasks;  int nbrOfHandlers;  int nbrOfMonitors;  int nbrOfTriggers;  int nbrOfSchedTasks;  int nbrOfSchedHandlers;  int nbrOfSchedMonitors;    double time;      // Current time in simulation  double prevHit;   // Previous invocation of kernel  double nextHit;   // Next invocation of kernel  double *inputs;          // Vector of input port values  double *outputs;         // Vector of output port values  double *interruptinputs;   double *oldinterruptinputs;  double *taskSched;     // Vector of values for the task schedule  double *handlerSched;  // Vector of values for the handler schedule  double *monitorGraph;  // Vector of values for the monitor graph  Task* running;          // Currently running task  Task* executing;        // Task executing its code function  Handler* activeHandler; // Currently running interrupt handler  List* readyQ;   // Contains tasks ready for execution  List* timeQ;    // Contains tasks waiting for new release  List* handlerQ; // Contains handlers ready for execution  List* timerQ;   // Contains timers set in the future   List *taskList;      List *handlerList;  List *monitorList;  List *eventList;  List *triggerList;  List *mailboxList;  double (*prioFcn)(Task*); // Priority function   bool simContextSwitch;    // true if context switches are simulated  bool savedContext;  double contextSwitchTime; // Time for a full context switch  Handler* kernelHandler;   // Handler simulating context switches  // NETWORK   int nbrOfNetworks;  double *nwSnd;      // snd output   double *networkinputs;  double *oldnetworkinputs;  List *networkList;  // Function pointers  double (*contextSwitchCode)(int, void*); // Code function for context switch handler  double (*periodicTaskHandlerCode)(int, void*);  // Code function for ...   int (*timeQCmpFcn)(Node* , Node*);  int (*readyQCmpFcn)(Node* , Node*);  int (*handlerQCmpFcn)(Node* , Node*);  int (*timerQCmpFcn)(Node* , Node*);  int (*jobQCmpFcn)(Node* , Node*);  void (*default_release)(Task*);  void (*default_start)(Task*);  void (*default_suspend)(Task*);  void (*default_resume)(Task*);  void (*default_finish)(Task*);  double (*prioFP)(Task*);  double (*prioRM)(Task*);  double (*prioEDF)(Task*);  double (*prioDM)(Task*);  RTsys(); // constructor  ~RTsys(); // deconstuctor};RTsys::RTsys() {  initialize = false;  error = false;  nbrOfInputs = 0;  nbrOfOutputs = 0;  nbrOfTasks = 0;  nbrOfHandlers = 0;  nbrOfMonitors = 0;  nbrOfTriggers = 0;  nbrOfSchedTasks = 0;  nbrOfSchedHandlers = 0;  nbrOfSchedMonitors = 0;    time = 0.0;  prevHit = 0.0;  nextHit = 0.0;  inputs = NULL;     outputs = NULL;    interruptinputs = NULL;   oldinterruptinputs = NULL;  taskSched = NULL;  handlerSched = NULL;  monitorGraph = NULL;  running = NULL;  executing = NULL;  activeHandler = NULL;  readyQ = NULL;  timeQ = NULL;  handlerQ = NULL;  timerQ = NULL;  taskList = NULL;  handlerList = NULL;  monitorList = NULL;  eventList = NULL;  triggerList = NULL;  mailboxList = NULL;  prioFcn = NULL;    nbrOfNetworks = 0;  nwSnd = NULL;    networkinputs = NULL;  oldnetworkinputs = NULL;}RTsys::~RTsys() {  if (inputs) delete[] inputs;  if (outputs) delete[] outputs;  if (interruptinputs) delete[] interruptinputs;  if (oldinterruptinputs) delete[] oldinterruptinputs;  if (taskSched) delete[] taskSched;  if (handlerSched) delete[] handlerSched;  if (monitorGraph) delete[] monitorGraph;  if (nwSnd) delete[] nwSnd;  if (networkinputs) delete[] networkinputs;  if (oldnetworkinputs) delete[] oldnetworkinputs;  if (readyQ) delete readyQ;  if (timeQ) delete timeQ;  if (handlerQ) delete handlerQ;    if (timerQ) {    TimerNode* tin = (TimerNode*) timerQ->getFirst();    while (tin != NULL) {      delete tin->getTimer();      tin = (TimerNode*) tin->getNext();    }    delete timerQ;  }  if (taskList) {    TaskNode* tn = (TaskNode*) taskList->getFirst();    while (tn != NULL) {      delete tn->getTask();      tn = (TaskNode*) tn->getNext();    }    delete taskList;  }  if (handlerList) {    HandlerNode* hn = (HandlerNode*) handlerList->getFirst();    while (hn != NULL) {      delete hn->getHandler();      hn = (HandlerNode*) hn->getNext();    }    delete handlerList;  }  if (monitorList) {    MonitorNode* mn = (MonitorNode*) monitorList->getFirst();    while (mn != NULL) {      delete mn->getMonitor();      mn = (MonitorNode*) mn->getNext();    }    delete monitorList;  }  if (eventList) {    EventNode* en = (EventNode*) eventList->getFirst();    while (en != NULL) {      delete en->getEvent();      en = (EventNode*) en->getNext();    }    delete eventList;  }  if (triggerList) {    TriggerNode* trn = (TriggerNode*) triggerList->getFirst();    while (trn != NULL) {      delete trn->getTrigger();      trn = (TriggerNode*) trn->getNext();    }    delete triggerList;  }    if (mailboxList) {    MailboxNode* mbn = (MailboxNode*) mailboxList->getFirst();    while (mbn != NULL) {      delete mbn->getMailbox();      mbn = (MailboxNode*) mbn->getNext();    }    delete mailboxList;  }   if (networkList) {    NetworkNode* nn = (NetworkNode*) networkList->getFirst();    while (nn != NULL) {      delete nn->getNetwork();      nn = (NetworkNode*) nn->getNext();    }    delete networkList;  } }  #endif // __TT_KERNEL_H__

⌨️ 快捷键说明

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