oremeq@3: /* oremeq@3: This file is part of CanFestival, a library implementing CanOpen Stack. oremeq@3: canfestival@canopencanada.ca oremeq@3: oremeq@3: See COPYING file for copyrights details. oremeq@3: oremeq@3: This library is free software; you can redistribute it and/or oremeq@3: modify it under the terms of the GNU Lesser General Public oremeq@3: License as published by the Free Software Foundation; either oremeq@3: version 2.1 of the License, or (at your option) any later version. oremeq@3: oremeq@3: This library is distributed in the hope that it will be useful, oremeq@3: but WITHOUT ANY WARRANTY; without even the implied warranty of oremeq@3: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU oremeq@3: Lesser General Public License for more details. oremeq@3: oremeq@3: You should have received a copy of the GNU Lesser General Public oremeq@3: License along with this library; if not, write to the Free Software oremeq@3: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA oremeq@3: */ oremeq@3: oremeq@3: /************************************************************************/ oremeq@3: /* */ oremeq@3: /* LPC2k_ee.H: Header file enabling EEPROM support */ oremeq@3: /* for Philips LPC2000 microcontroller's on-chip Flash memory */ oremeq@3: /* (revision 1.0, May 13th, 2005.) */ oremeq@3: /* */ oremeq@3: /* This file is to be used with LPC2k_ee.c file */ oremeq@3: /* */ oremeq@3: /* IMPORTANT: on-chip Flash memory sector(s) intended to be used as */ oremeq@3: /* an EEPROM will be unavailable for regular code storage! The smallest */ oremeq@3: /* amount of Flash memory that can be used as an EEPROM is a single */ oremeq@3: /* Flash sector (regardless of the Flash sector actual size). */ oremeq@3: /* */ oremeq@3: /* If size of desired EEPROM requires several Flash sectors, these */ oremeq@3: /* sectors must be a consecutive ones. */ oremeq@3: /* */ oremeq@3: /************************************************************************/ oremeq@3: oremeq@3: #define EE_SEC_L 1 //Flash sector where EEPROM begins (see UM for details) oremeq@3: #define EE_SEC_H 3 //Flash sector where EEPROM ends (see UM for details) oremeq@3: #define EE_ADDR_L 0x00001000 //Must match the EE_SEC_L Flash sector start address oremeq@3: #define EE_ADDR_H 0x00003FFF //Must match the EE_SEC_H Flash sector end address oremeq@3: #define EE_CCLK 60000 //system clock cclk expressed in kHz (5*12 MHz) oremeq@3: oremeq@3: /************************************************************************/ oremeq@3: /* */ oremeq@3: /* ee_data structure can be defined differently from this example. */ oremeq@3: /* The only requirement is to have _id field as it is defined here */ oremeq@3: /* since EE_REC_ID character is used to identify a record's presence */ oremeq@3: /* in the EEPROM memory. */ oremeq@3: /* */ oremeq@3: /* ==================================================================== */ oremeq@3: /* */ oremeq@3: /* IMPORTANT ARM memory access considerations: */ oremeq@3: /* */ oremeq@3: /* char : byte alligned. Can be accessed at any location in memory. */ oremeq@3: /* */ oremeq@3: /* short int: occupies 2 consecutive bytes. It can be read/write */ oremeq@3: /* accessed only when half-word alligned. Therefore, it is */ oremeq@3: /* located at addresses ending with 0x0, 0x2, 0x4, 0x6, 0x8, */ oremeq@3: /* 0xA, 0xC or 0xE. */ oremeq@3: /* */ oremeq@3: /* int : occupies 4 consecutive bytes. It can be read/write */ oremeq@3: /* accessed only when half-word alligned. Therefore, it is */ oremeq@3: /* located at addresses ending with 0x0, 0x4, 0x8 or 0xC. */ oremeq@3: /* */ oremeq@3: /* ==================================================================== */ oremeq@3: /* */ oremeq@3: /* Due to the LPC2000 Flash memory characteristics, an ee_data */ oremeq@3: /* structure size (EE_REC_SIZE) is limited to the following set: */ oremeq@3: /* */ oremeq@3: /* LPC2101/2/3, LPC2131/2/4/6/8, LPC2141/2/4/6/8: 0x10, 0x20, 0x40, */ oremeq@3: /* 0x80 or 0x100 */ oremeq@3: /* */ oremeq@3: /* LPC2104/5/6, LPC2112/4/9, LPC2124/9, LPC2192/4: 0x10, 0x20, 0x40, */ oremeq@3: /* 0x80, 0x100 or 0x200 */ oremeq@3: /* */ oremeq@3: /* ==================================================================== */ oremeq@3: /* */ oremeq@3: /* example1: */ oremeq@3: /* */ oremeq@3: /* struct ee_data{ //structure starts as word alligned */ oremeq@3: /* unsigned char _id; //1 byte - no allignement restr. */ oremeq@3: /* // 3 BYTE GAP!!!! */ oremeq@3: /* unsigned int _rec_count; //4 bytes - must be word alligned! */ oremeq@3: /* unsigned char _cs; //1 byte - no allignement restr. */ oremeq@3: /*}; // next structure will start as */ oremeq@3: /* // word alligned... */ oremeq@3: /* Structure in example 1 occupies 12 bytes of memory */ oremeq@3: /* */ oremeq@3: /* -------------------------------------------------------------------- */ oremeq@3: /* */ oremeq@3: /* example2: */ oremeq@3: /* */ oremeq@3: /* struct ee_data{ //structure starts as word alligned */ oremeq@3: /* unsigned char _id; //1 byte - no allignement restr. */ oremeq@3: /* unsigned char _cs; //1 byte - no allignement restr. */ oremeq@3: /* // 2 BYTE GAP!!!! */ oremeq@3: /* unsigned int _rec_count; //4 bytes - must be word alligned! */ oremeq@3: /*}; // next structure will start as */ oremeq@3: /* // word alligned... */ oremeq@3: /* Structure in example 2 occupies 8 bytes of memory */ oremeq@3: /* */ oremeq@3: /************************************************************************/ oremeq@3: oremeq@3: struct ee_data{ oremeq@3: unsigned char _id; // 4 bytes: 1 byte (char) + 3 byte GAP! oremeq@3: unsigned int _rec_count; // 4 bytes (int) oremeq@3: unsigned int _counter; // 4 bytes (int) oremeq@3: unsigned char _cs; // 4 bytes: 1 byte (char) + 3 byte GAP! oremeq@3: }; // 16 bytes total oremeq@3: oremeq@3: /************************************************************************/ oremeq@3: /* */ oremeq@3: /* Disclaimer: all observations presented in example1, example 2 and */ oremeq@3: /* ee_data structure defined here are based on Keil's ARM compiler. */ oremeq@3: /* If another compiler is used, memory usage would have to be */ oremeq@3: /* re-examined and verified. */ oremeq@3: /* */ oremeq@3: /************************************************************************/ oremeq@3: oremeq@3: oremeq@3: #define EE_REC_SIZE 0x10 //see restrictions from above oremeq@3: oremeq@3: /********************************************************************/ oremeq@3: /* */ oremeq@3: /* Valid combinations for */ oremeq@3: /* EE_REC_SIZE, EE_BUFFER_SIZE, EE_BUFFER_MASK and EE_START_MASK */ oremeq@3: /* */ oremeq@3: /* EE_BUFFER_SIZE ! EE_START_MASK ! EE_REC_SIZE ! EE_BUFFER_MASK */ oremeq@3: /* ---------------------------------------------------------------- */ oremeq@3: /* 256 0xFFFFFF00 0x010 0xF0 */ oremeq@3: /* 256 0xFFFFFF00 0x020 0xE0 */ oremeq@3: /* 256 0xFFFFFF00 0x040 0xC0 */ oremeq@3: /* 256 0xFFFFFF00 0x080 0x80 */ oremeq@3: /* 256 0xFFFFFF00 0x100 0x00 */ oremeq@3: /* ---------------------------------------------------------------- */ oremeq@3: /* 512 0xFFFFFE00 0x010 0x1F0 */ oremeq@3: /* 512 0xFFFFFE00 0x020 0x1E0 */ oremeq@3: /* 512 0xFFFFFE00 0x040 0x1C0 */ oremeq@3: /* 512 0xFFFFFE00 0x080 0x180 */ oremeq@3: /* 512 0xFFFFFE00 0x100 0x100 */ oremeq@3: /* 512 0xFFFFFE00 0x200 0x000 */ oremeq@3: /********************************************************************/ oremeq@3: /* For LPC2101/2/3, LPC213x and LPC214x EE_BUFFER_SIZE is 256. */ oremeq@3: /* For all other LPC2000 devices EE_BUFFER_SIZE is always 512. */ oremeq@3: /********************************************************************/ oremeq@3: #define EE_BUFFER_SIZE 256 oremeq@3: #define EE_START_MASK 0xFFFFFF00 oremeq@3: #define EE_BUFFER_MASK 0x000000F0 oremeq@3: oremeq@3: /********************************************************************/ oremeq@3: /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ oremeq@3: /*!! !!*/ oremeq@3: /*!! !!*/ oremeq@3: /*!! DO NOT MODIFY THE FOLLOWING CODE!!! !!*/ oremeq@3: /*!! =================================== !!*/ oremeq@3: /*!! !!*/ oremeq@3: /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ oremeq@3: /********************************************************************/ oremeq@3: oremeq@3: #define EE_REC_ID 0xAA oremeq@3: #define EE_SIZE (EE_ADDR_H+1-EE_ADDR_L) oremeq@3: #define NO_RECORDS_AVAILABLE 500 oremeq@3: #define NO_SPACE_IN_EEPROM 501 oremeq@3: #define INDEX_OUT_OF_RANGE 502 oremeq@3: oremeq@3: #ifndef _EEPROM_ oremeq@3: extern const unsigned char eeprom[]; oremeq@3: extern void ee_erase(unsigned int , unsigned int []); //function erases EEPROM oremeq@3: extern void ee_write(unsigned int , unsigned int []); //function adds a record in EEPROM oremeq@3: extern void ee_read (unsigned int , unsigned int []); //function reads the latest valid record in EEPROM oremeq@3: extern void ee_readn(unsigned int , unsigned int []); //function reads n-th record in EEPROM oremeq@3: extern void ee_count(unsigned int , unsigned int []); //function counts records in EEPROM oremeq@3: #endif