/*****************************************************************************
 * Copyright (c) 2010 Rowley Associates Limited.                             *
 *                                                                           *
 * This file may be distributed under the terms of the License Agreement     *
 * provided with this software.                                              *
 *                                                                           *
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING THE   *
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
 *****************************************************************************/

#include <targets/liblpc2000.h>
#include <libmem.h>
#include <libmem_loader.h>

unsigned long processor_clock_frequency = 57600000;

extern void __SRAM_segment_start__;
extern void __SRAM_segment_used_end__;

int
main(void)
{
  const int flash2_max_geometry_regions = 4;
  unsigned char *flash2_start = (unsigned char *)0x80000000;
  libmem_driver_handle_t flash1_handle, flash2_handle;
  libmem_geometry_t flash2_geometry[flash2_max_geometry_regions];
  libmem_flash_info_t flash2_info;
  size_t size;

  /* Register FLASH drivers */
  liblpc2000_register_libmem_driver(&flash1_handle);
  libmem_cfi_get_info(flash2_start, &size, flash2_geometry, flash2_max_geometry_regions, &flash2_info);
  libmem_register_sst39xFx00A_16_driver(&flash2_handle, flash2_start, size, flash2_geometry, &flash2_info);

  /* Run the loader - use the unused RAM minus the 32 bytes used by ISP as the RPC communication buffer */
  libmem_rpc_loader_start(&__SRAM_segment_used_end__, &__SRAM_segment_start__ + liblpc2000_get_ram_size() - 33);

  return 0;
}
