/*
Copyright 2003/2004, Freie Universitaet Berlin. All rights reserved.

These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
 
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors be liable
for any direct, indirect, incidental, special, exemplary, or
consequential damages (including, but not limited to, procurement of
substitute goods or services; loss of use, data, or profits; or
business interruption) however caused and on any theory of liability,
whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software, even
if advised of the possibility of such damage.

This implementation was developed by the CST group at the FUB.
Contributors: Bjoern Lichtblau

For documentation and questions please use the web site
http://www.scatterweb.net and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2003/2004
*/

#ifndef _PROGRAMMINGH_
#define _PROGRAMMINGH_

#define PROGRAMMING_MAGICNUMBER     (0x4711)  ///< Tag for reprogrammable images at the very beginning (0x1100).

#define IMAGE_AREALOCKED        (0x80) ///< Flag for EEPROM[EADR_IMAGESTATE]. Area above 0x1000 should not be changed.
#define IMAGE_REPROGRAMMABLE    (0x40) ///< Flag for EEPROM[EADR_IMAGESTATE]. Area from EEPROM[EADR_IMAGESTART]..EEPROM[EADR_IMAGEEND] (between 0x1100 and 0xFFFF) contains a reprogrammable Image.
#define IMAGE_JTAGPROGRAMMABLE  (0x20) ///< Flag for EEPROM[EADR_IMAGESTATE]. Area from EEPROM[EADR_JTAGFLASHMIN]..EEPROM[EADR_JTAGLFASHMAX] (between 0x1100 and 0xFFFF) contains a JTAG programmable Image (Stick only).
#define IMAGE_PICTURE           (0x10) ///< Flag for EEPROM[EADR_IMAGESTATE]. 
#define IMAGE_VM                (0x08) ///< Flag for EEPROM[EADR_IMAGESTATE]. 

#define EADR_FLASHERBUF   (0x0E00) ///< EEPROM base address for storing chunks or targets by flasher.c Don't change anything from 0xE00-0xEFF unless flasher_state==IDLE if that is needed.
#define EADR_IMAGESTATE   (0x0FF0) ///< State variable that holds the IMAGE_x flags. The flags are inverted, so 0xFF means no flag set (initial EEPROM status).

#define EADR_PICTURELENGTH (0x0FF0)

#define EADR_JTAGFLASHMIN (0x0FF8) ///< Start address JTAG programmable region in Flash (Stick only.)
#define EADR_JTAGFLASHMAX (0x0FFA) ///< End address JTAG programmable region in Flash (Stick only.)
#define EADR_IMAGESTART   (0x0FFC) ///< Start address of reprogrammable image.
#define EADR_IMAGEEND     (0x0FFE) ///< End address of reprogrammable image.

/// Used by the linker script to put the imageData struct at the very beginning of the reprogrammable image.
#define IMAGE_DATA         __attribute__((section(".imagedata")))

#define ERROR_NOIMAGE         (0x0001)
#define ERROR_SIZEMISMATCH    (0x0002)
#define ERROR_WRONGDEVICE     (0x0003)
#define ERROR_WRONGADDRESS    (0x0004)


typedef struct {
  unsigned  int imageStart;    ///< Start address of reprogrammable image. 
  unsigned  int imageEnd;      ///< End address of reprogrammable image.
  unsigned  int deviceType;    ///< Device type. (1=ESB430, 2=USB430Stick, 3=WEB430Stick, 4=ECR430)
  unsigned  int reprogramAdr;  ///< Address of programming entry function prog_reprogram.
  UINT8 versionName[21];       ///< Must be 20 chars max (with \0 21 alltogether).
  UINT8 softwareDate[23];      ///< Filled with current date and time string by preprocessor. 
} imageData_t;

extern const imageData_t imageData; ///< Should be defined in userapp.c. userapp.c gets compiled every run so the date is always current date.

//UINT16 prog_reprogram();

#endif


