drivers/ecos_lpc2138_sja1000/nvram_iap.h
changeset 3 d9cf34cd6823
equal deleted inserted replaced
2:8d4a822f95e4 3:d9cf34cd6823
       
     1 /*
       
     2 This file is part of CanFestival, a library implementing CanOpen Stack.
       
     3                    canfestival@canopencanada.ca
       
     4 
       
     5 See COPYING file for copyrights details.
       
     6 
       
     7 This library is free software; you can redistribute it and/or
       
     8 modify it under the terms of the GNU Lesser General Public
       
     9 License as published by the Free Software Foundation; either
       
    10 version 2.1 of the License, or (at your option) any later version.
       
    11 
       
    12 This library is distributed in the hope that it will be useful,
       
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15 Lesser General Public License for more details.
       
    16 
       
    17 You should have received a copy of the GNU Lesser General Public
       
    18 License along with this library; if not, write to the Free Software
       
    19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    20 */
       
    21 
       
    22 /************************************************************************/
       
    23 /*                                                                    	*/
       
    24 /*	LPC2k_ee.H:  Header file enabling EEPROM support		*/
       
    25 /* 	for Philips LPC2000 microcontroller's on-chip Flash memory	*/
       
    26 /*     	(revision 1.0, May 13th, 2005.)					*/
       
    27 /*                                                             		*/
       
    28 /*	This file is to be used with LPC2k_ee.c	file 		  	*/
       
    29 /*                                                                     	*/
       
    30 /* IMPORTANT: on-chip Flash memory sector(s) intended to be used as 	*/
       
    31 /* an EEPROM will be unavailable for regular code storage! The smallest	*/
       
    32 /* amount of Flash memory that can be used as an EEPROM is a single 	*/
       
    33 /* Flash sector (regardless of the Flash sector actual size). 		*/
       
    34 /*                                                                     	*/
       
    35 /* If size of desired EEPROM requires several Flash sectors, these	*/
       
    36 /* sectors must be a consecutive ones.					*/
       
    37 /*                                                                     	*/
       
    38 /************************************************************************/
       
    39 
       
    40 #define EE_SEC_L		1		//Flash sector where EEPROM begins (see UM for details)
       
    41 #define EE_SEC_H		3	  	//Flash sector where EEPROM ends (see UM for details)
       
    42 #define EE_ADDR_L		0x00001000	//Must match the EE_SEC_L Flash sector start address
       
    43 #define EE_ADDR_H		0x00003FFF 	//Must match the EE_SEC_H Flash sector end address
       
    44 #define EE_CCLK			60000		//system clock cclk expressed in kHz (5*12 MHz)
       
    45 
       
    46 /************************************************************************/
       
    47 /*                                                                    	*/
       
    48 /* ee_data structure can be defined differently from this example.	*/
       
    49 /* The only requirement is to have _id field as it is defined here	*/
       
    50 /* since EE_REC_ID character is used to identify a record's presence	*/
       
    51 /* in the EEPROM memory.						*/
       
    52 /*                                                                     	*/
       
    53 /* ====================================================================	*/
       
    54 /*                                                                     	*/
       
    55 /* IMPORTANT ARM memory access considerations:				*/
       
    56 /*                                                                     	*/
       
    57 /* char	: byte alligned. Can be accessed at any location in memory.	*/
       
    58 /*                                                                     	*/
       
    59 /* short int: occupies 2 consecutive bytes. It can be read/write 	*/
       
    60 /*	  accessed only when half-word alligned. Therefore, it is	*/
       
    61 /* 	  located at addresses ending with 0x0, 0x2, 0x4, 0x6, 0x8,	*/
       
    62 /*	  0xA, 0xC or 0xE.						*/
       
    63 /*                                                                     	*/
       
    64 /* int	: occupies 4 consecutive bytes.	It can be read/write 		*/
       
    65 /*	  accessed only when half-word alligned. Therefore, it is	*/
       
    66 /* 	  located at addresses ending with 0x0, 0x4, 0x8 or 0xC.	*/
       
    67 /*                                                                     	*/
       
    68 /* ====================================================================	*/
       
    69 /*                                                                     	*/
       
    70 /* Due to the LPC2000 Flash memory characteristics, an ee_data 		*/
       
    71 /* structure size (EE_REC_SIZE) is limited to the following set:	*/
       
    72 /*                                                                     	*/
       
    73 /* LPC2101/2/3, LPC2131/2/4/6/8, LPC2141/2/4/6/8: 0x10, 0x20, 0x40,     */ 
       
    74 /*                                                0x80 or 0x100         */
       
    75 /*                                                                     	*/
       
    76 /* LPC2104/5/6, LPC2112/4/9, LPC2124/9, LPC2192/4: 0x10, 0x20, 0x40,    */
       
    77 /*                                                 0x80, 0x100 or 0x200 */
       
    78 /*                                                                     	*/
       
    79 /* ====================================================================	*/
       
    80 /*                                                                     	*/
       
    81 /* example1:                                                          	*/
       
    82 /*                                                                     	*/
       
    83 /* struct ee_data{		//structure starts as word alligned	*/
       
    84 /*	unsigned char	_id;	//1 byte  - no allignement restr.	*/
       
    85 /*                                  // 	    3 BYTE GAP!!!!         	*/		
       
    86 /*	unsigned int	_rec_count; //4 bytes - must be word alligned!	*/
       
    87 /*	unsigned char	_cs;	//1 byte  - no allignement restr.	*/
       
    88 /*};				// next structure will start as		*/
       
    89 /*                                  // word alligned...                 */
       
    90 /* Structure in example 1 occupies 12 bytes of memory			*/
       
    91 /*                                                                     	*/
       
    92 /* --------------------------------------------------------------------	*/
       
    93 /*                                                                     	*/
       
    94 /* example2:                                                          	*/
       
    95 /*                                                                     	*/
       
    96 /* struct ee_data{		//structure starts as word alligned	*/
       
    97 /*	unsigned char	_id;	//1 byte  - no allignement restr.	*/
       
    98 /*	unsigned char	_cs;	//1 byte  - no allignement restr.	*/
       
    99 /*                              //  	    2 BYTE GAP!!!!         	*/		
       
   100 /*	unsigned int	_rec_count; //4 bytes - must be word alligned!	*/
       
   101 /*};				// next structure will start as		*/
       
   102 /*                                  // word alligned...                 */
       
   103 /* Structure in example 2 occupies 8 bytes of memory			*/
       
   104 /*                                                                     	*/
       
   105 /************************************************************************/
       
   106 
       
   107 struct ee_data{
       
   108 	unsigned char	_id;		//  4 bytes: 1 byte (char) + 3 byte GAP!
       
   109 	unsigned int	_rec_count;	//  4 bytes (int)
       
   110 	unsigned int	_counter;	//  4 bytes (int)
       
   111 	unsigned char	_cs;		//  4 bytes: 1 byte (char) + 3 byte GAP!
       
   112 };					// 16 bytes total
       
   113 
       
   114 /************************************************************************/
       
   115 /*									*/
       
   116 /* 	Disclaimer: all observations presented in example1, example 2 and */
       
   117 /*	ee_data structure defined here are based on Keil's ARM compiler. */
       
   118 /*	If another compiler is used, memory usage would have to be 	*/
       
   119 /*	re-examined and verified.					*/
       
   120 /*									*/
       
   121 /************************************************************************/
       
   122 
       
   123 
       
   124 #define EE_REC_SIZE		0x10	//see restrictions from above
       
   125 
       
   126 /********************************************************************/
       
   127 /*									*/
       
   128 /* 	Valid combinations for 						*/
       
   129 /* EE_REC_SIZE, EE_BUFFER_SIZE, EE_BUFFER_MASK and EE_START_MASK	*/
       
   130 /*									*/
       
   131 /* EE_BUFFER_SIZE ! EE_START_MASK ! EE_REC_SIZE ! EE_BUFFER_MASK	*/
       
   132 /* ----------------------------------------------------------------	*/
       
   133 /*    	256	0xFFFFFF00		0x010	  	0xF0		*/
       
   134 /*	256	0xFFFFFF00		0x020	 	0xE0		*/
       
   135 /*    	256	0xFFFFFF00		0x040	  	0xC0		*/
       
   136 /*	256	0xFFFFFF00		0x080	 	0x80		*/
       
   137 /*	256	0xFFFFFF00		0x100		0x00		*/
       
   138 /* ---------------------------------------------------------------- */
       
   139 /*    	512	0xFFFFFE00		0x010	  	0x1F0		*/
       
   140 /*	512	0xFFFFFE00		0x020	 	0x1E0		*/
       
   141 /*    	512	0xFFFFFE00		0x040	  	0x1C0		*/
       
   142 /*	512	0xFFFFFE00		0x080		0x180	 	*/
       
   143 /*	512	0xFFFFFE00		0x100	 	0x100		*/
       
   144 /*	512	0xFFFFFE00		0x200	 	0x000		*/
       
   145 /********************************************************************/
       
   146 /*	For LPC2101/2/3, LPC213x and LPC214x EE_BUFFER_SIZE is 256. */
       
   147 /*	For all other LPC2000 devices EE_BUFFER_SIZE is always 512. */
       
   148 /********************************************************************/
       
   149 #define EE_BUFFER_SIZE	256
       
   150 #define EE_START_MASK	0xFFFFFF00
       
   151 #define EE_BUFFER_MASK	0x000000F0
       
   152 
       
   153 /********************************************************************/
       
   154 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
       
   155 /*!!								  !!*/
       
   156 /*!!								  !!*/
       
   157 /*!! 	DO NOT MODIFY THE FOLLOWING CODE!!!			  !!*/
       
   158 /*!!	===================================			  !!*/
       
   159 /*!!								  !!*/
       
   160 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
       
   161 /********************************************************************/
       
   162 
       
   163 #define EE_REC_ID 				0xAA
       
   164 #define EE_SIZE					(EE_ADDR_H+1-EE_ADDR_L)
       
   165 #define NO_RECORDS_AVAILABLE	500
       
   166 #define NO_SPACE_IN_EEPROM		501
       
   167 #define INDEX_OUT_OF_RANGE		502
       
   168 
       
   169 #ifndef _EEPROM_
       
   170 	extern const unsigned char eeprom[];
       
   171 	extern void ee_erase(unsigned int , unsigned int []);	//function erases EEPROM
       
   172 	extern void ee_write(unsigned int , unsigned int []);	//function adds a record in EEPROM
       
   173 	extern void ee_read (unsigned int , unsigned int []);	//function reads the latest valid record in EEPROM
       
   174 	extern void ee_readn(unsigned int , unsigned int []);	//function reads n-th record in EEPROM
       
   175 	extern void ee_count(unsigned int , unsigned int []);	//function counts records in EEPROM
       
   176 #endif