/**********************************************************************/
/*                                                                    */
/* File name: driver.h                                                */
/*                                                                    */
/* Since:     2002/12/03                                              */
/*                                                                    */
/* Version:   1.02                                                    */
/*                                                                    */
/* Author:    MONTAGNE Xavier [XM] {link xavier.montagne@wanadoo.fr}  */
/*                                                                    */
/* Purpose: Offer low level functions for basic PIC programming       */
/*          procedures. Have a look at the Microchip specifications   */
/*          for further details.                                      */
/*                                                                    */
/* 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/03  [XM] Create this file                             */
/*                                                                    */
/**********************************************************************/

#ifndef __DRIVER_H__
#define __DRIVER_H__

/***********************************************************************
 * INCLUDES
 **********************************************************************/


/***********************************************************************
 * DEFINES
 **********************************************************************/
/* Specific to the hardware */
#define RB6_MASK                            0x02
#define RB7_MASK                            0x01
#define BUSY_MASK                           0x80
#define MCLR_MASK                           0x04
#define VCC_ON_MASK                         0x08
#define INVERTED                            0x10
#define NON_INVERTED                        0x20

/* To locate the TBLPTR register */
#define MOVLW                               0x0E00
#define MOVWF                               0x6E00
#define TBLPTRL_ad                          0xF6
#define TBLPTRH_ad                          0xF7
#define TBLPTRU_ad                          0xF8

/* As specified in ICSP for PIC18 family specification */
#define NB_BIT_PER_INST		                 4
#define NB_BIT_PER_DATA		                16
#define NB_BIT_PER_HALF_DATA   	             8

/* Parallel port adress definition */
#define PPORT_IN_ADR                        0x379
#define PPORT_OUT_ADR                       0x378


/***********************************************************************
 * TYPE & ENUM DEFINITIONS
 **********************************************************************/
typedef enum _action {
  NO_CHANGE,
  POST_INC,
  POST_DEC,
  PRE_INC 
} ACTION;

typedef enum _pin_label {
  PL_DATA_FROM_PIC,
  PL_DATA_TO_PIC,
  PL_CLOCK,
  PL_VPP,
  PL_VCC
} PIN_LABEL;

typedef struct _signal {
  PIN_LABEL name;
  unsigned char mask;
  unsigned char status;
} *pr_Signal, pr_ValSignal;


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

void _InitHardware(void);
void _PowerOn(void);
void _PowerOff(void);
void BulkErase(void);

void ReadBlock(unsigned int adr, unsigned short *block, unsigned int size);
void ProgramBlock(unsigned int adr, unsigned short *block, unsigned int size, \
                  unsigned int *try_done, unsigned int *word_programmed);
void ProgramBlockCfg(unsigned int adr, unsigned short *block, unsigned int size, \
                     unsigned int *try_done, unsigned int *word_programmed);
void ConfigBit(PIN_LABEL name, unsigned char mask, unsigned char status);
void SetBit(PIN_LABEL name);
void ClearBit(PIN_LABEL name);
unsigned char ReadBit(PIN_LABEL name);

unsigned char GetMask(PIN_LABEL name);
unsigned char GetStatus(PIN_LABEL name);

#if defined(__cplusplus)
}
#endif

#endif /* __DRIVER_H__ */
