csv files write issud

Hello there!
I am using pocketbeagle to acquire ADC data and log into csv files. Some time i am getting csv write issue like the shown in the below image. I am storing the data into DDR then the DDR Data will be written into CSV. can anybody help?

Would need to see the code you are using as that is the most likely cause for the corruption.

Hi @benedict.hewson,
i am attaching the code below.

Data flow is as below -
PRU will acquire data(60K samples per second) and will store in DDR, C code in linux will fetch the data and generate the CSV file. I am using 3 buffers(1 Second data). PRU will write data in one buffer an linux will fetch data from other buffer.

PRU code for data write -
volatile uint32_t *ddr_var = (uint32_t *)0x90000000; //address
ddr_var[ ddrCnt++] //write data on ddr address

Read code in linux -
Declare memory address

void *map_base = mmap(NULL, DDR_SIZE, PROT_WRITE, MAP_SHARED, fd, DDR_BASE_ADDR);
if (map_base == MAP_FAILED)
printf(“\nError mapping DDR memory\n”);
return -1;
volatile int *ddr = (volatile int *)map_base;

Read data

comp1 = (int16_t)ddr[i];
cali = comp1 * calFAct;

open file

FILE *ptr;
ptr = fopen(string, "w");

write to csv file

fprintf(ptr , “%.4f\n”,cali);

Let me know your thoghts