flash.c

来自「非常全的nrf2401设计资料」· C语言 代码 · 共 78 行

C
78
字号
/* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 * $LastChangedRevision: 2290 $
 */

/** @file
 * Flash (self) programming functions
 *
 * @author Ole Saether
 *
 */
#include <Nordic\reg24lu1.h>
#include "flash.h"
#include "config.h"

#ifdef USE_USERCLASS
#pragma userclass (code = BOOTLOADER)
#pragma userclass (const = BOOTLOADER)
#endif

void flash_page_erase(uint8_t pn)
{  
    // Enable flash write operation:
    FCR = 0xAA;
    FCR = 0x55;
    WEN = 1;
    //
    // Write the page address to FCR to start the page erase
    // operation:
    FCR = pn;
    //
    // Wait for the erase operation to finish:
    while(RDYN == 1)
        ;
    WEN = 0;
}

void flash_bytes_write(uint16_t a, uint8_t xdata *p, uint16_t n)
{
    uint8_t xdata *data pb;

    // Enable flash write operation:
    FCR = 0xAA;
    FCR = 0x55;
    WEN = 1;
    //
    // Write the bytes directly to the flash:
    pb = (uint8_t xdata *)a;
    while(n--)
    {
        *pb++ = *p++;
        //
        // Wait for the write operation to finish:
        while(RDYN == 1)
            ;
    }
    WEN = 0;
}

void flash_bytes_read(uint16_t a, uint8_t xdata *p, uint16_t n)
{
    uint8_t xdata *pb = (uint8_t xdata *)a;
    while(n--)
    {
        *p = *pb;
        pb++;
        p++;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?