Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

Peculiar compiled code behaviour

Altera_Forum
Honored Contributor II
1,035 Views

Hello, 

 

I'm currently working on a system consisting of several Nios II/f processors, all of which do not have a d-cache. To check that my program works correctly on the processors, I have created a code project for just one of the processors. Now heres the peculiar part, lets say I have the follow code segment: 

 

typedef struct  

int width; 

int height; 

char *data; 

} Image; 

 

 

Image* Resize(Image *input, float scaleFactor) 

Image *resizedIm = malloc(sizeof(Image)); 

 

resizedIm->width = input->width * scaleFactor; 

resizedIm->height = input->height * scaleFactor; 

 

... (and some other stuff) 

 

return resizedIm; 

 

int main(void) 

Image Im; // read in from a file 

Image *smallImage = Resize(im, 0.25); 

 

... (other processing stuff) 

 

Now, when I run the code I find that the contents of the image returned is garbage data, and it seems like the assignment of the width and height of the resized image is not getting the true value. If I go into debugging this and just step over the line "Image *smallImage = Resize(im, 0.25)", I find that I still get garbage data. But if I go into the Resize function and step over every line of code, I find that the values assigned to the width and height are correct. 

 

This program was working previously with a single core system with a Nios II/f processor with d-cache, and it still does. As such, based on this system I'd created another system, exactly the same as this one but with no d-cache. Once again I find the same issue - so I'm pretty sure its not a multiproccessor issue. I got really frustrated and just rebuilt the system (regenerated in SOPC and in Quartus) and funnily enough, it worked. I tried the same trip on the multiprocessor system but without much luck. 

 

I have looked at whether there is a memory leak issue, and applied the most recent patches without much luck. This is something that is really strange. Has anyone come across a similar issue because any kind of feedback on this would be really appreciated. 

 

I am using Quartus II 5.1 with SP2. The development board is a EP1S40. 

 

Kind regards, 

Colin
0 Kudos
0 Replies
Reply