diff options
| author | cpldcpu <cpldcpu@gmail.com> | 2014-01-05 19:35:47 +0100 | 
|---|---|---|
| committer | cpldcpu <cpldcpu@gmail.com> | 2014-01-05 19:35:47 +0100 | 
| commit | 568359df2c8ad4293dfc14b57db9b01fb2f1adab (patch) | |
| tree | 5a783fd1979d2084c1d7caf912a8f53e05cdd72d /commandline/library | |
| parent | 570ffd3e2f81f4ec03ed362c94b26573748864a1 (diff) | |
| download | micronucleus-568359df2c8ad4293dfc14b57db9b01fb2f1adab.tar.gz micronucleus-568359df2c8ad4293dfc14b57db9b01fb2f1adab.tar.bz2 micronucleus-568359df2c8ad4293dfc14b57db9b01fb2f1adab.zip | |
commandline: Support for new v2 transmission protocol
The block transfer is now done in the address and indexfield of a
setup-packet to save a lot of memory in the firmware:
This requires twice the number of transmissions, but is effectively
faster due to less bus congestion and resends.
Diffstat (limited to 'commandline/library')
| -rw-r--r-- | commandline/library/micronucleus_lib.c | 29 | 
1 files changed, 28 insertions, 1 deletions
| diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 51b42e7..dd10d25 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -176,6 +176,33 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz      // ask microcontroller to write this page's data      if (pagecontainsdata) { + +      if (deviceHandle->version.major == 1) { +        // Firmware rev.1 transfers a page as a single block +        // ask microcontroller to write this page's data +        res = usb_control_msg(deviceHandle->device, +               USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, +               1, +               page_length, address, +               page_buffer, page_length, +               MICRONUCLEUS_USB_TIMEOUT); +      } else if (deviceHandle->version.major >= 2) { +        // Firmware rev.2 uses individual set up packets to transfer data +        res = usb_control_msg(deviceHandle->device, USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, page_length, address, NULL, 0, MICRONUCLEUS_USB_TIMEOUT); +        if (res) return -1; +        int i; +         +        for (i=0; i< page_length; i+=4) +        { +          int w1,w2; +          w1=(page_buffer[i+1]<<8)+(page_buffer[i+0]<<0); +          w2=(page_buffer[i+3]<<8)+(page_buffer[i+2]<<0); +           +          res = usb_control_msg(deviceHandle->device, USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 3, w1, w2, NULL, 0, MICRONUCLEUS_USB_TIMEOUT); +          if (res) return -1; +        }      +      }   +    /*        res = usb_control_msg(deviceHandle->device,               USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE,               1, @@ -184,7 +211,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz               MICRONUCLEUS_USB_TIMEOUT);        if (res != page_length) return -1; - +    */        // give microcontroller enough time to write this page and come back online        delay(deviceHandle->write_sleep);      } | 
