📄 flashwritepage.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** HAL - FlashWritePage *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* *
*****************************************************************************
* Author: ROH *
*****************************************************************************
* Revision history: *
* *
* $Log: FlashWritePage.c,v $
* Revision 1.2 2003/02/25 10:00:28 tos
* Cosmetic change on header.
*
* Revision 1.1 2002/10/14 13:04:31 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#include <chipcon/hal.h>
//----------------------------------------------------------------------------
// bool halFlashWritePage(...)
//
// Description:
// Writes into the flash page pointed to by _flashPage_ 128 bytes of
// data pointed to by _ramBuffer_. The addresses of both _flashPage_ and
// _ramBuffer_ must be an integer multiple of 128, i.e adr mod 128=0.
// _clkFreq_ must be the XOSC frequency in kHz and is used to calculate
// the correct erasure and programming times.
// If these conditions are not met the function does not perform any
// programming and returns FALSE. A verification of the data written is
// performed after programming - if this verification fails for some reason
// (flash page is write locked, or flash programming failure) the function
// also returns FALSE.
// All interrupts are turned off while this function executes.
// An empty Flash interrupt handler must be present in order for flash
// writing to return execution to the program, e.g:
//
// void isr_flash() interrupt INUM_FLASH {
// }
//
// Arguments:
// byte code* flashPage
// Pointer to the destination of the write in code memory space.
// Address must be an integer multiple of 128 bytes.
// byte xdata* ramBuffer
// Pointer to the data source in RAM for the write in XDATA memory
// space. Address must be an integer multiple of 128 bytes.
// word clkFreq
// The XOSC clock frequency in kHz.
//
// Return value:
// bool
// TRUE if the write was successful. False if programming/verification
// failed or supplied arguments were invalid.
//----------------------------------------------------------------------------
bool halFlashWritePage(byte code* flashPage, byte xdata* ramBuffer, word clkFreq) {
byte i;
if ( ((word)flashPage&0x7F)!=0 || ((word)ramBuffer&0x7F)!=0 )
return FALSE;
// FLTIM >= clkFreq/800 -> FLTIM=clkFreq/(256*3)
FLTIM=(byte)(clkFreq>>8)/3;
// Setup Flash writing
FLADR=(word)flashPage>>7;
FLCON=(FLCON&0xF0) | (((word)ramBuffer>>7)&0x0F) | 0x10;
// Make sure that debugger knows it is us + turn off interrupt
CY=EA;
EA=0;
FDIE=1;
RESERVED|=0x80;
ENTER_IDLE_MODE();
RESERVED&=~0x80;
EA=CY;
FLCON &= ~0x10;
// Verify whole page
for (i=0; i<128; i++)
if (flashPage[i]!=ramBuffer[i])
return FALSE;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -