📄 c2188.c
字号:
/*******************************************************************************
Filename: c2188.c
Description: Library routines for the Software Drivers for
NAND flash 2112 byte/1056 word page family.
Author: STMicroelectronics
Copyright:(C)STMicroelectronics
You have a license to reproduce, display, perform, produce derivative works of,
and distribute (in original or modified form) the Program, provided that you
explicitly agree to the following disclaimer:
THIS PROGRAM IS PROVIDED "AS IT IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTY
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
********************************************************************************
Version History.
Ver. No Date Comments
Alpha 0.1 10/2004 Initial Alpha Release of the driver
Beta 0.5 04/2005 Not all functions tested.
Release 1.0 08/2005 First release
*******************************************************************************/
#include "c2188.h"
static ubyte cacheReadMode=0x00; /* the device is in cache read */
static udword lastAddressInCacheRead=0; /* last address used in cache operation */
/*************Utility Functions***********************/
/******************************************************************************
SetCacheReadMode
Function: void SetCacheReadMode(ubyte value)
Arguments: value:
the value that you want to set cacheReadMode variable
Return Value: na
Description: This function set the variable cacheReadMode to the desired value
******************************************************************************/
void SetCacheReadMode(ubyte value)
{
cacheReadMode=value;
}
/******************************************************************************
GetCacheReadMode
Function: ubyte GetCacheReadMode()
Arguments: na
Return Value: CACHE_READ_PENDING:
a cache read not terminate is in act
CACHE_READ_NOT_PENDING
cache read is not pending
Description: This function get the value of the variable cacheReadMode
******************************************************************************/
ubyte GetCacheReadMode()
{
return cacheReadMode;
}
/******************************************************************************
GetLastAddressInCacheRead
Function: udword GetLastAddressInCacheRead()
Arguments: na
Return Value: the last address read in cache read mode
Description: This function get the value of the variable lastAddressInCacheRead
******************************************************************************/
udword GetLastAddressInCacheRead()
{
return lastAddressInCacheRead;
}
/******************************************************************************
SetLastAddressInCacheRead
Function: void SetLastAddressInCacheRead(udword address)
Arguments: address:
the address that you want to set in lastAddressInCacheRead
Return Value: na
Description: This function set the value of the variable lastAddressInCacheRead
******************************************************************************/
void SetLastAddressInCacheRead(udword address)
{
lastAddressInCacheRead=address;
}
/******************************************************************************
InsertAddress
Function: void InsertAddress(udword address)
Arguments: address - the address to insert
Return Value: na
Description: This function perform the data insertion in 4/5 cycles(row & column address)
******************************************************************************/
void InsertAddress(udword address)
{
ubyte ubTemp;
ubTemp = (ubyte) address;
NAND_AddressInput(ubTemp); /* first address byte */
if (FLASH_WIDTH == 8)
ubTemp = (ubyte) (address>>8)&0x07;
else
ubTemp = (ubyte) (address>>8)&0x03;
NAND_AddressInput(ubTemp); /* second address byte */
ubTemp = (ubyte) (address>>(10 + SHIFT_A8));
NAND_AddressInput(ubTemp); /* third address byte */
ubTemp =((ubyte) (address>>( 18 + SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fourth address byte */
#ifdef NAND02GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND02GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND04GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND04GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND08GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND08GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
}
/******************************************************************************
InsertSpareAddress
Function: void InsertAddress(udword address)
Arguments: address - the address to insert
Return Value: na
Description: This function perform the data insertion in 4 cycles(row & column address)
******************************************************************************/
void InsertSpareAddress(udword address)
{
ubyte ubTemp;
ubTemp = (ubyte) address;
NAND_AddressInput(ubTemp); /* first address byte */
if (FLASH_WIDTH == 8)
ubTemp = (ubyte) (address>>8)&0x07|0x08;
else
ubTemp = (ubyte) (address>>8)&0x07|0x04;
NAND_AddressInput(ubTemp); /* second address byte */
ubTemp = (ubyte) (address>>(10 + SHIFT_A8));
NAND_AddressInput(ubTemp); /* third address byte */
ubTemp =((ubyte) (address>>( 18 + SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fourth address byte */
#ifdef NAND02GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND02GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND04GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND04GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND08GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND08GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
}
/******************************************************************************
InsertColumnAddress
Function: void InsertColumnAddress(udword address)
Arguments: address is the address to insert
Return Value: na
Description: This function perform the address insertion of bytes
that represent the column in the page
******************************************************************************/
void InsertColumnAddress(udword address)
{
ubyte ubTemp;
ubTemp = (ubyte) address;
NAND_AddressInput(ubTemp); /* first address byte */
/* Shift to right considering differences between x8/x16 device */
if (FLASH_WIDTH == 8)
ubTemp = (ubyte) (address>>8)&0x07;
else
ubTemp = (ubyte) (address>>8)&0x03;
NAND_AddressInput(ubTemp); /* second address byte */
}
/******************************************************************************
InsertColumnAddressSpare
Function: void InsertColumnAddress(udword address)
Arguments: address is the address to insert
Return Value: na
Description: This function perform the address insertion of bytes
that represent the column in the page
******************************************************************************/
void InsertColumnAddressSpare(udword address)
{
ubyte ubTemp;
ubTemp = (ubyte) address;
NAND_AddressInput(ubTemp); /* first address byte */
/* Shift to right considering differences between x8/x16 device */
if (FLASH_WIDTH == 8)
ubTemp = (ubyte) (address>>8)&0x07|0x08;
else
ubTemp = (ubyte) (address>>8)&0x07|0x04;
NAND_AddressInput(ubTemp); /* second address byte */
}
/******************************************************************************
InsertBlockAddress
Function: void InsertBlockAddress(udword address)
Arguments: address is the address to insert
Return Value: na
Description: This function perform the address insertion of the bytes
that represent the block number
******************************************************************************/
void InsertBlockAddress(udword address)
{
ubyte ubTemp;
ubTemp = (ubyte) (address>>(10 + SHIFT_A8));
NAND_AddressInput(ubTemp); /* third address byte */
ubTemp =((ubyte) (address>>( 18 + SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fourth address byte */
#ifdef NAND02GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND02GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND04GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND04GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND08GRW3B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
#ifdef NAND08GRW4B
ubTemp =((ubyte) (address>>( 26+ SHIFT_A8)));
NAND_AddressInput(ubTemp); /* fifth address byte */
#endif
}
/*******************************************************************************
waitForReady
Function: ubyte waitForReady()
Arguments:
Return Value: Return the status of the status register
Description: This function is called after an operation on the NAND is
asserted. The function wait until the NAND is ready.
NOTE: after return the NAND is lived in status register mode
*******************************************************************************/
ubyte waitForReady(){
ubyte ubStatus;
/*Read Status Register*/
NAND_CommandInput((ubyte)0x70);
ubStatus = NAND_DataOutput();
/*Wait until the NAND is busy*/
while ( (ubStatus&(0x40))!= 0x40 ) {
ubStatus = NAND_DataOutput();
}
return ubStatus;
}
/*****************************************************/
/****************************************************************************
///////////////////////////////////////////
/////// HARDWARE DEPENDENT FUNCTION ///////
///////////////////////////////////////////
****************************************************************************/
/******************************************************************************
NAND_SetWriteProtected
Function: void NAND_SetWriteProtected(void)
Arguments: na
Return Value: na
Description: This function set the WP pint to low
******************************************************************************/
void NAND_SetWriteProtect(void)
{
/*to be implemented */
}
/******************************************************************************
NAND_UnsetWriteProtected
Function: void NAND_UnsetWriteProtected(void)
Arguments: na
Return Value: na
Description: This function set the WP pint to high
******************************************************************************/
void NAND_UnsetWriteProtect(void)
{
/*to be implemented */
}
/******************************************************************************
Wait_time
Function: NAND_WaitTime(ubyte nanoseconds)
Arguments: nanosecond - time in ns
Return Value: na
Description: This function wait a period of time
******************************************************************************/
void NAND_WaitTime(ubyte nanoseconds){
/*to be implemented */
}
/******************************************************************************
NAND_Open
Function: void NAND_Open()
Arguments:
Return Value: na
Description: This function is called before a new operation on the NAND starts.
******************************************************************************/
void NAND_Open() {
/*to be implemented */
}
/************** NAND_Open ***************/
/******************************************************************************
NAND_AddressInput
Function: void NAND_AddressInput(ubyte ubAddress)
Arguments: ubAddress - is the address to be issued to the NAND.
Return Value: na
Description: This function issues an address byte to the flash and control the
specific hardware signals between the MCU and the device
******************************************************************************/
void NAND_AddressInput(ubyte ubAddress) {
/*to be implemented */
}
/******************************************************************************
NAND_CommandInput
Function: void NAND_CommandInput(ubyte ubCommand)
Arguments: ubCommand - is the command to be issued to the NAND.
Return Value: na
Description: This function issues a command to the flash and control the
specific hardware signals between the MCU and the device.
******************************************************************************/
void NAND_CommandInput(ubyte ubCommand) {
/*to be implemented */
}
/************** NAND_CommandInput ***************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -