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

'c' casting in sfr space data

i have an unusual problem which i'd very much like some help with.

i'm using floating point notation in my project, however it is a defacto 16 bit floating point system with a hardware engine doing all the hard arthmetic work. this engine is mapped into the 8052 sfr space.

this system has the problem that when debugging in an fpga we can't use the uv2 to view the 16 bit floats in useful format. ie we can't view '3.14' in the watch window, we get '0xABCD'.

an attempt to work around this problem has been to get the hardware engine to report its output in 32 bit ieee float format. the idea was that i could then park a 'float' type _at_ that location and watch it in the view window.

the obvious (with hindsight) problem is that it is not possible to declare variables in the sfr space. nor was i able to make a pointer point to that space.

is there anything else that i can do to view this data?

any thoughts or opinions very welcome,

robert young

Parents
  • nor was i able to make a pointer point to that space

    The 8051 architecture uses the high bit of the internal memory address in conjunction with the addressing mode to figure out what memory space to access. 00H-7Fh is 128 bytes of internal RAM for both direct and indirect addressing. 80H-FFH is SFR space for instructions using direct addressing. 80H-FFH is the indirect space (another 128 bytes of RAM) for instructions that do indirect addressing.


    a uVision Debug Function

    With a big enough sledgehammer, I think you could make it work. Something like:

    printf ("%f", ((U32)r1 << 24 + (U32)r2 << 16  + (U32)r3 << 8 + r4));
    

    where r1..r4 are the SFR registers that hold the IEEE 754 result. As long as you get the four bytes passed to printf in the correct order, it should work. Don't want to cast (convert) to float, though, or it would print a big integer.

    Come to think of it, if you're willing to confuse people and make lint scream even louder, you could just stuff the four bytes onto the stack:

    printf ("%f", r1, r2, r3, r4);
    

    printf() won't really know how the bytes got into its parameter region.

    One simple and ugly way might be to copy the SFRs down into the internal RAM space at a place where you can declare a float variable.

Reply
  • nor was i able to make a pointer point to that space

    The 8051 architecture uses the high bit of the internal memory address in conjunction with the addressing mode to figure out what memory space to access. 00H-7Fh is 128 bytes of internal RAM for both direct and indirect addressing. 80H-FFH is SFR space for instructions using direct addressing. 80H-FFH is the indirect space (another 128 bytes of RAM) for instructions that do indirect addressing.


    a uVision Debug Function

    With a big enough sledgehammer, I think you could make it work. Something like:

    printf ("%f", ((U32)r1 << 24 + (U32)r2 << 16  + (U32)r3 << 8 + r4));
    

    where r1..r4 are the SFR registers that hold the IEEE 754 result. As long as you get the four bytes passed to printf in the correct order, it should work. Don't want to cast (convert) to float, though, or it would print a big integer.

    Come to think of it, if you're willing to confuse people and make lint scream even louder, you could just stuff the four bytes onto the stack:

    printf ("%f", r1, r2, r3, r4);
    

    printf() won't really know how the bytes got into its parameter region.

    One simple and ugly way might be to copy the SFRs down into the internal RAM space at a place where you can declare a float variable.

Children
No data