📄 parser.c
字号:
// Parser
#include <REG1210.H>
#include "mvp.h"
unsigned char k1,k2,k3,vdds;
unsigned char data i,j,k, count;
void bakekey(void)
{ unsigned char c;
if (high(k1)) { //Pre-bake: Program Slave CPU with AA and check result
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
c=util(CPUS,0x0f); putok(c); putcr();
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
nokey();
}
if (high(k2)) { //After-bake: Slave Retention Check only
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
c=util(CPUS,0x0c); putok(c); putcr();
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
nokey();
}
if(high(k3)) { // After-bake: Slave Retention Check and March Test
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
c|=util(CPUS,0x0d); putok(c); putcr();
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
nokey();
}
}
void pgmkey(void)
{ unsigned char c;
if(high(k1)) { // Program from CPUA to CPUS
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
putstr("Copy buffer->target ");
c|=util(CPUS,0x02); putok(c); putcr();
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
nokey();
}
if(high(k2)) { // Program from CPUS to CPUA
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
putstr("Copy target->buffer");
c|=util(CPUA,0x02); putok(c); putcr();
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
nokey();
}
if(high(k3)) { //
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
putstr("Secure ");
c|=util(CPUS,0x01); putok(c); putcr();
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
nokey();
}
}
unsigned char fxn_number(unsigned char k)
{ unsigned char fxn;
if (k=='U') fxn=rx_hex_echo();
if (k=='C') fxn=0x02;//Copy
if (k=='B') fxn=0x04;//Blank
if (k=='V') fxn=0x03;//Verify
if (k=='X') fxn=0x01;//Secure
if (k=='K') fxn=0x05;//Mass Erase
if (k=='I') fxn=0xff;//Info
return(fxn);
}
void cmd_parser(void)
{ unsigned char kk,extend, cpu,c,b,t,d,r,err,done, trial,d10,d1, fxn;
unsigned int a;
cpu=nvcp->cpu;
//if (nvcp->cpu==CPUA) putstr("CPUA");
//if (nvcp->cpu==CPUS) putstr("CPUS");
// Note F1 is used for Echo Control Flag
while (SET){
putcr();
tx_byte('>');
while(1){
if (!rxmt) break; // Found Terminal Key Input
if (nvcp->mode==Bake)bakekey();
if (nvcp->mode==Program)pgmkey();
}
k=rx_byte_echo(); //get & parse command
extend=0;
if (k=='E') {
F1 = !F1;
} else if (k=='R') { //RR RW: dummy commands
if (rx_byte_echo()=='W') {
rx_hex_echo();
rx_hex_echo();
} else {
//tx_hex(rx_hex_echo());
tx_hex(fpm(cpu|SRD,rx_hex_echo(),0));
}
} else if (k=='H') { //Help Screen
screen();
} else if (k=='M') {
putok(fpm(cpu|FME,rx_hex_double_echo(),0xff)); //Mnnnn: Mass Erase
} else if (k=='L') {
done=0; while(!done){
while(rx_byte_echo()!=':'){;}
c=0; err=0; i=0;
b=rx_hex_echo(); c+=b; //bytecount
a=rx_hex_double_echo(); d=a; t=a>>8; c=c+d+t; // address
t=rx_hex_echo(); c+=t; // type
while(i!=b){
d=rx_hex_echo(); c+=d; trial=0;
while(trial!=99){
fpm(cpu|FWR,a,d);
if (d!=fpm(cpu|FRD,a,0)) { trial++;
if (trial>3) {err=1; trial=99;}
} else trial=99;
} a++; i++;
}
c+=rx_hex_echo(); r='.';
if (err!=0) {r='X'; done=1;} else if(c!=0) {r='E'; done=1;}
else if(t==1) {r='T'; done=1;}
tx_byte(r);
}
beep(700,100);
} else if (k=='a') {
resetpfpm(); display(cpu,k,rx_hex_double_echo()); release();
} else if (k=='>' || k=='<' || k=='r' ) {
resetpfpm(); display(cpu,k,0); release();
} else if (k=='Z') {
release();
beep(700,100);
} else if (k=='F') { //Flash RD/WR
c=resetpfpm(); if (c!=0) {putstr("\nReset Error");}
kk=rx_byte_echo();
if (kk=='R' && cpu != CPUBOTH) tx_hex(fpm(cpu|FRD,rx_hex_double_echo(),0));
else if(kk=='W') putok(fpm(cpu|FWR,rx_hex_double_echo(),rx_hex_echo()));
else if(kk=='P') putok(fpm(cpu|FPE,rx_hex_double_echo(),0xff));
release();
/*} else if (k=='S') { //SFR RD/WR
kk=rx_byte_echo();
if (kk=='R' && cpu != CPUBOTH) tx_hex(fpm(cpu|SRD,rx_hex_echo(),0));
else if (kk=='W') tx_hex(fpm(cpu|SWR,rx_hex_echo(),rx_hex_echo())); */
} else if (k=='U' || k=='C' || k=='B' || k=='V'|| k=='X'|| k=='K' || k=='I') {
c=resetpfpm();
if (c!=0) {putstr("\nReset Error");} else {
if (cpu==CPUS) {
if (target.exist==0xff) {
putstr(" Target Device Not Found");
} else if (target.exist==0) {
putstr(" Target Unknown HWPC/ID=");
tx_hex(target.HWPC1);
tx_hex(target.HWPC0);
tx_hex(target.HWID);
} else {
c=util(cpu,fxn_number(k));
putstr(" MSC");
if (target.part==MSC1210) putstr("1210Y");
if (target.part==MSC1211) putstr("1211Y");
if (target.part==MSC1212) putstr("1212Y");
tx_byte(target.y+'0'); putspace1();
d10=target.kbyte/10; d1=target.kbyte-d10*10;
tx_byte(d10+'0');tx_byte(d1+'0'); putstr("kByte ");
if (target.secure==1) putstr("SECURED ");
putok(c); putcr();
}
} else c=util(cpu,fxn_number(k)); // Aux Functions
if (c==0) {led(GREEN,ON); led(RED,OFF);} else {led(GREEN,OFF); led(RED,ON);}
release();
if (c==0) beep(700,100); else beep(1000,100);
beep(700,100);
}
} else if (k=='S') { // Slave CPU Command
cpu=CPUS; extend=1;
} else if (k=='A') { // Aux CPU Command
cpu=CPUA; extend=1;
} else if (k=='T') { // Both Slave and Aux CPU Command
cpu=CPUBOTH; extend=1;
} else if (k=='I') {
}
if (extend==1){
EAI=0; EA=0;
write_flash_chk(&(nvnp->cpu),cpu,FDM);
EAI=1; EA=1; updatenv();
}
}
}
unsigned char adc_delay=0;
void aux_int_isr(void) interrupt 6
{
if (PAI==5) { // MSINT
PAI=MSINT; //Dummy read (PAI is read only)
if (t0!=0) t0--; //GP Timer
if (t1!=0) {
t1--;
if(PWM!=0) PWM -= 1;
} else PWMCON=0; //Tone Timer
if (t2!=0) t2--;
}
if (PAI==6) { // ADCINT
if (adc_delay==3){
if (ADMUX == 0x08) {k1=ADRESH; ADMUX=0x18; }
else if (ADMUX == 0x18) {k2=ADRESH; ADMUX=0x28; }
else if (ADMUX == 0x28) {k3=ADRESH; ADMUX=0x78; }
else if (ADMUX == 0x78) {vdds=ADRESH; ADMUX=0x08; }
adc_delay=0;
} else adc_delay++;
PAI=ADRESL; //Dummy read
}
AI=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -