From ae7bcc513681273114df0f78120445e80165fc66 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sat, 9 Apr 2011 17:14:14 +0200 Subject: [PATCH] initial version --- .gitignore | 1 + Makefile | 62 +++++++++++++++++++++ main.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5cb18a9 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +TARGET = rc5switch +TARGET_MCU = attiny24 + +# --------------------------------------------------------- + +BUILD = build + +CC = avr-gcc +NM = avr-nm +SIZE = avr-size +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump + +override CFLAGS = -g -Wall -Os -mmcu=$(TARGET_MCU) -Wa,-gstabs,-adhlns=$(BUILD)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD)/$(*D)/$(*F).d -pipe +override LDFLAGS = -Wl,-Map=$(BUILD)/$(TARGET).map,--cref + +# --------------------------------------------------------- + +SRC := $(wildcard *.c) + +all: $(addprefix $(BUILD)/$(TARGET), .elf .lss .sym .bin .hex _eeprom.bin _eeprom.hex) +# @$(SIZE) -x -C --mcu=$(TARGET_MCU) $< + +%.lss: %.elf + @$(OBJDUMP) -h -S -C $< > $@ + +%.sym: %.elf + @$(NM) -n $< > $@ + +%.bin: %.elf + @$(OBJCOPY) -j .text -j .data -O binary $< $@ + +%.hex: %.elf + @$(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%_eeprom.bin: %.elf + @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ 2> /dev/null + +%_eeprom.hex: %.elf + @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ 2> /dev/null + +$(BUILD)/$(TARGET).elf: $(patsubst %,$(BUILD)/%,$(SRC:.c=.o)) + @echo " Linking file: $@" + @$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) > /dev/null + @$(SIZE) -x -B $^ $@ + +$(BUILD)/%.o: %.c $(MAKEFILE_LIST) + @echo " Building file: $<" + @$(shell mkdir -p $(BUILD)/$(*D)) + @$(CC) -c $(CFLAGS) $< -o $@ + +clean: + rm -rf $(BUILD) + +install: $(BUILD)/$(TARGET).hex $(BUILD)/$(TARGET)_eeprom.hex + avrdude -c dragon_isp -P usb -p t24 -U flash:w:$(BUILD)/$(TARGET).hex -U eeprom:w:$(BUILD)/$(TARGET)_eeprom.hex + +# no self programming, 2.7V BOD, 8MHz internal RC Osz. +fuses: + avrdude -c dragon_isp -P usb -p t24 -U lfuse:w:0xc2:m -U hfuse:w:0xdd:m -U efuse:w:0xff:m + +-include $(shell find $(BUILD) -name *.d 2> /dev/null) diff --git a/main.c b/main.c new file mode 100644 index 0000000..ab79d90 --- /dev/null +++ b/main.c @@ -0,0 +1,159 @@ +/*************************************************************************** + * Copyright (C) 04/2011 by Olaf Rempel * + * razzor@kopf-tisch.de * + * * + * 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; version 2 of the License, * + * * + * 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 +#include +#include +#include + +/* + * attiny24: (no self programming, 2.7V BOD, 8MHz internal RC Osz) + * LFUSE = 0xC2 + * HFUSE = 0xDD + * EFUSE = 0xFF + * + * RC5 Input on PB2 (INT0) + * PROGMODE Jumper (active low) on PB1 + * OUTPUT (active low) on PB0 + */ + +/* RC5 bitlength is 1778us +/-10% convert to time0 ticks (8us) */ +#define BITWIDTH (1778 / 8) +#define BITWIDTH_MIN (BITWIDTH - (BITWIDTH / 10)) +#define BITWIDTH_MAX (BITWIDTH + (BITWIDTH / 10)) + +#define RC5_BITCNT 14 +#define RC5_CMD_MASK 0x37FF +#define RC5_COMPLETE 0x8000 + +#define PROGMODE_CHECK() (!(PINB & (1<= RC5_BITCNT) + value |= RC5_COMPLETE; + + bitcnt = 0; +} + +int main(int argc, char *argv[]) +{ + /* pullup on RC5IN and PROGMEM, OUTPUT is low active */ + PORTB = (1<