亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? flash.c

?? 基于STR711的Flash程序
?? C
字號:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name          : flash.c
* Author             : MCD Application Team
* Date First Issued  : 07/28/2003
* Description        : This file provides all the Flash software functions
********************************************************************************
* History:
*  01/01/2004 : V1.2
*  14/07/2004 : V1.3
*******************************************************************************/

#include "flash.h"

/*******************************************************************************
* Function Name  : FLASH_Init
* Description    : Initialise the Flash
* Input          : None
* Return         : None
*******************************************************************************/
void FLASH_Init(void)
{
// Reset Flash Control Registers
  FLASHR->CR0 = 0x00000000;
  FLASHR->CR1 = 0x00000000;
// Reset Flash Data Registers
  FLASHR->DR0 = 0xFFFFFFFF;
  FLASHR->DR1 = 0xFFFFFFFF;
// Reset Flash Error Register
  FLASHR->ER  = 0x00000000;
}

/*******************************************************************************
* Function Name  : FLASH_WordWrite
* Description    : Writes a Word to the Flash
* Input 1        : Address of the Destination
* Input 2        : Word To program
* Return         : None
*******************************************************************************/
void FLASH_WordWrite(u32 XtargetAdd, u32 Xdata)
{
  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);
  // set the Word Programming bit 'WPG' in the CR0 Reg
  FLASHR->CR0 |= FLASH_WPG_Mask;
  // Load the destination address in AR
  FLASHR->AR   = XtargetAdd;
  // Load DATA to be programmed in DR0
  FLASHR->DR0  = Xdata;
  // Set the Write Mode Start bit 'WMS' in the CR0 Reg to Start Write Operation
  FLASHR->CR0 |= FLASH_WMS_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_DWordWrite
* Description    : Writes Double Word to the Flash
* Input 1        : Address of the Destination
* Input 2        : Word 1 To program
* Input 3        : Word 2 To program
* Return         : None
*******************************************************************************/
void FLASH_DWordWrite(u32 XtargetAdd, u32 Xdata0, u32 Xdata1)
{
  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);
  // set the Double Word Programming bit 'DWPG' in the CR0 Reg
  FLASHR->CR0 |= FLASH_DWPG_Mask;
  // Load the destination address in AR
  FLASHR->AR   = XtargetAdd;
  // Load DATA0 in DR0 Reg
  FLASHR->DR0  = Xdata0;
  // Load DATA1 in DR1 Reg
  FLASHR->DR1  = Xdata1;
  // Set the Write Mode Start bit 'WMS' in the CR0 Reg to Start Write Operation
  FLASHR->CR0 |= FLASH_WMS_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_WriteBlock
* Description    : Writes Data To the Flash
* Input 1        : Address of the Data source
* Input 2        : Address of the Destination
* Input 3        : Nbr of words to be stored
* Return         : None
*******************************************************************************/
void FLASH_BlockWrite(u32 XsourceAdd, u32 XtargetAdd, u32 XdataLength)
{
  u32 TmpAddrS, TmpAddrD;
  u32 NbrW, NbrDW;
  u32 TmpData0, TmpData1;
  // Get The Source Address
  TmpAddrS = XsourceAdd;
  // Get The Destination Address
  TmpAddrD = XtargetAdd;
  // Get Number of Double Words
  NbrDW    = XdataLength >> 1;
  // Get Number of single Words
  NbrW     = XdataLength & 0x00000001;
  // Programming Double Words
  while (NbrDW > 0)
  {
    // Get The First 32 bits
    TmpData0 = *(u32 *)TmpAddrS;
    // Increment The Source Address
    TmpAddrS += 4;
    // Get The Second 32 bits
    TmpData1 = *(u32 *)TmpAddrS;
    // Increment The Source Address
    TmpAddrS += 4;
    // Use The FLASH_DWordWrite function to program the 64 bits
    FLASH_DWordWrite(TmpAddrD, TmpData0, TmpData1);
    // Decrease number of Double word
    NbrDW--;
    // Increment The destination Address
    TmpAddrD += 8;
    // Waits for the data to be programmed
    FLASH_Delay();
  }

  if (NbrW > 0)
  {
    // Get The First 32 bits
    TmpData1 = *(u32 *)TmpAddrS;
    // Use The FLASH_WordWrite function to program the 32 bits
    FLASH_WordWrite(TmpAddrD, TmpData1);
    // Waits for the data to be programmed
    FLASH_Delay();
  }
}

/*******************************************************************************
* Function Name  : FLASH_EraseSector
* Description    : Erases a Flash sector
* Input 1        : Sectors to be Erased
* Return         : None
*******************************************************************************/
void FLASH_SectorErase(u32 Xsectors)
{
  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);

  // Set the Sector Erase flag 'SER' in the FCRO reg
  FLASHR->CR0 |= FLASH_SER_Mask;
  // Select the Sectors to be erased in the CR1 register
  FLASHR->CR1 |= Xsectors;
  // Set the Write Mode Start bit 'WMS' in the CR0 Reg to Start Erase Operation
  FLASHR->CR0 |= FLASH_WMS_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_EraseModule
* Description    : Erases a flash module
* Input          : None
* Return         : None
*******************************************************************************/
void FLASH_ModuleErase(void)
{
  WaitForLastTask(FLASH_BANK0);
  FLASH_BankErase(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);
  FLASH_BankErase(FLASH_BANK1);
  // waits for the end of the write operation on both banks
  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);
}

/*******************************************************************************
* Function Name  : FLASH_Delay
* Description    : Add the delay required for the Flash Write & Erase operation
* Input 1        : None
* Return         : None
*******************************************************************************/
void FLASH_Delay(void)
{
  u8 Xdelay;
  for(Xdelay = 0; Xdelay < 0xFE; Xdelay ++);
}

/*******************************************************************************
* Function Name  : FLASH_Suspend
* Description    : Suspends the current program or erase operation
* Input 1        : None
* Return         : None
*******************************************************************************/
void FLASH_Suspend(void)
{
  // Set The suspend Bit 'SUSP' in the CR0 register
  FLASHR->CR0 |= FLASH_SUSP_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_Resume
* Description    : Resume a Suspended program or erase operation
* Input 1        : None
* Return         : None
*******************************************************************************/
void FLASH_Resume(void)
{
  // Reset The suspend Bit 'SUSP' in the FRC0 register
  FLASHR->CR0 &= ~FLASH_SUSP_Mask;
  // Set write mode bit
  FLASHR->CR0  |= FLASH_WMS_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_ReadWord
* Description    : Read a single word of the flash
* Input 1        : Source Address
* Return         : Word
*******************************************************************************/
u32 FLASH_WordRead(u32 SourceAdd)
{
  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);
  // Waits for the flash to be unlocked
  while((FLASH_FlagStatus(FLASH_LOCK))== SET);
  // Reads the data from the specified Address
  return *(u32 *)(SourceAdd + 0x40000000);
}

/*******************************************************************************
* Function Name  : FLASH_ReadBlock -> Block Read
* Description    : Block Read from the flash
* Input 1        : Destination Address where the Data will be Stored
* Input 2        : Data Source Address
* Input 3        : Nbr of word to be Read
* Return         : Word
*******************************************************************************/
void FLASH_BlockRead(u32 DestAdd, u32 SourceAdd, u32 NbrData)
{
  u32 TmpaddrD,TmpaddrS,TmpNbrData;
  // Number of data to be Read from the Flash
  TmpNbrData = NbrData;
  // Source Address
  TmpaddrS = SourceAdd;
  // Destination Address
  TmpaddrD = DestAdd;

  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);

  while(TmpNbrData > 0)
  {
    *(u32 *)TmpaddrD = FLASH_WordRead(TmpaddrS);
    // Increase the Source Address
    TmpaddrS += 4;
    // Increase the Destination Address
    TmpaddrD += 4;
    // Decrease the Number of data to be read
    TmpNbrData --;
  }
}

/*******************************************************************************
* Function Name  : FLASH_WritePrConfig
* Description    : Configures The Write Protection Bits
* Input 1        : Flash Bank
* Input 2        : Enable Or disable Protection
* Return         : None
*******************************************************************************/
void FLASH_WritePrConfig(u32 Xsectors, FunctionalState NewState)
{
  u32 TmpProtection;

  TmpProtection = FLASHPR->NVWPAR;
  WaitForLastTask(FLASH_BANK0);
  WaitForLastTask(FLASH_BANK1);
  if (NewState == DISABLE) TmpProtection |= Xsectors;
  else TmpProtection &= ~Xsectors;
  // Set the Set protection Bit
  FLASHR->CR0 |= FLASH_SPR_Mask;
  // Set the Register Address
  FLASHR->AR  = 0x4010DFB0;
  // Data To be Programmed to the Protection Register
  FLASHR->DR0  = TmpProtection;
  // Set the WMS bit to Start the Sequence
  FLASHR->CR0 |= FLASH_WMS_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_DebugPrConfig
* Description    : Configures The Debug Protection Bits
* Input 1        : ENABLE or DISABLE
* Return         : Word
*******************************************************************************/
void FLASH_DebugPrConfig(FunctionalState NewState)
{
  u16 TmpPEN, TmpPDS, TmpProtection;
  TmpPEN = (FLASHPR->NVAPR1 & 0xFFFF0000) >> 16;
  TmpPDS = (FLASHPR->NVAPR1 & 0x0000FFFF);

  if (NewState == ENABLE)
  {
    //  If the First Protection Reset the DBGP bit
    if ((FLASHPR->NVAPR0 & 0x2)==0x02) FLASHPR->NVAPR0 &= ~FLASH_DBGP_Mask;
    else FLASHPR->NVAPR1 = ResetBit(FLASHPR->NVAPR1, ProtectionLevel(TmpPEN) + 16);
    //  FLASHPR->NVAPR1 =  TmpPDS |((TmpPEN & ~(1<<ProtectionLevel(TmpPEN)))<< 16);
  }
  else
  {
    //  Test wether the Protection is already Enabled
    if ((FLASHPR->NVAPR0 & 0x2) == 0x0) FLASHPR->NVAPR1 = ResetBit(FLASHPR->NVAPR1, ProtectionLevel(TmpPDS));
    //  FLASHPR->NVAPR1 =(TmpPEN << 16)|(TmpPDS &~(1 << ProtectionLevel(TmpPDS)));
  }
  // Set the Set protection Bit
  FLASHR->CR0 |= FLASH_SPR_Mask;
  // Set the Register Address
  FLASHR->AR  = 0x4010DFB0;
  // Data To be Programmed to the Protection Register
  FLASHR->DR0 = TmpProtection;
  // Set the WMS bit to Start the Sequence
  FLASHR->CR0 |= FLASH_WMS_Mask;
}

/*******************************************************************************
* Function Name  : FLASH_FlagStatus
* Description    : Returns the NewState of Flash flags
* Input 1        : Flash Flag
* Return         : flagstate
*******************************************************************************/
FlagStatus FLASH_FlagStatus(flashflags Xflag)
{
  FlagStatus TmpResult;
  u8 TmpReg, TmpPos;
  // get the Register Index
  TmpReg = (Xflag & FLASH_Reg_Mask) >> 5;
  // get the Flag Index
  TmpPos = (Xflag & FLASH_Flag_Mask);

  switch(TmpReg)
  {
    case 0 : // CR0
    {
      // Returns the status of the CR0[TmpPos] flag
      TmpResult = (FLASHR->CR0 & (1<<TmpPos))==0 ? RESET : SET;
      break;
    }
    case 1 : // CR1
    {
      // Returns the status of the CR1[TmpPos] flag
      TmpResult = (FLASHR->CR1 & (1<<TmpPos))==0 ? RESET : SET;
      break;
    }
    case 5 : // ER
    {
      // Returns the status of the ER[TmpPos] flag
      TmpResult = (FLASHR->ER  & (1<<TmpPos))==0 ? RESET : SET;
      break;
    }
  }
  return(TmpResult);
}

/*******************************************************************************
* Function Name  : FLASH_FlagClear
* Description    : Clears a flash flag
* Input 1        : Flash Flag
* Return         : None
*******************************************************************************/
void FLASH_FlagClear(flashflags Xflag)
{
  u8 TmpReg, TmpPos;
  TmpReg = (Xflag & FLASH_Reg_Mask) >> 5;
  TmpPos = (Xflag & FLASH_Flag_Mask);

  switch(TmpReg)
  {
    case 0 : // CR0
    {
      // Clears the status of the CR0[TmpPos] flag
      FLASHR->CR0 &= ~(1<<TmpPos);
      break;
    }
    case 1 : // CR1
    {
      // Clears the status of the CR1[TmpPos] flag
      FLASHR->CR1 &= ~(1<<TmpPos);
      break;
    }
    case 5 : // ER
    {
      // Clears the status of the ER[TmpPos] flag
      FLASHR->ER &= ~(1<<TmpPos);
      break;
    }
  }
}

/*******************************************************************************
* Function Name  : ProtectionLevel
* Description    : Returns the Index of the Last bit used to Enable / Disable the
*                  Permanent protection.
* Input 1        : None
* Return         : None
*******************************************************************************/
u16 ProtectionLevel(u16 ProtectionRegs)
{
  u16 TmpBitIndex = 0;
  while ((ProtectionRegs & 0x1) == 0 && TmpBitIndex < 16)
  {
    ProtectionRegs>>=1;
    TmpBitIndex++;
  }
  return TmpBitIndex;
}

/*******************************************************************************
* Function Name  : Wait For Last Task
* Description    : Waits for the end of last task on a Flash Bank
* Input 1        : Bank number.
* Return         : The value passed in parameter with the bit (Bitindex) reset
*******************************************************************************/
void WaitForLastTask(flashbanks Xbank)
{
  if (Xbank == FLASH_BANK0) while (FLASH_FlagStatus(FLASH_BSY0) == SET);
  else while (FLASH_FlagStatus(FLASH_BSY1) == SET);
}

/*******************(C)COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产乱码一区二区三区| 肉色丝袜一区二区| 精品午夜久久福利影院| 一本一本大道香蕉久在线精品| 日韩一区二区免费在线电影| 亚洲私人影院在线观看| 国产毛片一区二区| 3d动漫精品啪啪| 亚洲视频 欧洲视频| 国产河南妇女毛片精品久久久| 91精品国产欧美日韩| 最新日韩av在线| 国产精品911| 日韩一区二区三区四区| 亚洲最新在线观看| 成人教育av在线| 亚洲精品一线二线三线无人区| 午夜国产精品影院在线观看| 97精品国产露脸对白| 国产免费观看久久| 精品中文av资源站在线观看| 欧美日本精品一区二区三区| 亚洲手机成人高清视频| 国产成人精品aa毛片| 精品国产伦理网| 日本一道高清亚洲日美韩| 欧美手机在线视频| 亚洲免费电影在线| 99精品久久久久久| 中文乱码免费一区二区| 国产精品夜夜嗨| 久久女同性恋中文字幕| 美女视频黄a大片欧美| 91.xcao| 午夜久久久久久电影| 欧美视频在线不卡| 亚洲一区二区综合| 色噜噜狠狠成人网p站| 亚洲婷婷综合色高清在线| 91丨porny丨首页| 中文字幕第一区二区| 国产成人精品三级| 国产午夜精品美女毛片视频| 福利视频网站一区二区三区| 国产丝袜在线精品| 国产suv一区二区三区88区| 久久精品一区二区三区四区| 国产精品亚洲视频| 中文字幕va一区二区三区| 国产**成人网毛片九色| 国产精品网站在线播放| 成人av片在线观看| 国产麻豆9l精品三级站| 国产农村妇女精品| 不卡大黄网站免费看| 亚洲色图视频网站| 91福利国产精品| 亚洲超丰满肉感bbw| 欧美福利电影网| 国产剧情一区二区三区| 亚洲国产精品嫩草影院| 亚洲综合视频网| 中文幕一区二区三区久久蜜桃| 午夜电影久久久| 欧美三级电影在线观看| 日韩精品欧美精品| 精品国产一区二区三区久久久蜜月 | 国产一区二区中文字幕| 久久久久久久久久久久久夜| 欧美影院精品一区| 国产精品美女久久久久aⅴ | 国产精品视频在线看| 成人综合激情网| 亚洲女同一区二区| 欧美日韩黄色影视| 精品夜夜嗨av一区二区三区| 欧美激情中文字幕一区二区| 91美女蜜桃在线| 亚洲午夜视频在线观看| 精品久久久久久久久久久久久久久久久 | 欧美大尺度电影在线| 国产精品夜夜嗨| 一区av在线播放| 日韩欧美中文字幕公布| 成人免费高清视频| 一区二区成人在线视频| 日韩欧美区一区二| 99视频精品全部免费在线| 性做久久久久久久久| 久久伊99综合婷婷久久伊| 91影院在线免费观看| 日本中文字幕不卡| 欧美极品aⅴ影院| 欧美日韩亚洲综合一区二区三区 | 亚洲少妇最新在线视频| 3d动漫精品啪啪| 成人97人人超碰人人99| 视频一区二区三区在线| 国产欧美日韩三级| 欧美日韩一级片在线观看| 国产一区二区不卡| 亚洲国产精品久久久久秋霞影院| 精品99999| 欧美日韩一区二区不卡| 国产成人亚洲综合a∨婷婷图片| 亚洲午夜影视影院在线观看| 国产三级精品三级| 欧美精品成人一区二区三区四区| 成人三级伦理片| 日本vs亚洲vs韩国一区三区二区| 国产精品国模大尺度视频| 日韩网站在线看片你懂的| 91美女在线看| 国产白丝精品91爽爽久久| 日韩制服丝袜先锋影音| 亚洲欧美精品午睡沙发| 国产视频在线观看一区二区三区| 欧美日韩一区二区三区不卡| 成人av手机在线观看| 精品一二线国产| 首页国产丝袜综合| 亚洲婷婷综合色高清在线| 久久嫩草精品久久久久| 555www色欧美视频| 色噜噜狠狠色综合欧洲selulu| 国产成人综合亚洲91猫咪| 日本欧美加勒比视频| 一级精品视频在线观看宜春院| 国产精品人妖ts系列视频| 欧美成人一区二区三区在线观看| 欧洲国产伦久久久久久久| 成人免费看的视频| 国产乱淫av一区二区三区| 美女脱光内衣内裤视频久久影院| 亚洲午夜免费电影| 国产精品国产三级国产aⅴ中文 | 欧美一区二区三区在线电影| 99国内精品久久| 国产一区二区伦理片| 久久精品国产一区二区三区免费看| 亚洲高清在线视频| 亚洲精品精品亚洲| 亚洲人成在线观看一区二区| 欧美激情一区不卡| 久久久亚洲国产美女国产盗摄 | 欧美四级电影网| 91成人免费网站| 91热门视频在线观看| 成人高清免费在线播放| 国产精品18久久久久久久网站| 激情久久久久久久久久久久久久久久| 午夜一区二区三区在线观看| 亚洲亚洲精品在线观看| 一区二区三区在线不卡| 亚洲精品视频在线观看网站| 中文字幕中文字幕中文字幕亚洲无线| 国产视频一区二区三区在线观看 | 91高清在线观看| 91色在线porny| 91蜜桃网址入口| 色综合天天综合网天天狠天天| 成人网在线免费视频| 成人久久18免费网站麻豆| 国v精品久久久网| 99久久99久久久精品齐齐| av一区二区久久| 色综合久久中文字幕综合网| 91久久一区二区| 欧美日韩精品一区视频| 欧美电影一区二区三区| 日韩一区二区三区在线视频| 精品电影一区二区三区| 国产亚洲一区字幕| 中文字幕日韩欧美一区二区三区| 日韩一区在线免费观看| 亚洲欧美激情一区二区| 偷偷要91色婷婷| 久久av中文字幕片| 国产精品 日产精品 欧美精品| www.亚洲人| 欧美色图免费看| 日韩欧美在线123| 国产日韩v精品一区二区| 成人欧美一区二区三区白人 | 亚洲欧洲日韩av| 亚洲精品视频一区| 午夜激情综合网| 国产在线看一区| aaa亚洲精品一二三区| 在线视频综合导航| 欧美一级片在线观看| 国产日韩欧美精品一区| 亚洲精品视频免费看| 免费观看在线色综合| 成人一区二区在线观看| 欧美在线free| 精品国产免费人成电影在线观看四季| 国产精品九色蝌蚪自拍| 日韩和欧美的一区| 国产超碰在线一区|