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

mapping SFR space

How would I locate a structure to coincide with the beginning of SFR space for the 8051? address 0x80 of directly assessible data memory.

We are using a core8051 (inside an FPGA), and the core8051 lets us map external events to SFR space. So it would be very convienent to define a structure which allows us to more easily access all of SFR space. (we take care not to "stomp" on already defined SFR registers.

How can I do that?

Thanks

Parents
  • Hopefully

    That's exactly the problem, in a single word. You're relying on hope to resolve a technical problem. That cannot ever, possibly, be a good idea.

    That link you dug up doesn't actually define the struct in C --- it declares it in C, then defines the address (but not the size) in assembly. The C compiler doesn't even know this structure is in SFR space. That opens a can of worms like you wouldn't believe. E.g. if you were to use struct assignment on such a struct, the compiler would almost certainly use its internal equivalent of memcpy() to do that --- but that uses pointers, and there is no such thing as a pointer to an SFR. Madness will ensue.

    Basically none of the things for which a struct offers any actual advantage over individual variables can really work if the struct is in SFR space. The net gain between

    sfr foo_a;
    sfr foo_b;
    sfr foo_c;
    


    and what you want to do:

    sfr struct {
       u8 a;
       u8 b;
       u8 c;
    } foo;
    


    is, for practical purposes, zero.

Reply
  • Hopefully

    That's exactly the problem, in a single word. You're relying on hope to resolve a technical problem. That cannot ever, possibly, be a good idea.

    That link you dug up doesn't actually define the struct in C --- it declares it in C, then defines the address (but not the size) in assembly. The C compiler doesn't even know this structure is in SFR space. That opens a can of worms like you wouldn't believe. E.g. if you were to use struct assignment on such a struct, the compiler would almost certainly use its internal equivalent of memcpy() to do that --- but that uses pointers, and there is no such thing as a pointer to an SFR. Madness will ensue.

    Basically none of the things for which a struct offers any actual advantage over individual variables can really work if the struct is in SFR space. The net gain between

    sfr foo_a;
    sfr foo_b;
    sfr foo_c;
    


    and what you want to do:

    sfr struct {
       u8 a;
       u8 b;
       u8 c;
    } foo;
    


    is, for practical purposes, zero.

Children
No data