资源简介
完整的spiflash驱动代码,架构扩展性良好,兼容性广,支持四线串行闪存QPI模式。
先要调用init函数初始化,才能调用读写等函数。
代码片段和文件信息
/*
* (C) Copyright 2012 - 2014
*
* Written by: henry.he
*
* This program 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 of
* the License or (at your option) any later version.
*
* This program 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 this program; if not write to the Free Software
* Foundation Inc. 59 Temple Place Suite 330 Boston
* MA 02111-1307 USA
*/
#include “nor_flash_drv_hal.h“
#ifdef __cplusplus
extern “C“
{
#endif
extern NOR_FLASH_DRV_T g_hspi_flash_drv;
static NOR_FLASH_DRV_PTR s_Nor_Driver_ptr = NULL;
void NorFlash_Init(void)
{
s_Nor_Driver_ptr = &g_hspi_flash_drv;
DRV_ASSERT(s_Nor_Driver_ptr->_init != NULL);
s_Nor_Driver_ptr->_init();
}
int NorFlash_Read(u32 address u32 length u8 *rd_buf)
{
bool_t ret = FALSE;
FLASH_RW_PARA_T cmd_para;
u32 read_unit = 0;
u32 flash_size = 0;
NorFlash_InfoGet(FLASH_READ_UNIT_MIN (void *)&read_unit);
NorFlash_InfoGet(FLASH_CAPACITY (void *)&flash_size);
if (address != (address & (~(read_unit - 1))))
return FLASH_READ_ADDR_ALIGN_ERR;
if (address > flash_size)
return FLASH_READ_ADDR_LONG_ERR;
if (length < read_unit)
return FLASH_READ_SIZE_SHORT_ERR;
if (length != (length & (~(read_unit - 1))))
return FLASH_READ_SIZE_ALIGN_ERR;
if (address + length > flash_size)
return FLASH_READ_SIZE_LENGTH_ERR;
if (rd_buf == NULL)
return FLASH_READ_BUF_ERR;
if (s_Nor_Driver_ptr == NULL)
return FLASH_NOT_INIT_ERR;
cmd_para.addr = address;
cmd_para.size = length;
DRV_ASSERT(s_Nor_Driver_ptr->_ioctl != NULL);
ret = s_Nor_Driver_ptr->_ioctl(FLASH_READ (void *)&cmd_para (void *)rd_buf);
if(ret)
return 0;
else
return FLASH_READ_ERR;
}
int NorFlash_Write(u32 address u32 length u8 *wr_buf)
{
bool_t ret = FALSE;
FLASH_RW_PARA_T cmd_para;
u32 program_unit = 0;
u32 flash_size = 0;
NorFlash_InfoGet(FLASH_PROGRAM_UNIT_MIN (void *)&program_unit);
NorFlash_InfoGet(FLASH_CAPACITY (void *)&flash_size);
if (address != (address & (~(program_unit - 1))))
return FLASH_PROGRAM_ADDR_ALIGN_ERR;
if (address > flash_size)
return FLASH_PROGRAM_ADDR_LONG_ERR;
if (length < program_unit)
return FLASH_PROGRAM_SIZE_SHORT_ERR;
if (length != (length & (~(program_unit - 1))))
return FLASH_PROGRAM_S
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-05-19 10:22 hsflash_drv\
目录 0 2013-05-19 10:22 hsflash_drv\common\
文件 798 2013-05-06 09:20 hsflash_drv\common\arm_chip_drv.c
文件 4163 2013-04-29 16:02 hsflash_drv\common\timer.c
目录 0 2013-05-19 10:22 hsflash_drv\hsf_device\
文件 1497 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_eon.c
文件 1153 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_esmt.c
文件 1087 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_gigadevice.c
文件 4900 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_micron.c
文件 2722 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_mxic.c
文件 1157 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_sst.c
文件 1112 2013-05-18 13:27 hsflash_drv\hsf_device\hsf_dev_winbond.c
目录 0 2013-05-19 10:22 hsflash_drv\hsf_drv\
文件 8428 2013-05-18 13:27 hsflash_drv\hsf_drv\hsf_dev_config.c
文件 26950 2013-05-18 13:27 hsflash_drv\hsf_drv\hsf_drv_common.c
文件 18224 2013-05-18 13:31 hsflash_drv\hsf_drv\hsf_drv_interface.c
文件 22477 2013-05-19 09:13 hsflash_drv\hsf_drv\hsfc_drv_phy.c
文件 9499 2013-05-18 13:26 hsflash_drv\hsf_drv\hsfi_drv_phy.c
目录 0 2013-05-19 10:22 hsflash_drv\include\
文件 202 2013-04-19 21:00 hsflash_drv\include\arm_chip_drv.h
文件 1691 2013-05-18 13:27 hsflash_drv\include\hsf_dev_config.h
文件 7410 2013-05-19 09:14 hsflash_drv\include\hsf_drv_common.h
文件 3246 2013-05-18 13:27 hsflash_drv\include\hsf_drv_interface.h
文件 24761 2013-05-19 09:13 hsflash_drv\include\hsfc_drv_phy.h
文件 7296 2013-05-18 13:27 hsflash_drv\include\hsfi_drv_phy.h
文件 346 2013-04-29 14:39 hsflash_drv\include\timer.h
文件 1143 2013-04-29 16:29 hsflash_drv\include\type_def.h
文件 5274 2013-05-18 13:27 hsflash_drv\nor_flash_drv_hal.c
文件 2780 2013-05-18 13:27 hsflash_drv\nor_flash_drv_hal.h
文件 1843 2013-05-19 13:12 hsflash_drv\spiflash_test.c
- 上一篇:超声波电子测距仪 单片机
- 下一篇:MD5-SHA1-SHA256算法源码
评论
共有 条评论