📄 load.c
字号:
FCTRL |= PWE_; *(p_1byte + 0) = d.c[2]; FCTRL = 0;
FCTRL |= PWE_; *(p_1byte + 1) = d.c[3]; FCTRL = 0;
EA = FALSE;
p_1byte += 2; p_2byte++;
break;
case 4: // FLASH WRITE
EA = FALSE;
FCTRL |= PWE_; *(p_1byte + 0) = d.c[0]; FCTRL = 0;
FCTRL |= PWE_; *(p_1byte + 1) = d.c[1]; FCTRL = 0;
FCTRL |= PWE_; *(p_1byte + 2) = d.c[2]; FCTRL = 0;
FCTRL |= PWE_; *(p_1byte + 3) = d.c[3]; FCTRL = 0;
EA = FALSE;
p_1byte += 4; p_4byte++;
break;
}
break;
case LOAD_MPU_DATA:
switch (width_data)
{
case 1: *p_1byte++ = d.c[3]; break;
case 2: *p_2byte++ = d.i[1]; break;
case 4: *p_4byte++ = d.l; break;
}
break;
}
d.l = get_data (&width);
}
c = '\0';
put_char (&c);
cli_index--;
}
static int32_t get_addr (uint8x_t *width)
{
uint8_t data c;
while (!done (&c) && !isxdigit (c));
;
return (get_hex_long (c, width));
}
static int32_t get_data (uint8x_t *width)
{
uint8_t data c = 0;
while (!done (&c) && !isxdigit (c));
;
return (get_hex_long (c, width));
}
// Convert upto 8-digit ascii hexadecimal to binary number.
static int32_t get_hex_long (uint8_t c, uint8x_t *width)
{
uint8_t xdata i;
uint32_t xdata n;
if (isxdigit (c))
{
i = 8; // Maximum number of chars allowed for hex input.
n = 0; // Number to be returned.
do
{ // Convert ASCII hexadecimal number to binary number.
n = (n << 4) + ctoh (c);
} while ((--i > 0) && (isxdigit (c = get_char ())));
*width = (8 - i) >> 1;
}
else
*width = 0;
return (n);
}
// ascii hex character to hexadecimal digit.
static uint8_t ctoh (uint8_t c)
{
if (c <= '9')
{
c -= '0';
}
else
{
c &= ~CASE_;
c -= 'A' - 10; // 'A' mapped to 10.
}
return (c);
}
#define UPLOAD_SIZE 16
static void Upload (void)
{
uint8_t data c;
uint8_t xdata width;
uint32_t xdata addr;
uint32_t xdata cnt;
uint8_t xdata i;
uint8_16_32_t xdata d;
uint8x_t * xdata pchr;
uint8r_t * xdata p_1flash;
uint16r_t * xdata p_2flash;
uint32r_t * xdata p_4flash;
uint8x_t * xdata p_1byte;
#if TRACE10
uint16x_t * xdata p_2byte;
#endif
uint32x_t * xdata p_4byte;
#if CLI_EEPROM
struct EEPROM_t xdata eeRead;
uint8_t xdata ebuff[ UPLOAD_SIZE ];
#endif
uint8_t xdata cb;
addr = get_addr (&width);
if (!done (&c))
cnt = get_hex_long (c, &width);
else
cnt = 16;
switch (load)
{
#if TRACE10
case LOAD_CE_CODE:
p_2byte = (uint16x_t *) (CE_CODE_BASE + (addr << 1));
break;
#endif
case LOAD_CE_CODE_DEFAULT:
p_2flash = (uint16r_t *) (CeCode + addr); // Pointer addition used.
break;
case LOAD_CE_DATA:
p_4byte = (uint32x_t *) (CE_DATA_BASE + (addr << 2));
break;
case LOAD_CE_DATA_DEFAULT:
p_4flash = (uint32r_t *) (CeData + addr); // Pointer addition used.
break;
case LOAD_CE_DATA_MONITOR:
break; // Reset each cycle.
case LOAD_EEPROM:
break;
case LOAD_FLASH:
p_1flash = (uint8r_t *) (0 + addr);
break;
case LOAD_MPU_DATA:
p_1byte = (uint8x_t *) (0 + addr);
break;
case LOAD_MPU_MONITOR:
break; // Reset each cycle.
}
while (cnt--)
{
pchr = txbuffer;
*pchr++ = '@';
i = UPLOAD_SIZE;
switch (load)
{
#if TRACE10
case LOAD_CE_CODE:
d.i[1] = ((uint16_t) p_2byte - CE_CODE_BASE) >> 1;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
do
{
d.i[ 1 ] = *p_2byte++;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
if ((UPLOAD_SIZE >> 1) == i)
*pchr++ = ' ';
} while (--i);
break;
#endif
case LOAD_CE_CODE_DEFAULT:
d.i[1] = ((uint16_t) p_2flash - (uint16_t) CeCode) >> 1;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
do
{
d.i[ 1 ] = *p_2flash++;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
if ((UPLOAD_SIZE >> 1) == i)
*pchr++ = ' ';
} while (--i);
break;
case LOAD_CE_DATA:
d.i[1] = ((uint16_t) p_4byte - CE_DATA_BASE) >> 2;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
i /= 2;
do
{
/* Stretch to 6 Stretch to 1 (default) */
d.l = memget_ce ((int32x_t *) p_4byte);
p_4byte++;
pchr = put_hex_data (pchr, d.c, 4);
*pchr++ = ' ';
} while (--i);
break;
case LOAD_CE_DATA_DEFAULT:
d.i[1] = ((uint16_t) p_4flash - (uint16_t) CeData) >> 2;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
i /= 2;
do
{
d.l = *p_4flash++;
pchr = put_hex_data (pchr, d.c, 4);
*pchr++ = ' ';
} while (--i);
break;
case LOAD_CE_DATA_MONITOR:
cnt++;
do
{
main_background ();
p_4byte = (uint32x_t *) (CE_DATA_BASE + (addr << 2));
pchr = txbuffer;
i = max (cnt, 1);
do
{
/* Stretch to 6 Stretch to 1 (default) */
d.l = memget_ce ((int32x_t *) p_4byte);
p_4byte++;
pchr = put_hex_data (pchr, d.c, 4);
*pchr++ = ' ';
} while (--i);
*pchr++ = CRET;
*pchr++ = LF;
Serial_Tx (port, txbuffer, pchr - txbuffer);
} while (Serial_CRx (port, &cb, 1) < 1);
return;
#if CLI_EEPROM
case LOAD_EEPROM:
d.l = addr;
pchr = put_hex_data (pchr, d.c, 4);
*pchr++ = ' ';
eeRead.status = memcpy_xpr (ebuff, addr, UPLOAD_SIZE);
while (_PENDING == *eeRead.status)
main_background (); // Wait for read to finish.
addr += i;
eeRead.buffer = ebuff;
do
{
d.c[ 3 ] = *eeRead.buffer++;
pchr = put_hex_data (pchr, d.c, 1);
*pchr++ = ' ';
} while (--i);
break;
#endif
case LOAD_FLASH:
d.i[1] = (uint16_t) p_1flash;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
do
{
d.c[3] = *p_1flash++;
pchr = put_hex_data (pchr, d.c, 1);
*pchr++ = ' ';
} while (--i);
break;
case LOAD_MPU_DATA:
d.i[1] = (uint16_t) p_1byte;
pchr = put_hex_data (pchr, d.c, 2);
*pchr++ = ' ';
do
{
d.c[3] = *p_1byte++;
pchr = put_hex_data (pchr, d.c, 1);
*pchr++ = ' ';
} while (--i);
break;
case LOAD_MPU_MONITOR:
cnt++;
do
{
main_background ();
p_1byte = (uint8x_t *) addr;
pchr = txbuffer;
i = max (cnt, 1);
do
{
d.c[3] = *p_1byte++;
pchr = put_hex_data (pchr, d.c, 1);
*pchr++ = ' ';
} while (--i);
*pchr++ = CRET;
*pchr++ = LF;
Serial_Tx (port, txbuffer, pchr - txbuffer);
} while (Serial_CRx (port, &cb, 1) < 1);
return;
}
*pchr++ = CRET;
*pchr++ = LF;
Serial_Tx (port, txbuffer, pchr - txbuffer);
}
}
static uint8x_t *put_hex_data (uint8x_t *p, uint8x_t *c, uint8_t width)
{
switch (width)
{
case 1:
p = put_hex (p, c[3]);
break;
case 2:
p = put_hex (p, c[2]);
p = put_hex (p, c[3]);
break;
case 4:
p = put_hex (p, c[0]);
p = put_hex (p, c[1]);
p = put_hex (p, c[2]);
p = put_hex (p, c[3]);
break;
}
return (p);
}
static uint8x_t *put_hex (uint8x_t *p, uint8_t c)
{
*p++ = htoc (c >> 4);
*p++ = htoc (c & 0x0F);
return (p);
}
/***************************************************************************
* History:
* $Log: load.c,v $
* Revision 1.14 2006/10/13 00:46:20 tvander
* Removed compile options for 6530, 6515; renamed 6511 and 6513 to trace11 and trace13; Binary verified unchanged from previous version.
*
* Revision 1.13 2006/09/09 01:08:28 gmikef
* *** empty log message ***
*
* Revision 1.12 2006/03/07 23:57:08 tvander
* Revised help system for accuracy.
* Revised help system for compile flags.
* Clean build
*
* Revision 1.11 2006/03/06 03:28:43 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.10 2006/03/03 11:24:56 Michael T. Fischer
* Prep for 6530 LCD, etc.
*
* Revision 1.9 2006/01/10 03:55:03 gmikef
* Added PDATA support for CE Outputs.
*
* Revision 1.7 2005/12/08 03:08:46 gmikef
* Manually clear PWE (disable flash writes) after each write.
*
* Revision 1.6 2005/11/03 19:17:21 tvander
* Modified to compile with new flow control
*
* Revision 1.5 2005/11/02 03:07:06 gmikef
* Xon/Xoff flow control working.
*
* Revision 1.4 2005/10/08 04:41:17 tvander
* Fixed priority inversion.
* Rewrote watchdog to work in brownout, but of course it doesn't work.
* Watchdog can now be defeated by clearing watchdog option to 0.
* Reorganized watt hour modules (at last!).
* Disabled reading of STATUS in 6521_cli because the CE's status is always SAG.
* Tested with 6521_CLI; measurements seem to work.
* Fixed other builds.
*
* Revision 1.3 2005/09/02 20:38:52 gmikef
* Modified to fit CeCode of 1.5Kbytes and support new "ce_merge".
*
* Revision 1.2 2005/08/30 01:57:06 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/28 02:24:47 gmikef
* *** empty log message ***
*
* Revision 1.3 2005/08/20 01:32:44 gmikef
* *** empty log message ***
*
* Revision 1.2 2005/08/19 01:04:37 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/18 02:56:08 gmikef
* *** empty log message ***
*
*
* 2005 August 17; 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 + -