ReturnType KITECH_HSVColorRecognitionComp::onStop() { #if defined(WIN32) Sleep(100); #endif if(parameter.FindName("DBName")) { SetDataToDB(parameter.GetValue("DBName").c_str()); } return OPROS_SUCCESS; }
void loop() { int i, j; // delay(1); GPIO_SET(CLK); delay(1); GPIO_SET(CLK); clkCountHi = 1; clkCount++; T++; tracePauseCount++; ReadControlState(); GetAddressFromAB(); if (Mlast==1 && m1==0) T = 1, m1Count++; Mlast = m1; bool suppressDump = false; if (!traceRefresh & !rfsh) suppressDump = true; // If the number of M1 cycles has been reached, skip the rest since we dont // want to execute this M1 phase if (m1Count==stopAtM1) { sprintf(extraInfo, "Number of M1 cycles reached"), running = false; printf("-----------------------------------------------------------+\r\n"); goto control; } // If the address is tri-stated, skip checking various combinations of // control signals since they may also be floating and we can't detect that if (!abTristated) { // Simulate read from RAM if (!mreq && !rd) { SetDataToDB(ram[ab & 0xFFFF]); if (!m1) sprintf(extraInfo, "Opcode read from %03X -> %02X", ab, ram[ab & 0xFF]); else sprintf(extraInfo, "Memory read from %03X -> %02X", ab, ram[ab & 0xFF]); if (++ab % 0x1000 == 0) printf("%04X\n",ab); } else // Simulate interrupt requesting a vector if (!m1 && !iorq) { SetDataToDB(iorqVector); sprintf(extraInfo, "Pushing vector %02X", iorqVector); } else GetDataFromDB(); // Simulate write to RAM if (!mreq && !wr) { ram[ab & 0xFFFF] = db; sprintf(extraInfo, "Memory write to %03X <- %02X", ab, db); } // Detect I/O read: We don't place anything on the bus if (!iorq && !rd) { sprintf(extraInfo, "I/O read from %03X", ab); } // Detect I/O write if (!iorq && !wr) { sprintf(extraInfo, "I/O write to %03X <- %02X", ab, db); } // Capture memory refresh cycle if (!mreq && !rfsh) { sprintf(extraInfo, "Refresh address %03X", ab); } } else GetDataFromDB(); DumpState(suppressDump); // If the user wanted to pause simulation after a certain number of // clocks, handle it here. If the key pressed to continue was not Enter, // stop the simulation to issue that command if (tracePause==tracePauseCount) { tracePauseCount = 0; } //-------------------------------------------------------- // Clock goes low //-------------------------------------------------------- //delay(1); digitalWrite(CLK, LOW); delay(1); digitalWrite(CLK, LOW); clkCountHi = 0; if (traceShowBothPhases) { ReadControlState(); GetAddressFromAB(); DumpState(suppressDump); } // Perform various actions at the requested clock number // if the count is positive (we start it at -2 to skip initial 2T) if (clkCount>=0) { if (clkCount==intAtClk) zint = 0; if (clkCount==nmiAtClk) nmi = 0; if (clkCount==busrqAtClk) busrq = 0; if (clkCount==resetAtClk) reset = 0; if (clkCount==waitAtClk) wait = 0; // De-assert all control pins at this clock number if (clkCount==clearAtClk) zint = nmi = busrq = reset = wait = 1; WriteControlPins(); // Stop the simulation under some conditions if (clkCount==stopAtClk) sprintf(extraInfo, "Number of clocks reached"), running = false; if (stopAtHalt&!halt) sprintf(extraInfo, "HALT instruction"), running = false; } //-------------------------------------------------------- // Trace/simulation control handler //-------------------------------------------------------- control: if (!running) { printf(":Simulation stopped: %s\r\n", extraInfo); extraInfo[0] = 0; digitalWrite(CLK, HIGH); zint = nmi = busrq = wait = 1; WriteControlPins(); while(!running) { // Expect a command from the serial port // if (Serial.available()>0) { memset((void *)temp, 0, TEMP_SIZE); gets(temp); //Serial.readBytesUntil('\r', temp, TEMP_SIZE-1); // Option ":" : this is not really a user option. This is used to // Intel HEX format values into the RAM buffer // Multiple lines may be pasted. They are separated by a space character. char *pTemp = temp; while (*pTemp==':') { byte bytes = hexFromTemprintf(pTemp, 0); if (bytes>0) { int address = (hexFromTemprintf(pTemp, 1)<<8) + hexFromTemprintf(pTemp, 2); byte recordType = hexFromTemprintf(pTemp, 3); printf("%04X:", address); for (i=0; i<bytes; i++) { ram[(address + i) & 0xFF] = hexFromTemprintf(pTemp, 4+i); printf(" %02X", hexFromTemprintf(pTemp, 4+i)); } printf("\r\n"); } pTemp += bytes*2 + 12; // Skip to the next possible line of hex entry } // Option "r" : reset and run the simulation if (temp[0]=='r') { // If the variable 9 (Issue RESET) is not set, perform a RESET and run the simulation. // If the variable was set, skip reset sequence since we might be testing it. if (resetAtClk<0) DoReset(); running = true; } // Option "sc" : clear simulation variables to their default values if (temp[0]=='s' && temp[1]=='c') { ResetSimulationVars(); temp[1] = 0; // Proceed to dump all variables... } // Option "s" : show and set internal control variables if (temp[0]=='s' && temp[1]!='c') { // Show or set the simulation parameters int var = 0, value; int args = sscanf(&temp[1], "%d %d\r\n", &var, &value); // Parameter for the option #12 is read in as a hex; others are decimal by default if (var==12) args = sscanf(&temp[1], "%d %x\r\n", &var, &value); if (args==2) { if (var==0) traceShowBothPhases = value; if (var==1) traceRefresh = value; if (var==2) tracePause = value; if (var==3) stopAtClk = value; if (var==4) stopAtM1 = value; if (var==5) stopAtHalt = value; if (var==6) intAtClk = value; if (var==7) nmiAtClk = value; if (var==8) busrqAtClk = value; if (var==9) resetAtClk = value; if (var==10) waitAtClk = value; if (var==11) clearAtClk = value; if (var==12) iorqVector = value & 0xFF; } printf("------ Simulation variables ------\r\n"); printf("#0 Trace both clock phases = %d\r\n", traceShowBothPhases); printf("#1 Trace refresh cycles = %d\r\n", traceRefresh); printf("#2 Pause for keypress every = %d\r\n", tracePause); printf("#3 Stop after clock # = %d\r\n", stopAtClk); printf("#4 Stop after # M1 cycles = %d\r\n", stopAtM1); printf("#5 Stop at HALT = %d\r\n", stopAtHalt); printf("#6 Issue INT at clock # = %d\r\n", intAtClk); printf("#7 Issue NMI at clock # = %d\r\n", nmiAtClk); printf("#8 Issue BUSRQ at clock # = %d\r\n", busrqAtClk); printf("#9 Issue RESET at clock # = %d\r\n", resetAtClk); printf("#10 Issue WAIT at clock # = %d\r\n", waitAtClk); printf("#11 Clear all at clock # = %d\r\n", clearAtClk); printf("#12 Push IORQ vector #(hex) = %2X\r\n", iorqVector); } // Option "m" : dump RAM memory if (temp[0]=='m' && temp[1]!='c') { // Dump the content of a RAM buffer printf(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\r\n"); printf(" +-----------------------------------------------\r\n"); for(i=0; i<16; i++) { printf("%02X |", i); for(j=0; j<16; j++) { printf("%02X ", ram[i*16+j]); } printf("\r\n"); } } // Option "mc" : clear RAM memory if (temp[0]=='m' && temp[1]=='c') { memset(ram, 0, sizeof(ram)); printf("RAM cleared\r\n"); } // Option "?" : print help if (temp[0]=='?' || temp[0]=='h') { printf("s - show simulation variables\r\n"); printf("s #var value - set simulation variable number to a value\r\n"); printf("sc - clear simulation variables to their default values\r\n"); printf("r - restart the simulation\r\n"); printf(":INTEL-HEX - reload RAM buffer with a given data stream\r\n"); printf("m - dump the content of the RAM buffer\r\n"); printf("mc - clear the RAM buffer\r\n"); } } } } //return 0; } // main