//////////////////////////// PrintData //////////////////////////////// int PrintData( ){ u32 data; int dram_addr; //Read all data from DRAM // int dram_base = 0xa000000; // int dram_cieling = 0xa00ffff; //read out data from all integration channels // Read only Adj Average data from DRAM int dram_base = 0xa000000; int dram_cieling = 0xA004000; //read out just adjacent average (0xA004000 - 0xa000000 = 16384) Xil_DCacheInvalidateRange(0x00000000, 65536); for (dram_addr = dram_base; dram_addr <= dram_cieling; dram_addr+=4){ if (!sw) { sw = XGpioPs_ReadPin(&Gpio, SW_BREAK_GPIO); } //read pin data = Xil_In32(dram_addr); xil_printf("%d\r\n",data); XUartPs_Recv(&Uart_PS, &RecvBuffer, 32); if ( RecvBuffer[0] == 'q' ) { sw = 1; } if(sw) { return sw; } } return sw; }
void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) { BaseType_t xLEDState; ( void ) uxLED; xLEDState = XGpioPs_ReadPin( &xGpio, partstLED_OUTPUT ); XGpioPs_WritePin( &xGpio, partstLED_OUTPUT, !xLEDState ); }
/***************************************************************************** * * This function gets a GPIO button device state configured as INPUT. * * @param None. * * @return 1 if depressed, else 0. * * @note None. * ****************************************************************************/ int ps_gpio_get_button(zed_ali3_controller_demo_t *pDemo, int button_number) { int button_state; /* * Set the direction for the specified pin to be input. */ #ifdef PS_GPIO_USER_BUTTON0 if (button_number == 0) { XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), PS_GPIO_USER_BUTTON0, 0); } #ifdef PS_GPIO_USER_BUTTON1 else if (button_number == 1) { XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), PS_GPIO_USER_BUTTON1, 0); } #endif #else XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), (PS_GPIO_USER_BUTTON_START + button_number), 0); #endif /* * Read the state of the data so that it can be verified. */ #ifdef PS_GPIO_USER_BUTTON0 if (button_number == 0) { button_state = XGpioPs_ReadPin(&(pDemo->gpio_driver), PS_GPIO_USER_BUTTON0); } #ifdef PS_GPIO_USER_BUTTON1 else if (button_number == 1) { button_state = XGpioPs_ReadPin(&(pDemo->gpio_driver), PS_GPIO_USER_BUTTON1); } #endif #else button_state = XGpioPs_ReadPin(&(pDemo->gpio_driver), (PS_GPIO_USER_BUTTON_START + button_number)); #endif return button_state; }
/** * * This function performs a test on the GPIO driver/device with the GPIO * configured as INPUT. * * @param DataRead is the pointer where the data read from GPIO Input is * returned * * @return - XST_SUCCESS if the example has completed successfully. * - XST_FAILURE if the example has failed. * * @note None. * ******************************************************************************/ static int GpioInputExample(u32 *DataRead) { /* * Set the direction for the specified pin to be input. */ XGpioPs_SetDirectionPin(&Gpio, INPUT_PIN, 0x0); /* * Read the state of the data so that it can be verified. */ *DataRead = XGpioPs_ReadPin(&Gpio, INPUT_PIN); return XST_SUCCESS; }
/***************************************************************************** * * This function gets a GPIO switch device state configured as INPUT. * * @param None. * * @return 1 if set to ON postion, else 0. * * @note None. * ****************************************************************************/ int ps_gpio_get_switch(zed_ali3_controller_demo_t *pDemo, int switch_number) { int switch_state; /* * Set the direction for the specified pin to be input. */ XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), (PS_GPIO_USER_SWITCH_START + switch_number), 0); /* * Read the state of the data so that it can be verified. */ switch_state = XGpioPs_ReadPin(&(pDemo->gpio_driver), (PS_GPIO_USER_SWITCH_START + switch_number)); return switch_state; }
/***************************************************************************** * * This function gets a GPIO MIO state configured as INPUT. * * @param None. * * @return 1 if depressed, else 0. * * @note None. * ****************************************************************************/ int ps_gpio_get_mio_state(zed_ali3_controller_demo_t *pDemo, int mio_number) { int mio_state; /* * Set the direction for the specified pin to be input. */ XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), mio_number, 0); /* * Read the state of the data so that it can be verified. */ mio_state = XGpioPs_ReadPin(&(pDemo->gpio_driver), mio_number); return mio_state; }
/***************************************************************************** * * This function gets a GPIO button device state configured as INPUT. * * @param None. * * @return 1 if depressed, else 0. * * @note None. * ****************************************************************************/ int ps_gpio_get_button(zed_ali3_controller_demo_t *pDemo, int button_number) { int button_state; /* * Set the direction for the specified pin to be input. */ XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), (PS_GPIO_USER_BUTTON_START + button_number), 0); /* * Read the state of the data so that it can be verified. */ button_state = XGpioPs_ReadPin(&(pDemo->gpio_driver), (PS_GPIO_USER_BUTTON_START + button_number)); return button_state; }
/***************************************************************************//** * @brief gpio_get_value *******************************************************************************/ int32_t gpio_get_value(uint8_t pin, uint8_t *data) { #ifdef _XPARAMETERS_PS_H_ *data = XGpioPs_ReadPin(&gpio_instance, pin); #else uint32_t channel = 1; uint32_t config = 0; /* We assume that pin 32 is the first pin from channel 2 */ if (pin >= 32) { channel = 2; pin -= 32; } config = XGpio_DiscreteRead(&gpio_instance, channel); *data = (config & (1 << pin)) ? 1 : 0; #endif return 0; }
//////////////////////////// DAQ //////////////////////////////// int DAQ(){ int buffsize; //BRAM buffer size int dram_addr; // DRAM Address XUartPs_SetOptions(&Uart_PS,XUARTPS_OPTION_RESET_RX); Xil_Out32 (XPAR_AXI_DMA_0_BASEADDR + 0x48, 0xa000000); // DMA Transfer Step 1 Xil_Out32 (XPAR_AXI_DMA_0_BASEADDR + 0x58 , 65536); // DMA Transfer Step 2 sleep(1); // Built in Latency ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 s ClearBuffers(); // Clear Buffers. // Capture garbage in DRAM for (dram_addr = 0xa000000; dram_addr <= 0xA004000; dram_addr+=4){Xil_In32(dram_addr);} while(1){ buffsize = Xil_In32 (XPAR_AXI_GPIO_11_BASEADDR); if (!sw) { sw = XGpioPs_ReadPin(&Gpio, SW_BREAK_GPIO); } //read pin XUartPs_Recv(&Uart_PS, &RecvBuffer, 32); if ( RecvBuffer[0] == 'q' ) { sw = 1; } if(sw) { return sw; } if(buffsize >= 4095){ //Xil_Out32 (XPAR_AXI_GPIO_18_BASEADDR, 0); // Disable Capture Module in FPGA Xil_Out32 (XPAR_AXI_GPIO_15_BASEADDR, 1); //sleep(10); // Built in Latency ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 s Xil_Out32 (XPAR_AXI_DMA_0_BASEADDR + 0x48, 0xa000000); Xil_Out32 (XPAR_AXI_DMA_0_BASEADDR + 0x58 , 65536); sleep(1); // Built in Latency ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 s Xil_Out32 (XPAR_AXI_GPIO_15_BASEADDR, 0); //Xil_Out32(XPAR_AXI_GPIO_18_BASEADDR, 1); ClearBuffers(); PrintData(); } } return sw; }
int readPin (int pin) { int retVal = XGpioPs_ReadPin(&structXGpioPs, pin); return (retVal); }
/** * * This function does a minimal test on the GPIO device configured as OUTPUT. * * @param None. * * @return - XST_SUCCESS if the example has completed successfully. * - XST_FAILURE if the example has failed. * * @note None. * ****************************************************************************/ static int GpioOutputExample(void) { u32 Data; volatile int Delay; u32 LedLoop; /* * Set the direction for the pin to be output and * Enable the Output enable for the LED Pin. */ XGpioPs_SetDirectionPin(&Gpio, OUTPUT_PIN, 1); XGpioPs_SetOutputEnablePin(&Gpio, OUTPUT_PIN, 1); /* * Set the GPIO output to be low. */ XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x0); for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop ++) { #ifndef __SIM__ /* * Wait a small amount of time so the LED is visible. */ for (Delay = 0; Delay < LED_DELAY; Delay++); #endif /* * Set the GPIO Output to High. */ XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x1); /* * Read the state of the data and verify. If the data * read back is not the same as the data written then * return FAILURE. */ Data = XGpioPs_ReadPin(&Gpio, OUTPUT_PIN); if (Data != 1 ) { return XST_FAILURE; } #ifndef __SIM__ /* * Wait a small amount of time so the LED is visible. */ for (Delay = 0; Delay < LED_DELAY; Delay++); #endif /* * Clear the GPIO Output. */ XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x0); /* * Read the state of the data and verify. If the data * read back is not the same as the data written then * return FAILURE. */ Data = XGpioPs_ReadPin(&Gpio, OUTPUT_PIN); if (Data != 0) { return XST_FAILURE; } } return XST_SUCCESS; }
int main (void) { XGpio sw, led; int i, pshb_check, sw_check; XGpioPs_Config*GpioConfigPtr; int xStatus; int iPinNumberEMIO = 54; u32 uPinDirectionEMIO = 0x0; u32 uPinDirection = 0x1; xil_printf("-- Start of the Program --\r\n"); // AXI GPIO switches Intialization XGpio_Initialize(&sw, XPAR_SWITCHES_DEVICE_ID); // AXI GPIO leds Intialization XGpio_Initialize(&led, XPAR_LEDS_DEVICE_ID); // PS GPIO Intialization GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID); if(GpioConfigPtr == NULL) return XST_FAILURE; xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr, GpioConfigPtr, GpioConfigPtr->BaseAddr); if(XST_SUCCESS != xStatus) print(" PS GPIO INIT FAILED \n\r"); //PS GPIO pin setting to Output XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumber,uPinDirection); XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumber,1); //EMIO PIN Setting to Input port XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumberEMIO,uPinDirectionEMIO); XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberEMIO,0); xil_printf("-- Press BTNR (Zedboard) or BTN3 (Zybo) to see the LED light --\r\n"); xil_printf("-- Change slide switches to see corresponding output on LEDs --\r\n"); xil_printf("-- Set slide switches to 0x0F to exit the program --\r\n"); while (1) { sw_check = XGpio_DiscreteRead(&sw, 1); XGpio_DiscreteWrite(&led, 1, sw_check); pshb_check = XGpioPs_ReadPin(&psGpioInstancePtr,iPinNumberEMIO); XGpioPs_WritePin(&psGpioInstancePtr,iPinNumber,pshb_check); if((sw_check & 0x0f)==0x0F) break; for (i=0; i<9999999; i++); // delay loop } xil_printf("-- End of Program --\r\n"); #ifdef MULTIBOOT // Driver Instantiations XDcfg XDcfg_0; u32 MultiBootReg = 0; #define PS_RST_CTRL_REG (XPS_SYS_CTRL_BASEADDR + 0x200) #define PS_RST_MASK 0x1 /* PS software reset */ #define SLCR_UNLOCK_OFFSET 0x08 // Initialize Device Configuration Interface XDcfg_Config *Config = XDcfg_LookupConfig(XPAR_XDCFG_0_DEVICE_ID); XDcfg_CfgInitialize(&XDcfg_0, Config, Config->BaseAddr); MultiBootReg = 0; // Once done, boot the master image stored at 0xfc00_0000 Xil_Out32(0xF8000000 + SLCR_UNLOCK_OFFSET, 0xDF0DDF0D); // unlock SLCR XDcfg_WriteReg(XDcfg_0.Config.BaseAddr, XDCFG_MULTIBOOT_ADDR_OFFSET, MultiBootReg); // write to multiboot reg // synchronize __asm__( "dsb\n\t" "isb" ); Xil_Out32(PS_RST_CTRL_REG, PS_RST_MASK); #endif return 0; }