ARM Technical Support Knowledge Articles

ABSOLUTE MEMORY ACCESSES TO DALLAS 390'S FAR MEMORY

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

How can I generate absolute memory accesses to the far memory type in Dallas 390 Contiguous Mode? The following program should access the memory byte at 0x12000, but it does not work.

unsigned char far *p;

void test (void)  {
  p = 0x12000;
  *p = 0x5A;        // does NOT write 0x5A to 0x12000
}

ANSWER

Absolute memory accesses to the far memory type on the Dallas 390 in contiguous mode can be performed by far pointers, by macros, or with the _at_ keyword. There are certain restrictions with each method.

Far memory is addressed using 3-byte generic pointers. Far and const far memory types are limited to 64KB to 8MB (0x010000 to 0x7F0000) address space. This memory space restriction allows more compact code and avoids using 4-bytes to address memory locations.

Regular Generic pointers use an uppermost (4th) byte called the Memory Type Byte. For the Dallas 400 the memory type byte values are:

Pointer arithmetic for far objects is performed using 16-bit math operations by default. The upper byte of the complete 24-bit address is unchanged even if the operation's result is larger than 0xFFFF. Use long types or cast constants to long types in pointer manipulations to create 24-bit math code.

Absolute memory locations in extended (far) memory spaces can be accessed with the macros (FVAR, FCVAR, FARRAY, FCARRAY) defined in ABSACC.H. These macros are explained in detail in the Cx51 Compiler User's Guide, Chapter 8, Absolute Memory Access Macros. Using these macros give the correct results. For example:

#include <absacc.h>

unsigned char far *p;

void test (void)  {
  p = &FVAR(unsigned char, 0x12000);
  *p = 0x5A;        // writes 0x5A to 0x12000
}

In C51 Version 7.07 or higher it is even possible to use the _at_ keyword for locating absolute memory. For example:

unsigned char far IO_PORT        _at_ 0xC00000;
unsigned char far my_array[0x10] _at_ 0x400000;

unsigned char c;

void test (void)  {
  c = IO_PORT;
  my_array[5] = 0x55;
  my_array[c] = 1;
}

Far memory access above the memory range 0x7F0000 is more restricted. Only scalar variables (which have a fixed memory address) can be used to access memory above 0x7F0000 and are defined with the _at_ in the complete 16MB address space.

Pointer access is restricted to the Far and const far address space (0x010000 to 0x7F0000). Arrays must be located below 0x7F0000 when using the _at_ keyword. The Compiler uses pointer arithmetic for indirect access for memory above 0x7F0000.

As long as you access arrays directly in your C source (without using pointer constructs), you may bypass the 0x7F0000 limitation using the an Assembler Source file that defines the absolute memory location as shown in the following example:

Assembler Source File:

PUBLIC CAN_REG

CAN_REG XDATA 0xFFDB00    ; absolute location of the CAN register
END

C Source File:

extern unsigned char xdata CAN_REG[256];

void main (void)  {
  unsigned char i;

  for (i = 0; i < 100; i++)  {
    CAN_REG[i] = 0;
  }
}

Note: This trick works only when there are no pointer accesses to the array.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-25 08:30:28

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential