Add ATTiny24 single-LED experiment firmware
This commit is contained in:
commit
77f8009b39
2
tn24/.gitignore
vendored
Normal file
2
tn24/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
build/*
|
||||
src/.local.vimrc
|
69
tn24/makefile
Normal file
69
tn24/makefile
Normal file
|
@ -0,0 +1,69 @@
|
|||
PROJECT = main
|
||||
LOCAL_SOURCE_DIR = src
|
||||
BUILD_DIR = build
|
||||
|
||||
MCU = attiny24
|
||||
LFUSE = 0xc4
|
||||
HFUSE = 0xdf
|
||||
EFUSE = 0xff
|
||||
|
||||
FORMAT = ihex
|
||||
|
||||
LOCAL_SOURCES = $(wildcard $(LOCAL_SOURCE_DIR)/*.c)
|
||||
|
||||
CFLAGS = -mmcu=$(MCU) -Wall -Wstrict-prototypes -gstabs -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Os -lm
|
||||
|
||||
RM = rm -f
|
||||
CC = avr-gcc
|
||||
NM = avr-nm
|
||||
AVRDUDE = avrdude
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
SIZE = avr-size
|
||||
|
||||
LOCAL_OBJECTS = $(patsubst $(LOCAL_SOURCE_DIR)/%.c, $(BUILD_DIR)/%.o, $(LOCAL_SOURCES))
|
||||
OBJECTS = $(LOCAL_OBJECTS)
|
||||
LOCAL_DEPENDS = $(patsubst $(LOCAL_SOURCE_DIR)/%.c, $(BUILD_DIR)/%.d, $(LOCAL_SOURCES))
|
||||
|
||||
.DEFAULT_GOAL = all
|
||||
.DELETE_ON_ERROR:
|
||||
|
||||
$(LOCAL_OBJECTS): $(BUILD_DIR)/%.o: $(LOCAL_SOURCE_DIR)/%.c
|
||||
$(CC) $^ -c -o $@ $(CFLAGS)
|
||||
|
||||
$(LOCAL_DEPENDS): $(BUILD_DIR)/%.d: $(LOCAL_SOURCE_DIR)/%.c
|
||||
@set -e; rm -f $@; $(CC) -MM $(CFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$
|
||||
|
||||
include $(LOCAL_DEPENDS)
|
||||
|
||||
$(BUILD_DIR)/$(PROJECT).elf: $(OBJECTS) | $(BUILD_DIR)
|
||||
$(CC) $(OBJECTS) $(CFLAGS) --output $@
|
||||
|
||||
$(BUILD_DIR)/$(PROJECT).hex: $(BUILD_DIR)/$(PROJECT).elf | $(BUILD_DIR)
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
||||
|
||||
$(BUILD_DIR)/$(PROJECT).eep: $(BUILD_DIR)/$(PROJECT).elf | $(BUILD_DIR)
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
||||
|
||||
$(BUILD_DIR)/$(PROJECT).lss: $(BUILD_DIR)/$(PROJECT).elf | $(BUILD_DIR)
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
$(BUILD_DIR)/$(PROJECT).sym: $(BUILD_DIR)/$(PROJECT).elf | $(BUILD_DIR)
|
||||
$(NM) -n $< > $@
|
||||
|
||||
$(LOCAL_DEPENDS): | $(BUILD_DIR)
|
||||
$(BUILD_DIR):
|
||||
if [ ! -d "$(BUILD_DIR)" ]; then mkdir "$(BUILD_DIR)"; fi
|
||||
|
||||
.PHONY: all
|
||||
all: $(BUILD_DIR) $(OBJECTS) $(BUILD_DIR)/$(PROJECT).elf $(BUILD_DIR)/$(PROJECT).hex $(BUILD_DIR)/$(PROJECT).eep $(BUILD_DIR)/$(PROJECT).lss $(BUILD_DIR)/$(PROJECT).sym
|
||||
$(SIZE) $(BUILD_DIR)/$(PROJECT).elf
|
||||
|
||||
.PHONY: program
|
||||
program: $(BUILD_DIR)/$(PROJECT).hex
|
||||
avrdude -c usbasp -p $(MCU) -U flash:w:$(BUILD_DIR)/$(PROJECT).hex -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
|
||||
# avrdude -c usbasp -p $(MCU) -U flash:w:$(BUILD_DIR)/$(PROJECT).hex -U eeprom:w:$(BUILD_DIR)/$(PROJECT).eep -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(RM) $(BUILD_DIR)/*
|
8
tn24/src/config.h
Normal file
8
tn24/src/config.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#define F_CPU 128000UL
|
||||
|
||||
#define MAX_DELAY 600
|
||||
|
||||
#endif
|
94
tn24/src/main.c
Normal file
94
tn24/src/main.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include "main.h"
|
||||
|
||||
uint16_t RCounter;
|
||||
uint16_t GCounter;
|
||||
uint16_t BCounter;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
DDRA = 0;
|
||||
DDRB = 0;
|
||||
PORTA = 0;
|
||||
PORTB = 0;
|
||||
|
||||
D_LEDR |= (1 << P_LEDR);
|
||||
D_LEDG |= (1 << P_LEDG);
|
||||
D_LEDB |= (1 << P_LEDB);
|
||||
O_LEDR |= (1 << P_LEDR);
|
||||
|
||||
_delay_ms(50);
|
||||
|
||||
O_LEDR &= ~(1 << P_LEDR);
|
||||
|
||||
WDTCSR = (1 << WDIE) | (1 << WDP1);
|
||||
|
||||
RCounter = 10;
|
||||
GCounter = 35;
|
||||
BCounter = 20;
|
||||
|
||||
sei();
|
||||
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
sleep_mode();
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ISR(WATCHDOG_vect)
|
||||
{
|
||||
if(O_LEDR & (1 << P_LEDR))
|
||||
{
|
||||
O_LEDR &= ~(1 << P_LEDR);
|
||||
RCounter = rand() % MAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
RCounter--;
|
||||
if(RCounter == 0)
|
||||
{
|
||||
O_LEDR |= (1 << P_LEDR);
|
||||
}
|
||||
}
|
||||
|
||||
if(O_LEDG & (1 << P_LEDG))
|
||||
{
|
||||
O_LEDG &= ~(1 << P_LEDG);
|
||||
GCounter = rand() % MAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
GCounter--;
|
||||
if(GCounter == 0)
|
||||
{
|
||||
O_LEDG |= (1 << P_LEDG);
|
||||
}
|
||||
}
|
||||
|
||||
if(O_LEDB & (1 << P_LEDB))
|
||||
{
|
||||
O_LEDB &= ~(1 << P_LEDB);
|
||||
BCounter = rand() % MAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
BCounter--;
|
||||
if(BCounter == 0)
|
||||
{
|
||||
O_LEDB |= (1 << P_LEDB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t y = 132457;
|
||||
|
||||
uint16_t rand()
|
||||
{
|
||||
y ^= y << 13;
|
||||
y ^= y >> 7;
|
||||
y ^= y << 5;
|
||||
return y;
|
||||
}
|
20
tn24/src/main.h
Normal file
20
tn24/src/main.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef MAIN_H_
|
||||
#define MAIN_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <stdint.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "pinning.h"
|
||||
|
||||
int main(void);
|
||||
|
||||
uint16_t rand();
|
||||
|
||||
#endif
|
16
tn24/src/pinning.h
Normal file
16
tn24/src/pinning.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef PINNING_H_
|
||||
#define PINNING_H_
|
||||
|
||||
#define D_LEDR DDRA
|
||||
#define O_LEDR PORTA
|
||||
#define P_LEDR PA2
|
||||
|
||||
#define D_LEDG DDRA
|
||||
#define O_LEDG PORTA
|
||||
#define P_LEDG PA3
|
||||
|
||||
#define D_LEDB DDRA
|
||||
#define O_LEDB PORTA
|
||||
#define P_LEDB PA1
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue