/***************************************************************************** * file: flipflop.c * * Purpose: * * This file uses the OLC architecture to simulate the divide-by-8 * counter as descriped in problem (3) of the 91.522 Midterm Exam, * Tues. March 7, 1995 * * #include file names have changed to account for the <8>.<3> filename * and extension restrictions of DOS. * * This program has been built and executed successfully on a PC * using the Borland C/C++ compiler. * * OLC Debugger (OLCDBG) hooks can be enabled by adding * "-DOLCDBG" to the compiler flags. */ #define MAIN #include #include #include #ifdef PCDOS #include #include #endif #include "olc96fa.h" /* OLC Fall Semester 96 schema input file */ #include "olc3common.h" #include "activeclass.h" #include "activeinstance.h" #include "eventinstance.h" #include "statemodel.h" #include "processevent.h" #include "dbutils.h" /* ** Toggle FlipFlop (TF) SetUp and Action routines */ PROTOTYPE(extern void TFsetup, (void)) PROTOTYPE(extern void TFAction0, (hcg_key EIid)) PROTOTYPE(extern void TFAction1, (hcg_key EIid)) /* ** Timer SetUp and Action routines */ PROTOTYPE(extern void TIsetup, (void)) PROTOTYPE(extern void TIAction1, (hcg_key EIid)) PROTOTYPE(extern void TIAction2, (hcg_key EIid)) PROTOTYPE(extern void TIAction3, (hcg_key EIid)) PROTOTYPE(extern void TIAction4, (hcg_key EIid)) /* ** OLC Debugger (OLCDBG) SetUp and Action routines */ PROTOTYPE(extern void DBsetup, (void)) PROTOTYPE(extern void DBAction1, (hcg_key EIid)) /* Debugger Action Routines */ /* ** Periodic Clock (CK) SetUp and Action routines */ PROTOTYPE(extern void CKsetup, (void)) PROTOTYPE(extern void CKAction0, (hcg_key EIid)) PROTOTYPE(extern void CKAction1, (hcg_key EIid)) PROTOTYPE(extern void CKAction2, (hcg_key EIid)) PROTOTYPE(extern void CKAction3, (hcg_key EIid)) #ifdef OLCDBG void init_db(); void get_db_cmd() ; #endif /* */ /* ** Main Program */ int main( int argc, char **argv) { ActionRoutine *ActionList[12]; struct ST *tmp ; int i ; int ttg = 1 ; int SimulatedTime = 0; int RealToSimulated = 1; pr_init("flipflop.vdf", ""); /* ** Create the state models completely */ #ifdef NETWORK pr_load("JuicePlant","run1.ok1"); ActionList[0] = TFAction0; ActionList[1] = TFAction1; ActionList[2] = TIAction1; ActionList[3] = TIAction2; ActionList[4] = TIAction3; ActionList[5] = TIAction4; ActionList[6] = CKAction0; ActionList[7] = CKAction1; ActionList[8] = CKAction2; ActionList[9] = CKAction3; for (i=0,tmp=ST; tmp!=0; tmp=tmp->next_ptr, i++) tmp->ActFunc = ActionList[i] ; #else TFsetup(); TIsetup(); CKsetup() ; pr_dump("JuicePlant","run1.dat",2,"w"); #endif /* ** Generate event to jump start divide-by-8 counter */ GenerateEvent("CK1", "CK1", "CK00", 0, 0, 0.0, 0.0, "TI1"); #ifdef OLCDBG init_db() ; for (;;) get_db_cmd() ; #endif for(SimulatedTime = 0; SimulatedTime < 50; SimulatedTime += 1) { printf("At time %d\n", SimulatedTime); ProcessEvents(EventQueueOrder, 1); sleep(RealToSimulated); } #ifdef NETWORK pr_dump("JuicePlant","run1.dat",2,"a"); #endif return 0 ; }