From e86acbc704af719259c17580651d6b806c10dfc0 Mon Sep 17 00:00:00 2001 From: liang_mike Date: Thu, 10 Sep 2009 19:18:09 +0000 Subject: [PATCH] Add TOSThreads C API for config storage abstraction Parts of the code was contributed by Jo Agila Bitsch Link --- tools/tinyos/misc/tos-storage-at45db.in | 12 +-- tools/tinyos/misc/tos-storage-pxa27xp30.in | 12 +-- tools/tinyos/misc/tos-storage-stm25p.in | 12 +-- tos/lib/tosthreads/csystem/CConfigStorageC.nc | 39 ++++++++++ tos/lib/tosthreads/csystem/CConfigStorageP.nc | 59 +++++++++++++++ tos/lib/tosthreads/csystem/TosThreadApiC.nc | 4 + tos/lib/tosthreads/csystem/VolumeMapC.nc | 6 ++ tos/lib/tosthreads/csystem/VolumeMapP.nc | 74 +++++++++++++++++++ .../csystem/tosthread_configstorage.h | 39 ++++++++++ 9 files changed, 239 insertions(+), 18 deletions(-) create mode 100644 tos/lib/tosthreads/csystem/CConfigStorageC.nc create mode 100644 tos/lib/tosthreads/csystem/CConfigStorageP.nc create mode 100644 tos/lib/tosthreads/csystem/tosthread_configstorage.h diff --git a/tools/tinyos/misc/tos-storage-at45db.in b/tools/tinyos/misc/tos-storage-at45db.in index 73bb63a9..aa79f797 100644 --- a/tools/tinyos/misc/tos-storage-at45db.in +++ b/tools/tinyos/misc/tos-storage-at45db.in @@ -229,8 +229,8 @@ if cthreads == True: outFile.write(" interface BlockWrite[uint8_t volume_id]; \n") outFile.write(" interface LogRead[uint8_t volumeId]; \n") outFile.write(" interface LogWrite[uint8_t volumeId]; \n") -# outFile.write(" interface Mount[uint8_t volumeId]; \n") -# outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") + outFile.write(" interface Mount as ConfigMount[uint8_t volumeId]; \n") + outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") outFile.write(" } \n") outFile.write("} \n") outFile.write("\n") @@ -257,9 +257,9 @@ if cthreads == True: outFile.write(" VolumeMapP.SubLogWrite[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") outFile.write("\n") -# elif volumeTypes[volumeNames[i]] == "config": -# outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") -# outFile.write(" Mount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") -# outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + elif volumeTypes[volumeNames[i]] == "config": + outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigMount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") outFile.write("} \n") diff --git a/tools/tinyos/misc/tos-storage-pxa27xp30.in b/tools/tinyos/misc/tos-storage-pxa27xp30.in index a82efd54..d5e205a6 100755 --- a/tools/tinyos/misc/tos-storage-pxa27xp30.in +++ b/tools/tinyos/misc/tos-storage-pxa27xp30.in @@ -200,8 +200,8 @@ if cthreads == True: outFile.write(" interface BlockWrite[uint8_t volume_id]; \n") outFile.write(" interface LogRead[uint8_t volumeId]; \n") outFile.write(" interface LogWrite[uint8_t volumeId]; \n") -# outFile.write(" interface Mount[uint8_t volumeId]; \n") -# outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") + outFile.write(" interface Mount as ConfigMount[uint8_t volumeId]; \n") + outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") outFile.write(" } \n") outFile.write("} \n") outFile.write("\n") @@ -228,8 +228,8 @@ if cthreads == True: outFile.write(" VolumeMapP.SubLogWrite[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") outFile.write("\n") -# elif volumeTypes[volumeNames[i]] == "config": -# outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") -# outFile.write(" Mount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") -# outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + elif volumeTypes[volumeNames[i]] == "config": + outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigMount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") outFile.write("} \n") diff --git a/tools/tinyos/misc/tos-storage-stm25p.in b/tools/tinyos/misc/tos-storage-stm25p.in index f1b02b78..1256b877 100644 --- a/tools/tinyos/misc/tos-storage-stm25p.in +++ b/tools/tinyos/misc/tos-storage-stm25p.in @@ -247,8 +247,8 @@ if cthreads == True: outFile.write(" interface BlockWrite[uint8_t volume_id]; \n") outFile.write(" interface LogRead[uint8_t volumeId]; \n") outFile.write(" interface LogWrite[uint8_t volumeId]; \n") -# outFile.write(" interface Mount[uint8_t volumeId]; \n") -# outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") + outFile.write(" interface Mount as ConfigMount[uint8_t volumeId]; \n") + outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") outFile.write(" } \n") outFile.write("} \n") outFile.write("\n") @@ -275,8 +275,8 @@ if cthreads == True: outFile.write(" VolumeMapP.SubLogWrite[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") outFile.write("\n") -# elif volumeTypes[volumeNames[i]] == "config": -# outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") -# outFile.write(" Mount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") -# outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + elif volumeTypes[volumeNames[i]] == "config": + outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigMount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") outFile.write("} \n") diff --git a/tos/lib/tosthreads/csystem/CConfigStorageC.nc b/tos/lib/tosthreads/csystem/CConfigStorageC.nc new file mode 100644 index 00000000..995065b2 --- /dev/null +++ b/tos/lib/tosthreads/csystem/CConfigStorageC.nc @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2009 RWTH Aachen 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 J— çgila Bitsch Link + */ + +configuration CConfigStorageC {} + +implementation { + components CConfigStorageP, + BlockingConfigStorageP, + VolumeMapC; + + CConfigStorageP.BlockingConfig -> BlockingConfigStorageP; + CConfigStorageP.BlockingMount -> BlockingConfigStorageP; + + BlockingConfigStorageP.ConfigMount -> VolumeMapC.ConfigMount; + BlockingConfigStorageP.ConfigStorage -> VolumeMapC.ConfigStorage; +} diff --git a/tos/lib/tosthreads/csystem/CConfigStorageP.nc b/tos/lib/tosthreads/csystem/CConfigStorageP.nc new file mode 100644 index 00000000..bb67f9c3 --- /dev/null +++ b/tos/lib/tosthreads/csystem/CConfigStorageP.nc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 RWTH Aachen 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 J— çgila Bitsch Link + * @author Chieh-Jan Mike Liang + */ + +module CConfigStorageP { + uses { + interface BlockingConfig[uint8_t volume_id]; + interface BlockingMount[uint8_t volume_id]; + } +} + +implementation { + error_t volumeConfigMount(uint8_t volumeId) @C() AT_SPONTANEOUS { + return call BlockingMount.mount[volumeId](); + } + + error_t volumeConfigRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() AT_SPONTANEOUS { + return call BlockingConfig.read[volumeId](addr, buf, len); + } + + error_t volumeConfigWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() AT_SPONTANEOUS { + return call BlockingConfig.write[volumeId](addr, buf, len); + } + + error_t volumeConfigCommit(uint8_t volumeId) @C() AT_SPONTANEOUS { + return call BlockingConfig.commit[volumeId](); + } + + storage_len_t volumeConfigGetSize(uint8_t volumeId) @C() AT_SPONTANEOUS { + return call BlockingConfig.getSize[volumeId](); + } + + bool volumeConfigValid(uint8_t volumeId) @C() AT_SPONTANEOUS { + return call BlockingConfig.valid[volumeId](); + } +} diff --git a/tos/lib/tosthreads/csystem/TosThreadApiC.nc b/tos/lib/tosthreads/csystem/TosThreadApiC.nc index 17803b99..da04a860 100644 --- a/tos/lib/tosthreads/csystem/TosThreadApiC.nc +++ b/tos/lib/tosthreads/csystem/TosThreadApiC.nc @@ -31,6 +31,7 @@ /** * @author Kevin Klues + * @author Chieh-Jan Mike Liang */ #include "tosthread.h" @@ -67,6 +68,9 @@ implementation { #if defined(TOSTHREAD_LOGSTORAGE_H) || defined(TOSTHREAD_DYNAMIC_LOADER) components CLogStorageC; #endif + #if defined(TOSTHREAD_CONFIGSTORAGE_H) || defined(TOSTHREAD_DYNAMIC_LOADER) + components CConfigStorageC; + #endif #if defined(TOSTHREAD_COLLECTION_H) || defined(TOSTHREAD_DYNAMIC_LOADER) components CCollectionC; #endif diff --git a/tos/lib/tosthreads/csystem/VolumeMapC.nc b/tos/lib/tosthreads/csystem/VolumeMapC.nc index 2821a08c..ee2126fd 100644 --- a/tos/lib/tosthreads/csystem/VolumeMapC.nc +++ b/tos/lib/tosthreads/csystem/VolumeMapC.nc @@ -22,6 +22,7 @@ /** * @author Chieh-Jan Mike Liang + * @author J— çgila Bitsch Link */ configuration VolumeMapC { @@ -30,6 +31,8 @@ configuration VolumeMapC { interface BlockWrite[uint8_t volume_id]; interface LogRead[uint8_t volume_id]; interface LogWrite[uint8_t volume_id]; + interface ConfigStorage[uint8_t volume_id]; + interface Mount[uint8_t volume_id]; } } @@ -40,4 +43,7 @@ implementation { BlockWrite = VolumeMapP; LogRead = VolumeMapP; LogWrite = VolumeMapP; + + ConfigStorage = VolumeMapP; + Mount = VolumeMapP; } diff --git a/tos/lib/tosthreads/csystem/VolumeMapP.nc b/tos/lib/tosthreads/csystem/VolumeMapP.nc index 5c810dda..2896fa19 100644 --- a/tos/lib/tosthreads/csystem/VolumeMapP.nc +++ b/tos/lib/tosthreads/csystem/VolumeMapP.nc @@ -22,6 +22,7 @@ /** * @author Chieh-Jan Mike Liang + * @author J— çgila Bitsch Link */ module VolumeMapP { @@ -30,6 +31,8 @@ module VolumeMapP { interface BlockWrite[uint8_t volume_id]; interface LogRead[uint8_t volume_id]; interface LogWrite[uint8_t volume_id]; + interface ConfigStorage[uint8_t volume_id]; + interface Mount[uint8_t volume_id]; } uses { @@ -37,6 +40,8 @@ module VolumeMapP { interface BlockWrite as SubBlockWrite[uint8_t volume_id]; interface LogRead as SubLogRead[uint8_t volume_id]; interface LogWrite as SubLogWrite[uint8_t volume_id]; + interface ConfigStorage as SubConfigStorage[uint8_t volume_id]; + interface Mount as SubMount[uint8_t volume_id]; } } @@ -204,4 +209,73 @@ implementation { default event void LogWrite.appendDone[uint8_t volume_id](void* buf, storage_len_t len, bool recordsLost, error_t error) {} default event void LogWrite.eraseDone[uint8_t volume_id](error_t error) {} default event void LogWrite.syncDone[uint8_t volume_id](error_t error) {} + + command error_t ConfigStorage.read[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { + return call SubConfigStorage.read[volume_id](addr, buf, len); + } + + event void SubConfigStorage.readDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) { + signal ConfigStorage.readDone[volume_id](addr, buf, len, error); + } + + command error_t ConfigStorage.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { + return call SubConfigStorage.write[volume_id](addr, buf, len); + } + + event void SubConfigStorage.writeDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) { + signal ConfigStorage.writeDone[volume_id](addr, buf, len, error); + } + + command error_t ConfigStorage.commit[uint8_t volume_id]() { + return call SubConfigStorage.commit[volume_id](); + } + + event void SubConfigStorage.commitDone[uint8_t volume_id](error_t error) { + signal ConfigStorage.commitDone[volume_id](error); + } + + command storage_len_t ConfigStorage.getSize[uint8_t volume_id]() { + return call SubConfigStorage.getSize[volume_id](); + } + + command bool ConfigStorage.valid[uint8_t volume_id]() { + return call SubConfigStorage.valid[volume_id](); + } + + command error_t Mount.mount[uint8_t volume_id]() { + return call SubMount.mount[volume_id](); + } + + event void SubMount.mountDone[uint8_t volume_id](error_t error) { + signal Mount.mountDone[volume_id](error); + } + + default command error_t SubConfigStorage.read[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { + return FAIL; + } + + default command error_t SubConfigStorage.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { + return FAIL; + } + + default command error_t SubConfigStorage.commit[uint8_t volume_id]() { + return FAIL; + } + + default command storage_len_t SubConfigStorage.getSize[uint8_t volume_id]() { + return FAIL; + } + + default command bool SubConfigStorage.valid[uint8_t volume_id]() { + return FAIL; + } + + default command error_t SubMount.mount[uint8_t volume_id]() { + return FAIL; + } + + default event void ConfigStorage.commitDone[uint8_t volume_id](error_t error) {} + default event void ConfigStorage.writeDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {} + default event void ConfigStorage.readDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {} + default event void Mount.mountDone[uint8_t volume_id](error_t error) {} } diff --git a/tos/lib/tosthreads/csystem/tosthread_configstorage.h b/tos/lib/tosthreads/csystem/tosthread_configstorage.h new file mode 100644 index 00000000..51d5d300 --- /dev/null +++ b/tos/lib/tosthreads/csystem/tosthread_configstorage.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2009 RWTH Aachen 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 J— çgila Bitsch Link + */ + +#ifndef TOSTHREAD_CONFIGSTORAGE_H +#define TOSTHREAD_CONFIGSTORAGE_H + +#include "Storage.h" + +extern error_t volumeConfigMount(uint8_t volumeId); +extern error_t volumeConfigRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len); +extern error_t volumeConfigWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len); +extern error_t volumeConfigCommit(uint8_t volumeId); +extern storage_len_t volumeConfigGetSize(uint8_t volumeId); +extern bool volumeConfigValid(uint8_t volumeId); + +#endif // TOSTHREAD_CONFIGSTORAGE_H -- 2.39.2