Functions

projects/nrfgo_sdk/bootloader_32k/firmware/flash.c File Reference

#include <Nordic\reg24lu1.h>
#include "flash.h"

Go to the source code of this file.

Functions

void flash_page_erase (uint8_t pn)
void flash_bytes_write (uint16_t a, uint8_t xdata *p, uint16_t n)
void flash_byte_write (uint16_t a, uint8_t b)
void flash_bytes_read (uint16_t a, uint8_t xdata *p, uint16_t n)

Detailed Description

Flash (self) programming functions

Definition in file flash.c.


Function Documentation

void flash_page_erase ( uint8_t  pn )

Function to erase a page in the Flash memory

Parameters:
pnPage number

Definition at line 25 of file flash.c.

{  
    CKCON = 0x01;   // See nRF24LU1p AX PAN
    // 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;
    CKCON = 0x02;
}
void flash_bytes_write ( uint16_t  a,
uint8_t xdata *  p,
uint16_t  n 
)

Function to write n bytes to the Flash memory

Parameters:
a16 bit address in Flash
*ppointer to bytes to write
nnumber of bytes to write

Definition at line 44 of file flash.c.

{
    uint8_t xdata *data pb;

    CKCON = 0x01;
    // 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;
    CKCON = 0x02;
}
void flash_byte_write ( uint16_t  a,
uint8_t  b 
)

Function to write a byte to the Flash memory

Parameters:
a16 bit address in Flash
bbyte to write

Definition at line 68 of file flash.c.

{
    uint8_t xdata *data pb;
    
    CKCON = 0x01;
    // Enable flash write operation:
    FCR = 0xAA;
    FCR = 0x55;
    WEN = 1;
    //
    // Write the byte directly to the flash. This operation is "self timed" when
    // executing from the flash; the CPU will halt until the operation is
    // finished:
    pb = (uint8_t xdata *)a;
    *pb = b;
    //
    // When running from XDATA RAM we need to wait for the operation to finish:
    while(RDYN == 1)
        ;
    WEN = 0;
    CKCON = 0x02;
}
void flash_bytes_read ( uint16_t  a,
uint8_t xdata *  p,
uint16_t  n 
)

Function to read n bytes from the Flash memory

Parameters:
a16 bit address in Flash
*ppointer to bytes to write
nnumber of bytes to read

Definition at line 91 of file flash.c.

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