]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Add TOSThreads C API for random number generator
authorliang_mike <liang_mike>
Thu, 10 Sep 2009 20:00:12 +0000 (20:00 +0000)
committerliang_mike <liang_mike>
Thu, 10 Sep 2009 20:00:12 +0000 (20:00 +0000)
The code is from Jo Agila Bitsch Link <jo.bitsch@cs.rwth-aachen.de>

tos/lib/tosthreads/csystem/CRandomC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CRandomP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_random.h [new file with mode: 0644]

diff --git a/tos/lib/tosthreads/csystem/CRandomC.nc b/tos/lib/tosthreads/csystem/CRandomC.nc
new file mode 100644 (file)
index 0000000..15b2bcb
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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\97 çgila Bitsch Link <jo.bitsch@cs.rwth-aachen.de>
+ */
+configuration CRandomC {}
+
+implementation {
+  components CRandomP,
+             RandomC;
+
+  CRandomP.Random -> RandomC;
+  CRandomP.SeedInit -> RandomC;
+}
diff --git a/tos/lib/tosthreads/csystem/CRandomP.nc b/tos/lib/tosthreads/csystem/CRandomP.nc
new file mode 100644 (file)
index 0000000..348836c
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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\97 çgila Bitsch Link <jo.bitsch@cs.rwth-aachen.de>
+ */
+
+module CRandomP {
+  uses {
+    interface ParameterInit<uint16_t> as SeedInit;
+    interface Random;
+  }
+}
+
+implementation {
+  error_t randSeed(uint16_t seed) @C() AT_SPONTANEOUS {
+    return call SeedInit.init(seed);
+  }
+  
+  uint16_t rand16() @C() AT_SPONTANEOUS {
+    return call Random.rand16();
+  }
+  
+  uint32_t rand32() @C() AT_SPONTANEOUS {
+    return call Random.rand32();
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/tosthread_random.h b/tos/lib/tosthreads/csystem/tosthread_random.h
new file mode 100644 (file)
index 0000000..fb8e54d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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\97 çgila Bitsch Link <jo.bitsch@cs.rwth-aachen.de>
+ */
+
+#ifndef TOSTHREAD_RANDOM_H
+#define TOSTHREAD_RANDOM_H
+
+#include "TinyError.h"
+
+extern error_t randSeed(uint16_t seed);
+extern uint16_t rand16();
+extern uint32_t rand32();
+
+#endif //TOSTHREAD_RANDOM_H