12.5.3 Define How to Access Memory Spaces

References to variables placed in external memories are controlled via the use of several helper functions. Up to five functions may be defined for reading and five for writing. One of these functions is a generic routine and will be called if any of the other four are not defined but are required. If none of the functions are defined, the compiler will generate an error message. A brief example will be presented in the next subsection. Generally, defining the individual functions will result in more efficient code generation.

Functions for Reading

read_external

void __read_external(unsigned int address,
 
  unsigned int memory_space,
 
  void *buffer,
  
  unsigned int len)

This function is a generic Read function and will be called if one of the next functions are required but not defined. This function should perform the steps necessary to fill len bytes of memory in the buffer from the external memory named memory_space starting at address address.

read_external8

unsigned char __read_external8(unsigned int address,


unsigned int memory_space)

Read 8 bits from external memory space memory_space starting from address address. The compiler would like to call this function if trying to access an 8-bit sized object.

read_external16

unsigned int __read_external16(unsigned int address,


 unsigned int memory_space)

Read 16 bits from external memory space memory_space starting from address address. The compiler would like to call this function if trying to access an 16-bit sized object.

read_external32

unsigned long __read_external32(unsigned int address,


 unsigned int memory_space)

Read 32 bits from external memory space memory_space starting from address address. The compiler would like to call this function if trying to access a 32-bit sized object, such as a long or float type.

read_external64

unsigned long long __read_external64(unsigned int address,


 unsigned int memory_space)

Read 64 bits from external memory space memory_space starting from address address. The compiler would like to call this function if trying to access a 64-bit sized object, such as a long long or long double type.

Functions for Writing

write_external

void __write_external(unsigned int address,

 unsigned int memory_space,

 void *buffer,

 unsigned int len)

This function is a generic Write function and will be called if one of the next functions are required but not defined. This function should perform the steps necessary to write len bytes of memory from the buffer to the external memory named memory_space starting at address address.

write_external8

void __write_external8(unsigned int address,

 unsigned int memory_space,

 unsigned char data)

Write 8 bits of data to external memory space memory_space starting from address address. The compiler would like to call this function if trying to write an 8-bit sized object.

write_external16

void __write_external16(unsigned int address,

 unsigned int memory_space,

 unsigned int data)

Write 16 bits of data to external memory space memory_space starting from address address. The compiler would like to call this function if trying to write an 16-bit sized object.

write_external32

void __write_external32(unsigned int address,

 unsigned int memory_space,

 unsigned long data)

Write 32 bits of data to external memory space memory_space starting from address address. The compiler would like to call this function if trying to write a 32-bit sized object, such as a long or float type.

write_external64

void __write_external64(unsigned int address,

 unsigned int memory_space,

 unsigned long long data)

Write 64 bits of data to external memory space memory_space starting from address address. The compiler would like to call this function if trying to write a 64-bit sized object, such as a long long or long double type.