?? error.c
字號:
/***************************************************************************
* This code and information is provided "as is" without warranty of any *
* kind, either expressed or implied, including but not limited to the *
* implied warranties of merchantability and/or fitness for a particular *
* purpose. *
* *
* Copyright (C) 2006 Teridian Semiconductor Corp. All Rights Reserved. *
***************************************************************************/
//**************************************************************************
// DESCRIPTION: 71M652x POWER METER - error recording
//
// AUTHOR: RGV
//
// HISTORY: See end of file.
//**************************************************************************
// File: error.c
//
#include "options.h"
#if ERROR_RECORDING
#include FILE_DEFINING_ERROR // meter.h
#include "library.h"
#include "eeprom.h"
#include "error.h"
/*** External functions referenced by this module ***/
// Refer to include files.
/*** External variables referenced by this module ***/
/*** Public functions referenced by this module ***/
/*** Public variables referenced by this module ***/
/*** Private functions referenced by this module ***/
/*** Private variables referenced by this module ***/
// record new errors
#pragma save
#pragma NOAREGS
void Error_Record (void) small reentrant // in case of a sag
{
// Get a private copy that interrupts can't change
int32_t my_status = Status;
int32_t unrecorded = my_status ^ OldStatus; // changed bits
uint8_t changed = FALSE;
unrecorded &= WORTH_RECORDING; // record worthwhile errors
unrecorded &= my_status; // record only when error becomes 1
while (unrecorded) // errors exist
{
uint8_t done = FALSE;
uint8_t errno, errno_min, ierMin, ier;
uint32_t mask;
// find the highest-numbered (most important) unrecorded error
errno = 31;
mask = 0x80000000;
for(; mask != 0;)
{
if(mask & unrecorded)
{
unrecorded &= ~mask; // remove the error
break;
}
mask = (mask >> 1);
errno -= 1;
}
// is the unrecorded error equal to a recorded error?
for(ierMin = ierMax; ierMin <= ierMax; --ierMin)
{
if (Aer[ierMin].errno == errno)
{
// it's equal! Record the new occurrence.
Aer[ierMin].month = Rtc_Month;
Aer[ierMin].date = Rtc_Date;
Aer[ierMin].hour = Rtc_Hour;
if(Aer[ierMin].cnt < UINT8_MAX)
Aer[ierMin].cnt += 1;
done = TRUE;
changed = TRUE;
break;
}
}
if (done)
break; // it was equal; we're done
// find the smallest (least important) stored error number
errno_min = 32;
for(ier = 0; (!done) && (ier <= ierMax); ++ier)
{
if (Aer[ier].errno < errno_min)
{
ierMin = ier;
errno_min = Aer[ier].errno;
}
}
// is the new error more important than the least important record?
if (errno_min < errno)
{
// Record the new error in place of the least important record.
Aer[ierMin].month = Rtc_Month;
Aer[ierMin].date = Rtc_Date;
Aer[ierMin].hour = Rtc_Hour;
Aer[ierMin].errno = errno;
Aer[ierMin].cnt = 1;
changed = TRUE;
}
else
{
// Records are more important than anything new; stop storing
unrecorded = 0;
}
}
// forget that the errors are new
OldStatus = my_status;
if (changed)
{
LRC_Calc_NVR ((uint8x_t *) &Totals.Err, sizeof (Totals.Err), TRUE);
memcpy_prx (
EEPROM_ERRORS,
(uint8x_t*)&Totals.Err, // The start of the data
(sizeof (Totals.Err)) ); // get the revenue registers
changed = FALSE;
}
}
#pragma restore
// Clear the errors
void Error_Clear (void)
{
memset_x ((uint8x_t *) &Totals.Err, 0x00, sizeof (Totals.Err));
LRC_Calc_NVR ((uint8x_t *) &Totals.Err, sizeof (Totals.Err), TRUE);
memcpy_prx (
EEPROM_ERRORS,
(uint8x_t*)&Totals.Err, // The start of the data
(sizeof (Totals.Err)) ); // get the revenue registers
}
// initialize the error system
void Error_Init (void)
{
EEProm_Config (1, PAGE_SIZE, WRITE_TIME);
memcpy_xpr (
(uint8x_t*)&Totals.Err, // The start of the data
EEPROM_ERRORS,
sizeof (Totals.Err) );
if(!LRC_Calc_NVR ((uint8x_t *) &Totals.Err, sizeof (Totals.Err), TRUE))
{
Error_Clear ();
}
}
/***************************************************************************
* History:
* $Log: error.c,v $
* Revision 1.3 2006/09/09 01:13:47 gmikef
* *** empty log message ***
*
* Revision 1.2 2006/06/29 00:58:09 tvander
* Added NOAREGs to reeentrant code.
*
* Revision 1.1 2006/06/06 04:00:56 tvander
* Keeps an error list with times.
*
*
* Copyright (C) 2006 Teridian Semiconductor Corp. All Rights Reserved. *
* this program is fully protected by the United States copyright *
* laws and is the property of Teridian Semiconductor Corporation. *
***************************************************************************/
#endif /* ERROR */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -