/** * * Run a self-test on the timer. This test clears the timer enable bit in * the control register, writes to the timer load register and verifies the * value read back matches the value written and restores the control register * and the timer load register. * * @param InstancePtr is a pointer to the XScuTimer instance. * * @return * - XST_SUCCESS if self-test was successful. * - XST_FAILURE if self test was not successful. * * @note None. * ******************************************************************************/ s32 XScuTimer_SelfTest(XScuTimer *InstancePtr) { u32 Register; u32 CtrlOrig; u32 LoadOrig; s32 Status; /* * Assert to ensure the inputs are valid and the instance has been * initialized. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Save the contents of the Control Register and stop the timer. */ CtrlOrig = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr, XSCUTIMER_CONTROL_OFFSET); Register = CtrlOrig & (u32)(~XSCUTIMER_CONTROL_ENABLE_MASK); XScuTimer_WriteReg(InstancePtr->Config.BaseAddr, XSCUTIMER_CONTROL_OFFSET, Register); /* * Save the contents of the Load Register. * Load a new test value in the Load Register, read it back and * compare it with the written value. */ LoadOrig = XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, XSCUTIMER_LOAD_OFFSET); XScuTimer_LoadTimer(InstancePtr, XSCUTIMER_SELFTEST_VALUE); Register = XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, XSCUTIMER_LOAD_OFFSET); /* * Restore the contents of the Load Register and Control Register. */ XScuTimer_LoadTimer(InstancePtr, LoadOrig); XScuTimer_WriteReg(InstancePtr->Config.BaseAddr, XSCUTIMER_CONTROL_OFFSET, CtrlOrig); /* * Return a Failure if the contents of the Load Register do not * match with the value written to it. */ if (Register != XSCUTIMER_SELFTEST_VALUE) { Status = (s32)XST_FAILURE; } else { Status = (s32)XST_SUCCESS; } return Status; }
int main() { XScuTimer_Config *TMRConfigPtr; //timer config //Disable cache on OCM Xil_SetTlbAttributes(0xFFFF0000,0x14de2); // S=b1 TEX=b100 AP=b11, Domain=b1111, C=b0, B=b0 print("CPU1: starting\n\r"); //GPIO Initilization XGpio_Initialize(&Gpio, GPIO_DEVICE_ID); XGpio_SetDataDirection(&Gpio, CHANNEL, 0x00); XGpio_DiscreteWrite(&Gpio,CHANNEL, 0xff); //timer initialisation TMRConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID); XScuTimer_CfgInitialize(&Timer, TMRConfigPtr,TMRConfigPtr->BaseAddr); XScuTimer_SelfTest(&Timer); //load the timer XScuTimer_LoadTimer(&Timer, TIMER_LOAD_VALUE); SetupInterruptSystem(&Intc, &Timer,TIMER_IRPT_INTR); XScuTimer_Start(&Timer); print("CPU1: configured\n\r"); while(1){ } return 0; }
int Init_ScuTimer(void) { int Status = XST_SUCCESS; XScuTimer_Config *ConfigPtr; int TimerLoadValue = 0; ConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID); Status = XScuTimer_CfgInitialize(&TimerInstance, ConfigPtr, ConfigPtr->BaseAddr); if (Status != XST_SUCCESS) { xil_printf("In %s: Scutimer Cfg initialization failed...\r\n", __func__); return XST_FAILURE; } Status = XScuTimer_SelfTest(&TimerInstance); if (Status != XST_SUCCESS) { xil_printf("In %s: Scutimer Self test failed...\r\n", __func__); return XST_FAILURE; } XScuTimer_EnableAutoReload(&TimerInstance); /* * Set for 250 milli seconds timeout. */ TimerLoadValue = XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ / 8; XScuTimer_LoadTimer(&TimerInstance, TimerLoadValue); return XST_SUCCESS; }
/* * The application must provide a function that configures a peripheral to * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT() * in FreeRTOSConfig.h to call the function. This file contains a function * that is suitable for use on the Zynq SoC. */ void vConfigureTickInterrupt( void ) { static XScuGic xInterruptController; /* Interrupt controller instance */ BaseType_t xStatus; extern void FreeRTOS_Tick_Handler( void ); XScuTimer_Config *pxTimerConfig; XScuGic_Config *pxGICConfig; const uint8_t ucRisingEdge = 3; /* This function is called with the IRQ interrupt disabled, and the IRQ interrupt should be left disabled. It is enabled automatically when the scheduler is started. */ /* Ensure XScuGic_CfgInitialize() has been called. In this demo it has already been called from prvSetupHardware() in main(). */ pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID ); xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress ); configASSERT( xStatus == XST_SUCCESS ); ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */ /* The priority must be the lowest possible. */ XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge ); /* Install the FreeRTOS tick handler. */ xStatus = XScuGic_Connect( &xInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xTimer ); configASSERT( xStatus == XST_SUCCESS ); ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */ /* Initialise the timer. */ pxTimerConfig = XScuTimer_LookupConfig( XPAR_SCUTIMER_DEVICE_ID ); xStatus = XScuTimer_CfgInitialize( &xTimer, pxTimerConfig, pxTimerConfig->BaseAddr ); configASSERT( xStatus == XST_SUCCESS ); ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */ /* Enable Auto reload mode. */ XScuTimer_EnableAutoReload( &xTimer ); /* Ensure there is no prescale. */ XScuTimer_SetPrescaler( &xTimer, 0 ); /* Load the timer counter register. */ XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ ); /* Start the timer counter and then wait for it to timeout a number of times. */ XScuTimer_Start( &xTimer ); /* Enable the interrupt for the xTimer in the interrupt controller. */ XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR ); /* Enable the interrupt in the xTimer itself. */ vClearTickInterrupt(); XScuTimer_EnableInterrupt( &xTimer ); }
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; }
/** * * 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; }
static void TimerIntrHandler(void *CallBackRef) { //unsigned int cpu0; XScuTimer *TimerInstancePtr = (XScuTimer *) CallBackRef; XScuTimer_ClearInterruptStatus(TimerInstancePtr); //load timer XScuTimer_LoadTimer(&Timer, TIMER_LOAD_VALUE); //start timer XGpio_DiscreteWrite(&Gpio,CHANNEL,cpu0); XScuTimer_Start(&Timer); }
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; }
/** * * This function initializes SCU Private timer device and driver. * * @param DeviceId is the unique device id of the device. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ****************************************************************************/ int ScuTimerInit(void) { int Status; XScuTimer_Config *ConfigPtr; XScuTimer *TimerInstancePtr = &Timer; /* * Initialize the Scu Private Timer so that it is ready to use. */ ConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID); /* * 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; } /* * Disable auto reload of timer */ XScuTimer_DisableAutoReload(TimerInstancePtr); /* * Load the timer counter register. */ XScuTimer_LoadTimer(TimerInstancePtr, 0); /* * Start the Scu Private Timer device. */ XScuTimer_Start(TimerInstancePtr); return 0; }
/** * * 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 scu_sleep(unsigned int seconds) { // volatile u32 tEnd, tCur; volatile u32 tLoad; XScuTimer *TimerInstancePtr = &Timer; /* * Calculate load value for seconds */ tLoad = ((u32) seconds) * COUNTS_PER_SECOND; /* * Clear expired timer flag and Load the timer counter register. Timer should start */ XScuTimer_ClearInterruptStatus(TimerInstancePtr); XScuTimer_LoadTimer(TimerInstancePtr, tLoad); while ( !XScuTimer_IsExpired(TimerInstancePtr)) { // xil_printf("SCU Timer 0x%04x\n\r", XScuTimer_GetCounterValue(TimerInstancePtr)); } return 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; } } }
// User can set the prescaler on the private timer. // Also updates ticks per heart beat so that the LD4 heart-beat toggle rate remains constant. void interrupts_setPrivateTimerPrescalerValue(u32 prescalerValue) { XScuTimer_LoadTimer(&TimerInstance, prescalerValue); privateTimerPrescaler = prescalerValue; // Formula derived from the ARM documentation on the private timer (4.1.1) privateTimerTicksPerHeartbeat = (ZYBO_BUS_CLOCK /((privateTimerPrescaler+1) * (privateTimerLoadValue+1))) / HEARTBEAT_TOGGLES_PER_SECOND; }
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; }
int main (void) { XGpio dip, push; int psb_check, dip_check, dip_check_prev, count, Status; // PS Timer related definitions XScuTimer_Config *ConfigPtr; XScuTimer *TimerInstancePtr = &Timer; xil_printf("-- Start of the Program --\r\n"); XGpio_Initialize(&dip, XPAR_SW_4BIT_DEVICE_ID); XGpio_SetDataDirection(&dip, 1, 0xffffffff); XGpio_Initialize(&push, XPAR_BTNS_4BIT_DEVICE_ID); XGpio_SetDataDirection(&push, 1, 0xffffffff); count = 0; // Initialize the timer ConfigPtr = XScuTimer_LookupConfig(XPAR_PS7_SCUTIMER_0_DEVICE_ID); Status = XScuTimer_CfgInitialize(TimerInstancePtr, ConfigPtr, ConfigPtr->BaseAddr); if(Status != XST_SUCCESS){ return XST_FAILURE; } // Read dip switch values dip_check_prev = XGpio_DiscreteRead(&dip, 1); // Load timer with delay in multiple of ONE_SECOND XScuTimer_LoadTimer(TimerInstancePtr, ONE_SECOND*dip_check_prev); // Set AutoLoad mode XScuTimer_EnableAutoReload(TimerInstancePtr); // Start the timer XScuTimer_Start(TimerInstancePtr); while (1) { // Read push buttons and break the loop if Center button pressed psb_check = XGpio_DiscreteRead(&push, 1); if(psb_check & 0x1) { XScuTimer_Stop(TimerInstancePtr); break; } dip_check = XGpio_DiscreteRead(&dip, 1); if (dip_check != dip_check_prev) { xil_printf("DIP Switch Status %x, %x\r\n", dip_check_prev, dip_check); dip_check_prev = dip_check; // load timer with the new switch settings XScuTimer_LoadTimer(TimerInstancePtr, ONE_SECOND*dip_check_prev); count = 0; } if(XScuTimer_IsExpired(TimerInstancePtr)) { // clear status bit XScuTimer_ClearInterruptStatus(TimerInstancePtr); // output the count to LED and increment the count LED_IP_mWriteReg(XPAR_LED_IP_S_AXI_BASEADDR, 0, count); count++; } } return 0; }
/* * Setup the A9 internal timer to generate the tick interrupts at the * required frequency. */ static void prvSetupTimerInterrupt( void ) { extern void vTickISR (void); int Status; XScuTimer_Config *ScuConfig; prvSetupInterruptController(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, &InterruptController); /* * Connect to the interrupt controller */ Status = XScuGic_Connect(&InterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler)vTickISR, (void *)&Timer); if (Status != XST_SUCCESS) { return; } /* Timer Setup */ /* * Initialize the A9Timer driver. */ ScuConfig = XScuTimer_LookupConfig(XPAR_SCUTIMER_DEVICE_ID); Status = XScuTimer_CfgInitialize(&Timer, ScuConfig, ScuConfig->BaseAddr); if (Status != XST_SUCCESS) { return; } /* * Enable Auto reload mode. */ XScuTimer_EnableAutoReload(&Timer); /* * Load the timer counter register. */ XScuTimer_LoadTimer(&Timer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ); /* * Start the timer counter and then wait for it * to timeout a number of times. */ XScuTimer_Start(&Timer); /* * Enable the interrupt for the Timer in the interrupt controller */ XScuGic_Enable(&InterruptController, XPAR_SCUTIMER_INTR); /* * Enable the timer interrupts for timer mode. */ XScuTimer_EnableInterrupt(&Timer); /* * Do NOT enable interrupts in the ARM processor here. * This happens when the scheduler is started. */ }
int main() { init_platform(); XScuTimer Timer; XGpio ce, axis_data, axis_sw, btn, rst, sw; //setup of the timer XScuTimer_Config *TimerConfigPtr; XScuTimer *TimerInstancePtr = &Timer; TimerConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID); int status, readFlag, switchVal, i = 0; int16_t rawData = 0; //the raw binary from the ACL chip float res = 0.003921568627; //resolution of each bit in the raw binary double gData, angle, sumAngle = 0; /* Initialize all the GPIOs used */ status = XGpio_Initialize(&btn, BTN_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } status = XGpio_Initialize(&sw, SW_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } status = XGpio_Initialize(&ce, CE_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } status = XGpio_Initialize(&axis_data, AXIS_DATA_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } status = XGpio_Initialize(&axis_sw, AXIS_SW_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } status = XGpio_Initialize(&rst, RST_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } /* Private Timer Initialization */ status = XScuTimer_CfgInitialize(&Timer, TimerConfigPtr, TimerConfigPtr->BaseAddr); if (status != XST_SUCCESS) { return XST_FAILURE; } XScuTimer_LoadTimer(TimerInstancePtr, TIMER_LOAD_VALUE); //loaded with 65 XScuTimer_EnableAutoReload(TimerInstancePtr); XScuTimer_Start(TimerInstancePtr); while(1){ /* Constantly read the switches */ switchVal = XGpio_DiscreteRead(&sw, 1); /* Constantly looking for when the reset button (btn0) is pressed */ XGpio_DiscreteWrite(&rst, 1, XGpio_DiscreteRead(&btn, 1)); /* Tells the PmodACL HW model what switches are active */ XGpio_DiscreteWrite(&axis_sw, 1, switchVal); /* Used to see if the axis data gpio has been read yet */ readFlag = 0; if (XGpio_DiscreteRead(&ce, 1) == 0){ XScuTimer_LoadTimer(TimerInstancePtr, TIMER_LOAD_VALUE); /* This keeps us in here until it's done sending/receiving */ while (XGpio_DiscreteRead(&ce, 1) == 0){ if (XScuTimer_IsExpired(TimerInstancePtr)){ rawData = XGpio_DiscreteRead(&axis_data, 1); readFlag = 1; //you've read! XScuTimer_ClearInterruptStatus(TimerInstancePtr); } } } if (readFlag == 1){ /* This state is used to see if the number received is negative or not (rawData > 512 is negative) */ if (rawData < 512){ gData = rawData * res; //res is the resolution of each bit received }else{ gData = (512 - rawData) * res; //subtracting rawData from 512 is used to get the actual negative number } //not the binary unsigned /* This switch is used to see what axis you're using and what to display * NOTE: The Z-axis is setup to do angle measurement! */ switch(switchVal){ case 0: printf("x-axis:%fg\r\n", gData); break; case 1: printf("y-axis:%fg\r\n", gData); break; case 2: gData += .0991; //add the offset gData = (gData>1)? 1 : gData; //if gData is greater than 1, gData = 1 (because you can't take the acos angle = acos(gData); //of a number greater than 1) angle *= (180 / 3.14159); //acos gives you the angle in radians, this converts it to degrees sumAngle += angle; //used for finding the average i++; /* After 20 samples it prints the average value out */ if (i == 20){ printf("z-axis:%f degrees\r\n", (sumAngle / 20) ); i = 0; sumAngle = 0; } break; default: printf("x-axis:%fg\r\n", gData); //chooses x-axis by default break; } readFlag = 0; } } cleanup_platform(); return 0; }