在线时间260 小时
UID415468
注册时间2013-1-30
NXP金币0
TA的每日心情 | 慵懒 2018-11-15 16:18 |
---|
签到天数: 39 天 连续签到: 1 天 [LV.5]常住居民I
高级会员

- 积分
- 993
- 最后登录
- 2023-1-6
|
本帖最后由 小华-415468 于 2016-4-22 09:29 编辑
求助线上FAE FLASH擦写可以开中断吗(所用芯片是MC9S12G48)?因为擦(PFLASH)FLASH Sector时有好几十毫秒延时,关了总中断,定时器的定时时间就会有偏差,还有CallFnCmdInRam这个函数,为什么擦FLASH时要放到RAM执行,顺便发送一份擦FLASH的函数代码给予那些FLASH擦写没函数的学友们。
byte IFsh1_EraseSector(IFsh1_TAddress Addr)
{
if (BlockOutOfRange(Addr, Addr)) { /* Check range of address */
return(ERR_RANGE);
}
EnterCritical(); /* Enter critical section */
ClearFlags(); /* Clear all flags */
if (FSTAT_CCIF == 0U) { /* Is command buffer full ? */
ExitCritical(); /* Exit critical section */
return ERR_BUSY; /* If yes then error */
}
FCCOBIX = 0U; /* Clear index register */
FCCOBHI = 0x0AU; /* Erase P-Flash sector command */
FCCOBLO = (byte)(Addr >> 16U); /* High address word */
FCCOBIX++; /* Shift index register */
FCCOB = (word)(Addr & 0xFFFFFFF8UL); /* Low address word aligned to 8 byte phrase*/
CallFnCmdInRam(); /* Copy Wait in RAM routine to stack and launch the flash process */
if (FSTAT_FPVIOL == 1U) { /* Is protection violation detected ? */
ExitCritical(); /* Exit critical section */
return ERR_NOTAVAIL; /* If yes then error */
}
if (FSTAT_ACCERR == 1U) { /* Is acces error detected ? */
ExitCritical(); /* Exit critical section */
return ERR_NOTAVAIL; /* If yes then error */
}
if (FSTAT_MGSTAT) { /* Was attempt to erase the sector errorneous? */
ExitCritical(); /* Exit critical section */
return ERR_VALUE; /* If yes then error */
}
ExitCritical(); /* Exit critical section */
return ERR_OK; /* OK */
}
/*部分调用函数*/
#define EnterCritical() \
/*lint -save -e950 -esym(960,14.3) Disable MISRA rule (1.1,14.3) checking. */\
{ __asm(pshc); __asm(sei); __asm(movb 1,SP+,CCR_reg); } /* This macro is used by Processor Expert. It saves CCR register and disable global interrupts. */ \
#define ExitCritical() \
/*lint -save -e950 -esym(960,14.3) Disable MISRA rule (1.1,14.3) checking. */\
{ __asm(movb CCR_reg, 1,-SP); __asm(pulc); } /* This macro is used by Processor Expert. It restores CCR register saved in SaveStatusReg(). */ \
#define ClearFlags() (FSTAT = 0x30U)
static void FnCmdInRam_(void)
{
FSTAT = 0x80U; /* Clear flag command buffer empty */
while (FSTAT_CCIF == 0U) {} /* Wait to command complete */
return;
}
#pragma MESSAGE DISABLE C12056 /* Disable warning C12056 "SP debug info incorrect becouse of optimization or inline assembler" */
/* Types definitions */
typedef struct {
uint8_t code[15]; /* Structure required to copy code to ram memory */
/* Size of this structure needs to be at least (but best) the size of the FnCmdInRam_ */
} FnCmdInRamStruct;
typedef void (* near pFnCmdInRam)(void);
#pragma MESSAGE DISABLE C1805 /* Disable warning C1805 "Non-standard conversion used" */
/*lint -save -e740 -e931 Disable MISRA rule (1.2) checking. */
static void CallFnCmdInRam()
{
FnCmdInRamStruct FnCmdInRam = *(FnCmdInRamStruct *)(FnCmdInRam_); /* Create a copy of Wait in RAM routine on stack */
((pFnCmdInRam)&FnCmdInRam)(); /* Call code in RAM */
return;
}
|
|