This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/PROCESSOR-SDK-DRA8X-TDA4X: read file in tirtos

Part Number: PROCESSOR-SDK-DRA8X-TDA4X

Tool/software: Code Composer Studio

  Hi :

           i     have    run   vision_apps\apps\basic_demos\app_tirtos\tirtos_linux\c66x_1

          then   i   try  to  read  a  file   in   main  like  follow,     length_file is  right   but     inimg_data[0], inimg_data[2], inimg_data[4], inimg_data[6]    is  wrong.

           /////////////////

    FILE * fp_asv_nv21_read = fopen("./input_data.bin", "rb");
    fseek(fp_asv_nv21_read, 0, SEEK_END);
    int    length_file = ftell(fp_asv_nv21_read);

    unsigned char*  inimg_data = (unsigned char*)appMemAlloc(APP_UDMA_HEAP_ID, length_file,UDMA_CACHELINE_ALIGNMENT);
    fseek(fp_asv_nv21_read, 0, SEEK_SET);
    fread(inimg_data, sizeof(char), length_file, fp_asv_nv21_read);
    fclose(fp_asv_nv21_read);
    printf("length_file=%d,p0=%d,p2=%d,p4=%d,p6=%d,", length_file, inimg_data[0], inimg_data[2], inimg_data[4], inimg_data[6]);

thanks

Shuai

  • One of the Tips for Using Printf may solve the problem.  If not, then you need help from the experts on the Processor SDK.  I will notify them about this thread.

    Thanks and regards,

    -George

  • Hi Shuai,

    When you say wrong, is it all NULL? Or is the data shifted? Have you made sure the alloc is happening properly? Since you are running this on C66x, I would suggest to use CCS and connect to this core, step through and check the inimg_data variable after the fread() is called. Because the interpretation of printfs here can be a little messy as the types are getting mixed and so on. Please debug using CCS, and let me know what anomalies you find after doing the fread().

  • Hi :     Anand

             it    printf    Open file recfile,  so   fopen    is   have   some   problem.

    FILE * fp_asv_nv21_read = fopen("input_data.bin","rb");
        if (fp_asv_nv21_read == NULL)
        {
            printf("Open file recfile\n");
        }
        fseek(fp_asv_nv21_read, 0, SEEK_END);
        int    length_file = ftell(fp_asv_nv21_read);
        unsigned char*  inimg_data = (unsigned char*)appMemAlloc(APP_MEM_HEAP_DDR, length_file, 32);
        //unsigned char*  inimg_data[200000];
        fseek(fp_asv_nv21_read, 0, SEEK_SET);
        int readCnt = fread(inimg_data, sizeof(char), length_file, fp_asv_nv21_read);
        printf("readCnt = %d\n", readCnt);
        fclose(fp_asv_nv21_read);
        printf("length_file=%d,p0=%d,p2=%d,p4=%d,p6=%d\n", length_file, inimg_data[0], inimg_data[2], inimg_data[4], inimg_data[6]);
        FILE * fp_asv_nv21_write = fopen("output_data.bin", "w+");
        int    writeCnt = fwrite(inimg_data, length_file, 1, fp_asv_nv21_write);
        printf("writeCnt = %d\n", writeCnt);
        fclose(fp_asv_nv21_write);

    thanks

    shuai

  • Hi Shuai,

    The problem might be as simple as a wrong file path. Did you double check that? Where have you put your file in the SD card?

  • Hi  :Anand

          i  run   this   use  JTAG

          input_data.bin    is  the  same  path  with     .out     ,i   tyr      FILE * fp_asv_nv21_read = fopen("input_data.bin","rb");   

    and   FILE * fp_asv_nv21_read = fopen("./input_data.bin","rb");

    failed   both !

    Thanks

    Shuai

  • Hi Shuai,

    This is because I think you are doing it from an RTOS core. The data in the SD card is in the ext4 partition which is visible only to linux. If you want to do a file read in RTOS, you need to have a partition which can be read by the MMCSD driver (Probably FAT32) and your app should use those APIs to read data from the file. Why do you want to do a file read in the RTOS code anyway? Are you not running your app on A72, and then using the C66x DSP for processing? If you take any of the provided demos which in fact reads from the SD card, they do that in A72. Let me know what is your exact requirement. I can give a solution accordingly.