//------------------------------------------------------------------------------
// File:          partitioning.h
// Function:      Memory partitioning
// Supported chip(s):
//    - AT91SAM7XC128
//    - AT91SAM7XC256
// Supported toolchain(s):
//    - IAR Embedded Workbench
// Date created:  05 July 2006
// Created by:    JJo
//------------------------------------------------------------------------------

#ifndef BOOTLOADER_PARTITIONING_H
#define BOOTLOADER_PARTITIONING_H

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------

#include "common.h"
#include "board.h"
#include "memory.h"

#ifdef USE_MEMORY_PARTITIONING

//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------

#define REGION_A_START      ((void *) ((unsigned int) APP_START_ADDRESS))
#define REGION_B_START      ((void *) ((unsigned int) REGION_A_START + REGION_SIZE))
#define REGION_INFO_START   ((void *) ((unsigned int) REGION_B_START + REGION_SIZE))

//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------

typedef struct {

  // Signatures
  unsigned int signatureA;
  unsigned int signatureB;

  // Length fields
  unsigned int lengthA;
  unsigned int lengthB;

  // Padding
  unsigned int padding[MEMORY_PAGE_SIZE-16];

} regionInfo_t, * pRegionInfo_t;

//------------------------------------------------------------------------------
// Prototypes
//------------------------------------------------------------------------------

unsigned int partitioning_sign(void * vAddress, unsigned int length);
unsigned int partitioning_check(unsigned int signatureA, unsigned int signatureB);
void partitioning_writeInfo(void * vAddress, pRegionInfo_t pRegionInfo);
void partitioning_readInfo(void * vAddress, pRegionInfo_t pRegionInfo);
unsigned int partitioning_isRegionValid(void * vAddress,
                                        unsigned int signature,
                                        unsigned int length);

#endif // USE_MEMORY_PARTITIONING
#endif // BOOTLOADER_PARTITIONING_H
