Example #1
0
/*
 * USBaspの通信ブロック単位(200bytes)で分割して書き込む
 */
int usbasp_blockwrite(
    int      function,
    int      address,
    unsigned char *buffer,
    int      n_bytes,
    int      page_size,
    unsigned char  flags
)
{
    unsigned char cmd[4];
    int blocksize, n;
    int top            = address;
    int wbytes         = n_bytes;
    unsigned char  blockflags = USBASP_BLOCKFLAG_FIRST;

    while (wbytes > 0) {

		if (function == USBASP_FUNC_WRITEEEPROM) {
			blocksize = 1;
			wbytes -= 1;
        } else if (wbytes > USBASP_WRITEBLOCKSIZE) {
            blocksize = USBASP_WRITEBLOCKSIZE;
            wbytes   -= USBASP_WRITEBLOCKSIZE;
        } else {
            blocksize   = wbytes;
            wbytes      = 0;
            blockflags |= USBASP_BLOCKFLAG_LAST;
        }

        cmd[0] = address & 0xFF;
        cmd[1] = address >> 8;
        cmd[2] = page_size;
        cmd[3] = blockflags | flags;
        blockflags = 0;

        n = usbasp_transmit(0, function, cmd, buffer, blocksize);
		if (function == USBASP_FUNC_WRITEEEPROM) {
			delay_ms(Device->EepromWait);
		}

        if (n != blocksize)
            break;

        buffer  += blocksize;
        address += blocksize;

#if AVRSPX
        report_update(n);
#else
        //@ report_progress (address, n_bytes, NULL);
#endif
    }

    return address - top;
}
Example #2
0
/*
 * USBaspの通信ブロック単位(200bytes)で分割して読み込む
 */
int usbasp_paged_load_sub(int function, int address,
                          unsigned char *buffer, int n_bytes, unsigned char flags)
{
    int n;
    unsigned char cmd[4];
    int wbytes = n_bytes;
    int blocksize;
    
    while (wbytes > 0) {
        if (wbytes > USBASP_READBLOCKSIZE) {
            blocksize = USBASP_READBLOCKSIZE;
            wbytes   -= USBASP_READBLOCKSIZE;
        } else {
            blocksize = wbytes;
            wbytes    = 0;
        }
        
        cmd[0] = address & 0xFF;
        cmd[1] = address >> 8;
        cmd[2] = 0x5A;              //@@ magic no by t.k
        cmd[3] = flags;             //@@
        
        n = usbasp_transmit(1, function, cmd, buffer, blocksize);
        
        if (n != blocksize) {
            fprintf(stderr, "%s: error: wrong reading bytes %x\n",
                    progname, n);
            return -1;
        }
        
        buffer  += blocksize;
        address += blocksize;
#if AVRSPX
        report_update(n);
#else
        //@ report_progress (address, n_bytes, NULL);
#endif
    }
    
    return n_bytes;
}
Example #3
0
void loop() {
  scan();
  report_update();
}