• Main Page
  • Modules
  • Index
  • File List
  • Globals

projects/nrfgo_sdk/bootloader_32k/firmware/flash.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic 
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail 
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *              
00011  * $LastChangedRevision: 133 $
00012  */
00013 
00018 #include <Nordic\reg24lu1.h>
00019 #include "flash.h"
00020 
00021 // Place all code and constants in this file in the segment "BOOTLOADER":
00022 #pragma userclass (code = BOOTLOADER)
00023 #pragma userclass (const = BOOTLOADER)
00024 
00025 void flash_page_erase(uint8_t pn)
00026 {  
00027     CKCON = 0x01;   // See nRF24LU1p AX PAN
00028     // Enable flash write operation:
00029     FCR = 0xAA;
00030     FCR = 0x55;
00031     WEN = 1;
00032     //
00033     // Write the page address to FCR to start the page erase
00034     // operation:
00035     FCR = pn;
00036     //
00037     // Wait for the erase operation to finish:
00038     while(RDYN == 1)
00039         ;
00040     WEN = 0;
00041     CKCON = 0x02;
00042 }
00043 
00044 void flash_bytes_write(uint16_t a, uint8_t xdata *p, uint16_t n)
00045 {
00046     uint8_t xdata *data pb;
00047 
00048     CKCON = 0x01;
00049     // Enable flash write operation:
00050     FCR = 0xAA;
00051     FCR = 0x55;
00052     WEN = 1;
00053     //
00054     // Write the bytes directly to the flash:
00055     pb = (uint8_t xdata *)a;
00056     while(n--)
00057     {
00058         *pb++ = *p++;
00059         //
00060         // Wait for the write operation to finish:
00061         while(RDYN == 1)
00062             ;
00063     }
00064     WEN = 0;
00065     CKCON = 0x02;
00066 }
00067 
00068 void flash_byte_write(uint16_t a, uint8_t b)
00069 {
00070     uint8_t xdata *data pb;
00071     
00072     CKCON = 0x01;
00073     // Enable flash write operation:
00074     FCR = 0xAA;
00075     FCR = 0x55;
00076     WEN = 1;
00077     //
00078     // Write the byte directly to the flash. This operation is "self timed" when
00079     // executing from the flash; the CPU will halt until the operation is
00080     // finished:
00081     pb = (uint8_t xdata *)a;
00082     *pb = b;
00083     //
00084     // When running from XDATA RAM we need to wait for the operation to finish:
00085     while(RDYN == 1)
00086         ;
00087     WEN = 0;
00088     CKCON = 0x02;
00089 }
00090 
00091 void flash_bytes_read(uint16_t a, uint8_t xdata *p, uint16_t n)
00092 {
00093     uint8_t xdata *pb = (uint8_t xdata *)a;
00094     while(n--)
00095     {
00096         *p = *pb;
00097         pb++;
00098         p++;
00099     }
00100 }

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2