📄 main.c
字号:
va_list ap;
va_start(ap,fmt);
vfprintf(stderr,fmt,ap);
va_end(ap);
return true;
}
static void cleanup_exception() {
fprintf(stderr, "problem during cleanup - exiting\n");
_exit(2);
}
int main(int _argc, const char* _argv[]){
int return_val=0;
argc = _argc;
argv = _argv;
verbose_level=1;
if (argc==1){
Info(0, "%s: No commands specified. "
"Try '%s --help' for list of commands.\n",
argv[0], argv[0]);
exit(1);
}
argv_ok = (char *)malloc(argc);
for (int i=1; i<argc; i++){argv_ok[i]=0;}
/* Help Screen? */
if (GetCmdParam("-h", false) || GetCmdParam("--help", false)){
printf(version, VERSION);
printf("%s\n", help_screen);
return 0;
}
if (GetCmdParam("--version", false)){
printf(version, VERSION);
return 0;
}
/* Setup Verbose Level */
const char *p = GetCmdParam("-v",false);
if (p!=NULL){
if (*p==0){verbose_level=2;} else{verbose_level = atoi(p);}
}
/* Invoke Terminal or Command Line Batch Processing */
try{
const char* val;
val = GetCmdParam("-dprog");
/* backwards compatibility, -datmel is now -dprog=avr910 */
if (GetCmdParam("-datmel", false))
val = "avr910";
// BBD: add check for NULL on -dprog
if (val && (strcmp(val, "avr910") == 0 || strcmp(val, "pavr") == 0)) {
/* Drop setuid privileges (if any - not recommended) before
trying to open the serial device, they are only needed for
direct I/O access (not ppdev/ppi) to the parallel port. */
setgid(getgid());
setuid(getuid());
device = new TAvrAtmel();
}
else if ( (val && (strcmp(val, "stk500") == 0)) || (val && (strcmp(val, "mib510") == 0)) ) {
setgid(getgid());
setuid(getuid());
device = new TStk500();
}
else if (val && (strcmp(val, "stargate") == 0)) {
device = new TAvrStargate();
}
#ifndef NO_DAPA
else if (val) {
/* The TDAPA() constructor will drop setuid privileges after
opening the lpt ioport. */
device = new TAvrDummy();
}
#endif
/* Check Device's bad command line params. */
for (int i=1; i<argc; i++){
if (argv_ok[i]==0 && strncmp(argv[i], "-d", 2)==0){
Info(0,"Invalid parameter: %s\n", argv[i]); exit(1);
}
}
if (device()==NULL){
throw Error_Device("Programming method is not selected.");
}
/* Set Current Active Segment */
if ((val=GetCmdParam("--segment"))!=NULL){
if (!device->SetSegment(val)){
Info(0, "--segment=%s: bad segment name\n", val);
}
}
/* Device Operations: */
if (GetCmdParam("--download", false)) {
motintl.Write(GetCmdParam("of"));
}
if (GetCmdParam("--erase", false)){device->ChipErase();}
/* Input file */
if ((val=GetCmdParam("if"))) {
if (GetCmdParam("--upload", false)){motintl.Read(val, true, false);}
if (GetCmdParam("--verify", false)){motintl.Read(val, false, true);}
}
if (GetCmdParam("--rd_fuses",false))
{
TByte bits;
const char *old_seg = device->TellActiveSegment();
device->SetSegment("fuse");
printf("\n");
printf("Fuse Low Byte = 0x%02x\n", device->ReadByte(AVR_FUSE_LOW_ADDR));
printf("Fuse High Byte = 0x%02x\n", device->ReadByte(AVR_FUSE_HIGH_ADDR));
printf("Fuse Extended Byte = 0x%02x\n", device->ReadByte(AVR_FUSE_EXT_ADDR));
printf("Calibration Byte = 0x%02x -- Read Only\n",
device->ReadByte(AVR_CAL_ADDR));
bits = device->ReadByte(AVR_LOCK_ADDR);
printf("Lock Bits = 0x%02x\n", bits);
printf(" BLB12 -> %d\n", ((bits & BLB12) == BLB12));
printf(" BLB11 -> %d\n", ((bits & BLB11) == BLB11));
printf(" BLB02 -> %d\n", ((bits & BLB02) == BLB02));
printf(" BLB01 -> %d\n", ((bits & BLB01) == BLB01));
printf(" LB2 -> %d\n", ((bits & LB2) == LB2));
printf(" LB1 -> %d\n", ((bits & LB1) == LB1));
printf("\n");
device->SetSegment(old_seg);
}
if ((val=GetCmdParam("--wr_fuse_l")) != NULL)
{
unsigned int bits;
const char *old_seg = device->TellActiveSegment();
device->SetSegment("fuse");
if (sscanf(val, "%x", &bits) == 1)
{
device->WriteByte( AVR_FUSE_LOW_ADDR, (TByte)bits );
printf("\nFuse Low Byte set to 0x%02x\n", (TByte)bits);
}
else
throw Error_Device("Invalid argument for --wr_fuse_l.");
device->SetSegment(old_seg);
}
if ((val=GetCmdParam("--wr_fuse_h")) != NULL)
{
unsigned int bits;
const char *old_seg = device->TellActiveSegment();
device->SetSegment("fuse");
if (sscanf(val, "%x", &bits) == 1)
{
device->WriteByte( AVR_FUSE_HIGH_ADDR, (TByte)bits );
printf("\nFuse High Byte set to 0x%02x\n", (TByte)bits);
}
else
throw Error_Device("Invalid argument for --wr_fuse_h.");
device->SetSegment(old_seg);
}
if ((val=GetCmdParam("--wr_fuse_e")) != NULL)
{
unsigned int bits;
const char *old_seg = device->TellActiveSegment();
device->SetSegment("fuse");
if (sscanf(val, "%x", &bits) == 1)
{
device->WriteByte( AVR_FUSE_EXT_ADDR, (TByte)bits );
printf("\nFuse Extended Byte set to 0x%02x\n", (TByte)bits);
}
else
throw Error_Device("Invalid argument for --wr_fuse_e.");
device->SetSegment(old_seg);
}
if ((val=GetCmdParam("--wr_lock")) != NULL)
{
unsigned int bits;
if (sscanf(val, "%x", &bits) == 1)
{
device->WriteLockBits( (TByte)bits );
printf("\nLock Bits set to 0x%02x\n", (TByte)bits);
}
else
throw Error_Device("Invalid argument for --wr_lock.");
}
if (GetCmdParam("--lock", false))
{
Info(0, "NOTE: '--lock' is deprecated. Used '--wr_lock' instead.\n");
device->WriteLockBits(0xFC);
printf("\nLock Bits set to 0x%02x\n", 0xfc);
}
/* enter terminal */
if (GetCmdParam("--terminal", false)){terminal.Run();}
/* Check bad command line parameters */
for (int i=1; i<argc; i++){
if (argv_ok[i]==0){Info(0,"Invalid parameter: %s\n", argv[i]);}
}
}
catch(Error_C& errC){perror("Error"); errC.print(); return_val=1;}
catch(Error_Device& errDev){errDev.print(); return_val=2;}
catch(Error_MemoryRange& x){
Info(0, "Address out of memory range.\n"); return_val=3;
}
std::set_terminate(cleanup_exception);
return return_val;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -