fix: Bug causing the watchdog timer to continously reboot

In all USBaspLoader version up to 0.97 exists a bug, which causes the watchdog timer to continously reboot.

When a users firmware activates the watchdog timer, and then times out:
The MCUC(S)R register then has WDRF bit to HIGH.
On some ATmegas this keeps the AVRs internal hardware reset from disabling the active watchdog (even when the WDTON fuse is unprogrammed).
However the timeout period is reset anyway to minimal value of 16ms (WDPx to LOW).

In the bootloaders PROG-PIN chargeup phase, the bootloader stalls about 50ms, causing the AVR to reboot.

For deactivating the watchdog timer, some AVRs need to reset the WDRF bit first.
But since also the hardware reset seems to be restricted to this measure (hardware bug???), the watchdog stays on forever - even during RESET presses.
This also renders the RESET pin/button effectivly useless.

This patch fixes this issue by redesigning internal time management.
Now all relevant delays are based on _mywait, which might execute an additional WDR (watchdog timer refresh) when neccessary.
So active watchdog timers are now keept alive until it is shure that bootloaderCondition() is true.
As always: In situation where bootloaderCondition() is false, user firmwares can rely on active watchdog then.

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
introduce new feature for watchdog enabled USBaspLoader: PRESERVE_WATCHDOG

When this new feature becomes active, the bootloader will run with active
watchdog timer, instead of disabling it.
After leaving the bootloader, the original watchdog state is restored.

WARNING:This might break compatibility with user firmwares, since they
	need to be aware of watchdog enabled. (which could be enabled by some
	previous running firmware and not neccessarily only by the WDTON FUSE)
	In doubt compile your USBaspLoader with CONFIG_NO__PRESERVE_WATCHDOG

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
fix: missing MCUSCR cleanup to disable watchdog on newer ATmegas

This fix makes the updater a "PRESERVE_WATCHDOG" compliant firmware.

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
fix annoying compiler warning "'usbFunctionDescriptor' used but never defined"

Because in order to save a few bytes of code, the usbdrv.c is included in main.c,
instead of being linked.
This feature is supported by the usb driver, but needs "USB_PUBLIC" to be defined
as static.
Even when it is not really used in the code,
"static usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)" isn't optimized
out at this level of compilation.
Since it is never defined, the warning pops up.

Fix: Define a dummy function which becomes optimized out later.

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
fix warning "optimization may eliminate reads and/or writes to register variables"

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
fix warning "integer overflow in expression" in updater

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
fix automated feature selection due to bugfixes to still fit into bootloader

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
migrate to new v-usb driver release 20131128

The mainline master-HEAD commit 6f64e80f219273967d6ac7096f3ca3d7db5a0e79
was used.

https://github.com/obdev/v-usb/commit/6f64e80f219273967d6ac7096f3ca3d7db5a0e79

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
USBaspLoader v0.97.1 stable release

  -  fixed bug causing the watchdog timer to continously reboot
  -  new feature for watchdog enabled bootloader (and updater)
  -  cleanup compiler build warnings
  -  new and improved v-usb driver

Because users ofter were confused by the provided hexfiles and
The firmware from tinyUSBboard, precompiled hexfiles are not
further supported.
Please use binaries provided for tinyUSBboard instead:

	http://matrixstorm.com/avr/tinyusbboard/

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
tinyUSBboard specific patches for USBaspLoader updater

The updater is still a mess and would need a cleanup.
However, hack some API in there and just use it for now.
(Updates should be tested before rollen out to users!)

For the lack of stand-alone compilability: Copy some
stuff from the API library in here...

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
tinyUSBboard specific patches for USBaspLoader firmware

In order to match the correct size requirements, this firmware
needs to be build with avr-gcc version 4.8.1

	avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.3_1072) 4.8.1

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>