修改了Web后台的部分界面,增加了HAmqtt中的总电量传感器,后台新增mqtt上报频率设置

This commit is contained in:
OOP
2025-03-03 21:49:41 +08:00
parent e1e00b60ce
commit 9f9d4c7a56
4468 changed files with 1473046 additions and 10728 deletions

View File

@@ -0,0 +1,491 @@
/**
******************************************************************************
* @file spi_flash.c
* @author William Xu
* @version V1.0.0
* @date 16-Sep-2014
* @brief This file provides all the headers of flash operation functions.
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#include "platform_logging.h"
#include "platform.h"
#include "spi_flash.h"
#include "spi_flash_internal.h"
#include "spi_flash_platform_interface.h"
#include <string.h> /* for NULL */
#define sFLASH_SPI_PAGESIZE 0x100
int sflash_read_ID( const sflash_handle_t* const handle, void* const data_addr )
{
return generic_sflash_command( handle, SFLASH_READ_JEDEC_ID, 0, NULL, 3, NULL, data_addr );
}
int sflash_enter_dpmode( const sflash_handle_t* const handle )
{
return generic_sflash_command( handle, SFLASH_DEEP_POWER_DOWN, 0, NULL, 0, NULL, NULL );
}
int sflash_write_enable( const sflash_handle_t* const handle )
{
if ( handle->write_allowed == SFLASH_WRITE_ALLOWED )
{
/* Send write-enable command */
int status = generic_sflash_command( handle, SFLASH_WRITE_ENABLE, 0, NULL, 0, NULL, NULL );
if ( status != 0 )
{
return status;
}
/* Check status register */
unsigned char status_register;
if ( 0 != ( status = sflash_read_status_register( handle, &status_register ) ) )
{
return status;
}
/* Check if Block protect bits are set */
if ( status_register != SFLASH_STATUS_REGISTER_WRITE_ENABLED )
{
/* Disable protection for all blocks */
if (0 != ( status = sflash_write_status_register( handle, 0 ) ) )
{
return status;
}
/* Re-Enable writing */
if (0 != ( status = generic_sflash_command( handle, SFLASH_WRITE_ENABLE, 0, NULL, 0, NULL, NULL ) ) )
{
return status;
}
}
return 0;
}
else
{
return -1;
}
}
int sflash_chip_erase( const sflash_handle_t* const handle )
{
int status = sflash_write_enable( handle );
if ( status != 0 )
{
return status;
}
return generic_sflash_command( handle, SFLASH_CHIP_ERASE1, 0, NULL, 0, NULL, NULL );
}
int sflash_sector_erase ( const sflash_handle_t* const handle, unsigned long device_address )
{
char device_address_array[3] = { ( ( device_address & 0x00FF0000 ) >> 16 ),
( ( device_address & 0x0000FF00 ) >> 8 ),
( ( device_address & 0x000000FF ) >> 0 ) };
int retval;
int status = sflash_write_enable( handle );
if ( status != 0 )
{
return status;
}
retval = generic_sflash_command( handle, SFLASH_SECTOR_ERASE, 3, device_address_array, 0, NULL, NULL );
check_string(retval == 0, "SPI Flash erase error");
return retval;
}
int sflash_read_status_register( const sflash_handle_t* const handle, void* const dest_addr )
{
return generic_sflash_command( handle, SFLASH_READ_STATUS_REGISTER, 0, NULL, 1, NULL, dest_addr );
}
int sflash_read( const sflash_handle_t* const handle, unsigned long device_address, void* const data_addr, unsigned int size )
{
char device_address_array[3] = { ( ( device_address & 0x00FF0000 ) >> 16 ),
( ( device_address & 0x0000FF00 ) >> 8 ),
( ( device_address & 0x000000FF ) >> 0 ) };
return generic_sflash_command( handle, SFLASH_READ, 3, device_address_array, size, NULL, data_addr );
}
// int sflash_get_size( const sflash_handle_t* const handle, unsigned long* const size )
// {
// *size = 0; /* Unknown size to start with */
// #ifdef SFLASH_SUPPORT_MACRONIX_PARTS
// if ( handle->device_id == SFLASH_ID_MX25L8006E )
// {
// *size = 0x100000; /* 1MByte */
// }
// #endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
// #ifdef SFLASH_SUPPORT_WINBOND_PARTS
// if ( handle->device_id == SFLASH_ID_W25X80AVSIG )
// {
// *size = 0x100000; /* 1MByte */
// }
// #endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
// #ifdef SFLASH_SUPPORT_SST_PARTS
// if ( handle->device_id == SFLASH_ID_SST25VF080B )
// {
// *size = 0x100000; /* 1MByte */
// }
// #endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
// return 0;
// }
int sflash_get_size( const sflash_handle_t* const handle, /*@out@*/ unsigned long* const size )
{
*size = 0; /* Unknown size to start with */
#ifdef SFLASH_SUPPORT_MACRONIX_PARTS
if ( handle->device_id == SFLASH_ID_MX25L8006E )
{
*size = (unsigned long) 0x100000; /* 1MByte */
}
else if ( handle->device_id == SFLASH_ID_MX25L1606E )
{
*size = (unsigned long) 0x200000; /* 2MByte */
}
#endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
#ifdef SFLASH_SUPPORT_SST_PARTS
if ( handle->device_id == SFLASH_ID_SST25VF080B )
{
*size = (unsigned long) 0x100000; /* 1MByte */
}
#endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
#ifdef SFLASH_SUPPORT_EON_PARTS
if ( handle->device_id == SFLASH_ID_EN25QH16 )
{
*size = (unsigned long) 0x200000; /* 2MByte */
}
#endif /* ifdef SFLASH_SUPPORT_EON_PARTS */
#ifdef SFLASH_SUPPORT_WINBOND_PARTS
if ( handle->device_id == SFLASH_ID_W25X80AVSIG )
{
*size = (unsigned long) 0x100000; /* 1MByte */
}
#endif /* ifdef SFLASH_SUPPORT_WINBOND_PARTS */
return 0;
}
int sflash_write_page( const sflash_handle_t* const handle, unsigned long device_address, const void* const data_addr, int size )
{
int status;
int write_size;
int max_write_size = 256;
unsigned char enable_before_every_write = 1;
unsigned char* data_addr_ptr = (unsigned char*) data_addr;
unsigned char curr_device_address[3];
if ( handle->write_allowed == SFLASH_WRITE_ALLOWED )
{
}
else
{
return -1;
}
/* Some manufacturers support programming an entire page in one command. */
#ifdef SFLASH_SUPPORT_MACRONIX_PARTS
if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_MACRONIX )
{
max_write_size = 256; /* TODO: this should be 256, but that causes write errors */
enable_before_every_write = 1;
}
#endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
#ifdef SFLASH_SUPPORT_WINBOND_PARTS
if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_WINBOND )
{
max_write_size = 256; /* TODO: this should be 256, but that causes write errors */
enable_before_every_write = 1;
}
#endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */
#ifdef SFLASH_SUPPORT_SST_PARTS
if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_SST )
{
max_write_size = 1;
enable_before_every_write = 1;
}
#endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
#ifdef SFLASH_SUPPORT_EON_PARTS
if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_EON )
{
max_write_size = (unsigned int) 1;
enable_before_every_write = 1;
}
#endif /* ifdef SFLASH_SUPPORT_EON_PARTS */
if ( ( enable_before_every_write == 0 ) &&
( 0 != ( status = sflash_write_enable( handle ) ) ) )
{
return status;
}
/* Generic x-bytes-at-a-time write */
while ( size > 0 )
{
write_size = ( size > max_write_size )? max_write_size : size;
curr_device_address[0] = ( ( device_address & 0x00FF0000 ) >> 16 );
curr_device_address[1] = ( ( device_address & 0x0000FF00 ) >> 8 );
curr_device_address[2] = ( ( device_address & 0x000000FF ) >> 0 );
if ( ( enable_before_every_write == 1 ) &&
( 0 != ( status = sflash_write_enable( handle ) ) ) )
{
return status;
}
if ( 0 != ( status = generic_sflash_command( handle, SFLASH_WRITE, 3, curr_device_address, write_size, data_addr_ptr, NULL ) ) )
{
return status;
}
data_addr_ptr += write_size;
device_address += write_size;
size -= write_size;
}
return 0;
}
/**
* @brief Writes block of data to the FLASH. In this function, the number of
* WRITE cycles are reduced, using Page WRITE sequence.
* @param pBuffer: pointer to the buffer containing the data to be written
* to the FLASH.
* @param WriteAddr: FLASH's internal address to write to.
* @param NumByteToWrite: number of bytes to write to the FLASH.
* @retval None
*/
int sflash_write( const sflash_handle_t* const handle, unsigned long device_address, const void* const data_addr, unsigned int size )
{
int status;
uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
unsigned char* data_addr_ptr = (unsigned char*) data_addr;
Addr = device_address % sFLASH_SPI_PAGESIZE;
count = sFLASH_SPI_PAGESIZE - Addr;
NumOfPage = size / sFLASH_SPI_PAGESIZE;
NumOfSingle = size % sFLASH_SPI_PAGESIZE;
if (Addr == 0) /*!< WriteAddr is sFLASH_PAGESIZE aligned */
{
if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
{
status = sflash_write_page( handle, device_address, data_addr_ptr, size );
//sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite);
}
else /*!< NumByteToWrite > sFLASH_PAGESIZE */
{
while (NumOfPage--)
{
status = sflash_write_page( handle, device_address, data_addr_ptr, sFLASH_SPI_PAGESIZE );
//sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
device_address += sFLASH_SPI_PAGESIZE;
data_addr_ptr += sFLASH_SPI_PAGESIZE;
}
status = sflash_write_page( handle, device_address, data_addr_ptr, NumOfSingle);
}
}
else /*!< WriteAddr is not sFLASH_PAGESIZE aligned */
{
if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
{
if (NumOfSingle > count) /*!< (NumByteToWrite + WriteAddr) > sFLASH_PAGESIZE */
{
temp = NumOfSingle - count;
status = sflash_write_page( handle, device_address, data_addr_ptr, count );
//sFLASH_WritePage(pBuffer, WriteAddr, count);
device_address += count;
data_addr_ptr += count;
status = sflash_write_page( handle, device_address, data_addr_ptr, temp);
}
else
{
status = sflash_write_page(handle, device_address, data_addr_ptr, size);
}
}
else /*!< NumByteToWrite > sFLASH_PAGESIZE */
{
size -= count;
NumOfPage = size / sFLASH_SPI_PAGESIZE;
NumOfSingle = size % sFLASH_SPI_PAGESIZE;
status = sflash_write_page( handle, device_address, data_addr_ptr, count );
//sFLASH_WritePage(pBuffer, WriteAddr, count);
device_address += count;
data_addr_ptr += count;
while (NumOfPage--)
{
status = sflash_write_page( handle, device_address, data_addr_ptr, sFLASH_SPI_PAGESIZE );
//sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
device_address += sFLASH_SPI_PAGESIZE;
data_addr_ptr += sFLASH_SPI_PAGESIZE;
}
if (NumOfSingle != 0)
{
status = sflash_write_page( handle, device_address, data_addr_ptr, NumOfSingle );
//sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle);
}
}
}
return status;
}
int sflash_write_status_register( const sflash_handle_t* const handle, char value )
{
char status_register_val = value;
#ifdef SFLASH_SUPPORT_SST_PARTS
/* SST parts require enabling writing to the status register */
if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_SST )
{
int status;
if ( 0 != ( status = generic_sflash_command( handle, SFLASH_ENABLE_WRITE_STATUS_REGISTER, 0, NULL, 0, NULL, NULL ) ) )
{
return status;
}
}
#endif /* ifdef SFLASH_SUPPORT_SST_PARTS */
return generic_sflash_command( handle, SFLASH_WRITE_STATUS_REGISTER, 0, NULL, 1, &status_register_val, NULL );
}
int deinit_sflash( /*@out@*/ sflash_handle_t* const handle)
{
int status;
(void) handle;
status = sflash_platform_deinit( );
if ( status != 0 )
{
return status;
}
return 0;
}
int init_sflash( /*@out@*/ sflash_handle_t* const handle, /*@shared@*/ void* peripheral_id, sflash_write_allowed_t write_allowed_in )
{
int status;
device_id_t tmp_device_id;
status = sflash_platform_init( peripheral_id, &handle->platform_peripheral );
if ( status != 0 )
{
return status;
}
handle->write_allowed = write_allowed_in;
handle->device_id = 0;
status = sflash_read_ID( handle, &tmp_device_id );
if ( status != 0 )
{
return status;
}
handle->device_id = ( ((uint32_t) tmp_device_id.id[0]) << 16 ) +
( ((uint32_t) tmp_device_id.id[1]) << 8 ) +
( ((uint32_t) tmp_device_id.id[2]) << 0 );
if ( write_allowed_in == SFLASH_WRITE_ALLOWED )
{
/* Enable writing */
if (0 != ( status = sflash_write_enable( handle ) ) )
{
return status;
}
}
return 0;
}
static inline int is_write_command( sflash_command_t cmd )
{
return ( ( cmd == SFLASH_WRITE ) ||
( cmd == SFLASH_CHIP_ERASE1 ) ||
( cmd == SFLASH_CHIP_ERASE2 ) ||
( cmd == SFLASH_SECTOR_ERASE ) ||
( cmd == SFLASH_BLOCK_ERASE_MID ) ||
( cmd == SFLASH_BLOCK_ERASE_LARGE ) )? 1 : 0;
}
int generic_sflash_command( const sflash_handle_t* const handle,
sflash_command_t cmd,
unsigned long num_initial_parameter_bytes,
/*@null@*/ /*@observer@*/ const void* const parameter_bytes,
unsigned long num_data_bytes,
/*@null@*/ /*@observer@*/ const void* const data_MOSI,
/*@null@*/ /*@out@*/ /*@dependent@*/ void* const data_MISO )
{
int status;
sflash_platform_message_segment_t segments[3] =
{
{ &cmd, NULL, (unsigned long) 1 },
{ parameter_bytes, NULL, num_initial_parameter_bytes },
/*@-compdef@*/ /* Lint: Tell lint that it is OK that data_MISO is not completely defined */
{ data_MOSI, data_MISO, num_data_bytes }
/*@+compdef@*/
};
status = sflash_platform_send_recv( handle->platform_peripheral, segments, (unsigned int) 3 );
if ( status != 0 )
{
/*@-mustdefine@*/ /* Lint: do not need to define data_MISO due to failure */
return status;
/*@+mustdefine@*/
}
if ( is_write_command( cmd ) == 1 )
{
unsigned char status_register;
/* write commands require waiting until chip is finished writing */
do
{
status = sflash_read_status_register( handle, &status_register );
if ( status != 0 )
{
/*@-mustdefine@*/ /* Lint: do not need to define data_MISO due to failure */
return status;
/*@+mustdefine@*/
}
} while( ( status_register & SFLASH_STATUS_REGISTER_BUSY ) != (unsigned char) 0 );
}
/*@-mustdefine@*/ /* Lint: lint does not realise data_MISO was set by sflash_platform_send_recv */
return 0;
/*@+mustdefine@*/
}

View File

@@ -0,0 +1,161 @@
/**
******************************************************************************
* @file spi_flash.h
* @author William Xu
* @version V1.0.0
* @date 16-Sep-2014
* @brief This file provides all the headers of flash operation functions.
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#ifndef INCLUDED_SPI_FLASH_API_H
#define INCLUDED_SPI_FLASH_API_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/** @addtogroup MICO_Drivers_interface
* @{
*/
/** @defgroup MiCO_SPI_Flash_Driver MiCO SPI_Flash Driver
* @brief Provide driver interface for SPI Flash device
* @{
*/
typedef enum
{
SFLASH_WRITE_NOT_ALLOWED = 0,
SFLASH_WRITE_ALLOWED = 1,
} sflash_write_allowed_t;
typedef struct
{
uint32_t device_id;
void * platform_peripheral;
sflash_write_allowed_t write_allowed;
} sflash_handle_t;
/**
* @brief Initialize SPI flash
*
* @param handle: handle of spi flash to init
* @param peripheral_id:
* @param write_allowed_in:
*
* @return kNoErr : on success.
* @return kGeneralErr : if an error occurred
*/
int init_sflash ( /*@out@*/ sflash_handle_t* const handle, /*@shared@*/ void* peripheral_id, sflash_write_allowed_t write_allowed_in );
/**
* @brief SPI flash enter deep sleep mode
*
* @param handle: handle of spi flash to init
*
* @return kNoErr : on success.
* @return kGeneralErr : if an error occurred
*/
int sflash_enter_dpmode( const sflash_handle_t* const handle );
/**
* De-initializes a SPI Flash chip
*
* @param[in] handle Handle structure that will be used for this sflash instance - allocated by caller.
*
* @return @ref OSStatus
*/
int deinit_sflash ( /*@out@*/ sflash_handle_t* const handle);
/**
* @brief Read date from SPI flash
*
* @param handle: handle of spi flash to read
* @param device_address: address of spi flash to read
* @param data_addr: buffer address to put data read from spi flash
* @param size: size of data read from spi flash
*
* @return kNoErr : on success.
* @return kGeneralErr : if an error occurred
*/
int sflash_read( const sflash_handle_t* const handle, unsigned long device_address, /*@out@*/ /*@dependent@*/ void* const data_addr, unsigned int size );
/**
* @brief Write date to SPI flash
*
* @param handle: handle of spi flash to write
* @param device_address: address of spi flash to write
* @param data_addr: buffer address to put data write to spi flash
* @param size: size of data to be written in spi flash
*
* @return 0 : on success.
* @return none : if an error occurred
*/
int sflash_write( const sflash_handle_t* const handle, unsigned long device_address, /*@observer@*/ const void* const data_addr, unsigned int size );
/**
* @brief Erase all data of SPI flash
*
* @param handle: handle of spi flash to be erased
*
* @return 0 : on success.
* @return none : if an error occurred
*/
int sflash_chip_erase( const sflash_handle_t* const handle );
/**
* @brief Erase part date of SPI flash
*
* @param handle: handle of spi flash to be earsed
* @param device_address: address of spi flash to be erased
*
* @return 0 : on success.
* @return none : if an error occurred
*/
int sflash_sector_erase( const sflash_handle_t* const handle, unsigned long device_address );
/**
* @brief Get size of SPI flash
*
* @param handle: handle of spi flash
* @param size: size of spi flash
*
* @return 0 : on success.
* @return none : if an error occurred
*/
int sflash_get_size ( const sflash_handle_t* const handle, /*@out@*/ unsigned long* size );
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* INCLUDED_SPI_FLASH_API_H */

View File

@@ -0,0 +1,18 @@
#
# UNPUBLISHED PROPRIETARY SOURCE CODE
# Copyright (c) 2016 MXCHIP Inc.
#
# The contents of this file may not be disclosed to third parties, copied or
# duplicated in any form, in whole or in part, without the prior written
# permission of MXCHIP Corporation.
#
NAME := Lib_SPI_Flash_Library_$(PLATFORM)
$(NAME)_SOURCES := spi_flash.c spi_flash_platform.c
GLOBAL_INCLUDES := .
#(info $(COMPILER_SPECIFIC_PEDANTIC_CFLAGS))
# $(NAME)_CFLAGS = $(COMPILER_SPECIFIC_PEDANTIC_CFLAGS)

View File

@@ -0,0 +1,106 @@
/**
******************************************************************************
* @file spi_flash_internal.c
* @author William Xu
* @version V1.0.0
* @date 16-Sep-2014
* @brief This file provides all the headers of flash operation functions.
******************************************************************************
*
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#ifndef INCLUDED_SPI_FLASH_INTERNAL_H
#define INCLUDED_SPI_FLASH_INTERNAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "spi_flash.h"
#include <stdint.h>
/* Status Register bit definitions */
#define SFLASH_STATUS_REGISTER_BUSY ( 0x01 )
#define SFLASH_STATUS_REGISTER_WRITE_ENABLED ( 0x02 )
#define SFLASH_STATUS_REGISTER_BLOCK_PROTECTED_0 ( 0x04 )
#define SFLASH_STATUS_REGISTER_BLOCK_PROTECTED_1 ( 0x08 )
#define SFLASH_STATUS_REGISTER_BLOCK_PROTECTED_2 ( 0x10 ) /* SST Only */
#define SFLASH_STATUS_REGISTER_BLOCK_PROTECTED_3 ( 0x20 ) /* SST Only */
#define SFLASH_STATUS_REGISTER_AUTO_ADDRESS_INCREMENT ( 0x40 ) /* SST Only */
#define SFLASH_STATUS_REGISTER_BLOCK_PROTECT_BITS_READ_ONLY ( 0x80 ) /* SST Only */
/* Command definitions */
typedef enum
{
SFLASH_WRITE_STATUS_REGISTER = 0x01, /* WRSR */
SFLASH_WRITE = 0x02,
SFLASH_QUAD_WRITE = 0x38,
SFLASH_READ = 0x03,
SFLASH_QUAD_READ = 0xEB,
SFLASH_WRITE_DISABLE = 0x04, /* WRDI */
SFLASH_READ_STATUS_REGISTER = 0x05, /* RDSR */
SFLASH_WRITE_ENABLE = 0x06, /* WREN */
SFLASH_FAST_READ = 0x0B,
SFLASH_SECTOR_ERASE = 0x20, /* SE */
SFLASH_BLOCK_ERASE_MID = 0x52, /* SE */
SFLASH_BLOCK_ERASE_LARGE = 0xD8, /* SE */
SFLASH_READ_ID1 = 0x90, /* data size varies */
SFLASH_READ_ID2 = 0xAB, /* data size varies */
SFLASH_READ_JEDEC_ID = 0x9F, /* RDID */
SFLASH_CHIP_ERASE1 = 0x60, /* CE */
SFLASH_CHIP_ERASE2 = 0xC7, /* CE */
SFLASH_ENABLE_WRITE_STATUS_REGISTER = 0x50, /* EWSR - SST only */
SFLASH_READ_SECURITY_REGISTER = 0x2B, /* RDSCUR - Macronix only */
SFLASH_WRITE_SECURITY_REGISTER = 0x2F, /* WRSCUR - Macronix only */
SFLASH_ENTER_SECURED_OTP = 0xB1, /* ENSO - Macronix only */
SFLASH_EXIT_SECURED_OTP = 0xC1, /* EXSO - Macronix only */
SFLASH_DEEP_POWER_DOWN = 0xB9, /* DP - Macronix only */
SFLASH_RELEASE_DEEP_POWER_DOWN = 0xAB, /* RDP - Macronix only */
} sflash_command_t;
#define SFLASH_DUMMY_BYTE ( 0xA5 )
#define DUMMY_CLOCK_CYCLES_READ_QUAD 0x06
#define SFLASH_MANUFACTURER( id ) ( ( (id) & 0x00ff0000 ) >> 16 )
#define SFLASH_MANUFACTURER_SST ( (uint8_t) 0xBF )
#define SFLASH_MANUFACTURER_MACRONIX ( (uint8_t) 0xC2 )
#define SFLASH_MANUFACTURER_EON ( (uint8_t) 0x1C )
#define SFLASH_MANUFACTURER_WINBOND ( (uint8_t) 0xEF )
#define SFLASH_ID_MX25L8006E ( (uint32_t) 0xC22014 )
#define SFLASH_ID_MX25L1606E ( (uint32_t) 0xC22015 )
#define SFLASH_ID_SST25VF080B ( (uint32_t) 0xBF258E )
#define SFLASH_ID_EN25QH16 ( (uint32_t) 0x1C3015 )
#define SFLASH_ID_W25X80AVSIG ( (uint32_t) 0xEF3014 )
typedef struct
{
unsigned char id[3];
} device_id_t;
int sflash_read_ID ( const sflash_handle_t* handle, void* data_addr );
int sflash_read_status_register ( const sflash_handle_t* handle, void* dest_addr );
int sflash_write_status_register( const sflash_handle_t* handle, char value );
int generic_sflash_command ( const sflash_handle_t* handle, sflash_command_t cmd, unsigned long num_initial_parameter_bytes, /*@null@*/ /*@observer@*/ const void* parameter_bytes, unsigned long num_data_bytes, /*@null@*/ /*@observer@*/ const void* const data_MOSI, /*@null@*/ /*@out@*/ /*@dependent@*/ void* const data_MISO );
#ifdef __cplusplus
}
#endif
#endif /* INCLUDED_SPI_FLASH_INTERNAL_H */

View File

@@ -0,0 +1,85 @@
/**
******************************************************************************
* @file spi_flash_platform.c
* @author William Xu
* @version V1.0.0
* @date 16-Sep-2014
* @brief This file provides all the headers of flash operation functions.
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#include "spi_flash_platform_interface.h"
#include "mico_platform.h"
#if defined ( USE_MICO_SPI_FLASH )
int sflash_platform_init ( /*@shared@*/ void* peripheral_id, /*@out@*/ void** platform_peripheral_out )
{
UNUSED_PARAMETER( peripheral_id ); /* Unused due to single SPI Flash */
if ( kNoErr != MicoSpiInitialize( &mico_spi_flash ) )
{
/*@-mustdefine@*/ /* Lint: failed - do not define platform peripheral */
return -1;
/*@+mustdefine@*/
}
if( platform_peripheral_out != NULL)
*platform_peripheral_out = NULL;
return 0;
}
extern int sflash_platform_send_recv ( const void* platform_peripheral, /*@in@*/ /*@out@*/ sflash_platform_message_segment_t* segments, unsigned int num_segments )
{
UNUSED_PARAMETER( platform_peripheral );
if ( kNoErr != MicoSpiTransfer( &mico_spi_flash, (mico_spi_message_segment_t*) segments, (uint16_t) num_segments ) )
{
return -1;
}
return 0;
}
int sflash_platform_deinit( void )
{
if ( kNoErr != MicoSpiFinalize( &mico_spi_flash ) )
{
/*@-mustdefine@*/ /* Lint: failed - do not define platform peripheral */
return -1;
/*@+mustdefine@*/
}
return 0;
}
#else
int sflash_platform_init( /*@shared@*/ void* peripheral_id, /*@out@*/ void** platform_peripheral_out )
{
UNUSED_PARAMETER( peripheral_id );
UNUSED_PARAMETER( platform_peripheral_out );
return -1;
}
extern int sflash_platform_send_recv( const void* platform_peripheral, /*@in@*//*@out@*/sflash_platform_message_segment_t* segments, unsigned int num_segments )
{
UNUSED_PARAMETER( platform_peripheral );
UNUSED_PARAMETER( segments );
UNUSED_PARAMETER( num_segments );
return -1;
}
int sflash_platform_deinit( void )
{
return -1;
}
#endif

View File

@@ -0,0 +1,44 @@
/**
******************************************************************************
* @file spi_flash_platform_interface.h
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief This file provide all the headers of platform functions for spi
* flash driver
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#ifndef INCLUDED_SPI_FLASH_PLATFORM_INTERFACE_H
#define INCLUDED_SPI_FLASH_PLATFORM_INTERFACE_H
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
/*@null@*/ /*@observer@*/ const void* tx_buffer;
/*@null@*/ /*@dependent@*/ void* rx_buffer;
unsigned long length;
} sflash_platform_message_segment_t;
extern int sflash_platform_init ( /*@shared@*/ void* peripheral_id, /*@out@*/ void** platform_peripheral_out );
extern int sflash_platform_send_recv ( const void* platform_peripheral, /*@in@*/ /*@out@*/ sflash_platform_message_segment_t* segments, unsigned int num_segments );
extern int sflash_platform_deinit ( void );
#ifdef __cplusplus
}
#endif
#endif /* INCLUDED_SPI_FLASH_PLATFORM_INTERFACE_H */