X-Git-Url: http://git.smho.de/gw/?p=owTools.git;a=blobdiff_plain;f=src%2FowInterface.cpp;h=b02c04768626987b4c0dc700a0a52c9aa01974ed;hp=c08ea2d8a8ebb1aebac720e6dcade876dd02195a;hb=17ea6dc449cad650a4c783446ab048c12e44c666;hpb=03de69ffeb1f25ccbc7757c9600c38316c262a19 diff --git a/src/owInterface.cpp b/src/owInterface.cpp index c08ea2d..b02c047 100755 --- a/src/owInterface.cpp +++ b/src/owInterface.cpp @@ -119,12 +119,12 @@ int owInterface::testCRC16(std::vector data) { return calcCRC16(data)==0xB001; } -void owInterface::resetFlasher() { // go back from Bootloader +void owInterface::resetFlasher(uint64_t id) { // go back from Bootloader std::vector data; data.push_back(0x89); Wait_Free(); snum_t snum; - snum.num=0xfa55aa55aa55aaa3; + snum.num=id; MatchRom(snum); if (log->last()==OWLOG_ERROR) {Free(); return;} Communicate(&data, 1, 0); @@ -134,21 +134,21 @@ void owInterface::resetFlasher() { // go back from Bootloader usleep(50); } -void owInterface::resetID() { +void owInterface::resetID(uint64_t id) { std::vector data; data.push_back(0x8B); Wait_Free(); snum_t snum; - snum.num=0xfa55aa55aa55aaa3; + snum.num=id; MatchRom(snum); if (log->last()==OWLOG_ERROR) {Free(); return;} Communicate(&data, 1, 0); Free(); } -int owInterface::programmPage(int pagenr, std::vector page, int pagesize) { +int owInterface::programmPage(uint64_t id,int pagenr, std::vector page, int pagesize) { snum_t snum; - snum.num=0xfa55aa55aa55aaa3; + snum.num=id; // printf("programm page %i",pagenr); @@ -249,11 +249,7 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr if (hf->lastError==1) {log->set(OWLOG_ERROR,"CRC Error in HEX-File %s",filename.c_str());return -1;} if (hf->lastError==2) {log->set(OWLOG_ERROR,"Error interpreting HEX-File %s",filename.c_str());return -2;} if (hf->lastError==3) {log->set(OWLOG_ERROR,"File could not be opened: %s",filename.c_str());return -3;} - unsigned int blcount=hf->getBlockCount(64); - if (blcount>118) { - log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount); - return -5; - } + log->set(OWLOG_INFO,"Try to start Bootloader on device %llX",dev.num); int r=maxrepeat+1; int found; @@ -283,6 +279,10 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr found=1; break; } + if (dev->getNum().num==0x8A57AA57AA57AAA3) { + found=2; + break; + } } if (found==0) log->set(OWLOG_WARNING,"Bootloader not found"); r--; @@ -291,16 +291,43 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr log->set(OWLOG_ERROR,"Can not start Bootloader on this device %llX",dev.num); return -4; } + + unsigned int blcount=0; + + int blsize=64; + uint64_t id=0; + + if (found==1) { + log->set(OWLOG_INFO,"Bootloader on ATtiny84A found. Pagesize = 64 bytes"); + blsize=64; + blcount=hf->getBlockCount(64); + id=0xfa55aa55aa55aaa3; + if (blcount>118) { + log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount); + return -5; + } + } + if (found==2) { + log->set(OWLOG_INFO,"Bootloader on ATmega328PB found. Pagesize = 128 bytes"); + blsize=128; + blcount=hf->getBlockCount(128); + id=0x8A57AA57AA57AAA3; + if (blcount>248) { + log->set(OWLOG_ERROR,"Code to big, max 31744 Byte allowed (248 Pages). Code has %i pages!",blcount); + return -5; + } + + } log->set(OWLOG_INFO,"Start Programm %i Pages",blcount); int rp=0; int er=0; unsigned int i =0; for ( i= 0; i < blcount; i++) { - std::vector blk = hf->getBlock(i*64, 64); + std::vector blk = hf->getBlock(i*blsize, blsize); int errc = maxrepeat*5; while (errc != 0) { log->clear(); - if (programmPage(i, blk, 64) >= 0) { + if (programmPage(id,i, blk,blsize) >= 0) { if (progress) {printf("#");fflush(stdout);} break; } @@ -322,14 +349,14 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr } else { if (resetid) { log->set(OWLOG_INFO,"Set 1-Wire ID to ID in hexfile...",blcount); - resetID(); + resetID(id); #ifdef LINUX sleep(3); #endif #ifdef WIN Sleep(3000); #endif - resetID(); + resetID( id); #ifdef LINUX sleep(3); #endif @@ -342,14 +369,14 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr log->set(OWLOG_INFO,"Back from bootloader to normal device...",blcount); - resetFlasher(); + resetFlasher(id); #ifdef LINUX sleep(1); #endif #ifdef WIN Sleep(1000); #endif - resetFlasher(); + resetFlasher(id); #ifdef LINUX sleep(3); #endif