summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2014-07-03 22:41:08 +0200
committercpldcpu <cpldcpu@gmail.com>2014-07-03 22:41:08 +0200
commit1e6cfd178fc302e5dd269444063745dd7b7a66c0 (patch)
tree5462d77f07aafc0f5774f30dff4c18386acffa4a /firmware
parent8acc614a0d65ef4021295c3d4681f76d24b70e96 (diff)
downloadmicronucleus-1e6cfd178fc302e5dd269444063745dd7b7a66c0.tar.gz
micronucleus-1e6cfd178fc302e5dd269444063745dd7b7a66c0.tar.bz2
micronucleus-1e6cfd178fc302e5dd269444063745dd7b7a66c0.zip
firmware: Stored OSCCAL can now be used by userprogram
Diffstat (limited to 'firmware')
-rw-r--r--firmware/main.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/firmware/main.c b/firmware/main.c
index 625f026..0de341a 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -196,20 +196,6 @@ static void initHardware (void)
WDTCR = 1<<WDP2 | 1<<WDP1 | 1<<WDP0;
#endif
-
- /* save default OSCCAL calibration */
-#if OSCCAL_RESTORE_DEFAULT
- osccal_default = OSCCAL;
-#endif
-
-#if OSCCAL_SAVE_CALIB
- // adjust clock to previous calibration value, so bootloader starts with proper clock calibration
- unsigned char stored_osc_calibration = pgm_read_byte(BOOTLOADER_ADDRESS - TINYVECTOR_OSCCAL_OFFSET);
- if (stored_osc_calibration != 0xFF) {
- OSCCAL=stored_osc_calibration;
- nop();
- }
-#endif
usbDeviceDisconnect(); /* do this while interrupts are disabled */
_delay_ms(300);
@@ -243,6 +229,20 @@ static inline void leaveBootloader(void) {
void USB_INTR_VECTOR(void);
int main(void) {
bootLoaderInit();
+
+ /* save default OSCCAL calibration */
+#if OSCCAL_RESTORE_DEFAULT
+ osccal_default = OSCCAL;
+#endif
+
+#if OSCCAL_SAVE_CALIB
+ // adjust clock to previous calibration value, so bootloader starts with proper clock calibration
+ unsigned char stored_osc_calibration = pgm_read_byte(BOOTLOADER_ADDRESS - TINYVECTOR_OSCCAL_OFFSET);
+ if (stored_osc_calibration != 0xFF) {
+ OSCCAL=stored_osc_calibration;
+ nop();
+ }
+#endif
if (bootLoaderStartCondition()||(pgm_read_byte(BOOTLOADER_ADDRESS - TINYVECTOR_RESET_OFFSET + 1)==0xff)) {