From: razvanm Date: Wed, 23 Sep 2009 18:29:20 +0000 (+0000) Subject: Make tosboot compliant with TEP3. X-Git-Tag: rc_6_tinyos_2_1_1~221 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=622893623b38edfd9e183f4d31a48ba742ae0d22 Make tosboot compliant with TEP3. --- diff --git a/tos/lib/tosboot/Makefile b/tos/lib/tosboot/Makefile index 605bbbb4..cebcf9cb 100644 --- a/tos/lib/tosboot/Makefile +++ b/tos/lib/tosboot/Makefile @@ -28,7 +28,7 @@ # @author Jonathan Hui # -COMPONENT=TOSBoot +COMPONENT=TosBootC TINYOS_NP= PFLAGS += -DNESC_BUILD_BINARY diff --git a/tos/lib/tosboot/TOSBoot.h b/tos/lib/tosboot/TOSBoot.h deleted file mode 100644 index d490a62a..00000000 --- a/tos/lib/tosboot/TOSBoot.h +++ /dev/null @@ -1,33 +0,0 @@ -// $Id$ - -/* - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - */ - -/** - * @author Jonathan Hui - */ - -#ifndef __TOSBOOT_H__ -#define __TOSBOOT_H__ - -#include "TOSBoot_platform.h" - -#endif diff --git a/tos/lib/tosboot/TOSBoot.nc b/tos/lib/tosboot/TOSBoot.nc deleted file mode 100644 index 9bd5c2bf..00000000 --- a/tos/lib/tosboot/TOSBoot.nc +++ /dev/null @@ -1,62 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ - -includes Deluge; -includes DelugePageTransfer; -includes TOSBoot; - -configuration TOSBoot { -} -implementation { - - components - TOSBootM, - ExecC, - ExtFlashC, - HardwareC, - InternalFlashC as IntFlash, - LedsC, - PluginC, - ProgFlashM as ProgFlash, - VoltageC; - - TOSBootM.SubInit -> ExtFlashC; - TOSBootM.SubControl -> ExtFlashC.StdControl; - TOSBootM.SubControl -> PluginC; - - TOSBootM.Exec -> ExecC; - TOSBootM.ExtFlash -> ExtFlashC; - TOSBootM.Hardware -> HardwareC; - TOSBootM.IntFlash -> IntFlash; - TOSBootM.Leds -> LedsC; - TOSBootM.ProgFlash -> ProgFlash; - TOSBootM.Voltage -> VoltageC; - -} diff --git a/tos/lib/tosboot/TOSBootM.nc b/tos/lib/tosboot/TOSBootM.nc deleted file mode 100644 index b24b1762..00000000 --- a/tos/lib/tosboot/TOSBootM.nc +++ /dev/null @@ -1,279 +0,0 @@ -/* - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - * Copyright (c) 2007 Johns Hopkins University. - * All rights reserved. - * - */ - -/** - * @author Jonathan Hui - * @author Chieh-Jan Mike Liang - * @author Razvan Musaloiu-E. - */ - -includes crc; -includes hardware; - -module TOSBootM { - uses { - interface Exec; - interface ExtFlash; - interface Hardware; - interface InternalFlash as IntFlash; - interface Leds; - interface ProgFlash; - interface StdControl as SubControl; - interface Init as SubInit; - interface Voltage; - } -} -implementation { - - enum { - LEDS_LOWBATT = 1, - LEDS_GESTURE = 7, - }; - - enum { - R_SUCCESS, - R_INVALID_IMAGE_ERROR, - R_PROGRAMMING_ERROR, - }; - - void startupLeds() { - - uint8_t output = 0x7; - uint8_t i; - - for (i = 3; i; i--, output >>= 1 ) - call Leds.glow(output, output >> 1); - - } - - in_flash_addr_t extFlashReadAddr() { - in_flash_addr_t result = 0; - int8_t i; - for ( i = 3; i >= 0; i-- ) - result |= ((in_flash_addr_t)call ExtFlash.readByte() & 0xff) << (i*8); - return result; - } - - bool verifyBlock(ex_flash_addr_t crcAddr, ex_flash_addr_t startAddr, uint16_t len) - { - uint16_t crcTarget, crcTmp; - - // read crc - call ExtFlash.startRead(crcAddr); - crcTarget = (uint16_t)(call ExtFlash.readByte() & 0xff) << 8; - crcTarget |= (uint16_t)(call ExtFlash.readByte() & 0xff); - call ExtFlash.stopRead(); - - // compute crc - call ExtFlash.startRead(startAddr); - for ( crcTmp = 0; len; len-- ) - crcTmp = crcByte(crcTmp, call ExtFlash.readByte()); - call ExtFlash.stopRead(); - - return crcTarget == crcTmp; - } - - bool verifyImage(ex_flash_addr_t startAddr) { - uint32_t addr; - uint8_t numPgs; - uint8_t i; - - - if (!verifyBlock(startAddr + offsetof(DelugeIdent,crc), - startAddr, offsetof(DelugeIdent,crc))) - return FALSE; - - // read size of image - call ExtFlash.startRead(startAddr + offsetof(DelugeIdent,numPgs)); - numPgs = call ExtFlash.readByte(); - call ExtFlash.stopRead(); - - if (numPgs == 0 || numPgs == 0xff) - return FALSE; - - startAddr += DELUGE_IDENT_SIZE; - addr = DELUGE_CRC_BLOCK_SIZE; - - for ( i = 0; i < numPgs; i++ ) { - if (!verifyBlock(startAddr + i*sizeof(uint16_t), - startAddr + addr, DELUGE_BYTES_PER_PAGE)) { - return FALSE; - } - addr += DELUGE_BYTES_PER_PAGE; - } - - return TRUE; - } - - error_t programImage(ex_flash_addr_t startAddr) { - uint8_t buf[TOSBOOT_INT_PAGE_SIZE]; - uint32_t pageAddr, newPageAddr; - in_flash_addr_t intAddr; - in_flash_addr_t secLength; - ex_flash_addr_t curAddr; - - if (!verifyImage(startAddr)) - return R_INVALID_IMAGE_ERROR; - - curAddr = startAddr + DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE; - - call ExtFlash.startRead(curAddr); - - intAddr = extFlashReadAddr(); - secLength = extFlashReadAddr(); - curAddr = curAddr + 8; - -#if defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) - if (intAddr != TOSBOOT_END) { -#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) - if (intAddr != 0) { -#elif defined(PLATFORM_MULLE) - if (intAddr != 0xA0000) { -#else - #error "Target platform is not currently supported by Deluge T2" -#endif - call ExtFlash.stopRead(); - return R_INVALID_IMAGE_ERROR; - } - - call ExtFlash.stopRead(); - - while ( secLength ) { - - pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE; - - call ExtFlash.startRead(curAddr); - // fill in ram buffer for internal program flash sector - do { - - // check if secLength is all ones - if ( secLength == 0xffffffff ) { - call ExtFlash.stopRead(); - return FAIL; - } - - buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte(); - intAddr++; curAddr++; - - if ( --secLength == 0 ) { - intAddr = extFlashReadAddr(); - secLength = extFlashReadAddr(); - curAddr = curAddr + 8; - } - - newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE; - - } while ( pageAddr == newPageAddr && secLength ); - call ExtFlash.stopRead(); - - call Leds.set(pageAddr); - - // write out page - if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf, - TOSBOOT_INT_PAGE_SIZE) == FAIL) { - return R_PROGRAMMING_ERROR; - } - } - - return R_SUCCESS; - - } - - void runApp() { - call SubControl.stop(); - call Exec.exec(); - } - - void startupSequence() { - - BootArgs args; - - // check voltage and make sure flash can be programmed - // if not, just run the app, can't check for gestures - // if we can't write to the internal flash anyway - if ( !call Voltage.okToProgram() ) { - // give user some time and count down LEDs - call Leds.flash(LEDS_LOWBATT); - startupLeds(); - runApp(); - } - - // get current value of counter - call IntFlash.read((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args)); - - // increment gesture counter, see if it exceeds threshold - if ( ++args.gestureCount >= TOSBOOT_GESTURE_MAX_COUNT - 1 ) { - // gesture has been detected, display receipt of gesture on LEDs - call Leds.flash(LEDS_GESTURE); - - // load golden image from flash - // if the golden image is invalid, forget about reprogramming - // if an error happened during reprogramming, reboot and try again - // not much else we can do :-/ - if (programImage(TOSBOOT_GOLDEN_IMG_ADDR) == R_PROGRAMMING_ERROR) { - call Hardware.reboot(); - } - } - else { - // update gesture counter - call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args)); - if ( !args.noReprogram ) { - // if an error happened during reprogramming, reboot and try again - // after two tries, try programming the golden image - if (programImage(args.imageAddr) == R_PROGRAMMING_ERROR) { - call Hardware.reboot(); - } - } - } - - // give user some time and count down LEDs - startupLeds(); - - // reset counter and reprogramming flag - args.gestureCount = 0xff; - args.noReprogram = TRUE; - call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args)); - - runApp(); - - } - - int main() @C() @spontaneous() { - - __nesc_disable_interrupt(); - - TOSH_SET_PIN_DIRECTIONS(); - call Hardware.init(); - - call SubInit.init(); - call SubControl.start(); - - startupSequence(); - - return 0; - - } - -} diff --git a/tos/lib/tosboot/TosBoot.h b/tos/lib/tosboot/TosBoot.h new file mode 100644 index 00000000..d490a62a --- /dev/null +++ b/tos/lib/tosboot/TosBoot.h @@ -0,0 +1,33 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +/** + * @author Jonathan Hui + */ + +#ifndef __TOSBOOT_H__ +#define __TOSBOOT_H__ + +#include "TOSBoot_platform.h" + +#endif diff --git a/tos/lib/tosboot/TosBootC.nc b/tos/lib/tosboot/TosBootC.nc new file mode 100644 index 00000000..83172506 --- /dev/null +++ b/tos/lib/tosboot/TosBootC.nc @@ -0,0 +1,62 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +#include +#include +#include "TosBoot.h" + +configuration TosBootC { +} +implementation { + + components + TosBootP, + ExecC, + ExtFlashC, + HardwareC, + InternalFlashC as IntFlash, + LedsC, + PluginC, + ProgFlashC as ProgFlash, + VoltageC; + + TosBootP.SubInit -> ExtFlashC; + TosBootP.SubControl -> ExtFlashC.StdControl; + TosBootP.SubControl -> PluginC; + + TosBootP.Exec -> ExecC; + TosBootP.ExtFlash -> ExtFlashC; + TosBootP.Hardware -> HardwareC; + TosBootP.IntFlash -> IntFlash; + TosBootP.Leds -> LedsC; + TosBootP.ProgFlash -> ProgFlash; + TosBootP.Voltage -> VoltageC; + +} diff --git a/tos/lib/tosboot/TosBootP.nc b/tos/lib/tosboot/TosBootP.nc new file mode 100644 index 00000000..9340772c --- /dev/null +++ b/tos/lib/tosboot/TosBootP.nc @@ -0,0 +1,279 @@ +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2007 Johns Hopkins University. + * All rights reserved. + * + */ + +/** + * @author Jonathan Hui + * @author Chieh-Jan Mike Liang + * @author Razvan Musaloiu-E. + */ + +#include "crc.h" +#include + +module TosBootP { + uses { + interface Exec; + interface ExtFlash; + interface Hardware; + interface InternalFlash as IntFlash; + interface Leds; + interface ProgFlash; + interface StdControl as SubControl; + interface Init as SubInit; + interface Voltage; + } +} +implementation { + + enum { + LEDS_LOWBATT = 1, + LEDS_GESTURE = 7, + }; + + enum { + R_SUCCESS, + R_INVALID_IMAGE_ERROR, + R_PROGRAMMING_ERROR, + }; + + void startupLeds() { + + uint8_t output = 0x7; + uint8_t i; + + for (i = 3; i; i--, output >>= 1 ) + call Leds.glow(output, output >> 1); + + } + + in_flash_addr_t extFlashReadAddr() { + in_flash_addr_t result = 0; + int8_t i; + for ( i = 3; i >= 0; i-- ) + result |= ((in_flash_addr_t)call ExtFlash.readByte() & 0xff) << (i*8); + return result; + } + + bool verifyBlock(ex_flash_addr_t crcAddr, ex_flash_addr_t startAddr, uint16_t len) + { + uint16_t crcTarget, crcTmp; + + // read crc + call ExtFlash.startRead(crcAddr); + crcTarget = (uint16_t)(call ExtFlash.readByte() & 0xff) << 8; + crcTarget |= (uint16_t)(call ExtFlash.readByte() & 0xff); + call ExtFlash.stopRead(); + + // compute crc + call ExtFlash.startRead(startAddr); + for ( crcTmp = 0; len; len-- ) + crcTmp = crcByte(crcTmp, call ExtFlash.readByte()); + call ExtFlash.stopRead(); + + return crcTarget == crcTmp; + } + + bool verifyImage(ex_flash_addr_t startAddr) { + uint32_t addr; + uint8_t numPgs; + uint8_t i; + + + if (!verifyBlock(startAddr + offsetof(DelugeIdent,crc), + startAddr, offsetof(DelugeIdent,crc))) + return FALSE; + + // read size of image + call ExtFlash.startRead(startAddr + offsetof(DelugeIdent,numPgs)); + numPgs = call ExtFlash.readByte(); + call ExtFlash.stopRead(); + + if (numPgs == 0 || numPgs == 0xff) + return FALSE; + + startAddr += DELUGE_IDENT_SIZE; + addr = DELUGE_CRC_BLOCK_SIZE; + + for ( i = 0; i < numPgs; i++ ) { + if (!verifyBlock(startAddr + i*sizeof(uint16_t), + startAddr + addr, DELUGE_BYTES_PER_PAGE)) { + return FALSE; + } + addr += DELUGE_BYTES_PER_PAGE; + } + + return TRUE; + } + + error_t programImage(ex_flash_addr_t startAddr) { + uint8_t buf[TOSBOOT_INT_PAGE_SIZE]; + uint32_t pageAddr, newPageAddr; + in_flash_addr_t intAddr; + in_flash_addr_t secLength; + ex_flash_addr_t curAddr; + + if (!verifyImage(startAddr)) + return R_INVALID_IMAGE_ERROR; + + curAddr = startAddr + DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE; + + call ExtFlash.startRead(curAddr); + + intAddr = extFlashReadAddr(); + secLength = extFlashReadAddr(); + curAddr = curAddr + 8; + +#if defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) + if (intAddr != TOSBOOT_END) { +#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) + if (intAddr != 0) { +#elif defined(PLATFORM_MULLE) + if (intAddr != 0xA0000) { +#else + #error "Target platform is not currently supported by Deluge T2" +#endif + call ExtFlash.stopRead(); + return R_INVALID_IMAGE_ERROR; + } + + call ExtFlash.stopRead(); + + while ( secLength ) { + + pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE; + + call ExtFlash.startRead(curAddr); + // fill in ram buffer for internal program flash sector + do { + + // check if secLength is all ones + if ( secLength == 0xffffffff ) { + call ExtFlash.stopRead(); + return FAIL; + } + + buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte(); + intAddr++; curAddr++; + + if ( --secLength == 0 ) { + intAddr = extFlashReadAddr(); + secLength = extFlashReadAddr(); + curAddr = curAddr + 8; + } + + newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE; + + } while ( pageAddr == newPageAddr && secLength ); + call ExtFlash.stopRead(); + + call Leds.set(pageAddr); + + // write out page + if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf, + TOSBOOT_INT_PAGE_SIZE) == FAIL) { + return R_PROGRAMMING_ERROR; + } + } + + return R_SUCCESS; + + } + + void runApp() { + call SubControl.stop(); + call Exec.exec(); + } + + void startupSequence() { + + BootArgs args; + + // check voltage and make sure flash can be programmed + // if not, just run the app, can't check for gestures + // if we can't write to the internal flash anyway + if ( !call Voltage.okToProgram() ) { + // give user some time and count down LEDs + call Leds.flash(LEDS_LOWBATT); + startupLeds(); + runApp(); + } + + // get current value of counter + call IntFlash.read((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args)); + + // increment gesture counter, see if it exceeds threshold + if ( ++args.gestureCount >= TOSBOOT_GESTURE_MAX_COUNT - 1 ) { + // gesture has been detected, display receipt of gesture on LEDs + call Leds.flash(LEDS_GESTURE); + + // load golden image from flash + // if the golden image is invalid, forget about reprogramming + // if an error happened during reprogramming, reboot and try again + // not much else we can do :-/ + if (programImage(TOSBOOT_GOLDEN_IMG_ADDR) == R_PROGRAMMING_ERROR) { + call Hardware.reboot(); + } + } + else { + // update gesture counter + call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args)); + if ( !args.noReprogram ) { + // if an error happened during reprogramming, reboot and try again + // after two tries, try programming the golden image + if (programImage(args.imageAddr) == R_PROGRAMMING_ERROR) { + call Hardware.reboot(); + } + } + } + + // give user some time and count down LEDs + startupLeds(); + + // reset counter and reprogramming flag + args.gestureCount = 0xff; + args.noReprogram = TRUE; + call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args)); + + runApp(); + + } + + int main() @C() @spontaneous() { + + __nesc_disable_interrupt(); + + TOSH_SET_PIN_DIRECTIONS(); + call Hardware.init(); + + call SubInit.init(); + call SubControl.start(); + + startupSequence(); + + return 0; + + } + +} diff --git a/tos/lib/tosboot/avr/InternalFlashC.nc b/tos/lib/tosboot/avr/InternalFlashC.nc index 558f2426..3b8803eb 100644 --- a/tos/lib/tosboot/avr/InternalFlashC.nc +++ b/tos/lib/tosboot/avr/InternalFlashC.nc @@ -28,7 +28,7 @@ * @author Jonathan Hui */ -includes InternalFlash; +#include module InternalFlashC { provides interface InternalFlash; diff --git a/tos/lib/tosboot/avr/ProgFlashC.nc b/tos/lib/tosboot/avr/ProgFlashC.nc new file mode 100644 index 00000000..a3796eef --- /dev/null +++ b/tos/lib/tosboot/avr/ProgFlashC.nc @@ -0,0 +1,65 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +module ProgFlashC { + provides { + interface ProgFlash; + } +} + +implementation { + +#include + + command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) { + + uint16_t* wordBuf = (uint16_t*)buf; + uint32_t i; + + if ( addr + len > TOSBOOT_START ) + return FAIL; + + boot_page_erase_safe( addr ); + while( boot_rww_busy() ) + boot_rww_enable_safe(); + + for ( i = 0; i < len; i += 2 ) + boot_page_fill_safe( addr + i, *wordBuf++ ); + + boot_page_write_safe( addr ); + + while ( boot_rww_busy() ) + boot_rww_enable_safe(); + + return SUCCESS; + + } + +} diff --git a/tos/lib/tosboot/avr/ProgFlashM.nc b/tos/lib/tosboot/avr/ProgFlashM.nc deleted file mode 100644 index 898ebc64..00000000 --- a/tos/lib/tosboot/avr/ProgFlashM.nc +++ /dev/null @@ -1,65 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ - -module ProgFlashM { - provides { - interface ProgFlash; - } -} - -implementation { - -#include - - command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) { - - uint16_t* wordBuf = (uint16_t*)buf; - uint32_t i; - - if ( addr + len > TOSBOOT_START ) - return FAIL; - - boot_page_erase_safe( addr ); - while( boot_rww_busy() ) - boot_rww_enable_safe(); - - for ( i = 0; i < len; i += 2 ) - boot_page_fill_safe( addr + i, *wordBuf++ ); - - boot_page_write_safe( addr ); - - while ( boot_rww_busy() ) - boot_rww_enable_safe(); - - return SUCCESS; - - } - -} diff --git a/tos/lib/tosboot/epic/ExtFlashC.nc b/tos/lib/tosboot/epic/ExtFlashC.nc index 9f7d5347..34ada4e1 100644 --- a/tos/lib/tosboot/epic/ExtFlashC.nc +++ b/tos/lib/tosboot/epic/ExtFlashC.nc @@ -39,13 +39,13 @@ configuration ExtFlashC { implementation { components - ExtFlashM, - HPLUSART0M; + ExtFlashP, + HplUsart0C; - Init = ExtFlashM; - StdControl = ExtFlashM; - ExtFlash = ExtFlashM; + Init = ExtFlashP; + StdControl = ExtFlashP; + ExtFlash = ExtFlashP; - ExtFlashM.USARTControl -> HPLUSART0M; + ExtFlashP.UsartControl -> HplUsart0C; } diff --git a/tos/lib/tosboot/epic/ExtFlashM.nc b/tos/lib/tosboot/epic/ExtFlashM.nc deleted file mode 100644 index a80ecabe..00000000 --- a/tos/lib/tosboot/epic/ExtFlashM.nc +++ /dev/null @@ -1,98 +0,0 @@ -// $Id$ - -/* - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - */ - -/** - * @author Jonathan Hui - * @author Razvan Musaloiu-E. - */ - -module ExtFlashM { - provides { - interface StdControl; - interface Init; - interface ExtFlash; - } - uses { - interface HPLUSARTControl as USARTControl; - } -} - -implementation { - - uint32_t addr; - - command error_t Init.init() { - TOSH_MAKE_FLASH_CS_OUTPUT(); - TOSH_SET_FLASH_CS_PIN(); - call USARTControl.setModeSPI(); - return SUCCESS; - } - - command error_t StdControl.start() { - return SUCCESS; - } - - command error_t StdControl.stop() { - call USARTControl.disableSPI(); - return SUCCESS; - } - - command void ExtFlash.startRead(uint32_t newAddr) { - - uint8_t cmd[4]; - uint8_t i; - uint32_t page = newAddr / 512; - uint32_t offset = newAddr % 512; - - addr = newAddr; - - cmd[0] = 0x03; - cmd[1] = page >> 6; - cmd[2] = (page << 2) | (offset >> 8); - cmd[3] = offset; - - TOSH_CLR_FLASH_CS_PIN(); - - for ( i = 0; i < sizeof(cmd); i++ ) { - call USARTControl.tx(cmd[i]); - while(call USARTControl.isTxEmpty() != SUCCESS); - } - } - - command uint8_t ExtFlash.readByte() { - if (!(addr & 0x1ff)) { - call ExtFlash.stopRead(); - call ExtFlash.startRead(addr); - } - addr++; - call USARTControl.rx(); - call USARTControl.tx(0); - while(call USARTControl.isRxIntrPending() != SUCCESS); - return call USARTControl.rx(); - } - - command void ExtFlash.stopRead() { - TOSH_SET_FLASH_CS_PIN(); - } - -} diff --git a/tos/lib/tosboot/epic/ExtFlashP.nc b/tos/lib/tosboot/epic/ExtFlashP.nc new file mode 100644 index 00000000..621ead10 --- /dev/null +++ b/tos/lib/tosboot/epic/ExtFlashP.nc @@ -0,0 +1,98 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +/** + * @author Jonathan Hui + * @author Razvan Musaloiu-E. + */ + +module ExtFlashP { + provides { + interface StdControl; + interface Init; + interface ExtFlash; + } + uses { + interface HplUsartControl as UsartControl; + } +} + +implementation { + + uint32_t addr; + + command error_t Init.init() { + TOSH_MAKE_FLASH_CS_OUTPUT(); + TOSH_SET_FLASH_CS_PIN(); + call UsartControl.setModeSPI(); + return SUCCESS; + } + + command error_t StdControl.start() { + return SUCCESS; + } + + command error_t StdControl.stop() { + call UsartControl.disableSPI(); + return SUCCESS; + } + + command void ExtFlash.startRead(uint32_t newAddr) { + + uint8_t cmd[4]; + uint8_t i; + uint32_t page = newAddr / 512; + uint32_t offset = newAddr % 512; + + addr = newAddr; + + cmd[0] = 0x03; + cmd[1] = page >> 6; + cmd[2] = (page << 2) | (offset >> 8); + cmd[3] = offset; + + TOSH_CLR_FLASH_CS_PIN(); + + for ( i = 0; i < sizeof(cmd); i++ ) { + call UsartControl.tx(cmd[i]); + while(call UsartControl.isTxEmpty() != SUCCESS); + } + } + + command uint8_t ExtFlash.readByte() { + if (!(addr & 0x1ff)) { + call ExtFlash.stopRead(); + call ExtFlash.startRead(addr); + } + addr++; + call UsartControl.rx(); + call UsartControl.tx(0); + while(call UsartControl.isRxIntrPending() != SUCCESS); + return call UsartControl.rx(); + } + + command void ExtFlash.stopRead() { + TOSH_SET_FLASH_CS_PIN(); + } + +} diff --git a/tos/lib/tosboot/iris/ProgFlashC.nc b/tos/lib/tosboot/iris/ProgFlashC.nc new file mode 100644 index 00000000..3861a538 --- /dev/null +++ b/tos/lib/tosboot/iris/ProgFlashC.nc @@ -0,0 +1,65 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ +#include + +module ProgFlashC { + provides { + interface ProgFlash; + } +} + +implementation { + + + command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) { + + uint16_t* wordBuf = (uint16_t*)buf; + uint32_t i; + + if ( addr + len > TOSBOOT_START ) + return FAIL; + + boot_page_erase( addr ); + while( boot_rww_busy() ) + boot_rww_enable(); + + for ( i = 0; i < len; i += 2 ) + boot_page_fill( addr + i, *wordBuf++ ); + + boot_page_write( addr ); + + while ( boot_rww_busy() ) + boot_rww_enable(); + + return SUCCESS; + + } + +} diff --git a/tos/lib/tosboot/iris/ProgFlashM.nc b/tos/lib/tosboot/iris/ProgFlashM.nc deleted file mode 100644 index 34c60183..00000000 --- a/tos/lib/tosboot/iris/ProgFlashM.nc +++ /dev/null @@ -1,65 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ -#include - -module ProgFlashM { - provides { - interface ProgFlash; - } -} - -implementation { - - - command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) { - - uint16_t* wordBuf = (uint16_t*)buf; - uint32_t i; - - if ( addr + len > TOSBOOT_START ) - return FAIL; - - boot_page_erase( addr ); - while( boot_rww_busy() ) - boot_rww_enable(); - - for ( i = 0; i < len; i += 2 ) - boot_page_fill( addr + i, *wordBuf++ ); - - boot_page_write( addr ); - - while ( boot_rww_busy() ) - boot_rww_enable(); - - return SUCCESS; - - } - -} diff --git a/tos/lib/tosboot/m16c62p/ProgFlashC.nc b/tos/lib/tosboot/m16c62p/ProgFlashC.nc new file mode 100644 index 00000000..131171e2 --- /dev/null +++ b/tos/lib/tosboot/m16c62p/ProgFlashC.nc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of Communication Group at Lulea University of Technology + * nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Wiring so that the ProgFlashP module gets access to the HplM16c62pFlashC + * module. + * + * @author Henrik Makitaavola + */ +configuration ProgFlashC +{ + provides interface ProgFlash; +} +implementation +{ + components ProgFlashP, HplM16c62pFlashC; + + ProgFlashP.Flash -> HplM16c62pFlashC; + ProgFlash = ProgFlashP; +} \ No newline at end of file diff --git a/tos/lib/tosboot/m16c62p/ProgFlashM.nc b/tos/lib/tosboot/m16c62p/ProgFlashM.nc deleted file mode 100644 index 64669891..00000000 --- a/tos/lib/tosboot/m16c62p/ProgFlashM.nc +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2009 Communication Group and Eislab at - * Lulea University of Technology - * - * Contact: Laurynas Riliskis, LTU - * Mail: laurynas.riliskis@ltu.se - * All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - Neither the name of Communication Group at Lulea University of Technology - * nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD - * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Wiring so that the ProgFlashP module gets access to the HplM16c62pFlashC - * module. - * - * @author Henrik Makitaavola - */ -configuration ProgFlashM -{ - provides interface ProgFlash; -} -implementation -{ - components ProgFlashP, HplM16c62pFlashC; - - ProgFlashP.Flash -> HplM16c62pFlashC; - ProgFlash = ProgFlashP; -} \ No newline at end of file diff --git a/tos/lib/tosboot/msp430/HPLUSART0M.nc b/tos/lib/tosboot/msp430/HPLUSART0M.nc deleted file mode 100644 index 34e4422c..00000000 --- a/tos/lib/tosboot/msp430/HPLUSART0M.nc +++ /dev/null @@ -1,128 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ - -module HPLUSART0M { - provides interface HPLUSARTControl; -} -implementation { - - command void HPLUSARTControl.disableSPI() { - // USART0 SPI module disable - //ME1 &= ~USPIE0; - - // set to PUC values - ME1 = 0; - U0CTL = 1; - U0TCTL = 1; - U0RCTL = 0; - } - - command void HPLUSARTControl.setModeSPI() { - - //U0CTL = SWRST; - - // 8-bit char, SPI-mode, USART as master - U0CTL = SWRST | CHAR | SYNC | MM; - - // 3-pin + half-cycle delayed UCLK - U0TCTL |= STC + CKPH + SSEL_SMCLK; - - // as fast as possible - U0BR0 = 0x02; - U0BR1 = 0; - - // enable SPI - ME1 |= USPIE0; - - U0CTL &= ~SWRST; - - // clear interrupts - IFG1 = 0; - - } - - command void HPLUSARTControl.disableI2C() { - /* - U0CTL = 1; - U0TCTL = 1; - I2CTCTL = 0; - */ - U0CTL &= ~I2CEN; - U0CTL &= ~I2C; - I2CTCTL = 0; - call HPLUSARTControl.disableSPI(); - } - - command void HPLUSARTControl.setModeI2C() { - - // Recommended init procedure - U0CTL = I2C + SYNC + MST; - - // use 1MHz SMCLK as the I2C reference - I2CTCTL |= I2CSSEL_2 | I2CTRX; - - // Enable I2C - U0CTL |= I2CEN; - - return; - } - - command error_t HPLUSARTControl.isTxEmpty(){ - if (U0TCTL & TXEPT) { - return SUCCESS; - } - return FAIL; - } - - command error_t HPLUSARTControl.isTxIntrPending(){ - if (IFG1 & UTXIFG0){ - IFG1 &= ~UTXIFG0; - return SUCCESS; - } - return FAIL; - } - - command error_t HPLUSARTControl.isRxIntrPending(){ - if (IFG1 & URXIFG0){ - IFG1 &= ~URXIFG0; - return SUCCESS; - } - return FAIL; - } - - command void HPLUSARTControl.tx(uint8_t data){ - U0TXBUF = data; - } - - command uint8_t HPLUSARTControl.rx(){ - return U0RXBUF; - } - -} diff --git a/tos/lib/tosboot/msp430/HPLUSARTControl.nc b/tos/lib/tosboot/msp430/HPLUSARTControl.nc deleted file mode 100644 index c0254b17..00000000 --- a/tos/lib/tosboot/msp430/HPLUSARTControl.nc +++ /dev/null @@ -1,46 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ - -includes msp430usart; - -interface HPLUSARTControl { - - command void disableSPI(); - command void setModeSPI(); - command void disableI2C(); - command void setModeI2C(); - command error_t isTxEmpty(); - command error_t isTxIntrPending(); - command error_t isRxIntrPending(); - command void tx(uint8_t data); - command uint8_t rx(); - -} - diff --git a/tos/lib/tosboot/msp430/HplUsart0C.nc b/tos/lib/tosboot/msp430/HplUsart0C.nc new file mode 100644 index 00000000..e47ec505 --- /dev/null +++ b/tos/lib/tosboot/msp430/HplUsart0C.nc @@ -0,0 +1,128 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +module HplUsart0C { + provides interface HplUsartControl; +} +implementation { + + command void HplUsartControl.disableSPI() { + // USART0 SPI module disable + //ME1 &= ~USPIE0; + + // set to PUC values + ME1 = 0; + U0CTL = 1; + U0TCTL = 1; + U0RCTL = 0; + } + + command void HplUsartControl.setModeSPI() { + + //U0CTL = SWRST; + + // 8-bit char, SPI-mode, USART as master + U0CTL = SWRST | CHAR | SYNC | MM; + + // 3-pin + half-cycle delayed UCLK + U0TCTL |= STC + CKPH + SSEL_SMCLK; + + // as fast as possible + U0BR0 = 0x02; + U0BR1 = 0; + + // enable SPI + ME1 |= USPIE0; + + U0CTL &= ~SWRST; + + // clear interrupts + IFG1 = 0; + + } + + command void HplUsartControl.disableI2C() { + /* + U0CTL = 1; + U0TCTL = 1; + I2CTCTL = 0; + */ + U0CTL &= ~I2CEN; + U0CTL &= ~I2C; + I2CTCTL = 0; + call HplUsartControl.disableSPI(); + } + + command void HplUsartControl.setModeI2C() { + + // Recommended init procedure + U0CTL = I2C + SYNC + MST; + + // use 1MHz SMCLK as the I2C reference + I2CTCTL |= I2CSSEL_2 | I2CTRX; + + // Enable I2C + U0CTL |= I2CEN; + + return; + } + + command error_t HplUsartControl.isTxEmpty(){ + if (U0TCTL & TXEPT) { + return SUCCESS; + } + return FAIL; + } + + command error_t HplUsartControl.isTxIntrPending(){ + if (IFG1 & UTXIFG0){ + IFG1 &= ~UTXIFG0; + return SUCCESS; + } + return FAIL; + } + + command error_t HplUsartControl.isRxIntrPending(){ + if (IFG1 & URXIFG0){ + IFG1 &= ~URXIFG0; + return SUCCESS; + } + return FAIL; + } + + command void HplUsartControl.tx(uint8_t data){ + U0TXBUF = data; + } + + command uint8_t HplUsartControl.rx(){ + return U0RXBUF; + } + +} diff --git a/tos/lib/tosboot/msp430/HplUsartControl.nc b/tos/lib/tosboot/msp430/HplUsartControl.nc new file mode 100644 index 00000000..02feb351 --- /dev/null +++ b/tos/lib/tosboot/msp430/HplUsartControl.nc @@ -0,0 +1,46 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +#include + +interface HplUsartControl { + + command void disableSPI(); + command void setModeSPI(); + command void disableI2C(); + command void setModeI2C(); + command error_t isTxEmpty(); + command error_t isTxIntrPending(); + command error_t isRxIntrPending(); + command void tx(uint8_t data); + command uint8_t rx(); + +} + diff --git a/tos/lib/tosboot/msp430/ProgFlashC.nc b/tos/lib/tosboot/msp430/ProgFlashC.nc new file mode 100644 index 00000000..2c87c6f9 --- /dev/null +++ b/tos/lib/tosboot/msp430/ProgFlashC.nc @@ -0,0 +1,70 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +module ProgFlashC { + provides { + interface ProgFlash; + } +} + +implementation { + + enum { + RESET_ADDR = 0xfffe, + }; + + command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, uint16_t len) { + + volatile uint16_t *flashAddr = (uint16_t*)(uint16_t)addr; + uint16_t *wordBuf = (uint16_t*)buf; + uint16_t i = 0; + + // len is 16 bits so it can't be larger than 0xffff + // make sure we can't wrap around + if (addr < (0xffff - (len >> 1))) { + FCTL2 = FWKEY + FSSEL1 + FN2; + FCTL3 = FWKEY; + FCTL1 = FWKEY + ERASE; + *flashAddr = 0; + FCTL1 = FWKEY + WRT; + for (i = 0; i < (len >> 1); i++, flashAddr++) { + if ((uint16_t)flashAddr != RESET_ADDR) + *flashAddr = wordBuf[i]; + else + *flashAddr = TOSBOOT_START; + } + FCTL1 = FWKEY; + FCTL3 = FWKEY + LOCK; + return SUCCESS; + } + return FAIL; + } + +} diff --git a/tos/lib/tosboot/msp430/ProgFlashM.nc b/tos/lib/tosboot/msp430/ProgFlashM.nc deleted file mode 100644 index aa0adcca..00000000 --- a/tos/lib/tosboot/msp430/ProgFlashM.nc +++ /dev/null @@ -1,70 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ - -module ProgFlashM { - provides { - interface ProgFlash; - } -} - -implementation { - - enum { - RESET_ADDR = 0xfffe, - }; - - command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, uint16_t len) { - - volatile uint16_t *flashAddr = (uint16_t*)(uint16_t)addr; - uint16_t *wordBuf = (uint16_t*)buf; - uint16_t i = 0; - - // len is 16 bits so it can't be larger than 0xffff - // make sure we can't wrap around - if (addr < (0xffff - (len >> 1))) { - FCTL2 = FWKEY + FSSEL1 + FN2; - FCTL3 = FWKEY; - FCTL1 = FWKEY + ERASE; - *flashAddr = 0; - FCTL1 = FWKEY + WRT; - for (i = 0; i < (len >> 1); i++, flashAddr++) { - if ((uint16_t)flashAddr != RESET_ADDR) - *flashAddr = wordBuf[i]; - else - *flashAddr = TOSBOOT_START; - } - FCTL1 = FWKEY; - FCTL3 = FWKEY + LOCK; - return SUCCESS; - } - return FAIL; - } - -} diff --git a/tos/lib/tosboot/msp430f1611/PluginC.nc b/tos/lib/tosboot/msp430f1611/PluginC.nc index 860b2486..738bcae5 100644 --- a/tos/lib/tosboot/msp430f1611/PluginC.nc +++ b/tos/lib/tosboot/msp430f1611/PluginC.nc @@ -36,11 +36,11 @@ configuration PluginC { implementation { - components ExtFlashC, LedsC, PowerOffM; + components ExtFlashC, LedsC, PowerOffC; - StdControl = PowerOffM; + StdControl = PowerOffC; - PowerOffM.Leds -> LedsC; - PowerOffM.SubControl -> ExtFlashC; + PowerOffC.Leds -> LedsC; + PowerOffC.SubControl -> ExtFlashC; } diff --git a/tos/lib/tosboot/msp430f1611/PowerOffC.nc b/tos/lib/tosboot/msp430f1611/PowerOffC.nc new file mode 100644 index 00000000..e998cc30 --- /dev/null +++ b/tos/lib/tosboot/msp430f1611/PowerOffC.nc @@ -0,0 +1,85 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2004 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +module PowerOffC { + provides { + interface Init; + interface StdControl; + } + uses { + interface Leds; + interface StdControl as SubControl; + } +} + +implementation { + + void haltsystem() { + + uint16_t _lpmreg; + + TOSH_SET_PIN_DIRECTIONS(); + + call SubControl.stop(); + + call Leds.glow(0x7, 0x0); + + _lpmreg = LPM4_bits; + _lpmreg |= SR_GIE; + + __asm__ __volatile__( "bis %0, r2" : : "m" ((uint16_t)_lpmreg) ); + + } + + command error_t Init.init() { + return SUCCESS; + } + + command error_t StdControl.start() { + + int i; + + // wait a short period for things to stabilize + for ( i = 0; i < 4; i++ ) + wait(0xffff); + + // if user button is pressed, power down + if (!TOSH_READ_USERINT_PIN()) + haltsystem(); + + return SUCCESS; + + } + + command error_t StdControl.stop() { + return SUCCESS; + } + +} diff --git a/tos/lib/tosboot/msp430f1611/PowerOffM.nc b/tos/lib/tosboot/msp430f1611/PowerOffM.nc deleted file mode 100644 index 94d8dc37..00000000 --- a/tos/lib/tosboot/msp430f1611/PowerOffM.nc +++ /dev/null @@ -1,85 +0,0 @@ -// $Id$ - -/* - * - * - * "Copyright (c) 2000-2004 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - */ - -/** - * @author Jonathan Hui - */ - -module PowerOffM { - provides { - interface Init; - interface StdControl; - } - uses { - interface Leds; - interface StdControl as SubControl; - } -} - -implementation { - - void haltsystem() { - - uint16_t _lpmreg; - - TOSH_SET_PIN_DIRECTIONS(); - - call SubControl.stop(); - - call Leds.glow(0x7, 0x0); - - _lpmreg = LPM4_bits; - _lpmreg |= SR_GIE; - - __asm__ __volatile__( "bis %0, r2" : : "m" ((uint16_t)_lpmreg) ); - - } - - command error_t Init.init() { - return SUCCESS; - } - - command error_t StdControl.start() { - - int i; - - // wait a short period for things to stabilize - for ( i = 0; i < 4; i++ ) - wait(0xffff); - - // if user button is pressed, power down - if (!TOSH_READ_USERINT_PIN()) - haltsystem(); - - return SUCCESS; - - } - - command error_t StdControl.stop() { - return SUCCESS; - } - -} diff --git a/tos/lib/tosboot/stm25p/ExtFlashC.nc b/tos/lib/tosboot/stm25p/ExtFlashC.nc index 9f7d5347..34ada4e1 100644 --- a/tos/lib/tosboot/stm25p/ExtFlashC.nc +++ b/tos/lib/tosboot/stm25p/ExtFlashC.nc @@ -39,13 +39,13 @@ configuration ExtFlashC { implementation { components - ExtFlashM, - HPLUSART0M; + ExtFlashP, + HplUsart0C; - Init = ExtFlashM; - StdControl = ExtFlashM; - ExtFlash = ExtFlashM; + Init = ExtFlashP; + StdControl = ExtFlashP; + ExtFlash = ExtFlashP; - ExtFlashM.USARTControl -> HPLUSART0M; + ExtFlashP.UsartControl -> HplUsart0C; } diff --git a/tos/lib/tosboot/stm25p/ExtFlashM.nc b/tos/lib/tosboot/stm25p/ExtFlashM.nc deleted file mode 100644 index b9909b29..00000000 --- a/tos/lib/tosboot/stm25p/ExtFlashM.nc +++ /dev/null @@ -1,114 +0,0 @@ -// $Id$ - -/* - * "Copyright (c) 2000-2005 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice, the following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - */ - -/** - * @author Jonathan Hui - */ - -module ExtFlashM { - provides { - interface StdControl; - interface Init; - interface ExtFlash; - } - uses { - interface HPLUSARTControl as USARTControl; - } -} - -implementation { - - command error_t Init.init() { - TOSH_MAKE_FLASH_HOLD_OUTPUT(); - TOSH_MAKE_FLASH_CS_OUTPUT(); - TOSH_SET_FLASH_HOLD_PIN(); - call USARTControl.setModeSPI(); - return SUCCESS; - } - - command error_t StdControl.start() { - return SUCCESS; - } - - command error_t StdControl.stop() { - - TOSH_CLR_FLASH_CS_PIN(); - - call USARTControl.tx(0xb9); - while(call USARTControl.isTxEmpty() != SUCCESS); - - TOSH_SET_FLASH_CS_PIN(); - - call USARTControl.disableSPI(); - - return SUCCESS; - - } - - void powerOnFlash() { - - uint8_t i; - - TOSH_CLR_FLASH_CS_PIN(); - - // command byte + 3 dummy bytes + signature - for ( i = 0; i < 5; i++ ) { - call USARTControl.tx(0xab); - while(call USARTControl.isTxIntrPending() != SUCCESS); - } - - TOSH_SET_FLASH_CS_PIN(); - - } - - command void ExtFlash.startRead(uint32_t addr) { - - uint8_t i; - - powerOnFlash(); - - TOSH_CLR_FLASH_CS_PIN(); - - // add command byte to address - addr |= (uint32_t)0x3 << 24; - - // address - for ( i = 4; i > 0; i-- ) { - call USARTControl.tx((addr >> (i-1)*8) & 0xff); - while(call USARTControl.isTxIntrPending() != SUCCESS); - } - - } - - command uint8_t ExtFlash.readByte() { - call USARTControl.rx(); - call USARTControl.tx(0); - while(call USARTControl.isRxIntrPending() != SUCCESS); - return call USARTControl.rx(); - } - - command void ExtFlash.stopRead() { - TOSH_SET_FLASH_CS_PIN(); - } - -} diff --git a/tos/lib/tosboot/stm25p/ExtFlashP.nc b/tos/lib/tosboot/stm25p/ExtFlashP.nc new file mode 100644 index 00000000..f1a62175 --- /dev/null +++ b/tos/lib/tosboot/stm25p/ExtFlashP.nc @@ -0,0 +1,114 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +/** + * @author Jonathan Hui + */ + +module ExtFlashP { + provides { + interface StdControl; + interface Init; + interface ExtFlash; + } + uses { + interface HplUsartControl as UsartControl; + } +} + +implementation { + + command error_t Init.init() { + TOSH_MAKE_FLASH_HOLD_OUTPUT(); + TOSH_MAKE_FLASH_CS_OUTPUT(); + TOSH_SET_FLASH_HOLD_PIN(); + call UsartControl.setModeSPI(); + return SUCCESS; + } + + command error_t StdControl.start() { + return SUCCESS; + } + + command error_t StdControl.stop() { + + TOSH_CLR_FLASH_CS_PIN(); + + call UsartControl.tx(0xb9); + while(call UsartControl.isTxEmpty() != SUCCESS); + + TOSH_SET_FLASH_CS_PIN(); + + call UsartControl.disableSPI(); + + return SUCCESS; + + } + + void powerOnFlash() { + + uint8_t i; + + TOSH_CLR_FLASH_CS_PIN(); + + // command byte + 3 dummy bytes + signature + for ( i = 0; i < 5; i++ ) { + call UsartControl.tx(0xab); + while(call UsartControl.isTxIntrPending() != SUCCESS); + } + + TOSH_SET_FLASH_CS_PIN(); + + } + + command void ExtFlash.startRead(uint32_t addr) { + + uint8_t i; + + powerOnFlash(); + + TOSH_CLR_FLASH_CS_PIN(); + + // add command byte to address + addr |= (uint32_t)0x3 << 24; + + // address + for ( i = 4; i > 0; i-- ) { + call UsartControl.tx((addr >> (i-1)*8) & 0xff); + while(call UsartControl.isTxIntrPending() != SUCCESS); + } + + } + + command uint8_t ExtFlash.readByte() { + call UsartControl.rx(); + call UsartControl.tx(0); + while(call UsartControl.isRxIntrPending() != SUCCESS); + return call UsartControl.rx(); + } + + command void ExtFlash.stopRead() { + TOSH_SET_FLASH_CS_PIN(); + } + +}