/**
*
* This function does a minimal test on the SCU Private timer device and driver.
* The purpose of this function is to illustrate how to use the XScuTimer driver.
*
* @param	DeviceId is the unique device id of the device.
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note		None.
*
****************************************************************************/
int ScuTimerPolledExample(u16 DeviceId)
{
	int Status;
	volatile u32 CntValue1 = 0;
	volatile u32 CntValue2 = 0;
	XScuTimer_Config *ConfigPtr;
	XScuTimer *TimerInstancePtr = &Timer;

	/*
	 * Initialize the Scu Private Timer so that it is ready to use.
	 */
	ConfigPtr = XScuTimer_LookupConfig(DeviceId);

	/*
	 * This is where the virtual address would be used, this example
	 * uses physical address.
	 */
	Status = XScuTimer_CfgInitialize(TimerInstancePtr, ConfigPtr,
				 ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Load the timer counter register.
	 */
	XScuTimer_LoadTimer(TimerInstancePtr, TIMER_LOAD_VALUE);

	/*
	 * Get a snapshot of the timer counter value before it's started
	 * to compare against later.
	 */
	CntValue1 = XScuTimer_GetCounterValue(TimerInstancePtr);

	/*
	 * Start the Scu Private Timer device.
	 */
	XScuTimer_Start(TimerInstancePtr);

	/*
	 * Read the value of the timer counter and wait for it to change,
	 * since it's decrementing it should change, if the hardware is not
	 * working for some reason, this loop could be infinite such that the
	 * function does not return.
	 */
	while (1) {
		CntValue2 = XScuTimer_GetCounterValue(TimerInstancePtr);
		if (CntValue1 != CntValue2) {
			break;
		}
	}
	return XST_SUCCESS;
}
int main()
{
	init_platform();

	// Declare some variables that we'll use later
	int Status;
	int timer_value;
	int counter = 0;

	// Declare two structs.  One for the Timer instance, and
	// the other for the timer's config information
	XScuTimer my_Timer;
	XScuTimer_Config *Timer_Config;

	// Look up the the config information for the timer
	Timer_Config = XScuTimer_LookupConfig(XPAR_PS7_SCUTIMER_0_DEVICE_ID);

	// Initialise the timer using the config information
	Status = XScuTimer_CfgInitialize(&my_Timer, Timer_Config, Timer_Config->BaseAddr);

	// Load the timer with a value that represents one second
	// The SCU Timer is clocked at half the freq of the CPU.
	XScuTimer_LoadTimer(&my_Timer, XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2);

	// Start the timer running (it counts down)
	XScuTimer_Start(&my_Timer);

	// An infinite loop
	while(1)
	{
		// Read the value of the timer
		timer_value = XScuTimer_GetCounterValue(&my_Timer);

		// If the timer has reached zero
		if (timer_value == 0)
		{
			// Re-load the original value into the timer and re-start it
			XScuTimer_RestartTimer(&my_Timer);

			// Write something to the UART (and count the seconds)
			printf("Timer has reached zero %d times\n\r", counter++);
		}
		else
		{
			// Show the value of the timer's counter value, for debugging purposes
			//printf("Timer is still running (Timer value = %d)\n\r", timer_value);
		}
	}

	cleanup_platform();

	return 0;
}
示例#3
0
/*
 * This function is derived from PowerPC code (read timebase as long long).
 * On ARM it just returns the timer value.
 */
unsigned long long get_ticks(void)
{
	ulong now;

	now = XScuTimer_GetCounterValue() /  (TIMER_TICK_HZ/CONFIG_SYS_HZ);

	if (lastdec >= now) {
		/* normal mode */
		timestamp += lastdec - now;
	} else {
		/* we have an overflow ... */
		timestamp += lastdec + TIMER_LOAD_VAL - now;
	}
	lastdec = now;

	return timestamp;
}
示例#4
0
int WaitForStart::ScuTimerWait(u16 DeviceId, u32 timeOut) {

	int Status;
	XScuTimer_Config *ConfigPtr;
	XScuTimer *TimerInstancePtr = &Timer;

	/*
	 * Initialize the Scu Private Timer so that it is ready to use.
	 */
	ConfigPtr = XScuTimer_LookupConfig(DeviceId);

	/*
	 * This is where the virtual address would be used, this example
	 * uses physical address.
	 */
	Status = XScuTimer_CfgInitialize(TimerInstancePtr, ConfigPtr,
			ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// XScuTimer_SetPrescaler(TimerInstancePtr,16);
	XScuTimer_SetPrescaler(TimerInstancePtr, 1);

	/*
	 * Load the timer decrement register.
	 */
	XScuTimer_LoadTimer(TimerInstancePtr, timeOut);

	/*
	 * Start the Scu Private Timer device.
	 */
	XScuTimer_Start(TimerInstancePtr);

	while (XScuTimer_GetCounterValue(TimerInstancePtr) != 0) {

		// Wait for timer to expire

	}
	// Stop timer after use
	XScuTimer_Stop(TimerInstancePtr);

	return XST_SUCCESS;

}
示例#5
0
int main(void) {

	XGpio dip, push;
	XScuTimer Timer;  /* Cortex A9 SCU Private Timer Instance */
	XScuTimer_Config *ConfigPtr;
	int value, skip, psb_check, dip_check, status, timerCounter, time1, time2;
	VectorArray AInst;
	VectorArray BTinst;
	VectorArray PInst;
	
	xil_printf("-- Start of the Program --\r\n");
	xil_printf("Enter choice: 1 (SW->Leds), 2 (Timer->Leds), 3 (Matrix), 4 (Exit) \r\n");

	XGpio_Initialize(&dip, XPAR_SW_8BIT_DEVICE_ID);
	XGpio_SetDataDirection(&dip, 1, 0xffffffff);

	XGpio_Initialize(&push, XPAR_BTNS_5BIT_DEVICE_ID);
	XGpio_SetDataDirection(&push, 1, 0xffffffff);

	ConfigPtr = XScuTimer_LookupConfig (XPAR_PS7_SCUTIMER_0_DEVICE_ID);
	status = XScuTimer_CfgInitialize (&Timer, ConfigPtr, ConfigPtr->BaseAddr);

	if(status != XST_SUCCESS){
		xil_printf("Timer init() failed\r\n");
		return XST_FAILURE;
	}

	// Load timer with delay
	XScuTimer_LoadTimer(&Timer, ONE_SECOND);
	// Set AutoLoad mode
	XScuTimer_EnableAutoReload(&Timer);

	while (1) {
		xil_printf("CMD:> ");
		// Read an input value from the console.
		value = inbyte();
		skip = inbyte(); //CR
		skip = inbyte(); //LF
		switch (value) {
			case '1':
				while(!XGpio_DiscreteRead(&push, 1))
				{
					dip_check = XGpio_DiscreteRead(&dip, 1);
					LED_IP_mWriteReg(XPAR_LED_IP_S_AXI_BASEADDR, 0, dip_check);
					for (skip = 0; skip < 9999999; skip++);
				}
				break;
			case '2':

				timerCounter = 0;
				XScuTimer_Start(&Timer);

				while(!XGpio_DiscreteRead(&push, 1))
				{
					if(XScuTimer_IsExpired(&Timer))
					{
						XScuTimer_ClearInterruptStatus(&Timer);
						timerCounter = (timerCounter + 1) % 256;
						LED_IP_mWriteReg(XPAR_LED_IP_S_AXI_BASEADDR, 0, timerCounter);
					}
				}
				break;
			case '3':
				setInputMatrices(AInst, BTinst);
				displayMatrix(AInst);
				displayMatrix(BTinst);

				XScuTimer_Start(&Timer);
				// Software matrix
				time1 = XScuTimer_GetCounterValue(&Timer);
				multiMatrixSoft(AInst, BTinst, PInst);
				time2 = XScuTimer_GetCounterValue(&Timer);

				xil_printf("SW time: %d\n\n", time1-time2);
				displayMatrix(PInst);

				// Hardware matrix
				time1 = XScuTimer_GetCounterValue(&Timer);
				multiMatrixHard(AInst, BTinst, PInst);
				time2 = XScuTimer_GetCounterValue(&Timer);

				XScuTimer_Stop(&Timer);

				xil_printf("HW time: %d\n\n", time1-time2);
				displayMatrix(PInst);
				break;
			case '4':
				// Exit
				return XST_SUCCESS;
				break;
			default :
				break;
		}
	}
}
示例#6
0
// Reads the private counter on the Arm core.
u32 interrupts_getPrivateTimerCounterValue(void) {
    return XScuTimer_GetCounterValue(&TimerInstance);
}
示例#7
0
void reset_timer_masked(void)
{
	/* reset time */
	lastdec = XScuTimer_GetCounterValue() / (TIMER_TICK_HZ/CONFIG_SYS_HZ);
	timestamp = 0;
}
示例#8
0
int main(void) {
    xil_printf("Starting\r\n");

    int Status;
    int i;
    u32 start_time;
    u32 end_time;
    u32 return_val[ACTUAL_READS];

    // Initialize DMA
    Status = DMA_init(DMA_DEV_ID);
    if (Status != XST_SUCCESS) {
        xil_printf("XAxiDma_init: Failed %d\r\n", Status);
        return XST_FAILURE;
    }

    // Initialize PE
    Status = XNeedlemanwunsch_Initialize(&PE, PE_DEV_ID);
    if (Status != XST_SUCCESS) {
        xil_printf("XNeedlemanwunsch_Initialize: Failed %d\r\n", Status);
        return XST_FAILURE;
    }

    XNeedlemanwunsch_DisableAutoRestart(&PE);

    // Initialize timer with maximum value so we can see how far down it
    // goes. It should last about 12 seconds before hitting zero.
    Timer_init(TIMER_DEV_ID);
    XScuTimer_LoadTimer(&Timer, TIMER_MAX);
    XScuTimer_SetPrescaler(&Timer, TIMER_PRESCALE-1);
    start_time = TIMER_MAX;

    // Flush caches
    Xil_DCacheFlushRange((INTPTR)&ref_genome, sizeof(ref_genome));



    XScuTimer_Start(&Timer);

    for (i=0; i<ACTUAL_READS; i++) {
    	DMA_send();
    	writeRead(0, i);

		while(!XNeedlemanwunsch_IsIdle(&PE) && !XNeedlemanwunsch_IsReady(&PE)) {
			xil_printf("Waiting for idle/ready\r\n");
		}
		XNeedlemanwunsch_Start(&PE);
		//if (XNeedlemanwunsch_IsIdle(&PE) || XNeedlemanwunsch_IsReady(&PE)) {
			//xil_printf("Is still idle/ready\r\n");
		//}
		while(!XNeedlemanwunsch_IsDone(&PE) /*&& !XNeedlemanwunsch_IsIdle(&PE) && !XNeedlemanwunsch_IsReady(&PE)*/) {

		}

		return_val[i] = XNeedlemanwunsch_Get_return(&PE);
    }

    XScuTimer_Stop(&Timer);
    end_time = XScuTimer_GetCounterValue(&Timer);

    xil_printf("Done\r\n");
    for (i=0; i<ACTUAL_READS; i++) {
    	xil_printf("read %d best fit at %d\r\n", i, return_val[i]);
    }

    print_time(start_time, end_time);
    return 0;
}