summaryrefslogtreecommitdiff
path: root/n
diff options
context:
space:
mode:
authorschodet2005-07-21 20:26:15 +0000
committerschodet2005-07-21 20:26:15 +0000
commitc2fdf1755f9302c9fcb13094983d6df05b1e06f7 (patch)
treeb3f895bff60e066bd0331bbf291183021cc33bcc /n
parent3947ce7c8a79883c964aa19d6c29988b565dd722 (diff)
Ajout du test pour les m├ęthodes de byte.h.
Diffstat (limited to 'n')
-rw-r--r--n/avr/modules/utils/test/Makefile2
-rw-r--r--n/avr/modules/utils/test/test_byte_methods.c67
-rw-r--r--n/avr/modules/utils/utils.host.c2
3 files changed, 70 insertions, 1 deletions
diff --git a/n/avr/modules/utils/test/Makefile b/n/avr/modules/utils/test/Makefile
index c7d685e..535ac0e 100644
--- a/n/avr/modules/utils/test/Makefile
+++ b/n/avr/modules/utils/test/Makefile
@@ -1,7 +1,9 @@
BASE = ../../..
PROGS = test_utils test_byte
+AVR_PROGS = test_byte_methods
test_utils_SOURCES = test_utils.c
test_byte_SOURCES = test_byte.c
+test_byte_methods_SOURCES = test_byte_methods.c
DOC =
EXTRACTDOC =
MODULES = utils
diff --git a/n/avr/modules/utils/test/test_byte_methods.c b/n/avr/modules/utils/test/test_byte_methods.c
new file mode 100644
index 0000000..adf6d05
--- /dev/null
+++ b/n/avr/modules/utils/test/test_byte_methods.c
@@ -0,0 +1,67 @@
+/* test_byte.c */
+/* n.avr.utils - AVR utilities module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+#include "io.h"
+
+/* +AutoDec */
+/* -AutoDec */
+
+#define nop() asm volatile ("nop" ::)
+
+/* Union for byte access. */
+union _utils_byte_access
+{
+ uint8_t v8[4];
+ uint16_t v16[2];
+ uint32_t v32;
+};
+
+int
+main (void)
+{
+ union _utils_byte_access ba;
+ volatile uint32_t d = 0;
+ volatile uint8_t b0 = 1, b1 = 2, b2 = 3, b3 = 4;
+ nop (); // join union method.
+ ba.v8[0] = b0; ba.v8[1] = b1; ba.v8[2] = b2; ba.v8[3] = b3;
+ d = ba.v32;
+ nop (); // join asm method.
+ asm ("mov %A0, %1" "\r\n"
+ "mov %B0, %2" "\r\n"
+ "mov %C0, %3" "\r\n"
+ "mov %D0, %4" "\r\n"
+ : "=d" (d) : "r" (b0), "r" (b1), "r" (b2), "r" (b3));
+ nop (); // split union method.
+ ba.v32 = d;
+ b2 = ba.v8[2];
+ nop (); // split asm method.
+ asm ("mov %0, %A1" : "=r" (b2) : "d" (d));
+ nop (); // b2 = d >> 16;
+ b2 = d >> 16;
+ nop (); // b2 = ((uint8_t *) &d)[2];
+ b2 = ((uint8_t *) &d)[2];
+ nop ();
+ return 0;
+}
diff --git a/n/avr/modules/utils/utils.host.c b/n/avr/modules/utils/utils.host.c
index 1173eee..fcc93bf 100644
--- a/n/avr/modules/utils/utils.host.c
+++ b/n/avr/modules/utils/utils.host.c
@@ -38,7 +38,7 @@ utils_delay (double s)
struct timespec ts;
assert (s > 0.0);
ts.tv_sec = (long int) s;
- ts.tv_nsec = (s - (long int) s) * 1000000000l;
+ ts.tv_nsec = (long int) (s - (long int) s) * 1000000000l;
while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
;
}