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

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

?? flash.c

?? LPC Flash Programming Routines for LPC21
?? C
字號:
/******************************************************************************
 *
 * $RCSfile: $
 * $Revision: $
 *
 * This module provides interface routines to the LPC ARM Flash IAP.
 * Copyright 2004, 2005 R O SoftWare
 * No guarantees, warrantees, or promises, implied or otherwise.
 * May be used for hobby or commercial purposes provided copyright
 * notice remains intact.
 *
 *****************************************************************************/
#include <string.h>
#include "lpc.h"
#include "flash.h"
#include "armISR.h"

#define CCLK          (60000000)        // CPU Clock Speed

#ifndef MIN
#define MIN(n,m)      (((n) < (m)) ? (n) : (m))
#endif

#define IAP_LOCATION  0x7FFFFFF1ul

static int lastSector;
static unsigned long flashParams[5];

/******************************************************************************
 *
 * Function Name: callIAP()
 *
 * Description:
 *    This function loads the address of flashParams[] into r0 & r1
 *    then calls the LPC's IAP (Thumb mode) code.
 *
 * Calling Sequence: 
 *    void
 *
 * Returns:
 *    void
 *
 * NOTES:
 *    - We don't make this an inline function because the call to the
 *    IAP code is made from assembly language therefore the compiler
 *    doesn't realize other registers are possibly being altered.
 *    - pFP is in the source list of the asm so its assignment to the
 *    address of flashParams[] is not optimized away.
 *    - 'lr' is not assigned prior to 'bx' so the IAP code will return
 *    directly to this functions caller
 *
 *****************************************************************************/
static void callIAP(void) __attribute((naked));
static void callIAP(void)
{
  // fast way to get the address of flashParams[] directly into r0
  register void *pFP asm("r0") = flashParams;

  asm volatile(" mov r1, r0\n"          // copy &flashParams[] into r1
               " bx  %[iapLocation]"    // 'bx' because IAP is Thumb mode
               :
               : "r" (pFP), [iapLocation] "r" (IAP_LOCATION)
               : "r1" );
}

/******************************************************************************
 *
 * Function Name: flashBlank()
 *
 * Description:
 *    This function checks if the range of specified sectors is erased.
 *
 * Calling Sequence: 
 *    startSector - first sector to be erased
 *    endSector - last sector to be erased
 *
 * Returns:
 *    0 - success, else error code
 *
 *****************************************************************************/
int flashBlank(int startSector, int endSector)
{
  flashParams[0] = 53;                  // blank check
  flashParams[1] = startSector;         // start sector
  flashParams[2] = endSector;           // end sector
  callIAP();
  return (int)flashParams[0];
}

/******************************************************************************
 *
 * Function Name: flashErase()
 *
 * Description:
 *    This function erases the range of specified sectors
 *
 * Calling Sequence: 
 *    startSector - first sector to be erased
 *    endSector - last sector to be erased
 *
 * Returns:
 *    0 - success, else error code
 *
 *****************************************************************************/
int flashErase(int startSector, int endSector)
{
  unsigned long cpsr;
  unsigned char memmap;

  cpsr = disableINTs();                 // disable all interrupts
  memmap = MEMMAP;                      // get current memory map
  MEMMAP = MEMMAP_FLASH;                // map User Flash into low 64 bytes

  flashParams[0] = 50;                  // prepare sector(s)
  flashParams[1] = startSector;         // start sector
  flashParams[2] = endSector;           // end sector
  callIAP();

  if (flashParams[0] == CMD_SUCCESS)
    {
    flashParams[0] = 52;                // erase sector(s)
    flashParams[1] = startSector;       // start sector
    flashParams[2] = endSector;         // end sector
    flashParams[3] = CCLK/1000;         // cpu clock freq in KHz
    callIAP();
    }

  MEMMAP = memmap & 0x03;               // restore the memory map
  restoreINTs(cpsr);                    // restore all interrupts
  return (int)flashParams[0];
}

/******************************************************************************
 *
 * Function Name: flashWrite()
 *
 * Description:
 *    This function writes byteCount bytes of data from the src location
 *    to the dst location in flash.
 *
 * Calling Sequence: 
 *    *dst - location in flash at which to start writing
 *    *src - location from which to get data (word boundary)
 *    byteCount - number of bytes to write
 *
 * Returns:
 *    0 - success, else error code
 *
 *  NOTE: When programming data into a sector that is already partially
 *  programmed, all new data MUST be programmed into previously
 *  unprogrammed 16-byte (128-bit) blocks.  This requirement is NOT
 *  currently checked or enforced by this routine.  See msgs by Philps
 *  Tech Support in the LPC2100 mailing list on Yahoo for more details.
 *
 *****************************************************************************/
int flashWrite(void *dst, void *src, unsigned byteCount)
{
  unsigned char memmap;
  unsigned long cpsr, count;
  unsigned long buffer[512/sizeof (long)];

  if ((lastSector == 0) &&
      (flashInit() == LPCUNKN))
    return BUSY;

  while (byteCount)
    {
    cpsr = disableINTs();               // disable all interrupts
    memmap = MEMMAP;                    // get current memory map
    MEMMAP = MEMMAP_FLASH;              // map User Flash into low 64 bytes

    // prepare all sectors for programing
    flashParams[0] = 50;                // prepare sectors
    flashParams[1] = 0;                 // start sector
    flashParams[2] = lastSector;        // last sector
    callIAP();

    if (flashParams[0] != CMD_SUCCESS)
      {
      MEMMAP = memmap & 0x03;           // restore the memory map
      restoreINTs(cpsr);                // restore all interrupts
      return flashParams[0];
      }

    // check if dst is on 512 byte boundary
    if ((unsigned long)dst & 0x1FF)
      {
      // no, copy 512 bytes from flash into buffer
      memcpy(buffer, (void *)((unsigned long)dst & ~0x1FF), 512);

      // copy src into buffer
      count = MIN(byteCount, (512 - ((unsigned long)dst & 0x1FF)));
      memcpy((char *)buffer + ((unsigned long)dst & 0x1FF), src, count);

      flashParams[0] = 51;              // copy RAM to Flash
      flashParams[1] = (unsigned long)dst & ~0x1FF; // destination
      flashParams[2] = (unsigned long)buffer; // source
      flashParams[3] = 512;             // byte count
      flashParams[4] = CCLK/1000;       // CCLK in KHz
      callIAP();

      MEMMAP = memmap & 0x03;           // restore the memory map
      restoreINTs(cpsr);                // restore all interrupts

      if (flashParams[0] != CMD_SUCCESS)
        return (int)flashParams[0];

      dst = (char *)dst + count;
      src = (char *)src + count;
      byteCount -= count;
      continue;                         // restart the loop to prepare sectors again
      }

    // dst is now aligned on a 512 byte boundary
    // find the biggest chunk we can program at a time
    if (byteCount >= 8192)
      count = 8192;
    else if (byteCount >= 4096)
      count = 4096;
    else if (byteCount >= 1024)
      count = 1024;
    else if (byteCount >= 512)
      count = 512;
    else
      count = byteCount;

    if (count < 512)
      {
      memcpy(buffer, dst, 512);           // copy current flash contents into buffer
      memcpy(buffer, src, count);          // update buffer with the new contents
      flashParams[2] = (unsigned long)buffer; // source
      flashParams[3] = 512;             // byte count
      }
    else
      {
      flashParams[2] = (unsigned long)src;
      flashParams[3] = count;           // byte count
      }

    flashParams[0] = 51;                // copy RAM to Flash
    flashParams[1] = (unsigned long)dst; // destination
    flashParams[4] = CCLK/1000;         // CCLK in KHz
    callIAP();

    MEMMAP = memmap & 0x03;             // restore the memory map
    restoreINTs(cpsr);                  // restore all interrupts

    if (flashParams[0] != CMD_SUCCESS)
      return (int)flashParams[0];

    dst = (char *)dst + count;
    src = (char *)src + count;
    byteCount -= count;
    }

  return CMD_SUCCESS;
}

/******************************************************************************
 *
 * Function Name: flashInit()
 *
 * Description:
 *    This function tests if the LPC has 128K or 256K of flash and
 *    returns the result.
 *
 * Calling Sequence: 
 *    void
 *
 * Returns:
 *    LPC128K, LPC256K, or LPCUNKN (on error)
 *
 *****************************************************************************/
int flashInit(void)
{
  lastSector = 0;                       // clear last usable sector #

  switch (flashBlank(16, 16))           // check last sector of 256K parts
    {
    case CMD_SUCCESS:
    case SECTOR_NOT_BLANK:
      lastSector = 16;                  // store last usable sector #
      return LPC256K;

    case INVALID_SECTOR:
      break;

    default:
      return LPCUNKN;
    }

  switch (flashBlank(14, 14))           // check last sector of 128K parts
    {
    case CMD_SUCCESS:
    case SECTOR_NOT_BLANK:
      lastSector = 14;                  // store last usable sector #
      return LPC128K;

    default:
      break;
    }

  return LPCUNKN;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人天堂资源www在线| 91免费国产在线观看| 国产a区久久久| 欧美在线免费观看亚洲| 国产亚洲人成网站| 亚洲第一激情av| 成人不卡免费av| 精品国产电影一区二区| 亚洲电影一区二区三区| 国产成人午夜精品5599 | 欧美一区中文字幕| 综合网在线视频| 国产精品影音先锋| 精品欧美乱码久久久久久1区2区| 亚洲免费资源在线播放| 成人性视频网站| 久久欧美中文字幕| 蜜臀av性久久久久蜜臀aⅴ | 韩国av一区二区三区| 欧美老年两性高潮| 亚洲六月丁香色婷婷综合久久| 国产精品影视在线观看| 精品国产伦一区二区三区免费 | 中文字幕的久久| 国产一区二区不卡| 久久这里只有精品视频网| 日韩不卡一二三区| 制服丝袜中文字幕亚洲| 亚洲高清免费一级二级三级| 在线亚洲一区二区| 亚洲精品亚洲人成人网在线播放| 99在线视频精品| 1024成人网色www| 97久久精品人人做人人爽50路 | 精品久久国产97色综合| 日韩高清在线观看| 日韩三级视频在线看| 另类综合日韩欧美亚洲| 精品国产污网站| 国产永久精品大片wwwapp| 久久婷婷色综合| 国产精品主播直播| 中文字幕亚洲一区二区av在线 | 国产欧美一区二区在线| 国产成人免费视频| 欧美国产禁国产网站cc| 93久久精品日日躁夜夜躁欧美| 国产精品网曝门| 91蜜桃免费观看视频| 亚洲最色的网站| 欧美日韩美少妇| 美国三级日本三级久久99| 久久久久成人黄色影片| 成人免费视频app| 亚洲精品视频在线看| 欧美日韩精品一区二区三区蜜桃| 男人的天堂亚洲一区| 国产网站一区二区| 色久综合一二码| 麻豆久久久久久| 欧美国产1区2区| 欧美日韩国产一级二级| 国产一区二区三区在线观看免费| 国产精品的网站| 3751色影院一区二区三区| 国产福利视频一区二区三区| 综合久久久久综合| 欧美一区二区三区啪啪| 成人免费精品视频| 肉色丝袜一区二区| 国产精品乱码妇女bbbb| 欧美放荡的少妇| 成人免费视频免费观看| 午夜精品久久久久久久99樱桃| 精品国产一区二区国模嫣然| 色狠狠一区二区三区香蕉| 激情六月婷婷久久| 亚洲电影你懂得| 国产精品欧美久久久久无广告| 欧美日韩精品是欧美日韩精品| 国产精品1区2区3区在线观看| 亚洲国产成人va在线观看天堂| 国产日韩av一区| 在线91免费看| 色综合久久久久久久| 激情综合色播五月| 亚洲国产精品一区二区久久恐怖片| 久久人人爽人人爽| 欧美电影影音先锋| 99久久精品国产精品久久| 国产一区二区三区精品视频| 亚洲成av人片一区二区三区| 国产精品传媒在线| 久久久777精品电影网影网 | 国产无一区二区| 欧美一区二区精品久久911| 一本久道中文字幕精品亚洲嫩| 国产一区二区福利| 麻豆91精品视频| 日本中文字幕不卡| 午夜精品免费在线| 亚洲午夜久久久久久久久电影院| 国产精品污网站| 国产亚洲1区2区3区| www国产精品av| 欧美大胆一级视频| 日韩女优视频免费观看| 91精品国产麻豆国产自产在线 | 国产精品一级黄| 精品一区二区免费| 免费看欧美美女黄的网站| 亚洲成人精品影院| 亚洲第一搞黄网站| 五月天一区二区| 日韩精品一二三四| 美女视频黄久久| 久久99国内精品| 国产在线精品免费| 国产成人免费视频精品含羞草妖精 | 麻豆精品一二三| 青青草97国产精品免费观看| 人人狠狠综合久久亚洲| 日本不卡视频在线| 久久99热国产| 国产呦精品一区二区三区网站| 国产一区二区三区久久悠悠色av| 国产一区二区三区久久久| 成人性视频免费网站| 91在线国产福利| 欧美视频一区二| 欧美一级黄色片| 久久精品人人做人人综合 | 亚洲精品视频免费看| 亚洲精品欧美综合四区| 亚洲综合在线免费观看| 日本午夜精品一区二区三区电影| 青青草国产精品亚洲专区无| 国产在线视频一区二区| www.亚洲精品| 欧美精品一二三区| 精品va天堂亚洲国产| 中文字幕欧美一| 午夜精品久久久久久久| 国产精品一区在线观看乱码| 99久久精品国产一区| 欧美乱妇15p| 国产亚洲成av人在线观看导航| 国产精品国产馆在线真实露脸 | 欧美亚洲综合一区| 欧美一级黄色大片| 国产精品久久久久久久久果冻传媒 | 九九热在线视频观看这里只有精品| 国产成都精品91一区二区三| 色婷婷香蕉在线一区二区| 日韩三级高清在线| 亚洲图片欧美激情| 精品一区二区三区免费播放 | 国产一区福利在线| 欧美三片在线视频观看| 精品久久国产老人久久综合| 亚洲欧美一区二区三区极速播放| 日日夜夜一区二区| www.在线成人| 精品国产a毛片| 亚洲午夜精品网| 春色校园综合激情亚洲| 在线不卡一区二区| 亚洲欧美怡红院| 韩国精品久久久| 欧美三级视频在线播放| 国产精品麻豆99久久久久久| 蜜桃久久久久久| 在线观看成人免费视频| 国产色91在线| 久久精品国产精品亚洲精品| 欧美日韩在线精品一区二区三区激情 | 在线视频亚洲一区| 国产人伦精品一区二区| 天堂精品中文字幕在线| 一本到高清视频免费精品| 国产女主播视频一区二区| 人人超碰91尤物精品国产| 欧美综合一区二区三区| 国产精品久久久久aaaa| 国产精品主播直播| 久久久天堂av| 加勒比av一区二区| 日韩欧美一区二区视频| 午夜伊人狠狠久久| 欧美三日本三级三级在线播放| 日韩美女精品在线| 99久久99久久精品免费观看| 国产日韩欧美高清| 国产一区二区电影| 久久综合999| 国产伦精品一区二区三区视频青涩| 欧美白人最猛性xxxxx69交| 青草av.久久免费一区| 欧美一区二区三区思思人| 青青草97国产精品免费观看 |