int main (void) { XGpio dip, push; int i, psb_check, dip_check; xil_printf("-- Start of the Program --\r\n"); XGpio_Initialize(&dip, XPAR_SW_4BIT_DEVICE_ID); // Modify this XGpio_SetDataDirection(&dip, 1, 0xffffffff); XGpio_Initialize(&push, XPAR_BTNS_4BIT_DEVICE_ID); // Modify this XGpio_SetDataDirection(&push, 1, 0xffffffff); while (1) { psb_check = XGpio_DiscreteRead(&push, 1); xil_printf("Push Buttons Status %x\r\n", psb_check); dip_check = XGpio_DiscreteRead(&dip, 1); xil_printf("DIP Switch Status %x\r\n", dip_check); // output dip switches value on LED_ip device LED_IP_mWriteReg(XPAR_LED_IP_0_S_AXI_BASEADDR,0,dip_check); for (i=0; i<9999999; i++); } }
/** * * Run a self-test on the driver/device. Note this may be a destructive test if * resets of the device are performed. * * If the hardware system is not built correctly, this function may never * return to the caller. * * @param baseaddr_p is the base address of the LED_IPinstance to be worked on. * * @return * * - XST_SUCCESS if all self-test code passed * - XST_FAILURE if any self-test code failed * * @note Caching must be turned off for this function to work. * @note Self test may fail if data memory and device are not on the same bus. * */ XStatus LED_IP_Reg_SelfTest(void * baseaddr_p) { Xuint32 baseaddr; int write_loop_index; int read_loop_index; int Index; baseaddr = (Xuint32) baseaddr_p; xil_printf("******************************\n\r"); xil_printf("* User Peripheral Self Test\n\r"); xil_printf("******************************\n\n\r"); /* * Write to user logic slave module register(s) and read back */ xil_printf("User logic slave module test...\n\r"); for (write_loop_index = 0 ; write_loop_index < 4; write_loop_index++) LED_IP_mWriteReg (baseaddr, write_loop_index*4, (write_loop_index+1)*READ_WRITE_MUL_FACTOR); for (read_loop_index = 0 ; read_loop_index < 4; read_loop_index++) if ( LED_IP_mReadReg (baseaddr, read_loop_index*4) != (read_loop_index+1)*READ_WRITE_MUL_FACTOR){ xil_printf ("Error reading register value at address %x\n", (int)baseaddr + read_loop_index*4); return XST_FAILURE; } xil_printf(" - slave register write/read passed\n\n\r"); return XST_SUCCESS; }
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; } } }
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; }