This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Hardware Implementation

hi i created a hardware that calculates the square root of (a^2+b^2 )

i sent the inputs (a and b) with assembly and that was fine however when i tried to send them using c code the hardware take them as inputs calculates a^2 + b^2 but never do the square root

i am really clueless here i couldn't locate the problem

heeeeeeeeeeeeeeelp

Parents
  • Assuming regdistance is an address of your hardware peripheral, then it needs to be a pointer, not an integer, and you need to write to the value pointed at by the pointer, rather than just setting the address locally. Eg. something like:

    volatile unsigned int * regdistance __attribute__((at(0x59000000)));
    int main() { 
        int i;
        for( i=0;i<10;i++) {
            xd[0]=0;
            yd[0]=0;
            xd[i+1]= xd[i]+1;
            yd[i+1]= yd[i]+1;
    
            *regdistance = xd[i];
            *regdistance = yd[i];
        }
        while(1);
    }
    

    P.S. It looks like you will overflow your loop (I had to guess a bit what the expected indentation for the for loop was). E.g. your access xd[i+1] will access xd[10]which is element 11 in the array, but they are only allocated as 10 elements long.

    HTH,
    Pete

Reply
  • Assuming regdistance is an address of your hardware peripheral, then it needs to be a pointer, not an integer, and you need to write to the value pointed at by the pointer, rather than just setting the address locally. Eg. something like:

    volatile unsigned int * regdistance __attribute__((at(0x59000000)));
    int main() { 
        int i;
        for( i=0;i<10;i++) {
            xd[0]=0;
            yd[0]=0;
            xd[i+1]= xd[i]+1;
            yd[i+1]= yd[i]+1;
    
            *regdistance = xd[i];
            *regdistance = yd[i];
        }
        while(1);
    }
    

    P.S. It looks like you will overflow your loop (I had to guess a bit what the expected indentation for the for loop was). E.g. your access xd[i+1] will access xd[10]which is element 11 in the array, but they are only allocated as 10 elements long.

    HTH,
    Pete

Children