/*
* COPYRIGHT (c) 2010 MACRONIX INTERNATIONAL CO., LTD
* Flash Low Level Driver (LLD) Sample Code
*
* and PARELLEL interface command set
*
* $Id: MX25_CMD.c,v 1.6 2010/06/02 01:35:22 benhuang Exp $
*/
#include "config.h"
#include "MX25_CMD.h"
#define PAGE_SIZE 256
#define SECTOR_SIZE 4096
#define PAGESOFSECTOR SECTOR_SIZE/PAGE_SIZE
#define CE0 ((uint32)1<<7) //P0.7
#define CE1 ((uint32)1<<24) //P1.24
/*********************************************************************************************************
** Function name: Initialise
**
** Descriptions: Initialize the
**
** input parameters: 速率分频值
** Returned value: 1 OK 0 NOT OK
**
** Used global variables: None
** Calling modules: None
**
** Created by: sdg
** Created Date: 2005/07/12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 InitialiseSPI(uint8 Fdiv)
{
IODIR |= CE0;
IO1DIR|= CE1; //0508 设置为输出
IOSET |= CE0;
IO1SET|= CE1; //0508 输出为高
PINSEL0 =(PINSEL0 &0xFFFFC0FF) | 0x1500;
SPI_SPCCR = Fdiv & 0xfe; /* 分频值 */
SPI_SPCR = 0x38; /* 主机、不允许中断 */
/* 高位在前、SCK高有效 */
/* 数据在SCK的第二个时钟沿采样 */
return(1);
}
/*
* Function: CS_Low, CS_High
* Arguments: None.
* Description: Chip select go low / high.
* Return Message: None.
*/
void CS_Low(uint8 cs)
{
/*
if(cs == 0)
IO0CLR |= CE0;
else
IO1CLR|= CE1;
*/
IO0CLR |= CE0;
}
void CS_High(uint8 cs)
{
/*
if(cs == 0)
IO0SET |= CE0;
else
IO1SET|= CE1;
*/
IO0SET |= CE0;
}
/*********************************************************************************************************
** Function name: SECTOR_SIZE
**
** Descriptions: 写一个字节
**
** input parameters: 欲写的数据
** Returned value: 1 OK 0 NOT OK
**
** Used global variables: None
** Calling modules: None
**
** Created by: sdg
** Created Date: 2005/07/12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void spi_write(uint8 dat)
{
SPI_SPDR =dat;
while(!(SPI_SPSR &0x80));
}
/*********************************************************************************************************
** Function name: spi_write
**
** Descriptions: 读一个字节
**
** input parameters: none
** Returned value: 读取的数据
**
** Used global variables: None
** Calling modules: None
**
** Created by: sdg
** Created Date: 2005/07/12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static uint8 spi_read(void)
{
SPI_SPDR =0;
while(!(SPI_SPSR &0x80));
return(SPI_SPDR);
}
/*
--Common functions
*/
void InsertDummyCycle( uint8 dummy_cycle )
{
uint8 i;
for(i = 0; i < dummy_cycle;i++);
}
/*
* Function: WaitFlashReady
* Arguments: ExpectTime, expected time-out value of flash operations.
* No use at non-synchronous IO mode.
* fsptr, pointer of flash status structure
* No use at non-synchronous IO mode.
* Description: Synchronous IO:
* If flash is ready return TRUE.
* If flash is time-out return FALSE.
* Non-synchronous IO:
* Always return TRUE
* Return Message: TRUE, FALSE
*/
BOOL WaitFlashReady( uint32 ExpectTime, FlashStatus *fsptr )
{
#ifndef NON_SYNCHRONOUS_IO
uint32 temp = 0;
while( IsFlashBusy( fsptr ) )
{
if( temp > ExpectTime )
{
return FALSE;
}
temp = temp + 1;
}
return TRUE;
#else
return TRUE;
#endif
}
/*
* Function: WaitRYBYReady
* Arguments: ExpectTime, expected time-out value of flash operations.
* No use at non-synchronous IO mode.
* Description: Synchronous IO:
* If flash is ready return TRUE.
* If flash is time-out return FALSE.
* Non-synchronous IO:
* Always return TRUE
* Return Message: TRUE, FALSE
*/
BOOL WaitRYBYReady( uint32 ExpectTime )
{
#ifndef NON_SYNCHRONOUS_IO
uint32 temp = 0;
if( temp > ExpectTime )
{
return FALSE;
}
temp = temp + 1;
return TRUE;
#else
return TRUE;
#endif
}
/*
* Function: IsFlashBusy
* Arguments: fsptr, pointer of flash status structure
* Description: Check status register WIP bit.
* If WIP bit = 1: return TRUE ( Busy )
* = 0: return FALSE ( Ready ).
* Return Message: TRUE, FALSE
*/
BOOL IsFlashBusy( FlashStatus *fsptr )
{
uint8 gDataBuffer;
CMD_RDSR( &gDataBuffer, fsptr );
if( (gDataBuffer & FLASH_WIP_MASK) == FLASH_WIP_MASK )
return TRUE;
else
return FALSE;
}
/*
* Function: IsFlashPAR
* Arguments: fsptr, pointer of flash status structure
* Description: Return flash current state: or PARALLEL
* Return Message: PAR enable or not ( TRUE / FALSE )
*/
BOOL IsFlashPAR( FlashStatus *fsptr )
{
if( (fsptr->ModeReg&0x02) == 0x02 )
return TRUE;
else
return FALSE;
}
/*
* Function: IsFlashQIO
* Arguments: fsptr, pointer of flash status structure
* Description: If flash QE bit = 1: return TRUE
* = 0: return FALSE.
* Return Message: TRUE, FALSE
*/
BOOL IsFlashQIO( FlashStatus *fsptr )
{
uint8 gDataBuffer;
CMD_RDSR( &gDataBuffer, fsptr );
if( (gDataBuffer & FLASH_QE_MASK) == FLASH_QE_MASK )
return TRUE;
else
return FALSE;
}
/*
* Function: IsFlash4Byte
* Arguments: None
* Description: Check flash address is 3-byte or 4-byte.
* If flash 4BYTE bit = 1: return TRUE
* = 0: return FALSE.
* Return Message: TRUE, FALSE
*/
BOOL IsFlash4Byte( void )
{
uint8 gDataBuffer;
CMD_RDSCUR( &gDataBuffer );
if( (gDataBuffer & FLASH_4BYTE_MASK) == FLASH_4BYTE_MASK )
return TRUE;
else
return FALSE;
}
/*
* Function: SendFlashAddr
* Arguments: flash_address, 32 bit flash memory address
* addr_4byte_mode,
* Description: Send flash address with 3-byte or 4-byte mode.
* Return Message: None
*/
void SendFlashAddr( uint32 flash_address, BOOL addr_4byte_mode )
{
/* Check flash is 3-byte or 4-byte mode.
4-byte mode: Send 4-byte address (A31-A0)
3-byte mode: Send 3-byte address (A23-A0) */
if( addr_4byte_mode == TRUE ){
spi_write( (flash_address >> 24) ); // A31-A24
}
/* A23-A0 */
spi_write( (flash_address >> 16) );
spi_write( (flash_address >> 8) );
spi_write( (flash_address) );
}
/*
* Function: CMD_RDID
* Arguments: Identification, 32 bit buffer to store id
* fsptr, pointer of flash status structure
* Description: The RDID instruction is to read the manufacturer ID
* of 1-byte and followed by Device I
MX25L128相关驱动
4星 · 超过85%的资源 需积分: 50 56 浏览量
2012-08-04
13:11:30
上传
评论 4
收藏 11KB RAR 举报
hxh07
- 粉丝: 1
- 资源: 6
最新资源
- 基于matlab实现文档+程序边缘计算任务卸载与资源调度的算法,是论文的源代码,具有价值.rar
- 什么是学生成绩管理系统c++以及学习学生成绩管理系统的意义
- 什么是词向量-以及学习关于了解词向量的意义
- 什么是mybatis动态sql以及学习mybatis动态sql的意义
- 华为数据治理方法论,包括:数据治理框架、数据治理组织架构、数据治理度量评估体系以及华为数据治理案例分享
- 基于matlab实现对表面肌电信号进行归一化处理,并对归一化后的图形显示 .rar
- 基于matlab实现单级倒立摆的 T-S 模型 包括 LMI 程序源码
- 图书管理系统(struts+hibernate+spring+ext).rar
- 基于matlab实现此压缩包包含语音信号处理中的语音变声代码加音频.rar
- STM32使用PWM驱动舵机并通过OLED显示
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页