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: fwrite not working as required.



Tool/software: Code Composer Studio

Hello Team,

I created simple CCS project for edge detection,i used .y extension file as input and generating .y output file which should detect the edge of image.

But when i try to see .y output which is generated image is not properly generated,so i opened same file editor so i came to know that file is not properly written.

Afterwards i used same .c file and run it on gcc platform and checked output file that file is properly generated and edges are also clearly visible in that.

So,can you suggest any pointer for running code on DSP core ....? 

I am using cmd file from path "vision_sdk/ti_components/drivers/pdk_01_08_00_16/packages/ti/csl/example" : lnk_dsp.cmd

Please find attached source file for your reference.

#include <stdio.h>
#include <stdlib.h>
#define WIDTH   640
#define HEIGHT  480


void main()
{

    
	int size,x,y,value;

	unsigned int *data[2];

	FILE   *Fp_input;
	FILE   *Fp_output;
	unsigned char buffer1[WIDTH];
	unsigned char buffer2[WIDTH];

	unsigned char *ptr1, *ptr2, *inptr1, *inptr2, *inptr3, *temp;
	unsigned int WordWidth = sizeof(unsigned int);

    

	data[0] = (unsigned int*)malloc(WIDTH*HEIGHT);
	data[1] = (unsigned int*)malloc((WIDTH*HEIGHT)/2);
	ptr1 = buffer1;
	ptr2 = buffer2;

	Fp_output = fopen("output.y","wb");
    if ( Fp_output == 0 )
    {
            printf("couldn't write output file");
            exit(EXIT_FAILURE);
    }
    
	
	Fp_input = fopen("VGA.y","rb");
	
	if ( Fp_input == 0 )
	{
        	printf("couldn't open input file");
        	exit(EXIT_FAILURE);
	}
	else 
	{

	//while(!feof(Fp_input))
	{
		size = fread( data[0], WordWidth, (WIDTH*HEIGHT)/(WordWidth), Fp_input );
		//size = fread( data[1], WordWidth, (WIDTH*HEIGHT)/(2*WordWidth), Fp_input );

		inptr1 = data[0] ;
		inptr2 = inptr1+WIDTH ;
		inptr3 = inptr2+WIDTH ;
		memcpy(ptr1 , inptr1 , WIDTH);
		for ( y = 1; y < HEIGHT; ++y) 
		{
			
                for ( x = 1; x < WIDTH; ++x)
                {
                    value = *(inptr1+(x-1))*(-2)   +   *(inptr1+(x))*(-1)  +  *(inptr1+(x+1))*(-2) +
                        *(inptr2+(x-1))*(0)   +   *(inptr2+(x))*(0)  +  *(inptr2+(x+1))*(0)  +
                        *(inptr3+(x-1))*(2)   +   *(inptr3+(x))*(1)  +  *(inptr3+(x+1))*(2) ;
                    if (value< 0)
                        value =0;
                    if (value>255)
                        value =255;
                    *(ptr2+x) = value;
                }
        memcpy(inptr1 , ptr1 ,WIDTH);
        temp = ptr1;
        ptr1 = ptr2;
        ptr2= temp;
        inptr1 += WIDTH;
        inptr2 += WIDTH;
        inptr3 += WIDTH;
	}

		fwrite( data[0], WordWidth,   (WIDTH*HEIGHT)/WordWidth, Fp_output );
   }

  }

}

Regards,

Pritam

  • Pritam,

    You did not mention which device you are using, but I ran your code on my TDA3x board and it lacks the VGA.y input file for proper testing.

    The linker.cmd file you are using looks ok, although I used one of the more device-oriented linker .cmd files present in the following sub-directory:

    PROCESSOR_SDK_VISION_03_01_00_00\ti_components\drivers\pdk_01_08_00_16\packages\ti\boot\sbl_auto\examples\sbl_multicore_mbx

    Regardless of all this, the compiler warns about incompatible variable types that may cause truncating errors - check the warning below.

    Another detail I would check is the heap size. Console I/O operations use quite a lot of heap. Check sections 2.3 and 2.4 of the following reference: 

    processors.wiki.ti.com/.../Tips_for_using_printf

    Regards,

    Rafael

  • vga.zipPlease find attached input file for your reference,I am using TDA2x device and ccs7.3 version on ubuntu 14.04.

    Meanwhile i will go through sections 2.3 and 2.4 you have suggested.

    Regards,

    Pritam

  • Pritam,

    I am not entirely sure what is the end result you are looking for, but the VGA.y and the output.y results I got here are shown in the following screens, together with the parameters I used. 

    Does that look ok?

    Regards,

    Rafael

  • Hi Rafael,

    Yes,that's the output expected which you have shown in second screen,but i didn't get that output ......?

    The output.y which is generated is showing only black and white strips on image generated.

    I am testing it on TDA2x board for DSP core on ubuntu system.

    And i checked same code on CCS5.5 simulator(on windows platform) it is showing correct output as you have shown in second image....!

    Regards,

    Pritam

  • Pritam,

    I don't have access to my Ubuntu machine at the moment, but I will test this tomorrow.

    Regards,
    Rafael
  • Pritam,

    Unfortunately I still couldn't reproduce this issue in Ubuntu. I tested CCSv7.4 and an internal Beta of 8.0. 

    I suspect there may be something else at play in your environment. Did you make sure the image parameters are identical to what I showed in my screenshots?

    This may be an issue with some temporary settings of the Debugger. Can you check sections 4 and 6 of the Troubleshooting page and see if the suggestions there help you get a correct output? 

    I send attached my project with the generated output.y file. 

    Hope this helps,

    Rafael

    TDA3x_C66_CIO.zip