05-23-2018 12:18 AM
Hi,
I am using SDK 2017.2 for making a multicore application in zync mpsoc. I have a test data file in which every data is floating point value. I am running my code on FREE RTOS . I enabled xilffs bsp library and i am using 'f_read' function to read the data. Problem that i am facing is ,if data value is 234.567, 'fread ' will read '2','3','4','.','5','6','7' as individual characters. I want to read 234.567 as a single data and i want to store data into a floating point variable. Can anyone help me with this.
In simple words i want to replicate 'fscanf' function ?
I am attaching my input file also.
Thanks and Regards,
Sarath
05-27-2018 11:28 PM
Hi All,
I have posted above question some days back. I found answer for this. i am giving the same program below .
Notes: file which you want to read should be a bin file , you have write float data into a bin file instead of text file.
increase stack/heap size depending upon your buffer size.
program is tested on : Zync Ultrascale MPSOC (ZCU102).
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "ff.h"
#define TOTAL_SIZE (512*256*16*8)
typedef struct complex {
float real;
float imag;
}cmplx;
int main()
{
FATFS def_drive;
FRESULT rc;
FIL fp1;
UINT bytes_read;
UINT bytesToBeRd = sizeof(cmplx) * TOTAL_SIZE;
//cmplx data_test[10];
cmplx data[TOTAL_SIZE];
init_platform();
print("Hello World\n\r");
if((rc = f_mount(&def_drive,"0:",0)) != FR_OK)
{
print("ERROR : f_mount failed\n\r");
return 0;
}
if((rc = f_open(&fp1,"0:elevOut.bin",FA_OPEN_EXISTING | FA_READ)) != FR_OK)
{
print("ERROR : f_open failed\n\r");
return 0;
}
if((rc = f_read(&fp1,&data[0],bytesToBeRd,&bytes_read)) != FR_OK)
{
print("ERROR : f_read failed\n\r");
return 0;
}
if((rc = f_close(&fp1)) != FR_OK)
{
print("ERROR : f_close failed\n\r");
return 0;
}
cleanup_platform();
return 0;
}
regards,
sarath
05-23-2018 06:12 AM
> i want to replicate 'fscanf' function ?
It's only 5 KiB ... why not just read the whole file into memory? ... then just use sscanf to your hearts content?
05-26-2018 06:33 AM
Thank you for ur reply.
Can u tell me where is this sscanf function defined and how to use it?
i have files with bigger size also at that time how can i read the whole file ?
Regards,
sarath
05-27-2018 11:28 PM
Hi All,
I have posted above question some days back. I found answer for this. i am giving the same program below .
Notes: file which you want to read should be a bin file , you have write float data into a bin file instead of text file.
increase stack/heap size depending upon your buffer size.
program is tested on : Zync Ultrascale MPSOC (ZCU102).
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "ff.h"
#define TOTAL_SIZE (512*256*16*8)
typedef struct complex {
float real;
float imag;
}cmplx;
int main()
{
FATFS def_drive;
FRESULT rc;
FIL fp1;
UINT bytes_read;
UINT bytesToBeRd = sizeof(cmplx) * TOTAL_SIZE;
//cmplx data_test[10];
cmplx data[TOTAL_SIZE];
init_platform();
print("Hello World\n\r");
if((rc = f_mount(&def_drive,"0:",0)) != FR_OK)
{
print("ERROR : f_mount failed\n\r");
return 0;
}
if((rc = f_open(&fp1,"0:elevOut.bin",FA_OPEN_EXISTING | FA_READ)) != FR_OK)
{
print("ERROR : f_open failed\n\r");
return 0;
}
if((rc = f_read(&fp1,&data[0],bytesToBeRd,&bytes_read)) != FR_OK)
{
print("ERROR : f_read failed\n\r");
return 0;
}
if((rc = f_close(&fp1)) != FR_OK)
{
print("ERROR : f_close failed\n\r");
return 0;
}
cleanup_platform();
return 0;
}
regards,
sarath
08-21-2019 03:44 AM
Hi sarath,
I want to read text file which is off size 19MB and store it into DDR memory.
How can I do that operation? Application should be linux or baremetal?
Your input is highly appreciated
Thanks and regards.