drivers/ecos_lpc2138_sja1000/nvram_iap.c
author lbessard
Wed, 10 Jan 2007 17:42:34 +0100
changeset 64 c72dd78e547f
parent 18 2fc8aa46980b
permissions -rw-r--r--
Bug reported by Dean corrected
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     1
/*
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     2
                   canfestival@canopencanada.ca
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     4
See COPYING file for copyrights details.
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     5
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     6
This library is free software; you can redistribute it and/or
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     7
modify it under the terms of the GNU Lesser General Public
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     8
License as published by the Free Software Foundation; either
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
     9
version 2.1 of the License, or (at your option) any later version.
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    10
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    11
This library is distributed in the hope that it will be useful,
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    12
but WITHOUT ANY WARRANTY; without even the implied warranty of
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    14
Lesser General Public License for more details.
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    15
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    16
You should have received a copy of the GNU Lesser General Public
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    17
License along with this library; if not, write to the Free Software
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    19
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    20
flash.c
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    21
	save to / retrieve from  the non-volatile memory
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    22
	to be tested
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    23
	- can we write/read into an address without working with the whole page (256bytes)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    24
*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    25
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    26
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    27
#include <stdio.h>
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    28
#include <stdlib.h>
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    29
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    30
#include "applicfg.h"
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    31
#include "data.h"
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    32
#include "objdictdef.h"
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    33
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    34
#include "lpc2138_defs.h"                    /* LPC21xx definitions */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    35
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    36
#define IAP_LOCATION 			0x7ffffff1
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    37
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    38
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    39
// define a page of data of NVRAM_BLOCK_SIZE bytes
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    40
//
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    41
short data_len; /* 0 to NVRAM_BLOCK_SIZE bytes */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    42
short data_num_pages;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    43
unsigned int *data_page = NULL;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    44
unsigned int data_addr;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    45
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    46
unsigned int *regs_page = NULL;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    47
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    48
// local definitons
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    49
void ee_erase(unsigned int ,unsigned int[]);		//function erases EEPROM
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    50
void ee_write_page(unsigned int);	//function adds a record in EEPROM
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    51
void ee_read_page(unsigned int);	//function reads the latest valid record in EEPROM
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    52
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    53
typedef void (*IAP)(unsigned int [],unsigned int[]);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    54
IAP iap_entry;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    55
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
    56
18
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    57
int iat_init()
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    58
{
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    59
	int n = NVRAM_BLOCK_SIZE / sizeof(unsigned int);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    60
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    61
	/* some actions to initialise the flash */
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    62
	data_len = 0;
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    63
	data_num_pages = 0;
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    64
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    65
	data_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    66
	memset(data_page, 0, sizeof(unsigned int)*n);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    67
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    68
	if (data_page == NULL)
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    69
		return -1;
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    70
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    71
	regs_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    72
	memset(regs_page, 0, sizeof(unsigned int)*n);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    73
	if (regs_page == NULL)
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    74
		return -2;
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    75
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    76
	iat_flash_read_regs();
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    77
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    78
	/* start the data at the location specified in the registers */ 
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    79
	if (0) /* for now it is 0, but put here a test to know whether
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    80
                  or not the NVRAM has been written before */
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    81
		data_addr = regs_page[1];
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    82
	else
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    83
		data_addr = NVRAM_BLOCK_SIZE; /* let start at block 1 */
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    84
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    85
	return 0;
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    86
}
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    87
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    88
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    89
void iat_end()
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    90
{
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    91
	/* write the last page before closing */
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    92
	iat_flash_write_page(data_addr);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    93
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    94
	/* some actions to end accessing the flash */
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    95
	free(data_page);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    96
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    97
	regs_page[4] = data_num_pages;
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    98
	/* write the registers to the NVRAM before closing */
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
    99
	iat_flash_write_regs();
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   100
	free(regs_page);
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   101
}
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   102
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   103
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   104
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   105
/************************************************************************/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   106
/*                                                                    	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   107
/* function:								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   108
/*  void ee_erase(unsigned int command_ee,unsigned int result_ee[])	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   109
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   110
/* type: void                                                          	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   111
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   112
/* parameters: 								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   113
/* 	command_ee   - Not used.  	               			*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   114
/*  result_ee[0] - Returns a response to the last IAP command used.	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   115
/*                 0 - EEPROM successfully erased.			*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   116
/*                 For all other response values, see microcontroller 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   117
/*		   User Manual, IAP Commands and Status Codes Summary.	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   118
/*  result_ee[1] - Not used.                         			*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   119
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   120
/* version: 1.1 (01/27/2006)                                           	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   121
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   122
/* constants defined in LPC2k_ee.h used in this function:              	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   123
/*  EE_SEC_L 	 - microcontroller's Flash sector where EEPROM begins	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   124
/*  EE_SEC_H 	 - microcontroller's Flash sector where EEPROM ends	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   125
/*  EE_CCLK		 - microcontroller's system clock (cclk)        */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   126
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   127
/* description:								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   128
/*  This function erases LPC2000 on-chip Flash sectors selected to act 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   129
/*  as an EEPROM. All Flash sectors between EE_SEC_L abd EE_SEC_H	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   130
/*  (including these sectors) will be erased using the In Application	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   131
/*  Programming (IAP) routines (see User Manual for more details). 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   132
/*  Also, this function disables all interrupts while erasing the       */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   133
/*  EEPROM. If this is not needed, three lines of the ee_erase          */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   134
/*  subroutine can simply be commented-out without affecting the        */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   135
/*  routine performance at all.                                         */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   136
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   137
/* revision history:                                                   	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   138
/* - Rev. 1.1 adds interrupt disable feature.				*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   139
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   140
/************************************************************************/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   141
void ee_erase(unsigned int command_ee,unsigned int result_ee[])
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   142
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   143
	unsigned int command_iap[5];
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   144
	unsigned int result_iap[3];
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   145
	unsigned long int enabled_interrupts;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   146
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   147
	enabled_interrupts = VICIntEnable;  //disable all interrupts
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   148
	VICIntEnClr        = enabled_interrupts;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   149
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   150
	command_iap[0]=50;	// prepare sectors from EE_SEC_L to EE_SEC_H for erase
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   151
	command_iap[1]=EE_SEC_L;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   152
	command_iap[2]=EE_SEC_H;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   153
	iap_entry=(IAP) IAP_LOCATION;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   154
	iap_entry(command_iap,result_iap);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   155
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   156
	command_iap[0]=52;	// erase sectors from EE_SEC_L to EE_SEC_H
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   157
	command_iap[1]=EE_SEC_L;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   158
	command_iap[2]=EE_SEC_H;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   159
	command_iap[3]=EE_CCLK;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   160
	iap_entry=(IAP) IAP_LOCATION;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   161
	iap_entry(command_iap,result_iap);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   162
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   163
	command_iap[0]=53;	// blankcheck sectors from EE_SEC_L to EE_SEC_H
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   164
	command_iap[1]=EE_SEC_L;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   165
	command_iap[2]=EE_SEC_H;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   166
	iap_entry=(IAP) IAP_LOCATION;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   167
	iap_entry(command_iap,result_iap);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   168
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   169
	VICIntEnable = enabled_interrupts;  //restore interrupt enable register
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   170
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   171
	result_ee[0]=result_iap[0];
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   172
	return;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   173
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   174
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   175
/************************************************************************/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   176
/*                                                                    	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   177
/* function: 								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   178
/*  void ee_write(unsigned int command_ee,unsigned int result_ee[])	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   179
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   180
/* type: void                                                          	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   181
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   182
/* parameters: 								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   183
/* 	command_ee   - An address of a content of ee_data type that has	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   184
/*                 to be programmed into EEPROM.                       	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   185
/*  result_ee[0] - Returns a response to the last IAP command used.	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   186
/*                 0 - data successfully programmed in EEPROM.		*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   187
/*               501 - no space in EEPROM to program data.             	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   188
/*                 For all other response values, see microcontroller 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   189
/*		   User Manual, IAP Commands and Status Codes Summary.	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   190
/*  result_ee[1] - Not used.                           			*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   191
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   192
/* version: 1.1 (01/27/2006)                                           	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   193
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   194
/* constants defined in LPC2k_ee.h used in this function:              	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   195
/*  EE_BUFFER_SIZE 	   - IAP buffer size; must be 256 or 512 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   196
/*  NO_SPACE_IN_EEPROM - EEPROM is full and no data can be programmed	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   197
/*  EE_BUFFER_MASK	   - parameter used for interfacing with IAP	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   198
/*  EE_REC_SIZE   	   - ee_data structure size in bytes        	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   199
/*  EE_SEC_L 	 	   - micro's Flash sector where EEPROM begins	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   200
/*  EE_SEC_H 	 	   - micro's Flash sector where EEPROM ends	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   201
/*  EE_CCLK		 	   - micro's system clock (cclk)       	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   202
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   203
/* description:								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   204
/*  This function writes a single structure of ee_data type into the	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   205
/*  EEPROM using an In Application	Programming (IAP) routines (see */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   206
/*  User Manual for more details). command_ee contains an address of	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   207
/*  this structure. EEPROM is scanned for the last (if any) record 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   208
/*  identifier (EE_REC_ID), and a new record is added next to it.      	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   209
/*  Also, this function disables all interrupts while erasing the       */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   210
/*  EEPROM. If this is not needed, three lines of the ee_write          */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   211
/*  subroutine can simply be commented-out without affecting the        */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   212
/*  routine performance at all.                                         */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   213
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   214
/* revision history:                                                   	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   215
/* - Rev. 1.1 fixes a bug related to verifying a content written into	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   216
/*   the EEPROM. 1.0 was reporting missmatch even when there were no	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   217
/*   problems at all.							*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   218
/*   Rev. 1.1 adds interrupt disable feature.				*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   219
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   220
/************************************************************************/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   221
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   222
void ee_write_page(unsigned int addr)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   223
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   224
	unsigned long int enabled_interrupts;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   225
	// unsigned char ee_buffer[16];
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   226
	unsigned int command_iap[5], result_iap[3];
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   227
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   228
	enabled_interrupts = VICIntEnable;  //disable all interrupts
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   229
	VICIntEnClr        = enabled_interrupts;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   230
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   231
	iap_entry = (IAP) IAP_LOCATION;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   232
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   233
	// prepare sectors from EE_SEC_L to EE_SEC_H for erase
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   234
	command_iap[0] = 50;			
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   235
	command_iap[1] = EE_SEC_L;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   236
	command_iap[2] = EE_SEC_H;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   237
	iap_entry(command_iap, result_iap);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   238
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   239
	// copy RAM to flash/eeprom
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   240
	command_iap[0] = 51;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   241
	command_iap[1] = (unsigned int) (addr & EE_START_MASK); // 256 kb boundary
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   242
	command_iap[2] = (unsigned int) (data_page);            // should be on a word boundary
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   243
	command_iap[3] = 256;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   244
	command_iap[4] = EE_CCLK;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   245
	iap_entry(command_iap, result_iap);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   246
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   247
#if 0 
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   248
	// compare RAM and flash/eeprom
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   249
	command_iap[0] = 56;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   250
	command_iap[1] = (unsigned int) data;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   251
	command_iap[2] = addr;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   252
	command_iap[3] = dlen;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   253
	iap_entry(command_iap, result_iap);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   254
#endif
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   255
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   256
	VICIntEnable = enabled_interrupts;  //restore interrupt enable register
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   257
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   258
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   259
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   260
/************************************************************************/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   261
/*                                                                    	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   262
/* function: 								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   263
/*  void ee_read(unsigned int command_ee,unsigned int result_ee[])	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   264
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   265
/* type: void                                                          	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   266
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   267
/* parameters: 								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   268
/* 	command_ee   - Not used.					*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   269
/*  result_ee[0] - Returns a response.					*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   270
/*                 0 - data successfully found in EEPROM.		*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   271
/*               500 - no data/records available in EEPROM.		*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   272
/*  result_ee[1] - an address of the last record of ee_data type	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   273
/*				   in EEPROM.  	              		*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   274
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   275
/* version: 1.1 (01/27/2006)                                           	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   276
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   277
/* constants defined in LPC2k_ee.h used in this function:              	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   278
/*  NO_RECORDS_AVAILABLE - EEPROM is empty/no records identifiable	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   279
/*			   with a record identifier (EE_REC_ID) found	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   280
/*  EE_ADR_L 	    - micro's Flash address from where EEPROM begins	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   281
/*  EE_REC_SIZE    - size (in bytes) of a ee_data structure        	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   282
/*                                                                 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   283
/* description:								*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   284
/*  This function scans an EEPROM content looking for the last record 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   285
/*  that can be identified with a record identifier (EE_REC_ID). When 	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   286
/*  such data is found, its address is passed as result_ee[1].		*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   287
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   288
/* revision history:                                                   	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   289
/* - Rev. 1.0 had problems with accessing the last record in a fully	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   290
/*   occupied EEPROM. Rev. 1.1 fixes this.				*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   291
/*                                                                     	*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   292
/************************************************************************/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   293
void ee_read_page(unsigned int addr)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   294
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   295
	memcpy(data_page, (unsigned int *)addr, sizeof(unsigned int)*64);
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   296
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   297
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   298
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   299
//////////////////////////////////////////////////////////////////////////////////////////
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   300
//////////////////////////////////////////////////////////////////////////////////////////
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   301
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   302
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   303
/*
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   304
	CAN FESTIVAL interface functions
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   305
*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   306
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   307
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   308
int _get_data_len(int type)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   309
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   310
	int len = 0; /* number of bytes */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   311
	switch(type)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   312
	{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   313
		case  boolean:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   314
			len = 1;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   315
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   316
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   317
		case  int8:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   318
		case  uint8:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   319
			len = 1;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   320
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   321
		case  int16:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   322
		case  uint16:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   323
			len = 2;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   324
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   325
		case  int24:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   326
		case  uint24:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   327
			len = 3;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   328
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   329
		case  int32:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   330
		case  uint32:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   331
		case  real32:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   332
			len = 4;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   333
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   334
		case  int40:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   335
		case  uint40:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   336
			len = 5;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   337
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   338
		case  int48:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   339
		case  uint48:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   340
			len = 6;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   341
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   342
		case  int56:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   343
		case  uint56:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   344
			len = 7;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   345
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   346
		case  int64:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   347
		case  uint64:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   348
		case  real64:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   349
			len = 8;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   350
			break;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   351
#if 0
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   352
/* TO DO */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   353
		case  visible_string:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   354
		case  octet_string:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   355
		case  unicode_string:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   356
		case  time_of_day:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   357
		case  time_difference:
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   358
#endif
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   359
	}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   360
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   361
	return len;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   362
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   363
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   364
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents:
diff changeset
   365