aboutsummaryrefslogtreecommitdiff
path: root/bootloaders/diskloader/src
diff options
context:
space:
mode:
authorZach Eveland <zeveland@blacklabel-development.com>2011-09-08 16:23:29 -0400
committerZach Eveland <zeveland@blacklabel-development.com>2011-09-08 16:23:29 -0400
commit874cacf143330bf156d44102faba83ade270029d (patch)
treea4bc644d35723ea3e2d7f41e2872ba2b6ec8b3d9 /bootloaders/diskloader/src
parent63ec4aba2221ce5f9d57cfa305e2ad3f253de732 (diff)
misc. bootloader fixes: increased wait time after receiving avrdude 'Q', increased bootloader timeout, and fixed LED one-shot timing
Diffstat (limited to 'bootloaders/diskloader/src')
-rw-r--r--bootloaders/diskloader/src/DiskLoader.cpp5
-rw-r--r--bootloaders/diskloader/src/USBCore.cpp31
2 files changed, 22 insertions, 14 deletions
diff --git a/bootloaders/diskloader/src/DiskLoader.cpp b/bootloaders/diskloader/src/DiskLoader.cpp
index 34a9c94..da57e75 100644
--- a/bootloaders/diskloader/src/DiskLoader.cpp
+++ b/bootloaders/diskloader/src/DiskLoader.cpp
@@ -210,7 +210,7 @@ int main()
if (cmd == 'Q')
break;
}
- _timeout = 1; // signal to exit the bootloader
+ _timeout = 1000; // wait a moment before exiting the bootloader - may need to finish responding to 'Q' for example
_ejected = 1;
}
}
@@ -232,7 +232,8 @@ void LEDPulse()
void Reboot()
{
- /* TODO - ZE - this should probably be a WDT reset instead, right? */
+ TXLED0; // switch off the RX and TX LEDs before starting the user sketch
+ RXLED0;
UDCON = 1; // Detatch USB
UDIEN = 0;
asm volatile ( // Reset vector to run firmware
diff --git a/bootloaders/diskloader/src/USBCore.cpp b/bootloaders/diskloader/src/USBCore.cpp
index 142fc79..1a8f2d0 100644
--- a/bootloaders/diskloader/src/USBCore.cpp
+++ b/bootloaders/diskloader/src/USBCore.cpp
@@ -29,6 +29,11 @@
#define EP_TYPE_ISOCHRONOUS_IN 0x41
#define EP_TYPE_ISOCHRONOUS_OUT 0x40
+/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
+#define TX_RX_LED_PULSE_MS 100
+u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
+u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
+
void Reboot();
//==================================================================
@@ -85,6 +90,7 @@ static
void Send(volatile const u8* data, u8 count)
{
TXLED1; // light the TX LED
+ TxLEDPulse = TX_RX_LED_PULSE_MS;
while (count--)
UEDATX = *data++;
}
@@ -92,6 +98,7 @@ void Send(volatile const u8* data, u8 count)
void Recv(volatile u8* data, u8 count)
{
RXLED1; // light the RX LED
+ RxLEDPulse = TX_RX_LED_PULSE_MS;
while (count--)
*data++ = UEDATX;
}
@@ -99,12 +106,14 @@ void Recv(volatile u8* data, u8 count)
static inline u8 Recv8()
{
RXLED1; // light the RX LED
+ RxLEDPulse = TX_RX_LED_PULSE_MS;
return UEDATX;
}
static inline void Send8(u8 d)
{
TXLED1; // light the TX LED
+ TxLEDPulse = TX_RX_LED_PULSE_MS;
UEDATX = d;
}
@@ -451,12 +460,17 @@ void USBGeneralInterrupt()
{
InitEP(0,EP_TYPE_CONTROL,EP_SINGLE_64); // init ep0
_usbConfiguration = 0; // not configured yet
- //UEIENX = 1 << RXSTPE;
}
- // Start of Frame
+ // Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
if (udint & (1<<SOFI))
{
+ // check whether the one-shot period has elapsed. if so, turn off the LED
+ if (TxLEDPulse && !(--TxLEDPulse))
+ TXLED0;
+ if (RxLEDPulse && !(--RxLEDPulse))
+ RXLED0;
+
if (!_ejected)
_timeout = 0;
}
@@ -477,20 +491,13 @@ int USBGetChar()
if (!ReadWriteAllowed())
ReleaseRX();
return c;
- } else {
- u8 temp = 0;
- for (temp=100; temp; temp--)
- asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t"::);
- RXLED0; // we turn the RX and TX LEDs on in the relevant Send or Recv instruction
- TXLED0; // we turn them off here after some time has passed to ensure a minimum on time.
- }
+ }
if (!--_timeout) {
- TXLED0; // switch off the RX and TX LEDs before starting the user sketch
- RXLED0;
Reboot(); // USB not connected, run firmware
}
-
+
+ _delay_us(100); // stretch out the bootloader period to about 5 seconds after enumeration
LEDPulse();
}
return -1;