summaryrefslogtreecommitdiff
path: root/src/cc1111
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-11-11 22:30:17 -0800
committerKeith Packard <keithp@keithp.com>2011-11-11 22:30:17 -0800
commitb132eefc5f63412bb4a98a4bb72b9055e40d5d42 (patch)
tree53f0d529cf30b21649b69cee3e5f8966adf86642 /src/cc1111
parent7ecde50fbebe68a2e2200a2f8d081fd37074f840 (diff)
altos: Make ao_xmem funcs require __xdata void * instead of casting
Having an explicit cast in the ao_xmem wrapper macros caused the compiler to generate garbage values for pdata addresses, making the upper byte 0x00 instead of the required 0xf0. Removing the casts from the ao_xmem macros exposed this problem, so a new PDATA_TO_XDATA macros was added, along with a CODE_TO_XDATA macro which serve to cast pointers, with suitable address modifications, so that things work again. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/cc1111')
-rw-r--r--src/cc1111/ao_arch.h18
-rw-r--r--src/cc1111/ao_string.c23
2 files changed, 27 insertions, 14 deletions
diff --git a/src/cc1111/ao_arch.h b/src/cc1111/ao_arch.h
index f0f0daae..001165fa 100644
--- a/src/cc1111/ao_arch.h
+++ b/src/cc1111/ao_arch.h
@@ -27,6 +27,12 @@
/* Convert a __data pointer into an __xdata pointer */
#define DATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xff00))
+/* Code and xdata use the same address space */
+#define CODE_TO_XDATA(a) ((__xdata void *) ((uint16_t) (a)))
+
+/* Pdata lives at the start of xdata */
+#define PDATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xf000))
+
/* Stack runs from above the allocated __data space to 0xfe, which avoids
* writing to 0xff as that triggers the stack overflow indicator
*/
@@ -228,18 +234,18 @@ ao_button_get(void) __critical;
/* ao_string.c */
void
-_ao_xmemcpy(__xdata uint8_t *dst, __xdata uint8_t *src, uint8_t count);
+_ao_xmemcpy(__xdata void *dst, __xdata void *src, uint8_t count);
-#define ao_xmemcpy(d,s,c) _ao_xmemcpy((__xdata uint8_t *) (d), (__xdata uint8_t *) (s), (c))
+#define ao_xmemcpy(d,s,c) _ao_xmemcpy(d,s,c)
void
-_ao_xmemset(__xdata uint8_t *dst, uint8_t value, uint8_t count);
+_ao_xmemset(__xdata void *dst, uint8_t value, uint8_t count);
-#define ao_xmemset(d,v,c) _ao_xmemset((__xdata uint8_t *) (d), (v), (c))
+#define ao_xmemset(d,v,c) _ao_xmemset(d,v,c)
int8_t
-_ao_xmemcmp(__xdata uint8_t *a, __xdata uint8_t *b, uint8_t count);
+_ao_xmemcmp(__xdata void *a, __xdata void *b, uint8_t count);
-#define ao_xmemcmp(d,s,c) _ao_xmemcmp((__xdata uint8_t *) (d), (__xdata uint8_t *) (s), (c))
+#define ao_xmemcmp(d,s,c) _ao_xmemcmp((d), (s), (c))
#endif /* _AO_ARCH_H_ */
diff --git a/src/cc1111/ao_string.c b/src/cc1111/ao_string.c
index daa5c14b..3a07e47e 100644
--- a/src/cc1111/ao_string.c
+++ b/src/cc1111/ao_string.c
@@ -18,26 +18,33 @@
#include "ao.h"
void
-_ao_xmemcpy(__xdata uint8_t *dst, __xdata uint8_t *src, uint8_t count)
+_ao_xmemcpy(__xdata void *dst, __xdata void *src, uint8_t count)
{
- while (count--)
- *dst++ = *src++;
+ while (count--) {
+ *(__xdata uint8_t *) dst = *(__xdata uint8_t *) src;
+ dst = (__xdata uint8_t *) dst + 1;
+ src = (__xdata uint8_t *) src + 1;
+ }
}
void
-_ao_xmemset(__xdata uint8_t *dst, uint8_t v, uint8_t count)
+_ao_xmemset(__xdata void *dst, uint8_t v, uint8_t count)
{
- while (count--)
- *dst++ = v;
+ while (count--) {
+ *(__xdata uint8_t *) dst = v;
+ dst = (__xdata uint8_t *) dst + 1;
+ }
}
int8_t
-_ao_xmemcmp(__xdata uint8_t *a, __xdata uint8_t *b, uint8_t count)
+_ao_xmemcmp(__xdata void *a, __xdata void *b, uint8_t count)
{
while (count--) {
- int8_t d = *a++ - *b++;
+ int8_t d = *(__xdata int8_t *) a - *(__xdata int8_t *) b;
if (d)
return d;
+ a = (__xdata int8_t *) a + 1;
+ b = (__xdata int8_t *) b + 1;
}
return 0;
}