/**********************************************************************/
/*                                                                    */
/* File name: DLL_interface.h                                         */
/*                                                                    */
/* Since:     2002/12/01                                              */
/*                                                                    */
/* Version:   2.02                                                    */
/*                                                                    */
/* Author:    MONTAGNE Xavier [XM] {link xavier.montagne@wanadoo.fr}  */
/*                                                                    */
/* Purpose: Definition of the interface between the Main Window and   */
/*          the DLL dedicated to one PIC18.                           */
/*                                                                    */
/* Distribution: This file is part of PP18.                           */
/*               PP18 is free software; you can redistribute it       */
/*               and/or modify it under the terms of the GNU General  */
/*               Public License as published by the Free Software     */
/*               Foundation; either version 2, or (at your option)    */
/*               any later version.                                   */
/*                                                                    */
/*               PP18 is distributed in the hope that it will be      */
/*               useful, but WITHOUT ANY WARRANTY; without even the   */
/*               implied warranty of MERCHANTABILITY or FITNESS FOR A */
/*               PARTICULAR PURPOSE.  See the GNU General Public      */
/*               License for more details.                            */
/*                                                                    */
/*               You should have received a copy of the GNU General   */
/*               Public License along with PP18; see the file         */
/*               COPYING.txt. If not, write to the Free Software      */
/*               Foundation, 59 Temple Place - Suite 330,             */
/*               Boston, MA 02111-1307, USA.                          */
/*                                                                    */
/* History:                                                           */
/*      2002/12/01  [XM] Create this file                             */
/*                                                                    */
/**********************************************************************/

#if !defined(__DLL_INTERFACE_H__)
#define __DLL_INTERFACE_H__

/***********************************************************************
 * INCLUDES
 **********************************************************************/
#include <windows.h>

/***********************************************************************
 * DEFINES
 **********************************************************************/
#define FromPIC                1
#define FromFile               0

/*** Status fields return by the interface functions ******************/
typedef enum _Status_t {
	ALL_RIGHT = 0,
    FILE_ERROR,      /* File can not be open or not intel hex format */
    NOT_BLANK,       /* The chip is not blank - all data = 0xFFFF */
	BLANK,           /* The chip is blank - all data = 0xFFFF */
	PROGRAMMED,      /* The chip is properly programmed */
	BAD_PROGRAMMED,  /* The program process didn't succeed */
	LOCKED,          /* The chip is code protected */
    PIC_DETECTED,
	HARDWARE_ERROR,  /* The hardware doesn't work properly */
	INTERNAL_ERROR   /* Internal error return by a function */
} Status_t;

/***********************************************************************
 * FUNCTION DEFINITIONS
 **********************************************************************/
#if defined(__cplusplus)
extern "C"
{
#endif

/***********************************************************************
 * Only fill the SHexFile structure. Do not proceed to any programming 
 * sequences. This function fills the Hex_from_file structure, so it has
 * to be called first to initialyze. 
 *
 * @param  char *ucFilename   IN  HEX filename to parse
 * @return Status_t               FILE_ERROR if something wrong appends
 *                                (Hex larger than PIC memory size)
 *                                ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*ParseFile)(char *ucFilename);

/***********************************************************************
 * Give the memory size of the chip (and not the memory size of usefull
 * data inside the PIC), or the data size of the HEX file parsed.
 *
 * @param  u_int *uiSize      OUT PIC memory size
 * @param  u_int uiFrom       IN  Flag (PIC or File)
 * @return Status_t               Always ALL_RIGHT
 **********************************************************************/
Status_t (*GetMemorySize)(unsigned int *uiSize, unsigned int uiFrom);

/***********************************************************************
 * Copy the memory content from the PIC or FILE structure to the buffer
 * parameter.
 *
 * @param  u_short *usMemory  OUT Memory buffer
 * @param  u_int uiFrom       IN  Flag (PIC or File)
 * @return Status_t               Always ALL_RIGHT
 **********************************************************************/
Status_t (*GetMemoryBuffer)(unsigned short *usMemory, unsigned int uiFrom);

/***********************************************************************
 * Copy the memory content from the buffer to the PIC or FILE structure.
 *
 * @param  u_short *usMemory  IN  Memory buffer
 * @param  u_int uiFrom       IN  Flag (PIC or File)
 * @return Status_t               Always ALL_RIGHT
 **********************************************************************/
Status_t (*SetMemoryBuffer)(unsigned short *usMemory, unsigned int uiFrom);

/***********************************************************************
 * Rebuil a HEX File from memory, config and ID. Do not proceed to any
 * programming sequences. This function creats a new HEX file a replace
 * an existing one.
 *
 * @param  char *ucFilename   IN  HEX filename to build
 * @param  u_int uiFrom       IN  Flag (PIC or File)
 * @return Status_t               FILE_ERROR if something wrong appends
 *                                (cannot creat a new file)
 *                                ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*UnParseFile)(char *ucFilename, unsigned int uiFrom);

/***********************************************************************
 * Perform a programmation process to the hardware programmer and the
 * chip on it concerning memory area only.
 *
 * @param  u_int uiFrom      IN  Flag (PIC or File)
 * @return Status_t              BAD_PROGRAMMED if something wrong appends
 *                               PROGRAMMED if not
 *                               ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*ProgramMem)(unsigned int uiFrom);

/***********************************************************************
 * Perform a programmation process to the hardware programmer and the
 * chip on it concerning config area only.
 *
 * @param  u_int uiFrom      IN  Flag (PIC or File)
 * @return Status_t              BAD_PROGRAMMED if something wrong appends
 *                               PROGRAMMED if not
 *                               ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*ProgramConfig)(unsigned int uiFrom);

/***********************************************************************
 * Perform a programmation process to the hardware programmer and the
 * chip on it concerning ID area only.
 *
 * @param  u_int uiFrom      IN  Flag (PIC or File)
 * @return Status_t              BAD_PROGRAMMED if something wrong appends
 *                               PROGRAMMED if not
 *                               ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*ProgramID)(unsigned int uiFrom);

/***********************************************************************
 * Download the code memory field from the PIC device, and update the
 * PIC structure.
 *
 * @param  void
 * @return Status_t                BLANK if all memory set to 0xFFFF
 *                                 NOT_BLANK if not
 *                                 ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*ReadMem)(void);

/***********************************************************************
 * Download the config field from the PIC device, and update the PIC
 * structure.
 *
 * @param  void
 * @return Status_t                LOCKED if Code Prection ON
 *                                 ALL_RIGHT otherwise
 **********************************************************************/
Status_t (*ReadConfig)(void);

/***********************************************************************
 * Download the ID field from the PIC device, and update the PIC
 * structure.
 *
 * @param  void
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*ReadID)(void);

/***********************************************************************
 * Download REV+DEV from the chip present in the device chip.
 * This function fills the Hex_from_file structure, so it has
 * to be called first to initialyze the PIC structure.
 *
 * @param  char *PICname      IN  PIC name reference (name of DLL)
 * @return Status_t               PIC_DETECTED if right PIC detected
 *                                HARDWARE_ERROR if not detected
 **********************************************************************/
Status_t (*ReadRevDev)(char *PICname);

/***********************************************************************
 * Get the ID field of the structure specify by uiFrom with the ucValue.
 * The field is 8 bytes long, so just the byte specified by ucIndex is
 * modified.
 *
 * @param  u_char *ucValue     IN  Value of the ID to get at ucIndex pos
 * @param  u_char ucIndex      IN  Index of the ID to get
 * @param  u_int uiFrom        IN  Flag (PIC or File)
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*GetIDValue)(unsigned char *ucValue, unsigned char ucIndex, \
                    unsigned int uiFrom);

/***********************************************************************
 * Fill the ID field of the structure specify by uiFrom with the ucValue.
 * The field is 8 bytes long, so just the byte specified by ucIndex is
 * modified.
 *
 * @param  u_char ucValue      IN  Value of the ID to set at ucIndex pos
 * @param  u_char ucIndex      IN  Index of the ID to set
 * @param  u_int uiFrom        IN  Flag (PIC or File)
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*SetIDValue)(unsigned char ucValue, unsigned char ucIndex, \
                    unsigned int uiFrom);

/***********************************************************************
 * Extract the checksum info from every line of an INTEL HEX file.
 * Compare it with the value computed by the HEX parser.
 *
 * @param  u_short *usChecksum IN  Reference to the checksum computed
 * @param  u_int uiFrom        IN  Flag (PIC or File)
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*ComputeGeneralChecksum)(unsigned short *usChecksum, unsigned int uiFrom);

/***********************************************************************
 * Check the presence of a programmer on LPT port.
 * Hardware present if DATA_FROM_PIC == DATA_TO_PIC[0 or 1]
 *
 * @param  void
 * @return Status_t                ALL_RIGHT if hardware present
 *                                 HARDWARE_ERROR if not present
 **********************************************************************/
Status_t (*IsHWPresent)(void);

/***********************************************************************
 * Stuck at 0 all of the signals (logical 0, not necessarily physical 0).
 *
 * @param  void
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*InitHardware)(void);

/***********************************************************************
 * Stuck at 1 the VCC signal (logical 1, not necessarily physical 1).
 *
 * @param  void
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*PowerOn)(void);

/***********************************************************************
 * Stuck at 0 the VCC signal (logical 0, not necessarily physical 0).
 *
 * @param  void
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*PowerOff)(void);

/***********************************************************************
 * Display the "About" window of the DLL.
 * Catch the HWND handle of the application.
 *
 * @param  HWND hWnd           IN  Handle of the main window
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*ShowDLL)(HWND hWnd);

/***********************************************************************
 * Display the "Settings" window of the DLL.
 *
 * @param  HWND hWnd           IN  Handle of the main window
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*ShowSettings)(HWND hWnd);

/***********************************************************************
 * Display the "Config" window of the DLL.
 *
 * @param  HWND hWnd           IN  Handle of the main window
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*ShowConfig)(HWND hWnd, unsigned int uiFrom);

   /***********************************************************************
 * Erase all the programmable bits of the PIC18.
 *
 * @param  HWND hWnd           IN  Handle of the main window
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*BulkErase)(HWND hWnd);

/***********************************************************************
 * Set /MCLR to VDD to start the target.
 *
 * @param  HWND hWnd           IN  Handle of the main window
 * @return Status_t                Always ALL_RIGHT
 **********************************************************************/
Status_t (*RunTarget)(void);

#if defined(__cplusplus)
}
#endif


#endif /* __DLL_INTERFACE_H__ */

/* End of File */




