static void issueDelayReqTimerExpired(PtpClock *ptpClock) { switch (ptpClock->portDS.delayMechanism) { case E2E: if(ptpClock->portDS.portState != PTP_SLAVE) { break; } if (timerExpired(DELAYREQ_INTERVAL_TIMER, ptpClock->itimer)) { timerStart(DELAYREQ_INTERVAL_TIMER, getRand(pow2ms(ptpClock->portDS.logMinDelayReqInterval + 1)), ptpClock->itimer); DBGV("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n"); issueDelayReq(ptpClock); } break; case P2P: if (timerExpired(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer)) { timerStart(PDELAYREQ_INTERVAL_TIMER, getRand(pow2ms(ptpClock->portDS.logMinPdelayReqInterval + 1)), ptpClock->itimer); DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n"); issuePDelayReq(ptpClock); } break; default: break; } }
void MB_byte_received_cb(uint8_t chr) { //printf("%x ", chr); if (txState != TX_STATE_IDLE) { return; } switch(rxState) { case RX_STATE_INIT : //Wait 3.5 chars, required for ModBus initialization timerStart((uint16_t)(7 * tChar / 2), MB_t35Expired_cb); break; case RX_STATE_IDLE : //First byte of Serial PDU received mbBufferPosition = 0; mbBuffer[mbBufferPosition++] = chr; rxState = RX_STATE_RCV; timerStart((uint16_t)(3 * tChar / 2), MB_t15Expired_cb); break; case RX_STATE_RCV : //Next byte of Serial PDU received if (mbBufferPosition < MB_SIZE_MAX + 1) { mbBuffer[mbBufferPosition++] = chr; //Save byte to buffer } else { //Buffer overflow occurred mbEvent = MB_EVENT_ERROR; rxState = RX_STATE_INIT; } timerStart((uint16_t)(3 * tChar / 2), MB_t15Expired_cb); break; case RX_STATE_T35EXPECTED : //t15 interval passed from last byte, but t35 not mbEvent = MB_EVENT_ERROR; rxState = RX_STATE_INIT; break; } }
int main() { // Example 1 [-1,1] a = -1.0; b = 1.0; n = 1000; int curr_num_threads[3] = {2, 50, 100}; for (int i=0; i<3; i++) { approx = 0; thread_count = curr_num_threads[i]; printf("\nRun with %d threads\n", thread_count); timerStart(); run_threads(); printf("Took %ld ms\n", timerStop()); printf("a:%f\t b:%f\t n:%d\t actual:%f\t approximation:%f\n", a, b, n, NEG_1_TO_POS_1, approx); } // Example 2 [0,10] a = 0.0; b = 10.0; n = 1000; for (int i=0; i<3; i++) { approx = 0; thread_count = curr_num_threads[i]; printf("\nRun with %d threads\n", thread_count); timerStart(); run_threads(); printf("Took %ld ms\n", timerStop()); printf("a:%f\t b:%f\t n:%d\t actual:%f\t approximation:%f\n", a, b, n, ZERO_TO_POS_10, approx); } return 0; }
void trainIterationA(svd_entry * users, svd_entry * movies, float l, data_entry* trainset, float* temporary, int trainsize) { float t,h = 0; svd_entry *u, *m; data_entry *tt; timerStart(1); for (int i = 0; i < trainsize; i++) { tt = &trainset[i]; temporary[i] = l*(tt->rating - predict(users, movies, tt->user_ptr, tt->movie_ptr)); } printf("---errors:%.3f\n", timerGetS(1)); for (int i = 0; i < SVD_dim; i++) { timerStart(1); for (int j = 0; j < trainsize; j++) { u = &users[trainset[j].user_ptr]; m = &movies[trainset[j].movie_ptr]; h = u->params[i]; t = temporary[j]; u->params[i] += t*m->params[i]; m->params[i] += t*h; } } }
bool onOffDelayUpdate(OnOffDelay* me, bool Trg) { switch (me->state) { case S0: if (Trg) { me->state = S1; timerStart(me->timer, me->TH); } break; case S1: if (Trg) { if (timerExpired(me->timer)) { me->state = S2; } } else { me->state = S0; } break; case S2: if (!Trg) { me->state = S3; timerStart(me->timer, me->TL); } break; case S3: if (!Trg) { if (timerExpired(me->timer)) { me->state = S0; } } else { me->state = S0; } break; } return onOffDelayOutput(me); }
bool videoVBL() { if(!videoPlaying) return false; while(videoFrames == 0) swiWaitForVBlank(); videoFrames--; printf("\x1b[13;1HOVERHEAD: %d ", videoFrames); timerStart(0, ClockDivider_1024, 0, NULL); bool ok = videoReadFrame(); int dd = timerElapsed(0)/ (BUS_CLOCK / 100 / 60 / 1024); printf("\x1b[11;1HREAD TIME: %d %% ", dd); timerStop(0); if(!ok) return false; timerStart(0, ClockDivider_1024, 0, NULL); videoDecodeFrame(); dd = timerElapsed(0)/ (BUS_CLOCK / 100 / 60 / 1024); printf("\x1b[12;1HDISP TIME: %d %% ", dd); timerStop(0); printf("\x1b[14;1HFRAME SIZE: %d ", videoFrameLen); return true; }
// Main method int main(int argc, char* argv[]) { int N; double elapsedTime; // checking parameters if (argc != 2 && argc != 4) { printf("Parameters: <N> [<fileA> <fileB>]\n"); return 1; } N = atoi(argv[1]); initMatrixes(N); // reading files (optional) if(argc == 4){ readMatrixFile(A,N,argv[2]); readMatrixFile(B,N,argv[3]); } else { // Otherwise, generate two random matrix. for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { A[i][j] = rand() % 5; B[i][j] = rand() % 5; } } } // Do simple multiplication and time it. timerStart(); simpleMM(N); printf("Simple MM took %ld ms\n", timerStop()); // Do strassen multiplication and time it. timerStart(); strassenMM(N); printf("Strassen MM took %ld ms\n", timerStop()); if (compareMatrix(C, R, N) != 0) { if (N < 20) { printf("\n\n------- MATRIX C\n"); printMatrix(C,N); printf("\n------- MATRIX R\n"); printMatrix(R,N); } printf("Matrix C doesn't match Matrix R, if N < 20 they will be printed above.\n"); } // stopping timer cleanup(); return 0; }
/** * @details * Runs the pipeline. * * This method is run repeatedly by the pipeline application every time * data matching the requested remote data is available until either * the pipeline application is killed or the method 'stop()' is called. */ void UdpBFPipeline::run(QHash<QString, DataBlob*>& remoteData) { timerStart(&_totalTime); // Get pointer to the remote time series data blob. // This is a block of data containing a number of time series of length // N for each sub-band and polarisation. timeSeries = (TimeSeriesDataSetC32*) remoteData[_streamIdentifier]; dataOutput( timeSeries, _streamIdentifier); // Run the polyphase channeliser. // Generates spectra from a blocks of time series indexed by sub-band // and polarisation. ppfChanneliser->run(timeSeries, spectra); // Convert spectra in X, Y polarisation into spectra with stokes parameters. stokesGenerator->run(spectra, stokes); // Clips RFI and modifies blob in place weightedIntStokes->reset(stokes); timerStart(&_rfiClipperTime); rfiClipper->run(weightedIntStokes); timerUpdate(&_rfiClipperTime); dataOutput(&(weightedIntStokes->stats()), "RFI_Stats"); stokesIntegrator->run(stokes, intStokes); // Calls output stream managed->send(data, stream) the output stream // manager is configured in the xml. dataOutput(intStokes, "SpectrumDataSetStokes"); // stop(); if (_iteration % 100 == 0) cout << "Finished the CV beamforming pipeline, iteration " << _iteration << " out of " << _totalIterations << endl; _iteration++; if (_iteration == _totalIterations) stop(); #ifdef TIMING_ENABLED timerUpdate(&_totalTime); if( _iteration % 100 == 0 ) { timerReport(&_rfiClipperTime, "RFI_Clipper"); timerReport(&_totalTime, "Pipeline Time (excluding adapter)"); std::cout << std::endl; } #endif }
void SoundEngine::initStreaming(int timerChannel) { memset(buffer, 0, sizeof buffer); bufferIndex = 0; /* * Next timer tick will populate the first half of the buffer * (bufferIndex=0) but by the time we get there, the audio * hardware will already be started on the second half. We want * the sound hardware and Timer 0 to stay synchronized, so that * they're always operating on opposite halves of 'buffer'. */ timerStart(timerChannel, ClockDivider_256, timerFreqToTicks_256(SAMPLE_RATE / SAMPLES_PER_FRAME), timerCallback); /* * Start playing a circular sound buffer that holds 2 frames. */ SCHANNEL_SOURCE(CHANNEL_PCSPEAKER) = (uint32_t) &buffer[0]; SCHANNEL_REPEAT_POINT(CHANNEL_PCSPEAKER) = 0; SCHANNEL_LENGTH(CHANNEL_PCSPEAKER) = BUFFER_SIZE / sizeof(uint32_t); SCHANNEL_TIMER(CHANNEL_PCSPEAKER) = SOUND_FREQ(SAMPLE_RATE); SCHANNEL_CR(CHANNEL_PCSPEAKER) = SCHANNEL_ENABLE | SOUND_VOL(127) | SOUND_PAN(64) | SOUND_REPEAT | SOUND_FORMAT_8BIT; }
void testTimer(void) { unsigned int count = 0; signed int ms = 0; signed int ss = 0; timerClearCount(HW_TIMER2); timerBegin(__CLK__FREQUENCY,__GSM_MODEM_TIMEOUT_US,HW_TIMER2); timerEnableInterrupt(HW_TIMER2); timerStart(HW_TIMER2); while(1) { if(timerCount2 >= 1000) { timerCount2 = 0; ms++; /* if(ms == 1000) { ms = 0; ss++; SerialIntWrite(ss,10); Serialwrite(LF); }*/ SerialIntWrite(ms,10); Serialwrite(LF); } } }
/** * \fn U8 realTimeInit(U32 tickPeriod) * @brief Initialised the Real-Time system to a specified sysTick period * @note Intensive Computation, used only at init time. * Keep the value between 100 and 64 535 000 to be accurate and useful * Use the Hardware Timer 1 * Use a dividable number by 1000 to assure precision of the software rtcc * @arg U32 tickPeriod Desired period of a sysTick (in µs) * @return U8 errorCode STD Error Code (return STD_EC_SUCCESS if successful) */ U8 realTimeInit(U32 tickPeriod) { // -- Init and set the Timer 1 -- // timerInit(RT_TIMER_ID,TMR_CS_PBCLK|TMR_FRZ_STOP); //Timer 1 is based off PBCLK (and freezed in debug mode) timerSetOverflow(RT_TIMER_ID,tickPeriod); //Set the overflow time to the desired sysTick period intFastSetPriority(RT_TIMER_INT_ID,7); //Set the Timer 1 interrupt to max priority intFastSetSubPriority(RT_TIMER_INT_ID,3); intFastEnable(RT_TIMER_INT_ID); //Enable Timer 1 interrupt // ------------------------------ // sysTickValue = tickPeriod; //Save the tick period in µs // -- Init the soft rtcc if needed -- // #if RTCC_SYSTEM == RTCC_SOFTWARE rtTimeClear(&rtccTime); #endif // ---------------------------------- // // -- Reset the up-time -- // rtTimeClear(&upTime); // ----------------------- // //Start the timer timerStart(RT_TIMER_ID); return STD_EC_SUCCESS; }
/* Main function */ int main(int argc, char** argv){ char* trainingFile, * trainingTargetFile, * testingFile; double duration = 0; verbose = 0; if(getenv("VERBOSE") != 0) { verbose = atoi(getenv("VERBOSE")); } /* read num inputs/outputs nodes */ numInputNodes = atoi(argv[1]); numOutputNodes = atoi(argv[2]); numTrainingSamples = atoi(argv[3]); numTestSamples = atoi(argv[4]); /* read the number of Hidden layers in net */ numHiddenLayers = atoi(argv[5]); neuronsPerLayer = atoi(argv[6]); /* read learning rate */ learningRate = atof(argv[7]); /* read testing data file */ testingFile = argv[8]; /* read training data file */ trainingFile = argv[9]; /* read training target data */ trainingTargetFile = argv[10]; /* initialize the neural network */ InitNeuralNet(); InitSamples(numTrainingSamples, numTestSamples); ReadFile(trainingFile, numInputNodes, numTrainingSamples, trainingSamples); ReadFile(trainingTargetFile, numOutputNodes, numTrainingSamples, trainingTargets); ReadFile(testingFile, numInputNodes, numTestSamples, testSamples); /* train the neural network */ timerStart(); Train(); duration = timerStop(); printf("Duration: %f seconds\n", (duration)); Test(); cleanUp(); return 0; }
void statusInit(uintmax_t gaugemax, uint_fast8_t features, wchar_t *format, ...) { va_list va; va_start(va, format); vswprintf(status_caption, _MAX_LFN + 1, format, va); va_end(va); *status_value = 0; if (gaugemax) { progress_screen = &bottomScreen; progress_rect = style.gaugeRect; progress_frame = style.gaugeFrameColor; progress_done = style.gaugeDoneColor; progress_back = style.gaugeBackColor; progress_textcolor = style.gaugeTextColor; progress_fontsize = 30; progress_posmax = gaugemax; progress_offset = 0; progress_pos = -1; if ((status_features = features) & STATUS_CANCELABLE) swprintf(status_value, _MAX_LFN + 1, lang(SF2_PRESS_BUTTON_ACTION), lang(S_BUTTON_B), lang(S_CANCEL)); timerStart(); progressSetPos(0); } else { statusDrawStart(); statusDrawFinish(); } }
void SnmpTest::onEventInit() { timerStart(); //Snmp request object snmpRequest_ = SnmpRequest::instance(this); snmpRequest_->moveToThread(&myThread_); //Register the object for receive messages connect(snmpRequest_, SIGNAL(eventSnmpResponse(QSharedPointer<SnmpData>)), this, SLOT(onEventSnmpResponse(QSharedPointer<SnmpData>)), Qt::UniqueConnection); //Snmp traps object snmpTrap_ = SnmpTrap::instance(this); snmpTrap_->moveToThread(&myThread_); //Register the object for receive messages connect(snmpTrap_, SIGNAL(eventSnmpReceiveTrap(QSharedPointer<SnmpTrapData>)), this, SLOT(onEventSnmpReceiveTrap(QSharedPointer<SnmpTrapData>)), Qt::UniqueConnection); myThread_.start(); //Run test //test(); timerEvent(NULL); }
bool offDelayUpdate(OffDelay* me, bool Trg, bool R) { if (R) { me->state = S0; } else { switch (me->state) { case S0: if (Trg) { me->state = S1; } break; case S1: if (!Trg) { timerStart(me->timer, me->T); me->state = S2; } break; case S2: if (Trg) { me->state = S1; } else { if (timerExpired(me->timer)) { me->state = S0; } } break; } } return offDelayOutput(me); }
void packetHandler(int packetID, int readlength) { static char data[4096]; // static int bytesRead = 0; // Not used // Wifi_RxRawReadPacket: Allows user code to read a packet from within the WifiPacketHandler function // long packetID: a non-unique identifier which locates the packet specified in the internal buffer // long readlength: number of bytes to read (actually reads (number+1)&~1 bytes) // unsigned short * data: location for the data to be read into // bytesRead = Wifi_RxRawReadPacket(packetID, readlength, (unsigned short *)data); // Not used Wifi_RxRawReadPacket(packetID, readlength, (unsigned short *)data); // Check this is the right kind of packet if (data[32] == 'Y' && data[33] == 'O') { u8 command = data[34]; u8 val = data[35]; int sendid = *((int*)(data+36)); if (lastSendid == sendid) { if (!(ioRam[0x02] & 0x01)) { nifiSendid--; sendPacketByte(56, linkSendData); nifiSendid++; } return; } lastSendid = sendid; if (command == 55 || command == 56) { //printLog("%d: Received %x\n", ioRam[0x02]&1, val); linkReceivedData = val; } //linkReceivedData = 0; switch(command) { // Command sent from "internal clock" case 55: if (ioRam[0x02] & 0x80) { // Falls through to case 56 } else { printLog("Not ready!\n"); transferWaiting = true; timerStart(2, ClockDivider_64, 10000, transferWaitingTimeoutFunc); break; } // Internal clock receives a response from external clock case 56: transferReady = true; cyclesToExecute = -1; nifiSendid++; break; default: //printLog("Unknown packet\n"); break; } } }
void SDL_StartTicks(void) { timer_ticks = 0; /* Set timer 2 to fire every ms. */ timerStart(2, ClockDivider_1024, TIMER_FREQ_1024(1000), NDS_TimerInterrupt); }
bool debounceUpdate(Debounce* me, bool i) { switch (me->state) { case S0: // init timerInit(me->timer); timerSingleShot(me->timer); me->state = S1; break; case S1: // steady state if (i) { // rising edge of input timerStart(me->timer, DEBOUNCE_TIME); me->state = S2; } break; case S2: // input is high if (i) { if (timerExpired(me->timer)) { // if it is high for the debounce time me->state = S3; // it is considered high for the observer (output) } } else { me->state = S1; } break; case S3: // input is steady high if (!i) { // if it goes low next state timerStart(me->timer, DEBOUNCE_TIME); me->state = S4; } break; case S4: if (!i) { if (timerExpired(me->timer)) { me->state = S1; } } else { me->state = S3; } break; } return debounceOutput(me); }
/* * This function arms the timer with a uniform range, as requested by page 105 of the standard (for sending delayReqs.) * actual time will be U(0, interval * 2.0); * * PTPv1 algorithm was: * ptpClock->R = getRand(&ptpClock->random_seed) % (PTP_DELAY_REQ_INTERVAL - 2) + 2; * R is the number of Syncs to be received, before sending a new request * */ void timerStart_random(UInteger16 index, float interval, IntervalTimer * itimer) { float new_value; new_value = getRand() * interval * 2.0; DBG2(" timerStart_random: requested %.2f, got %.2f\n", interval, new_value); timerStart(index, new_value, itimer); }
int main() { consoleDemoInit(); uint ticks = 0; TimerStates state = timerState_Stop; int down = keysDown(); while(!(down & KEY_START)) { swiWaitForVBlank(); consoleClear(); scanKeys(); down = keysDown(); if(state == timerState_Running) { ticks += timerElapsed(0); } if(down & KEY_A) { if(state == timerState_Stop) { timerStart(0, ClockDivider_1024, 0, NULL); state = timerState_Running; } else if(state == timerState_Pause) { timerUnpause(0); state = timerState_Running; } else if(state == timerState_Running) { ticks += timerPause(0); state = timerState_Pause; } } else if(down & KEY_B) { timerStop(0); ticks = 0; state = timerState_Stop; } iprintf("Press A to start and pause the \ntimer, B to clear the timer \nand start to quit the program.\n\n"); iprintf("ticks: %u\n", ticks); iprintf("second: %u:%u\n", ticks/TIMER_SPEED, ((ticks%TIMER_SPEED)*1000) /TIMER_SPEED); } if(state != timerState_Stop) { timerStop(0); } return 0; }
void Modem::timerDone() { #ifdef MODEM_DEBUG fprintf(stderr, "Modem: timeout, xstate = %d.\n", xstate); #endif switch(xstate) { case 0: /* non-XModem mode */ emit timeout(); break; case 1: /* 1st 'C' sent */ case 2: /* 2nd 'C' sent */ case 3: /* 3rd 'C' sent */ writeChar('C'); xstate++; timerStart(1000); /* Should be 3000 in original XModem */ break; case 4: /* 4th 'C' sent */ xcrc = false; case 5: /* 1st <NAK> sent */ case 6: /* 2nd <NAK> sent */ case 7: /* 3rd <NAK> sent */ case 8: /* 4th <NAK> sent */ case 9: /* 5th <NAK> sent */ writeChar(CNAK); xstate++; timerStart(1000); /* Should be 10000 in original XModem */ break; case 10: /* 6th <NAK> sent */ xreset(); emit xmodemDone(false); break; default: /* pending XModem block */ writeChar(CNAK); xstate = 5; timerStart(1000); /* Should be 10000 in original XModem */ } }
void Modem::receiveXModem( bool crc ) { disconnect( sn, 0, this, 0 ); connect( sn, SIGNAL( activated( int ) ), SLOT( readXChar( int ) ) ); xcrc = crc; if ( xcrc ) { writeChar( 'C' ); xstate = 1; timerStart( 3000 ); } else { writeChar( CNAK ); xstate = 5; timerStart( 10000 ); } xblock = 1; }
void Control::onStatusChanged(bool s) { switch(s){ case true: timerStart(); break; case false: timerStop(); break; } }
void initimer() { int i = 0; while(i < 8) { soundLentimefild[i] = 0; //soundothertimefild[i] = 0; i++; } timerStart(2, ClockDivider_1,0x10000-0xFFFF, timerlen); //512 Hz }
void GLWindow::toggleAnimationState() { if (timer->isActive()) { timerStop(); } else { timerStart(); } }
int main() { // Example 1 [-1,1] a = -1.0; b = 1.0; n = 1000000000; int current_number_of_threads[3] = {2, 50, 100}; pthread_mutex_init(&approx_lock,NULL); int i = 0; for (i = 0; i<3; i++) { approx = 0; thread_amount = current_number_of_threadsi[i]; printf("\nRan with %d threads\n", thread_amount); timerStart(); run_threads(); printf("Took %ld ms\n", timerStop()); printf("a:%f\t b:%f\t n:%d\t actual:%f\t approximation:%f\n", a, b, n, NEG_1_TO_POS_1, approx); } // Example 2 [0,10] a = 0.0; b = 10.0; n = 1000000000; int i = 0; for (i = 0; i<3; i++) { approx = 0; thread_amount = current_number_of_threadsi[i]; printf("\nRan with %d threads\n", thread_amount); timerStart(); run_threads(); printf("Took %ld ms\n", timerStop()); printf("a:%f\t b:%f\t n:%d\t actual:%f\t approximation:%f\n", a, b, n, NEG_1_TO_POS_1, approx); } pthread_mutex_destroy(&approx_lock); return 0; }
int main() { // Example 1 [-1,1] a = -1.0; b = 1.0; n = 1000; timerStart(); trap(); printf("Took %ld ms\n", timerStop()); printf("a:%f\t b:%f\t n:%d\t actual:%f\t approximation:%f\n", a, b, n, NEG_1_TO_POS_1, approx); // Example 2 [0,10] a = 0.0; b = 10.0; n = 1000; timerStart(); trap(); printf("Took %ld ms\n", timerStop()); printf("a:%f\t b:%f\t n:%d\t actual:%f\t approximation:%f\n", a, b, n, ZERO_TO_POS_10, approx); return 0; }
int main() { defaultExceptionHandler(); mgr_system.init_DS(); mgr_system.init_timer(inc_timer,&millisec); timerStart(0,ClockDivider_1024,timerFreqToTicks_1024(24),inc_timer); app_test.init( &mgr_display /*, &mgr_input */, &mgr_system); app_test.start(); return 0; }//end main
void Manager_System::init_timer(void xp_fct_timer(), int32 * xp_millisec) { this->last_millisec = 0; // TIMER0_CR = 0; // TIMER0_DATA = TIMER_FREQ(0x409); // TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ; this->millisec = xp_millisec; // irqSet(IRQ_TIMER0, xp_fct_timer); // irqEnable(IRQ_TIMER0); timerStart(0,ClockDivider_1,timerFreqToTicks_1(25),xp_fct_timer); irqEnable(IRQ_TIMER0); }
int main() { soundEnable(); channel = soundPlayPSG(DutyCycle_50, 10000, 127, 64); //calls the timerCallBack function 5 times per second. timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(5), timerCallBack); waitfor(KEY_A); return 0; }