00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _EEPROM_H
00012 #define _EEPROM_H
00013
00014 #include <arch/param.h>
00015 #include <gnu_defs.h>
00016 #include <clocks.h>
00017 #include <debug.h>
00018
00019
00020 #define EEPROM_ADD 0x800
00021 #define MAX_EEPROM_CLK 200000
00022 #define SECTOR_ERASE 0x40
00023 #define WORD_PROGRAM 0x20
00024 #define SECTOR_MODIFY 0x60
00025
00026 #define ECLKDIV *(volatile unsigned char *)(IO_BASE + 0x110)
00027 #define ECNFG *(volatile unsigned char *)(IO_BASE + 0x113)
00028 #define EPROT *(volatile unsigned char *)(IO_BASE + 0x114)
00029 #define ESTAT *(volatile unsigned char *)(IO_BASE + 0x115)
00030 #define ECMD *(volatile unsigned char *)(IO_BASE + 0x116)
00031
00032 #define CBEIF 0x80
00033 #define CBEIE 0x80
00034 #define CCIF 0x40
00035
00036 #define EEPROM_BUSY (!(ESTAT&CCIF))
00037
00038 typedef volatile u16 eeblock;
00039
00040 static inline int eeprom_init(void){
00041 ECLKDIV = OSCCLK/MAX_EEPROM_CLK;
00042 return 0;
00043 }
00044
00045 static inline int eeprom_command(int command){
00046 ECMD = command;
00047 ESTAT |= CBEIF;
00048 return 0;
00049 }
00050
00051 static inline int eeprom_modify(eeblock *address,eeblock data){
00052 if(EEPROM_BUSY)
00053 return -1;
00054 GENDEBUG("eeprom write %x to address %x\r\n",(long)data,(long)address);
00055 *address = data ;
00056 eeprom_command(SECTOR_MODIFY);
00057 return 0;
00058 }
00059
00060 #endif