#include #include "platform.h" #include "xscutimer.h" #include "xparameters.h" #include "xgpiops.h" #include "xsdps.h" #include "ff.h" #include "xil_printf.h" #include "xil_cache.h" #include "xil_io.h" #define PIN_OFFSET 54 #define MAX_SIZE 30000000 int8_t I0Out[MAX_SIZE] ; int8_t Q0Out[MAX_SIZE] ; int8_t I1Out[MAX_SIZE] ; int8_t Q1Out[MAX_SIZE] ; int8_t ClkOut[MAX_SIZE]; int counter = 0; int count = 0; int Status1,Status2; UINT BytesWritten; int main() { init_platform(); printf("started........"); // Declare some variables that we'll use later int timer_value; int counter = 0; int count = 0; static FATFS FS_instance; static FIL file1; static FIL file2; static FIL file3; static FIL file4; static FIL file5; FRESULT result; TCHAR *Path = "0:/"; int i = 0; int j = 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; // Declare two structs. One for the GPIO instance, and // the other for the GPIO's config information XGpioPs Gpio; XGpioPs_Config *ConfigPtr; // Look up the the config information for the timer Timer_Config = XScuTimer_LookupConfig(XPAR_PS7_SCUTIMER_0_DEVICE_ID); // Look up the the config information for the GPIO ConfigPtr = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID); // Initialize the timer and GPIO using the config information Status1 = XScuTimer_CfgInitialize(&my_Timer, Timer_Config, Timer_Config->BaseAddr); Status2 = XGpioPs_CfgInitialize(&Gpio, ConfigPtr,ConfigPtr->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); // Set GPIO[0:4] as a input port XGpioPs_SetDirectionPin(&Gpio, PIN_OFFSET, 0); XGpioPs_SetOutputEnablePin(&Gpio, PIN_OFFSET, 0); XGpioPs_SetDirectionPin(&Gpio, PIN_OFFSET+1, 0); XGpioPs_SetOutputEnablePin(&Gpio, PIN_OFFSET+1, 0); XGpioPs_SetDirectionPin(&Gpio, PIN_OFFSET+2, 0); XGpioPs_SetOutputEnablePin(&Gpio, PIN_OFFSET+2, 0); XGpioPs_SetDirectionPin(&Gpio, PIN_OFFSET+3, 0); XGpioPs_SetOutputEnablePin(&Gpio, PIN_OFFSET+3, 0); XGpioPs_SetDirectionPin(&Gpio, PIN_OFFSET+4, 0); XGpioPs_SetOutputEnablePin(&Gpio, PIN_OFFSET+4, 0); // Start the timer running (it counts down) XScuTimer_Start(&my_Timer); // Loop for counter seconds. Counter value increments after very seconds. while(1) { // Read the value of GPIO which is connected to I and Q I1Out[count]= XGpioPs_ReadPin(&Gpio, PIN_OFFSET); I0Out[count]= XGpioPs_ReadPin(&Gpio, PIN_OFFSET+1); Q1Out[count]= XGpioPs_ReadPin(&Gpio, PIN_OFFSET+2); Q0Out[count]= XGpioPs_ReadPin(&Gpio, PIN_OFFSET+3); ClkOut[count] = XGpioPs_ReadPin(&Gpio, PIN_OFFSET+4); count++; // 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); //counter++; //printf("seconds: %d \n\r", counter++); // One seconds has reached hence break the loop and check the output data break; } } printf("Count is%d\n\r",count); // mount SD card result = f_mount(&FS_instance,Path, 0); // Opening of file. result = f_open(&file1, "fiile1.csv", FA_OPEN_ALWAYS | FA_WRITE) ; result = f_open(&file2, "file2.csv", FA_OPEN_ALWAYS | FA_WRITE) ; result = f_open(&file3, "file3.csv", FA_OPEN_ALWAYS | FA_WRITE) ; result = f_open(&file4, "file4.csv", FA_OPEN_ALWAYS | FA_WRITE) ; result = f_open(&file5, "file5.csv", FA_OPEN_ALWAYS | FA_WRITE) ; // Points to beginning of file result = f_lseek(&file1, f_size(&file1)); result = f_lseek(&file1, f_size(&file2)); result = f_lseek(&file1, f_size(&file3)); result = f_lseek(&file1, f_size(&file4)); result = f_lseek(&file1, f_size(&file5)); // Writing data to file. for (j = 0; j < count; ++j) { f_printf(&file1,"%d\n",I1Out[j]); f_printf(&file2,"%d\n",I0Out[j]); f_printf(&file3,"%d\n",Q1Out[j]); f_printf(&file4,"%d\n",Q0Out[j]); f_printf(&file5,"%d\n",ClkOut[j]); } // close file f_close(&file1); f_close(&file2); f_close(&file3); f_close(&file4); f_close(&file5); // Unmount SD card f_mount(0,Path,1); printf("Its done........"); cleanup_platform(); return 0; }