summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/avr/utils/Makefile14
-rw-r--r--n/avr/utils/Makefile.avr59
-rw-r--r--n/avr/utils/byte.h102
-rw-r--r--n/avr/utils/test_byte.c38
-rw-r--r--n/avr/utils/utils.h2
5 files changed, 187 insertions, 28 deletions
diff --git a/n/avr/utils/Makefile b/n/avr/utils/Makefile
index eff599f..798bd2a 100644
--- a/n/avr/utils/Makefile
+++ b/n/avr/utils/Makefile
@@ -1,8 +1,10 @@
-PROGS = test_utils
-SOURCES = test_utils.c
+PROGS = test_utils test_byte
+test_utils_OBJECTS = test_utils.o
+test_bytes_OBJECTS = test_bytes.o
DOC = utils.html
-EXTRACTDOC = utils.h avrconfig.h
+EXTRACTDOC = utils.h byte.h avrconfig.h
MODULES =
+CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
MCU_TARGET = atmega128
# -O2 : speed
@@ -10,6 +12,10 @@ MCU_TARGET = atmega128
OPTIMIZE = -O2
DEFS =
-LIBS =
+LDLIBS =
include Makefile.avr
+
+test_utils.elf: $(test_utils_OBJECTS)
+
+test_bytes.elf: $(test_bytes_OBJECTS)
diff --git a/n/avr/utils/Makefile.avr b/n/avr/utils/Makefile.avr
index b3ceb39..6a4324d 100644
--- a/n/avr/utils/Makefile.avr
+++ b/n/avr/utils/Makefile.avr
@@ -1,55 +1,68 @@
+# Makefile.avr 1.6
+#
# Flags. {{{1
-CC = avr-gcc
-
CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
-CPPFLAGS = $(DEFS)
-LDFLAGS =
+CPPFLAGS = $(DEFS) -MMD $(INCLUDES) \
+ $(if $(CONFIGFILE), $(CONFIGFILE:%=-include %))
+INCLUDES = -Imodules
+LDFLAGS = $(CFLAGS)
+CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
# Main rules. {{{1
-CSOURCES = $(filter %.c, $(SOURCES))
-SSOURCES = $(filter %.s, $(SOURCES))
-OBJECTS = $(CSOURCES:%.c=%.o) $(SSOURCES:%.s=%.o)
-ELFS = $(PROGS:%=%.elf)
-
all: elf lst hex
.PHONY: all clean elf lst doc text hex srec bin eeprom ehex esrec ebin
# Rules for modules. {{{1
-MODULESFILES = $(MODULES:%=modules/%/Module)
+VPATH = $(MODULES:%=modules/%)
-Makefile: $(MODULESFILES)
+modules_checkout: modules_co
-MODULESOURCES = $(addprefix modules/$(module)/,\
- $(shell cat modules/$(module)/Module))
-MODULESSOURCES := $(if $(MODULES),\
- $(foreach module,$(MODULES),$(MODULESOURCES)))
-SOURCES += $(MODULESSOURCES)
+modules_co: $(MODULES:%=modules_co.%)
-$(MODULESFILES):
+$(MODULES:%=modules_co.%):
mkdir -p modules
- cd modules && cvs co $(@:modules/%/Module=%)
- test -f $@
+ cd modules && cvs co $(@:modules_co.%=%)
+
+modules_update: modules_up
+
+modules_up: $(MODULES:%=modules_up.%)
+
+$(MODULES:%=modules_up.%):
+ cd modules/$(@:modules_up.%=%) && cvs up
# General rules. {{{1
-elf: $(PROGS:%=%.elf)
+ELFS = $(PROGS:%=%.elf)
+OBJECTS = $(filter %.o,$(foreach prog,$(PROGS),$($(prog)_OBJECTS)))
+
+elf: $(ELFS)
lst: $(PROGS:%=%.lst)
-$(PROGS:%=%.elf): $(OBJECTS)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+# Great piece of rules which only works in make 3.80+.
+# define PROG_template
+# $(1).elf: $$($(1)_OBJECTS)
+# endef
+#
+# $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))
+
+$(ELFS):
+ $(LINK.o) $^ $(LDLIBS) -o $@
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
+# Dependency checking.
+-include $(OBJECTS:%.o=%.d)
+
clean:
- rm -f *.o $(OBJECTS) $(PROGS:%=%.elf) *.lst *.map *.bak *~
+ rm -f *.o *.d $(ELFS) *.lst *.map *.bak *~
rm -f $(DOC) *.exd $(EXTRA_CLEAN_FILES) $(TEXTS) $(EEPROMS)
# Rules for building the doc. {{{1
diff --git a/n/avr/utils/byte.h b/n/avr/utils/byte.h
new file mode 100644
index 0000000..c1b4f93
--- /dev/null
+++ b/n/avr/utils/byte.h
@@ -0,0 +1,102 @@
+#ifndef byte_h
+#define byte_h
+/* byte.h */
+/* 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 <stdint.h>
+
+/** WARNING: Theses functions only works on little endian processor, do not
+ * use them on other processors, prefer the portable bit shifts and or. This
+ * file only exist to overide bad code production with avr-gcc in the bit
+ * shifts idiom. */
+
+/* Union needed for byte access. */
+union _utils_byte_access
+{
+ uint8_t v8[4];
+ uint16_t v16[2];
+ uint32_t v32;
+};
+
+/** Byte packing macro, pack 4 bytes into a double word. */
+extern inline uint32_t
+v8_to_v32 (uint8_t b3, uint8_t b2, uint8_t b1, uint8_t b0)
+{
+ union _utils_byte_access ba;
+ ba.v8[0] = b0;
+ ba.v8[1] = b1;
+ ba.v8[2] = b2;
+ ba.v8[3] = b3;
+ return ba.v32;
+}
+
+/** Byte packing macro, pack 2 bytes into a word. */
+extern inline uint16_t
+v8_to_v16 (uint8_t b1, uint8_t b0)
+{
+ union _utils_byte_access ba;
+ ba.v8[0] = b0;
+ ba.v8[1] = b1;
+ return ba.v16[0];
+}
+
+/** Word packing macro, pack 2 words into a double word. */
+extern inline uint32_t
+v16_to_v32 (uint16_t w1, uint16_t w0)
+{
+ union _utils_byte_access ba;
+ ba.v16[0] = w0;
+ ba.v16[1] = w1;
+ return ba.v32;
+}
+
+/** Byte unpacking macro, extract one specified byte from a double word. */
+extern inline uint8_t
+v32_to_v8 (uint32_t d, int pos)
+{
+ union _utils_byte_access ba;
+ ba.v32 = d;
+ return ba.v8[pos];
+}
+
+/** Byte unpacking macro, extract one specified byte from a word. */
+extern inline uint8_t
+v16_to_v8 (uint16_t w, int pos)
+{
+ union _utils_byte_access ba;
+ ba.v16[0] = w;
+ return ba.v8[pos];
+}
+
+/** Word unpacking macro, extract one specified word from a double word. */
+extern inline uint16_t
+v32_to_v16 (uint32_t d, int pos)
+{
+ union _utils_byte_access ba;
+ ba.v32 = d;
+ return ba.v16[pos];
+}
+
+#endif /* byte_h */
diff --git a/n/avr/utils/test_byte.c b/n/avr/utils/test_byte.c
new file mode 100644
index 0000000..f4bba30
--- /dev/null
+++ b/n/avr/utils/test_byte.c
@@ -0,0 +1,38 @@
+/* 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 "byte.h"
+
+/* +AutoDec */
+/* -AutoDec */
+
+int
+main (void)
+{
+ volatile uint32_t d;
+ volatile uint8_t b0 = 1, b1 = 2, b2 = 3, b3 = 4;
+ d = v8_to_v32 (b3, b2, b1, b0);
+ b2 = v32_to_v8 (d, 2);
+ return 0;
+}
diff --git a/n/avr/utils/utils.h b/n/avr/utils/utils.h
index 3445d3c..a445edb 100644
--- a/n/avr/utils/utils.h
+++ b/n/avr/utils/utils.h
@@ -27,7 +27,7 @@
#include <avr/delay.h>
#include <avr/wdt.h>
-#include <inttypes.h>
+#include <stdint.h>
/** Helper macro to build register value. Call it like this :
*