summaryrefslogtreecommitdiffstats
path: root/firmware/main.c
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2013-12-31 00:54:19 +0100
committercpldcpu <cpldcpu@gmail.com>2013-12-31 00:54:19 +0100
commit58514cfadd15985ff3ac279679930d372f705687 (patch)
treeb4e0fc8026ab82cc4af5a8dc6dd60fe384199ad9 /firmware/main.c
parentc76ecfb6151c615cc35774c404b956a16c14085c (diff)
downloadmicronucleus-58514cfadd15985ff3ac279679930d372f705687.tar.gz
micronucleus-58514cfadd15985ff3ac279679930d372f705687.tar.bz2
micronucleus-58514cfadd15985ff3ac279679930d372f705687.zip
firmware: Directly mapped command register saves 12 btes
Diffstat (limited to 'firmware/main.c')
-rw-r--r--firmware/main.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/firmware/main.c b/firmware/main.c
index 447ff20..d0a3edd 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -36,10 +36,11 @@
register uint8_t command asm( "r3" ); // register saves many bytes
enum {
- cmd_nop=0,
- cmd_erase_application,
- cmd_write_page,
- cmd_exit
+ cmd_nop=0, // also: get device info
+ cmd_transfer_page=1,
+ cmd_erase_application=2,
+ cmd_exit=4,
+ cmd_write_page=5,
};
// Definition of sei and cli without memory barrier keyword to prevent reloading of memory variables
@@ -162,22 +163,18 @@ static uint8_t usbFunctionSetup(uint8_t data[8]) {
if (rq->bRequest == 0) { // get device info
usbMsgPtr = replyBuffer;
return 4;
- } else if (rq->bRequest == 1) { // write page
+ } else if (rq->bRequest == cmd_transfer_page) { // transfer page
// clear page buffer as a precaution before filling the buffer in case
// a previous write operation failed and there is still something in the buffer.
__boot_page_fill_clear();
currentAddress = rq->wIndex.word;
return USB_NO_MSG; // hands off work to usbFunctionWrite
-
- } else if (rq->bRequest == 2) { // erase application
- command=cmd_erase_application;
-
- } else { // exit bootloader
- command=cmd_exit;
- }
-
+ } else {
+ // Handle cmd_erase_application and cmd_exit
+ command=rq->bRequest;
return 0;
+ }
}
// read in a page over usb, and write it in to the flash write buffer