summaryrefslogtreecommitdiffstats
path: root/commandline/library/micronucleus_lib.c
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2014-05-01 19:15:05 +0200
committercpldcpu <cpldcpu@gmail.com>2014-05-01 19:15:05 +0200
commit7e103740357273dcf1143bd04a1cb7fa957be89a (patch)
treed17dc4cc9b3da13520a50c1d9b4caf0bc994c984 /commandline/library/micronucleus_lib.c
parent0b653a2d0d74c1ad0ed6e2d0b54cdf6e46ab67a4 (diff)
downloadmicronucleus-7e103740357273dcf1143bd04a1cb7fa957be89a.tar.gz
micronucleus-7e103740357273dcf1143bd04a1cb7fa957be89a.tar.bz2
micronucleus-7e103740357273dcf1143bd04a1cb7fa957be89a.zip
commandline: Added signature to configurationreply
Diffstat (limited to 'commandline/library/micronucleus_lib.c')
-rw-r--r--commandline/library/micronucleus_lib.c74
1 files changed, 49 insertions, 25 deletions
diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c
index d6b4243..f7b51d5 100644
--- a/commandline/library/micronucleus_lib.c
+++ b/commandline/library/micronucleus_lib.c
@@ -62,32 +62,56 @@ micronucleus* micronucleus_connect(int fast_mode) {
nucleus->device = usb_open(dev);
- // get nucleus info
- unsigned char buffer[4];
- int res = usb_control_msg(nucleus->device, USB_ENDPOINT_IN| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, 0, 0, (char *)buffer, 4, MICRONUCLEUS_USB_TIMEOUT);
- assert(res >= 4);
-
- nucleus->flash_size = (buffer[0]<<8) + buffer[1];
- nucleus->page_size = buffer[2];
- nucleus->pages = (nucleus->flash_size / nucleus->page_size);
- if (nucleus->pages * nucleus->page_size < nucleus->flash_size) nucleus->pages += 1;
-
- nucleus->bootloader_start = nucleus->pages*nucleus->page_size;
-
- if ((nucleus->version.major>=2)&&(!fast_mode)) {
- // firmware v2 reports more aggressive write times. Add 2ms if fast mode is not used.
- nucleus->write_sleep = (buffer[3] & 127) + 2;
- } else {
+ if (nucleus->version.major>=2) { // Version 2.x
+ // get nucleus info
+ unsigned char buffer[6];
+ int res = usb_control_msg(nucleus->device, USB_ENDPOINT_IN| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, 0, 0, (char *)buffer, 6, MICRONUCLEUS_USB_TIMEOUT);
+ assert(res >= 4);
+
+ nucleus->flash_size = (buffer[0]<<8) + buffer[1];
+ nucleus->page_size = buffer[2];
+ nucleus->pages = (nucleus->flash_size / nucleus->page_size);
+ if (nucleus->pages * nucleus->page_size < nucleus->flash_size) nucleus->pages += 1;
+
+ nucleus->bootloader_start = nucleus->pages*nucleus->page_size;
+
+ if ((nucleus->version.major>=2)&&(!fast_mode)) {
+ // firmware v2 reports more aggressive write times. Add 2ms if fast mode is not used.
+ nucleus->write_sleep = (buffer[3] & 127) + 2;
+ } else {
+ nucleus->write_sleep = (buffer[3] & 127);
+ }
+
+ // if bit 7 of write sleep time is set, divide the erase time by four to
+ // accomodate to the 4*page erase of the ATtiny841/441
+ if (buffer[3]&128) {
+ nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages / 4;
+ } else {
+ nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages;
+ }
+
+ nucleus->signature1 = buffer[4];
+ nucleus->signature2 = buffer[5];
+
+ } else { // Version 1.x
+ // get nucleus info
+ unsigned char buffer[4];
+ int res = usb_control_msg(nucleus->device, USB_ENDPOINT_IN| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, 0, 0, (char *)buffer, 4, MICRONUCLEUS_USB_TIMEOUT);
+ assert(res >= 4);
+
+ nucleus->flash_size = (buffer[0]<<8) + buffer[1];
+ nucleus->page_size = buffer[2];
+ nucleus->pages = (nucleus->flash_size / nucleus->page_size);
+ if (nucleus->pages * nucleus->page_size < nucleus->flash_size) nucleus->pages += 1;
+
+ nucleus->bootloader_start = nucleus->pages*nucleus->page_size;
+
nucleus->write_sleep = (buffer[3] & 127);
- }
-
- // if bit 7 of write sleep time is set, divide the erase time by four to
- // accomodate to the 4*page erase of the ATtiny841/441
- if (buffer[3]&128) {
- nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages / 4;
- } else {
- nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages;
- }
+ nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages;
+
+ nucleus->signature1 = 0;
+ nucleus->signature2 = 0;
+ }
}
}
}