Permalink
Browse files

Added generic xc "pointer" library

  • Loading branch information...
1 parent d6d86b1 commit f3a046814db8b7c0212f4ecf7ac872c940ce1d1e @davelxmos davelxmos committed Jun 13, 2012
Showing with 48 additions and 0 deletions.
  1. +11 −0 module_xc_ptr/module_build_info
  2. +34 −0 module_xc_ptr/src/xc_ptr.h
  3. +3 −0 module_xc_ptr/src/xc_ptr.xc
@@ -0,0 +1,11 @@
+# You can set flags specifically for your module by using the MODULE_XCC_FLAGS
+# variable. So the following
+#
+# MODULE_XCC_FLAGS = $(XCC_FLAGS) -O3
+#
+# specifies that everything in the modules should have the application
+# build flags with -O3 appended (so the files will build at
+# optimization level -O3).
+#
+# You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc..
+
View
@@ -0,0 +1,34 @@
+#ifndef __xc_ptr__
+#define __xc_ptr__
+
+typedef unsigned int xc_ptr;
+
+// Note that this function is marked as const to avoid the XC
+// parallel usage checks, this is only really going to work if this
+// is the *only* way the array a is accessed (and everything else uses
+// the xc_ptr)
+inline xc_ptr array_to_xc_ptr(const char a[])
+{
+ xc_ptr x;
+ asm("mov %0, %1":"=r"(x):"r"(a));
+ return x;
+}
+
+#define write_via_xc_ptr(p,x) asm("stw %0, %1[0]"::"r"(x),"r"(p))
+
+#define write_via_xc_ptr_indexed(p,i,x) asm("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
+#define write_byte_via_xc_ptr_indexed(p,i,x) asm("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
+// No immediate st8 format
+#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
+
+#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
+
+#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
+#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
+// No immediate ld8u format
+#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
+
+#define GET_SHARED_GLOBAL(x, g) asm("ldw %0, dp[" #g "]":"=r"(x))
+#define SET_SHARED_GLOBAL(g, v) asm("stw %0, dp[" #g "]"::"r"(v))
+
+#endif
@@ -0,0 +1,3 @@
+#include "xc_ptr.h"
+
+extern inline xc_ptr array_to_xc_ptr(const char a[]);

0 comments on commit f3a0468

Please sign in to comment.