?? access.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) 2005 Teridian Semiconductor Corp. All Rights Reserved. *
***************************************************************************/
// DESCRIPTION: 71M652x POWER METER - Memory Access Routines.
//
// AUTHOR: MTF
//
// HISTORY: See below
//***************************************************************************
// File: access.c
//
#include "options.h"
#if CLI
#include "ce.h"
#include "ce_dat.h"
#include "cli.h"
#include "flash.h"
#include "io.h"
#include "meter.h"
#include "calibration.h"
#include "sercli.h"
#include "sfrs.h"
#include "stm.h"
#include <ctype.h>
/*** Private functions declared within this module ***/
static void cmd_sfr_data (void);
static void cmd_sfr_xdata (void);
/*** Private variables declared within this module ***/
// None.
//----------------------------------------------------//
void cmd_sfr (void) // 'R' Special Function (R)egisters.
{
uint8_t data d;
switch (toupper (get_char_d (&d)))
{
case 'I':
cmd_sfr_xdata (); // IO space.
break;
default:
cli_index = d; // Unget last character.
cmd_sfr_data ();
break;
}
}
static void cmd_sfr_xdata (void)
{
uint8_t xdata * xdata p;
uint8_t xdata c;
uint8_t data d;
p = (uint8x_t *) (IO_BASE | (uint8_t) get_num ()); // Get SFR's two-byte address.
c = get_char_d (&d); // Get action for SFR.
switch (c)
{
case '?':
case '$':
do
{
d = *p;
if ('?' == c)
send_byte (d);
else
send_byte_hex (d);
p++;
c = get_char_d (&d) ;
} while (('?' == c) || ('$' == c));
send_crlf ();
break;
case '=':
do
{
d = get_num ();
if (&CONFIG0 == p)
{
if (!MPU_Clk_Select (port, d & 0x07))
{
start_tx_rslt ("\r\nNeed to first lower Serial Rate\r\n");
return;
}
}
if (&RTC_SEC <= p && p <= &RTC_ADJUST)
{
stm_wait (milliseconds(20)); // Wait between RTC writes.
#if M6520
WE = 0x00; // Write Enable RTC.
#endif
}
*p++ = d;
c = get_char_d (&d);
} while ('=' == c);
break;
}
cli_index = d; // Unget last character.
}
static void cmd_sfr_data (void)
{
uint8_t xdata s;
uint8_t data c, d;
enum SFR_RC xdata rc;
s = get_num (); // Get SFR's one-byte address.
c = get_char_d (&d); // Get action for SFR.
switch (toupper (c))
{
case '?':
case '$':
do
{
if (SFR_OK == (rc = SFR_Read (s++, &d)))
{
if ('?' == c)
send_byte (d);
else
send_byte_hex (d);
}
c = get_char_d (&d) ;
} while ((('?' == c) || ('$' == c)) && (SFR_OK == rc));
send_crlf ();
break;
case '=':
do
{
d = get_num ();
rc = SFR_Write (s++, d, ASSIGN);
c = get_char_d (&d);
} while ('=' == c);
break;
}
cli_index = d; // Unget last character.
}
#if M6520
#define NUM_DATA_PAGES (0x0200 / FPAGE_SIZE)
#elif TRACE10
#define NUM_DATA_PAGES (0x0400 / FPAGE_SIZE)
#endif
void cmd_ce_data_access (void) // ']' CE data access.
{
uint8_t xdata c;
uint8_t data d;
int32x_t * xdata x;
int32_t xdata n;
c = get_char_d (&d); // Check for possible FLASH update.
if ('U' == c)
{
bool ok;
if (CE0 & CE_EN)
{
ok = FALSE;
}
else
{
#if CAL_SAVE
cal_save ();
#else
ok = memcpy_rce (CeData, (int32x_t *) CE_DATA_BASE, FPAGE_SIZE / sizeof (int32_t));
#endif
}
if(!ok)
{
start_tx_rslt ("Save failed; turn CE off, check save device.");
send_crlf ();
}
return;
}
cli_index = d; // Unget last character.
// Get data's two-byte address.
x = (int32_t xdata *) ((uint16_t) CE_DATA_BASE | ((uint8_t) get_num () << 2));
c = get_char_d (&d); // Get action for address.
switch (c)
{
case '?':
case '$':
do
{
n = memget_ce (x++);
if ('?' == c)
send_long (n);
else
send_long_hex (n);
c = get_char_d (&d) ;
} while (('?' == c) || ('$' == c));
send_crlf ();
break;
case '=':
do
{
memset_ce (x++, get_long ());
c = get_char_d (&d);
} while ('=' == c);
#if CONSTANTS_DBG
get_ce_constants (); // Update "shadow" copy.
#endif
break;
}
cli_index = d; // Unget last character.
}
typedef struct Parm
{
uint8x_t *p;
int8_t s; // negative indicates a signed value
} PARM;
#define cpMax 0x20
#define ipMax (cpMax - 1)
PARM code ap[cpMax]=
{
{(uint8x_t *) &IThrshld, sizeof(IThrshld)},
{(uint8x_t *) &Config, sizeof(Config)},
{(uint8x_t *) &VPThrshld, sizeof(VPThrshld)},
{(uint8x_t *) &IPThrshld, sizeof(IPThrshld)},
{(uint8x_t *) &Y_Cal_Deg0, -sizeof(Y_Cal_Deg0)},
{(uint8x_t *) &Y_Cal_Deg1, -sizeof(Y_Cal_Deg1)},
{(uint8x_t *) &Y_Cal_Deg2, -sizeof(Y_Cal_Deg2)},
{(uint8x_t *) &PulseWSource, sizeof(PulseWSource)},
{(uint8x_t *) &PulseRSource, sizeof(PulseRSource)},
{(uint8x_t *) &Vmax, -sizeof(Vmax)},
{(uint8x_t *) &Imax, -sizeof(Imax)},
{(uint8x_t *) &ppmc1, -sizeof(ppmc1)},
{(uint8x_t *) &ppmc2, -sizeof(ppmc2)},
{(uint8x_t *) &Pulse3Source, sizeof(Pulse3Source)},
{(uint8x_t *) &Pulse4Source, sizeof(Pulse4Source)},
{(uint8x_t *) &Scal, sizeof(Scal)},
{(uint8x_t *) &Vcal, sizeof(Vcal)},
{(uint8x_t *) &Ical, sizeof(Ical)},
{(uint8x_t *) &VThrshld, sizeof(VThrshld)},
{(uint8x_t *) &PulseWidth, sizeof(PulseWidth)},
{(uint8x_t *) &temp_nom, sizeof(temp_nom)},
#if IMAX2
{(uint8x_t *) &Imax2, -sizeof(Imax2)},
{(uint8x_t *) &IThrshld2, sizeof(IThrshld2)},
#else
{NULL, 0},
{NULL, 0},
#endif
{(uint8x_t *) &VBatMin, sizeof(VBatMin)},
{(uint8x_t *) &CalibrationCount, sizeof(CalibrationCount)},
{(uint8x_t *) &Rtc_Sec, sizeof(Rtc_Sec)},
{(uint8x_t *) &Rtc_Min, sizeof(Rtc_Min)},
{(uint8x_t *) &Rtc_Hour, sizeof(Rtc_Hour)},
{(uint8x_t *) &Rtc_Day, sizeof(Rtc_Day)},
{(uint8x_t *) &Rtc_Date, sizeof(Rtc_Date)},
{(uint8x_t *) &Rtc_Month, sizeof(Rtc_Month)},
{(uint8x_t *) &Rtc_Year, sizeof(Rtc_Year)}
};
// fetch a parameter
static uint32_t f (uint16_t ip)
{
uint32_t v;
if (ip > ipMax) // defaults to fetch a 32-bit number
return *((ip - cpMax) + (uint32x_t*)&deltaT);
switch (ap[ ip ].s)
{
case 0:
v = 0;
break;
default:
case 1:
v = (uint32_t) (*((uint8x_t *) ap[ ip ].p));
break;
case 2:
v = (uint32_t) (*((uint16x_t *) ap[ ip ].p));
break;
case 4:
case -4:
v = *((uint32x_t *) ap[ ip ].p);
break;
case -1:
v = (uint32_t) (*((uint8x_t *) ap[ ip ].p));
if (v & 0x80L) v |= 0xFFFFFF80L; // sign extend
break;
case -2:
v = (uint32_t) (*((uint16x_t *) ap[ ip ].p));
if (v & 0x8000L) v |= 0xFFFF8000L; // sign extend
break;
}
return v;
}
// store a parameter
static void s (uint16_t ip, uint32_t v)
{
uint8x_t *pT;
if (ip > ipMax) // defaults to store a 32-bit number
{
*((ip - cpMax) + &deltaT) = v;
return;
}
switch (ap[ ip ].s)
{
case 0:
break;
default:
case 1:
case -1:
pT = ap[ ip ].p;
*((uint8x_t *) pT) = v;
if ((&Rtc_Sec <= pT) && (pT <= &Rtc_Year))
{
#if REAL_TIME_DATE
stm_wait (milliseconds(30)); // Wait between RTC writes.
RTClk_Write (); // Set the clock from the revised totals.
#endif
}
break;
case 2:
case -2:
*((uint16x_t *) ap[ ip ].p) = v;
break;
case 4:
case -4:
*((uint32x_t *) ap[ ip ].p) = v;
break;
}
}
void cmd_mpu_data_access (void) // ')' MPU data access.
{
uint8_t xdata c;
uint8_t data d;
uint16_t xdata x;
x = get_num ();
c = get_char_d (&d); // Get action for address.
switch (c)
{
case '?':
case '$':
do
{
if ('?' == c)
send_long (f (x++));
else
send_long_hex (f (x++));
c = get_char_d (&d) ;
} while (('?' == c) || ('$' == c));
send_crlf ();
break;
case '=':
do
{
s (x++, get_long ());
c = get_char_d (&d);
} while ('=' == c);
break;
}
cli_index = d; // Unget last character.
}
/***************************************************************************
* $Log: access.c,v $
* Revision 1.24 2006/10/13 00:46:18 tvander
* Removed compile options for 6530, 6515; renamed 6511 and 6513 to trace11 and trace13; Binary verified unchanged from previous version.
*
* Revision 1.23 2006/09/29 08:51:56 tvander
* EEPROM operations are locked out when the CE is running.
*
* Revision 1.22 2006/09/09 01:07:57 gmikef
* *** empty log message ***
*
* Revision 1.21 2006/06/06 03:53:50 tvander
* Added calibration count to access.c
* Added to help files, at least, they compile for a 6513.
* io.c support the calibration loader.
* ser0cli.c and ser1cli.c were allocating too many timers. Fixed.
*
* Revision 1.20 2006/06/05 23:47:18 tvander
* Modified for cal_save that does not return a success/fail boolean.
* Modified to include cal-count, the count of calibration saves
*
* Revision 1.19 2006/05/25 03:25:58 tvander
* Some untested adjustments for calibration loader.
* Added automatic enabling of UART2 and switching to pulse output on DIO2
*
* Revision 1.18 2006/05/18 23:18:41 tvander
* 16K and 32K
* First cut at new requirements.
* 32K 6521 is grossly tested.
* All others have a clean compile with C51 8.02
*
* Revision 1.17 2006/04/28 22:24:05 tvander
* Reverse ported defects fixed when these files were ported to the 3.05 code.
*
* Revision 1.16 2006/04/25 01:09:48 tvander
* Integrated improved RTC. Compensates for time off, has default constant
* compensation. Computes true hours of operation.
*
* Revision 1.15 2006/04/06 18:57:58 tvander
* Imax2 changes
*
* Revision 1.14 2006/03/17 00:20:18 tvander
* StMask deprecated
*
* Revision 1.13 2006/03/07 23:57:06 tvander
* Revised help system for accuracy.
* Revised help system for compile flags.
* Clean build
*
* Revision 1.12 2006/03/06 03:27:27 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.11 2006/03/03 11:23:52 Michael T. Fischer
* Prep for 6530 LCD, etc.
*
* Revision 1.10 2006/01/25 00:37:58 tvander
* Handles signed 1 and 2 byte values.
*
* Revision 1.9 2006/01/16 20:11:18 tvander
* Clean Keil build, all versions
*
* Revision 1.7 2005/10/06 20:56:38 tvander
* Made access table automatically cope with changing field sizes.
*
* Revision 1.6 2005/09/22 23:44:53 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.5 2005/09/12 07:47:27 tvander
* Power measurement is stable, with no creep.
* VARh measurement is stable, with no creep.
* Pulse sources work.
* Full access to MPU variables.
* Rolled date.
* Clock software works.
*
* Revision 1.4 2005/09/01 02:02:10 gmikef
* Cleaned up the builds.
*
* Revision 1.3 2005/08/31 05:50:51 gmikef
* First version w/ LAPIE interface.
*
* Revision 1.2 2005/08/30 01:56:00 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/28 02:20:57 gmikef
* *** empty log message ***
*
* Revision 1.3 2005/08/20 01:32:43 gmikef
* *** empty log message ***
*
* Revision 1.2 2005/08/19 01:04:36 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/18 02:56:04 gmikef
* *** empty log message ***
*
* Revision 1.4 2005/08/03 18:34:43 tvander
* Changed copyright to "Teridian Semiconductor Co."
* Put in alt-mux change in MPU parameters in api_struct.h
* Revised validity date of cal.c
*
* Revision 1.3 2005/06/22 20:19:42 tvander
* I-102, DEG_SCALE is in two places and could become unequal.
*
* Revision 1.2 2005/02/17 18:32:16 tvander
* Added automatic check-in logging to all source code.
*
* 2003 OCTOBER 30; First Version.
* Copyright (C) 2005 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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -