Initial commit
This commit is contained in:
commit
ed91cc5216
|
@ -0,0 +1,619 @@
|
||||||
|
# Hey Emacs, this is a -*- makefile -*-
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
|
||||||
|
#
|
||||||
|
# Released to the Public Domain
|
||||||
|
#
|
||||||
|
# Additional material for this makefile was written by:
|
||||||
|
# Peter Fleury
|
||||||
|
# Tim Henigan
|
||||||
|
# Colin O'Flynn
|
||||||
|
# Reiner Patommel
|
||||||
|
# Markus Pfaff
|
||||||
|
# Sander Pool
|
||||||
|
# Frederik Rouleau
|
||||||
|
# Carlos Lamas
|
||||||
|
#
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# On command line:
|
||||||
|
#
|
||||||
|
# make all = Make software.
|
||||||
|
#
|
||||||
|
# make clean = Clean out built project files.
|
||||||
|
#
|
||||||
|
# make coff = Convert ELF to AVR COFF.
|
||||||
|
#
|
||||||
|
# make extcoff = Convert ELF to AVR Extended COFF.
|
||||||
|
#
|
||||||
|
# make program = Download the hex file to the device, using avrdude.
|
||||||
|
# Please customize the avrdude settings below first!
|
||||||
|
#
|
||||||
|
# make debug = Start either simulavr or avarice as specified for debugging,
|
||||||
|
# with avr-gdb or avr-insight as the front end for debugging.
|
||||||
|
#
|
||||||
|
# make filename.s = Just compile filename.c into the assembler code only.
|
||||||
|
#
|
||||||
|
# make filename.i = Create a preprocessed source file for use in submitting
|
||||||
|
# bug reports to the GCC project.
|
||||||
|
#
|
||||||
|
# To rebuild project do "make clean" then "make all".
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# MCU name
|
||||||
|
MCU = attiny84
|
||||||
|
|
||||||
|
|
||||||
|
# Processor frequency.
|
||||||
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||||
|
# processor frequency. You can then use this symbol in your source code to
|
||||||
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||||
|
# automatically to create a 32-bit value in your source code.
|
||||||
|
# Typical values are:
|
||||||
|
# F_CPU = 1000000
|
||||||
|
# F_CPU = 1843200
|
||||||
|
# F_CPU = 2000000
|
||||||
|
# F_CPU = 3686400
|
||||||
|
# F_CPU = 4000000
|
||||||
|
# F_CPU = 7372800
|
||||||
|
# F_CPU = 8000000
|
||||||
|
# F_CPU = 11059200
|
||||||
|
# F_CPU = 14745600
|
||||||
|
# F_CPU = 16000000
|
||||||
|
# F_CPU = 18432000
|
||||||
|
# F_CPU = 20000000
|
||||||
|
F_CPU = 8000000
|
||||||
|
|
||||||
|
|
||||||
|
# Output format. (can be srec, ihex, binary)
|
||||||
|
FORMAT = ihex
|
||||||
|
|
||||||
|
|
||||||
|
# Target file name (without extension).
|
||||||
|
TARGET = main
|
||||||
|
|
||||||
|
|
||||||
|
# Object files directory
|
||||||
|
# To put object files in current directory, use a dot (.), do NOT make
|
||||||
|
# this an empty or blank macro!
|
||||||
|
OBJDIR = .
|
||||||
|
|
||||||
|
|
||||||
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
|
SRC = $(TARGET).c libs/serialdebug.c
|
||||||
|
|
||||||
|
|
||||||
|
# List C++ source files here. (C dependencies are automatically generated.)
|
||||||
|
CPPSRC =
|
||||||
|
|
||||||
|
|
||||||
|
# List Assembler source files here.
|
||||||
|
# Make them always end in a capital .S. Files ending in a lowercase .s
|
||||||
|
# will not be considered source files but generated files (assembler
|
||||||
|
# output from the compiler), and will be deleted upon "make clean"!
|
||||||
|
# Even though the DOS/Win* filesystem matches both .s and .S the same,
|
||||||
|
# it will preserve the spelling of the filenames, and gcc itself does
|
||||||
|
# care about how the name is spelled on its command-line.
|
||||||
|
ASRC =
|
||||||
|
|
||||||
|
|
||||||
|
# Optimization level, can be [0, 1, 2, 3, s].
|
||||||
|
# 0 = turn off optimization. s = optimize for size.
|
||||||
|
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
||||||
|
OPT = s
|
||||||
|
|
||||||
|
|
||||||
|
# Debugging format.
|
||||||
|
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
|
||||||
|
# AVR Studio 4.10 requires dwarf-2.
|
||||||
|
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
|
||||||
|
DEBUG = dwarf-2
|
||||||
|
|
||||||
|
|
||||||
|
# List any extra directories to look for include files here.
|
||||||
|
# Each directory must be seperated by a space.
|
||||||
|
# Use forward slashes for directory separators.
|
||||||
|
# For a directory that has spaces, enclose it in quotes.
|
||||||
|
EXTRAINCDIRS = libs
|
||||||
|
|
||||||
|
|
||||||
|
# Compiler flag to set the C Standard level.
|
||||||
|
# c89 = "ANSI" C
|
||||||
|
# gnu89 = c89 plus GCC extensions
|
||||||
|
# c99 = ISO C99 standard (not yet fully implemented)
|
||||||
|
# gnu99 = c99 plus GCC extensions
|
||||||
|
CSTANDARD = -std=gnu99
|
||||||
|
|
||||||
|
|
||||||
|
# Place -D or -U options here for C sources
|
||||||
|
CDEFS = -DF_CPU=$(F_CPU)UL
|
||||||
|
|
||||||
|
|
||||||
|
# Place -D or -U options here for ASM sources
|
||||||
|
ADEFS = -DF_CPU=$(F_CPU)
|
||||||
|
|
||||||
|
|
||||||
|
# Place -D or -U options here for C++ sources
|
||||||
|
CPPDEFS = -DF_CPU=$(F_CPU)UL
|
||||||
|
#CPPDEFS += -D__STDC_LIMIT_MACROS
|
||||||
|
#CPPDEFS += -D__STDC_CONSTANT_MACROS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Compiler Options C ----------------
|
||||||
|
# -g*: generate debugging information
|
||||||
|
# -O*: optimization level
|
||||||
|
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||||
|
# -Wall...: warning level
|
||||||
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
|
# -adhlns...: create assembler listing
|
||||||
|
CFLAGS = -g$(DEBUG)
|
||||||
|
CFLAGS += $(CDEFS)
|
||||||
|
CFLAGS += -O$(OPT)
|
||||||
|
CFLAGS += -funsigned-char
|
||||||
|
CFLAGS += -funsigned-bitfields
|
||||||
|
CFLAGS += -fpack-struct
|
||||||
|
CFLAGS += -fshort-enums
|
||||||
|
CFLAGS += -Wall
|
||||||
|
CFLAGS += -Wstrict-prototypes
|
||||||
|
#CFLAGS += -mshort-calls
|
||||||
|
#CFLAGS += -fno-unit-at-a-time
|
||||||
|
#CFLAGS += -Wundef
|
||||||
|
#CFLAGS += -Wunreachable-code
|
||||||
|
#CFLAGS += -Wsign-compare
|
||||||
|
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||||
|
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||||
|
CFLAGS += $(CSTANDARD)
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Compiler Options C++ ----------------
|
||||||
|
# -g*: generate debugging information
|
||||||
|
# -O*: optimization level
|
||||||
|
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||||
|
# -Wall...: warning level
|
||||||
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
|
# -adhlns...: create assembler listing
|
||||||
|
CPPFLAGS = -g$(DEBUG)
|
||||||
|
CPPFLAGS += $(CPPDEFS)
|
||||||
|
CPPFLAGS += -O$(OPT)
|
||||||
|
CPPFLAGS += -funsigned-char
|
||||||
|
CPPFLAGS += -funsigned-bitfields
|
||||||
|
CPPFLAGS += -fpack-struct
|
||||||
|
CPPFLAGS += -fshort-enums
|
||||||
|
CPPFLAGS += -fno-exceptions
|
||||||
|
CPPFLAGS += -Wall
|
||||||
|
CPPFLAGS += -Wundef
|
||||||
|
#CPPFLAGS += -mshort-calls
|
||||||
|
#CPPFLAGS += -fno-unit-at-a-time
|
||||||
|
#CPPFLAGS += -Wstrict-prototypes
|
||||||
|
#CPPFLAGS += -Wunreachable-code
|
||||||
|
#CPPFLAGS += -Wsign-compare
|
||||||
|
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
|
||||||
|
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||||
|
#CPPFLAGS += $(CSTANDARD)
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Assembler Options ----------------
|
||||||
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
|
# -adhlns: create listing
|
||||||
|
# -gstabs: have the assembler create line number information; note that
|
||||||
|
# for use in COFF files, additional information about filenames
|
||||||
|
# and function names needs to be present in the assembler source
|
||||||
|
# files -- see avr-libc docs [FIXME: not yet described there]
|
||||||
|
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
|
||||||
|
# dump that will be displayed for a given single line of source input.
|
||||||
|
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Library Options ----------------
|
||||||
|
# Minimalistic printf version
|
||||||
|
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
|
||||||
|
|
||||||
|
# Floating point printf version (requires MATH_LIB = -lm below)
|
||||||
|
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
|
||||||
|
|
||||||
|
# If this is left blank, then it will use the Standard printf version.
|
||||||
|
PRINTF_LIB =
|
||||||
|
#PRINTF_LIB = $(PRINTF_LIB_MIN)
|
||||||
|
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
|
||||||
|
|
||||||
|
|
||||||
|
# Minimalistic scanf version
|
||||||
|
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
|
||||||
|
|
||||||
|
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
|
||||||
|
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
|
||||||
|
|
||||||
|
# If this is left blank, then it will use the Standard scanf version.
|
||||||
|
SCANF_LIB =
|
||||||
|
#SCANF_LIB = $(SCANF_LIB_MIN)
|
||||||
|
#SCANF_LIB = $(SCANF_LIB_FLOAT)
|
||||||
|
|
||||||
|
|
||||||
|
MATH_LIB = -lm
|
||||||
|
|
||||||
|
|
||||||
|
# List any extra directories to look for libraries here.
|
||||||
|
# Each directory must be seperated by a space.
|
||||||
|
# Use forward slashes for directory separators.
|
||||||
|
# For a directory that has spaces, enclose it in quotes.
|
||||||
|
EXTRALIBDIRS =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- External Memory Options ----------------
|
||||||
|
|
||||||
|
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
|
||||||
|
# used for variables (.data/.bss) and heap (malloc()).
|
||||||
|
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
|
||||||
|
|
||||||
|
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
|
||||||
|
# only used for heap (malloc()).
|
||||||
|
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
|
||||||
|
|
||||||
|
EXTMEMOPTS =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Linker Options ----------------
|
||||||
|
# -Wl,...: tell GCC to pass this to linker.
|
||||||
|
# -Map: create map file
|
||||||
|
# --cref: add cross reference to map file
|
||||||
|
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
|
||||||
|
LDFLAGS += $(EXTMEMOPTS)
|
||||||
|
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
||||||
|
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||||
|
#LDFLAGS += -T linker_script.x
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Programming Options (avrdude) ----------------
|
||||||
|
|
||||||
|
# Programming hardware
|
||||||
|
# Type: avrdude -c ?
|
||||||
|
# to get a full listing.
|
||||||
|
#
|
||||||
|
AVRDUDE_PROGRAMMER = usbasp
|
||||||
|
|
||||||
|
# com1 = serial port. Use lpt1 to connect to parallel port.
|
||||||
|
AVRDUDE_PORT = usb
|
||||||
|
|
||||||
|
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
||||||
|
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
|
||||||
|
|
||||||
|
|
||||||
|
# Uncomment the following if you want avrdude's erase cycle counter.
|
||||||
|
# Note that this counter needs to be initialized first using -Yn,
|
||||||
|
# see avrdude manual.
|
||||||
|
#AVRDUDE_ERASE_COUNTER = -y
|
||||||
|
|
||||||
|
# Uncomment the following if you do /not/ wish a verification to be
|
||||||
|
# performed after programming the device.
|
||||||
|
#AVRDUDE_NO_VERIFY = -V
|
||||||
|
|
||||||
|
# Increase verbosity level. Please use this when submitting bug
|
||||||
|
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
|
||||||
|
# to submit bug reports.
|
||||||
|
#AVRDUDE_VERBOSE = -v -v
|
||||||
|
|
||||||
|
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
|
||||||
|
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
|
||||||
|
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
|
||||||
|
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Debugging Options ----------------
|
||||||
|
|
||||||
|
# For simulavr only - target MCU frequency.
|
||||||
|
DEBUG_MFREQ = $(F_CPU)
|
||||||
|
|
||||||
|
# Set the DEBUG_UI to either gdb or insight.
|
||||||
|
# DEBUG_UI = gdb
|
||||||
|
DEBUG_UI = insight
|
||||||
|
|
||||||
|
# Set the debugging back-end to either avarice, simulavr.
|
||||||
|
DEBUG_BACKEND = avarice
|
||||||
|
#DEBUG_BACKEND = simulavr
|
||||||
|
|
||||||
|
# GDB Init Filename.
|
||||||
|
GDBINIT_FILE = __avr_gdbinit
|
||||||
|
|
||||||
|
# When using avarice settings for the JTAG
|
||||||
|
JTAG_DEV = /dev/com1
|
||||||
|
|
||||||
|
# Debugging port used to communicate between GDB / avarice / simulavr.
|
||||||
|
DEBUG_PORT = 4242
|
||||||
|
|
||||||
|
# Debugging host used to communicate between GDB / avarice / simulavr, normally
|
||||||
|
# just set to localhost unless doing some sort of crazy debugging when
|
||||||
|
# avarice is running on a different computer.
|
||||||
|
DEBUG_HOST = localhost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
# Define programs and commands.
|
||||||
|
SHELL = sh
|
||||||
|
CC = avr-gcc
|
||||||
|
OBJCOPY = avr-objcopy
|
||||||
|
OBJDUMP = avr-objdump
|
||||||
|
SIZE = avr-size
|
||||||
|
AR = avr-ar rcs
|
||||||
|
NM = avr-nm
|
||||||
|
AVRDUDE = avrdude
|
||||||
|
REMOVE = rm -f
|
||||||
|
REMOVEDIR = rm -rf
|
||||||
|
COPY = cp
|
||||||
|
WINSHELL = cmd
|
||||||
|
|
||||||
|
|
||||||
|
# Define Messages
|
||||||
|
# English
|
||||||
|
MSG_ERRORS_NONE = Errors: none
|
||||||
|
MSG_BEGIN = -------- begin --------
|
||||||
|
MSG_END = -------- end --------
|
||||||
|
MSG_SIZE_BEFORE = Size before:
|
||||||
|
MSG_SIZE_AFTER = Size after:
|
||||||
|
MSG_COFF = Converting to AVR COFF:
|
||||||
|
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
|
||||||
|
MSG_FLASH = Creating load file for Flash:
|
||||||
|
MSG_EEPROM = Creating load file for EEPROM:
|
||||||
|
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
||||||
|
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||||
|
MSG_LINKING = Linking:
|
||||||
|
MSG_COMPILING = Compiling C:
|
||||||
|
MSG_COMPILING_CPP = Compiling C++:
|
||||||
|
MSG_ASSEMBLING = Assembling:
|
||||||
|
MSG_CLEANING = Cleaning project:
|
||||||
|
MSG_CREATING_LIBRARY = Creating library:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define all object files.
|
||||||
|
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
||||||
|
|
||||||
|
# Define all listing files.
|
||||||
|
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
||||||
|
|
||||||
|
|
||||||
|
# Compiler flags to generate dependency files.
|
||||||
|
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||||
|
|
||||||
|
|
||||||
|
# Combine all necessary flags and optional flags.
|
||||||
|
# Add target processor to flags.
|
||||||
|
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||||
|
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
|
||||||
|
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Default target.
|
||||||
|
all: begin gccversion sizebefore build sizeafter end
|
||||||
|
|
||||||
|
# Change the build target to build a HEX file or a library.
|
||||||
|
build: elf hex eep lss sym
|
||||||
|
#build: lib
|
||||||
|
|
||||||
|
|
||||||
|
elf: $(TARGET).elf
|
||||||
|
hex: $(TARGET).hex
|
||||||
|
eep: $(TARGET).eep
|
||||||
|
lss: $(TARGET).lss
|
||||||
|
sym: $(TARGET).sym
|
||||||
|
LIBNAME=lib$(TARGET).a
|
||||||
|
lib: $(LIBNAME)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Eye candy.
|
||||||
|
# AVR Studio 3.x does not check make's exit code but relies on
|
||||||
|
# the following magic strings to be generated by the compile job.
|
||||||
|
begin:
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_BEGIN)
|
||||||
|
|
||||||
|
end:
|
||||||
|
@echo $(MSG_END)
|
||||||
|
@echo
|
||||||
|
|
||||||
|
|
||||||
|
# Display size of file.
|
||||||
|
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||||
|
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
|
||||||
|
|
||||||
|
sizebefore:
|
||||||
|
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||||
|
2>/dev/null; echo; fi
|
||||||
|
|
||||||
|
sizeafter:
|
||||||
|
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||||
|
2>/dev/null; echo; fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Display compiler version information.
|
||||||
|
gccversion :
|
||||||
|
@$(CC) --version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Program the device.
|
||||||
|
program: $(TARGET).hex $(TARGET).eep
|
||||||
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
|
||||||
|
|
||||||
|
|
||||||
|
# Generate avr-gdb config/init file which does the following:
|
||||||
|
# define the reset signal, load the target file, connect to target, and set
|
||||||
|
# a breakpoint at main().
|
||||||
|
gdb-config:
|
||||||
|
@$(REMOVE) $(GDBINIT_FILE)
|
||||||
|
@echo define reset >> $(GDBINIT_FILE)
|
||||||
|
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
|
||||||
|
@echo end >> $(GDBINIT_FILE)
|
||||||
|
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
|
||||||
|
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
|
||||||
|
ifeq ($(DEBUG_BACKEND),simulavr)
|
||||||
|
@echo load >> $(GDBINIT_FILE)
|
||||||
|
endif
|
||||||
|
@echo break main >> $(GDBINIT_FILE)
|
||||||
|
|
||||||
|
debug: gdb-config $(TARGET).elf
|
||||||
|
ifeq ($(DEBUG_BACKEND), avarice)
|
||||||
|
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
|
||||||
|
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
|
||||||
|
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
|
||||||
|
@$(WINSHELL) /c pause
|
||||||
|
|
||||||
|
else
|
||||||
|
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
|
||||||
|
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
|
||||||
|
endif
|
||||||
|
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
||||||
|
COFFCONVERT = $(OBJCOPY) --debugging
|
||||||
|
COFFCONVERT += --change-section-address .data-0x800000
|
||||||
|
COFFCONVERT += --change-section-address .bss-0x800000
|
||||||
|
COFFCONVERT += --change-section-address .noinit-0x800000
|
||||||
|
COFFCONVERT += --change-section-address .eeprom-0x810000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
coff: $(TARGET).elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_COFF) $(TARGET).cof
|
||||||
|
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
|
||||||
|
|
||||||
|
|
||||||
|
extcoff: $(TARGET).elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
|
||||||
|
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Create final output files (.hex, .eep) from ELF output file.
|
||||||
|
%.hex: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_FLASH) $@
|
||||||
|
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
|
||||||
|
|
||||||
|
%.eep: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_EEPROM) $@
|
||||||
|
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||||
|
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
|
||||||
|
|
||||||
|
# Create extended listing file from ELF output file.
|
||||||
|
%.lss: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_EXTENDED_LISTING) $@
|
||||||
|
$(OBJDUMP) -h -S -z $< > $@
|
||||||
|
|
||||||
|
# Create a symbol table from ELF output file.
|
||||||
|
%.sym: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_SYMBOL_TABLE) $@
|
||||||
|
$(NM) -n $< > $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Create library from object files.
|
||||||
|
.SECONDARY : $(TARGET).a
|
||||||
|
.PRECIOUS : $(OBJ)
|
||||||
|
%.a: $(OBJ)
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_CREATING_LIBRARY) $@
|
||||||
|
$(AR) $@ $(OBJ)
|
||||||
|
|
||||||
|
|
||||||
|
# Link: create ELF output file from object files.
|
||||||
|
.SECONDARY : $(TARGET).elf
|
||||||
|
.PRECIOUS : $(OBJ)
|
||||||
|
%.elf: $(OBJ)
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_LINKING) $@
|
||||||
|
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create object files from C source files.
|
||||||
|
$(OBJDIR)/%.o : %.c
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_COMPILING) $<
|
||||||
|
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create object files from C++ source files.
|
||||||
|
$(OBJDIR)/%.o : %.cpp
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_COMPILING_CPP) $<
|
||||||
|
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create assembler files from C source files.
|
||||||
|
%.s : %.c
|
||||||
|
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create assembler files from C++ source files.
|
||||||
|
%.s : %.cpp
|
||||||
|
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Assemble: create object files from assembler source files.
|
||||||
|
$(OBJDIR)/%.o : %.S
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_ASSEMBLING) $<
|
||||||
|
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Create preprocessed source for use in sending a bug report.
|
||||||
|
%.i : %.c
|
||||||
|
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Target: clean project.
|
||||||
|
clean: begin clean_list end
|
||||||
|
|
||||||
|
clean_list :
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_CLEANING)
|
||||||
|
$(REMOVE) $(TARGET).hex
|
||||||
|
$(REMOVE) $(TARGET).eep
|
||||||
|
$(REMOVE) $(TARGET).cof
|
||||||
|
$(REMOVE) $(TARGET).elf
|
||||||
|
$(REMOVE) $(TARGET).map
|
||||||
|
$(REMOVE) $(TARGET).sym
|
||||||
|
$(REMOVE) $(TARGET).lss
|
||||||
|
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
|
||||||
|
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||||
|
$(REMOVE) $(SRC:.c=.s)
|
||||||
|
$(REMOVE) $(SRC:.c=.d)
|
||||||
|
$(REMOVE) $(SRC:.c=.i)
|
||||||
|
$(REMOVEDIR) .dep
|
||||||
|
|
||||||
|
|
||||||
|
# Create object files directory
|
||||||
|
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||||
|
|
||||||
|
|
||||||
|
# Include the dependency files.
|
||||||
|
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||||
|
|
||||||
|
|
||||||
|
# Listing of phony targets.
|
||||||
|
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||||
|
build elf hex eep lss sym coff extcoff \
|
||||||
|
clean clean_list program debug gdb-config
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
avrdude -c usbasp -p t84 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
|
||||||
|
|
||||||
|
make clean && make && make program
|
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define SET_BIT(byte, bit) ((byte) |= _BV(bit))
|
||||||
|
#define CLEAR_BIT(byte,bit) ((byte) &= ~_BV(bit))
|
||||||
|
#define IS_SET(byte,bit) (((byte) & (1UL << (bit))) >> (bit))
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include <libs/serialdebug.h>
|
||||||
|
|
||||||
|
#if SERIALDEBUG_USE_INTS
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void serial_configure(void) {
|
||||||
|
// Configure serial output
|
||||||
|
SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
SERIALDEBUG_SOFT_TX_DDR |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
fdev_setup_stream(&serialdebug_usartout, usart_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
stdout = &serialdebug_usartout;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usart_putchar (char c, FILE *stream) {
|
||||||
|
#if SERIALDEBUG_USE_INTS
|
||||||
|
cli();
|
||||||
|
#endif
|
||||||
|
// Print 1 char to serial
|
||||||
|
uint8_t bit_mask;
|
||||||
|
|
||||||
|
// start bit
|
||||||
|
SERIALDEBUG_SOFT_TX_PORT &= ~(1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
_delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT);
|
||||||
|
|
||||||
|
// data bits
|
||||||
|
for (bit_mask=0x01; bit_mask; bit_mask<<=1) {
|
||||||
|
if (c & bit_mask) {
|
||||||
|
SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SERIALDEBUG_SOFT_TX_PORT &= ~(1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
}
|
||||||
|
_delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop bit(s)
|
||||||
|
SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
_delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT * SERIALDEBUG_STOP_BITS);
|
||||||
|
|
||||||
|
#if SERIALDEBUG_USE_INTS
|
||||||
|
sei();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return c;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_putstring(char string[]) {
|
||||||
|
// Print a string of arbitrary length to serial
|
||||||
|
int i=0;
|
||||||
|
while (string[i] != '\0') {
|
||||||
|
usart_putchar(string[i], &serialdebug_usartout);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_putstring_nl(char string[]) {
|
||||||
|
if(string) dbg_putstring(string);
|
||||||
|
dbg_putstring("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbg_putint(unsigned int num) {
|
||||||
|
// Create string representing int and print to serial
|
||||||
|
char c[7];
|
||||||
|
itoa(num, c, 10);
|
||||||
|
dbg_putstring(c);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <serialsettings.h>
|
||||||
|
|
||||||
|
FILE static serialdebug_usartout = {0};
|
||||||
|
|
||||||
|
void serial_configure(void);
|
||||||
|
int usart_putchar (char c, FILE *stream);
|
||||||
|
int usart_putchar_nl (char c, FILE *stream);
|
|
@ -0,0 +1,595 @@
|
||||||
|
1 .file "serialdebug.c"
|
||||||
|
2 __SP_H__ = 0x3e
|
||||||
|
3 __SP_L__ = 0x3d
|
||||||
|
4 __SREG__ = 0x3f
|
||||||
|
5 __tmp_reg__ = 0
|
||||||
|
6 __zero_reg__ = 1
|
||||||
|
7 .text
|
||||||
|
8 .Ltext0:
|
||||||
|
9 .cfi_sections .debug_frame
|
||||||
|
10 .global usart_putchar
|
||||||
|
12 usart_putchar:
|
||||||
|
13 .LFB8:
|
||||||
|
14 .file 1 "libs/serialdebug.c"
|
||||||
|
1:libs/serialdebug.c **** #include <libs/serialdebug.h>
|
||||||
|
2:libs/serialdebug.c ****
|
||||||
|
3:libs/serialdebug.c **** #if SERIALDEBUG_USE_INTS
|
||||||
|
4:libs/serialdebug.c **** #include <avr/interrupt.h>
|
||||||
|
5:libs/serialdebug.c **** #endif
|
||||||
|
6:libs/serialdebug.c ****
|
||||||
|
7:libs/serialdebug.c **** void serial_configure(void) {
|
||||||
|
8:libs/serialdebug.c **** // Configure serial output
|
||||||
|
9:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
10:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_DDR |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
11:libs/serialdebug.c **** fdev_setup_stream(&serialdebug_usartout, usart_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
12:libs/serialdebug.c **** stdout = &serialdebug_usartout;
|
||||||
|
13:libs/serialdebug.c **** }
|
||||||
|
14:libs/serialdebug.c ****
|
||||||
|
15:libs/serialdebug.c **** int usart_putchar (char c, FILE *stream) {
|
||||||
|
15 .loc 1 15 0
|
||||||
|
16 .cfi_startproc
|
||||||
|
17 .LVL0:
|
||||||
|
18 /* prologue: function */
|
||||||
|
19 /* frame size = 0 */
|
||||||
|
20 /* stack size = 0 */
|
||||||
|
21 .L__stack_usage = 0
|
||||||
|
16:libs/serialdebug.c **** #if SERIALDEBUG_USE_INTS
|
||||||
|
17:libs/serialdebug.c **** cli();
|
||||||
|
18:libs/serialdebug.c **** #endif
|
||||||
|
19:libs/serialdebug.c **** // Print 1 char to serial
|
||||||
|
20:libs/serialdebug.c **** uint8_t bit_mask;
|
||||||
|
21:libs/serialdebug.c ****
|
||||||
|
22:libs/serialdebug.c **** // start bit
|
||||||
|
23:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT &= ~(1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
22 .loc 1 23 0
|
||||||
|
23 0000 DE98 cbi 0x1b,6
|
||||||
|
24 .LVL1:
|
||||||
|
25 .LBB8:
|
||||||
|
26 .LBB9:
|
||||||
|
27 .file 2 "/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h"
|
||||||
|
1:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /* Copyright (c) 2002, Marek Michalkiewicz
|
||||||
|
2:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Copyright (c) 2004,2005,2007 Joerg Wunsch
|
||||||
|
3:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Copyright (c) 2007 Florin-Viorel Petrov
|
||||||
|
4:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** All rights reserved.
|
||||||
|
5:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
6:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Redistribution and use in source and binary forms, with or without
|
||||||
|
7:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** modification, are permitted provided that the following conditions are met:
|
||||||
|
8:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
9:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** * Redistributions of source code must retain the above copyright
|
||||||
|
10:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** notice, this list of conditions and the following disclaimer.
|
||||||
|
11:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
12:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** * Redistributions in binary form must reproduce the above copyright
|
||||||
|
13:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** notice, this list of conditions and the following disclaimer in
|
||||||
|
14:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** the documentation and/or other materials provided with the
|
||||||
|
15:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** distribution.
|
||||||
|
16:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
17:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** * Neither the name of the copyright holders nor the names of
|
||||||
|
18:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** contributors may be used to endorse or promote products derived
|
||||||
|
19:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** from this software without specific prior written permission.
|
||||||
|
20:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
21:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
22:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
23:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
24:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
25:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
26:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
27:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
28:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
29:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
30:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
31:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** POSSIBILITY OF SUCH DAMAGE. */
|
||||||
|
32:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
33:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /* $Id$ */
|
||||||
|
34:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
35:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef _UTIL_DELAY_H_
|
||||||
|
36:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #define _UTIL_DELAY_H_ 1
|
||||||
|
37:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
38:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef __HAS_DELAY_CYCLES
|
||||||
|
39:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #define __HAS_DELAY_CYCLES 1
|
||||||
|
40:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
41:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
42:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <inttypes.h>
|
||||||
|
43:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <util/delay_basic.h>
|
||||||
|
44:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <math.h>
|
||||||
|
45:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
46:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /** \file */
|
||||||
|
47:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /** \defgroup util_delay <util/delay.h>: Convenience functions for busy-wait delay loops
|
||||||
|
48:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \code
|
||||||
|
49:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #define F_CPU 1000000UL // 1 MHz
|
||||||
|
50:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** //#define F_CPU 14.7456E6
|
||||||
|
51:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <util/delay.h>
|
||||||
|
52:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \endcode
|
||||||
|
53:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
54:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \note As an alternative method, it is possible to pass the
|
||||||
|
55:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** F_CPU macro down to the compiler from the Makefile.
|
||||||
|
56:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Obviously, in that case, no \c \#define statement should be
|
||||||
|
57:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** used.
|
||||||
|
58:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
59:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The functions in this header file are wrappers around the basic
|
||||||
|
60:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** busy-wait functions from <util/delay_basic.h>. They are meant as
|
||||||
|
61:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** convenience functions where actual time values can be specified
|
||||||
|
62:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** rather than a number of cycles to wait for. The idea behind is
|
||||||
|
63:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** that compile-time constant expressions will be eliminated by
|
||||||
|
64:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** compiler optimization so floating-point expressions can be used
|
||||||
|
65:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** to calculate the number of delay cycles needed based on the CPU
|
||||||
|
66:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** frequency passed by the macro F_CPU.
|
||||||
|
67:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
68:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \note In order for these functions to work as intended, compiler
|
||||||
|
69:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** optimizations <em>must</em> be enabled, and the delay time
|
||||||
|
70:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** <em>must</em> be an expression that is a known constant at
|
||||||
|
71:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** compile-time. If these requirements are not met, the resulting
|
||||||
|
72:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** delay will be much longer (and basically unpredictable), and
|
||||||
|
73:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** applications that otherwise do not use floating-point calculations
|
||||||
|
74:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** will experience severe code bloat by the floating-point library
|
||||||
|
75:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** routines linked into the application.
|
||||||
|
76:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
77:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The functions available allow the specification of microsecond, and
|
||||||
|
78:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** millisecond delays directly, using the application-supplied macro
|
||||||
|
79:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** F_CPU as the CPU clock frequency (in Hertz).
|
||||||
|
80:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
81:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** */
|
||||||
|
82:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
83:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if !defined(__DOXYGEN__)
|
||||||
|
84:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** static inline void _delay_us(double __us) __attribute__((always_inline));
|
||||||
|
85:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** static inline void _delay_ms(double __ms) __attribute__((always_inline));
|
||||||
|
86:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
87:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
88:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef F_CPU
|
||||||
|
89:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /* prevent compiler error by supplying a default */
|
||||||
|
90:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # warning "F_CPU not defined for <util/delay.h>"
|
||||||
|
91:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # define F_CPU 1000000UL
|
||||||
|
92:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
93:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
94:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef __OPTIMIZE__
|
||||||
|
95:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
|
||||||
|
96:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
97:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
98:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
|
||||||
|
99:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \
|
||||||
|
100:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __STDC_HOSTED__
|
||||||
|
101:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # include <math.h>
|
||||||
|
102:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
103:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
104:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /**
|
||||||
|
105:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \ingroup util_delay
|
||||||
|
106:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
107:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Perform a delay of \c __ms milliseconds, using _delay_loop_2().
|
||||||
|
108:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
109:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The macro F_CPU is supposed to be defined to a
|
||||||
|
110:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** constant defining the CPU clock frequency (in Hertz).
|
||||||
|
111:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
112:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The maximal possible delay is 262.14 ms / F_CPU in MHz.
|
||||||
|
113:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
114:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** When the user request delay which exceed the maximum possible one,
|
||||||
|
115:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_ms() provides a decreased resolution functionality. In this
|
||||||
|
116:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** mode _delay_ms() will work with a resolution of 1/10 ms, providing
|
||||||
|
117:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** delays up to 6.5535 seconds (independent from CPU frequency). The
|
||||||
|
118:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** user will not be informed about decreased resolution.
|
||||||
|
119:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
120:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
|
||||||
|
121:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For
|
||||||
|
122:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** values greater than the maximal possible delay, overflows results in
|
||||||
|
123:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** no delay i.e., 0ms.
|
||||||
|
124:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
125:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Conversion of __us into clock cycles may not always result in integer.
|
||||||
|
126:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** By default, the clock cycles rounded up to next integer. This ensures that
|
||||||
|
127:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** the user gets atleast __us microseconds of delay.
|
||||||
|
128:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
129:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__
|
||||||
|
130:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** to round down and round to closest integer.
|
||||||
|
131:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
132:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Note: The new implementation of _delay_ms(double __ms) with
|
||||||
|
133:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
|
||||||
|
134:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
|
||||||
|
135:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Also, the backward compatible
|
||||||
|
136:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** algorithm will be chosen if the code is compiled in a <em>freestanding
|
||||||
|
137:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** environment</em> (GCC option \c -ffreestanding), as the math functions
|
||||||
|
138:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** required for rounding are not available to the compiler then.
|
||||||
|
139:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
140:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** */
|
||||||
|
141:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** void
|
||||||
|
142:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_ms(double __ms)
|
||||||
|
143:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
|
||||||
|
144:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** double __tmp ;
|
||||||
|
145:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
|
||||||
|
146:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \
|
||||||
|
147:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __STDC_HOSTED__
|
||||||
|
148:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** uint32_t __ticks_dc;
|
||||||
|
149:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** extern void __builtin_avr_delay_cycles(unsigned long);
|
||||||
|
150:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __tmp = ((F_CPU) / 1e3) * __ms;
|
||||||
|
151:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
152:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if defined(__DELAY_ROUND_DOWN__)
|
||||||
|
153:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)fabs(__tmp);
|
||||||
|
154:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
155:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #elif defined(__DELAY_ROUND_CLOSEST__)
|
||||||
|
156:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
|
||||||
|
157:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
158:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #else
|
||||||
|
159:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** //round up by default
|
||||||
|
160:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
|
||||||
|
161:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
162:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
163:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(__ticks_dc);
|
||||||
|
164:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
165:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #else
|
||||||
|
166:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** uint16_t __ticks;
|
||||||
|
167:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __tmp = ((F_CPU) / 4e3) * __ms;
|
||||||
|
168:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** if (__tmp < 1.0)
|
||||||
|
169:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks = 1;
|
||||||
|
170:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** else if (__tmp > 65535)
|
||||||
|
171:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
|
||||||
|
172:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** // __ticks = requested delay in 1/10 ms
|
||||||
|
173:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks = (uint16_t) (__ms * 10.0);
|
||||||
|
174:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** while(__ticks)
|
||||||
|
175:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
|
||||||
|
176:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** // wait 1/10 ms
|
||||||
|
177:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_loop_2(((F_CPU) / 4e3) / 10);
|
||||||
|
178:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks --;
|
||||||
|
179:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** }
|
||||||
|
180:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** return;
|
||||||
|
181:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** }
|
||||||
|
182:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** else
|
||||||
|
183:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks = (uint16_t)__tmp;
|
||||||
|
184:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_loop_2(__ticks);
|
||||||
|
185:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
186:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** }
|
||||||
|
187:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
188:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /**
|
||||||
|
189:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \ingroup util_delay
|
||||||
|
190:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
191:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Perform a delay of \c __us microseconds, using _delay_loop_1().
|
||||||
|
192:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
193:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The macro F_CPU is supposed to be defined to a
|
||||||
|
194:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** constant defining the CPU clock frequency (in Hertz).
|
||||||
|
195:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
196:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The maximal possible delay is 768 us / F_CPU in MHz.
|
||||||
|
197:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
198:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** If the user requests a delay greater than the maximal possible one,
|
||||||
|
199:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_us() will automatically call _delay_ms() instead. The user
|
||||||
|
200:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** will not be informed about this case.
|
||||||
|
201:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
202:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
|
||||||
|
203:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** support, maximal possible delay is 4294967.295 us/ F_CPU in MHz. For
|
||||||
|
204:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** values greater than the maximal possible delay, overflow results in
|
||||||
|
205:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** no delay i.e., 0us.
|
||||||
|
206:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
207:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Conversion of __us into clock cycles may not always result in integer.
|
||||||
|
208:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** By default, the clock cycles rounded up to next integer. This ensures that
|
||||||
|
209:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** the user gets atleast __us microseconds of delay.
|
||||||
|
210:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
211:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__
|
||||||
|
212:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** to round down and round to closest integer.
|
||||||
|
213:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
214:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Note: The new implementation of _delay_us(double __us) with
|
||||||
|
215:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
|
||||||
|
216:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
|
||||||
|
217:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Also, the backward compatible
|
||||||
|
218:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** algorithm will be chosen if the code is compiled in a <em>freestanding
|
||||||
|
219:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** environment</em> (GCC option \c -ffreestanding), as the math functions
|
||||||
|
220:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** required for rounding are not available to the compiler then.
|
||||||
|
221:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
222:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** */
|
||||||
|
223:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** void
|
||||||
|
224:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_us(double __us)
|
||||||
|
225:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
|
||||||
|
226:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** double __tmp ;
|
||||||
|
227:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
|
||||||
|
228:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \
|
||||||
|
229:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __STDC_HOSTED__
|
||||||
|
230:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** uint32_t __ticks_dc;
|
||||||
|
231:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** extern void __builtin_avr_delay_cycles(unsigned long);
|
||||||
|
232:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __tmp = ((F_CPU) / 1e6) * __us;
|
||||||
|
233:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
234:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if defined(__DELAY_ROUND_DOWN__)
|
||||||
|
235:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)fabs(__tmp);
|
||||||
|
236:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
237:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #elif defined(__DELAY_ROUND_CLOSEST__)
|
||||||
|
238:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
|
||||||
|
239:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
240:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #else
|
||||||
|
241:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** //round up by default
|
||||||
|
242:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
|
||||||
|
243:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
|
||||||
|
244:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
|
||||||
|
245:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(__ticks_dc);
|
||||||
|
28 .loc 2 245 0
|
||||||
|
29 0002 EFEC ldi r30,lo8(207)
|
||||||
|
30 0004 F0E0 ldi r31,hi8(207)
|
||||||
|
31 0006 3197 1: sbiw r30,1
|
||||||
|
32 0008 01F4 brne 1b
|
||||||
|
33 000a 00C0 rjmp .
|
||||||
|
34 000c 0000 nop
|
||||||
|
35 .LVL2:
|
||||||
|
36 000e 28E0 ldi r18,lo8(8)
|
||||||
|
37 0010 30E0 ldi r19,0
|
||||||
|
38 .LBE9:
|
||||||
|
39 .LBE8:
|
||||||
|
24:libs/serialdebug.c **** _delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT);
|
||||||
|
25:libs/serialdebug.c ****
|
||||||
|
26:libs/serialdebug.c **** // data bits
|
||||||
|
27:libs/serialdebug.c **** for (bit_mask=0x01; bit_mask; bit_mask<<=1) {
|
||||||
|
40 .loc 1 27 0
|
||||||
|
41 0012 91E0 ldi r25,lo8(1)
|
||||||
|
42 .LVL3:
|
||||||
|
43 .L5:
|
||||||
|
28:libs/serialdebug.c **** if (c & bit_mask) {
|
||||||
|
44 .loc 1 28 0
|
||||||
|
45 0014 492F mov r20,r25
|
||||||
|
46 0016 4823 and r20,r24
|
||||||
|
47 0018 01F0 breq .L2
|
||||||
|
29:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
48 .loc 1 29 0
|
||||||
|
49 001a DE9A sbi 0x1b,6
|
||||||
|
50 001c 00C0 rjmp .L3
|
||||||
|
51 .L2:
|
||||||
|
30:libs/serialdebug.c **** }
|
||||||
|
31:libs/serialdebug.c **** else {
|
||||||
|
32:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT &= ~(1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
52 .loc 1 32 0
|
||||||
|
53 001e DE98 cbi 0x1b,6
|
||||||
|
54 .L3:
|
||||||
|
55 .LVL4:
|
||||||
|
56 .LBB10:
|
||||||
|
57 .LBB11:
|
||||||
|
58 .loc 2 245 0
|
||||||
|
59 0020 EFEC ldi r30,lo8(207)
|
||||||
|
60 0022 F0E0 ldi r31,hi8(207)
|
||||||
|
61 0024 3197 1: sbiw r30,1
|
||||||
|
62 0026 01F4 brne 1b
|
||||||
|
63 0028 00C0 rjmp .
|
||||||
|
64 002a 0000 nop
|
||||||
|
65 .LBE11:
|
||||||
|
66 .LBE10:
|
||||||
|
27:libs/serialdebug.c **** for (bit_mask=0x01; bit_mask; bit_mask<<=1) {
|
||||||
|
67 .loc 1 27 0
|
||||||
|
68 002c 990F lsl r25
|
||||||
|
69 .LVL5:
|
||||||
|
70 002e 2150 subi r18,1
|
||||||
|
71 0030 3109 sbc r19,__zero_reg__
|
||||||
|
72 0032 2115 cp r18,__zero_reg__
|
||||||
|
73 0034 3105 cpc r19,__zero_reg__
|
||||||
|
74 0036 01F4 brne .L5
|
||||||
|
33:libs/serialdebug.c **** }
|
||||||
|
34:libs/serialdebug.c **** _delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT);
|
||||||
|
35:libs/serialdebug.c **** }
|
||||||
|
36:libs/serialdebug.c ****
|
||||||
|
37:libs/serialdebug.c **** // stop bit(s)
|
||||||
|
38:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
75 .loc 1 38 0
|
||||||
|
76 0038 DE9A sbi 0x1b,6
|
||||||
|
77 .LVL6:
|
||||||
|
78 .LBB12:
|
||||||
|
79 .LBB13:
|
||||||
|
80 .loc 2 245 0
|
||||||
|
81 003a EFEC ldi r30,lo8(207)
|
||||||
|
82 003c F0E0 ldi r31,hi8(207)
|
||||||
|
83 003e 3197 1: sbiw r30,1
|
||||||
|
84 0040 01F4 brne 1b
|
||||||
|
85 0042 00C0 rjmp .
|
||||||
|
86 0044 0000 nop
|
||||||
|
87 .LBE13:
|
||||||
|
88 .LBE12:
|
||||||
|
39:libs/serialdebug.c **** _delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT * SERIALDEBUG_STOP_BITS);
|
||||||
|
40:libs/serialdebug.c ****
|
||||||
|
41:libs/serialdebug.c **** #if SERIALDEBUG_USE_INTS
|
||||||
|
42:libs/serialdebug.c **** sei();
|
||||||
|
43:libs/serialdebug.c **** #endif
|
||||||
|
44:libs/serialdebug.c ****
|
||||||
|
45:libs/serialdebug.c **** return c;
|
||||||
|
46:libs/serialdebug.c ****
|
||||||
|
47:libs/serialdebug.c **** }
|
||||||
|
89 .loc 1 47 0
|
||||||
|
90 0046 90E0 ldi r25,0
|
||||||
|
91 .LVL7:
|
||||||
|
92 0048 0895 ret
|
||||||
|
93 .cfi_endproc
|
||||||
|
94 .LFE8:
|
||||||
|
96 .global serial_configure
|
||||||
|
98 serial_configure:
|
||||||
|
99 .LFB7:
|
||||||
|
7:libs/serialdebug.c **** void serial_configure(void) {
|
||||||
|
100 .loc 1 7 0
|
||||||
|
101 .cfi_startproc
|
||||||
|
102 /* prologue: function */
|
||||||
|
103 /* frame size = 0 */
|
||||||
|
104 /* stack size = 0 */
|
||||||
|
105 .L__stack_usage = 0
|
||||||
|
9:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
106 .loc 1 9 0
|
||||||
|
107 004a DE9A sbi 0x1b,6
|
||||||
|
10:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_DDR |= (1<<SERIALDEBUG_SOFT_TX_BIT);
|
||||||
|
108 .loc 1 10 0
|
||||||
|
109 004c D69A sbi 0x1a,6
|
||||||
|
11:libs/serialdebug.c **** fdev_setup_stream(&serialdebug_usartout, usart_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
110 .loc 1 11 0
|
||||||
|
111 004e 80E0 ldi r24,lo8(gs(usart_putchar))
|
||||||
|
112 0050 90E0 ldi r25,hi8(gs(usart_putchar))
|
||||||
|
113 0052 9093 0000 sts serialdebug_usartout+8+1,r25
|
||||||
|
114 0056 8093 0000 sts serialdebug_usartout+8,r24
|
||||||
|
115 005a 1092 0000 sts serialdebug_usartout+10+1,__zero_reg__
|
||||||
|
116 005e 1092 0000 sts serialdebug_usartout+10,__zero_reg__
|
||||||
|
117 0062 82E0 ldi r24,lo8(2)
|
||||||
|
118 0064 8093 0000 sts serialdebug_usartout+3,r24
|
||||||
|
119 0068 1092 0000 sts serialdebug_usartout+12+1,__zero_reg__
|
||||||
|
120 006c 1092 0000 sts serialdebug_usartout+12,__zero_reg__
|
||||||
|
12:libs/serialdebug.c **** stdout = &serialdebug_usartout;
|
||||||
|
121 .loc 1 12 0
|
||||||
|
122 0070 80E0 ldi r24,lo8(serialdebug_usartout)
|
||||||
|
123 0072 90E0 ldi r25,hi8(serialdebug_usartout)
|
||||||
|
124 0074 9093 0000 sts __iob+2+1,r25
|
||||||
|
125 0078 8093 0000 sts __iob+2,r24
|
||||||
|
126 007c 0895 ret
|
||||||
|
127 .cfi_endproc
|
||||||
|
128 .LFE7:
|
||||||
|
130 .global dbg_putstring
|
||||||
|
132 dbg_putstring:
|
||||||
|
133 .LFB9:
|
||||||
|
48:libs/serialdebug.c ****
|
||||||
|
49:libs/serialdebug.c **** void dbg_putstring(char string[]) {
|
||||||
|
134 .loc 1 49 0
|
||||||
|
135 .cfi_startproc
|
||||||
|
136 .LVL8:
|
||||||
|
137 007e CF93 push r28
|
||||||
|
138 .LCFI0:
|
||||||
|
139 .cfi_def_cfa_offset 3
|
||||||
|
140 .cfi_offset 28, -2
|
||||||
|
141 0080 DF93 push r29
|
||||||
|
142 .LCFI1:
|
||||||
|
143 .cfi_def_cfa_offset 4
|
||||||
|
144 .cfi_offset 29, -3
|
||||||
|
145 /* prologue: function */
|
||||||
|
146 /* frame size = 0 */
|
||||||
|
147 /* stack size = 2 */
|
||||||
|
148 .L__stack_usage = 2
|
||||||
|
149 0082 EC01 movw r28,r24
|
||||||
|
150 .LVL9:
|
||||||
|
151 .L9:
|
||||||
|
50:libs/serialdebug.c **** // Print a string of arbitrary length to serial
|
||||||
|
51:libs/serialdebug.c **** int i=0;
|
||||||
|
52:libs/serialdebug.c **** while (string[i] != '\0') {
|
||||||
|
152 .loc 1 52 0 discriminator 1
|
||||||
|
153 0084 8991 ld r24,Y+
|
||||||
|
154 .LVL10:
|
||||||
|
155 0086 8823 tst r24
|
||||||
|
156 0088 01F0 breq .L11
|
||||||
|
53:libs/serialdebug.c **** usart_putchar(string[i], &serialdebug_usartout);
|
||||||
|
157 .loc 1 53 0
|
||||||
|
158 008a 60E0 ldi r22,lo8(serialdebug_usartout)
|
||||||
|
159 008c 70E0 ldi r23,hi8(serialdebug_usartout)
|
||||||
|
160 008e 00D0 rcall usart_putchar
|
||||||
|
161 .LVL11:
|
||||||
|
162 0090 00C0 rjmp .L9
|
||||||
|
163 .LVL12:
|
||||||
|
164 .L11:
|
||||||
|
165 /* epilogue start */
|
||||||
|
54:libs/serialdebug.c **** i++;
|
||||||
|
55:libs/serialdebug.c **** }
|
||||||
|
56:libs/serialdebug.c **** }
|
||||||
|
166 .loc 1 56 0
|
||||||
|
167 0092 DF91 pop r29
|
||||||
|
168 0094 CF91 pop r28
|
||||||
|
169 .LVL13:
|
||||||
|
170 0096 0895 ret
|
||||||
|
171 .cfi_endproc
|
||||||
|
172 .LFE9:
|
||||||
|
174 .section .rodata.str1.1,"aMS",@progbits,1
|
||||||
|
175 .LC0:
|
||||||
|
176 0000 0A00 .string "\n"
|
||||||
|
177 .text
|
||||||
|
178 .global dbg_putstring_nl
|
||||||
|
180 dbg_putstring_nl:
|
||||||
|
181 .LFB10:
|
||||||
|
57:libs/serialdebug.c ****
|
||||||
|
58:libs/serialdebug.c **** void dbg_putstring_nl(char string[]) {
|
||||||
|
182 .loc 1 58 0
|
||||||
|
183 .cfi_startproc
|
||||||
|
184 .LVL14:
|
||||||
|
185 /* prologue: function */
|
||||||
|
186 /* frame size = 0 */
|
||||||
|
187 /* stack size = 0 */
|
||||||
|
188 .L__stack_usage = 0
|
||||||
|
59:libs/serialdebug.c **** if(string) dbg_putstring(string);
|
||||||
|
189 .loc 1 59 0
|
||||||
|
190 0098 0097 sbiw r24,0
|
||||||
|
191 009a 01F0 breq .L13
|
||||||
|
192 .loc 1 59 0 is_stmt 0 discriminator 1
|
||||||
|
193 009c 00D0 rcall dbg_putstring
|
||||||
|
194 .LVL15:
|
||||||
|
195 .L13:
|
||||||
|
60:libs/serialdebug.c **** dbg_putstring("\n");
|
||||||
|
196 .loc 1 60 0 is_stmt 1
|
||||||
|
197 009e 80E0 ldi r24,lo8(.LC0)
|
||||||
|
198 00a0 90E0 ldi r25,hi8(.LC0)
|
||||||
|
199 00a2 00C0 rjmp dbg_putstring
|
||||||
|
200 .LVL16:
|
||||||
|
201 .cfi_endproc
|
||||||
|
202 .LFE10:
|
||||||
|
204 .global dbg_putint
|
||||||
|
206 dbg_putint:
|
||||||
|
207 .LFB11:
|
||||||
|
61:libs/serialdebug.c **** }
|
||||||
|
62:libs/serialdebug.c ****
|
||||||
|
63:libs/serialdebug.c **** void dbg_putint(unsigned int num) {
|
||||||
|
208 .loc 1 63 0
|
||||||
|
209 .cfi_startproc
|
||||||
|
210 .LVL17:
|
||||||
|
211 00a4 CF93 push r28
|
||||||
|
212 .LCFI2:
|
||||||
|
213 .cfi_def_cfa_offset 3
|
||||||
|
214 .cfi_offset 28, -2
|
||||||
|
215 00a6 DF93 push r29
|
||||||
|
216 .LCFI3:
|
||||||
|
217 .cfi_def_cfa_offset 4
|
||||||
|
218 .cfi_offset 29, -3
|
||||||
|
219 00a8 CDB7 in r28,__SP_L__
|
||||||
|
220 00aa DEB7 in r29,__SP_H__
|
||||||
|
221 .LCFI4:
|
||||||
|
222 .cfi_def_cfa_register 28
|
||||||
|
223 00ac 2797 sbiw r28,7
|
||||||
|
224 .LCFI5:
|
||||||
|
225 .cfi_def_cfa_offset 11
|
||||||
|
226 00ae 0FB6 in __tmp_reg__,__SREG__
|
||||||
|
227 00b0 F894 cli
|
||||||
|
228 00b2 DEBF out __SP_H__,r29
|
||||||
|
229 00b4 0FBE out __SREG__,__tmp_reg__
|
||||||
|
230 00b6 CDBF out __SP_L__,r28
|
||||||
|
231 /* prologue: function */
|
||||||
|
232 /* frame size = 7 */
|
||||||
|
233 /* stack size = 9 */
|
||||||
|
234 .L__stack_usage = 9
|
||||||
|
64:libs/serialdebug.c **** // Create string representing int and print to serial
|
||||||
|
65:libs/serialdebug.c **** char c[7];
|
||||||
|
66:libs/serialdebug.c **** itoa(num, c, 10);
|
||||||
|
235 .loc 1 66 0
|
||||||
|
236 00b8 4AE0 ldi r20,lo8(10)
|
||||||
|
237 00ba 50E0 ldi r21,0
|
||||||
|
238 00bc BE01 movw r22,r28
|
||||||
|
239 00be 6F5F subi r22,-1
|
||||||
|
240 00c0 7F4F sbci r23,-1
|
||||||
|
241 00c2 00D0 rcall itoa
|
||||||
|
242 .LVL18:
|
||||||
|
67:libs/serialdebug.c **** dbg_putstring(c);
|
||||||
|
243 .loc 1 67 0
|
||||||
|
244 00c4 CE01 movw r24,r28
|
||||||
|
245 00c6 0196 adiw r24,1
|
||||||
|
246 00c8 00D0 rcall dbg_putstring
|
||||||
|
247 .LVL19:
|
||||||
|
248 /* epilogue start */
|
||||||
|
68:libs/serialdebug.c **** }
|
||||||
|
249 .loc 1 68 0
|
||||||
|
250 00ca 2796 adiw r28,7
|
||||||
|
251 00cc 0FB6 in __tmp_reg__,__SREG__
|
||||||
|
252 00ce F894 cli
|
||||||
|
253 00d0 DEBF out __SP_H__,r29
|
||||||
|
254 00d2 0FBE out __SREG__,__tmp_reg__
|
||||||
|
255 00d4 CDBF out __SP_L__,r28
|
||||||
|
256 00d6 DF91 pop r29
|
||||||
|
257 00d8 CF91 pop r28
|
||||||
|
258 00da 0895 ret
|
||||||
|
259 .cfi_endproc
|
||||||
|
260 .LFE11:
|
||||||
|
262 .local serialdebug_usartout
|
||||||
|
263 .comm serialdebug_usartout,14,1
|
||||||
|
264 .Letext0:
|
||||||
|
265 .file 3 "/usr/local/CrossPack-AVR-20131216/avr/include/stdint.h"
|
||||||
|
266 .file 4 "/usr/local/CrossPack-AVR-20131216/avr/include/stdio.h"
|
||||||
|
267 .file 5 "./libs/serialdebug.h"
|
||||||
|
DEFINED SYMBOLS
|
||||||
|
*ABS*:00000000 serialdebug.c
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:2 *ABS*:0000003e __SP_H__
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:3 *ABS*:0000003d __SP_L__
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:4 *ABS*:0000003f __SREG__
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:5 *ABS*:00000000 __tmp_reg__
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:6 *ABS*:00000001 __zero_reg__
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:12 .text:00000000 usart_putchar
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:98 .text:0000004a serial_configure
|
||||||
|
.bss:00000000 serialdebug_usartout
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:132 .text:0000007e dbg_putstring
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:180 .text:00000098 dbg_putstring_nl
|
||||||
|
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:206 .text:000000a4 dbg_putint
|
||||||
|
|
||||||
|
UNDEFINED SYMBOLS
|
||||||
|
__iob
|
||||||
|
itoa
|
||||||
|
__do_copy_data
|
||||||
|
__do_clear_bss
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
||||||
|
#define SERIALDEBUG_SOFT_TX_BIT 6
|
||||||
|
#define SERIALDEBUG_SOFT_TX_DDR DDRA
|
||||||
|
#define SERIALDEBUG_SOFT_TX_PORT PORTA
|
||||||
|
#define SERIALDEBUG_BAUD 9600
|
||||||
|
#define SERIALDEBUG_STOP_BITS 1
|
||||||
|
#define SERIALDEBUG_MICROSECONDS_OVERHEAD_ADJUST 0
|
||||||
|
#define SERIALDEBUG_MICROSECONDS_PER_BIT ((1000000ul / SERIALDEBUG_BAUD) - SERIALDEBUG_MICROSECONDS_OVERHEAD_ADJUST)
|
||||||
|
#define SERLAILDEBUG_USE_INTRS 1
|
|
@ -0,0 +1,252 @@
|
||||||
|
#define __DEBUG__ 1
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <libs/serialdebug.h>
|
||||||
|
#include <libs/macros.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/sleep.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
// User settings
|
||||||
|
#define HOUR 3600
|
||||||
|
// I wanted each block of time to be 45 mins, but my chip's clock is slow
|
||||||
|
// 40 should roughly scale to 45
|
||||||
|
#define BLOCK_MINS 40
|
||||||
|
// How long to pour for
|
||||||
|
#define DISPENSE_MS 12000
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
vcc [1 14] gnd
|
||||||
|
[2 13] input speed_0
|
||||||
|
[3 12] input speed_1
|
||||||
|
rst [4 11] input speed_2
|
||||||
|
INT/input feed button [5 10] input speed_3
|
||||||
|
motor [6 9]
|
||||||
|
debug serial [7 8]
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Ports
|
||||||
|
|
||||||
|
#define FEED_DDR DDRA
|
||||||
|
#define FEED_PORT PORTA
|
||||||
|
#define FEED_BIT PA7
|
||||||
|
|
||||||
|
#define PWRON_DDR DDRA
|
||||||
|
#define PWRON_PORT PORTA
|
||||||
|
#define PWRON_BIT PA5
|
||||||
|
|
||||||
|
#define FORCE_DDR DDRB
|
||||||
|
#define FORCE_PORT PINB
|
||||||
|
#define FORCE_BIT PB2
|
||||||
|
|
||||||
|
#define NIBBLE0_DDR DDRA
|
||||||
|
#define NIBBLE0_PORT PINA
|
||||||
|
#define NIBBLE0_BIT PA0
|
||||||
|
|
||||||
|
#define NIBBLE1_DDR DDRA
|
||||||
|
#define NIBBLE1_PORT PINA
|
||||||
|
#define NIBBLE1_BIT PA1
|
||||||
|
|
||||||
|
#define NIBBLE2_DDR DDRA
|
||||||
|
#define NIBBLE2_PORT PINA
|
||||||
|
#define NIBBLE2_BIT PA2
|
||||||
|
|
||||||
|
#define NIBBLE3_DDR DDRA
|
||||||
|
#define NIBBLE3_PORT PINA
|
||||||
|
#define NIBBLE3_BIT PA3
|
||||||
|
|
||||||
|
|
||||||
|
void motor_on(void) {
|
||||||
|
// Start turning the motor
|
||||||
|
SET_BIT(FEED_PORT, FEED_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void motor_off(void) {
|
||||||
|
// Stop turning the motor
|
||||||
|
CLEAR_BIT(FEED_PORT, FEED_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispense(int ms) {
|
||||||
|
// Activate motor for X ms
|
||||||
|
motor_on();
|
||||||
|
while(ms > 0) {
|
||||||
|
_delay_ms(15);
|
||||||
|
ms -= 15;
|
||||||
|
}
|
||||||
|
motor_off();
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwr_on(void) {
|
||||||
|
// Enable power to the motor control and input dial
|
||||||
|
SET_BIT(PWRON_PORT, PWRON_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwr_off(void) {
|
||||||
|
// Disable power to the motor control and input dial
|
||||||
|
CLEAR_BIT(PWRON_PORT, PWRON_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define WAKEUP_PULSE 100
|
||||||
|
#define WAKEUP_BETWEEN 75
|
||||||
|
|
||||||
|
void bootpulse(void) {
|
||||||
|
// Pulse the motor quickly
|
||||||
|
motor_on();
|
||||||
|
_delay_ms(WAKEUP_PULSE);
|
||||||
|
motor_off();
|
||||||
|
_delay_ms(WAKEUP_BETWEEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wakeup(void) {
|
||||||
|
// Perform
|
||||||
|
motor_on();
|
||||||
|
for(int i=0;i<6;i++) bootpulse();
|
||||||
|
motor_off();
|
||||||
|
}
|
||||||
|
|
||||||
|
void delay_s(int seconds) {
|
||||||
|
while(seconds-- > 0) {
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
_delay_ms(100);
|
||||||
|
#ifdef __DEBUG__
|
||||||
|
dbg_putstring("Wait...\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_speed() {
|
||||||
|
// Get speed setting, 0-15 from 4 pins
|
||||||
|
uint8_t speed = 0;
|
||||||
|
speed |= (IS_SET(NIBBLE3_PORT,NIBBLE3_BIT));
|
||||||
|
speed |= (IS_SET(NIBBLE2_PORT,NIBBLE2_BIT) << 1);
|
||||||
|
speed |= (IS_SET(NIBBLE1_PORT,NIBBLE1_BIT) << 2);
|
||||||
|
speed |= (IS_SET(NIBBLE0_PORT,NIBBLE0_BIT) << 3);
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// PART 1: setup io pins
|
||||||
|
// Set motor pin as output
|
||||||
|
SET_BIT(FEED_DDR, FEED_BIT);
|
||||||
|
// Set button pin as input
|
||||||
|
CLEAR_BIT(FORCE_DDR, FORCE_BIT);
|
||||||
|
// Set speed control pins as input
|
||||||
|
CLEAR_BIT(NIBBLE0_DDR, NIBBLE0_BIT);
|
||||||
|
CLEAR_BIT(NIBBLE1_DDR, NIBBLE1_BIT);
|
||||||
|
CLEAR_BIT(NIBBLE2_DDR, NIBBLE2_BIT);
|
||||||
|
CLEAR_BIT(NIBBLE3_DDR, NIBBLE3_BIT);
|
||||||
|
|
||||||
|
// PART 2: Set up interupts
|
||||||
|
cli(); //disable global interrupts
|
||||||
|
|
||||||
|
// Set ISC01= 1 and ISC00 = 0 to generate an external interrupt request
|
||||||
|
// on any change of INT0
|
||||||
|
SET_BIT(MCUCR,ISC00);
|
||||||
|
SET_BIT(MCUCR,ISC01);
|
||||||
|
//enable external interrupt request 0
|
||||||
|
SET_BIT(GIMSK,INT0);
|
||||||
|
|
||||||
|
// disable ADC (saves power)
|
||||||
|
ADCSRA = 0;
|
||||||
|
|
||||||
|
// configure sleep mode
|
||||||
|
WDTCSR |= (_BV(WDCE) | _BV(WDE)); // Enable the WD Change Bit
|
||||||
|
WDTCSR = _BV(WDIE) | // Enable WDT Interrupt
|
||||||
|
_BV(WDP1) | _BV(WDP2); // Set Timeout to 1 seconds
|
||||||
|
|
||||||
|
//enable global interrupts
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
|
void gotosleep(void) {
|
||||||
|
// Put the MCU to sleep
|
||||||
|
sleep_bod_disable();
|
||||||
|
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||||
|
sleep_enable();
|
||||||
|
sleep_cpu();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use to track timing
|
||||||
|
long seconds_since_last_spin = 0;
|
||||||
|
|
||||||
|
// watchdog interrupt
|
||||||
|
ISR (WDT_vect) {
|
||||||
|
// break out of sleep mode
|
||||||
|
sleep_disable();
|
||||||
|
// Increment time counter
|
||||||
|
seconds_since_last_spin += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//external interrupt ISR (for INT0 pin)
|
||||||
|
ISR(INT0_vect) {
|
||||||
|
#ifdef __DEBUG__
|
||||||
|
dbg_putstring("AYE MATEY\n");
|
||||||
|
#endif
|
||||||
|
pwr_on();
|
||||||
|
while(IS_SET(FORCE_PORT, FORCE_BIT)) {
|
||||||
|
motor_on();
|
||||||
|
}
|
||||||
|
motor_off();
|
||||||
|
seconds_since_last_spin = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// Reset all pin configs
|
||||||
|
DDRA = 0b00000000;
|
||||||
|
DDRB = 0b00000000;
|
||||||
|
|
||||||
|
#ifdef __DEBUG__
|
||||||
|
serial_configure();
|
||||||
|
dbg_putstring("\n\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Configure the mcu
|
||||||
|
setup();
|
||||||
|
|
||||||
|
// Wiggle so the user knows we're alive
|
||||||
|
pwr_on();
|
||||||
|
wakeup();
|
||||||
|
pwr_off();
|
||||||
|
|
||||||
|
delay_s(1);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (seconds_since_last_spin % 10 == 0) {
|
||||||
|
pwr_on();
|
||||||
|
_delay_ms(1); // Let input pins warm up
|
||||||
|
|
||||||
|
// speed can be 0-15
|
||||||
|
// delay = 2hrs + speed * .75h
|
||||||
|
// range of 1hr to 12hrs25m
|
||||||
|
uint8_t speed = get_speed();
|
||||||
|
long sleep_max = HOUR + (BLOCK_MINS * 60 * speed); // 45 mins per unit of speed
|
||||||
|
|
||||||
|
long to_go = sleep_max - seconds_since_last_spin;
|
||||||
|
|
||||||
|
#ifdef __DEBUG__
|
||||||
|
dbg_putstring("Mins to sleep: ");
|
||||||
|
dbg_putint((unsigned int)sleep_max/60);
|
||||||
|
dbg_putstring("\n");
|
||||||
|
dbg_putstring("Mins to go: ");
|
||||||
|
dbg_putint((unsigned int)to_go/60);
|
||||||
|
dbg_putstring("\n\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If it's been long enough, do the thing
|
||||||
|
if(to_go <= 0) {
|
||||||
|
dispense(DISPENSE_MS);
|
||||||
|
seconds_since_last_spin = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sleep and do it all again tomorrow
|
||||||
|
pwr_off();
|
||||||
|
gotosleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue