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 "nrf24lu1p.h" 00019 #include "hal_flash.h" 00020 00021 void hal_flash_page_erase(uint8_t pn) 00022 { 00023 uint8_t ckcon_val; 00024 00025 //Backup CKCON value and force CKCON to 0x01. nRF24LU1p PAN 011 #2 00026 ckcon_val = CKCON; 00027 CKCON = 0x01; 00028 // Save interrupt enable state and disable interrupts: 00029 F0 = EA; 00030 EA = 0; 00031 // Enable flash write operation: 00032 FCR = 0xAA; 00033 FCR = 0x55; 00034 WEN = 1; 00035 // 00036 // Write the page address to FCR to start the page erase operation. This 00037 // operation is "self timed" when executing from the flash; the CPU will 00038 // halt until the operation is finished: 00039 FCR = pn; 00040 // 00041 // When running from XDATA RAM we need to wait for the operation to finish: 00042 while(RDYN == 1) 00043 ; 00044 WEN = 0; 00045 EA = F0; // Restore interrupt enable state 00046 CKCON = ckcon_val; //Restore CKCON state 00047 } 00048 00049 void hal_flash_byte_write(uint16_t a, uint8_t b) 00050 { 00051 uint8_t xdata * pb; 00052 uint8_t ckcon_val; 00053 00054 //Backup CKCON value and force CKCON to 0x01. nRF24LU1p PAN 011 #2 00055 ckcon_val = CKCON; 00056 CKCON = 0x01; 00057 // Save interrupt enable state and disable interrupts: 00058 F0 = EA; 00059 EA = 0; 00060 // Enable flash write operation: 00061 FCR = 0xAA; 00062 FCR = 0x55; 00063 WEN = 1; 00064 // 00065 // Write the byte directly to the flash. This operation is "self timed" when 00066 // executing from the flash; the CPU will halt until the operation is 00067 // finished: 00068 pb = (uint8_t xdata *)a; 00069 *pb = b; 00070 // 00071 // When running from XDATA RAM we need to wait for the operation to finish: 00072 while(RDYN == 1) 00073 ; 00074 WEN = 0; 00075 EA = F0; // Restore interrupt enable state 00076 CKCON = ckcon_val; //Restore CKCON state 00077 } 00078 00079 void hal_flash_bytes_write(uint16_t a, const uint8_t *p, uint16_t n) 00080 { 00081 uint8_t xdata * pb; 00082 uint8_t ckcon_val; 00083 00084 //Backup CKCON value and force CKCON to 0x01. nRF24LU1p PAN 011 #2 00085 ckcon_val = CKCON; 00086 CKCON = 0x01; 00087 // Save interrupt enable state and disable interrupts: 00088 F0 = EA; 00089 EA = 0; 00090 // Enable flash write operation: 00091 FCR = 0xAA; 00092 FCR = 0x55; 00093 WEN = 1; 00094 // 00095 // Write the bytes directly to the flash. This operation is 00096 // "self timed"; the CPU will halt until the operation is 00097 // finished: 00098 pb = (uint8_t xdata *)a; 00099 while(n--) 00100 { 00101 //lint --e{613} Suppress possible use of null pointer warning: 00102 *pb++ = *p++; 00103 // 00104 // When running from XDATA RAM we need to wait for the operation to 00105 // finish: 00106 while(RDYN == 1) {} 00107 } 00108 WEN = 0; 00109 EA = F0; // Restore interrupt enable state 00110 CKCON = ckcon_val; //Restore CKCON state 00111 } 00112 00113 uint8_t hal_flash_byte_read(uint16_t a) 00114 { 00115 //lint --e{613} Suppress possible use of null pointer warning: 00116 uint8_t xdata *pb = (uint8_t xdata *)a; 00117 return *pb; 00118 } 00119 00120 void hal_flash_bytes_read(uint16_t a, uint8_t *p, uint16_t n) 00121 { 00122 uint8_t xdata *pb = (uint8_t xdata *)a; 00123 while(n--) 00124 { 00125 //lint --e{613} Suppress possible use of null pointer warning: 00126 *p = *pb; 00127 pb++; 00128 p++; 00129 } 00130 }