📄 funcfile.c
字号:
//These codes contains the functions to operate the 24C64 EEPROM
//For the reason that the length of address domain is longer, the library
//functions of serial I2C EEPROM con not be used derectly
// The operation on EEPROM can't be done by multiple user simultanously, so a semephone is
// applied when write or read the EEPROMs
#include <p18cxxx.h>
#include "includes.h"
#include "ComStruct.h"
#include "funcprom.h"
#include "funcfile.h"
#include "device.h"
#include "feeprom.h"
extern unsigned char DebugContent[48];
extern OS_EVENT * rom EepromSem;
extern OS_EVENT *rom peventMCNM;
extern OS_EVENT *rom peventDVS;
extern INT16U GetMCNMFileLen(void);
extern INT16U GetDVSFileLen(void);
//Public functions
typedef rom struct FileTableItem{
INT16U Start;
INT16U End;
}FILETABLEITEM;
typedef rom struct FileTable{
INT16U U_W; //unique word, mark if these EEPROMs have been initialized
INT32U SN; //serial number of the equipment, write before shipping
FILETABLEITEM FileIndex[MAXFILENUM]; //The File alocation table
INT8U ChkSum; //Check Sum of all the former parts
} FILETABLE;
#pragma romdata EXTRAM
FILETABLE FileSys;
INT8U rom hdl_eeprom;
//FileHandle: handle of the file
//Position: start position of the data to be saved. it's the offset from the start address in the EEPROM
// of the file
//ptrData: start address of the data in the ram
//DataLen: length of the data to be saved
//For example, FileSave(HANDLEX, 2, 0x103000, 20)
// if HANDLEX relating with a file saved in EEPROM ranging from 0x2300 to 0x2400, then the function save 20
// bytes in the ram begining at 0x103000 into EEPROM address from 0x2302 to 0x230e
INT8U FileSave(INT8U FileID, INT16U Position, INT8U rom * ptrData, INT16U DataLen){
INT8U Temp,i,err;
INT16U PhyPos; //physical address in EEPROM
INT16U writetimes;
//if(FileID != OSPrioCur) return (1); //return if it's not the owner of the file
if (FileSys.FileIndex[FileID].Start == 0xffff) return (1); //return if the file has not been create
PhyPos = FileSys.FileIndex[FileID].Start + Position; //calaulate the start address of EEPROM
if((PhyPos > FileSys.FileIndex[FileID].End) ||
((PhyPos+DataLen-1)> FileSys.FileIndex[FileID].End)){
return (1); //if the data to be saved is not in the legal range, return
}
else{ //exacute the write operation
OSSemPend (EepromSem,0,&err); //seize the semephone
if(err != OS_NO_ERR) return (0xff);
sysdev_ioctl(hdl_eeprom, EEPROM_ADDRESS, PhyPos);
err = sysdev_write(hdl_eeprom, ptrData, i);
OSSemPost (EepromSem); //finish writing
return(0);
}
}
INT8U FileRead(INT8U FileID, INT16U Position, INT8U rom * ptrData, INT16U DataLen){
INT8U Temp,i,err;
INT16U PhyPos;
INT16U rom1len,rom2len;
//for test
rom1len = FileSys.FileIndex[FileID].Start;
rom2len = FileSys.FileIndex[FileID].End;
//
if (FileSys.FileIndex[FileID].Start == 0xffff) return (1); //return if the file has not been create
PhyPos = FileSys.FileIndex[FileID].Start + Position;
if((PhyPos > FileSys.FileIndex[FileID].End) ||
((PhyPos+DataLen-1)> FileSys.FileIndex[FileID].End)){
return (1);
}
OSSemPend (EepromSem,0,&err);
if(err != OS_NO_ERR) return (0xff);
sysdev_ioctl(hdl_eeprom, EEPROM_ADDRESS, PhyPos);
sysdev_read(hdl_eeprom, ptrData, DataLen);
OSSemPost (EepromSem);
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -