diff options
author | Zach Eveland <zeveland@blacklabel-development.com> | 2011-10-21 20:06:17 -0400 |
---|---|---|
committer | Zach Eveland <zeveland@blacklabel-development.com> | 2011-10-21 20:06:17 -0400 |
commit | b9eece6584577968a7bcd04249039408a68ba4be (patch) | |
tree | 254b2917a5f28589a58634facf19b2df0fd3273d /bootloaders/nuevo_diskloader/src | |
parent | c83d85b87a658751f8e28735c1f08b37898b2b64 (diff) |
some progress on responding to parameter requests
Diffstat (limited to 'bootloaders/nuevo_diskloader/src')
-rw-r--r-- | bootloaders/nuevo_diskloader/src/DiskLoader.cpp | 153 | ||||
-rw-r--r-- | bootloaders/nuevo_diskloader/src/USBCore.cpp | 14 |
2 files changed, 92 insertions, 75 deletions
diff --git a/bootloaders/nuevo_diskloader/src/DiskLoader.cpp b/bootloaders/nuevo_diskloader/src/DiskLoader.cpp index 5f7139c..4f9c793 100644 --- a/bootloaders/nuevo_diskloader/src/DiskLoader.cpp +++ b/bootloaders/nuevo_diskloader/src/DiskLoader.cpp @@ -122,80 +122,97 @@ int main() u16 address = 0; for (;;) { + while (Serial.available() <= 0) + ; + + u8 cmd = Serial.read(); + // Read packet contents + u8 len; + const u8* rs = _readSize; + for (;;) + { + u8 c = pgm_read_byte(rs++); + len = pgm_read_byte(rs++); + if (c == cmd || c == 0) + break; + } + _timeout = 0; + // Read params + USB_Recv(CDC_RX, packet, len); -// if (Serial.available() > 0) { - while (Serial.available() <= 0) - ; + // Send a response + u8 send = 0; + const u8* pgm = _consts+7; + if (STK_GET_PARAMETER == cmd) + { + u8 i = packet[0] - 0x80; + if (i > 2) + i = (i==0x18) ? 3 : 4; // 0x80:HW_VER,0x81:SW_MAJOR,0x82:SW_MINOR,0x18:3 or 0 + pgm = _consts + i + 3; + send = 1; + } + else if (STK_UNIVERSAL == cmd) + { + if (packet[0] == 0x30) + pgm = _consts + packet[2]; + send = 1; + } + else if (STK_READ_SIGN == cmd) + { + pgm = _consts; + send = 3; + } + else if (STK_LOAD_ADDRESS == cmd) + { + address = *((u16*)packet); // word address + address += address; + } + else if (STK_PROG_PAGE == cmd) + { + Program(CDC_RX, address, packet[1]); + } + else if (STK_READ_PAGE == cmd) + { + send = packet[1]; + pgm = (const u8*)address; + address += send; + } + + // Check sync + if (Serial.available() > 0 && Serial.read() != ' ') + break; +// Serial.write(STK_INSYNC); + USB_Send(CDC_TX, &_inSync, 1); - u8 cmd = Serial.read(); - // Read packet contents - u8 len; - const u8* rs = _readSize; - for (;;) - { - u8 c = pgm_read_byte(rs++); - len = pgm_read_byte(rs++); - if (c == cmd || c == 0) - break; - } - _timeout = 0; - // Read params - USB_Recv(CDC_RX, packet, len); - - // Send a response - u8 send = 0; - const u8* pgm = _consts+7; - if (STK_GET_PARAMETER == cmd) - { - u8 i = packet[0] - 0x80; - if (i > 2) - i = (i==0x18) ? 3 : 4; // 0x80:HW_VER,0x81:SW_MAJOR,0x82:SW_MINOR,0x18:3 or 0 - pgm = _consts + i + 3; - send = 1; - } - else if (STK_UNIVERSAL == cmd) - { - if (packet[0] == 0x30) - pgm = _consts + packet[2]; - send = 1; - } - else if (STK_READ_SIGN == cmd) - { - pgm = _consts; - send = 3; - } - else if (STK_LOAD_ADDRESS == cmd) - { - address = *((u16*)packet); // word address - address += address; - } - else if (STK_PROG_PAGE == cmd) - { - Program(CDC_RX, address, packet[1]); - } - else if (STK_READ_PAGE == cmd) - { - send = packet[1]; - pgm = (const u8*)address; - address += send; - } - - // Check sync - if (Serial.available() > 0 && Serial.read() != ' ') - break; - Serial.write(STK_INSYNC); - // u8 i; // for (i=0; i<send; i++) { // Serial.write(pgm[i]); // } - - // Send ok - Serial.write(STK_OK); - - if ('Q' == cmd) - break; -// } +// Serial.write(0x01); +// u8 i; +// for (i=0; i<send; i++) { +// Serial.write(); +// } + +// if (send > 0) +// USB_Send(CDC_TX, pgm, send); + +// if (send) { +//// USB_Send(CDC_TX|TRANSFER_PGM, pgm, send); +// u8 _foo; +// _foo = 0x01; +// USB_Send(CDC_TX|TRANSFER_PGM, &_foo, 1); +// +// } + if (send) + Serial.write(0x01); + + // Send ok +// Serial.write(STK_OK); + USB_Send(CDC_TX|TRANSFER_RELEASE, &_ok, 1); + + if ('Q' == cmd) + break; } } } diff --git a/bootloaders/nuevo_diskloader/src/USBCore.cpp b/bootloaders/nuevo_diskloader/src/USBCore.cpp index bf6a6d9..8b7ef82 100644 --- a/bootloaders/nuevo_diskloader/src/USBCore.cpp +++ b/bootloaders/nuevo_diskloader/src/USBCore.cpp @@ -268,14 +268,14 @@ int USB_Send(u8 ep, const void* d, int len) while (len) { u8 n = USB_SendSpace(ep); - if (n == 0) - { - if (!(--timeout)) - return -1; +// if (n == 0) +// { +// if (!(--timeout)) +// return -1; // delay(1); - _delay_ms(1); - continue; - } +// _delay_ms(1); +// continue; +// } if (n > len) n = len; |