Synopsis
int libmem_rpc_loader_start(void *comm_buffer_start,
                            void *comm_buffer_end);
Description

comm_buffer_start — A pointer to the start of an area of RAM that can be used by the host to store data passed to the remotely called libmem functions.

comm_buffer_end — A pointer to the last byte of the of an area of RAM that can be used by the host to store data passed to the remotely called libmem functions.

libmem_rpc_loader_start returns — The last error result returned from a LIBMEM function or LIBMEM_STATUS_SUCCESS if there has been no error.

This function starts up a LIBMEM loader that uses direct remote procedure calls of the LIBMEM library.

A communication buffer is required to store the parameters passed to the LIBMEM functions, this buffer is specified using the comm_buffer_start and comm_buffer_end parameters. The buffer must be at least 8 bytes in length, however you will find the bigger the buffer is, the better the loader performance will be because fewer RPC calls will be required.

Example:

static unsigned char buffer[256];

int main(void)
{
  uint8_t *flash1_start = (uint8_t *)0x10000000;
  const int flash1_max_geometry_regions = 4;
  libmem_driver_handle_t flash1_handle;
  libmem_geometry_t flash1_geometry[flash1_max_geometry_regions];
  libmem_flash_info_t flash1_info;
  int res;

  // Register FLASH driver.
  res = libmem_register_cfi_driver(&flash1_handle, 
                                   flash1_start,
                                   flash1_geometry,
                                   flash1_max_geometry_regions, 
                                   &flash1_info);

  if (res == LIBMEM_STATUS_SUCCESS)
    {
      // Run the loader 
      libmem_rpc_loader_start(buffer, buffer + sizeof(buffer) - 1);
    }

  libmem_rpc_loader_exit(res, NULL);

  return 0;
}

Parameters are passed to an RPC loader by initialising the CPU registers prior to starting the loader. On entry, the register R0 contains the LIBMEM loader flags which can be any of the following:

Note that older versions of LIBMEM loader required that you always link certain LIBMEM functions such as libmem_write() and libmem_erase() into the loader using the "Linker | Keep Symbols" project property. This is now only required if you want the loader to be compatible with versions of CrossWorks prior to version 3.