]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/libmetal.git/commitdiff
Add sleep functions
authorWendy Liang <jliang@xilinx.com>
Fri, 14 Oct 2016 23:40:51 +0000 (16:40 -0700)
committerWendy Liang <jliang@xilinx.com>
Fri, 14 Oct 2016 23:42:12 +0000 (16:42 -0700)
For now, only implement microseconds sleep function.

Signed-off-by: Wendy Liang <jliang@xilinx.com>
README.md
lib/CMakeLists.txt
lib/sleep.h [new file with mode: 0644]
lib/system/freertos/CMakeLists.txt
lib/system/freertos/sleep.c [new file with mode: 0644]
lib/system/generic/CMakeLists.txt
lib/system/generic/sleep.c [new file with mode: 0644]
lib/system/linux/CMakeLists.txt
lib/system/linux/sleep.c [new file with mode: 0644]

index 21159714b751832c895460d6454e2a2a98aab45b..5109f9a46e13884f98755a4cbc677b3da05c69f3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -150,6 +150,9 @@ memory for this release.
 ### Time
 libmetal time APIs provide getting timestamp implementation.
 
+### Sleep
+libmetal sleep APIs provide getting delay execution implementation.
+
 ### Compiler
 
 This API is for compiler dependent functions.  For this release, there is only
index 961a453e6f61886d1d3f6ad82e3f10a20ad58aaa..72d767b20cab1f227dffacfa0d53c34b5142a339 100644 (file)
@@ -24,6 +24,7 @@ collect (PROJECT_LIB_HEADERS alloc.h)
 collect (PROJECT_LIB_HEADERS cache.h)
 collect (PROJECT_LIB_HEADERS dma.h)
 collect (PROJECT_LIB_HEADERS time.h)
+collect (PROJECT_LIB_HEADERS sleep.h)
 
 collect (PROJECT_LIB_SOURCES device.c)
 collect (PROJECT_LIB_SOURCES init.c)
diff --git a/lib/sleep.h b/lib/sleep.h
new file mode 100644 (file)
index 0000000..396df4a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of Xilinx 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 THE COPYRIGHT HOLDER OR 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.
+ */
+
+/*
+ * @file       sleep.h
+ * @brief      Sleep primitives for libmetal.
+ */
+
+#ifndef __METAL_SLEEP__H__
+#define __METAL_SLEEP__H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \defgroup sleep Sleep Interfaces
+ *  @{ */
+
+/**
+ * @brief      delay in microseconds
+ *             delay the next execution in the calling thread
+ *             fo usec microseconds.
+ *
+ * @param[in]  usec      microsecond intervals
+ * @return     0 on success, non-zero for failures
+ */
+int metal_sleep_usec(unsigned int usec);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __METAL_SLEEP__H__ */
+
index e0dc66f663594cc16f717c5fb4aea754381127c8..c21d676510d083b40d5e32a69ce5760f15467c7a 100644 (file)
@@ -11,6 +11,7 @@ collect (PROJECT_LIB_SOURCES io.c)
 collect (PROJECT_LIB_SOURCES shmem.c)
 collect (PROJECT_LIB_SOURCES condition.c)
 collect (PROJECT_LIB_SOURCES time.c)
+collect (PROJECT_LIB_SOURCES sleep.c)
 
 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
   add_subdirectory(${PROJECT_MACHINE})
diff --git a/lib/system/freertos/sleep.c b/lib/system/freertos/sleep.c
new file mode 100644 (file)
index 0000000..4f7b902
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of Xilinx 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 THE COPYRIGHT HOLDER OR 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.
+ */
+
+/*
+ * @file       freertos/sleep.c
+ * @brief      freertos libmetal sleep handling.
+ */
+
+#include <FreeRTOS.h>
+#include <task.h>
+#include "metal/sleep.h"
+
+int metal_sleep_usec(unsigned int usec)
+{
+       const TickType_t xDelay = usec / portTICK_PERIOD_MS;
+       vTaskDelay(xDelay);
+       return 0;
+}
+
index 6e3614317e68061e749f9ab58ec39f8315d6dbcd..5e33671bf2b59f7f2a21f45128dbf97efef0390c 100644 (file)
@@ -11,6 +11,7 @@ collect (PROJECT_LIB_SOURCES cache.c)
 collect (PROJECT_LIB_SOURCES io.c)
 collect (PROJECT_LIB_SOURCES irq.c)
 collect (PROJECT_LIB_SOURCES time.c)
+collect (PROJECT_LIB_SOURCES sleep.c)
 
 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
   add_subdirectory(${PROJECT_MACHINE})
diff --git a/lib/system/generic/sleep.c b/lib/system/generic/sleep.c
new file mode 100644 (file)
index 0000000..5a03eea
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of Xilinx 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 THE COPYRIGHT HOLDER OR 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.
+ */
+
+/*
+ * @file       generic/sleep.c
+ * @brief      Generic libmetal sleep handling.
+ */
+
+#include "metal/sleep.h"
+
+int metal_sleep_usec(unsigned int usec)
+{
+       /* TODO: Implement usleep fo generic system */
+       (void)usec;
+       return 0;
+}
+
index 6da113454e5496992d84f23ac3a12d2274678d7a..86aa72ddb21b579e5e94138103b08d5c9648fcf6 100644 (file)
@@ -13,5 +13,6 @@ collect (PROJECT_LIB_SOURCES irq.c)
 collect (PROJECT_LIB_SOURCES cache.c)
 collect (PROJECT_LIB_SOURCES io.c)
 collect (PROJECT_LIB_SOURCES time.c)
+collect (PROJECT_LIB_SOURCES sleep.c)
 
 # vim: expandtab:ts=2:sw=2:smartindent
diff --git a/lib/system/linux/sleep.c b/lib/system/linux/sleep.c
new file mode 100644 (file)
index 0000000..ab9e538
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of Xilinx 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 THE COPYRIGHT HOLDER OR 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.
+ */
+
+/*
+ * @file       Linux/sleep.c
+ * @brief      Linux libmetal sleep handling.
+ */
+
+#include <unistd.h>
+#include "metal/sleep.h"
+
+int metal_sleep_usec(unsigned int usec)
+{
+       return usleep(usec);
+}