summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorBluebie <a@creativepony.com>2013-03-04 01:08:26 +1100
committerBluebie <a@creativepony.com>2013-03-04 01:08:26 +1100
commit3ee4ba640936bd5c4a2e02309f8c863568bc828b (patch)
treed995f13da75f50554bea0a6b2927fee205f5c643 /firmware
parent58a113df9678b4502f87e0e91fc01d023a59393d (diff)
downloadmicronucleus-3ee4ba640936bd5c4a2e02309f8c863568bc828b.tar.gz
micronucleus-3ee4ba640936bd5c4a2e02309f8c863568bc828b.tar.bz2
micronucleus-3ee4ba640936bd5c4a2e02309f8c863568bc828b.zip
firmware: added osccal store and retrieve code, untested
Diffstat (limited to 'firmware')
-rw-r--r--firmware/bootloaderconfig.h38
-rw-r--r--firmware/main.c17
2 files changed, 31 insertions, 24 deletions
diff --git a/firmware/bootloaderconfig.h b/firmware/bootloaderconfig.h
index 75ca572..1f1cb94 100644
--- a/firmware/bootloaderconfig.h
+++ b/firmware/bootloaderconfig.h
@@ -183,6 +183,7 @@ these macros are defined, the boot loader uses them.
// number of bytes before the boot loader vectors to store the tiny application vector table
#define TINYVECTOR_RESET_OFFSET 4
#define TINYVECTOR_USBPLUS_OFFSET 2
+#define TINYVECTOR_OSCCAL_OFFSET 6
#define RESET_VECTOR_OFFSET 0
#define USBPLUS_VECTOR_OFFSET 2
@@ -213,15 +214,17 @@ these macros are defined, the boot loader uses them.
// set clock prescaler to a value before running user program
//#define SET_CLOCK_PRESCALER _BV(CLKPS0) /* divide by 2 for 8mhz */
-
-/*#if LOW_POWER_MODE
+#define bootLoaderInit()
+#define bootLoaderExit()
+#define bootLoaderCondition() (idlePolls < (AUTO_EXIT_MS * 10UL))
+#if LOW_POWER_MODE
// only starts bootloader if USB D- is pulled high on startup - by putting your pullup in to an external connector
// you can avoid ever entering an out of spec clock speed or waiting on bootloader when that pullup isn't there
#define bootLoaderStartCondition() \
(PINB & (_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DMINUS_BIT))) == _BV(USB_CFG_DMINUS_BIT)
#else
#define bootLoaderStartCondition() 1
-#endif*/
+#endif
/* ----------------------- Optional MCU Description ------------------------ */
@@ -241,25 +244,24 @@ these macros are defined, the boot loader uses them.
/* #define USB_INTR_VECTOR INT0_vect */
// todo: change to pin 5
-#define DEUXVIS_JUMPER_PIN 5
-#define digitalRead(pin) ((PINB >> pin) & 0b00000001)
-#define bootLoaderStartCondition() (!digitalRead(DEUXVIS_JUMPER_PIN))
-#define bootLoaderCondition() (1)
+//#define DEUXVIS_JUMPER_PIN 5
+//#define digitalRead(pin) ((PINB >> pin) & 0b00000001)
+//#define bootLoaderStartCondition() (!digitalRead(DEUXVIS_JUMPER_PIN))
+//#define bootLoaderCondition() (1)
#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */
-static inline void bootLoaderInit(void) {
- // DeuxVis pin-5 pullup
- DDRB |= _BV(DEUXVIS_JUMPER_PIN); // is an input
- PORTB |= _BV(DEUXVIS_JUMPER_PIN); // has pullup enabled
- _delay_ms(10);
-}
-
-static inline void bootLoaderExit(void) {
+//static inline void bootLoaderInit(void) {
+// // DeuxVis pin-5 pullup
+// DDRB |= _BV(DEUXVIS_JUMPER_PIN); // is an input
+// PORTB |= _BV(DEUXVIS_JUMPER_PIN); // has pullup enabled
+// _delay_ms(10);
+//}
+//static inline void bootLoaderExit(void) {
// DeuxVis pin-5 pullup
- PORTB = 0;
- DDRB = 0;
-}
+// PORTB = 0;
+// DDRB = 0;
+//}
#endif /* __ASSEMBLER__ */
diff --git a/firmware/main.c b/firmware/main.c
index 4fcdedd..708f474 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -180,10 +180,10 @@ static void writeWordToPageBuffer(uint16_t data) {
// for info on how the tiny vector table works
if (currentAddress == BOOTLOADER_ADDRESS - TINYVECTOR_RESET_OFFSET) {
data = vectorTemp[0] + ((FLASHEND + 1) - BOOTLOADER_ADDRESS)/2 + 2 + RESET_VECTOR_OFFSET;
- }
-
- if (currentAddress == BOOTLOADER_ADDRESS - TINYVECTOR_USBPLUS_OFFSET) {
+ } else if (currentAddress == BOOTLOADER_ADDRESS - TINYVECTOR_USBPLUS_OFFSET) {
data = vectorTemp[1] + ((FLASHEND + 1) - BOOTLOADER_ADDRESS)/2 + 1 + USBPLUS_VECTOR_OFFSET;
+ } else if (currentAddress == BOOTLOADER_ADDRESS - TINYVECTOR_OSCCAL_OFFSET) {
+ data = OSCCAL;
}
@@ -196,9 +196,9 @@ static void writeWordToPageBuffer(uint16_t data) {
boot_page_fill(currentAddress, data);
sei();
- // only need to erase if there is data already in the page that doesn't match what we're programming
- // TODO: what about this: if (pgm_read_word(currentAddress) & data != data) { ??? should work right?
- //if (pgm_read_word(currentAddress) != data && pgm_read_word(currentAddress) != 0xFFFF) {
+ // only need to erase if there is data already in the page that doesn't match what we're programming
+ // TODO: what about this: if (pgm_read_word(currentAddress) & data != data) { ??? should work right?
+ //if (pgm_read_word(currentAddress) != data && pgm_read_word(currentAddress) != 0xFFFF) {
//if ((pgm_read_word(currentAddress) & data) != data) {
// fireEvent(EVENT_PAGE_NEEDS_ERASE);
//}
@@ -382,6 +382,11 @@ int main(void) {
uint8_t prescaler_default = CLKPR;
#endif
+ unsigned char stored_osc_calibration = pgm_read_byte(BOOTLOADER_ADDRESS - TINYVECTOR_OSCCAL_OFFSET + 1);
+ if (stored_osc_calibration != 0xFF) {
+ OSCCAL = stored_osc_calibration;
+ }
+
wdt_disable(); /* main app may have enabled watchdog */
tiny85FlashInit();
bootLoaderInit();