uchar usbFunctionWrite(uchar *data, uchar len) { uchar retVal = 0; uchar i; /* check if programmer is in correct write state */ if ((prog_state != PROG_STATE_WRITEFLASH) && (prog_state != PROG_STATE_WRITEEEPROM)) { return 0xff; } for (i = 0; i < len; i++) { if (prog_state == PROG_STATE_WRITEFLASH) { /* Flash */ if (prog_pagesize == 0) { /* not paged */ ispWriteFlash(prog_address, data[i], 1); } else { /* paged */ ispWriteFlash(prog_address, data[i], 0); prog_pagecounter --; if (prog_pagecounter == 0) { ispFlushPage(prog_address, data[i]); prog_pagecounter = prog_pagesize; } } } else { /* EEPROM */ ispWriteEEPROM(prog_address, data[i]); } prog_nbytes --; if (prog_nbytes == 0) { prog_state = PROG_STATE_IDLE; if ((prog_blockflags & PROG_BLOCKFLAG_LAST) && (prog_pagecounter != prog_pagesize)) { /* last block and page flush pending, so flush it now */ ispFlushPage(prog_address, data[i]); } retVal = 1; // Need to return 1 when no more data is to be received } prog_address ++; } return retVal; }
uchar usbFunctionWrite(uchar *data, uchar len) { uchar retVal = 0; uchar i; // check if programmer is in correct write state if ( (prog_state != PROG_STATE_WRITEFLASH) &&(prog_state != PROG_STATE_WRITEEEPROM) &&(prog_state != STATE_WRITE_CDC) &&(prog_state != STATE_SET_CDC_MODE) ) return 0xff; for (i = 0; i < len; i++) { if (prog_state == PROG_STATE_WRITEFLASH) { if (prog_pagesize == 0) ispWriteFlash(prog_address, data[i], 1); else ispWriteFlash(prog_address, data[i], 0); prog_pagecounter --; if (prog_pagecounter == 0) { ispFlushPage(prog_address, data[i]); prog_pagecounter = prog_pagesize; } prog_nbytes --; } else if (prog_state == PROG_STATE_WRITEEEPROM) { ispWriteEEPROM(prog_address, data[i]); prog_nbytes --; } else if (prog_state == STATE_WRITE_CDC) Oncharrecived(data[i]); else if (prog_state == STATE_SET_CDC_MODE) CDC_mode[i] = data[i]; if (prog_nbytes == 0) { prog_state = PROG_STATE_IDLE; if ((prog_blockflags & PROG_BLOCKFLAG_LAST) && (prog_pagecounter != prog_pagesize)) ispFlushPage(prog_address, data[i]); retVal = 1; // Need to return 1 when no more data is to be received } prog_address ++; } if (prog_state == STATE_SET_CDC_MODE) prog_state = PROG_STATE_IDLE; return retVal; }