1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-22 08:22:04 +03:00

Reworked build system: makefiles replaced with in-program logic; core replaced with targets; preproc/ replaced with Wiring's; now prepend "#include "WProgram.h" instead of wiringlite.inc; new entries in preferences.txt; bundled Wiring libs.

This commit is contained in:
David A. Mellis
2005-09-25 14:11:32 +00:00
parent 10b3f4fe08
commit 7fbb37cbe0
98 changed files with 44948 additions and 18090 deletions

View File

@ -0,0 +1,421 @@
# Hey Emacs, this is a -*- makefile -*-
#
# WinAVR Sample makefile written by Eric B. Weddington, J<>rg Wunsch, et al.
# Released to the Public Domain
# Please read the make user manual!
#
# Additional material for this makefile was submitted by:
# Tim Henigan
# Peter Fleury
# Reiner Patommel
# Sander Pool
# Frederik Rouleau
# Markus Pfaff
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
#
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
# 4.07 or greater).
#
# make program = Download the hex file to the device, using avrdude. Please
# customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#
# MCU name
MCU = atmega8
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = prog
# List C source files here. (C dependencies are automatically generated.)
#SRC = pins_arduino.c wiring.c ../avrlib/uart.c ../avrlib/buffer.c ../avrlib/timer.c ../avrlib/a2d.c $(TARGET).c
#SRC = pins_arduino.c wiring.c ../avrlib/uart.c ../avrlib/buffer.c ../avrlib/timer.c $(TARGET).c
SRC = pins_arduino.c wiring.c ../lib/avrlib/uart.c ../lib/avrlib/buffer.c ../lib/avrlib/timer.c $(TARGET).c
# 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
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS = ../lib/avrlib
# 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
CDEFS = -D F_CPU=16000000L
# Place -I options here
CINCS =
# Compiler flags.
# -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
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
# Assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: 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]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
#Additional libraries.
# 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
PRINTF_LIB =
# 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
SCANF_LIB =
MATH_LIB = -lm
# 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,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
# Linker flags.
# -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 += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
# Programming support using avrdude. Settings and variables.
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = com1 # programmer connected to serial device
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)
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = ../tools/avr
DIRAVRBIN = $(DIRAVR)/bin
# Define programs and commands.
SHELL = sh
CC = ${DIRAVRBIN}/avr-gcc
OBJCOPY = ${DIRAVRBIN}/avr-objcopy
OBJDUMP = ${DIRAVRBIN}/avr-objdump
SIZE = ${DIRAVRBIN}/avr-size
NM = ${DIRAVRBIN}/avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp
# 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:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
#all: begin gccversion sizebefore build sizeafter finished end
all: begin gccversion build finished end
build: elf hex eep lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
# 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)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); 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)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--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 $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) dep/*
# 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

View File

@ -0,0 +1,421 @@
# Hey Emacs, this is a -*- makefile -*-
#
# WinAVR Sample makefile written by Eric B. Weddington, J<>rg Wunsch, et al.
# Released to the Public Domain
# Please read the make user manual!
#
# Additional material for this makefile was submitted by:
# Tim Henigan
# Peter Fleury
# Reiner Patommel
# Sander Pool
# Frederik Rouleau
# Markus Pfaff
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
#
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
# 4.07 or greater).
#
# make program = Download the hex file to the device, using avrdude. Please
# customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#
# MCU name
MCU = atmega8
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = prog
# List C source files here. (C dependencies are automatically generated.)
#SRC = pins_arduino.c wiring.c ../avrlib/uart.c ../avrlib/buffer.c ../avrlib/timer.c ../avrlib/a2d.c $(TARGET).c
#SRC = pins_arduino.c wiring.c ../avrlib/uart.c ../avrlib/buffer.c ../avrlib/timer.c $(TARGET).c
SRC = pins_arduino.c wiring.c ../lib/avrlib/uart.c ../lib/avrlib/buffer.c ../lib/avrlib/timer.c $(TARGET).c
# 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
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS = ../lib/avrlib
# 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
CDEFS = -D F_CPU=16000000L
# Place -I options here
CINCS =
# Compiler flags.
# -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
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
# Assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: 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]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
#Additional libraries.
# 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
PRINTF_LIB =
# 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
SCANF_LIB =
MATH_LIB = -lm
# 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,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
# Linker flags.
# -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 += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
# Programming support using avrdude. Settings and variables.
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = com1 # programmer connected to serial device
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)
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = ..\tools\avr
DIRAVRBIN = $(DIRAVR)\bin
# Define programs and commands.
SHELL = sh
CC = ${DIRAVRBIN}\avr-gcc
OBJCOPY = ${DIRAVRBIN}\avr-objcopy
OBJDUMP = ${DIRAVRBIN}\avr-objdump
SIZE = ${DIRAVRBIN}\avr-size
NM = ${DIRAVRBIN}\avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp
# 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:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
#all: begin gccversion sizebefore build sizeafter finished end
all: begin gccversion build finished end
build: elf hex eep lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
# 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)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); 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)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--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 $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) dep/*
# 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

6
targets/arduino/WProgram.h Executable file
View File

@ -0,0 +1,6 @@
#include <avr/io.h>
#include "wiring.h"
#include <avr/interrupt.h>
#include <avr/signal.h>

77
targets/arduino/avrlibdefs.h Executable file
View File

@ -0,0 +1,77 @@
/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */
//*****************************************************************************
//
// File Name : 'avrlibdefs.h'
// Title : AVRlib global defines and macros include file
// Author : Pascal Stang
// Created : 7/12/2001
// Revised : 9/30/2002
// Version : 1.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Description : This include file is designed to contain items useful to all
// code files and projects, regardless of specific implementation.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef AVRLIBDEFS_H
#define AVRLIBDEFS_H
// Code compatibility to new AVR-libc
// outb(), inb(), BV(), sbi(), cbi(), sei(), cli()
#ifndef outb
#define outb(addr, data) addr = (data)
#endif
#ifndef inb
#define inb(addr) (addr)
#endif
#ifndef BV
#define BV(bit) (1<<(bit))
#endif
#ifndef cbi
#define cbi(reg,bit) reg &= ~(BV(bit))
#endif
#ifndef sbi
#define sbi(reg,bit) reg |= (BV(bit))
#endif
#ifndef cli
#define cli() __asm__ __volatile__ ("cli" ::)
#endif
#ifndef sei
#define sei() __asm__ __volatile__ ("sei" ::)
#endif
// support for individual port pin naming in the mega128
// see port128.h for details
#ifdef __AVR_ATmega128__
// not currently necessary due to inclusion
// of these defines in newest AVR-GCC
// do a quick test to see if include is needed
#ifndef PD0
#include "port128.h"
#endif
#endif
// use this for packed structures
// (this is seldom necessary on an 8-bit architecture like AVR,
// but can assist in code portability to AVR)
#define GNUC_PACKED __attribute__((packed))
// port address helpers
#define DDR(x) ((x)-1) // address of data direction register of port x
#define PIN(x) ((x)-2) // address of input register of port x
// MIN/MAX/ABS macros
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a>b)?(a):(b))
#define ABS(x) ((x>0)?(x):(-x))
// constants
#define PI 3.14159265359
#endif

84
targets/arduino/avrlibtypes.h Executable file
View File

@ -0,0 +1,84 @@
/*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */
//*****************************************************************************
//
// File Name : 'avrlibtypes.h'
// Title : AVRlib global types and typedefines include file
// Author : Pascal Stang
// Created : 7/12/2001
// Revised : 9/30/2002
// Version : 1.0
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Description : Type-defines required and used by AVRlib. Most types are also
// generally useful.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef AVRLIBTYPES_H
#define AVRLIBTYPES_H
#ifndef WIN32
// true/false defines
#define FALSE 0
#define TRUE -1
#endif
// datatype definitions macros
typedef unsigned char u08;
typedef signed char s08;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned long u32;
typedef signed long s32;
typedef unsigned long long u64;
typedef signed long long s64;
/* use inttypes.h instead
// C99 standard integer type definitions
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned long uint64_t;
typedef signed long int64_t;
*/
// maximum value that can be held
// by unsigned data types (8,16,32bits)
#define MAX_U08 255
#define MAX_U16 65535
#define MAX_U32 4294967295
// maximum values that can be held
// by signed data types (8,16,32bits)
#define MIN_S08 -128
#define MAX_S08 127
#define MIN_S16 -32768
#define MAX_S16 32767
#define MIN_S32 -2147483648
#define MAX_S32 2147483647
#ifndef WIN32
// more type redefinitions
typedef unsigned char BOOL;
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
typedef unsigned char UCHAR;
typedef unsigned int UINT;
typedef unsigned short USHORT;
typedef unsigned long ULONG;
typedef char CHAR;
typedef int INT;
typedef long LONG;
#endif
#endif

110
targets/arduino/buffer.c Executable file
View File

@ -0,0 +1,110 @@
/*! \file buffer.c \brief Multipurpose byte buffer structure and methods. */
//*****************************************************************************
//
// File Name : 'buffer.c'
// Title : Multipurpose byte buffer structure and methods
// Author : Pascal Stang - Copyright (C) 2001-2002
// Created : 9/23/2001
// Revised : 9/23/2001
// Version : 1.0
// Target MCU : any
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#include "buffer.h"
// global variables
// initialization
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size)
{
// set start pointer of the buffer
buffer->dataptr = start;
buffer->size = size;
// initialize index and length
buffer->dataindex = 0;
buffer->datalength = 0;
}
// access routines
unsigned char bufferGetFromFront(cBuffer* buffer)
{
unsigned char data = 0;
// check to see if there's data in the buffer
if(buffer->datalength)
{
// get the first character from buffer
data = buffer->dataptr[buffer->dataindex];
// move index down and decrement length
buffer->dataindex++;
if(buffer->dataindex >= buffer->size)
{
buffer->dataindex %= buffer->size;
}
buffer->datalength--;
}
// return
return data;
}
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes)
{
// dump numbytes from the front of the buffer
// are we dumping less than the entire buffer?
if(numbytes < buffer->datalength)
{
// move index down by numbytes and decrement length by numbytes
buffer->dataindex += numbytes;
if(buffer->dataindex >= buffer->size)
{
buffer->dataindex %= buffer->size;
}
buffer->datalength -= numbytes;
}
else
{
// flush the whole buffer
buffer->datalength = 0;
}
}
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index)
{
// return character at index in buffer
return buffer->dataptr[(buffer->dataindex+index)%(buffer->size)];
}
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data)
{
// make sure the buffer has room
if(buffer->datalength < buffer->size)
{
// save data byte at end of buffer
buffer->dataptr[(buffer->dataindex + buffer->datalength) % buffer->size] = data;
// increment the length
buffer->datalength++;
// return success
return -1;
}
else return 0;
}
unsigned char bufferIsNotFull(cBuffer* buffer)
{
// check to see if the buffer has room
// return true if there is room
return (buffer->datalength < buffer->size);
}
void bufferFlush(cBuffer* buffer)
{
// flush contents of the buffer
buffer->datalength = 0;
}

56
targets/arduino/buffer.h Executable file
View File

@ -0,0 +1,56 @@
/*! \file buffer.h \brief Multipurpose byte buffer structure and methods. */
//*****************************************************************************
//
// File Name : 'buffer.h'
// Title : Multipurpose byte buffer structure and methods
// Author : Pascal Stang - Copyright (C) 2001-2002
// Created : 9/23/2001
// Revised : 11/16/2002
// Version : 1.1
// Target MCU : any
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef BUFFER_H
#define BUFFER_H
// structure/typdefs
// the cBuffer structure
typedef struct struct_cBuffer
{
unsigned char *dataptr; // the physical memory address where the buffer is stored
unsigned short size; // the allocated size of the buffer
unsigned short datalength; // the length of the data currently in the buffer
unsigned short dataindex; // the index into the buffer where the data starts
} cBuffer;
// function prototypes
//! initialize a buffer to start at a given address and have given size
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size);
//! get the first byte from the front of the buffer
unsigned char bufferGetFromFront(cBuffer* buffer);
//! dump (discard) the first numbytes from the front of the buffer
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes);
//! get a byte at the specified index in the buffer (kind of like array access)
// ** note: this does not remove the byte that was read from the buffer
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index);
//! add a byte to the end of the buffer
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data);
//! check if the buffer is full/not full (returns non-zero value if not full)
unsigned char bufferIsNotFull(cBuffer* buffer);
//! flush (clear) the contents of the buffer
void bufferFlush(cBuffer* buffer);
#endif

390
targets/arduino/buffer.lst Executable file
View File

@ -0,0 +1,390 @@
1 .file "buffer.c"
2 .arch atmega8
3 __SREG__ = 0x3f
4 __SP_H__ = 0x3e
5 __SP_L__ = 0x3d
6 __tmp_reg__ = 0
7 __zero_reg__ = 1
8 .global __do_copy_data
9 .global __do_clear_bss
12 .text
13 .Ltext0:
44 .global bufferInit
46 bufferInit:
1:../avrlib/buffer.c **** /*! \file buffer.c \brief Multipurpose byte buffer structure and methods. */
2:../avrlib/buffer.c **** //*****************************************************************************
3:../avrlib/buffer.c **** //
4:../avrlib/buffer.c **** // File Name : 'buffer.c'
5:../avrlib/buffer.c **** // Title : Multipurpose byte buffer structure and methods
6:../avrlib/buffer.c **** // Author : Pascal Stang - Copyright (C) 2001-2002
7:../avrlib/buffer.c **** // Created : 9/23/2001
8:../avrlib/buffer.c **** // Revised : 9/23/2001
9:../avrlib/buffer.c **** // Version : 1.0
10:../avrlib/buffer.c **** // Target MCU : any
11:../avrlib/buffer.c **** // Editor Tabs : 4
12:../avrlib/buffer.c **** //
13:../avrlib/buffer.c **** // This code is distributed under the GNU Public License
14:../avrlib/buffer.c **** // which can be found at http://www.gnu.org/licenses/gpl.txt
15:../avrlib/buffer.c **** //
16:../avrlib/buffer.c **** //*****************************************************************************
17:../avrlib/buffer.c ****
18:../avrlib/buffer.c **** #include "buffer.h"
19:../avrlib/buffer.c ****
20:../avrlib/buffer.c **** // global variables
21:../avrlib/buffer.c ****
22:../avrlib/buffer.c **** // initialization
23:../avrlib/buffer.c ****
24:../avrlib/buffer.c **** void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size)
25:../avrlib/buffer.c **** {
48 .LM1:
49 /* prologue: frame size=0 */
50 /* prologue end (size=0) */
51 0000 FC01 movw r30,r24
26:../avrlib/buffer.c **** // set start pointer of the buffer
27:../avrlib/buffer.c **** buffer->dataptr = start;
53 .LM2:
54 0002 6083 st Z,r22
55 0004 7183 std Z+1,r23
28:../avrlib/buffer.c **** buffer->size = size;
57 .LM3:
58 0006 4283 std Z+2,r20
59 0008 5383 std Z+3,r21
29:../avrlib/buffer.c **** // initialize index and length
30:../avrlib/buffer.c **** buffer->dataindex = 0;
61 .LM4:
62 000a 1682 std Z+6,__zero_reg__
63 000c 1782 std Z+7,__zero_reg__
31:../avrlib/buffer.c **** buffer->datalength = 0;
65 .LM5:
66 000e 1482 std Z+4,__zero_reg__
67 0010 1582 std Z+5,__zero_reg__
68 /* epilogue: frame size=0 */
69 0012 0895 ret
70 /* epilogue end (size=1) */
71 /* function bufferInit size 10 (9) */
73 .Lscope0:
77 .global bufferGetFromFront
79 bufferGetFromFront:
32:../avrlib/buffer.c **** }
33:../avrlib/buffer.c ****
34:../avrlib/buffer.c **** // access routines
35:../avrlib/buffer.c **** unsigned char bufferGetFromFront(cBuffer* buffer)
36:../avrlib/buffer.c **** {
81 .LM6:
82 /* prologue: frame size=0 */
83 0014 CF93 push r28
84 0016 DF93 push r29
85 /* prologue end (size=2) */
86 0018 EC01 movw r28,r24
37:../avrlib/buffer.c **** unsigned char data = 0;
88 .LM7:
89 001a E0E0 ldi r30,lo8(0)
38:../avrlib/buffer.c ****
39:../avrlib/buffer.c **** // check to see if there's data in the buffer
40:../avrlib/buffer.c **** if(buffer->datalength)
91 .LM8:
92 001c 2C81 ldd r18,Y+4
93 001e 3D81 ldd r19,Y+5
94 0020 2115 cp r18,__zero_reg__
95 0022 3105 cpc r19,__zero_reg__
96 0024 B1F0 breq .L3
41:../avrlib/buffer.c **** {
42:../avrlib/buffer.c **** // get the first character from buffer
43:../avrlib/buffer.c **** data = buffer->dataptr[buffer->dataindex];
98 .LM9:
99 0026 E881 ld r30,Y
100 0028 F981 ldd r31,Y+1
101 002a 8E81 ldd r24,Y+6
102 002c 9F81 ldd r25,Y+7
103 002e E80F add r30,r24
104 0030 F91F adc r31,r25
105 0032 E081 ld r30,Z
44:../avrlib/buffer.c **** // move index down and decrement length
45:../avrlib/buffer.c **** buffer->dataindex++;
107 .LM10:
108 0034 0196 adiw r24,1
109 0036 8E83 std Y+6,r24
110 0038 9F83 std Y+7,r25
46:../avrlib/buffer.c **** if(buffer->dataindex >= buffer->size)
112 .LM11:
113 003a 6A81 ldd r22,Y+2
114 003c 7B81 ldd r23,Y+3
115 003e 8617 cp r24,r22
116 0040 9707 cpc r25,r23
117 0042 18F0 brlo .L4
47:../avrlib/buffer.c **** {
48:../avrlib/buffer.c **** buffer->dataindex %= buffer->size;
119 .LM12:
120 0044 00D0 rcall __udivmodhi4
121 0046 8E83 std Y+6,r24
122 0048 9F83 std Y+7,r25
123 .L4:
49:../avrlib/buffer.c **** }
50:../avrlib/buffer.c **** buffer->datalength--;
125 .LM13:
126 004a 2150 subi r18,lo8(-(-1))
127 004c 3040 sbci r19,hi8(-(-1))
128 004e 2C83 std Y+4,r18
129 0050 3D83 std Y+5,r19
130 .L3:
51:../avrlib/buffer.c **** }
52:../avrlib/buffer.c **** // return
53:../avrlib/buffer.c **** return data;
54:../avrlib/buffer.c **** }
132 .LM14:
133 0052 8E2F mov r24,r30
134 0054 9927 clr r25
135 /* epilogue: frame size=0 */
136 0056 DF91 pop r29
137 0058 CF91 pop r28
138 005a 0895 ret
139 /* epilogue end (size=3) */
140 /* function bufferGetFromFront size 36 (31) */
145 .Lscope1:
150 .global bufferDumpFromFront
152 bufferDumpFromFront:
55:../avrlib/buffer.c ****
56:../avrlib/buffer.c **** void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes)
57:../avrlib/buffer.c **** {
154 .LM15:
155 /* prologue: frame size=0 */
156 005c CF93 push r28
157 005e DF93 push r29
158 /* prologue end (size=2) */
159 0060 FC01 movw r30,r24
160 0062 EB01 movw r28,r22
58:../avrlib/buffer.c **** // dump numbytes from the front of the buffer
59:../avrlib/buffer.c **** // are we dumping less than the entire buffer?
60:../avrlib/buffer.c **** if(numbytes < buffer->datalength)
162 .LM16:
163 0064 2481 ldd r18,Z+4
164 0066 3581 ldd r19,Z+5
165 0068 6217 cp r22,r18
166 006a 7307 cpc r23,r19
167 006c 98F4 brsh .L6
61:../avrlib/buffer.c **** {
62:../avrlib/buffer.c **** // move index down by numbytes and decrement length by numbytes
63:../avrlib/buffer.c **** buffer->dataindex += numbytes;
169 .LM17:
170 006e 8681 ldd r24,Z+6
171 0070 9781 ldd r25,Z+7
172 0072 860F add r24,r22
173 0074 971F adc r25,r23
174 0076 8683 std Z+6,r24
175 0078 9783 std Z+7,r25
64:../avrlib/buffer.c **** if(buffer->dataindex >= buffer->size)
177 .LM18:
178 007a 6281 ldd r22,Z+2
179 007c 7381 ldd r23,Z+3
180 007e 8617 cp r24,r22
181 0080 9707 cpc r25,r23
182 0082 18F0 brlo .L7
65:../avrlib/buffer.c **** {
66:../avrlib/buffer.c **** buffer->dataindex %= buffer->size;
184 .LM19:
185 0084 00D0 rcall __udivmodhi4
186 0086 8683 std Z+6,r24
187 0088 9783 std Z+7,r25
188 .L7:
67:../avrlib/buffer.c **** }
68:../avrlib/buffer.c **** buffer->datalength -= numbytes;
190 .LM20:
191 008a 2C1B sub r18,r28
192 008c 3D0B sbc r19,r29
193 008e 2483 std Z+4,r18
194 0090 3583 std Z+5,r19
195 0092 02C0 rjmp .L5
196 .L6:
69:../avrlib/buffer.c **** }
70:../avrlib/buffer.c **** else
71:../avrlib/buffer.c **** {
72:../avrlib/buffer.c **** // flush the whole buffer
73:../avrlib/buffer.c **** buffer->datalength = 0;
198 .LM21:
199 0094 1482 std Z+4,__zero_reg__
200 0096 1582 std Z+5,__zero_reg__
201 .L5:
202 /* epilogue: frame size=0 */
203 0098 DF91 pop r29
204 009a CF91 pop r28
205 009c 0895 ret
206 /* epilogue end (size=3) */
207 /* function bufferDumpFromFront size 33 (28) */
209 .Lscope2:
214 .global bufferGetAtIndex
216 bufferGetAtIndex:
74:../avrlib/buffer.c **** }
75:../avrlib/buffer.c **** }
76:../avrlib/buffer.c ****
77:../avrlib/buffer.c **** unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index)
78:../avrlib/buffer.c **** {
218 .LM22:
219 /* prologue: frame size=0 */
220 /* prologue end (size=0) */
221 009e FC01 movw r30,r24
79:../avrlib/buffer.c **** // return character at index in buffer
80:../avrlib/buffer.c **** return buffer->dataptr[(buffer->dataindex+index)%(buffer->size)];
223 .LM23:
224 00a0 8681 ldd r24,Z+6
225 00a2 9781 ldd r25,Z+7
226 00a4 2281 ldd r18,Z+2
227 00a6 3381 ldd r19,Z+3
228 00a8 860F add r24,r22
229 00aa 971F adc r25,r23
230 00ac B901 movw r22,r18
231 00ae 00D0 rcall __udivmodhi4
232 00b0 0190 ld __tmp_reg__,Z+
233 00b2 F081 ld r31,Z
234 00b4 E02D mov r30,__tmp_reg__
235 00b6 E80F add r30,r24
236 00b8 F91F adc r31,r25
237 00ba 8081 ld r24,Z
81:../avrlib/buffer.c **** }
239 .LM24:
240 00bc 9927 clr r25
241 /* epilogue: frame size=0 */
242 00be 0895 ret
243 /* epilogue end (size=1) */
244 /* function bufferGetAtIndex size 17 (16) */
246 .Lscope3:
251 .global bufferAddToEnd
253 bufferAddToEnd:
82:../avrlib/buffer.c ****
83:../avrlib/buffer.c **** unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data)
84:../avrlib/buffer.c **** {
255 .LM25:
256 /* prologue: frame size=0 */
257 00c0 CF93 push r28
258 00c2 DF93 push r29
259 /* prologue end (size=2) */
260 00c4 EC01 movw r28,r24
261 00c6 462F mov r20,r22
85:../avrlib/buffer.c **** // make sure the buffer has room
86:../avrlib/buffer.c **** if(buffer->datalength < buffer->size)
263 .LM26:
264 00c8 2C81 ldd r18,Y+4
265 00ca 3D81 ldd r19,Y+5
266 00cc 6A81 ldd r22,Y+2
267 00ce 7B81 ldd r23,Y+3
268 00d0 2617 cp r18,r22
269 00d2 3707 cpc r19,r23
270 00d4 90F4 brsh .L11
87:../avrlib/buffer.c **** {
88:../avrlib/buffer.c **** // save data byte at end of buffer
89:../avrlib/buffer.c **** buffer->dataptr[(buffer->dataindex + buffer->datalength) % buffer->size] = data;
272 .LM27:
273 00d6 8E81 ldd r24,Y+6
274 00d8 9F81 ldd r25,Y+7
275 00da 820F add r24,r18
276 00dc 931F adc r25,r19
277 00de 00D0 rcall __udivmodhi4
278 00e0 E881 ld r30,Y
279 00e2 F981 ldd r31,Y+1
280 00e4 E80F add r30,r24
281 00e6 F91F adc r31,r25
282 00e8 4083 st Z,r20
90:../avrlib/buffer.c **** // increment the length
91:../avrlib/buffer.c **** buffer->datalength++;
284 .LM28:
285 00ea 8C81 ldd r24,Y+4
286 00ec 9D81 ldd r25,Y+5
287 00ee 0196 adiw r24,1
288 00f0 8C83 std Y+4,r24
289 00f2 9D83 std Y+5,r25
92:../avrlib/buffer.c **** // return success
93:../avrlib/buffer.c **** return -1;
291 .LM29:
292 00f4 8FEF ldi r24,lo8(255)
293 00f6 90E0 ldi r25,hi8(255)
294 00f8 02C0 rjmp .L10
295 .L11:
94:../avrlib/buffer.c **** }
95:../avrlib/buffer.c **** else return 0;
297 .LM30:
298 00fa 80E0 ldi r24,lo8(0)
299 00fc 90E0 ldi r25,hi8(0)
300 .L10:
301 /* epilogue: frame size=0 */
302 00fe DF91 pop r29
303 0100 CF91 pop r28
304 0102 0895 ret
305 /* epilogue end (size=3) */
306 /* function bufferAddToEnd size 34 (29) */
308 .Lscope4:
312 .global bufferIsNotFull
314 bufferIsNotFull:
96:../avrlib/buffer.c **** }
97:../avrlib/buffer.c ****
98:../avrlib/buffer.c **** unsigned char bufferIsNotFull(cBuffer* buffer)
99:../avrlib/buffer.c **** {
316 .LM31:
317 /* prologue: frame size=0 */
318 /* prologue end (size=0) */
319 0104 FC01 movw r30,r24
100:../avrlib/buffer.c **** // check to see if the buffer has room
101:../avrlib/buffer.c **** // return true if there is room
102:../avrlib/buffer.c **** return (buffer->datalength < buffer->size);
321 .LM32:
322 0106 40E0 ldi r20,lo8(0)
323 0108 50E0 ldi r21,hi8(0)
324 010a 2481 ldd r18,Z+4
325 010c 3581 ldd r19,Z+5
326 010e 8281 ldd r24,Z+2
327 0110 9381 ldd r25,Z+3
328 0112 2817 cp r18,r24
329 0114 3907 cpc r19,r25
330 0116 10F4 brsh .L14
332 .LM33:
333 0118 41E0 ldi r20,lo8(1)
334 011a 50E0 ldi r21,hi8(1)
335 .L14:
103:../avrlib/buffer.c **** }
337 .LM34:
338 011c CA01 movw r24,r20
339 /* epilogue: frame size=0 */
340 011e 0895 ret
341 /* epilogue end (size=1) */
342 /* function bufferIsNotFull size 14 (13) */
344 .Lscope5:
348 .global bufferFlush
350 bufferFlush:
104:../avrlib/buffer.c ****
105:../avrlib/buffer.c **** void bufferFlush(cBuffer* buffer)
106:../avrlib/buffer.c **** {
352 .LM35:
353 /* prologue: frame size=0 */
354 /* prologue end (size=0) */
107:../avrlib/buffer.c **** // flush contents of the buffer
108:../avrlib/buffer.c **** buffer->datalength = 0;
356 .LM36:
357 0120 FC01 movw r30,r24
358 0122 1482 std Z+4,__zero_reg__
359 0124 1582 std Z+5,__zero_reg__
360 /* epilogue: frame size=0 */
361 0126 0895 ret
362 /* epilogue end (size=1) */
363 /* function bufferFlush size 4 (3) */
365 .Lscope6:
367 .text
369 Letext:
370 /* File "../avrlib/buffer.c": code 148 = 0x0094 ( 129), prologues 6, epilogues 13 */
DEFINED SYMBOLS
*ABS*:00000000 buffer.c
*ABS*:0000003f __SREG__
*ABS*:0000003e __SP_H__
*ABS*:0000003d __SP_L__
*ABS*:00000000 __tmp_reg__
*ABS*:00000001 __zero_reg__
/var/tmp//ccWNR2QI.s:46 .text:00000000 bufferInit
/var/tmp//ccWNR2QI.s:79 .text:00000014 bufferGetFromFront
/var/tmp//ccWNR2QI.s:152 .text:0000005c bufferDumpFromFront
/var/tmp//ccWNR2QI.s:216 .text:0000009e bufferGetAtIndex
/var/tmp//ccWNR2QI.s:253 .text:000000c0 bufferAddToEnd
/var/tmp//ccWNR2QI.s:314 .text:00000104 bufferIsNotFull
/var/tmp//ccWNR2QI.s:350 .text:00000120 bufferFlush
/var/tmp//ccWNR2QI.s:369 .text:00000128 Letext
UNDEFINED SYMBOLS
__do_copy_data
__do_clear_bss
__udivmodhi4

40
targets/arduino/global.h Executable file
View File

@ -0,0 +1,40 @@
/*! \file global.h \brief AVRlib project global include. */
//*****************************************************************************
//
// File Name : 'global.h'
// Title : AVRlib project global include
// Author : Pascal Stang - Copyright (C) 2001-2002
// Created : 7/12/2001
// Revised : 9/30/2002
// Version : 1.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Description : This include file is designed to contain items useful to all
// code files and projects.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef GLOBAL_H
#define GLOBAL_H
// global AVRLIB defines
#include "avrlibdefs.h"
// global AVRLIB types definitions
#include "avrlibtypes.h"
// project/system dependent defines
// CPU clock speed
//#define F_CPU 16000000 // 16MHz processor
//#define F_CPU 14745000 // 14.745MHz processor
//#define F_CPU 8000000 // 8MHz processor
//#define F_CPU 7372800 // 7.37MHz processor
//#define F_CPU 4000000 // 4MHz processor
//#define F_CPU 3686400 // 3.69MHz processor
#define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond
#endif

137
targets/arduino/pins_arduino.c Executable file
View File

@ -0,0 +1,137 @@
/*
pins_arduino.c - pin definitions for the Arduino board
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: pins_arduino.c,v 1.4 2005/05/24 17:47:41 mellis Exp $
*/
#include <avr/io.h>
#include "wiring.h"
// On the Arduino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA8 / ARDUINO
//
// +-\/-+
// PC6 1| |28 PC5 (AI 0)
// (D 0) PD0 2| |27 PC4 (AI 1)
// (D 1) PD1 3| |26 PC3 (AI 2)
// (D 2) PD2 4| |25 PC2 (AI 3)
// (D 3) PD3 5| |24 PC1 (AI 4)
// (D 4) PD4 6| |23 PC0 (AI 5)
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5 (D 13)
// (D 5) PD5 11| |18 PB4 (D 12)
// (D 6) PD6 12| |17 PB3 (D 11)
// (D 7) PD7 13| |16 PB2 (D 10)
// (D 8) PB0 14| |15 PB1 (D 9)
// +----+
#define NUM_DIGITAL_PINS 14
#define NUM_ANALOG_OUT_PINS 11
#define NUM_ANALOG_IN_PINS 6
#define NUM_PORTS 4
#define PB 2
#define PC 3
#define PD 4
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
int port_to_mode[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(DDRB),
_SFR_IO_ADDR(DDRC),
_SFR_IO_ADDR(DDRD),
};
int port_to_output[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PORTB),
_SFR_IO_ADDR(PORTC),
_SFR_IO_ADDR(PORTD),
};
int port_to_input[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PINB),
_SFR_IO_ADDR(PINC),
_SFR_IO_ADDR(PIND),
};
// these arrays map the pin numbers on the arduino
// board to the atmega8 port and pin numbers
pin_t digital_pin_to_port_array[NUM_DIGITAL_PINS] = {
{ PD, 0 },
{ PD, 1 },
{ PD, 2 },
{ PD, 3 },
{ PD, 4 },
{ PD, 5 },
{ PD, 6 },
{ PD, 7 },
{ PB, 0 },
{ PB, 1 },
{ PB, 2 },
{ PB, 3 },
{ PB, 4 },
{ PB, 5 },
};
pin_t *digital_pin_to_port = digital_pin_to_port_array;
// Some of the digital pins also support hardware PWM (analog output).
pin_t analog_out_pin_to_port_array[NUM_DIGITAL_PINS] = {
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ PB, 1 },
{ PB, 2 },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
};
pin_t *analog_out_pin_to_port = analog_out_pin_to_port_array;
pin_t analog_in_pin_to_port_array[NUM_ANALOG_IN_PINS] = {
{ PC, 5 },
{ PC, 4 },
{ PC, 3 },
{ PC, 2 },
{ PC, 1 },
{ PC, 0 },
};
pin_t *analog_in_pin_to_port = analog_in_pin_to_port_array;

135
targets/arduino/rprintf.h Executable file
View File

@ -0,0 +1,135 @@
/*! \file rprintf.h \brief printf routine and associated routines. */
//****************************************************************************
//
// File Name : 'rprintf.h'
// Title : printf routine and associated routines
// Author : Pascal Stang - Copyright (C) 2000-2002
// Created : 2000.12.26
// Revised : 2003.5.1
// Version : 1.0
// Target MCU : Atmel AVR series and other targets
// Editor Tabs : 4
//
// NOTE: This code is currently below version 1.0, and therefore is considered
// to be lacking in some functionality or documentation, or may not be fully
// tested. Nonetheless, you can expect most functions to work.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//****************************************************************************
#ifndef RPRINTF_H
#define RPRINTF_H
// needed for use of PSTR below
#include <avr/pgmspace.h>
// configuration
// defining RPRINTF_SIMPLE will compile a smaller, simpler, and faster printf() function
// defining RPRINTF_COMPLEX will compile a larger, more capable, and slower printf() function
#ifndef RPRINTF_COMPLEX
#define RPRINTF_SIMPLE
#endif
// Define RPRINTF_FLOAT to enable the floating-point printf function: rprintfFloat()
// (adds +4600bytes or 2.2Kwords of code)
// defines/constants
#define STRING_IN_RAM 0
#define STRING_IN_ROM 1
// make a putchar for those that are used to using it
//#define putchar(c) rprintfChar(c);
// functions
//! initializes the rprintf library for an output stream
// you must call this initializer once before using any other rprintf function
// the argument must be a single-character stream output function
void rprintfInit(void (*putchar_func)(unsigned char c));
//! prints a single character to the current output device
void rprintfChar(unsigned char c);
//! prints a null-terminated string stored in RAM
void rprintfStr(char str[]);
//! prints a section of a string stored in RAM
// begins printing at position indicated by <start>
// prints number of characters indicated by <len>
void rprintfStrLen(char str[], unsigned int start, unsigned int len);
//! prints a string stored in program rom
// NOTE: this function does not actually store your string in
// program rom, but merely reads it assuming you stored it properly.
void rprintfProgStr(const prog_char str[]);
// Using the function rprintfProgStrM(...) automatically causes
// your string to be stored in ROM, thereby not wasting precious RAM
// Example usage:
// rprintfProgStrM("Hello, this string is stored in program rom");
#define rprintfProgStrM(string) (rprintfProgStr(PSTR(string)))
//! prints a carriage return and line feed
// useful when printing to serial ports/terminals
void rprintfCRLF(void);
// prints the number contained in "data" in hex format
// u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively
void rprintfu04(unsigned char data); ///< print 4-bit hex number
void rprintfu08(unsigned char data); ///< print 8-bit hex number
void rprintfu16(unsigned short data); ///< print 16-bit hex number
void rprintfu32(unsigned long data); ///< print 32-bit hex number
//! a flexible integer number printing routine
void rprintfNum(char base, char numDigits, char isSigned, char padchar, long n);
#ifdef RPRINTF_FLOAT
//! floating-point print routine
void rprintfFloat(char numDigits, double x);
#endif
// NOTE: Below you'll see the function prototypes of rprintf1RamRom and
// rprintf2RamRom. rprintf1RamRom and rprintf2RamRom are both reduced versions
// of the regular C printf() command. However, they are modified to be able
// to read their text/format strings from RAM or ROM in the Atmel microprocessors.
// Unless you really intend to, do not use the "RamRom" versions of the functions
// directly. Instead use the #defined function versions:
//
// printfx("text/format",args) ...to keep your text/format string stored in RAM
// - or -
// printfxROM("text/format",args) ...to keep your text/format string stored in ROM
//
// where x is either 1 or 2 for the simple or more powerful version of printf()
//
// Since there is much more ROM than RAM available in the Atmel microprocessors,
// and nearly all text/format strings are constant (never change in the course
// of the program), you should try to use the ROM printf version exclusively.
// This will ensure you leave as much RAM as possible for program variables and
// data.
#ifdef RPRINTF_SIMPLE
// a simple printf routine
int rprintf1RamRom(unsigned char stringInRom, const char *format, ...);
// #defines for RAM or ROM operation
#define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)
#define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args)
// *** Default rprintf(...) ***
// this next line determines what the the basic rprintf() defaults to:
#define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)
#endif
#ifdef RPRINTF_COMPLEX
// a more powerful printf routine
int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...);
// #defines for RAM or ROM operation
#define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args)
#define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args)
// *** Default rprintf(...) ***
// this next line determines what the the basic rprintf() defaults to:
#define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args)
#endif
#endif

472
targets/arduino/timer.c Executable file
View File

@ -0,0 +1,472 @@
/*! \file timer.c \brief System Timer function library. */
//*****************************************************************************
//
// File Name : 'timer.c'
// Title : System Timer function library
// Author : Pascal Stang - Copyright (C) 2000-2002
// Created : 11/22/2000
// Revised : 07/09/2003
// Version : 1.1
// Target MCU : Atmel AVR Series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef WIN32
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>
#endif
#include "global.h"
#include "timer.h"
#include "rprintf.h"
// Program ROM constants
// the prescale division values stored in order of timer control register index
// STOP, CLK, CLK/8, CLK/64, CLK/256, CLK/1024
unsigned short __attribute__ ((progmem)) TimerPrescaleFactor[] = {0,1,8,64,256,1024};
// the prescale division values stored in order of timer control register index
// STOP, CLK, CLK/8, CLK/32, CLK/64, CLK/128, CLK/256, CLK/1024
unsigned short __attribute__ ((progmem)) TimerRTCPrescaleFactor[] = {0,1,8,32,64,128,256,1024};
// Global variables
// time registers
volatile unsigned long TimerPauseReg;
volatile unsigned long Timer0Reg0;
volatile unsigned long Timer2Reg0;
typedef void (*voidFuncPtr)(void);
volatile static voidFuncPtr TimerIntFunc[TIMER_NUM_INTERRUPTS];
// delay for a minimum of <us> microseconds
// the time resolution is dependent on the time the loop takes
// e.g. with 4Mhz and 5 cycles per loop, the resolution is 1.25 us
void delay_us(unsigned short time_us)
{
unsigned short delay_loops;
register unsigned short i;
delay_loops = (time_us+3)/5*CYCLES_PER_US; // +3 for rounding up (dirty)
// one loop takes 5 cpu cycles
for (i=0; i < delay_loops; i++) {};
}
/*
void delay_ms(unsigned char time_ms)
{
unsigned short delay_count = F_CPU / 4000;
unsigned short cnt;
asm volatile ("\n"
"L_dl1%=:\n\t"
"mov %A0, %A2\n\t"
"mov %B0, %B2\n"
"L_dl2%=:\n\t"
"sbiw %A0, 1\n\t"
"brne L_dl2%=\n\t"
"dec %1\n\t" "brne L_dl1%=\n\t":"=&w" (cnt)
:"r"(time_ms), "r"((unsigned short) (delay_count))
);
}
*/
void timerInit(void)
{
u08 intNum;
// detach all user functions from interrupts
for(intNum=0; intNum<TIMER_NUM_INTERRUPTS; intNum++)
timerDetach(intNum);
// initialize all timers
timer0Init();
timer1Init();
#ifdef TCNT2 // support timer2 only if it exists
timer2Init();
#endif
// enable interrupts
sei();
}
void timer0Init()
{
// initialize timer 0
timer0SetPrescaler( TIMER0PRESCALE ); // set prescaler
outb(TCNT0, 0); // reset TCNT0
sbi(TIMSK, TOIE0); // enable TCNT0 overflow interrupt
timer0ClearOverflowCount(); // initialize time registers
}
void timer1Init(void)
{
// initialize timer 1
timer1SetPrescaler( TIMER1PRESCALE ); // set prescaler
outb(TCNT1H, 0); // reset TCNT1
outb(TCNT1L, 0);
sbi(TIMSK, TOIE1); // enable TCNT1 overflow
}
#ifdef TCNT2 // support timer2 only if it exists
void timer2Init(void)
{
// initialize timer 2
timer2SetPrescaler( TIMER2PRESCALE ); // set prescaler
outb(TCNT2, 0); // reset TCNT2
sbi(TIMSK, TOIE2); // enable TCNT2 overflow
timer2ClearOverflowCount(); // initialize time registers
}
#endif
void timer0SetPrescaler(u08 prescale)
{
// set prescaler on timer 0
outb(TCCR0, (inb(TCCR0) & ~TIMER_PRESCALE_MASK) | prescale);
}
void timer1SetPrescaler(u08 prescale)
{
// set prescaler on timer 1
outb(TCCR1B, (inb(TCCR1B) & ~TIMER_PRESCALE_MASK) | prescale);
}
#ifdef TCNT2 // support timer2 only if it exists
void timer2SetPrescaler(u08 prescale)
{
// set prescaler on timer 2
outb(TCCR2, (inb(TCCR2) & ~TIMER_PRESCALE_MASK) | prescale);
}
#endif
u16 timer0GetPrescaler(void)
{
// get the current prescaler setting
return (pgm_read_word(TimerPrescaleFactor+(inb(TCCR0) & TIMER_PRESCALE_MASK)));
}
u16 timer1GetPrescaler(void)
{
// get the current prescaler setting
return (pgm_read_word(TimerPrescaleFactor+(inb(TCCR1B) & TIMER_PRESCALE_MASK)));
}
#ifdef TCNT2 // support timer2 only if it exists
u16 timer2GetPrescaler(void)
{
//TODO: can we assume for all 3-timer AVR processors,
// that timer2 is the RTC timer?
// get the current prescaler setting
return (pgm_read_word(TimerRTCPrescaleFactor+(inb(TCCR2) & TIMER_PRESCALE_MASK)));
}
#endif
void timerAttach(u08 interruptNum, void (*userFunc)(void) )
{
// make sure the interrupt number is within bounds
if(interruptNum < TIMER_NUM_INTERRUPTS)
{
// set the interrupt function to run
// the supplied user's function
TimerIntFunc[interruptNum] = userFunc;
}
}
void timerDetach(u08 interruptNum)
{
// make sure the interrupt number is within bounds
if(interruptNum < TIMER_NUM_INTERRUPTS)
{
// set the interrupt function to run nothing
TimerIntFunc[interruptNum] = 0;
}
}
/*
u32 timerMsToTics(u16 ms)
{
// calculate the prescaler division rate
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)));
// calculate the number of timer tics in x milliseconds
return (ms*(F_CPU/(prescaleDiv*256)))/1000;
}
u16 timerTicsToMs(u32 tics)
{
// calculate the prescaler division rate
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)));
// calculate the number of milliseconds in x timer tics
return (tics*1000*(prescaleDiv*256))/F_CPU;
}
*/
void timerPause(unsigned short pause_ms)
{
// pauses for exactly <pause_ms> number of milliseconds
u08 timerThres;
u32 ticRateHz;
u32 pause;
// capture current pause timer value
timerThres = inb(TCNT0);
// reset pause timer overflow count
TimerPauseReg = 0;
// calculate delay for [pause_ms] milliseconds
// prescaler division = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)))
ticRateHz = F_CPU/timer0GetPrescaler();
// precision management
// prevent overflow and precision underflow
// -could add more conditions to improve accuracy
if( ((ticRateHz < 429497) && (pause_ms <= 10000)) )
pause = (pause_ms*ticRateHz)/1000;
else
pause = pause_ms*(ticRateHz/1000);
// loop until time expires
while( ((TimerPauseReg<<8) | inb(TCNT0)) < (pause+timerThres) )
{
if( TimerPauseReg < (pause>>8));
{
// save power by idling the processor
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
}
/* old inaccurate code, for reference
// calculate delay for [pause_ms] milliseconds
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)));
u32 pause = (pause_ms*(F_CPU/(prescaleDiv*256)))/1000;
TimerPauseReg = 0;
while(TimerPauseReg < pause);
*/
}
void timer0ClearOverflowCount(void)
{
// clear the timer overflow counter registers
Timer0Reg0 = 0; // initialize time registers
}
long timer0GetOverflowCount(void)
{
// return the current timer overflow count
// (this is since the last timer0ClearOverflowCount() command was called)
return Timer0Reg0;
}
#ifdef TCNT2 // support timer2 only if it exists
void timer2ClearOverflowCount(void)
{
// clear the timer overflow counter registers
Timer2Reg0 = 0; // initialize time registers
}
long timer2GetOverflowCount(void)
{
// return the current timer overflow count
// (this is since the last timer2ClearOverflowCount() command was called)
return Timer2Reg0;
}
#endif
void timer1PWMInit(u08 bitRes)
{
// configures timer1 for use with PWM output
// on OC1A and OC1B pins
// enable timer1 as 8,9,10bit PWM
if(bitRes == 9)
{ // 9bit mode
sbi(TCCR1A,PWM11);
cbi(TCCR1A,PWM10);
}
else if( bitRes == 10 )
{ // 10bit mode
sbi(TCCR1A,PWM11);
sbi(TCCR1A,PWM10);
}
else
{ // default 8bit mode
cbi(TCCR1A,PWM11);
sbi(TCCR1A,PWM10);
}
// clear output compare value A
outb(OCR1AH, 0);
outb(OCR1AL, 0);
// clear output compare value B
outb(OCR1BH, 0);
outb(OCR1BL, 0);
}
#ifdef WGM10
// include support for arbitrary top-count PWM
// on new AVR processors that support it
void timer1PWMInitICR(u16 topcount)
{
// set PWM mode with ICR top-count
cbi(TCCR1A,WGM10);
sbi(TCCR1A,WGM11);
sbi(TCCR1B,WGM12);
sbi(TCCR1B,WGM13);
// set top count value
ICR1 = topcount;
// clear output compare value A
OCR1A = 0;
// clear output compare value B
OCR1B = 0;
}
#endif
void timer1PWMOff(void)
{
// turn off timer1 PWM mode
cbi(TCCR1A,PWM11);
cbi(TCCR1A,PWM10);
// set PWM1A/B (OutputCompare action) to none
timer1PWMAOff();
timer1PWMBOff();
}
void timer1PWMAOn(void)
{
// turn on channel A (OC1A) PWM output
// set OC1A as non-inverted PWM
sbi(TCCR1A,COM1A1);
cbi(TCCR1A,COM1A0);
}
void timer1PWMBOn(void)
{
// turn on channel B (OC1B) PWM output
// set OC1B as non-inverted PWM
sbi(TCCR1A,COM1B1);
cbi(TCCR1A,COM1B0);
}
void timer1PWMAOff(void)
{
// turn off channel A (OC1A) PWM output
// set OC1A (OutputCompare action) to none
cbi(TCCR1A,COM1A1);
cbi(TCCR1A,COM1A0);
}
void timer1PWMBOff(void)
{
// turn off channel B (OC1B) PWM output
// set OC1B (OutputCompare action) to none
cbi(TCCR1A,COM1B1);
cbi(TCCR1A,COM1B0);
}
void timer1PWMASet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel A
// this PWM output is generated on OC1A pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
//outp( (pwmDuty>>8), OCR1AH); // set the high 8bits of OCR1A
//outp( (pwmDuty&0x00FF), OCR1AL); // set the low 8bits of OCR1A
OCR1A = pwmDuty;
}
void timer1PWMBSet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel B
// this PWM output is generated on OC1B pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
//outp( (pwmDuty>>8), OCR1BH); // set the high 8bits of OCR1B
//outp( (pwmDuty&0x00FF), OCR1BL); // set the low 8bits of OCR1B
OCR1B = pwmDuty;
}
//! Interrupt handler for tcnt0 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW0)
{
Timer0Reg0++; // increment low-order counter
// increment pause counter
TimerPauseReg++;
// if a user function is defined, execute it too
if(TimerIntFunc[TIMER0OVERFLOW_INT])
TimerIntFunc[TIMER0OVERFLOW_INT]();
}
//! Interrupt handler for tcnt1 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW1)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OVERFLOW_INT])
TimerIntFunc[TIMER1OVERFLOW_INT]();
}
#ifdef TCNT2 // support timer2 only if it exists
//! Interrupt handler for tcnt2 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW2)
{
Timer2Reg0++; // increment low-order counter
// if a user function is defined, execute it
if(TimerIntFunc[TIMER2OVERFLOW_INT])
TimerIntFunc[TIMER2OVERFLOW_INT]();
}
#endif
#ifdef OCR0
// include support for Output Compare 0 for new AVR processors that support it
//! Interrupt handler for OutputCompare0 match (OC0) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE0)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER0OUTCOMPARE_INT])
TimerIntFunc[TIMER0OUTCOMPARE_INT]();
}
#endif
//! Interrupt handler for CutputCompare1A match (OC1A) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1A)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OUTCOMPAREA_INT])
TimerIntFunc[TIMER1OUTCOMPAREA_INT]();
}
//! Interrupt handler for OutputCompare1B match (OC1B) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1B)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OUTCOMPAREB_INT])
TimerIntFunc[TIMER1OUTCOMPAREB_INT]();
}
//! Interrupt handler for InputCapture1 (IC1) interrupt
TIMER_INTERRUPT_HANDLER(SIG_INPUT_CAPTURE1)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1INPUTCAPTURE_INT])
TimerIntFunc[TIMER1INPUTCAPTURE_INT]();
}
//! Interrupt handler for OutputCompare2 match (OC2) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE2)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER2OUTCOMPARE_INT])
TimerIntFunc[TIMER2OUTCOMPARE_INT]();
}

278
targets/arduino/timer.h Executable file
View File

@ -0,0 +1,278 @@
/*! \file timer.h \brief System Timer function library. */
//*****************************************************************************
//
// File Name : 'timer.h'
// Title : System Timer function library
// Author : Pascal Stang - Copyright (C) 2000-2002
// Created : 11/22/2000
// Revised : 02/10/2003
// Version : 1.1
// Target MCU : Atmel AVR Series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//
// Notes: The Atmel AVR Series Processors each contain at least one
// hardware timer/counter. Many of the processors contain 2 or 3
// timers. Generally speaking, a timer is a hardware counter inside
// the processor which counts at a rate related to the main CPU clock
// frequency. Because the counter value increasing (counting up) at
// a precise rate, we can use it as a timer to create or measure
// precise delays, schedule events, or generate signals of a certain
// frequency or pulse-width.
// As an example, the ATmega163 processor has 3 timer/counters.
// Timer0, Timer1, and Timer2 are 8, 16, and 8 bits wide respectively.
// This means that they overflow, or roll over back to zero, at a
// count value of 256 for 8bits or 65536 for 16bits. A prescaler is
// avaiable for each timer, and the prescaler allows you to pre-divide
// the main CPU clock rate down to a slower speed before feeding it to
// the counting input of a timer. For example, if the CPU clock
// frequency is 3.69MHz, and Timer0's prescaler is set to divide-by-8,
// then Timer0 will "tic" at 3690000/8 = 461250Hz. Because Timer0 is
// an 8bit timer, it will count to 256 in just 256/461250Hz = 0.555ms.
// In fact, when it hits 255, it will overflow and start again at
// zero. In this case, Timer0 will overflow 461250/256 = 1801.76
// times per second.
// Timer0 can be used a number of ways simultaneously. First, the
// value of the timer can be read by accessing the CPU register TCNT0.
// We could, for example, figure out how long it takes to execute a
// C command by recording the value of TCNT0 before and after
// execution, then subtract (after-before) = time elapsed. Or we can
// enable the overflow interrupt which goes off every time T0
// overflows and count out longer delays (multiple overflows), or
// execute a special periodic function at every overflow.
// The other timers (Timer1 and Timer2) offer all the abilities of
// Timer0 and many more features. Both T1 and T2 can operate as
// general-purpose timers, but T1 has special hardware allowing it to
// generate PWM signals, while T2 is specially designed to help count
// out real time (like hours, minutes, seconds). See the
// Timer/Counter section of the processor datasheet for more info.
//
//*****************************************************************************
#ifndef TIMER_H
#define TIMER_H
#include "global.h"
// constants/macros/typdefs
// processor compatibility fixes
#ifdef __AVR_ATmega323__
// redefinition for the Mega323
#define CTC1 CTC10
#endif
#ifndef PWM10
// mega128 PWM bits
#define PWM10 WGM10
#define PWM11 WGM11
#endif
// Timer/clock prescaler values and timer overflow rates
// tics = rate at which the timer counts up
// 8bitoverflow = rate at which the timer overflows 8bits (or reaches 256)
// 16bit [overflow] = rate at which the timer overflows 16bits (65536)
//
// overflows can be used to generate periodic interrupts
//
// for 8MHz crystal
// 0 = STOP (Timer not counting)
// 1 = CLOCK tics= 8MHz 8bitoverflow= 31250Hz 16bit= 122.070Hz
// 2 = CLOCK/8 tics= 1MHz 8bitoverflow= 3906.25Hz 16bit= 15.259Hz
// 3 = CLOCK/64 tics= 125kHz 8bitoverflow= 488.28Hz 16bit= 1.907Hz
// 4 = CLOCK/256 tics= 31250Hz 8bitoverflow= 122.07Hz 16bit= 0.477Hz
// 5 = CLOCK/1024 tics= 7812.5Hz 8bitoverflow= 30.52Hz 16bit= 0.119Hz
// 6 = External Clock on T(x) pin (falling edge)
// 7 = External Clock on T(x) pin (rising edge)
// for 4MHz crystal
// 0 = STOP (Timer not counting)
// 1 = CLOCK tics= 4MHz 8bitoverflow= 15625Hz 16bit= 61.035Hz
// 2 = CLOCK/8 tics= 500kHz 8bitoverflow= 1953.125Hz 16bit= 7.629Hz
// 3 = CLOCK/64 tics= 62500Hz 8bitoverflow= 244.141Hz 16bit= 0.954Hz
// 4 = CLOCK/256 tics= 15625Hz 8bitoverflow= 61.035Hz 16bit= 0.238Hz
// 5 = CLOCK/1024 tics= 3906.25Hz 8bitoverflow= 15.259Hz 16bit= 0.060Hz
// 6 = External Clock on T(x) pin (falling edge)
// 7 = External Clock on T(x) pin (rising edge)
// for 3.69MHz crystal
// 0 = STOP (Timer not counting)
// 1 = CLOCK tics= 3.69MHz 8bitoverflow= 14414Hz 16bit= 56.304Hz
// 2 = CLOCK/8 tics= 461250Hz 8bitoverflow= 1801.758Hz 16bit= 7.038Hz
// 3 = CLOCK/64 tics= 57625.25Hz 8bitoverflow= 225.220Hz 16bit= 0.880Hz
// 4 = CLOCK/256 tics= 14414.063Hz 8bitoverflow= 56.305Hz 16bit= 0.220Hz
// 5 = CLOCK/1024 tics= 3603.516Hz 8bitoverflow= 14.076Hz 16bit= 0.055Hz
// 6 = External Clock on T(x) pin (falling edge)
// 7 = External Clock on T(x) pin (rising edge)
// for 32.768KHz crystal on timer 2 (use for real-time clock)
// 0 = STOP
// 1 = CLOCK tics= 32.768kHz 8bitoverflow= 128Hz
// 2 = CLOCK/8 tics= 4096kHz 8bitoverflow= 16Hz
// 3 = CLOCK/32 tics= 1024kHz 8bitoverflow= 4Hz
// 4 = CLOCK/64 tics= 512Hz 8bitoverflow= 2Hz
// 5 = CLOCK/128 tics= 256Hz 8bitoverflow= 1Hz
// 6 = CLOCK/256 tics= 128Hz 8bitoverflow= 0.5Hz
// 7 = CLOCK/1024 tics= 32Hz 8bitoverflow= 0.125Hz
#define TIMER_CLK_STOP 0x00 ///< Timer Stopped
#define TIMER_CLK_DIV1 0x01 ///< Timer clocked at F_CPU
#define TIMER_CLK_DIV8 0x02 ///< Timer clocked at F_CPU/8
#define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64
#define TIMER_CLK_DIV256 0x04 ///< Timer clocked at F_CPU/256
#define TIMER_CLK_DIV1024 0x05 ///< Timer clocked at F_CPU/1024
#define TIMER_CLK_T_FALL 0x06 ///< Timer clocked at T falling edge
#define TIMER_CLK_T_RISE 0x07 ///< Timer clocked at T rising edge
#define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask
#define TIMERRTC_CLK_STOP 0x00 ///< RTC Timer Stopped
#define TIMERRTC_CLK_DIV1 0x01 ///< RTC Timer clocked at F_CPU
#define TIMERRTC_CLK_DIV8 0x02 ///< RTC Timer clocked at F_CPU/8
#define TIMERRTC_CLK_DIV32 0x03 ///< RTC Timer clocked at F_CPU/32
#define TIMERRTC_CLK_DIV64 0x04 ///< RTC Timer clocked at F_CPU/64
#define TIMERRTC_CLK_DIV128 0x05 ///< RTC Timer clocked at F_CPU/128
#define TIMERRTC_CLK_DIV256 0x06 ///< RTC Timer clocked at F_CPU/256
#define TIMERRTC_CLK_DIV1024 0x07 ///< RTC Timer clocked at F_CPU/1024
#define TIMERRTC_PRESCALE_MASK 0x07 ///< RTC Timer Prescaler Bit-Mask
// default prescale settings for the timers
// these settings are applied when you call
// timerInit or any of the timer<x>Init
#define TIMER0PRESCALE TIMER_CLK_DIV8 ///< timer 0 prescaler default
#define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default
#define TIMER2PRESCALE TIMERRTC_CLK_DIV64 ///< timer 2 prescaler default
// interrupt macros for attaching user functions to timer interrupts
// use these with timerAttach( intNum, function )
#define TIMER0OVERFLOW_INT 0
#define TIMER1OVERFLOW_INT 1
#define TIMER1OUTCOMPAREA_INT 2
#define TIMER1OUTCOMPAREB_INT 3
#define TIMER1INPUTCAPTURE_INT 4
#define TIMER2OVERFLOW_INT 5
#define TIMER2OUTCOMPARE_INT 6
#ifdef OCR0 // for processors that support output compare on Timer0
#define TIMER0OUTCOMPARE_INT 7
#define TIMER_NUM_INTERRUPTS 8
#else
#define TIMER_NUM_INTERRUPTS 7
#endif
// default type of interrupt handler to use for timers
// *do not change unless you know what you're doing
// Value may be SIGNAL or INTERRUPT
#ifndef TIMER_INTERRUPT_HANDLER
#define TIMER_INTERRUPT_HANDLER SIGNAL
#endif
// functions
#define delay delay_us
#define delay_ms timerPause
void delay_us(unsigned short time_us);
//! initializes timing system (all timers)
// runs all timer init functions
// sets all timers to default prescale values #defined in systimer.c
void timerInit(void);
// default initialization routines for each timer
void timer0Init(void); ///< initialize timer0
void timer1Init(void); ///< initialize timer1
#ifdef TCNT2 // support timer2 only if it exists
void timer2Init(void); ///< initialize timer2
#endif
// Clock prescaler set/get commands for each timer/counter
// For setting the prescaler, you should use one of the #defines
// above like TIMER_CLK_DIVx, where [x] is the division rate
// you want.
// When getting the current prescaler setting, the return value
// will be the [x] division value currently set.
void timer0SetPrescaler(u08 prescale); ///< set timer0 prescaler
u16 timer0GetPrescaler(void); ///< get timer0 prescaler
void timer1SetPrescaler(u08 prescale); ///< set timer1 prescaler
u16 timer1GetPrescaler(void); ///< get timer0 prescaler
#ifdef TCNT2 // support timer2 only if it exists
void timer2SetPrescaler(u08 prescale); ///< set timer2 prescaler
u16 timer2GetPrescaler(void); ///< get timer2 prescaler
#endif
// TimerAttach and Detach commands
// These functions allow the attachment (or detachment) of any user function
// to a timer interrupt. "Attaching" one of your own functions to a timer
// interrupt means that it will be called whenever that interrupt happens.
// Using attach is better than rewriting the actual INTERRUPT() function
// because your code will still work and be compatible if the timer library
// is updated. Also, using Attach allows your code and any predefined timer
// code to work together and at the same time. (ie. "attaching" your own
// function to the timer0 overflow doesn't prevent timerPause from working,
// but rather allows you to share the interrupt.)
//
// timerAttach(TIMER1OVERFLOW_INT, myOverflowFunction);
// timerDetach(TIMER1OVERFLOW_INT)
//
// timerAttach causes the myOverflowFunction() to be attached, and therefore
// execute, whenever an overflow on timer1 occurs. timerDetach removes the
// association and executes no user function when the interrupt occurs.
// myOverflowFunction must be defined with no return value and no arguments:
//
// void myOverflowFunction(void) { ... }
//! Attach a user function to a timer interrupt
void timerAttach(u08 interruptNum, void (*userFunc)(void) );
//! Detach a user function from a timer interrupt
void timerDetach(u08 interruptNum);
// timing commands
//! timerPause pauses for the number of milliseconds specified in <pause_ms>
void timerPause(unsigned short pause_ms);
// overflow counters
void timer0ClearOverflowCount(void); ///< clear timer0's overflow counter
long timer0GetOverflowCount(void); ///< read timer0's overflow counter
#ifdef TCNT2 // support timer2 only if it exists
void timer2ClearOverflowCount(void); ///< clear timer2's overflow counter
long timer2GetOverflowCount(void); ///< read timer0's overflow counter
#endif
// PWM initialization and set commands for timer1
// timer1PWMInit()
// configures the timer1 hardware for PWM mode on pins OC1A and OC1B.
// bitRes should be 8,9,or 10 for 8,9,or 10bit PWM resolution
//
// timer1PWMOff()
// turns off all timer1 PWM output and set timer mode to normal state
//
// timer1PWMAOn() and timer1PWMBOn()
// turn on output of PWM signals to OC1A or OC1B pins
// NOTE: Until you define the OC1A and OC1B pins as outputs, and run
// this "on" command, no PWM output will be output
//
// timer1PWMAOff() and timer1PWMBOff()
// turn off output of PWM signals to OC1A or OC1B pins
//
// timer1PWMASet() and timer1PWMBSet()
// sets the PWM duty cycle for each channel
// NOTE: <pwmDuty> should be in the range 0-255 for 8bit PWM
// <pwmDuty> should be in the range 0-511 for 9bit PWM
// <pwmDuty> should be in the range 0-1023 for 10bit PWM
// NOTE: the PWM frequency can be controlled in increments by setting the
// prescaler for timer1
void timer1PWMInit(u08 bitRes); ///< initialize and set timer1 mode to PWM
void timer1PWMInitICR(u16 topcount);///< initialize and set timer1 mode to PWM with specific top count
void timer1PWMOff(void); ///< turn off all timer1 PWM output and set timer mode to normal
void timer1PWMAOn(void); ///< turn on timer1 Channel A (OC1A) PWM output
void timer1PWMBOn(void); ///< turn on timer1 Channel B (OC1B) PWM output
void timer1PWMAOff(void); ///< turn off timer1 Channel A (OC1A) PWM output
void timer1PWMBOff(void); ///< turn off timer1 Channel B (OC1B) PWM output
void timer1PWMASet(u16 pwmDuty); ///< set duty of timer1 Channel A (OC1A) PWM output
void timer1PWMBSet(u16 pwmDuty); ///< set duty of timer1 Channel B (OC1B) PWM output
// Pulse generation commands have been moved to the pulse.c library
#endif

1709
targets/arduino/timer.lst Executable file

File diff suppressed because it is too large Load Diff

284
targets/arduino/uart.c Executable file
View File

@ -0,0 +1,284 @@
/*! \file uart.c \brief UART driver with buffer support. */
// *****************************************************************************
//
// File Name : 'uart.c'
// Title : UART driver with buffer support
// Author : Pascal Stang - Copyright (C) 2000-2002
// Created : 11/22/2000
// Revised : 06/09/2003
// Version : 1.3
// Target MCU : ATMEL AVR Series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
// *****************************************************************************
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include "buffer.h"
#include "uart.h"
// UART global variables
// flag variables
volatile u08 uartReadyTx; ///< uartReadyTx flag
volatile u08 uartBufferedTx; ///< uartBufferedTx flag
// receive and transmit buffers
cBuffer uartRxBuffer; ///< uart receive buffer
cBuffer uartTxBuffer; ///< uart transmit buffer
unsigned short uartRxOverflow; ///< receive overflow counter
#ifndef UART_BUFFERS_EXTERNAL_RAM
// using internal ram,
// automatically allocate space in ram for each buffer
static char uartRxData[UART_RX_BUFFER_SIZE];
static char uartTxData[UART_TX_BUFFER_SIZE];
#endif
typedef void (*voidFuncPtru08)(unsigned char);
volatile static voidFuncPtru08 UartRxFunc;
//! enable and initialize the uart
void uartInit(void)
{
// initialize the buffers
uartInitBuffers();
// initialize user receive handler
UartRxFunc = 0;
// enable RxD/TxD and interrupts
outb(UCR, BV(RXCIE)|BV(TXCIE)|BV(RXEN)|BV(TXEN));
// set default baud rate
uartSetBaudRate(UART_DEFAULT_BAUD_RATE);
// initialize states
uartReadyTx = TRUE;
uartBufferedTx = FALSE;
// clear overflow count
uartRxOverflow = 0;
// enable interrupts
sei();
}
//! create and initialize the uart transmit and receive buffers
void uartInitBuffers(void)
{
#ifndef UART_BUFFERS_EXTERNAL_RAM
// initialize the UART receive buffer
bufferInit(&uartRxBuffer, uartRxData, UART_RX_BUFFER_SIZE);
// initialize the UART transmit buffer
bufferInit(&uartTxBuffer, uartTxData, UART_TX_BUFFER_SIZE);
#else
// initialize the UART receive buffer
bufferInit(&uartRxBuffer, (u08*) UART_RX_BUFFER_ADDR, UART_RX_BUFFER_SIZE);
// initialize the UART transmit buffer
bufferInit(&uartTxBuffer, (u08*) UART_TX_BUFFER_ADDR, UART_TX_BUFFER_SIZE);
#endif
}
//! redirects received data to a user function
void uartSetRxHandler(void (*rx_func)(unsigned char c))
{
// set the receive interrupt to run the supplied user function
UartRxFunc = rx_func;
}
//! set the uart baud rate
void uartSetBaudRate(u32 baudrate)
{
// calculate division factor for requested baud rate, and set it
u16 bauddiv = ((F_CPU+(baudrate*8L))/(baudrate*16L)-1);
outb(UBRRL, bauddiv);
#ifdef UBRRH
outb(UBRRH, bauddiv>>8);
#endif
}
//! returns the receive buffer structure
cBuffer* uartGetRxBuffer(void)
{
// return rx buffer pointer
return &uartRxBuffer;
}
//! returns the transmit buffer structure
cBuffer* uartGetTxBuffer(void)
{
// return tx buffer pointer
return &uartTxBuffer;
}
//! transmits a byte over the uart
void uartSendByte(u08 txData)
{
// wait for the transmitter to be ready
while(!uartReadyTx);
// send byte
outb(UDR, txData);
// set ready state to FALSE
uartReadyTx = FALSE;
}
//! gets a single byte from the uart receive buffer (getchar-style)
int uartGetByte(void)
{
u08 c;
if(uartReceiveByte(&c))
return c;
else
return -1;
}
//! gets a byte (if available) from the uart receive buffer
u08 uartReceiveByte(u08* rxData)
{
// make sure we have a receive buffer
if(uartRxBuffer.size)
{
// make sure we have data
if(uartRxBuffer.datalength)
{
// get byte from beginning of buffer
*rxData = bufferGetFromFront(&uartRxBuffer);
return TRUE;
}
else
{
// no data
return FALSE;
}
}
else
{
// no buffer
return FALSE;
}
}
//! flush all data out of the receive buffer
void uartFlushReceiveBuffer(void)
{
// flush all data from receive buffer
//bufferFlush(&uartRxBuffer);
// same effect as above
uartRxBuffer.datalength = 0;
}
//! return true if uart receive buffer is empty
u08 uartReceiveBufferIsEmpty(void)
{
if(uartRxBuffer.datalength == 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
//! add byte to end of uart Tx buffer
void uartAddToTxBuffer(u08 data)
{
// add data byte to the end of the tx buffer
bufferAddToEnd(&uartTxBuffer, data);
}
//! start transmission of the current uart Tx buffer contents
void uartSendTxBuffer(void)
{
// turn on buffered transmit
uartBufferedTx = TRUE;
// send the first byte to get things going by interrupts
uartSendByte(bufferGetFromFront(&uartTxBuffer));
}
/*
//! transmit nBytes from buffer out the uart
u08 uartSendBuffer(char *buffer, u16 nBytes)
{
register u08 first;
register u16 i;
// check if there's space (and that we have any bytes to send at all)
if((uartTxBuffer.datalength + nBytes < uartTxBuffer.size) && nBytes)
{
// grab first character
first = *buffer++;
// copy user buffer to uart transmit buffer
for(i = 0; i < nBytes-1; i++)
{
// put data bytes at end of buffer
bufferAddToEnd(&uartTxBuffer, *buffer++);
}
// send the first byte to get things going by interrupts
uartBufferedTx = TRUE;
uartSendByte(first);
// return success
return TRUE;
}
else
{
// return failure
return FALSE;
}
}
*/
//! UART Transmit Complete Interrupt Handler
UART_INTERRUPT_HANDLER(SIG_UART_TRANS)
{
// check if buffered tx is enabled
if(uartBufferedTx)
{
// check if there's data left in the buffer
if(uartTxBuffer.datalength)
{
// send byte from top of buffer
outb(UDR, bufferGetFromFront(&uartTxBuffer));
}
else
{
// no data left
uartBufferedTx = FALSE;
// return to ready state
uartReadyTx = TRUE;
}
}
else
{
// we're using single-byte tx mode
// indicate transmit complete, back to ready
uartReadyTx = TRUE;
}
}
//! UART Receive Complete Interrupt Handler
UART_INTERRUPT_HANDLER(SIG_UART_RECV)
{
u08 c;
// get received char
c = inb(UDR);
// if there's a user function to handle this receive event
if(UartRxFunc)
{
// call it and pass the received data
UartRxFunc(c);
}
else
{
// otherwise do default processing
// put received char in buffer
// check if there's space
if( !bufferAddToEnd(&uartRxBuffer, c) )
{
// no space in buffer
// count overflow
uartRxOverflow++;
}
}
}

134
targets/arduino/uart.h Executable file
View File

@ -0,0 +1,134 @@
/*! \file uart.h \brief UART driver with buffer support. */
//*****************************************************************************
//
// File Name : 'uart.h'
// Title : UART driver with buffer support
// Author : Pascal Stang - Copyright (C) 2000-2002
// Created : 11/22/2000
// Revised : 02/01/2004
// Version : 1.3
// Target MCU : ATMEL AVR Series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef UART_H
#define UART_H
#include "global.h"
#include "buffer.h"
//! default baud rate
//! can be changed by using uartSetBaudRate()
#define UART_DEFAULT_BAUD_RATE 9600
// buffer memory allocation defines
// buffer sizes
#ifndef UART_TX_BUFFER_SIZE
#define UART_TX_BUFFER_SIZE 0x0040 ///< number of bytes for uart transmit buffer
#endif
#ifndef UART_RX_BUFFER_SIZE
#define UART_RX_BUFFER_SIZE 0x0040 ///< number of bytes for uart receive buffer
#endif
// define this key if you wish to use
// external RAM for the UART buffers
//#define UART_BUFFER_EXTERNAL_RAM
#ifdef UART_BUFFER_EXTERNAL_RAM
// absolute address of uart buffers
#define UART_TX_BUFFER_ADDR 0x1000
#define UART_RX_BUFFER_ADDR 0x1100
#endif
// type of interrupt handler to use
// *do not change unless you know what you're doing
// Value may be SIGNAL or INTERRUPT
#ifndef UART_INTERRUPT_HANDLER
#define UART_INTERRUPT_HANDLER SIGNAL
#endif
// compatibility with most newer processors
#ifdef UCSRB
#define UCR UCSRB
#endif
// compatibility with old Mega processors
#if defined(UBRR) && !defined(UBRRL)
#define UBRRL UBRR
#endif
// compatibility with dual-uart processors
// (if you need to use both uarts, please use the uart2 library)
#if defined(__AVR_ATmega128__)
#define UDR UDR0
#define UCR UCSR0B
#define UBRRL UBRR0L
#define UBRRH UBRR0H
#define SIG_UART_TRANS SIG_UART0_TRANS
#define SIG_UART_RECV SIG_UART0_RECV
#define SIG_UART_DATA SIG_UART0_DATA
#endif
#if defined(__AVR_ATmega161__)
#define UDR UDR0
#define UCR UCSR0B
#define UBRRL UBRR0
#define SIG_UART_TRANS SIG_UART0_TRANS
#define SIG_UART_RECV SIG_UART0_RECV
#define SIG_UART_DATA SIG_UART0_DATA
#endif
// functions
//! initializes transmit and receive buffers
// called from uartInit()
void uartInitBuffers(void);
//! initializes uart
void uartInit(void);
//! redirects received data to a user function
void uartSetRxHandler(void (*rx_func)(unsigned char c));
//! sets the uart baud rate
void uartSetBaudRate(u32 baudrate);
//! returns pointer to the receive buffer structure
cBuffer* uartGetRxBuffer(void);
//! returns pointer to the transmit buffer structure
cBuffer* uartGetTxBuffer(void);
//! sends a single byte over the uart
void uartSendByte(u08 data);
//! gets a single byte from the uart receive buffer (getchar-style)
// returns the byte, or -1 if no byte is available
int uartGetByte(void);
//! gets a single byte from the uart receive buffer
// Function returns TRUE if data was available, FALSE if not.
// Actual data is returned in variable pointed to by "data".
// example usage:
// char myReceivedByte;
// uartReceiveByte( &myReceivedByte );
u08 uartReceiveByte(u08* data);
//! returns TRUE/FALSE if receive buffer is empty/not-empty
u08 uartReceiveBufferIsEmpty(void);
//! flushes (deletes) all data from receive buffer
void uartFlushReceiveBuffer(void);
//! add byte to end of uart Tx buffer
void uartAddToTxBuffer(u08 data);
//! begins transmission of the transmit buffer under interrupt control
void uartSendTxBuffer(void);
//! sends a buffer of length nBytes via the uart using interrupt control
u08 uartSendBuffer(char *buffer, u16 nBytes);
#endif

789
targets/arduino/uart.lst Executable file
View File

@ -0,0 +1,789 @@
1 .file "uart.c"
2 .arch atmega8
3 __SREG__ = 0x3f
4 __SP_H__ = 0x3e
5 __SP_L__ = 0x3d
6 __tmp_reg__ = 0
7 __zero_reg__ = 1
8 .global __do_copy_data
9 .global __do_clear_bss
12 .text
13 .Ltext0:
86 .global uartSetBaudRate
88 uartSetBaudRate:
1:../avrlib/uart.c **** /*! \file uart.c \brief UART driver with buffer support. */
2:../avrlib/uart.c **** // *****************************************************************************
3:../avrlib/uart.c **** //
4:../avrlib/uart.c **** // File Name : 'uart.c'
5:../avrlib/uart.c **** // Title : UART driver with buffer support
6:../avrlib/uart.c **** // Author : Pascal Stang - Copyright (C) 2000-2002
7:../avrlib/uart.c **** // Created : 11/22/2000
8:../avrlib/uart.c **** // Revised : 06/09/2003
9:../avrlib/uart.c **** // Version : 1.3
10:../avrlib/uart.c **** // Target MCU : ATMEL AVR Series
11:../avrlib/uart.c **** // Editor Tabs : 4
12:../avrlib/uart.c **** //
13:../avrlib/uart.c **** // This code is distributed under the GNU Public License
14:../avrlib/uart.c **** // which can be found at http://www.gnu.org/licenses/gpl.txt
15:../avrlib/uart.c **** //
16:../avrlib/uart.c **** // *****************************************************************************
17:../avrlib/uart.c ****
18:../avrlib/uart.c **** #include <avr/io.h>
19:../avrlib/uart.c **** #include <avr/interrupt.h>
20:../avrlib/uart.c **** #include <avr/signal.h>
21:../avrlib/uart.c ****
22:../avrlib/uart.c **** #include "buffer.h"
23:../avrlib/uart.c **** #include "uart.h"
24:../avrlib/uart.c ****
25:../avrlib/uart.c **** // UART global variables
26:../avrlib/uart.c **** // flag variables
27:../avrlib/uart.c **** volatile u08 uartReadyTx; ///< uartReadyTx flag
28:../avrlib/uart.c **** volatile u08 uartBufferedTx; ///< uartBufferedTx flag
29:../avrlib/uart.c **** // receive and transmit buffers
30:../avrlib/uart.c **** cBuffer uartRxBuffer; ///< uart receive buffer
31:../avrlib/uart.c **** cBuffer uartTxBuffer; ///< uart transmit buffer
32:../avrlib/uart.c **** unsigned short uartRxOverflow; ///< receive overflow counter
33:../avrlib/uart.c ****
34:../avrlib/uart.c **** #ifndef UART_BUFFERS_EXTERNAL_RAM
35:../avrlib/uart.c **** // using internal ram,
36:../avrlib/uart.c **** // automatically allocate space in ram for each buffer
37:../avrlib/uart.c **** static char uartRxData[UART_RX_BUFFER_SIZE];
38:../avrlib/uart.c **** static char uartTxData[UART_TX_BUFFER_SIZE];
39:../avrlib/uart.c **** #endif
40:../avrlib/uart.c ****
41:../avrlib/uart.c **** typedef void (*voidFuncPtru08)(unsigned char);
42:../avrlib/uart.c **** volatile static voidFuncPtru08 UartRxFunc;
43:../avrlib/uart.c ****
44:../avrlib/uart.c **** //! enable and initialize the uart
45:../avrlib/uart.c **** void uartInit(void)
46:../avrlib/uart.c **** {
47:../avrlib/uart.c **** // initialize the buffers
48:../avrlib/uart.c **** uartInitBuffers();
49:../avrlib/uart.c **** // initialize user receive handler
50:../avrlib/uart.c **** UartRxFunc = 0;
51:../avrlib/uart.c ****
52:../avrlib/uart.c **** // enable RxD/TxD and interrupts
53:../avrlib/uart.c **** outb(UCR, BV(RXCIE)|BV(TXCIE)|BV(RXEN)|BV(TXEN));
54:../avrlib/uart.c ****
55:../avrlib/uart.c **** // set default baud rate
56:../avrlib/uart.c **** uartSetBaudRate(UART_DEFAULT_BAUD_RATE);
57:../avrlib/uart.c **** // initialize states
58:../avrlib/uart.c **** uartReadyTx = TRUE;
59:../avrlib/uart.c **** uartBufferedTx = FALSE;
60:../avrlib/uart.c **** // clear overflow count
61:../avrlib/uart.c **** uartRxOverflow = 0;
62:../avrlib/uart.c **** // enable interrupts
63:../avrlib/uart.c **** sei();
64:../avrlib/uart.c **** }
65:../avrlib/uart.c ****
66:../avrlib/uart.c **** //! create and initialize the uart transmit and receive buffers
67:../avrlib/uart.c **** void uartInitBuffers(void)
68:../avrlib/uart.c **** {
69:../avrlib/uart.c **** #ifndef UART_BUFFERS_EXTERNAL_RAM
70:../avrlib/uart.c **** // initialize the UART receive buffer
71:../avrlib/uart.c **** bufferInit(&uartRxBuffer, uartRxData, UART_RX_BUFFER_SIZE);
72:../avrlib/uart.c **** // initialize the UART transmit buffer
73:../avrlib/uart.c **** bufferInit(&uartTxBuffer, uartTxData, UART_TX_BUFFER_SIZE);
74:../avrlib/uart.c **** #else
75:../avrlib/uart.c **** // initialize the UART receive buffer
76:../avrlib/uart.c **** bufferInit(&uartRxBuffer, (u08*) UART_RX_BUFFER_ADDR, UART_RX_BUFFER_SIZE);
77:../avrlib/uart.c **** // initialize the UART transmit buffer
78:../avrlib/uart.c **** bufferInit(&uartTxBuffer, (u08*) UART_TX_BUFFER_ADDR, UART_TX_BUFFER_SIZE);
79:../avrlib/uart.c **** #endif
80:../avrlib/uart.c **** }
81:../avrlib/uart.c ****
82:../avrlib/uart.c **** //! redirects received data to a user function
83:../avrlib/uart.c **** void uartSetRxHandler(void (*rx_func)(unsigned char c))
84:../avrlib/uart.c **** {
85:../avrlib/uart.c **** // set the receive interrupt to run the supplied user function
86:../avrlib/uart.c **** UartRxFunc = rx_func;
87:../avrlib/uart.c **** }
88:../avrlib/uart.c ****
89:../avrlib/uart.c **** //! set the uart baud rate
90:../avrlib/uart.c **** void uartSetBaudRate(u32 baudrate)
91:../avrlib/uart.c **** {
90 .LM1:
91 /* prologue: frame size=0 */
92 /* prologue end (size=0) */
93 0000 DC01 movw r26,r24
94 0002 CB01 movw r24,r22
92:../avrlib/uart.c **** // calculate division factor for requested baud rate, and set it
93:../avrlib/uart.c **** u16 bauddiv = ((F_CPU+(baudrate*8L))/(baudrate*16L)-1);
96 .LM2:
97 0004 73E0 ldi r23,3
98 0006 880F 1: lsl r24
99 0008 991F rol r25
100 000a AA1F rol r26
101 000c BB1F rol r27
102 000e 7A95 dec r23
103 0010 D1F7 brne 1b
104 0012 9C01 movw r18,r24
105 0014 AD01 movw r20,r26
106 0016 220F lsl r18
107 0018 331F rol r19
108 001a 441F rol r20
109 001c 551F rol r21
110 001e 8050 subi r24,lo8(-(16000000))
111 0020 9C4D sbci r25,hi8(-(16000000))
112 0022 AB40 sbci r26,hlo8(-(16000000))
113 0024 BF4F sbci r27,hhi8(-(16000000))
114 0026 BC01 movw r22,r24
115 0028 CD01 movw r24,r26
116 002a 00D0 rcall __udivmodsi4
117 002c DA01 movw r26,r20
118 002e C901 movw r24,r18
119 0030 0197 sbiw r24,1
94:../avrlib/uart.c **** outb(UBRRL, bauddiv);
121 .LM3:
122 0032 89B9 out 41-0x20,r24
95:../avrlib/uart.c **** #ifdef UBRRH
96:../avrlib/uart.c **** outb(UBRRH, bauddiv>>8);
124 .LM4:
125 0034 892F mov r24,r25
126 0036 9927 clr r25
127 0038 80BD out 64-0x20,r24
128 /* epilogue: frame size=0 */
129 003a 0895 ret
130 /* epilogue end (size=1) */
131 /* function uartSetBaudRate size 30 (29) */
136 .Lscope0:
139 .global uartInitBuffers
141 uartInitBuffers:
143 .LM5:
144 /* prologue: frame size=0 */
145 /* prologue end (size=0) */
147 .LM6:
148 003c 40E4 ldi r20,lo8(64)
149 003e 50E0 ldi r21,hi8(64)
150 0040 60E0 ldi r22,lo8(uartRxData)
151 0042 70E0 ldi r23,hi8(uartRxData)
152 0044 80E0 ldi r24,lo8(uartRxBuffer)
153 0046 90E0 ldi r25,hi8(uartRxBuffer)
154 0048 00D0 rcall bufferInit
156 .LM7:
157 004a 40E4 ldi r20,lo8(64)
158 004c 50E0 ldi r21,hi8(64)
159 004e 60E0 ldi r22,lo8(uartTxData)
160 0050 70E0 ldi r23,hi8(uartTxData)
161 0052 80E0 ldi r24,lo8(uartTxBuffer)
162 0054 90E0 ldi r25,hi8(uartTxBuffer)
163 0056 00D0 rcall bufferInit
164 /* epilogue: frame size=0 */
165 0058 0895 ret
166 /* epilogue end (size=1) */
167 /* function uartInitBuffers size 15 (14) */
169 .Lscope1:
172 .global uartInit
174 uartInit:
176 .LM8:
177 /* prologue: frame size=0 */
178 /* prologue end (size=0) */
180 .LM9:
181 005a F0DF rcall uartInitBuffers
183 .LM10:
184 005c 1092 0000 sts (UartRxFunc)+1,__zero_reg__
185 0060 1092 0000 sts UartRxFunc,__zero_reg__
187 .LM11:
188 0064 88ED ldi r24,lo8(-40)
189 0066 8AB9 out 42-0x20,r24
191 .LM12:
192 0068 60E8 ldi r22,lo8(9600)
193 006a 75E2 ldi r23,hi8(9600)
194 006c 80E0 ldi r24,hlo8(9600)
195 006e 90E0 ldi r25,hhi8(9600)
196 0070 C7DF rcall uartSetBaudRate
198 .LM13:
199 0072 8FEF ldi r24,lo8(-1)
200 0074 8093 0000 sts uartReadyTx,r24
202 .LM14:
203 0078 1092 0000 sts uartBufferedTx,__zero_reg__
205 .LM15:
206 007c 1092 0000 sts (uartRxOverflow)+1,__zero_reg__
207 0080 1092 0000 sts uartRxOverflow,__zero_reg__
209 .LM16:
210 /* #APP */
211 0084 7894 sei
212 /* #NOAPP */
213 /* epilogue: frame size=0 */
214 0086 0895 ret
215 /* epilogue end (size=1) */
216 /* function uartInit size 24 (23) */
218 .Lscope2:
222 .global uartSetRxHandler
224 uartSetRxHandler:
226 .LM17:
227 /* prologue: frame size=0 */
228 /* prologue end (size=0) */
230 .LM18:
231 0088 9093 0000 sts (UartRxFunc)+1,r25
232 008c 8093 0000 sts UartRxFunc,r24
233 /* epilogue: frame size=0 */
234 0090 0895 ret
235 /* epilogue end (size=1) */
236 /* function uartSetRxHandler size 5 (4) */
238 .Lscope3:
241 .global uartGetRxBuffer
243 uartGetRxBuffer:
97:../avrlib/uart.c **** #endif
98:../avrlib/uart.c **** }
99:../avrlib/uart.c ****
100:../avrlib/uart.c **** //! returns the receive buffer structure
101:../avrlib/uart.c **** cBuffer* uartGetRxBuffer(void)
102:../avrlib/uart.c **** {
245 .LM19:
246 /* prologue: frame size=0 */
247 /* prologue end (size=0) */
103:../avrlib/uart.c **** // return rx buffer pointer
104:../avrlib/uart.c **** return &uartRxBuffer;
105:../avrlib/uart.c **** }
249 .LM20:
250 0092 80E0 ldi r24,lo8(uartRxBuffer)
251 0094 90E0 ldi r25,hi8(uartRxBuffer)
252 /* epilogue: frame size=0 */
253 0096 0895 ret
254 /* epilogue end (size=1) */
255 /* function uartGetRxBuffer size 3 (2) */
257 .Lscope4:
260 .global uartGetTxBuffer
262 uartGetTxBuffer:
106:../avrlib/uart.c ****
107:../avrlib/uart.c **** //! returns the transmit buffer structure
108:../avrlib/uart.c **** cBuffer* uartGetTxBuffer(void)
109:../avrlib/uart.c **** {
264 .LM21:
265 /* prologue: frame size=0 */
266 /* prologue end (size=0) */
110:../avrlib/uart.c **** // return tx buffer pointer
111:../avrlib/uart.c **** return &uartTxBuffer;
112:../avrlib/uart.c **** }
268 .LM22:
269 0098 80E0 ldi r24,lo8(uartTxBuffer)
270 009a 90E0 ldi r25,hi8(uartTxBuffer)
271 /* epilogue: frame size=0 */
272 009c 0895 ret
273 /* epilogue end (size=1) */
274 /* function uartGetTxBuffer size 3 (2) */
276 .Lscope5:
280 .global uartSendByte
282 uartSendByte:
113:../avrlib/uart.c ****
114:../avrlib/uart.c **** //! transmits a byte over the uart
115:../avrlib/uart.c **** void uartSendByte(u08 txData)
116:../avrlib/uart.c **** {
284 .LM23:
285 /* prologue: frame size=0 */
286 /* prologue end (size=0) */
287 009e 982F mov r25,r24
288 .L8:
117:../avrlib/uart.c **** // wait for the transmitter to be ready
118:../avrlib/uart.c **** while(!uartReadyTx);
290 .LM24:
291 00a0 8091 0000 lds r24,uartReadyTx
292 00a4 8823 tst r24
293 00a6 E1F3 breq .L8
119:../avrlib/uart.c **** // send byte
120:../avrlib/uart.c **** outb(UDR, txData);
295 .LM25:
296 00a8 9CB9 out 44-0x20,r25
121:../avrlib/uart.c **** // set ready state to FALSE
122:../avrlib/uart.c **** uartReadyTx = FALSE;
298 .LM26:
299 00aa 1092 0000 sts uartReadyTx,__zero_reg__
300 /* epilogue: frame size=0 */
301 00ae 0895 ret
302 /* epilogue end (size=1) */
303 /* function uartSendByte size 9 (8) */
305 .Lscope6:
309 .global uartReceiveByte
311 uartReceiveByte:
123:../avrlib/uart.c **** }
124:../avrlib/uart.c ****
125:../avrlib/uart.c **** //! gets a single byte from the uart receive buffer (getchar-style)
126:../avrlib/uart.c **** int uartGetByte(void)
127:../avrlib/uart.c **** {
128:../avrlib/uart.c **** u08 c;
129:../avrlib/uart.c **** if(uartReceiveByte(&c))
130:../avrlib/uart.c **** return c;
131:../avrlib/uart.c **** else
132:../avrlib/uart.c **** return -1;
133:../avrlib/uart.c **** }
134:../avrlib/uart.c ****
135:../avrlib/uart.c **** //! gets a byte (if available) from the uart receive buffer
136:../avrlib/uart.c **** u08 uartReceiveByte(u08* rxData)
137:../avrlib/uart.c **** {
313 .LM27:
314 /* prologue: frame size=0 */
315 00b0 CF93 push r28
316 00b2 DF93 push r29
317 /* prologue end (size=2) */
318 00b4 EC01 movw r28,r24
138:../avrlib/uart.c **** // make sure we have a receive buffer
139:../avrlib/uart.c **** if(uartRxBuffer.size)
320 .LM28:
321 00b6 8091 0000 lds r24,uartRxBuffer+2
322 00ba 9091 0000 lds r25,(uartRxBuffer+2)+1
323 00be 0097 sbiw r24,0
324 00c0 61F0 breq .L11
140:../avrlib/uart.c **** {
141:../avrlib/uart.c **** // make sure we have data
142:../avrlib/uart.c **** if(uartRxBuffer.datalength)
326 .LM29:
327 00c2 8091 0000 lds r24,uartRxBuffer+4
328 00c6 9091 0000 lds r25,(uartRxBuffer+4)+1
329 00ca 0097 sbiw r24,0
330 00cc 31F0 breq .L11
143:../avrlib/uart.c **** {
144:../avrlib/uart.c **** // get byte from beginning of buffer
145:../avrlib/uart.c **** *rxData = bufferGetFromFront(&uartRxBuffer);
332 .LM30:
333 00ce 80E0 ldi r24,lo8(uartRxBuffer)
334 00d0 90E0 ldi r25,hi8(uartRxBuffer)
335 00d2 00D0 rcall bufferGetFromFront
336 00d4 8883 st Y,r24
146:../avrlib/uart.c **** return TRUE;
338 .LM31:
339 00d6 8FEF ldi r24,lo8(255)
340 00d8 90E0 ldi r25,hi8(255)
341 .L11:
342 /* epilogue: frame size=0 */
343 00da DF91 pop r29
344 00dc CF91 pop r28
345 00de 0895 ret
346 /* epilogue end (size=3) */
347 /* function uartReceiveByte size 24 (19) */
349 .Lscope7:
352 .global uartGetByte
354 uartGetByte:
356 .LM32:
357 /* prologue: frame size=1 */
358 00e0 CF93 push r28
359 00e2 DF93 push r29
360 00e4 CDB7 in r28,__SP_L__
361 00e6 DEB7 in r29,__SP_H__
362 00e8 2197 sbiw r28,1
363 00ea 0FB6 in __tmp_reg__,__SREG__
364 00ec F894 cli
365 00ee DEBF out __SP_H__,r29
366 00f0 0FBE out __SREG__,__tmp_reg__
367 00f2 CDBF out __SP_L__,r28
368 /* prologue end (size=10) */
370 .LM33:
371 00f4 CE01 movw r24,r28
372 00f6 0196 adiw r24,1
373 00f8 DBDF rcall uartReceiveByte
374 00fa 8823 tst r24
375 00fc 19F0 breq .L17
377 .LM34:
378 00fe 8981 ldd r24,Y+1
379 0100 9927 clr r25
380 0102 02C0 rjmp .L16
381 .L17:
383 .LM35:
384 0104 8FEF ldi r24,lo8(-1)
385 0106 9FEF ldi r25,hi8(-1)
386 .L16:
387 /* epilogue: frame size=1 */
388 0108 2196 adiw r28,1
389 010a 0FB6 in __tmp_reg__,__SREG__
390 010c F894 cli
391 010e DEBF out __SP_H__,r29
392 0110 0FBE out __SREG__,__tmp_reg__
393 0112 CDBF out __SP_L__,r28
394 0114 DF91 pop r29
395 0116 CF91 pop r28
396 0118 0895 ret
397 /* epilogue end (size=9) */
398 /* function uartGetByte size 29 (10) */
403 .Lscope8:
406 .global uartFlushReceiveBuffer
408 uartFlushReceiveBuffer:
147:../avrlib/uart.c **** }
148:../avrlib/uart.c **** else
149:../avrlib/uart.c **** {
150:../avrlib/uart.c **** // no data
151:../avrlib/uart.c **** return FALSE;
152:../avrlib/uart.c **** }
153:../avrlib/uart.c **** }
154:../avrlib/uart.c **** else
155:../avrlib/uart.c **** {
156:../avrlib/uart.c **** // no buffer
157:../avrlib/uart.c **** return FALSE;
158:../avrlib/uart.c **** }
159:../avrlib/uart.c **** }
160:../avrlib/uart.c ****
161:../avrlib/uart.c **** //! flush all data out of the receive buffer
162:../avrlib/uart.c **** void uartFlushReceiveBuffer(void)
163:../avrlib/uart.c **** {
410 .LM36:
411 /* prologue: frame size=0 */
412 /* prologue end (size=0) */
164:../avrlib/uart.c **** // flush all data from receive buffer
165:../avrlib/uart.c **** //bufferFlush(&uartRxBuffer);
166:../avrlib/uart.c **** // same effect as above
167:../avrlib/uart.c **** uartRxBuffer.datalength = 0;
414 .LM37:
415 011a 1092 0000 sts (uartRxBuffer+4)+1,__zero_reg__
416 011e 1092 0000 sts uartRxBuffer+4,__zero_reg__
417 /* epilogue: frame size=0 */
418 0122 0895 ret
419 /* epilogue end (size=1) */
420 /* function uartFlushReceiveBuffer size 5 (4) */
422 .Lscope9:
425 .global uartReceiveBufferIsEmpty
427 uartReceiveBufferIsEmpty:
168:../avrlib/uart.c **** }
169:../avrlib/uart.c ****
170:../avrlib/uart.c **** //! return true if uart receive buffer is empty
171:../avrlib/uart.c **** u08 uartReceiveBufferIsEmpty(void)
172:../avrlib/uart.c **** {
429 .LM38:
430 /* prologue: frame size=0 */
431 /* prologue end (size=0) */
173:../avrlib/uart.c **** if(uartRxBuffer.datalength == 0)
433 .LM39:
434 0124 8091 0000 lds r24,uartRxBuffer+4
435 0128 9091 0000 lds r25,(uartRxBuffer+4)+1
436 012c 892B or r24,r25
437 012e 19F4 brne .L21
174:../avrlib/uart.c **** {
175:../avrlib/uart.c **** return TRUE;
439 .LM40:
440 0130 8FEF ldi r24,lo8(255)
441 0132 90E0 ldi r25,hi8(255)
442 0134 0895 ret
443 .L21:
176:../avrlib/uart.c **** }
177:../avrlib/uart.c **** else
178:../avrlib/uart.c **** {
179:../avrlib/uart.c **** return FALSE;
445 .LM41:
446 0136 80E0 ldi r24,lo8(0)
447 0138 90E0 ldi r25,hi8(0)
180:../avrlib/uart.c **** }
181:../avrlib/uart.c **** }
449 .LM42:
450 013a 0895 ret
451 /* epilogue: frame size=0 */
452 013c 0895 ret
453 /* epilogue end (size=1) */
454 /* function uartReceiveBufferIsEmpty size 13 (12) */
456 .Lscope10:
460 .global uartAddToTxBuffer
462 uartAddToTxBuffer:
182:../avrlib/uart.c ****
183:../avrlib/uart.c **** //! add byte to end of uart Tx buffer
184:../avrlib/uart.c **** void uartAddToTxBuffer(u08 data)
185:../avrlib/uart.c **** {
464 .LM43:
465 /* prologue: frame size=0 */
466 /* prologue end (size=0) */
186:../avrlib/uart.c **** // add data byte to the end of the tx buffer
187:../avrlib/uart.c **** bufferAddToEnd(&uartTxBuffer, data);
468 .LM44:
469 013e 682F mov r22,r24
470 0140 80E0 ldi r24,lo8(uartTxBuffer)
471 0142 90E0 ldi r25,hi8(uartTxBuffer)
472 0144 00D0 rcall bufferAddToEnd
473 /* epilogue: frame size=0 */
474 0146 0895 ret
475 /* epilogue end (size=1) */
476 /* function uartAddToTxBuffer size 5 (4) */
478 .Lscope11:
481 .global uartSendTxBuffer
483 uartSendTxBuffer:
188:../avrlib/uart.c **** }
189:../avrlib/uart.c ****
190:../avrlib/uart.c **** //! start transmission of the current uart Tx buffer contents
191:../avrlib/uart.c **** void uartSendTxBuffer(void)
192:../avrlib/uart.c **** {
485 .LM45:
486 /* prologue: frame size=0 */
487 /* prologue end (size=0) */
193:../avrlib/uart.c **** // turn on buffered transmit
194:../avrlib/uart.c **** uartBufferedTx = TRUE;
489 .LM46:
490 0148 8FEF ldi r24,lo8(-1)
491 014a 8093 0000 sts uartBufferedTx,r24
195:../avrlib/uart.c **** // send the first byte to get things going by interrupts
196:../avrlib/uart.c **** uartSendByte(bufferGetFromFront(&uartTxBuffer));
493 .LM47:
494 014e 80E0 ldi r24,lo8(uartTxBuffer)
495 0150 90E0 ldi r25,hi8(uartTxBuffer)
496 0152 00D0 rcall bufferGetFromFront
497 0154 A4DF rcall uartSendByte
498 /* epilogue: frame size=0 */
499 0156 0895 ret
500 /* epilogue end (size=1) */
501 /* function uartSendTxBuffer size 8 (7) */
503 .Lscope12:
506 .global __vector_13
508 __vector_13:
197:../avrlib/uart.c **** }
198:../avrlib/uart.c **** /*
199:../avrlib/uart.c **** //! transmit nBytes from buffer out the uart
200:../avrlib/uart.c **** u08 uartSendBuffer(char *buffer, u16 nBytes)
201:../avrlib/uart.c **** {
202:../avrlib/uart.c **** register u08 first;
203:../avrlib/uart.c **** register u16 i;
204:../avrlib/uart.c ****
205:../avrlib/uart.c **** // check if there's space (and that we have any bytes to send at all)
206:../avrlib/uart.c **** if((uartTxBuffer.datalength + nBytes < uartTxBuffer.size) && nBytes)
207:../avrlib/uart.c **** {
208:../avrlib/uart.c **** // grab first character
209:../avrlib/uart.c **** first = *buffer++;
210:../avrlib/uart.c **** // copy user buffer to uart transmit buffer
211:../avrlib/uart.c **** for(i = 0; i < nBytes-1; i++)
212:../avrlib/uart.c **** {
213:../avrlib/uart.c **** // put data bytes at end of buffer
214:../avrlib/uart.c **** bufferAddToEnd(&uartTxBuffer, *buffer++);
215:../avrlib/uart.c **** }
216:../avrlib/uart.c ****
217:../avrlib/uart.c **** // send the first byte to get things going by interrupts
218:../avrlib/uart.c **** uartBufferedTx = TRUE;
219:../avrlib/uart.c **** uartSendByte(first);
220:../avrlib/uart.c **** // return success
221:../avrlib/uart.c **** return TRUE;
222:../avrlib/uart.c **** }
223:../avrlib/uart.c **** else
224:../avrlib/uart.c **** {
225:../avrlib/uart.c **** // return failure
226:../avrlib/uart.c **** return FALSE;
227:../avrlib/uart.c **** }
228:../avrlib/uart.c **** }
229:../avrlib/uart.c **** */
230:../avrlib/uart.c **** //! UART Transmit Complete Interrupt Handler
231:../avrlib/uart.c **** UART_INTERRUPT_HANDLER(SIG_UART_TRANS)
232:../avrlib/uart.c **** {
510 .LM48:
511 /* prologue: frame size=0 */
512 0158 1F92 push __zero_reg__
513 015a 0F92 push __tmp_reg__
514 015c 0FB6 in __tmp_reg__,__SREG__
515 015e 0F92 push __tmp_reg__
516 0160 1124 clr __zero_reg__
517 0162 2F93 push r18
518 0164 3F93 push r19
519 0166 4F93 push r20
520 0168 5F93 push r21
521 016a 6F93 push r22
522 016c 7F93 push r23
523 016e 8F93 push r24
524 0170 9F93 push r25
525 0172 AF93 push r26
526 0174 BF93 push r27
527 0176 EF93 push r30
528 0178 FF93 push r31
529 /* prologue end (size=17) */
233:../avrlib/uart.c **** // check if buffered tx is enabled
234:../avrlib/uart.c **** if(uartBufferedTx)
531 .LM49:
532 017a 8091 0000 lds r24,uartBufferedTx
533 017e 8823 tst r24
534 0180 69F0 breq .L26
235:../avrlib/uart.c **** {
236:../avrlib/uart.c **** // check if there's data left in the buffer
237:../avrlib/uart.c **** if(uartTxBuffer.datalength)
536 .LM50:
537 0182 8091 0000 lds r24,uartTxBuffer+4
538 0186 9091 0000 lds r25,(uartTxBuffer+4)+1
539 018a 892B or r24,r25
540 018c 29F0 breq .L27
238:../avrlib/uart.c **** {
239:../avrlib/uart.c **** // send byte from top of buffer
240:../avrlib/uart.c **** outb(UDR, bufferGetFromFront(&uartTxBuffer));
542 .LM51:
543 018e 80E0 ldi r24,lo8(uartTxBuffer)
544 0190 90E0 ldi r25,hi8(uartTxBuffer)
545 0192 00D0 rcall bufferGetFromFront
546 0194 8CB9 out 44-0x20,r24
547 0196 05C0 rjmp .L25
548 .L27:
241:../avrlib/uart.c **** }
242:../avrlib/uart.c **** else
243:../avrlib/uart.c **** {
244:../avrlib/uart.c **** // no data left
245:../avrlib/uart.c **** uartBufferedTx = FALSE;
550 .LM52:
551 0198 1092 0000 sts uartBufferedTx,__zero_reg__
552 .L26:
246:../avrlib/uart.c **** // return to ready state
247:../avrlib/uart.c **** uartReadyTx = TRUE;
248:../avrlib/uart.c **** }
249:../avrlib/uart.c **** }
250:../avrlib/uart.c **** else
251:../avrlib/uart.c **** {
252:../avrlib/uart.c **** // we're using single-byte tx mode
253:../avrlib/uart.c **** // indicate transmit complete, back to ready
254:../avrlib/uart.c **** uartReadyTx = TRUE;
554 .LM53:
555 019c 8FEF ldi r24,lo8(-1)
556 019e 8093 0000 sts uartReadyTx,r24
557 .L25:
558 /* epilogue: frame size=0 */
559 01a2 FF91 pop r31
560 01a4 EF91 pop r30
561 01a6 BF91 pop r27
562 01a8 AF91 pop r26
563 01aa 9F91 pop r25
564 01ac 8F91 pop r24
565 01ae 7F91 pop r23
566 01b0 6F91 pop r22
567 01b2 5F91 pop r21
568 01b4 4F91 pop r20
569 01b6 3F91 pop r19
570 01b8 2F91 pop r18
571 01ba 0F90 pop __tmp_reg__
572 01bc 0FBE out __SREG__,__tmp_reg__
573 01be 0F90 pop __tmp_reg__
574 01c0 1F90 pop __zero_reg__
575 01c2 1895 reti
576 /* epilogue end (size=17) */
577 /* function __vector_13 size 54 (20) */
579 .Lscope13:
582 .global __vector_11
584 __vector_11:
255:../avrlib/uart.c **** }
256:../avrlib/uart.c **** }
257:../avrlib/uart.c ****
258:../avrlib/uart.c **** //! UART Receive Complete Interrupt Handler
259:../avrlib/uart.c **** UART_INTERRUPT_HANDLER(SIG_UART_RECV)
260:../avrlib/uart.c **** {
586 .LM54:
587 /* prologue: frame size=0 */
588 01c4 1F92 push __zero_reg__
589 01c6 0F92 push __tmp_reg__
590 01c8 0FB6 in __tmp_reg__,__SREG__
591 01ca 0F92 push __tmp_reg__
592 01cc 1124 clr __zero_reg__
593 01ce 2F93 push r18
594 01d0 3F93 push r19
595 01d2 4F93 push r20
596 01d4 5F93 push r21
597 01d6 6F93 push r22
598 01d8 7F93 push r23
599 01da 8F93 push r24
600 01dc 9F93 push r25
601 01de AF93 push r26
602 01e0 BF93 push r27
603 01e2 EF93 push r30
604 01e4 FF93 push r31
605 /* prologue end (size=17) */
261:../avrlib/uart.c **** u08 c;
262:../avrlib/uart.c ****
263:../avrlib/uart.c **** // get received char
264:../avrlib/uart.c **** c = inb(UDR);
607 .LM55:
608 01e6 6CB1 in r22,44-0x20
265:../avrlib/uart.c ****
266:../avrlib/uart.c **** // if there's a user function to handle this receive event
267:../avrlib/uart.c **** if(UartRxFunc)
610 .LM56:
611 01e8 8091 0000 lds r24,UartRxFunc
612 01ec 9091 0000 lds r25,(UartRxFunc)+1
613 01f0 892B or r24,r25
614 01f2 39F0 breq .L31
268:../avrlib/uart.c **** {
269:../avrlib/uart.c **** // call it and pass the received data
270:../avrlib/uart.c **** UartRxFunc(c);
616 .LM57:
617 01f4 E091 0000 lds r30,UartRxFunc
618 01f8 F091 0000 lds r31,(UartRxFunc)+1
619 01fc 862F mov r24,r22
620 01fe 0995 icall
621 0200 0EC0 rjmp .L30
622 .L31:
271:../avrlib/uart.c **** }
272:../avrlib/uart.c **** else
273:../avrlib/uart.c **** {
274:../avrlib/uart.c **** // otherwise do default processing
275:../avrlib/uart.c **** // put received char in buffer
276:../avrlib/uart.c **** // check if there's space
277:../avrlib/uart.c **** if( !bufferAddToEnd(&uartRxBuffer, c) )
624 .LM58:
625 0202 80E0 ldi r24,lo8(uartRxBuffer)
626 0204 90E0 ldi r25,hi8(uartRxBuffer)
627 0206 00D0 rcall bufferAddToEnd
628 0208 8823 tst r24
629 020a 49F4 brne .L30
278:../avrlib/uart.c **** {
279:../avrlib/uart.c **** // no space in buffer
280:../avrlib/uart.c **** // count overflow
281:../avrlib/uart.c **** uartRxOverflow++;
631 .LM59:
632 020c 8091 0000 lds r24,uartRxOverflow
633 0210 9091 0000 lds r25,(uartRxOverflow)+1
634 0214 0196 adiw r24,1
635 0216 9093 0000 sts (uartRxOverflow)+1,r25
636 021a 8093 0000 sts uartRxOverflow,r24
637 .L30:
638 /* epilogue: frame size=0 */
639 021e FF91 pop r31
640 0220 EF91 pop r30
641 0222 BF91 pop r27
642 0224 AF91 pop r26
643 0226 9F91 pop r25
644 0228 8F91 pop r24
645 022a 7F91 pop r23
646 022c 6F91 pop r22
647 022e 5F91 pop r21
648 0230 4F91 pop r20
649 0232 3F91 pop r19
650 0234 2F91 pop r18
651 0236 0F90 pop __tmp_reg__
652 0238 0FBE out __SREG__,__tmp_reg__
653 023a 0F90 pop __tmp_reg__
654 023c 1F90 pop __zero_reg__
655 023e 1895 reti
656 /* epilogue end (size=17) */
657 /* function __vector_11 size 62 (28) */
662 .Lscope14:
664 .comm uartReadyTx,1,1
665 .comm uartBufferedTx,1,1
666 .comm uartRxBuffer,8,1
667 .comm uartTxBuffer,8,1
668 .comm uartRxOverflow,2,1
669 .lcomm uartRxData,64
670 .lcomm uartTxData,64
671 .lcomm UartRxFunc,2
680 .text
682 Letext:
683 /* File "../avrlib/uart.c": code 289 = 0x0121 ( 186), prologues 46, epilogues 57 */
DEFINED SYMBOLS
*ABS*:00000000 uart.c
*ABS*:0000003f __SREG__
*ABS*:0000003e __SP_H__
*ABS*:0000003d __SP_L__
*ABS*:00000000 __tmp_reg__
*ABS*:00000001 __zero_reg__
/var/tmp//cclgUhYv.s:88 .text:00000000 uartSetBaudRate
/var/tmp//cclgUhYv.s:141 .text:0000003c uartInitBuffers
.bss:00000000 uartRxData
*COM*:00000008 uartRxBuffer
/var/tmp//cclgUhYv.s:669 .bss:00000040 uartTxData
*COM*:00000008 uartTxBuffer
/var/tmp//cclgUhYv.s:174 .text:0000005a uartInit
/var/tmp//cclgUhYv.s:670 .bss:00000080 UartRxFunc
*COM*:00000001 uartReadyTx
*COM*:00000001 uartBufferedTx
*COM*:00000002 uartRxOverflow
/var/tmp//cclgUhYv.s:224 .text:00000088 uartSetRxHandler
/var/tmp//cclgUhYv.s:243 .text:00000092 uartGetRxBuffer
/var/tmp//cclgUhYv.s:262 .text:00000098 uartGetTxBuffer
/var/tmp//cclgUhYv.s:282 .text:0000009e uartSendByte
/var/tmp//cclgUhYv.s:311 .text:000000b0 uartReceiveByte
/var/tmp//cclgUhYv.s:354 .text:000000e0 uartGetByte
/var/tmp//cclgUhYv.s:408 .text:0000011a uartFlushReceiveBuffer
/var/tmp//cclgUhYv.s:427 .text:00000124 uartReceiveBufferIsEmpty
/var/tmp//cclgUhYv.s:462 .text:0000013e uartAddToTxBuffer
/var/tmp//cclgUhYv.s:483 .text:00000148 uartSendTxBuffer
/var/tmp//cclgUhYv.s:508 .text:00000158 __vector_13
/var/tmp//cclgUhYv.s:584 .text:000001c4 __vector_11
/var/tmp//cclgUhYv.s:682 .text:00000240 Letext
UNDEFINED SYMBOLS
__do_copy_data
__do_clear_bss
__udivmodsi4
bufferInit
bufferGetFromFront
bufferAddToEnd

311
targets/arduino/wiring.c Executable file
View File

@ -0,0 +1,311 @@
/*
wiring.c - Wiring API Partial Implementation
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c,v 1.7 2005/05/28 21:04:15 mellis Exp $
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/delay.h>
#include <stdio.h>
#include <stdarg.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// from Pascal's avrlib
#include "global.h"
//#include "a2d.h"
#include "timer.h"
#include "uart.h"
// timer.h #defines delay to be delay_us, we need to undefine
// it so our delay can be in milliseconds.
#undef delay
#include "wiring.h"
// Get the hardware port of the given virtual pin number. This comes from
// the pins_*.c file for the active board configuration.
int digitalPinToPort(int pin)
{
return digital_pin_to_port[pin].port;
}
// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
int digitalPinToBit(int pin)
{
return digital_pin_to_port[pin].bit;
}
int analogOutPinToPort(int pin)
{
return analog_out_pin_to_port[pin].port;
}
int analogOutPinToBit(int pin)
{
return analog_out_pin_to_port[pin].bit;
}
int analogInPinToBit(int pin)
{
return analog_in_pin_to_port[pin].bit;
}
void pinMode(int pin, int mode)
{
if (digitalPinToPort(pin) != NOT_A_PIN) {
if (mode == INPUT)
cbi(_SFR_IO8(port_to_mode[digitalPinToPort(pin)]), digitalPinToBit(pin));
else
sbi(_SFR_IO8(port_to_mode[digitalPinToPort(pin)]), digitalPinToBit(pin));
}
}
void digitalWrite(int pin, int val)
{
if (digitalPinToPort(pin) != NOT_A_PIN) {
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (analogOutPinToBit(pin) == 1)
timer1PWMAOff();
if (analogOutPinToBit(pin) == 2)
timer1PWMBOff();
if (val == LOW)
cbi(_SFR_IO8(port_to_output[digitalPinToPort(pin)]), digitalPinToBit(pin));
else
sbi(_SFR_IO8(port_to_output[digitalPinToPort(pin)]), digitalPinToBit(pin));
}
}
int digitalRead(int pin)
{
if (digitalPinToPort(pin) != NOT_A_PIN) {
// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (analogOutPinToBit(pin) == 1)
timer1PWMAOff();
if (analogOutPinToBit(pin) == 2)
timer1PWMBOff();
return (_SFR_IO8(port_to_input[digitalPinToPort(pin)]) >> digitalPinToBit(pin)) & 0x01;
}
return LOW;
}
/*
int analogRead(int pin)
{
unsigned long start_time = millis();
int ch = analogInPinToBit(pin);
volatile unsigned int low, high;
//return a2dConvert10bit(ch);
a2dSetChannel(ch);
a2dStartConvert();
// wait until the conversion is complete or we
// time out. without the timeout, this sometimes
// becomes an infinite loop. page 245 of the atmega8
// datasheet says the conversion should take at most
// 260 microseconds, so if two milliseconds have ticked
// by, something's wrong.
//while (!a2dIsComplete() && millis() - start_time < 50);
while (!a2dIsComplete());
// a2Convert10bit sometimes read ADCL and ADCH in the
// wrong order (?) causing it to sometimes miss reading,
// especially if called multiple times in rapid succession.
//return a2dConvert10bit(ch);
//return ADCW;
low = ADCL;
high = ADCH;
return (high << 8) | low;
}
*/
int analogRead(int pin)
{
unsigned int low, high, ch = analogInPinToBit(pin);
// the low 4 bits of ADMUX select the ADC channel
ADMUX = (ADMUX & (unsigned int) 0xf0) | (ch & (unsigned int) 0x0f);
// without a delay, we seem to read from the wrong channel
delay(1);
// start the conversion
sbi(ADCSRA, ADSC);
// ADSC is cleared when the conversion finishes
while (bit_is_set(ADCSRA, ADSC));
// we have to read ADCL first; doing so locks both ADCL
// and ADCH until ADCH is read. reading ADCL second would
// cause the results of each conversion to be discarded,
// as ADCL and ADCH would be locked when it completed.
low = ADCL;
high = ADCH;
// combine the two bytes
return (high << 8) | low;
}
// Right now, PWM output only works on the pins with
// hardware support. These are defined in the appropriate
// pins_*.c file. For the rest of the pins, we default
// to digital output.
void analogWrite(int pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
if (analogOutPinToBit(pin) == 1) {
pinMode(pin, OUTPUT);
timer1PWMAOn();
timer1PWMASet(val);
} else if (analogOutPinToBit(pin) == 2) {
pinMode(pin, OUTPUT);
timer1PWMBOn();
timer1PWMBSet(val);
} else if (val < 128)
digitalWrite(pin, LOW);
else
digitalWrite(pin, HIGH);
}
void beginSerial(int baud)
{
uartInit();
uartSetBaudRate(baud);
}
void serialWrite(unsigned char c)
{
uartSendByte(c);
}
int serialAvailable()
{
return uartGetRxBuffer()->datalength;
}
int serialRead()
{
return uartGetByte();
}
void printMode(int mode)
{
// do nothing, we only support serial printing, not lcd.
}
void uartSendString(unsigned char *str)
{
while (*str)
uartSendByte(*str++);
}
void print(const char *format, ...)
{
char buf[256];
va_list ap;
va_start(ap, format);
vsnprintf(buf, 256, format, ap);
va_end(ap);
uartSendString(buf);
}
unsigned long millis()
{
// timer 0 increments every timer0GetPrescaler() cycles, and
// overflows when it reaches 256. we calculate the total
// number of clock cycles, then divide by the number of clock
// cycles per millisecond.
return timer0GetOverflowCount() * timer0GetPrescaler() * 256L / F_CPU * 1000L;
}
void delay(unsigned long ms)
{
timerPause(ms);
}
void delayMicro(unsigned long us)
{
delay_us(us);
}
int main(void)
{
sei();
// timer 0 is used for millis() and delay()
timer0Init();
// timer 1 is used for the hardware pwm
timer1Init();
timer1SetPrescaler(TIMER_CLK_DIV1);
timer1PWMInit(8);
//a2dInit();
//a2dSetPrescaler(ADC_PRESCALE_DIV128);
// set a2d reference to AVCC (5 volts)
cbi(ADMUX, REFS1);
sbi(ADMUX, REFS0);
// set a2d prescale factor to 128
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
// XXX: this will not work properly for other clock speeds, and
// this code should use F_CPU to determine the prescale factor.
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);
// enable a2d conversions
sbi(ADCSRA, ADEN);
setup();
for (;;)
loop();
return 0;
}

88
targets/arduino/wiring.h Executable file
View File

@ -0,0 +1,88 @@
/*
wiring.h - Wiring API Partial Implementation
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h,v 1.4 2005/05/24 17:47:41 mellis Exp $
*/
#ifndef Wiring_h
#define Wiring_h
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define true 0x1
#define false 0x0
#define PI 3.14159265
#define HALF_PI 1.57079
#define TWO_PI 6.283185
#define SERIAL 0x0
#define DISPLAY 0x1
#define NOT_A_PIN 0
#define NOT_A_PORT -1
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a>b)?(a):(b))
#define abs(x) ((x>0)?(x):(-x))
#define constrain(amt,low,high) ((amt<low)?(low):((amt>high)?(high):(amt)))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
typedef uint8_t boolean;
typedef uint8_t byte;
void delay(unsigned long);
void delay_ms(unsigned short ms);
void delayMicro(unsigned long us);
void pinMode(int, int);
void digitalWrite(int, int);
int digitalRead(int);
void analogWrite(int, int);
int analogRead(int);
unsigned long millis(void);
void setup(void);
void loop(void);
void beginSerial(int);
void serialWrite(unsigned char);
int serialAvailable();
int serialRead();
void print(const char *, ...);
void printMode(int);
typedef struct {
int port;
int bit;
} pin_t;
extern int port_to_mode[];
extern int port_to_input[];
extern int port_to_output[];
extern pin_t *digital_pin_to_port;
extern pin_t *analog_in_pin_to_port;
extern pin_t *analog_out_pin_to_port;
#endif

119
targets/atmega8/pins_atmega8.c Executable file
View File

@ -0,0 +1,119 @@
/*
pin_atmega8.c - pin definitions for the atmega8
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: pins_atmega8.c,v 1.4 2005/05/24 17:47:41 mellis Exp $
*/
#include <avr/io.h>
#include "wiring.h"
// We map the pin numbers passed to digitalRead() or
// analogRead() directly to the corresponding pin
// numbers on the Atmega8. No distinction is made
// between analog and digital pins.
// ATMEL ATMEGA8
//
// +-\/-+
// PC6 1| |28 PC5
// PD0 2| |27 PC4
// PD1 3| |26 PC3
// PD2 4| |25 PC2
// PD3 5| |24 PC1
// PD4 6| |23 PC0
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5
// PD5 11| |18 PB4
// PD6 12| |17 PB3
// PD7 13| |16 PB2
// PB0 14| |15 PB1
// +----+
#define NUM_PINS 28
#define NUM_PORTS 4
#define PB 2
#define PC 3
#define PD 4
int port_to_mode[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(DDRB),
_SFR_IO_ADDR(DDRC),
_SFR_IO_ADDR(DDRD),
};
int port_to_output[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PORTB),
_SFR_IO_ADDR(PORTC),
_SFR_IO_ADDR(PORTD),
};
int port_to_input[NUM_PORTS + 1] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PINB),
_SFR_IO_ADDR(PINC),
_SFR_IO_ADDR(PIND),
};
pin_t digital_pin_to_port_array[] = {
{ NOT_A_PIN, NOT_A_PIN },
{ PC, 6 },
{ PD, 0 },
{ PD, 1 },
{ PD, 2 },
{ PD, 3 },
{ PD, 4 },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ PB, 6 },
{ PB, 7 },
{ PD, 5 },
{ PD, 6 },
{ PD, 7 },
{ PB, 0 },
{ PB, 1 },
{ PB, 2 },
{ PB, 3 },
{ PB, 4 },
{ PB, 5 },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ PC, 0 },
{ PC, 1 },
{ PC, 2 },
{ PC, 3 },
{ PC, 4 },
{ PC, 5 },
};
pin_t *digital_pin_to_port = digital_pin_to_port_array;
pin_t *analog_in_pin_to_port = digital_pin_to_port_array;
pin_t *analog_out_pin_to_port = digital_pin_to_port_array;

52
targets/wiring/Matrix.h Executable file
View File

@ -0,0 +1,52 @@
/*
Matrix.h - Max7219 LED Matrix library file for Wiring
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-2005 Hernando Barragan
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
Max7219 LED Matrix library by Nicholas Zambetti
*/
#ifndef Matrix_h
#define Matrix_h
#include <inttypes.h>
class Matrix
{
private:
uint8_t _pinClock;
uint8_t _pinLoad;
uint8_t _pinData;
uint8_t _screenBuffer[8];
void putByte(uint8_t);
public:
Matrix(uint8_t, uint8_t, uint8_t);
void set(uint8_t, uint8_t);
void setAll(uint8_t);
void setScanLimit(uint8_t);
void setIntensity(uint8_t);
void storePixel(uint8_t, uint8_t, uint8_t);
void updatePixels(void);
};
#endif

53
targets/wiring/Servo.h Executable file
View File

@ -0,0 +1,53 @@
/*
Servo.h - Servo library file for Wiring
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-2005 Hernando Barragan
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
Servo library by Nicholas Zambetti
*/
#ifndef Servo_h
#define Servo_h
#include <inttypes.h>
class Servo
{
private:
uint8_t _index;
uint8_t _pin;
uint16_t _duty;
static uint8_t _count;
static Servo* _servos[];
static int8_t _current;
static uint16_t _positionTicks;
static void start();
static void end();
static void service();
public:
Servo();
uint8_t attach(int);
void detach();
void write(int);
uint8_t read();
uint8_t attached();
};
#endif

BIN
targets/wiring/Servo.o Normal file

Binary file not shown.

BIN
targets/wiring/WApplet.o Normal file

Binary file not shown.

246
targets/wiring/WConstants.h Executable file
View File

@ -0,0 +1,246 @@
/*
WConstats.h - main definitions file for Wiring
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-2005 Hernando Barragan
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
*/
#ifndef WConstants_h
#define WConstants_h
#define PI (3.1415927)
#define HALF_PI (1.57079)
#define TWO_PI (6.2831854)
#define DEG_TO_RAD (0.01745329)
#define RAD_TO_DEG (57.2957786)
#define EPSILON (0.0001)
#define WPIN0 (1<<0)
#define WPIN1 (1<<1)
#define WPIN2 (1<<2)
#define WPIN3 (1<<3)
#define WPIN4 (1<<4)
#define WPIN5 (1<<5)
#define WPIN6 (1<<6)
#define WPIN7 (1<<7)
#define WPWMPIN5 (1<<5) // PINB5
#define WPWMPIN4 (1<<6) // PINB6
#define WPWMPIN3 (1<<7) // PINB7
#define WPWMPIN2 (1<<3) // PINE3
#define WPWMPIN1 (1<<4) // PINE4
#define WPWMPIN0 (1<<5) // PINE5
#define WPORTA PORTA
#define WPORTB PORTB
#define WPORTC PORTC
#define WPORTD PORTD
#define WPORTE PORTE
#define WPORTF PORTF
#define WPORTG PORTG
#define WPINA PINA
#define WPINB PINB
#define WPINC PINC
#define WPIND PIND
#define WPINE PINE
#define WPINF PINF
#define WPING PING
#define WDDRA DDRA
#define WDDRB DDRB
#define WDDRC DDRC
#define WDDRD DDRD
#define WDDRE DDRE
#define WDDRF DDRF
#define WDDRG DDRG
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define true 0x1
#define false 0x0
#define CPU_FREQ 16000000L
#define TIMER0OVERFLOW_INT 0
#define TIMER0OUTCOMPARE_INT 1
#define TIMER1OVERFLOW_INT 2
#define TIMER1OUTCOMPAREA_INT 3
#define TIMER1OUTCOMPAREB_INT 4
#define TIMER1OUTCOMPAREC_INT 5
#define TIMER1INPUTCAPTURE_INT 6
#define TIMER2OVERFLOW_INT 7
#define TIMER2OUTCOMPARE_INT 8
#define TIMER3OVERFLOW_INT 9
#define TIMER3OUTCOMPAREA_INT 10
#define TIMER3OUTCOMPAREB_INT 11
#define TIMER3OUTCOMPAREC_INT 12
#define TIMER3INPUTCAPTURE_INT 13
#define TIMER_NUM_INTERRUPTS 14
#define TIMER_CLK_STOP 0x00
#define TIMER_CLK_DIV1 0x01
#define TIMER_CLK_DIV8 0x02
#define TIMER_CLK_DIV64 0x03
#define TIMER_CLK_DIV256 0x04
#define TIMER_CLK_DIV1024 0x05
#define TIMER_CLK_T_FALL 0x06
#define TIMER_CLK_T_RISE 0x07
#define TIMER_PRESCALE_MASK 0x07
#define TIMERRTC_CLK_STOP 0x00
#define TIMERRTC_CLK_DIV1 0x01
#define TIMERRTC_CLK_DIV8 0x02
#define TIMERRTC_CLK_DIV32 0x03
#define TIMERRTC_CLK_DIV64 0x04
#define TIMERRTC_CLK_DIV128 0x05
#define TIMERRTC_CLK_DIV256 0x06
#define TIMERRTC_CLK_DIV1024 0x07
#define TIMERRTC_PRESCALE_MASK 0x07
#define TIMER0PRESCALE TIMERRTC_CLK_DIV64
#define TIMER1PRESCALE TIMER_CLK_DIV64
#define TIMER2PRESCALE TIMER_CLK_DIV8
#define TIMER3PRESCALE TIMER_CLK_DIV64
#ifndef __cplusplus
volatile struct {
uint8_t rxInt : 1;
uint8_t rx1Int : 1;
uint8_t uart0TxComplete : 1;
uint8_t uart1TxComplete : 1;
} event;
#endif
typedef struct wbuffer_t {
uint16_t buflen;
uint16_t bufcnt;
uint8_t * in;
uint8_t * out;
uint8_t * buf;
} WBuffer;
typedef struct {
void (*begin) (int);
uint8_t (*available) ();
int (*read) ();
void (*write) (int);
void (*writeBytes) (char[]);
} WSerial;
extern WSerial Serial1;
extern WSerial Serial;
typedef uint8_t boolean;
typedef uint8_t byte;
//int serial;
#define DEF_UART 0
#define AUX_UART 1
#define SERIAL0 0
#define SERIAL1 1
#define UART_BUF_LEN 32
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a>b)?(a):(b))
#define abs(x) ((x>0)?(x):(-x))
#define constrain(amt,low,high) ((amt<low)?(low):((amt>high)?(high):(amt)))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define SERVO_NUM_CHANNELS 8
#define SERVO_MAX 142
#define SERVO_MIN 34
#define POSITION_MAX 255
#define SERVO_DEFAULT_PORT PORTA
//static char uartBuffer[UART_BUF_LEN];
//WBuffer uartbuf;
typedef void (*voidFuncPtru08)(void);
volatile static voidFuncPtru08 uartRxFunc;
typedef void (*voidFuncPtr)(void);
#define WD_CTRL_PORT PORTC
#define WD_CTRL_DDR DDRC
#define WD_CTRL_RS 0
#define WD_CTRL_RW 1
#define WD_CTRL_E 2
#define WD_DATA_POUT PORTA
#define WD_DATA_PIN PINA
#define WD_DATA_DDR DDRA
#define WD_LINE0_DDRAMADDR 0x00
#define WD_LINE1_DDRAMADDR 0x40
#define WD_LINE2_DDRAMADDR 0x14
#define WD_LINE3_DDRAMADDR 0x54
#define WD_CLR 0
#define WD_HOME 1
#define WD_ENTRY_MODE 2
#define WD_ENTRY_INC 1
#define WD_ENTRY_SHIFT 0
#define WD_ON_CTRL 3
#define WD_ON_DISPLAY 2
#define WD_ON_CURSOR 1
#define WD_ON_BLINK 0
#define WD_MOVE 4
#define WD_MOVE_DISP 3
#define WD_MOVE_RIGHT 2
#define WD_FUNCTION 5
#define WD_FUNCTION_8BIT 4
#define WD_FUNCTION_2LINES 3
#define WD_FUNCTION_10DOTS 2
#define WD_CGRAM 6
#define WD_DDRAM 7
#define WD_BUSY 7
#define DATA_8_BITS 0x0
#define DATA_4_BITS 0x1
#define SERIAL 0x0
#define DISPLAY 0x1
#define EXTERNAL_NUM_INTERRUPTS 8
#define NUM_ENCODERS 4
#define EXTERNAL_INT_0 0
#define EXTERNAL_INT_1 1
#define EXTERNAL_INT_2 2
#define EXTERNAL_INT_3 3
#define EXTERNAL_INT_4 4
#define EXTERNAL_INT_5 5
#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7
#ifndef __cplusplus
void print(const char *template, ...);
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
void delay(int);
#endif
#endif

BIN
targets/wiring/WCounter.o Normal file

Binary file not shown.

BIN
targets/wiring/WDisplay.o Normal file

Binary file not shown.

BIN
targets/wiring/WEncoder.o Normal file

Binary file not shown.

Binary file not shown.

86
targets/wiring/WProgram.h Executable file
View File

@ -0,0 +1,86 @@
extern "C" {
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/delay.h>
#include "WConstants.h"
// main program prototypes
void setup(void);
void loop(void);
// timing prototypes
void delay(int);
int millis(void);
// pin prototypes
void pinMode(uint8_t, uint8_t);
uint8_t digitalRead(uint8_t);
void digitalWrite(int, uint8_t);
void portMode(int, int);
int portRead(int);
void portWrite(int, int);
int analogRead(int);
void analogWrite(int, int);
// pulse prototypes
void beginPulse(void);
void endPulse(void);
void pulseFrequency(int, int);
void pulseRun(int, int);
void pulseStop(int);
int pulseRunning(int);
uint16_t pulseIn(uint8_t, uint8_t);
// interrupt management prototypes
void attachInterrupt(uint8_t, void *(void) );
void detachInterrupt(uint8_t);
// serial prototypes
void beginSerial(int);
void endSerial(void);
int serialRead(void);
void serialWrite(int);
void serialWriteBytes(char[]);
uint8_t serialAvailable(void);
void beginSerial1(int);
void endSerial1(void);
int serial1Read(void);
void serial1Write(int);
void serial1WriteBytes(char[]);
uint8_t serial1Available(void);
void printMode(int);
void print(const char *, ...);
/*
// servo prototypes
void beginServo(void);
void endServo(void);
void attachServo(int, int);
uint8_t servoRead(int);
void servoWrite(int, int);
*/
// lcd prototypes
void beginDisplay(void);
void endDisplay(void);
void displayWrite(int);
void displayClear(void);
void cursorHome(void);
void cursorMoveTo(uint8_t, uint8_t);
// encoder prototypes
void beginEncoder(void);
void endEncoder(void);
void attachEncoder(int, int, int);
int32_t encoderRead(uint8_t);
void encoderWrite(uint8_t, uint32_t);
}
// library includes
#include "Servo.h"
//#include "Wire.h"
//#include "Matrix.h"

BIN
targets/wiring/WSerial.o Normal file

Binary file not shown.

BIN
targets/wiring/WTimer.o Normal file

Binary file not shown.

83
targets/wiring/Wire.h Executable file
View File

@ -0,0 +1,83 @@
/*
Wire.h - TWI/I2C library file for Wiring
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-2005 Hernando Barragan
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
Wire TWI/I2C library by Nicholas Zambetti
*/
#ifndef Wire_h
#define Wire_h
#include <inttypes.h>
#ifndef TWI_FREQ
#define TWI_FREQ 100000L
#endif
#ifndef TWI_BUFFERSIZE
#define TWI_BUFFERSIZE 32
#endif
class Wire
{
private:
static volatile uint8_t _state;
static uint8_t _slarw;
static uint8_t _masterBuffer[TWI_BUFFERSIZE];
static uint8_t _masterBufferLength;
static volatile uint8_t _masterBufferIndex;
static void (*Wire::_onSlaveTransmit)(void);
static void (*Wire::_onSlaveReceive)(int);
static uint8_t _txBuffer[TWI_BUFFERSIZE];
static volatile uint8_t _txBufferIndex;
static volatile uint8_t _txBufferLength;
static uint8_t _rxBuffer[TWI_BUFFERSIZE];
static volatile uint8_t _rxBufferIndex;
uint8_t readFrom(uint8_t, uint8_t*, uint8_t);
uint8_t writeTo(uint8_t, uint8_t*, uint8_t, uint8_t);
static void reply(uint8_t);
static void stop(void);
static void releaseBus(void);
static void interruptLogic(void);
public:
Wire(uint8_t);
uint8_t read(int);
void readBytes(int, uint8_t*, int);
void readBytes(int, char*, int);
void write(int, int);
void writeBytes(int, uint8_t*, int);
void writeBytes(int, char*);
void transmit(uint8_t);
void transmitBytes(uint8_t*, uint8_t);
void transmitBytes(char*);
uint8_t receive(void);
void receiveBytes(uint8_t*);
void receiveBytes(char*);
void onDataIn( void (*)(int) );
void onDataOut( void (*)(void) );
};
#endif

BIN
targets/wiring/Wire.o Normal file

Binary file not shown.