/****************************************************************************** * * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * Use of the Software is limited solely to applications: * (a) running on a Xilinx device, or * (b) that interact with a Xilinx device through a bus or interconnect. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the Xilinx shall not be used * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * ******************************************************************************/ /* * helloworld.c: simple test application * * This application configures UART 16550 to baud rate 9600. * PS7 UART (Zynq) is not initialized by this application, since * bootrom/bsp configures it to baud rate 115200 * * ------------------------------------------------ * | UART TYPE BAUD RATE | * ------------------------------------------------ * uartns550 9600 * uartlite Configurable only in HW design * ps7_uart 115200 (configured by bootrom/bsp) */ #include #include "platform.h" #include "xil_printf.h" #include "xgpio.h" #include "xbram.h" #include "xil_cache.h" #include "xparameters.h" #include "xil_io.h" void delay(long int); void init_io(void); void init_bram(void); #define GPIO_DEVICE_ID0 XPAR_GPIO_0_DEVICE_ID #define GPIO_DEVICE_ID1 XPAR_GPIO_1_DEVICE_ID #define GPIO_DEVICE_ID2 XPAR_GPIO_2_DEVICE_ID #define GPIO_DEVICE_ID3 XPAR_GPIO_3_DEVICE_ID static XGpio Gpio0; /* The Instance of the GPIO Driver */ static XGpio Gpio1; /* The Instance of the GPIO Driver */ static XGpio Gpio2; /* The Instance of the GPIO Driver */ static XGpio Gpio3; /* The Instance of the GPIO Driver */ static XBram Bram; /* The Instance of the BRAM Driver */ uint16_t uiData; int main() { uint8_t flag, scratch = 0, synch, gathering; uint16_t uiLoop, index; init_platform(); init_io(); init_bram(); XGpio_DiscreteWrite(&Gpio0, 1, 1); //Turn off reset line delay(2); //wait for some clocks XGpio_DiscreteWrite(&Gpio0, 1, 0); //Turn off reset line synch = 0; gathering = 0; XGpio_DiscreteWrite(&Gpio0, 2, 1); //Turn on synch line while(1) { flag = XGpio_DiscreteRead(&Gpio1, 1) & 0xf; //Read the Synch Modules Synch line scratch = flag & 0x1; xil_printf("Main Loop Active\r\n"); if((scratch == 1) && (synch == 0)) //Synch to the known word has occured { xil_printf("Synchronizer has synched with ADC\r\n"); XGpio_DiscreteWrite(&Gpio0, 2, 0); //Turn off synch line XGpio_DiscreteWrite(&Gpio1, 2, 1); //Turn on BRAM read mode synch = 1; //Move to the next step in the process } else if((scratch == 0) && (synch == 0)) { xil_printf("Synchronizer has not synched with ADC\r\n"); XGpio_DiscreteWrite(&Gpio0, 2, 0); //Turn off synch line XGpio_DiscreteWrite(&Gpio0, 1, 1); //Turn off reset line delay(100); //wait for some clocks XGpio_DiscreteWrite(&Gpio0, 1, 0); //Turn off reset line XGpio_DiscreteWrite(&Gpio0, 2, 1); //Turn on synch line } if((synch == 1) && (gathering == 0)) //the adc has synched to the deserializer. { XGpio_DiscreteWrite(&Gpio2, 2, 0); //Turn the counter on xil_printf("Gathering data from ADC\r\n"); gathering = 1; } if(gathering == 1) { flag = XGpio_DiscreteRead(&Gpio2, 1) & 0xf; //wait until the count is done scratch = flag & 0x1; xil_printf("Checking for count done bit\r\n"); if(scratch == 1) { XGpio_DiscreteWrite(&Gpio1, 2, 0); //Turn on BRAM write mode delay(10); //wait a little for(uiLoop = 0 ; uiLoop <= 511 ; uiLoop+=4) { uiData = XBram_In32(XPAR_BRAM_2_BASEADDR + uiLoop); xil_printf("%x %x \n\r", uiData, uiLoop); } xil_printf("%x\n\r", index); } XGpio_DiscreteWrite(&Gpio2, 2, 1); //Reset the counter delay(10); XGpio_DiscreteWrite(&Gpio1, 2, 1); //Turn on BRAM read mode scratch = 0; gathering = 0; } delay(100); } cleanup_platform(); return 0; } void init_io(void) { int Status; Status = XGpio_Initialize(&Gpio0, GPIO_DEVICE_ID0); if (Status != XST_SUCCESS) { xil_printf("Gpio Initialization Failed\r\n"); } XGpio_SetDataDirection(&Gpio0, 1, 0x0); //Reset line XGpio_SetDataDirection(&Gpio0, 2, 0x0); //Synch line XGpio_DiscreteWrite(&Gpio0, 1, 0); //Turn off reset line XGpio_DiscreteWrite(&Gpio0, 2, 0); //Turn off synch line Status = XGpio_Initialize(&Gpio1, GPIO_DEVICE_ID1); if (Status != XST_SUCCESS) { xil_printf("Gpio Initialization Failed\r\n"); } XGpio_SetDataDirection(&Gpio1, 1, 0x1); //Modules are synched XGpio_SetDataDirection(&Gpio1, 2, 0x0); //BRAM read / write: 0 = write to control, 1 = lets BRAM read ADC Status = XGpio_Initialize(&Gpio2, GPIO_DEVICE_ID2); if (Status != XST_SUCCESS) { xil_printf("Gpio Initialization Failed\r\n"); } XGpio_SetDataDirection(&Gpio2, 1, 1); //counter is done counting 1024 words from ADC XGpio_SetDataDirection(&Gpio2, 2, 0); //Reset Counter: 0 = Normal Operations, 1 = Reset XGpio_DiscreteWrite(&Gpio2, 2, 1); //Hold counter in reset until needed Status = XGpio_Initialize(&Gpio3, GPIO_DEVICE_ID3); if (Status != XST_SUCCESS) { xil_printf("Gpio Initialization Failed\r\n"); } XGpio_SetDataDirection(&Gpio3, 1, 0x3); //bitslip check } void init_bram(void) { int Status; XBram_Config *ConfigPtr; ConfigPtr = XBram_LookupConfig(XPAR_AXI_BRAM_CTRL_0_DEVICE_ID); if (ConfigPtr == (XBram_Config *) NULL) { return XST_FAILURE; } Status = XBram_CfgInitialize(&Bram, ConfigPtr, ConfigPtr->CtrlBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } } void delay(long int x){ int z = x * 100; for (int b = z; b > 0; b--) { x++; } }