2

i'm working on an embedded C program, where the killnoise function is not executed even if it is called and the program always reach it, but when i chek the values at the output of this function i just discover that nothig happened:

void KillNoise( int* array, int size )
{
  int k;

    for (k=0;k<size;k++)
    {
       if (array[k] < 20)
           array[k] = 0;
    }

}

here is where and how i call it :

void UX_zswDecide( void )
{
    float __xdata centerOfMass[UX_NUM_SENSORS];
    float __xdata vectx, vecty, module, tg;
    int __xdata i,j;

    KillNoise( UX_bigUpArray,    NUMPOINTS );
    KillNoise( UX_bigDownArray,  NUMPOINTS );
    KillNoise( UX_bigLeftArray, NUMPOINTS );
    KillNoise( UX_bigRightArray,  NUMPOINTS );

/* the rest of the function */ 
}

where NUMPOINTS, biguparray, bigleftarray ... are global variables declared previously:

int   __xdata UX_bigUpArray[100];

int   __xdata UX_bigDownArray[100] ;

int   __xdata UX_bigLeftArray[100];
int   __xdata UX_bigRightArray[100] ;

#define NUMPOINTS 100 

thank you a lot for your help, (i'm facing the same issue with another function)

Tarik Mokafih
  • 1,247
  • 7
  • 19
  • 38
  • This looks ok in isolation. Can you provide a [minimal test-case](http://sscce.org)? – Oliver Charlesworth Apr 30 '12 at 09:04
  • Based on the data you provided, your code seems to be OK. There is something else we don't see that cause your code not working. – MrTJ Apr 30 '12 at 09:05
  • 2
    Nothing would happen if all the values in the array were equal to or greater than 20. – Nick Apr 30 '12 at 09:06
  • 1
    are you sure that UX_zswDecide(()is executing? if it was not executing then KillNoise() will not be called – Jeegar Patel Apr 30 '12 at 09:08
  • i'm sure the UX_zswDecide() is executed the debuger even shows that the program enters to killnoise() but the output is the same as the input the big**arrays stay unchanged even if there is a lot of values less than 20 – Tarik Mokafih Apr 30 '12 at 09:17
  • what's important of __xdata here? – Jeegar Patel Apr 30 '12 at 09:28
  • just for testing mask all member of that array to 0 and cross check that that function is realy calling...!! we dont have full PICTURE so we cant help you more.. – Jeegar Patel Apr 30 '12 at 09:31
  • I believe that `__xdata` sticks the variable into external RAM rather than processor memory. – Nick Apr 30 '12 at 09:43
  • if i try to compile without __xdata i don't get enough memory space so the linking fails. – Tarik Mokafih Apr 30 '12 at 09:50
  • 4
    Is this a cut'n'paste from your source? If not, check you don't have a semi-colon after your for-loop! – Nick Apr 30 '12 at 10:10
  • 1
    @Nick ahh brilliant you are my savior from being expelled from job, hhhhhh – Tarik Mokafih Apr 30 '12 at 10:39
  • You're welcome! We've all done it before! – Nick Apr 30 '12 at 11:21
  • Had to upvote Nick's comment. Took me 5 mintues to figure it out. I thought he was referring to something in the pasted code, then I realized he just pulled that out of his head that the op had an extra semicolon in his code. I was off in the weeds wondering if the data were stored in ram or not. – djs May 02 '12 at 03:12
  • actually, did someone believed Nick's comment ! For me it was a jock, hhhhh, I would hoped if it was as simple as that but unfortunately the problem stills unsolved, – Tarik Mokafih May 02 '12 at 08:34

1 Answers1

1

I think you need __xdata in the declaration of the array parameter in KillNoise

void KillNoise( int* __xdata array, int size )

or something similar.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • yes if i compile without __xdata i get a linking error ( there isn't enought memory space) – Tarik Mokafih Apr 30 '12 at 10:16
  • @TarikMokafih: But your example code just says `void KillNoise( int* array, int size )` I think you need `void KillNoise( int* __xdata array, int size )` or similar – JeremyP Apr 30 '12 at 10:21
  • i just tried it, no difference at all, could it be a debugger problem may be everything is ok, only the debugger doesn't refresh its values and shows every time the values before the killnoise function even if it is supposed to refresh it's values after every stop, there is also something weird i noticed when I’m running the program step by step, it seems that when it arrives to the end of the FOR loop the step by step debugger cursor just disappears while it's supposed to return to the beginning of the FOR loop – Tarik Mokafih Apr 30 '12 at 10:30
  • You don't *need* it but the code will be smaller and faster. – Ben Jackson Feb 24 '14 at 15:57