コード例 #1
0
ファイル: mem2_3.c プロジェクト: Navax99/SO
static inline unsigned long long getTime(void)
{
	unsigned long low, high;
	getCycles(low, high);
	return ((unsigned long long)high << 32) + low;

}
コード例 #2
0
void FieldAnimation::internalUpdate(const Real32& t, const Real32 prev_t)
{
    if(getContainer() == NULL || getFieldId() == 0)
    {
        SWARNING << "There is no Field Container defined to Animate"  << std::endl;
        return;
    }
    EditFieldHandlePtr TheField = getContainer()->editField( getFieldId() );

    //Check if it's the right type
    if(getContainer()->getFieldDescription(getFieldId())->getFieldType().getContentType() != getAnimator()->getDataType())
    {
        SWARNING << "The data type of the field: " << getContainer()->getFieldDescription(getFieldId())->getName() << " with type: "  << getContainer()->getFieldDescription(getFieldId())->getFieldType().getContentType().getCName() << " connected to this animation is not the same data type: " << getAnimator()->getDataType().getCName() << ", that the animator works on."  << std::endl;
        return;
    }

    //Update the Field Container
    if( getAnimator()->animate(
                static_cast<Animator::InterpolationType>(getInterpolationType()),
                static_cast<Animator::ValueReplacementPolicy>(getReplacementPolicy()),
                (getCycling() < 0) || (getCycling() > getCycles()),
                t,
                prev_t,
                TheField,
                getIndex()) )
    {
        commitChanges();
    }
}
コード例 #3
0
ファイル: system6502.cpp プロジェクト: MoleskiCoder/cpp_6502
void System6502::Execute(uint8_t cell) {

	auto oldCycles = getCycles();

	CheckPoll();

	// XXXX Fetch byte has already incremented PC.
	auto executingAddress = (uint16_t)(getPC() - 1);

	AddressEventArgs e(executingAddress, cell);
	ExecutingInstruction.fire(e);
	__super::Execute(cell);
	ExecutedInstruction.fire(e);

	auto deltaCycles = getCycles() - oldCycles;
	intervalCycles += deltaCycles;
}
コード例 #4
0
ファイル: system6502.cpp プロジェクト: MoleskiCoder/cpp_6502
void System6502::Throttle() {
	auto now = std::chrono::high_resolution_clock::now();
	auto elapsed = now - startTime;
	auto timerCurrent = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();

	auto cyclesAllowed = timerCurrent * cyclesPerMillisecond;
	auto cyclesMismatch = getCycles() - cyclesAllowed;
	if (cyclesMismatch > 0.0) {
		auto delay = cyclesMismatch / cyclesPerMillisecond;
		if (delay > 0) {
			heldCycles += (uint64_t)cyclesMismatch;
			std::this_thread::sleep_for(std::chrono::milliseconds((long long)delay));
		}
	}
}
コード例 #5
0
/*!
 * \fn bool OSG::Animation::update(const Time& ElapsedTime)
 *
 * \brief Update the animation with the time since the last update
 *
 * The result of the animation will also be applied to the
 * object it is connected to.
 *
 * \param[in] ElapsedTime The time, in seconds, since the previous call to
 * update.
 */
bool Animation::update(const Time& ElapsedTime)
{
    if(!_IsPlaying || _IsPaused)
    {
        return false;
    }

    //Increment the updated animations statistic
    StatIntElem *NAnimationsStatElem = StatCollector::getGlobalElem(statNAnimations);
    if(NAnimationsStatElem) { NAnimationsStatElem->inc(); }

    //Start the  animation update time statistic
    StatTimeElem *AnimUpdateTimeStatElem = StatCollector::getGlobalElem(statAnimUpdateTime);
    if(AnimUpdateTimeStatElem) { AnimUpdateTimeStatElem->start(); }

    _CurrentTime += getScale()*ElapsedTime;
    UInt32 PreUpdateCycleCount(getCycles());
    if(getCycling() < 0 || PreUpdateCycleCount < getCycling())
    {
        Real32 CycleLength(getCycleLength() * getScale());

        //Check if the Animation Time is past the end
        if(_CurrentTime >= CycleLength)
        {
            //Update the number of cycles completed
            setCycles( (CycleLength <= 0.0f) ? (0): (static_cast<UInt32>( osgFloor( _CurrentTime / CycleLength ) )) );
            //commitChanges();
        }
        Real32 t(_CurrentTime);

        if(getCycling() > 0 && getCycles() >= getCycling())
        {
            if(getSpan() > 0.0f)
            {
                t = getSpan();
            }
            t -= 0.0001f;
        }
        else
        {
            if(getSpan() > 0.0f)
            {
                t -= osgFloor(_CurrentTime/getSpan())*getSpan();
            }
        }
        t += getOffset();

        //Internal Update
        internalUpdate(t, _PrevTime);


        //If the number of cycles has changed
        if(getCycles() != PreUpdateCycleCount)
        {
            if(getCycling() > 0 && getCycles() >= getCycling())
            {
                //Animation has reached the end
                //Remove the Animation from it's update producer
                _UpdateEventConnection.disconnect();
                _IsPlaying = false;

                //Produce the Ended event
                produceAnimationEnded();
            }
            else
            {
                //Animation hasn't finished yet
                //Produce the Cycled event
                produceAnimationCycled();
            }
        }
    }

    _PrevTime = _CurrentTime;

    //Stp[ the  animation update time statistic
    if(AnimUpdateTimeStatElem) { AnimUpdateTimeStatElem->stop(); }

    //Return true if the animation has completed its number of cycles, false otherwise
    return (getCycling() > 0 && getCycles() >= getCycling());
}
コード例 #6
0
int main(void)
{
    volatile int * (cam_start) = (int *)CAM_START; // Output
    volatile int * (sdram_data1) = (int *)SDRAM_DATA1; //Input
    volatile int * (sdram_read) = (int *)READ_OUT_ADDR;  //Output
    volatile int * (read_good) = (int *)VGA_CLK_IN;  //Input
    volatile int * (sdram_reset) = (int *)VGA_DATA1; //Output
    volatile int * (vga_reset) = (int *)VGA_DATA2; //Output
    volatile int *(clock_select) = (int *)SOURCE_SELECT;
    volatile int *(clock_gen) = (int *)CONTROLLING_CLK;


    volatile int *nn_write_data_1 = (int *)NN_WRITE_DATA_1;
    volatile int *nn_write_data_2 = (int *)NN_WRITE_DATA_2;
    volatile int *nn_write_enable = (int *)NN_WRITE_ENABLE;
    volatile int *nn_write_clock = (int *)NN_WRITE_CLOCK;
    volatile int *nn_read_enable = (int *)NN_READ_ENABLE;
    volatile int *nn_read_clock = (int *)NN_READ_CLOCK;
    volatile int *nn_bootup = (int *)NN_BOOTUP;
    volatile int *nn_access = (int *)NN_ACCESS;
    volatile int *nn_read_data_1 = (int *)NN_READ_DATA_1;
    volatile int *nn_read_data_2 = (int *)NN_READ_DATA_2;




    int16_t number1, number2;
  *cam_start = 0;
  *nn_write_clock = 0;
  *nn_read_clock = 0;
  *nn_bootup = 1;
  *sdram_reset = 1; // reset signals to set read address
  *sdram_reset = 0;
  *sdram_reset = 1;
  *nn_write_enable = 1;
  
  int i = 0;
  


  // WRITING
  // finalW1L1
  /*
  for (int i = 0; i < 200; i++)
  {
      for (int j = 0; j < 784/4; j = j + 4)
      {
          number1 = (finalW1L1[i][j] << 8) | (finalW1L1[i][j+1] & 0xff);
          number2 = (finalW1L1[i][j+2] << 8) | (finalW1L1[i][j+3] & 0xff);
          *nn_write_data_1 = number1;
          *nn_write_data_2 = number2;
          *nn_write_clock = 1;
          *nn_write_clock = 0;
      }
  } // finalW1L1
  // finalB1L1
  for (int i = 0; i < 200/4; i = i + 4)
  {
    number1 = (finalB1L1[i] << 8) | (finalB1L1[i+1] & 0xff);
    number2 = (finalB1L1[i+2] << 8) | (finalB1L1[i+3] & 0xff);
    *nn_write_data_1 = number1;
    *nn_write_data_2 = number2;
    *nn_write_clock = 1;
    *nn_write_clock = 0;
  } // finalB1L1
  
  
    // finalW1L2
  for (int i = 0; i < 200; i++)
  {
      for (int j = 0; j < 200/4; j = j + 4)
      {
          number1 = (finalW1L2[i][j] << 8) | (finalW1L2[i][j+1] & 0xff);
          number2 = (finalW1L2[i][j+2] << 8) | (finalW1L2[i][j+3] & 0xff);
          *nn_write_data_1 = number1;
          *nn_write_data_2 = number2;
          *nn_write_clock = 1;
          *nn_write_clock = 0;
      }
  } // finalW1L2
  // finalB1L2
  for (int i = 0; i < 200/4; i = i + 4)
  {
    number1 = (finalW1L2[i] << 8) | (finalW1L2[i+1] & 0xff);
    number2 = (finalW1L2[i+2] << 8) | (finalW1L2[i+3] & 0xff);
    *nn_write_data_1 = number1;
    *nn_write_data_2 = number2;
    *nn_write_clock = 1;
    *nn_write_clock = 0;
  } // finalB1L2
    // finalSoftmaxTheta
  for (int i = 0; i < 10; i++)
  {
      for (int j = 0; j < 200/4; j = j + 4)
      {
          number1 = (finalW1L2[i][j] << 8) | (finalW1L2[i][j+1] & 0xff);
          number2 = (finalW1L2[i][j+2] << 8) | (finalW1L2[i][j+3] & 0xff);
          *nn_write_data_1 = number1;
          *nn_write_data_2 = number2;
          *nn_write_clock = 1;
          *nn_write_clock = 0;
      }
  } // finalSoftmaxTheta
  */

    for (i = 0; i < 20; i = i + 2)
    {
        number1 = 1;
        number2 = 2;
        *nn_write_data_1 = number1;
        *nn_write_data_2 = number2;
        *nn_write_clock = 1;
        *nn_write_clock = 0;
    }


    // READING
    *nn_access = 1;
    *nn_read_enable = 1;
    *sdram_reset = 0;  // reset sdram
    *sdram_reset = 1;
    int8_t testRead1, testRead2;
    for (i = 0; i < 20; i = i + 2)
    {
        number1 = *nn_read_data_1;
        number2 = *nn_read_data_2;
        *nn_read_clock = 1;
        *nn_read_clock = 0;

        printf("%d\t", number1);
        printf("%d\n", number2);

    }



    *nn_write_enable = 0;
    *nn_bootup = 0;


    
    

    *nn_read_enable = 0;
    *nn_access = 0;







    int M;
    //int i = 0;
    int j = 0;
    int k = 0;
    int L = 0;
    int snapshot = 0;
    *nn_bootup = 0;
    *nn_access = 0;
    *sdram_reset = 0;
    *sdram_reset = 1;
    *vga_reset = 1;
    *clock_select = 0;


    int write_data = 0;
    int written = 0;
    int height = HEIGHT, width = WIDTH;

    int** black_white = (int**)malloc(HEIGHT*sizeof(int*));
    for (i = 0; i < HEIGHT; i++)
    {
        black_white[i] = (int*)malloc(sizeof(int)*WIDTH);
    }

    while (1){
        *cam_start = 1;
        totalCycles = 0;
        printf("Press enter to start\n");

        fflush(stdin);
        getchar();
        fflush(stdin);



        // delay before capture
        for (i = 0; i < 30000; i++)
        {
        }
        snapshot = 1;
        if (snapshot)
        {
            //
            //      int cycleCounter = 0;
            //      int cycleIndex = 0;
            initCounters();
            main_1 = getCycles();

            *cam_start = 0; // pause camera
            *clock_select = 1;  // choose custom clock from hps
            *sdram_reset = 0; // reset sdram
            *sdram_reset = 1;
            *sdram_read = 1;  // set read request to high

            //
            //     main_2 = getCycles();

            // clear out first horizontal row, it is all black
            for (k = 0; k < WIDTH + 3; k = k + 1)
            {
                *clock_gen = 1; // generate 4 clock cycles to move slower clock 1 cycle
                *clock_gen = 0;
                *clock_gen = 1;
                *clock_gen = 0;

            }

            //      
            //      main_3 = getCycles();

            // begin reading in data
            for (j = 0; j < HEIGHT; j = j + 1)
            {
                for (k = 0; k < WIDTH; k = k + 1)
                {
                    for (L = 0; L < 2; L = L + 1)
                    {
                        *clock_gen = 1; // generate 4 clock cycles, checking each cycle
                        if (!written)
                        {
                            if (*read_good) // take in data from verilog to read block (not sure if needed)
                            {
                                black_white[j][k] = *(sdram_data1);
                                written = 1;
                            }
                        }
                        *clock_gen = 0;
                    }
                    written = 0;
                }
                *sdram_read = 0;
                *sdram_read = 1;
                /*
                //
                if (cycleCounter == 48)
                {
                cycleCounter = 0;
                cycle[cycleIndex] = getCycles();
                cycleIndex++;
                }
                */
            }

            // 
            //      main_3 = getCycles();

            *sdram_read = 0;

            *sdram_reset = 0;
            *vga_reset = 0;
            *sdram_reset = 1;
            *vga_reset = 1;

            *cam_start = 1;
            *clock_select = 0;
            snapshot = 0;
            //printf("Done\n");
        }

        //
        main_4 = getCycles();

        height = HEIGHT;
        width = WIDTH;
        
        printf("Image = %d  x %d\n", height, width);
        printf("\n\n");
        for (i = 0; i < height; i++)
        {
        for (k = 0; k < width; k++)
        {
        printf("%d\t", black_white[i][k]);
        }
        printf("\n");
        }/**/


        //printf("Total Image = %d   %d\n",height, width);
        region_1 = getCycles();
        region2(&width, &height, black_white);
        region_end = getCycles();
        /*
        printf("ROI = %d  x %d\n",height, width);
        printf("\n\n");
        for (i = 0; i < height; i++)
        {
        for (k = 0; k < width; k++)
        {
        printf("%d\t",black_white[i][k]);
        }
        printf("\n");
        } /* */
        //printf("Region Found\n\n");


        digit_separate2(height, width, black_white);
        //separate_end = getCycles();
        rec_2 = getCycles();
        printf("Done\n");

        /*    	for (i = 0; i < 10; i++)
        printf("%d:\t %u\n",i+1,cycle[i]);
        */
        //    printf("\n1: \t%d\n2: \t%d\n3: \t%d\n4: \n5: \n6: \t%d\n7: \t%d\n", main_1, main_2, main_3, main_6, main_7);

        final = (main_4 - main_1);
        //        printf("\nTimes:\nMain: \t%d\n\n", final);
        totalCycles += final;

        final = (region_end - region_1);
コード例 #7
0
bool AnimationGroup::update(const Time& ElapsedTime)
{
    if(!_IsPlaying || _IsPaused)
    {
        return false;
    }
    _CurrentTime += getScale()*ElapsedTime;

    UInt32 PreUpdateCycleCount(getCycles());
    if(getCycling() < 0 || PreUpdateCycleCount < getCycling())
    {
        Real32 CycleLength(getCycleLength() * getScale());
        
        //Check if the Animation Time is past the end
        if(_CurrentTime >= CycleLength)
        {
            //Update the number of cycles completed
            setCycles( (CycleLength <= 0.0f) ? (0): (static_cast<UInt32>( osgFloor( _CurrentTime / CycleLength ) )) );
            //commitChanges();
        }
        Real32 t(_CurrentTime);

        if(getCycling() > 0 && getCycles() >= getCycling())
        {
            if(getSpan() > 0.0f)
            {
                t = getSpan();
            }
            else
            {
                t = CycleLength;
            }
            t -= 0.0001f;
        }
        else
        {
            if(getSpan() > 0.0f)
            {
                t -= osgFloor(_CurrentTime/getSpan())*getSpan();
            }
        }
        t += getOffset();

        //Internal Update
        for(UInt32 i = 0; i < getMFAnimations()->size(); ++i)
        {
            getAnimations(i)->internalUpdate(t, _PrevTime);
        }

        //If the number of cycles has changed
        if(getCycles() != PreUpdateCycleCount)
        {
            if(getCycling() > 0 && getCycles() >= getCycling())
            {
                //Animation has reached the end
                //Remove the Animation from it's update producer
                _UpdateEventConnection.disconnect();
                _IsPlaying = false;

                //Produce the Ended event
                produceAnimationEnded();
            }
            else
            {
                //Animation hasn't finished yet
                //Produce the Cycled event
                produceAnimationCycled();
            }
        }
    }

    _PrevTime = _CurrentTime;

    //Return true if the animation has completed its number of cycles, false otherwise
    return (getCycling() > 0 && getCycles() >= getCycling());
}