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

over 16 bit DPTR limit

I have 8051 with 2 DPTR, SFR register to switch data banks(32Kb/16Kb)... Both DPTRs used to increment read/write pointers. I need correct 32bit address increment over all accessible memory.
How to widen DPTR to work with 32 bit address?

Parents Reply Children
  • The Keil tools support extended DPTRs by using far memory. You'll have to customize XBANKING.A51 or L51_BANK.A51 to support your exact hardware.

    The 8051 variants I know with extended DPTRs have 24-bit DPTRs -- one additional byte per pointer. The Keil generic/far pointer scheme is also a 3-byte format, so it can't store 32-bit addresses.

    If you really need 32-bit-wide DPTRs, you're going to have to do most of the work yourself. Create a type that is 32 bits (a structure, as you suggest). Then you'll need to create some library routines to write the upper bits of that value to your extended hardware, and the lower bits to the DPTR proper. You'll probably want routines to set a memory bank and to extract a far pointer from the 32-bit value.

  • The DPTR isn't an integer, so you can't glue together a number of integer variables to form a larger DPTR.

    DPTR has special magic meaning to the processor, resulting in physical memory accesses. If the processor doesn't have the required hardware to address 4GB linear memory then it simply isn't possible to get a 4GB linear address space.

    The only thing you can do when your processor has too little address space is to use memory overlays. But you must manually switch in the different memory banks, and it will not be fast unless your application has a high degree of locality-of-reference.

  • Thanks, so at the end my solution is:

    typedef union U32
    {
            unsigned long dword;
            unsigned short word[2];
            unsigned char byte[4];
    } bdata U32;
    ...
    unsigned long Inc32bitDPTR (unsigned long addr)
    {
            U32 idata tmp_dptr;
    
            tmp_dptr.dword = addr;
            tmp_dptr.dword++;
            switch (DPS)
            {
                    case 0x00:
                            DPL0 = tmp_dptr.byte[3];
                            DPH0 = tmp_dptr.byte[2];
                            break;
                    case 0x01:
                            DPL1 = tmp_dptr.byte[3];
                            DPH1 = tmp_dptr.byte[2];
            }
    
            if (tmp_dptr.dword >= MAX_ADDR)
                    tmp_dptr.dword = 0;
    
            return tmp_dptr.dword;
    }
    ...
    tmp_dptr_dst.dword = addr;//long addr;
    WriteByte (tmp_dptr_dst.dword, byte);
    tmp_dptr_dst.dword = Inc32bitDPTR(tmp_dptr_dst.dword);
    ...
    


    May be anybody realized it better and faster?

  • I would avoid the use of "word" to mean "16 bits"

    See: www.8052.com/.../read.phtml

    Strictly, on an 8051, the word-size is 8 bits.

  • I would avoid the use of "word" to mean "16 bits"

    Micro$oft wouldn't :)

    They currently uses it to mean half (and possibly also a quarter of) the size of an integer register...)

  • That's because they used it specifically in the context of their original 16-bit platform.

    They are now stuck with it for 32- and 64-bit platforms.

    Serves 'em right!

    Learn form their mistake!