X-Git-Url: http://git.linex4red.de/pub/USBaspLoader.git/blobdiff_plain/c99e4b0f4e8dc636060fca152df271298caa8342..875edf3ae79b91102f59f69f7b225cb752f818df:/firmware/main.c diff --git a/firmware/main.c b/firmware/main.c index 4a94194..fd5dd48 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -20,6 +20,8 @@ #include +#include + #include @@ -46,6 +48,15 @@ static void leaveBootloader() __attribute__((__noreturn__)); #define USBASP_FUNC_WRITEEEPROM 8 #define USBASP_FUNC_SETLONGADDRESS 9 +// additional USBasp Commands +#define USBASP_FUNC_SETISPSCK 10 +#define USBASP_FUNC_TPI_CONNECT 11 +#define USBASP_FUNC_TPI_DISCONNECT 12 +#define USBASP_FUNC_TPI_RAWREAD 13 +#define USBASP_FUNC_TPI_RAWWRITE 14 +#define USBASP_FUNC_TPI_READBLOCK 15 +#define USBASP_FUNC_TPI_WRITEBLOCK 16 +#define USBASP_FUNC_GETCAPABILITIES 127 /* ------------------------------------------------------------------------ */ #ifndef ulong @@ -111,8 +122,6 @@ static uchar currentRequest; static const uchar currentRequest = 0; #endif -static unsigned char wdtstatus; - static const uchar signatureBytes[4] = { #ifdef SIGNATURE_BYTES SIGNATURE_BYTES @@ -126,6 +135,8 @@ static const uchar signatureBytes[4] = { 0x1e, 0x94, 0x06, 0 #elif defined (__AVR_ATmega328P__) 0x1e, 0x95, 0x0f, 0 +#elif defined (__AVR_ATmega1284P__) + 0x1e, 0x97, 0x05, 0 #else # error "Device signature is not known, please edit main.c!" #endif @@ -146,8 +157,6 @@ static void leaveBootloader() GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (0 << IVSEL); /* move interrupts to application flash section */ - WDTCR = wdtstatus; - /* We must go through a global function pointer variable instead of writing * ((void (*)(void))0)(); * because the compiler optimizes a constant 0 to "rcall 0" which is not @@ -208,7 +217,7 @@ static uchar replyBuffer[4]; } replyBuffer[3] = rval; len = 4; - }else if(rq->bRequest == USBASP_FUNC_ENABLEPROG){ + }else if((rq->bRequest == USBASP_FUNC_ENABLEPROG) || (rq->bRequest == USBASP_FUNC_SETISPSCK)){ /* replyBuffer[0] = 0; is never touched and thus always 0 which means success */ len = 1; }else if(rq->bRequest >= USBASP_FUNC_READFLASH && rq->bRequest <= USBASP_FUNC_SETLONGADDRESS){ @@ -258,6 +267,7 @@ uchar isLast; for(i = 0; i < len;){ #if HAVE_BLB11_SOFTW_LOCKBIT if (CURRENT_ADDRESS >= (addr_t)(BOOTLOADER_ADDRESS)) { + return 1; } #endif i += 2; @@ -333,8 +343,6 @@ uchar i = 0; int __attribute__((noreturn)) main(void) { /* initialize */ - wdtstatus = WDTCR; - wdt_disable(); /* main app may have enabled watchdog */ bootLoaderInit(); odDebugInit(); DBG1(0x00, 0, 0); @@ -343,6 +351,7 @@ int __attribute__((noreturn)) main(void) GICR = (1 << IVSEL); /* move interrupts to boot flash section */ #endif if(bootLoaderCondition()){ + wdt_disable(); /* main app may have enabled watchdog */ #if BOOTLOADER_CAN_EXIT uchar i = 0, j = 0; #endif