summaryrefslogtreecommitdiffstats
path: root/firmware/main.c
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/main.c
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/main.c')
-rw-r--r--firmware/main.c17
1 files changed, 11 insertions, 6 deletions
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();