Content originally posted in LPCWare by ramesh@spatika on Wed Dec 08 01:06:56 MST 2010
Every 15 minute i am logging the data into the flash using the following function
void Log_Data_In_Flash(void)
{
int iCount,sample;
char test[40];
int i;
if((giDom!=(xMonthly_Log[giMoy]->xdaily_log[giDom].idd))||(giMoy!=(xMonthly_Log[giMoy]->xdaily_log[giDom].imm))||(giYy!=(xMonthly_Log[giMoy]->xdaily_log[giDom].iyy)))
{
Erase_n_Format(giYy, giMoy, giDom);//Mismatch Erase the entire months space
}
//now let us read the daily space
Read_Daily_Data(&local_daybuf_4_log, giMoy, giDom);
sample=(giHh*60+giMin)/15;//position of the data to be written for the time
vPrintStringAndNumber("sample",sample);
local_daybuf_4_log.irf[sample]=siRain_Log;
local_daybuf_4_log.itemp[sample]=siTemp_Log;
local_daybuf_4_log.ihumi[sample]=siHumi_Log;
local_daybuf_4_log.iws[sample]=siWs_Log;
local_daybuf_4_log.iwd[sample]=siWd_Log;
//now log the data on the flash by writing
Write_Daily_Data(&local_daybuf_4_log,giMoy, giDom);
sample=(giHh*60+giMin)/15;//position of the data to be written for the time
}
//erasing the data and formatting
void Erase_n_Format(unsigned int iYear, unsigned int iMonth, unsigned int iDate )
{
int day,month,year,sector;
//Claculate the sector
sector=START_SEC_NO_DEF+iMonth-1;
vPrintStringAndNumber("\nSec ",sector);
__disable_irq();
Prepare_Sector(sector,sector);//prepare the sector
Erase_Sector(sector,sector);//erase the sector
__enable_irq();
//before formatting clear the local buffer by readin the erased space
Read_Daily_Data(&local_daybuf_4_log,iMonth,iDate);
//format the buffer
for(day=0;day<32;day++)
{
local_daybuf_4_log.idd=(short int)day;
local_daybuf_4_log.imm=(short int)iMonth;
local_daybuf_4_log.iyy=(short int)iYear;
Write_Daily_Data(&local_daybuf_4_log,iMonth,day);
}
}
//writing the data every 15 minute
void Write_Daily_Data(Reading_def *xWrite_local,unsigned int iMonth,unsigned int iDate)
{
int sector;
int ret;
int i;
sector=START_SEC_NO_DEF+iMonth-1;
__disable_irq();
Prepare_Sector(sector,sector);//prepare the sector
ret=Write_Sector((unsigned int)&(xMonthly_Log[iMonth]->xdaily_log[iDate]),(unsigned int)xWrite_local,1024);//write the sector
if(ret!=0)
vPrintString("Error in writing");
__enable_irq();
}
void Read_Daily_Data(Reading_def *xRead_Local,unsigned int iMonth,unsigned int iDate)
{
int i;
char test[40];
xRead_Local->idd=xMonthly_Log[iMonth]->xdaily_log[iDate].idd;
xRead_Local->imm=xMonthly_Log[iMonth]->xdaily_log[iDate].imm;
xRead_Local->iyy=xMonthly_Log[iMonth]->xdaily_log[iDate].iyy;
for(i=0;i<96;i++)
{
xRead_Local->irf=xMonthly_Log[iMonth]->xdaily_log[iDate].irf;
xRead_Local->itemp=xMonthly_Log[iMonth]->xdaily_log[iDate].itemp;
xRead_Local->ihumi=xMonthly_Log[iMonth]->xdaily_log[iDate].ihumi;
xRead_Local->iws=xMonthly_Log[iMonth]->xdaily_log[iDate].iws;
xRead_Local->iwd=xMonthly_Log[iMonth]->xdaily_log[iDate].iwd;
if((xRead_Local->itemp!=0xffff)&&(xRead_Local->itemp!=455)){
sprintf(test,"\nteRd %d, %d; ",xRead_Local->itemp,i);
vPrintString(test);
}
if((xRead_Local->ihumi!=0xffff)&&(xRead_Local->ihumi!=677)){
sprintf(test,"\nhuRd %d, %d; ",xRead_Local->ihumi,i);
vPrintString(test);
}
}
xRead_Local->imax_temp=xMonthly_Log[iMonth]->xdaily_log[iDate].imax_temp;
xRead_Local->imin_temp=xMonthly_Log[iMonth]->xdaily_log[iDate].imin_temp;
xRead_Local->imax_humi=xMonthly_Log[iMonth]->xdaily_log[iDate].imax_humi;
xRead_Local->imin_humi=xMonthly_Log[iMonth]->xdaily_log[iDate].imin_humi;
xRead_Local->imax_wind=xMonthly_Log[iMonth]->xdaily_log[iDate].imax_wind;
for(i=0;i<24;i++)
{
xRead_Local->padding=xMonthly_Log[iMonth]->xdaily_log[iDate].padding;
}
}
please see the code above for you reference.
As i told at every 15 minute i am reading the flash.
If there is no content in the flash memory i will write the text format.
I there is right contentt in the flash memory then i will read the same and substitute the value for the particular sample.
kindly guide me further.