在线时间15 小时
UID3298921
注册时间2016-7-19
NXP金币0
该用户从未签到
注册会员

- 积分
- 84
- 最后登录
- 2016-8-23
|
看飞思卡尔官方给出的bootloader中的flash的分频程序,感到很不解
1、为什么file:/// li16ClockFreq大于12000时,要并上一个0x40
2、if (FSTAT&0x30) //Check to see if FACCERR or PVIOL are set
{
FSTAT |= 0x30; //write a 1 to FACCERR and PVIOL to clear
}
这段代码为什么还要来一个if判断,直接写FSTAT |= 0x30;不就行了吗?
图片中的代码和文字贴出来的代码都一样,其中中文注释是我自己加上去的
- uint8 near vfnFlashInit(uint16 li16ClockFreq)
- {
- uint8 lbFlashMask = 0;
- FCNFG = 0x00; //FLASH配置寄存器,不进行任何操作或请求
- if (li16ClockFreq > 1000) /*The oscillator must be greater than 1MHz to use the Flash Routines*/
- {
- if (!(FCLKDIV&(0x80))) //检查FCLKDIV是否已经被写入数据,若没有,则执行if中的语句
- {
- /*
- * The DataSheet specifies that the value of the FCLKDIV must set the Flash Clock in a value
- * between 150KHz and 200KHz. The FDIV8 Bit should be set if the value of the XTAL is greater
- * than 12.8MHz; Instead of using 12.8MHz as a maximum, we are using the value of 12MHz, this
- * makes the code smaller
- */
- if (li16ClockFreq > 12000) /*If the oscillator value is greater than 12000KHz (12.0MHz) set the PRDIV8*/
- {
- li16ClockFreq >>= 3; /*Divide the frequency by 8*/
- lbFlashMask = 0x40;
- }
- /*Calculate the value to adjust the Flash clock to 200KHz*/
- FCLKDIV = (((uint8)(li16ClockFreq /200)) - 1) | lbFlashMask;
- }
- if (FSTAT&0x30) //Check to see if FACCERR or PVIOL are set
- {
- FSTAT |= 0x30; //write a 1 to FACCERR and PVIOL to clear
- }
- return(OK);
- }
- return(ERROR);
- }
复制代码
flash分频函数.png
、

|
|