/***************************************************************************//**
 *   @file   MemFlash.h
 *   @brief  Initialisation et séquencement des tâches de l'application
 *   @author Kévin MARCHAND(Kevin.marchand@intelligence-electronique.com)
********************************************************************************
 * Copyright 2014(c) PLCD, Inc.
 *
 * Initialisation et séquencement des tâches de l'application
 *
********************************************************************************
 *   SVN Revision: 1
*******************************************************************************/

#ifndef __FLASH_H__
#define __FLASH_H__ 

/******************************************************************************/
/************************* Define Declarations ********************************/
/******************************************************************************/
// La taille de la flash par defaut est 32M
#define FLASH_SIZE_64M

#define PAGE_SIZE                       264
#define PAGE_SIZE_MULT                  33

#define Main_Page_Read			0xE8                                    // Lecture continue flash 64Mb 68h ; Lecture de la page courante 
#define Main_Page_To_Buffer		0x53                                    // Transfert la page courante au Buffer 1
#define Main_Page_Write			0x82                                    // Ecriture de la page courante

/******************************************************************************/
/*********************** Declarations adresses   ******************************/
/******************************************************************************/
#define Fichier_CONFIG 			1
#define Fichier_LOG			100

/*----------------- BASE MESSAGES  ---------------------------------------------*/
#define Base_Header			0
#define Base_Messages                   100

#define Msg_OK 				Base_Messages + 0
#define Msg_Erreur 			Base_Messages + 1
#define Msg_Commande_Inconnue	 	Base_Messages + 2
#define Msg_Commande_Non_Autorisee	Base_Messages + 3
#define Msg_Ecriture_OK 		Base_Messages + 4
#define Msg_Defaut			Base_Messages + 5
#define Msg_Reset_CPU			Base_Messages + 6

/******************************************************************************/
/*********************** Prototypes Declarations ******************************/
/******************************************************************************/
//! Fonction bas niveau utiliser par les fonctions haut niveau (ne pas utiliser directement ces fonctions)
void Flash_N_Clock(unsigned char Nombre);
void Active_Flash(void);
void Desactive_Flash(void);
int Flash_Ready(void);
void Wait_Flash_Ready(void);
void Write_Flash(unsigned char Byte_To_Write);
void Charge_Pointeurs(unsigned char Add_H,unsigned char Add_L,unsigned char Add_B);
void Lecture_Byte_In_Flash(unsigned char Add_H,unsigned char Add_L,unsigned char Add_B);
void Direct_Byte_Write_In_Page(unsigned char Add_H,unsigned char Add_L,unsigned char Add_B);
void Transfert_Page_To_Buffer(unsigned char Add_H,unsigned char Add_L,unsigned char Add_B);
unsigned char Read_Flash(void);
void Incremente_Adresse_FlashDB64(unsigned char *Add_H, unsigned char *Add_L, unsigned char *Add_B);
char MakeAddrDB64(unsigned char File_Number, unsigned int position, unsigned char *Add_H, unsigned char *Add_L,unsigned  char *Add_B);
void Incremente_Adresse_FlashDB32(unsigned char *Add_H, unsigned char *Add_L, unsigned char *Add_B);
char MakeAddrDB32(unsigned char File_Number, unsigned int position, unsigned char *Add_H, unsigned char *Add_L,unsigned  char *Add_B);

//! Fonction haut niveau utiliser par l'application
unsigned char Lecture_Memoire_Flash_Ligne_Str(unsigned char File_Number, unsigned int Numero_Ligne, unsigned char *Buff);
void Ecriture_Memoire_Flash_Ligne_Str(unsigned char File_Number, unsigned int Numero_Ligne, unsigned char *Buff);


#endif



