📄 low_drv.c
字号:
/*****************************************************************************
FILE NAME: low_drv.c
DESCRIPTION:
relocatable driver code for intel single bank flash.
Copyright (c) 2002, VIA Technologies, Inc.
*****************************************************************************/
#include "fsmdefs.h"
#include "FsmFlash.h"
#include "intelflash.h"
#include "hwddefs.h"
#ifndef INTERRUPT_PENDING
#define INTERRUPT_PENDING \
((*((volatile uint16 *)(HWD_CP_SRC0_L))) || \
(*((volatile uint16 *)(HWD_CP_SRC1_L))) || \
(*((volatile uint16 *)(HWD_CP_SRC2_L))) || \
/* (*((volatile uint16 *)(HWD_CP_SRC3_L))) || */ \
(*((volatile uint16 *)(HWD_CP_SRC0_H))) || \
(*((volatile uint16 *)(HWD_CP_SRC1_H))) || \
(*((volatile uint16 *)(HWD_CP_SRC2_H))) || \
((((*((volatile uint16 *)(HWD_UART0_ISR))) & 0x07) & HWD_ISR_INT_PEND) == 0) || \
((((*((volatile uint16 *)(HWD_UART1_ISR))) & 0x07) & HWD_ISR_INT_PEND) == 0) || \
((((*((volatile uint16 *)(HWD_UART2_ISR))) & 0x07) & HWD_ISR_INT_PEND) == 0) || \
(*((volatile uint16 *)(HWD_ST_CPINT_SRC))) /* || \
(*((volatile uint16 *)(HWD_CP_SRC3_H))) */ )
#endif /* INTERRUPT_PENDING */
#define LOCK_BLOCK(addr_ptr) \
do \
{ \
*(addr_ptr) = FLASH_COMMAND_LOCK; \
*(addr_ptr) = FLASH_COMMAND_LOCK_CONFIRM; \
} while(0)
#define UNLOCK_BLOCK(addr_ptr) \
do \
{ \
*(addr_ptr) = FLASH_COMMAND_LOCK; \
*(addr_ptr) = FLASH_COMMAND_UNLOCK_CONFIRM; \
} while(0)
/*
* Global Declarations
*/
volatile uint8 FsmStarting = FALSE;
#if (RELOCATE_CODE == TRUE)
/******************************************************************************
* FsmLowerBegin()
*
* descriptions:
* This function is used as a "bookmark",
* used to locate the following functions.
*
* parameters:
*
* return:
*
*****************************************************************************/
void FsmLowerBegin()
{
return;
}
#endif /* RELOCATE_CODE */
/******************************************************************************
* FsmLowerWrite()
*
* descriptions:
* Writes data to the flash.
*
* parameters:
* FLASH_DATA_PTR flash_ptr - flash address where the block resides.
* FLASH_DATA * ram_ptr - buffer contains the data to be written.
* uint32 status - the status of the previous operation.
*
* return:
* HW_ERR_NONE, HW_ERR_SUSPEND, HW_ERR_WRITE.
*****************************************************************************/
uint32 FsmLowerWrite(
volatile FLASH_DATA * flash_ptr,
const FLASH_DATA * ram_ptr,
uint32 status
)
{
/* if previously suspended, resume write */
if (status == HW_ERR_SUSPEND)
{
*flash_ptr = FLASH_COMMAND_RESUME;
*flash_ptr = FLASH_COMMAND_STATUS;
}
/* otherwise, write data */
else
{
/* If try to program data bit from 0 to 1. */
if(((*ram_ptr) & (~(*flash_ptr))) != 0)
{
return HW_ERR_WRITE;
}
/* If the result data is equal to original. */
if((*ram_ptr) == (*flash_ptr))
{
return HW_ERR_NONE;
}
UNLOCK_BLOCK(flash_ptr);
*flash_ptr = FLASH_COMMAND_WRITE;
*flash_ptr = *ram_ptr;
}
/* wait until flash ready or interrupt occurs */
while (((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) &&
((!(INTERRUPT_PENDING)) || FsmStarting)) /*(!(INTERRUPT_PENDING)))*/
{
}
/* if an interrupt occurred, suspend */
if ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
*flash_ptr = FLASH_COMMAND_SUSPEND;
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
}
}
if (*flash_ptr & FLASH_STATUS_WRITE_SUSPENDED)
{
status = HW_ERR_SUSPEND;
}
/* write complete, check for errors */
else if (*flash_ptr & FLASH_STATUS_ERROR)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
status = HW_ERR_WRITE;
}
/* write was successful */
else
{
status = HW_ERR_NONE;
}
/* lock block if not suspended */
if (status != HW_ERR_SUSPEND)
{
LOCK_BLOCK(flash_ptr);
}
/* reset to read mode */
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
/******************************************************************************
* FsmLowerErase()
*
* descriptions:
* erase a flash block.
*
* parameters:
* FLASH_DATA_PTR flash_ptr - flash address where the block resides.
* uint32 status - the status of the previous operation.
*
* return:
* HW_ERR_NONE, HW_ERR_SUSPEND, HW_ERR_ERASE.
*****************************************************************************/
uint32 FsmLowerErase(volatile FLASH_DATA_PTR flash_ptr, uint32 status)
{
/* check if previously suspended; if so, resume */
if (status == HW_ERR_SUSPEND)
{
UNLOCK_BLOCK(flash_ptr);
*flash_ptr = FLASH_COMMAND_RESUME;
*flash_ptr = FLASH_COMMAND_STATUS;
}
/* otherwise, unlock block & issue erase command */
else
{
UNLOCK_BLOCK(flash_ptr);
*flash_ptr = FLASH_COMMAND_ERASE;
*flash_ptr = FLASH_COMMAND_CONFIRM;
}
/* wait until flash ready or interrupt occurs */
while (((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) &&
((!(INTERRUPT_PENDING)) || FsmStarting)) /*(!(INTERRUPT_PENDING)))*/
{
}
/* if an interrupt occurred, suspend */
if ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
*flash_ptr = FLASH_COMMAND_SUSPEND;
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
}
}
if (*flash_ptr & FLASH_STATUS_ERASE_SUSPENDED)
{
status = HW_ERR_SUSPEND;
}
/* erase complete, check for errors */
else if (*flash_ptr & FLASH_STATUS_ERROR)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
status = HW_ERR_ERASE;
}
/* erase was successful */
else
{
status = HW_ERR_NONE;
}
LOCK_BLOCK(flash_ptr);
/* reset to read mode */
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
/******************************************************************************
* FsmLowerReadStat()
*
* descriptions:
* Reads the status of the flash.
*
* parameters:
* FLASH_DATA_PTR flash_ptr - flash address.
*
* return:
* status value.
*****************************************************************************/
FLASH_DATA FsmLowerReadStat(volatile FLASH_DATA_PTR flash_ptr)
{
FLASH_DATA status;
*flash_ptr = FLASH_COMMAND_STATUS;
status = *flash_ptr;
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
/******************************************************************************
* FsmLowerClearStat()
*
* descriptions:
* Clears the error status of the flash.
*
* parameters:
* FLASH_DATA_PTR flash_ptr - flash address.
*
* return:
*
*****************************************************************************/
void FsmLowerClearStat(volatile FLASH_DATA_PTR flash_ptr)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
*flash_ptr = FLASH_COMMAND_READ;
}
#if (RELOCATE_CODE == TRUE)
/******************************************************************************
* FsmLowerEnd()
*
* descriptions:
* This function is used as a "bookmark",
* indicates the end of the module.
*
* parameters:
*
* return:
*
*****************************************************************************/
void FsmLowerEnd()
{
return;
}
#endif /* RELOCATE_CODE */
/*****************************************************************************
* $Log: low_drv.c $
* Revision 1.4 2004/03/17 12:58:07 zgy
* Revision 1.5 2004/03/16 15:56:24 jjs
* Revision 1.4 2003/10/27 13:28:10 jjs
* included the intel flash command & status definitions.
* Revision 1.3 2003/10/15 18:41:01 jjs
* Revision 1.2 2003/09/12 14:16:57 jjs
* Revision 1.1 2003/09/09 15:07:32 jjs
* Initial revision
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -