From: liang_mike Date: Thu, 10 Sep 2009 19:08:50 +0000 (+0000) Subject: Add nesC API for config storage abstraction X-Git-Tag: rc_6_tinyos_2_1_1~282 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=4c7c35af4d09991a198e4d71166f53ec44a5ef74 Add nesC API for config storage abstraction --- diff --git a/tos/lib/tosthreads/interfaces/BlockingConfig.nc b/tos/lib/tosthreads/interfaces/BlockingConfig.nc new file mode 100644 index 00000000..9ffd6476 --- /dev/null +++ b/tos/lib/tosthreads/interfaces/BlockingConfig.nc @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2009 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 + */ + +#include "Storage.h" + +interface BlockingConfig +{ + command error_t read(storage_addr_t addr, void* buf, storage_len_t* len); + command error_t write(storage_addr_t addr, void* buf, storage_len_t* len); + command error_t commit(); + command storage_len_t getSize(); + command bool valid(); +} diff --git a/tos/lib/tosthreads/interfaces/BlockingMount.nc b/tos/lib/tosthreads/interfaces/BlockingMount.nc new file mode 100644 index 00000000..b459c697 --- /dev/null +++ b/tos/lib/tosthreads/interfaces/BlockingMount.nc @@ -0,0 +1,52 @@ +/* Copyright (c) 2002-2006 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ + +/** + * Mount a volume. + * + * @author David Gay + * @version $Revision$ $Date$ + */ + +/* + * Copyright (c) 2009 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 + */ + +interface BlockingMount { + /** + * Mount a particular volume. This must be done before the volume's + * first use. mountDone will be signaled if SUCCESS is + * returned. + * @return SUCCESS if mount request is accepted, FAIL if mount has + * already been attempted. + */ + command error_t mount(); +} diff --git a/tos/lib/tosthreads/system/BlockingConfigStorageC.nc b/tos/lib/tosthreads/system/BlockingConfigStorageC.nc new file mode 100644 index 00000000..96564451 --- /dev/null +++ b/tos/lib/tosthreads/system/BlockingConfigStorageC.nc @@ -0,0 +1,49 @@ +/* + * 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 + */ + +#define UQ_BLOCKING_CONFIG_STORAGE_VOLUME "Blocking.Config.Storage.Volume" + +generic configuration BlockingConfigStorageC(volume_id_t volume_id) { + provides { + interface BlockingConfig; + interface BlockingMount; + } +} + +implementation { + enum { + VOLUME_ID = unique(UQ_BLOCKING_CONFIG_STORAGE_VOLUME), + }; + + components new ConfigStorageC(volume_id), + BlockingConfigStorageP; + + BlockingConfig = BlockingConfigStorageP.BlockingConfig[VOLUME_ID]; + BlockingMount = BlockingConfigStorageP.BlockingMount[VOLUME_ID]; + + BlockingConfigStorageP.ConfigStorage[VOLUME_ID] -> ConfigStorageC; + BlockingConfigStorageP.ConfigMount[VOLUME_ID] -> ConfigStorageC; +} diff --git a/tos/lib/tosthreads/system/BlockingConfigStorageImplP.nc b/tos/lib/tosthreads/system/BlockingConfigStorageImplP.nc new file mode 100644 index 00000000..12877836 --- /dev/null +++ b/tos/lib/tosthreads/system/BlockingConfigStorageImplP.nc @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2009 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 + */ + +module BlockingConfigStorageImplP { + provides { + interface Init; + interface BlockingConfig[uint8_t volume_id]; + interface BlockingMount[uint8_t volume_id]; + } + + uses { + interface ConfigStorage[uint8_t volume_id]; + interface Mount as ConfigMount[uint8_t volume_id]; + interface SystemCall; + interface SystemCallQueue; + } +} + +implementation { + typedef struct read_write_params { + storage_addr_t addr; + void* buf; + storage_len_t* len; + error_t error; + } read_write_params_t; + + typedef struct commit_mount_params { + error_t error; + } commit_mount_params_t; + + syscall_queue_t vol_queue; + + command error_t Init.init() + { + call SystemCallQueue.init(&vol_queue); + return SUCCESS; + } + + command storage_len_t BlockingConfig.getSize[uint8_t volume_id]() { + return call ConfigStorage.getSize[volume_id](); + } + + command bool BlockingConfig.valid[uint8_t volume_id]() { + return call ConfigStorage.valid[volume_id](); + } + + /**************************** Reading ********************************/ + void readTask(syscall_t* s) + { + read_write_params_t* p = s->params; + p->error = call ConfigStorage.read[s->id](p->addr, p->buf, *(p->len)); + if(p->error != SUCCESS) { + call SystemCall.finish(s); + } + } + + command error_t BlockingConfig.read[uint8_t volume_id](storage_addr_t addr, void *buf, storage_len_t* len) + { + syscall_t s; + read_write_params_t p; + atomic { + if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL) { + return EBUSY; + } + call SystemCallQueue.enqueue(&vol_queue, &s); + } + + p.addr = addr; + p.buf = buf; + p.len = len; + call SystemCall.start(&readTask, &s, volume_id, &p); + + atomic { + call SystemCallQueue.remove(&vol_queue, &s); + return p.error; + } + } + + event void ConfigStorage.readDone[uint8_t volume_id](storage_addr_t addr, void *buf, storage_len_t len, error_t error) + { + syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id); + read_write_params_t* p = s->params; + p->error = error; + *(p->len) = len; + call SystemCall.finish(s); + } + + + /**************************** Writing ********************************/ + void writeTask(syscall_t* s) + { + read_write_params_t* p = s->params; + p->error = call ConfigStorage.write[s->id](p->addr, p->buf, *(p->len)); + if(p->error != SUCCESS) { + call SystemCall.finish(s); + } + } + + command error_t BlockingConfig.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t* len) + { + syscall_t s; + read_write_params_t p; + atomic { + if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL) { + return EBUSY; + } + call SystemCallQueue.enqueue(&vol_queue, &s); + } + + p.addr = addr; + p.buf = buf; + p.len = len; + call SystemCall.start(&writeTask, &s, volume_id, &p); + + atomic { + call SystemCallQueue.remove(&vol_queue, &s); + return p.error; + } + } + + event void ConfigStorage.writeDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) + { + syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id); + read_write_params_t* p = s->params; + *(p->len) = len; + p->error = error; + call SystemCall.finish(s); + } + + /**************************** Committing ********************************/ + void commitTask(syscall_t* s) + { + commit_mount_params_t* p = s->params; + p->error = call ConfigStorage.commit[s->id](); + if(p->error != SUCCESS) { + call SystemCall.finish(s); + } + } + + command error_t BlockingConfig.commit[uint8_t volume_id]() + { + syscall_t s; + commit_mount_params_t p; + atomic { + if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL) { + return EBUSY; + } + call SystemCallQueue.enqueue(&vol_queue, &s); + } + + call SystemCall.start(&commitTask, &s, volume_id, &p); + + atomic { + call SystemCallQueue.remove(&vol_queue, &s); + return p.error; + } + } + + event void ConfigStorage.commitDone[uint8_t volume_id](error_t error) + { + syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id); + commit_mount_params_t* p = s->params; + p->error = error; + call SystemCall.finish(s); + } + + /**************************** Mounting ********************************/ + void mountTask(syscall_t* s) + { + commit_mount_params_t* p = s->params; + p->error = call ConfigMount.mount[s->id](); + if(p->error != SUCCESS) { + call SystemCall.finish(s); + } + } + + command error_t BlockingMount.mount[uint8_t volume_id]() + { + syscall_t s; + commit_mount_params_t p; + atomic { + if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL) { + return EBUSY; + } + call SystemCallQueue.enqueue(&vol_queue, &s); + } + + call SystemCall.start(&mountTask, &s, volume_id, &p); + + atomic { + call SystemCallQueue.remove(&vol_queue, &s); + return p.error; + } + } + + event void ConfigMount.mountDone[uint8_t volume_id](error_t error) + { + syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id); + commit_mount_params_t* p = s->params; + p->error = error; + call SystemCall.finish(s); + } + + default command error_t ConfigStorage.read[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; } + default command error_t ConfigStorage.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; } + default command error_t ConfigStorage.commit[uint8_t volume_id]() { return FAIL; } + default command storage_len_t ConfigStorage.getSize[uint8_t volume_id]() { return 0; } + default command bool ConfigStorage.valid[uint8_t volume_id]() { return FALSE; } + default command error_t ConfigMount.mount[uint8_t volume_id]() { return FAIL; } +} diff --git a/tos/lib/tosthreads/system/BlockingConfigStorageP.nc b/tos/lib/tosthreads/system/BlockingConfigStorageP.nc new file mode 100644 index 00000000..8c6060d7 --- /dev/null +++ b/tos/lib/tosthreads/system/BlockingConfigStorageP.nc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009 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 + */ + +configuration BlockingConfigStorageP { + provides { + interface BlockingConfig[uint8_t id]; + interface BlockingMount[uint8_t id]; + } + + uses { + interface ConfigStorage[uint8_t id]; + interface Mount as ConfigMount[uint8_t id]; + } +} + +implementation { + components MainC, + SystemCallC, + SystemCallQueueC, + BlockingConfigStorageImplP; + + MainC.SoftwareInit -> BlockingConfigStorageImplP; + + BlockingConfig = BlockingConfigStorageImplP; + BlockingMount = BlockingConfigStorageImplP; + ConfigStorage = BlockingConfigStorageImplP; + ConfigMount = BlockingConfigStorageImplP; + + BlockingConfigStorageImplP.SystemCall -> SystemCallC; + BlockingConfigStorageImplP.SystemCallQueue -> SystemCallQueueC; +}