[PATCH 1/5] score: Add _Workspace_Allocate_aligned()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Jan 29 10:17:48 UTC 2014


---
 cpukit/score/include/rtems/score/wkspace.h |   11 +++++++++++
 cpukit/score/src/wkspace.c                 |    5 +++++
 testsuites/sptests/spwkspace/init.c        |   14 ++++++++++++++
 testsuites/sptests/spwkspace/spwkspace.doc |    2 ++
 testsuites/sptests/spwkspace/spwkspace.scn |    2 ++
 5 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/cpukit/score/include/rtems/score/wkspace.h b/cpukit/score/include/rtems/score/wkspace.h
index 7adf9df..ea8ad85 100644
--- a/cpukit/score/include/rtems/score/wkspace.h
+++ b/cpukit/score/include/rtems/score/wkspace.h
@@ -72,6 +72,17 @@ void *_Workspace_Allocate(
 );
 
 /**
+ * @brief Allocate aligned memory from workspace.
+ *
+ * @param[in] size The size of the requested memory.
+ * @param[in] alignment The alignment of the requested memory.
+ *
+ * @retval NULL Not enough resources.
+ * @retval other The memory area begin.
+ */
+void *_Workspace_Allocate_aligned( size_t size, size_t alignment );
+
+/**
  * @brief Free memory to the workspace.
  *
  *  This function frees the specified block of memory.  If the block
diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c
index b948296..6580686 100644
--- a/cpukit/score/src/wkspace.c
+++ b/cpukit/score/src/wkspace.c
@@ -114,6 +114,11 @@ void *_Workspace_Allocate(
   return memory;
 }
 
+void *_Workspace_Allocate_aligned( size_t size, size_t alignment )
+{
+  return _Heap_Allocate_aligned( &_Workspace_Area, size, alignment );
+}
+
 /*
  *  _Workspace_Free
  */
diff --git a/testsuites/sptests/spwkspace/init.c b/testsuites/sptests/spwkspace/init.c
index 1441662..f6102e2 100644
--- a/testsuites/sptests/spwkspace/init.c
+++ b/testsuites/sptests/spwkspace/init.c
@@ -54,6 +54,17 @@ static void test_workspace_string_duplicate(void)
   _Workspace_Free( dup_e );
 }
 
+static void test_workspace_allocate_aligned(void)
+{
+  uintptr_t align = 512;
+  void *p = _Workspace_Allocate_aligned( 1, align );
+
+  rtems_test_assert( p != NULL );
+  rtems_test_assert( ((uintptr_t) p & (align - 1)) == 0 );
+
+  _Workspace_Free( p );
+}
+
 rtems_task Init(
   rtems_task_argument argument
 )
@@ -100,6 +111,9 @@ rtems_task Init(
   puts( "_Workspace_String_duplicate - samples" );
   test_workspace_string_duplicate();
 
+  puts( "_Workspace_Allocate_aligned" );
+  test_workspace_allocate_aligned();
+
   puts( "*** END OF TEST WORKSPACE CLASSIC API ***" );
   rtems_test_exit( 0 );
 }
diff --git a/testsuites/sptests/spwkspace/spwkspace.doc b/testsuites/sptests/spwkspace/spwkspace.doc
index 3b03781..dcd4e7a 100644
--- a/testsuites/sptests/spwkspace/spwkspace.doc
+++ b/testsuites/sptests/spwkspace/spwkspace.doc
@@ -15,6 +15,8 @@ directives:
   rtems_workspace_get_information
   rtems_workspace_allocate
   rtems_workspace_free
+  _Workspace_String_duplicate
+  _Workspace_Allocate_aligned
 
 concepts:
 
diff --git a/testsuites/sptests/spwkspace/spwkspace.scn b/testsuites/sptests/spwkspace/spwkspace.scn
index 0fe8088..6431923 100644
--- a/testsuites/sptests/spwkspace/spwkspace.scn
+++ b/testsuites/sptests/spwkspace/spwkspace.scn
@@ -7,4 +7,6 @@ rtems_workspace_allocate - too many bytes
 rtems_workspace_allocate - 42 bytes
 rtems_workspace_free - NULL
 rtems_workspace_free - previous pointer to 42 bytes
+_Workspace_String_duplicate - samples
+_Workspace_Allocate_aligned
 *** END OF TEST WORKSPACE CLASSIC API ***
-- 
1.7.7




More information about the devel mailing list