[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/tosthreads/lib/tinyld BigCrc.nc, NONE, 1.1 BigCrcC.nc, NONE, 1.1 BigCrcP.nc, NONE, 1.1 DynamicLoader.h, NONE, 1.1 DynamicLoader.nc, NONE, 1.1 DynamicLoaderC.nc, NONE, 1.1 DynamicLoaderP.nc, NONE, 1.1 LoadSourceMapC.nc, NONE, 1.1 LoadSourceMapP.nc, NONE, 1.1 MemoryStorageC.nc, NONE, 1.1 MemoryStorageP.nc, NONE, 1.1 NullVolumeMapC.nc, NONE, 1.1 PMManager.nc, NONE, 1.1 PMManagerC.nc, NONE, 1.1 PMManagerP.nc, NONE, 1.1 TosThreadApiC.nc, NONE, 1.1 UserButton.nc, NONE, 1.1 UserButtonC.nc, NONE, 1.1 UserButtonP.nc, NONE, 1.1 slcs_types.h, NONE, 1.1 tosthread_slcs_types.h, NONE, 1.1
Chieh-Jan Mike Liang
liang_mike at users.sourceforge.net
Tue Feb 3 23:41:37 PST 2009
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tosthreads/lib/tinyld
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8269/tos/lib/tosthreads/lib/tinyld
Added Files:
BigCrc.nc BigCrcC.nc BigCrcP.nc DynamicLoader.h
DynamicLoader.nc DynamicLoaderC.nc DynamicLoaderP.nc
LoadSourceMapC.nc LoadSourceMapP.nc MemoryStorageC.nc
MemoryStorageP.nc NullVolumeMapC.nc PMManager.nc PMManagerC.nc
PMManagerP.nc TosThreadApiC.nc UserButton.nc UserButtonC.nc
UserButtonP.nc slcs_types.h tosthread_slcs_types.h
Log Message:
Initial commit of TinyLD (TOSThreads' dynamic loader)
--- NEW FILE: BigCrc.nc ---
interface BigCrc {
command error_t computeCrc(void* buf, uint16_t len);
event void computeCrcDone(void* buf, uint16_t len, uint16_t crc, error_t error);
}
--- NEW FILE: BigCrcC.nc ---
configuration BigCrcC {
provides interface BigCrc;
}
implementation {
components CrcC,
BigCrcP;
BigCrc = BigCrcP;
BigCrcP.Crc -> CrcC;
}
--- NEW FILE: BigCrcP.nc ---
module BigCrcP {
provides interface BigCrc;
uses interface Crc;
}
implementation {
bool isBusy = FALSE;
void* inbuf;
uint16_t inlen;
uint16_t pos;
uint16_t computedCrc;
task void computeCrc()
{
uint8_t len = 0xFF;
if (inlen < 0xFF) {
len = inlen;
}
computedCrc = call Crc.seededCrc16(computedCrc, inbuf + pos, len);
inlen -= len;
pos += len;
if (inlen > 0) {
post computeCrc();
} else {
isBusy = FALSE;
signal BigCrc.computeCrcDone(inbuf, pos + 1, computedCrc, SUCCESS);
}
}
command error_t BigCrc.computeCrc(void* buf, uint16_t len)
{
if (isBusy == TRUE) {
return EBUSY;
}
inbuf = buf;
inlen = len;
computedCrc = pos = 0;
post computeCrc();
return SUCCESS;
}
}
--- NEW FILE: DynamicLoader.h ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#ifndef DYNAMICLOADER_H
#define DYNAMICLOADER_H
//#defines for setting up which set of apis the dynamic loader
//should recognize. This should eventually move into a file that
//gets #included in here, but for now we set the defaults here.
#ifdef TOSTHREAD_TENET
#define ApiForDynamicLoaderC TosThreadTenetApiC
#define SLCS_TYPES_FILE "tosthread_tenet_slcs_types.h"
#else
#define ApiForDynamicLoaderC TosThreadApiC
#define SLCS_TYPES_FILE "tosthread_slcs_types.h"
#endif
#define TOSTHREAD_DYNAMIC_LOADER
#ifndef DISABLE_LOADER_FLASH
#include "StorageVolumes.h"
#endif
enum {
READSOURCE_MEMORY = 0xFF,
};
#endif
--- NEW FILE: DynamicLoader.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#include "thread.h"
interface DynamicLoader
{
command error_t loadFromFlash(uint8_t volumeId);
event void loadFromFlashDone(uint8_t volumeId, tosthread_t id, error_t error);
command error_t loadFromMemory(void *addr);
event void loadFromMemoryDone(void *addr, tosthread_t id, error_t error);
}
--- NEW FILE: DynamicLoaderC.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
*/
#include "DynamicLoader.h"
configuration DynamicLoaderC
{
provides interface DynamicLoader;
}
implementation
{
components MainC,
DynamicLoaderP,
LedsC, NoLedsC,
LoadSourceMapC,
DynamicThreadC,
ReferenceCounterC,
TinyThreadSchedulerC;
DynamicLoader = DynamicLoaderP;
DynamicLoaderP <- MainC.SoftwareInit;
DynamicLoaderP.Leds -> LedsC;
DynamicLoaderP.ImageRead -> LoadSourceMapC;
DynamicLoaderP.DynamicThread -> DynamicThreadC;
DynamicLoaderP.ReferenceCounter -> ReferenceCounterC;
DynamicLoaderP.ThreadNotification -> DynamicThreadC;
DynamicLoaderP.ThreadScheduler -> TinyThreadSchedulerC;
components ApiForDynamicLoaderC;
components PMManagerC;
DynamicLoaderP.PMManager -> PMManagerC;
#ifndef DISABLE_LOADER_USERBUTTON
components UserButtonC;
DynamicLoaderP.UserButton -> UserButtonC;
#endif
}
--- NEW FILE: DynamicLoaderP.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
*/
#include SLCS_TYPES_FILE
#include "thread.h"
module DynamicLoaderP
{
provides {
interface Init;
interface DynamicLoader;
}
uses {
interface Leds;
interface BlockRead as ImageRead[uint8_t id];
interface DynamicThread;
interface ThreadNotification[uint8_t id];
interface ThreadScheduler;
interface ReferenceCounter;
interface PMManager;
#ifndef DISABLE_LOADER_USERBUTTON
interface UserButton;
#endif
}
}
implementation
{
uint8_t *code; // Points to first byte of the program code in the internal flash
uint8_t *tablesMemory;
void *gVarMemory;
struct prog_desc prog_desc;
init_block_t *proc;
uint16_t codePtr; // Records what code has been copied to the internal flash
uint16_t nextAddr;
uint8_t *nextTask_chain; // Used to update the next patching address in a chain
uint8_t readSource; // Loads from flash or memory
uint16_t readSourceOffset; // If loading from memory, then this is effectively the passed-in memory address
error_t retError = FAIL;
tosthread_t handler;
uint16_t threadCodeSizes[TOSTHREAD_MAX_NUM_THREADS];
uint16_t codeFirstAddrs[TOSTHREAD_MAX_NUM_THREADS];
async event void ThreadNotification.justCreated[uint8_t id]()
{
thread_t *t = call ThreadScheduler.threadInfo(id);
if(t->init_block != NULL) {
call ReferenceCounter.increment(&(t->init_block->thread_counter));
}
}
async event void ThreadNotification.aboutToDestroy[uint8_t id]()
{
thread_t *t = call ThreadScheduler.threadInfo(id);
if(t->init_block != NULL) {
call ReferenceCounter.decrement(&(t->init_block->thread_counter));
}
}
task void loadDoneTask()
{
if (retError != SUCCESS)
handler = TOSTHREAD_INVALID_THREAD_ID;
if (readSource == READSOURCE_MEMORY) {
signal DynamicLoader.loadFromMemoryDone(((void *)readSourceOffset), handler, retError);
} else {
signal DynamicLoader.loadFromFlashDone(readSource, handler, retError);
}
}
void initProgDesc()
{
prog_desc.main_addr = 0;
prog_desc.alloc_count = 0;
prog_desc.g_reloc_count = 0;
prog_desc.l_reloc_count = 0;
prog_desc.code_count = 0;
prog_desc.patch_table_count = 0;
prog_desc.loading_stage = 0;
codePtr = 0;
}
void errorHandler()
{
call Leds.set(7);
if (tablesMemory != NULL) { free(tablesMemory); tablesMemory = NULL; }
if (gVarMemory != NULL) { free(gVarMemory); gVarMemory = NULL; }
if (proc != NULL) { free(proc); proc = NULL; }
initProgDesc();
retError = FAIL;
post loadDoneTask();
}
void run_proc(void *arg)
{
init_block_t* curProc = arg;
thread_t* t = call ThreadScheduler.currentThreadInfo();
t->init_block = curProc;
(*(curProc->init_ptr))(curProc->init_arg);
call ReferenceCounter.waitOnValue(&(curProc->thread_counter), 0);
call PMManager.release(codeFirstAddrs[t->id], threadCodeSizes[t->id]);
codeFirstAddrs[t->id] = 0;
threadCodeSizes[t->id] = 0;
if (curProc->globals != NULL) {
free(curProc->globals);
}
free(curProc);
}
task void start_prog()
{
free(tablesMemory);
proc = malloc(sizeof(init_block_t));
proc->globals = gVarMemory;
proc->init_ptr = (void *)((uint16_t)code + prog_desc.main_addr);
proc->init_arg = NULL;
call ReferenceCounter.init( &(proc->thread_counter) );
if (call DynamicThread.create(&handler, run_proc, proc, 200) == SUCCESS) {
codeFirstAddrs[handler] = (uint16_t)code;
threadCodeSizes[handler] = prog_desc.code_count;
retError = SUCCESS;
post loadDoneTask();
} else {
retError = FAIL;
post loadDoneTask();
if (proc->globals != NULL) {
free(proc->globals);
}
free(proc);
}
initProgDesc();
}
// Gets write access to the internal flash
void eeprom_w()
{
FCTL2 = FWKEY + FSSEL1 + FN2; // selects SMCLK and divides it by 4
FCTL3 = FWKEY; // enables the writing/erasing by clearing the LOCK bit
FCTL1 = FWKEY + WRT; // enables the writing
}
// Gets read-only access to the internal flash
void eeprom_r()
{
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // disabling the writing/erasing
}
// Calculates where should the code be placed in the internal flash
/*
uint16_t eeprom_code_addr()
{
uint16_t addr;
addr = (((prog_desc.code_count - 1) / 512) + 1) * 512; // Spaces needed for the code
addr = 0xFFFF - 512 - addr + 1; // The 1 is to align the code
return addr;
}
*/
// Loads program image meta data
void loader_metaData()
{
prog_desc.patch_table_count = prog_desc.alloc_count +
prog_desc.g_reloc_count +
prog_desc.l_reloc_count;
prog_desc.code_offset = sizeof(prog_desc.main_addr) +
sizeof(prog_desc.alloc_count) +
sizeof(prog_desc.alloc_size) +
sizeof(prog_desc.g_reloc_count) +
sizeof(prog_desc.l_reloc_count) +
sizeof(prog_desc.datasec_count) +
sizeof(prog_desc.code_count) +
(prog_desc.patch_table_count * 4) +
(prog_desc.datasec_count * 6);
if (prog_desc.patch_table_count > 0 || prog_desc.datasec_count > 0) {
if ((prog_desc.patch_table_count * 4) > (prog_desc.datasec_count * 6)) {
tablesMemory = malloc(prog_desc.patch_table_count * 4);
} else {
tablesMemory = malloc(prog_desc.datasec_count * 6);
}
} else {
tablesMemory = NULL;
}
}
// Prepares the patch table before patching addresses in the binary code
void loader_patch_table()
{
uint16_t i, tempUInt16 = 0;
// Find out the total space global variables need, and malloc
/*
for (i = 0; i < (prog_desc.alloc_count * 4); i+=4) {
tempUInt16 += *((uint16_t *)&tablesMemory[i]);
*((uint16_t *)&tablesMemory[i]) = tempUInt16 - *((uint16_t *)&tablesMemory[i]);
}
*/
if (prog_desc.alloc_size > 0) {
gVarMemory = malloc(prog_desc.alloc_size);
memset(gVarMemory, 0, prog_desc.alloc_size);
} else {
gVarMemory = NULL;
}
// Some "real" addresses need offsets added. For example, local relocation table entries need
// the starting code address
for (i = 0; i < (prog_desc.patch_table_count * 4); i+=4) {
if (i < (prog_desc.alloc_count * 4)) {
tempUInt16 = (uint16_t)gVarMemory; // Allocation table needs memory's offset
} else if (i < ((prog_desc.alloc_count + prog_desc.g_reloc_count) * 4)) {
tempUInt16 = 0; // Global relocation table doesn't need anything
} else {
tempUInt16 = (uint16_t)code; // Local relocation table needs code's offset
}
*((uint16_t *)&(tablesMemory[i])) = *((uint16_t *)&(tablesMemory[i])) + tempUInt16; // Writes the real address
}
// Converts function IDs in global relocation table to real addresses
for (i = (prog_desc.alloc_count * 4); i < ((prog_desc.alloc_count + prog_desc.g_reloc_count) * 4); i+=4) {
tempUInt16 = *((uint16_t *)&tablesMemory[i]); // Gets function ID
tempUInt16 = (uint16_t)fun[tempUInt16].addr; // Gets the real address of the function ID
*((uint16_t *)&tablesMemory[i]) = tempUInt16; // Writes the real address
}
}
void loader_addr_1()
{
uint16_t i, laddr = 0, raddr = 0;
// Resets before start
nextTask_chain = 0x0;
nextAddr = 0;
// Gets the next task by searching for the lowest next patching address
raddr = 0xFFFF; // Temp variable to store the minimum patching address so far
laddr = 0; // Temp variable to store the current patching address
for (i = 0; i < (prog_desc.patch_table_count * 4); i+=4) {
laddr = *((uint16_t *)&tablesMemory[i + 2]);
if (((uint16_t)nextTask_chain == 0x0 && laddr != 0xFFFF) ||
raddr > laddr) {
nextTask_chain = &(tablesMemory[i]);
raddr = laddr;
}
}
if (nextTask_chain != 0x0) {
// Gets the next patching address in the chain from the flash
raddr = *((uint16_t *)&nextTask_chain[2]);
call ImageRead.read[readSource](readSourceOffset + prog_desc.code_offset + raddr,
&nextAddr,
2);
} else {
// Copies the rest of the binary code
call ImageRead.read[readSource](readSourceOffset + prog_desc.code_offset + codePtr,
&(code[codePtr]),
prog_desc.code_count - codePtr);
prog_desc.loading_stage++;
}
}
// Patches the part of binary code that needs "real" addresses
void loader_addr_2()
{
uint16_t laddr;
laddr = *((uint16_t *)&nextTask_chain[2]); // Gets the current patching address
// Updates the chain with the next patching address
if (nextAddr == 0x0000) {
nextAddr = 0xFFFF; // End of chain, marks it with a big number
}
*((uint16_t *)&nextTask_chain[2]) = nextAddr;
// Patches address in the binary code
*((uint16_t *)&code[laddr]) = *((uint16_t *)&nextTask_chain[0]);
// Copies the binary code between the last patching address and the current patching address
call ImageRead.read[readSource](readSourceOffset + prog_desc.code_offset + codePtr,
&(code[codePtr]),
laddr - codePtr);
codePtr = laddr + 2; // Notes up to what location in the binary code we have copied
}
void loader_datasec()
{
uint16_t i, j;
for (i = 0; i < (prog_desc.datasec_count * 6); i+=6) {
uint16_t destAddr = *((uint16_t *)&(tablesMemory[i])) + (uint16_t)gVarMemory; // Writes the real address
uint16_t srcAddr = *((uint16_t *)&(tablesMemory[i + 2])) + (uint16_t)code; // Writes the real address
uint16_t size = *((uint16_t *)&(tablesMemory[i + 4]));
for (j = 0; j < size; j++) {
((uint8_t *)((void *)(destAddr + j)))[0] = ((uint8_t *)((void *)(srcAddr + j)))[0];
//*((uint8_t *)&code[destAddr + j]) = *((uint8_t *)&code[srcAddr + j]);
}
}
}
void loadProgram()
{
error_t error = SUCCESS;
switch (prog_desc.loading_stage) {
case 0:
// Loads meta data to memory array
error = call ImageRead.read[readSource](readSourceOffset + 0,
&prog_desc,
7 * 2);
if (error == SUCCESS) {
prog_desc.loading_stage++; // Moves to next loading phase
} else {
errorHandler();
}
break;
case 1:
loader_metaData(); // Gets meta data
code = (void *) call PMManager.request(prog_desc.code_count); // Gets the location of where the code will be copied to
if ((uint16_t)code != 0xFFFF) {
// Loads patch table to memory array
error = call ImageRead.read[readSource](readSourceOffset + 7 * 2,
tablesMemory,
prog_desc.patch_table_count * 4);
if (error == SUCCESS) {
prog_desc.loading_stage++; // Moves to next loading phase
} else {
errorHandler();
}
} else {
errorHandler();
}
break;
case 2:
loader_patch_table();
eeprom_w(); // Gets write-access to internal flash
prog_desc.loading_stage++; // Moves to next loading phase
case 3:
loader_addr_1();
break;
case 4:
eeprom_r(); // Locks the internal flash back
error = call ImageRead.read[readSource](readSourceOffset + 7 * 2 + prog_desc.patch_table_count * 4,
tablesMemory,
prog_desc.datasec_count * 6);
if (error == SUCCESS) {
prog_desc.loading_stage++; // Moves to next loading phase
} else {
errorHandler();
}
break;
case 5:
loader_datasec();
prog_desc.loading_stage++;
case 6:
post start_prog();
break;
}
}
command error_t Init.init()
{
int i;
for (i = 0; i < TOSTHREAD_MAX_NUM_THREADS; i++) {
threadCodeSizes[i] = 0;
codeFirstAddrs[i] = 0;
}
initProgDesc();
return SUCCESS;
}
task void taskLoadProgram()
{
loadProgram();
}
error_t start_load(uint8_t in_readSource, uint16_t in_readSourceOffset)
{
if (prog_desc.loading_stage == 0) {
uint16_t i;
call Leds.set(7);
for (i = 0; i < 2000; i++) { }
call Leds.set(0);
readSource = in_readSource;
readSourceOffset = in_readSourceOffset;
post taskLoadProgram(); // Start Loading
return SUCCESS;
}
return EBUSY;
}
command error_t DynamicLoader.loadFromFlash(uint8_t volumeId) { return start_load(volumeId, 0); }
command error_t DynamicLoader.loadFromMemory(void *addr) { return start_load(READSOURCE_MEMORY, (uint16_t)addr); }
event void ImageRead.readDone[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
if (error == SUCCESS) {
if (buf == &nextAddr) {
loader_addr_2();
} else {
post taskLoadProgram();
}
} else {
errorHandler();
}
}
#ifndef DISABLE_LOADER_USERBUTTON
event void UserButton.fired()
{
call DynamicLoader.loadFromFlash(VOLUME_MICROEXEIMAGE);
}
#endif
event void ImageRead.computeCrcDone[uint8_t id](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {}
default command error_t ImageRead.read[uint8_t id](storage_addr_t addr, void *buf, storage_len_t len) { return FAIL; }
default event void DynamicLoader.loadFromFlashDone(uint8_t volumeId, tosthread_t id, error_t error) {}
default event void DynamicLoader.loadFromMemoryDone(void *addr, tosthread_t id, error_t error) {}
}
--- NEW FILE: LoadSourceMapC.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
configuration LoadSourceMapC
{
provides interface BlockRead[uint8_t id];
}
implementation
{
components LoadSourceMapP,
#ifdef DISABLE_LOADER_FLASH
NullVolumeMapC as VolumeMapC,
#else
VolumeMapC,
#endif
MemoryStorageC;
BlockRead = LoadSourceMapP;
LoadSourceMapP.SubBlockRead -> VolumeMapC;
LoadSourceMapP.SubMemoryRead -> MemoryStorageC;
}
--- NEW FILE: LoadSourceMapP.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#include "DynamicLoader.h"
module LoadSourceMapP
{
provides interface BlockRead[uint8_t id];
uses {
interface BlockRead as SubBlockRead[uint8_t id];
interface BlockRead as SubMemoryRead;
}
}
implementation
{
event void SubMemoryRead.readDone(storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
signal BlockRead.readDone[READSOURCE_MEMORY](addr, buf, len, error);
}
event void SubBlockRead.readDone[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
signal BlockRead.readDone[id](addr, buf, len, error);
}
command error_t BlockRead.read[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len)
{
error_t error = FAIL;
if (id == READSOURCE_MEMORY) {
error = call SubMemoryRead.read(addr, buf, len);
} else {
error = call SubBlockRead.read[id](addr, buf, len);
}
return error;
}
event void SubMemoryRead.computeCrcDone(storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error)
{
signal BlockRead.computeCrcDone[READSOURCE_MEMORY](addr, len, crc, error);
}
event void SubBlockRead.computeCrcDone[uint8_t id](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error)
{
signal BlockRead.computeCrcDone[id](addr, len, crc, error);
}
command error_t BlockRead.computeCrc[uint8_t id](storage_addr_t addr, storage_len_t len, uint16_t crc)
{
error_t error = FAIL;
if (id == READSOURCE_MEMORY) {
error = call SubMemoryRead.computeCrc(addr, len, crc);
} else {
error = call SubBlockRead.computeCrc[id](addr, len, crc);
}
return error;
}
command storage_len_t BlockRead.getSize[uint8_t id]()
{
storage_len_t len;
if (id == READSOURCE_MEMORY) {
len = call SubMemoryRead.getSize();
} else {
len = call SubBlockRead.getSize[id]();
}
return len;
}
default command error_t SubBlockRead.read[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
default command error_t SubBlockRead.computeCrc[uint8_t id](storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
default command storage_len_t SubBlockRead.getSize[uint8_t id]() { return 0; }
default event void BlockRead.readDone[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
default event void BlockRead.computeCrcDone[uint8_t id](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {}
}
--- NEW FILE: MemoryStorageC.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
configuration MemoryStorageC
{
provides interface BlockRead;
}
implementation
{
components MemoryStorageP,
CrcC;
BlockRead = MemoryStorageP;
MemoryStorageP.Crc -> CrcC;
}
--- NEW FILE: MemoryStorageP.nc ---
module MemoryStorageP
{
provides interface BlockRead;
uses interface Crc;
}
implementation
{
storage_addr_t retAddr;
void *retBuf;
storage_len_t retLen;
uint16_t retCrc;
task void taskReadDone()
{
signal BlockRead.readDone(retAddr, retBuf, retLen, SUCCESS);
}
command error_t BlockRead.read(storage_addr_t addr, void* buf, storage_len_t len)
{
storage_len_t i;
uint8_t *from = (uint8_t *)((void *)((uint16_t)addr));
for (i = 0; i < len; i++) {
((uint8_t *)buf)[i] = from[i];
}
retAddr = addr;
retBuf = buf;
retLen = len;
post taskReadDone();
return SUCCESS;
}
task void taskCrcDone()
{
signal BlockRead.computeCrcDone(retAddr, retLen, retCrc, SUCCESS);
}
command error_t BlockRead.computeCrc(storage_addr_t addr, storage_len_t len, uint16_t crc)
{
retCrc = call Crc.seededCrc16(crc, (void *)addr, len);
retAddr = addr;
retLen = len;
post taskCrcDone();
return SUCCESS;
}
command storage_len_t BlockRead.getSize()
{
return 0; // Not sure what to do
}
default event void BlockRead.readDone(storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
default event void BlockRead.computeCrcDone(storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {}
}
--- NEW FILE: NullVolumeMapC.nc ---
/**
* @author Jeongyeup Paek <jpaek at enl.usc.edu>
*/
#include "DynamicLoader.h"
module NullVolumeMapC
{
provides interface BlockRead[uint8_t id];
}
implementation
{
command error_t BlockRead.read[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
command error_t BlockRead.computeCrc[uint8_t id](storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
command storage_len_t BlockRead.getSize[uint8_t id]() { return 0; }
}
--- NEW FILE: PMManager.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
interface PMManager
{
command uint16_t request(uint16_t size);
command void release(uint16_t startingAddr, uint16_t size);
}
--- NEW FILE: PMManagerC.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
configuration PMManagerC
{
provides interface PMManager;
}
implementation
{
components MainC,
PMManagerP,
LedsC,
BitArrayUtilsC;
PMManager = PMManagerP;
MainC.SoftwareInit -> PMManagerP;
PMManagerP.BitArrayUtils -> BitArrayUtilsC;
PMManagerP.Leds -> LedsC;
}
--- NEW FILE: PMManagerP.nc ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
module PMManagerP {
provides {
interface Init;
interface PMManager;
}
uses {
interface BitArrayUtils;
interface Leds;
}
}
implementation {
uint16_t HOST_ROM_SIZE = 0; // Set by tos-set-symbol
uint16_t SEGMENT_SIZE = 512; // For telosb, the internal flash segment size is 512 bytes
uint16_t FLASH_ROM_START_ADDR = 0x4000; // For telosb, the program memory starts at 0x4000
uint16_t FLASH_ROM_END_ADDR = 0xFDFF; // Last free byte (the last segment is used for interrupt vector)
uint16_t numFreeSegments = 0;
uint8_t *segmentBitArray;
command error_t Init.init()
{
uint16_t numBytes;
// Adjust FLASH_ROM_START_ADDR to account for the code loaded with PMManager
if (HOST_ROM_SIZE == 0) {
// Should not be here at all
// return FAIL;
} else {
FLASH_ROM_START_ADDR += (((HOST_ROM_SIZE - 1) / SEGMENT_SIZE) + 1) * SEGMENT_SIZE;
}
// Calculates the number of available segments
numFreeSegments = FLASH_ROM_END_ADDR - FLASH_ROM_START_ADDR + 1;
numFreeSegments = ((numFreeSegments - 1) / SEGMENT_SIZE) + 1;
// Initializes an bit array to track the status of available segments
numBytes = ((numFreeSegments - 1) / 8) + 1;
segmentBitArray = malloc(numBytes);
call BitArrayUtils.clrArray(segmentBitArray, numBytes);
return SUCCESS;
}
uint16_t bitIndexToAddress(uint16_t bitIndex)
{
return FLASH_ROM_START_ADDR + (bitIndex * SEGMENT_SIZE);
}
void eraseSegment(void* addr)
{
FCTL2 = FWKEY + FSSEL1 + FN2;
FCTL3 = FWKEY;
FCTL1 = FWKEY + ERASE;
*((uint16_t *)addr) = 0;
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
}
command uint16_t PMManager.request(uint16_t size)
{
if (size > 0) {
uint8_t numSegments = ((size - 1) / SEGMENT_SIZE) + 1; // Number of segments needed to cover size
int i;
for (i = (numFreeSegments - 1); i >= 0; i--) {
if (call BitArrayUtils.getBit(segmentBitArray, i) == FALSE) {
int j, tempNumSegments = numSegments - 1;
for (j = (i - 1); j >= 0 && tempNumSegments > 0; ) {
// Checks if there are enough consecutive free segments
if (call BitArrayUtils.getBit(segmentBitArray, j) == TRUE) {
break;
} else {
j--;
tempNumSegments--;
}
}
j++;
if ((i - j + 1) >= numSegments) {
// There are enough consecutive free segments (starting segment index (j + 1))
int k;
for (k = j; k <= i; k++) {
eraseSegment((void *)bitIndexToAddress(k)); // Erase segment content
call BitArrayUtils.setBit(segmentBitArray, k); // Mark segment as occupied
}
return bitIndexToAddress(j);
} else {
i = j;
}
}
}
}
return 0xFFFF;
}
command void PMManager.release(uint16_t startingAddr, uint16_t size)
{
if ((startingAddr >= FLASH_ROM_START_ADDR && startingAddr <= FLASH_ROM_END_ADDR) &&
size > 0) {
uint8_t numSegments = ((size - 1) / SEGMENT_SIZE) + 1; // Number of segments needed to cover size
uint8_t startingSegment = (startingAddr - FLASH_ROM_START_ADDR) / SEGMENT_SIZE;
int i;
for (i = 0; i < numSegments && (i + startingSegment) < numFreeSegments; i++) {
call BitArrayUtils.clrBit(segmentBitArray, i + startingSegment); // Mark the segment as free
}
}
}
}
--- NEW FILE: TosThreadApiC.nc ---
/*
* Copyright (c) 2008 Stanford University.
* 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 the Stanford University 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.
*/
/**
* @author Kevin Klues <klueska at cs.stanford.edu>
*/
#include "tosthread.h"
configuration TosThreadApiC {
}
implementation {
//Here are all the components that implement the Tosthread API calls
components CThreadC;
#if defined(PRINTF_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components PrintfC;
#endif
#if defined(TOSTHREAD_QUEUE_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CQueueC;
#endif
#if defined(TOSTHREAD_LINKED_LIST_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CLinkedListC;
#endif
#if defined(TOSTHREAD_THREADSYNC_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CThreadSynchronizationC;
#endif
#if defined(TOSTHREAD_LEDS_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CLedsC;
#endif
#if defined(TOSTHREAD_AMRADIO_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CAMRadioC;
#endif
#if defined(TOSTHREAD_AMSERIAL_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CAMSerialC;
#endif
#if defined(TOSTHREAD_BLOCKSTORAGE_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CBlockStorageC;
#endif
#if defined(TOSTHREAD_LOGSTORAGE_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CLogStorageC;
#endif
#if defined(TOSTHREAD_COLLECTION_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
// components CCollectionC;
#endif
//Telosb sensorboard specific.
#if defined(TOSTHREAD_HAMAMATSUS1087_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CHamamatsuS1087ParC;
#endif
#if defined(TOSTHREAD_HAMAMATSUS10871_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CHamamatsuS10871TsrC;
#endif
#if defined(TOSTHREAD_SENSIRIONSHT11_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
components CSensirionSht11C;
#endif
//Universal sensorboard specific
#if defined(TOSTHREAD_SINESENSOR_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
// components CSineSensorC;
#endif
//Basicsb sensorboard specific
#if defined(TOSTHREAD_PHOTO_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
// components CPhotoC;
#endif
#if defined(TOSTHREAD_TEMP_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
// components CTempC;
#endif
}
--- NEW FILE: UserButton.nc ---
interface UserButton
{
event void fired();
}
--- NEW FILE: UserButtonC.nc ---
/* "Copyright (c) 2000-2003 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."
*/
/**
* Init/start/stop the user button with StdControl and get interrupt events
* when the button is released with MSP430Event.
*
* @author Cory Sharp <cssharp at eecs.berkeley.edu>
* @author Andrew Redfern <aredfern at kingkong.me.berkeley.edu>
*/
configuration UserButtonC
{
provides interface UserButton;
}
implementation
{
components MainC, new TimerMilliC(),
HplMsp430GeneralIOC, HplMsp430InterruptC,
UserButtonP;
UserButton = UserButtonP;
MainC.SoftwareInit -> UserButtonP;
UserButtonP -> HplMsp430GeneralIOC.Port27;
UserButtonP -> HplMsp430InterruptC.Port27;
UserButtonP.Timer -> TimerMilliC;
}
--- NEW FILE: UserButtonP.nc ---
/* "Copyright (c) 2000-2003 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."
*/
/**
* Andew's timer debouce logic used from the CountInput application.
*
* @author Cory Sharp <cssharp at eecs.berkeley.edu>
* @author Andrew Redfern <aredfern at kingkong.me.berkeley.edu>
*/
module UserButtonP
{
provides {
interface Init;
interface UserButton;
}
uses {
interface HplMsp430GeneralIO;
interface HplMsp430Interrupt;
interface Timer<TMilli>;
}
}
implementation
{
command error_t Init.init()
{
atomic {
call HplMsp430Interrupt.disable();
call HplMsp430GeneralIO.makeInput();
call HplMsp430GeneralIO.selectIOFunc();
call HplMsp430Interrupt.edge(TRUE);
call HplMsp430Interrupt.clear();
call HplMsp430Interrupt.enable();
}
return SUCCESS;
}
event void Timer.fired()
{
atomic {
call HplMsp430Interrupt.clear();
call HplMsp430Interrupt.enable();
}
}
task void debounce()
{
call Timer.startOneShot(100);
signal UserButton.fired();
}
async event void HplMsp430Interrupt.fired()
{
atomic {
call HplMsp430Interrupt.disable();
post debounce();
}
}
}
--- NEW FILE: slcs_types.h ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#ifndef _SLCS_TYPES_H
#define _SLCS_TYPES_H
#include "tosthread.h"
#include "tosthread_leds.h"
#include "tosthread_amradio.h"
#include "tosthread_blockstorage.h"
#include "tosthread_threadsync.h"
#include "tosthread_amserial.h"
#include "tosthread_queue.h"
#include "tosthread_sensirionSht11.h"
#include "tosthread_hamamatsuS10871.h"
#include "tosthread_hamamatsuS1087.h"
struct value_addr_pair {
uint16_t value;
void *addr;
};
struct addr {
void *addr;
};
struct prog_desc {
uint16_t main_addr; // Loadable program's main function (or tosthread_main() in our case)
uint16_t alloc_count;
uint16_t alloc_size;
uint16_t g_reloc_count;
uint16_t l_reloc_count;
uint16_t datasec_count;
uint16_t code_count;
uint16_t patch_table_count; // alloc_count + g_reloc_count + l_reloc_count;
uint16_t code_offset; // sizeof(main_addr) +
// sizeof(alloc_count) +
// sizeof(alloc_size) +
// sizeof(g_reloc_count) +
// sizeof(l_reloc_count) +
// sizeof(datasec_count) +
// sizeof(code_count) +
// (g_sym_count + patch_table_count) * 4
uint16_t loading_stage;
};
#endif
--- NEW FILE: tosthread_slcs_types.h ---
/*
* Copyright (c) 2008 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* 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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#ifndef _TOSTHREAD_SLCS_TYPES_H
#define _TOSTHREAD_SLCS_TYPES_H
#include "tosthread.h"
#include "tosthread_leds.h"
#include "tosthread_amradio.h"
#include "tosthread_blockstorage.h"
#include "tosthread_logstorage.h"
#include "tosthread_threadsync.h"
#include "tosthread_amserial.h"
#include "tosthread_queue.h"
#include "tosthread_sensirionSht11.h"
#include "tosthread_hamamatsuS10871.h"
#include "tosthread_hamamatsuS1087.h"
/*******************************/
#include "slcs_types.h"
struct addr fun[] = {
{tosthread_sleep}, {tosthread_create},
{led0On}, {led1On}, {led2On},
{led0Off}, {led1Off}, {led2Off},
{led0Toggle}, {led1Toggle}, {led2Toggle},
{amSerialStart}, {amSerialStop}, {amSerialReceive},
{amSerialSend}, {amSerialLocalAddress}, {amSerialGetLocalGroup},
{amSerialGetDestination}, {amSerialGetSource}, {amSerialSetDestination},
{amSerialSetSource}, {amSerialIsForMe}, {amSerialGetType},
{amSerialSetType}, {amSerialGetGroup}, {amSerialSetGroup},
{serialClear}, {serialGetPayloadLength}, {serialSetPayloadLength},
{serialMaxPayloadLength}, {serialGetPayload}, {serialRequestAck},
{serialNoAck}, {serialWasAcked},
{amRadioStart}, {amRadioStop}, {amRadioReceive},
{amRadioSend}, {amRadioGetLocalAddress}, {amRadioGetLocalGroup},
{amRadioGetDestination}, {amRadioGetSource}, {amRadioSetDestination},
{amRadioSetSource}, {amRadioIsForMe}, {amRadioGetType},
{amRadioSetType}, {amRadioGetGroup}, {amRadioSetGroup},
{radioClear}, {radioGetPayloadLength}, {radioSetPayloadLength},
{radioMaxPayloadLength}, {radioGetPayload}, {radioRequestAck},
{radioNoAck}, {radioWasAcked},
{semaphore_reset}, {semaphore_acquire}, {semaphore_release},
{barrier_reset}, {barrier_block}, {barrier_isBlocking},
{condvar_init}, {condvar_wait}, {condvar_signalNext},
{condvar_signalAll}, {condvar_isBlocking},
{mutex_init}, {mutex_lock}, {mutex_unlock},
{volumeBlockRead}, {volumeBlockWrite}, {volumeBlockCrc},
{volumeBlockErase}, {volumeBlockSync},
{refcounter_init}, {refcounter_increment}, {refcounter_decrement},
{refcounter_waitOnValue}, {refcounter_count},
{amRadioSnoop},
{queue_init}, {queue_clear}, {queue_enqueue},
{queue_dequeue}, {queue_remove}, {queue_size},
{queue_is_empty},
{sensirionSht11_humidity_read}, {sensirionSht11_humidity_getNumBits}, {sensirionSht11_temperature_read},
{sensirionSht11_temperature_getNumBits},
{hamamatsuS10871_tsr_read}, {hamamatsuS10871_tsr_readStream}, {hamamatsuS10871_tsr_getNumBits},
{hamamatsuS1087_par_read}, {hamamatsuS1087_par_readStream}, {hamamatsuS1087_par_getNumBits},
{volumeLogRead}, {volumeLogCurrentReadOffset}, {volumeLogSeek},
{volumeLogGetSize},
{volumeLogAppend}, {volumeLogCurrentWriteOffset}, {volumeLogErase},
{volumeLogSync},
{getLeds}, {setLeds},
{div}
};
#endif
More information about the Tinyos-2-commits
mailing list