summaryrefslogtreecommitdiff
path: root/n/chenil
diff options
context:
space:
mode:
authorschodet2004-07-08 22:30:51 +0000
committerschodet2004-07-08 22:30:51 +0000
commitf80ac61093ddebc1e00083f89940d5ab5ba038b8 (patch)
tree5b579d26d0bf02c9bcda06e2c54be55d396db72e /n/chenil
parentd84fdd69c0742834f24740f5dffaf69af87ebd8e (diff)
Initial revision
Diffstat (limited to 'n/chenil')
-rw-r--r--n/chenil/Makefile15
-rw-r--r--n/chenil/Makefile.avr103
-rw-r--r--n/chenil/avrconfig.h32
-rw-r--r--n/chenil/chenil.c187
4 files changed, 337 insertions, 0 deletions
diff --git a/n/chenil/Makefile b/n/chenil/Makefile
new file mode 100644
index 0000000..707ae0a
--- /dev/null
+++ b/n/chenil/Makefile
@@ -0,0 +1,15 @@
+PROGS = chenil
+SOURCES = chenil.c
+DOC =
+EXTRACTDOC =
+MODULES = n/avr/utils
+# atmega8, atmega8535, atmega128...
+MCU_TARGET = atmega8
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -O2
+
+DEFS =
+LIBS =
+
+include Makefile.avr
diff --git a/n/chenil/Makefile.avr b/n/chenil/Makefile.avr
new file mode 100644
index 0000000..d1411f4
--- /dev/null
+++ b/n/chenil/Makefile.avr
@@ -0,0 +1,103 @@
+# Flags. {{{1
+
+CC = avr-gcc
+
+CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
+CPPFLAGS = $(DEFS) -Imodules
+LDFLAGS =
+
+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)
+
+Makefile: $(MODULESFILES)
+
+MODULESOURCES = $(addprefix modules/$(module)/,\
+ $(shell cat modules/$(module)/Module))
+MODULESSOURCES := $(if $(MODULES),\
+ $(foreach module,$(MODULES),$(MODULESOURCES)))
+SOURCES += $(MODULESSOURCES)
+
+$(MODULESFILES):
+ mkdir -p modules
+ cd modules && cvs co $(@:modules/%/Module=%)
+ test -f $@
+
+# General rules. {{{1
+
+elf: $(PROGS:%=%.elf)
+lst: $(PROGS:%=%.lst)
+
+$(PROGS:%=%.elf): $(OBJECTS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+%.lst: %.elf
+ $(OBJDUMP) -h -S $< > $@
+
+clean:
+ rm -f *.o $(OBJECTS) $(PROGS:%=%.elf) *.lst *.map *.bak *~
+ rm -f $(DOC) *.exd $(EXTRA_CLEAN_FILES) $(TEXTS) $(EEPROMS)
+
+# Rules for building the doc. {{{1
+
+doc: $(DOC)
+
+%.html: %.txt %.exd
+ aft $<
+
+%.exd: $(EXTRACTDOC)
+ test -n "$^" && extractdoc $^ > $@ || true
+
+# Rules for building the .text rom images. {{{1
+
+TEXTS = $(PROGS:%=%.hex) $(PROGS:%=%.bin) $(PROGS:%=%.srec)
+
+text: hex bin srec
+
+hex: $(PROGS:%=%.hex)
+bin: $(PROGS:%=%.bin)
+srec: $(PROGS:%=%.srec)
+
+%.hex: %.elf
+ $(OBJCOPY) -j .text -j .data -O ihex $< $@
+
+%.srec: %.elf
+ $(OBJCOPY) -j .text -j .data -O srec $< $@
+
+%.bin: %.elf
+ $(OBJCOPY) -j .text -j .data -O binary $< $@
+
+# Rules for building the .eeprom rom images. {{{1
+
+EEPROMS = $(PROGS:%=%_eeprom.hex) $(PROGS:%=%_eeprom.bin) \
+ $(PROGS:%=%_eeprom.srec)
+
+eeprom: ehex ebin esrec
+
+ehex: $(PROGS:%=%_eeprom.hex)
+ebin: $(PROGS:%=%_eeprom.bin)
+esrec: $(PROGS:%=%_eeprom.srec)
+
+%_eeprom.hex: %.elf
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
+
+%_eeprom.srec: %.elf
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
+
+%_eeprom.bin: %.elf
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
+
diff --git a/n/chenil/avrconfig.h b/n/chenil/avrconfig.h
new file mode 100644
index 0000000..4ae9b05
--- /dev/null
+++ b/n/chenil/avrconfig.h
@@ -0,0 +1,32 @@
+#ifndef avrconfig_h
+#define avrconfig_h
+/* avrconfig.h - config file for avr projects. */
+/* Chenillard. {{{
+ *
+ * Copyright (C) 2004 Nicolas Schodet
+ *
+ * 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.
+ *
+ * Contact :
+ * Web: http://perso.efrei.fr/~schodet/
+ * Email: <contact@ni.fr.eu.org>
+ * }}} */
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+#endif /* avrconfig_h */
diff --git a/n/chenil/chenil.c b/n/chenil/chenil.c
new file mode 100644
index 0000000..3c497a4
--- /dev/null
+++ b/n/chenil/chenil.c
@@ -0,0 +1,187 @@
+/* chenil.c */
+/* Chenillard. {{{
+ *
+ * Copyright (C) 2004 Nicolas Schodet
+ *
+ * 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.
+ *
+ * Contact :
+ * Web: http://perso.efrei.fr/~schodet/
+ * Email: <contact@ni.fr.eu.org>
+ * }}} */
+#include "n/avr/utils/utils.h"
+#include <avr/io.h>
+#include <inttypes.h>
+
+/*
+ * Brochage :
+ *
+ * leds sur D1 D2 D3 D4 C0 C1 C2 C3.
+ */
+
+/* +AutoDec */
+/* -AutoDec */
+
+/* Allume les leds indiquées dans LED. */
+static inline void
+allume (uint8_t leds)
+{
+ PORTD = (leds << 1) & 0x1e;
+ PORTC = (leds >> 4) & 0x0f;
+}
+
+/* Allume les N leds indiquées dans le tableau LEDT pendant T * 10ms. */
+static void
+go_chenil (uint8_t t, uint8_t n, uint8_t ledt[])
+{
+ uint8_t i;
+ int8_t l;
+ uint8_t leds;
+ while (t--)
+ {
+ /* 255 itération afin de varier le rapport cyclique. */
+ for (i = 255; i; i--)
+ {
+ leds = 0;
+ /* Construit le mot pour allume(). */
+ for (l = n - 1; l >= 0; l--)
+ {
+ leds <<= 1;
+ if (ledt[l] >= i)
+ leds |= 1;
+ }
+ allume (leds);
+ delay_ns (10000000 / 255);
+ }
+ }
+}
+
+/* Codes de programmation du chenillard, voir plus bas le switch. */
+static const uint8_t modes[] = {
+ 101, 10,
+ 1, 7,
+ 2, 7,
+ 1, 7,
+ 2, 7,
+ 1, 7,
+ 2, 7,
+ 3, 16,
+ 101, 5,
+ 1, 7,
+ 2, 7,
+ 1, 7,
+ 2, 7,
+ 1, 7,
+ 2, 7,
+ 3, 16,
+ 4, 8,
+ 103, 0,
+ 1, 15,
+ 2, 7,
+ 0, 1
+};
+
+int
+main (void)
+{
+ uint8_t step = 0;
+ uint8_t mode = 0, repeat = 0, index = 0, speed = 7, decay = 64, on = 255;
+ uint8_t ons = 0;
+ uint8_t n1 = 8 - 1, leds[8];
+ int8_t l;
+ DDRD = 0x1e;
+ DDRC = 0x0f;
+ for (l = n1; l >= 0; l--)
+ leds[l] = 0;
+ while (1)
+ {
+ if (!repeat)
+ {
+ /* Change de mode. */
+ mode = modes[index++];
+ repeat = modes[index++];
+ }
+ switch (mode)
+ {
+ case 0:
+ /* Fin de liste. */
+ index = 0;
+ goto noled;
+ case 1:
+ /* Vers la droite. */
+ leds[step++] = on;
+ step &= n1;
+ break;
+ case 2:
+ /* Vers la gauche. */
+ leds[step--] = on;
+ step &= n1;
+ break;
+ case 3:
+ /* Les deux. */
+ leds[step] = on;
+ leds[n1 - step] = on;
+ step++;
+ step &= n1;
+ break;
+ case 4:
+ /* Colision. */
+ if (step < 4)
+ {
+ leds[step] = on;
+ leds[n1 - step] = on;
+ }
+ step++;
+ step &= n1;
+ break;
+ case 101:
+ speed = repeat;
+ repeat = 1;
+ goto noled;
+ case 102:
+ speed = repeat;
+ repeat = 1;
+ goto noled;
+ case 103:
+ step = repeat;
+ repeat = 1;
+ goto noled;
+ case 104:
+ on = repeat;
+ repeat = 1;
+ goto noled;
+ case 105:
+ ons = repeat;
+ repeat = 1;
+ goto noled;
+ case 106:
+ decay = repeat;
+ repeat = 1;
+ goto noled;
+ }
+ go_chenil (speed, n1 + 1, leds);
+ /* Faibli les leds. */
+ for (l = n1; l >= 0; l--)
+ {
+ if (leds[l] > decay)
+ leds[l] -= decay;
+ else
+ leds[l] = 0;
+ }
+ on += ons;
+noled:
+ repeat--;
+ }
+}