/**
*   @file       mnsh_spi.h
*   @author     IPC - Industrial BU
*   @date       15 september 2013
*   @brief      Defines the public interface for the SPI minishell
*               routines
*   @note       (C) COPYRIGHT 2013 STMicroelectronics
*
* @attention
*
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
*/
#include "stdint.h"
#ifndef HANDLER_SFLASH_H
#define HANDLER_SFLASH_H

/*******************************************************************************
* INCLUDE FILES:
*******************************************************************************/

/** @addtogroup GENERIC
  * @{
  */


/*******************************************************************************
* MACROS & CONSTANTS:
*******************************************************************************/
#define SPI_MEM_SIZE                        (80)

#define SPI_FLASH_PAGE_SIZE                 ((uint16_t)256)         /*!< Flash Page size */
#define SPI_FLASH_PAGES_IN_SECTOR_CNT       ((uint16_t)256)
#define SPI_FLASH_SECTORS_CNT               ((uint16_t)32)

#define SPI_FLASH_PAGE_MASK                 (SPI_FLASH_PAGE_SIZE - 1)
#define SPI_FLASH_TOT_MASK                  (SPI_FLASH_SIZE - 1)

#define SPI_FLASH_SECTOR_SIZE               ((uint32_t)SPI_FLASH_PAGE_SIZE * SPI_FLASH_PAGES_IN_SECTOR_CNT)

#define SPI_FLASH_SECTORS_IN_IMAGE_BLK_CNT  ((uint16_t)(SPI_FLASH_IMAGE_BLK_SIZE / SPI_FLASH_SECTOR_SIZE))

#define SPI_FLASH_SIZE                      (SPI_FLASH_SECTOR_SIZE * SPI_FLASH_SECTORS_CNT)

/*******************************************************************************
* GLOBAL VARIABLES:
*******************************************************************************/

/*******************************************************************************
* TYPES:
*******************************************************************************/

/*******************************************************************************
* FUNCTIONS:
*******************************************************************************/
void      SFLASH_Conf(void);
void      SFLASH_Read(uint8_t *buf, uint32_t address, uint16_t size);
void      SFLASH_Write(uint32_t address, uint8_t *buf, uint16_t size);
void      SFLASH_Erase(uint32_t address);
void      SFLASH_EraseAll(void);
uint8_t   SFLASH_GetStatusReg(void);
uint32_t  SFLASH_GetDeviceId(void);

uint8_t    SFLASH_ReadBuffer(uint8_t *buffer, uint32_t start_addr, uint16_t bytes_to_read);
uint8_t    SFLASH_WriteBuffer(uint8_t *buffer, uint32_t start_addr, uint16_t bytes_to_write);
uint8_t    SFLASH_SectorErase(uint16_t sector_id);
uint8_t    SFLASH_BulkErase(void);
void    SFLASH_SendBytes(uint8_t *buffer, uint16_t bytes_to_read);

#endif /* HANDLER_SFLASH_H */

/**
  * @}
  */

/* End Of File */
