First commit, Working Version

This commit is contained in:
unknown 2012-07-17 20:09:48 -06:00
commit 91744bc720
25 changed files with 27076 additions and 0 deletions

46
code/.gitignore vendored Normal file
View File

@ -0,0 +1,46 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.o.d
*.lst
*.so
*.eep
*.elf
*.hex
*.lss
*.map
*.sym
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

635
code/Makefile Normal file
View File

@ -0,0 +1,635 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = atmega168
PROG_DEVICE = M168
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
# Typical values are:
# F_CPU = 1000000
# F_CPU = 1843200
# F_CPU = 2000000
# F_CPU = 3686400
# F_CPU = 4000000
# F_CPU = 7372800
# F_CPU = 8000000
# F_CPU = 11059200
# F_CPU = 14745600
# F_CPU = 16000000
# F_CPU = 18432000
# F_CPU = 20000000
F_CPU = 12000000
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = main
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
OBJDIR = bin
# List C source files here. (C dependencies are automatically generated.)
SRC += src/main.c
SRC += src/USART.c
SRC += src/task_man.c
SRC += src/AVC.c
SRC += src/AVC_messages.c
SRC += src/bluetooth.c
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = 2
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = stabs
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS =
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
#CPPDEFS += -D__STDC_LIMIT_MACROS
#CPPDEFS += -D__STDC_CONSTANT_MACROS
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -Wall
#CFLAGS += -Wstrict-prototypes
CFLAGS += -Iusbdrv -I. -DDEBUG_LEVEL=0
#CFLAGS += -mshort-calls
#CFLAGS += -fno-unit-at-a-time
#CFLAGS += -Wundef
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wsign-compare
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += -ffunction-sections
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -fno-exceptions
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
#CPPFLAGS += -mshort-calls
#CPPFLAGS += -fno-unit-at-a-time
#CPPFLAGS += -Wstrict-prototypes
#CPPFLAGS += -Wunreachable-code
#CPPFLAGS += -Wsign-compare
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS =
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
LDFLAGS += -Wl,--gc-sections
#---------------- Programming Options (avrdude) ----------------
# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = usbtiny
# 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
AVRDUDE_WRITE_FUSE = -U lfuse:w:0xcf:m -U hfuse:w:0xdf:m -U efuse:w:0x01:m
# 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 $(PROG_DEVICE) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
#$(AVRDUDE_WRITE_FUSE)
#$(AVRDUDE_WRITE_EEPROM)
program-flash: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
program-fuse: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSE)
program-eeprom: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
create-eeprom:
printf "\x010 ZOO \nRules!!\n" > ee_tmp.bin
avr-objcopy -I binary -O ihex ee_tmp.bin $(TARGET).eep
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
@$(REMOVE) $(GDBINIT_FILE)
@echo define reset >> $(GDBINIT_FILE)
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
@echo end >> $(GDBINIT_FILE)
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
@echo load >> $(GDBINIT_FILE)
endif
@echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
@$(WINSHELL) /c pause
else
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT = $(OBJCOPY) --debugging
COFFCONVERT += --change-section-address .data-0x800000
COFFCONVERT += --change-section-address .bss-0x800000
COFFCONVERT += --change-section-address .noinit-0x800000
COFFCONVERT += --change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
@echo
@echo $(MSG_CREATING_LIBRARY) $@
$(AR) $@ $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
@echo
@echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) $(SRC:.c=.i)
$(REMOVEDIR) .dep
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program debug gdb-config

578
code/src/AVC.c Normal file
View File

@ -0,0 +1,578 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stddef.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <stdio.h>
#include "task_man.h"
#include "USART.h"
#include "AVC.h"
#include "AVC_MACROS.h"
#include "AVC_messages.h"
#include "bluetooth.h"
extern MSG_IDENTIFIER message_identification_list [];
static void AVC_process_received_messages(void);
static void remove_head_rx_msg(void);
static MSG_ID find_message_id(MESSAGE* msg);
static volatile uint8_t parity = 0;
static volatile uint8_t broadcast = 0;
static volatile uint16_t master_address = 0;
static volatile uint16_t slave_address = 0;
static volatile uint8_t control;
static volatile uint8_t data_size;
static volatile uint8_t data[ MAX_DATA_BUFFER ];
static volatile uint16_t data_bits = 0;
static volatile uint8_t bit_count = 0;
static volatile uint16_t bit_mask = 0;
static volatile uint8_t data_count = 0;
static volatile AVC_FRAMES bit_frame = IDLE;
static MESSAGE message_tx_buffer[MAX_MESSAGE_CNT_TX];
static MESSAGE message_rx_buffer[MAX_MESSAGE_CNT_RX];
static MESSAGE* message_tx_head;//pop here
static MESSAGE* message_tx_tail;//insert here
static MESSAGE* message_rx_head;//pop here
static MESSAGE* message_rx_tail;//insert here
static uint8_t usart_quiet = 0;
static uint8_t IS_PLAYING = 0;
static uint8_t SECONDS = 0;
static uint8_t MINUTES = 0;
void status_update(void){
if(IS_PLAYING){
MESSAGE* msg = AVC_add_tx_transaction_from_list(SELF_PLAYING_STATUS);
msg->data[8] = AVC_Toyota_digits(SECONDS++);
msg->data[7] = AVC_Toyota_digits(MINUTES);
sei();
if(SECONDS == 60){
SECONDS = 0;
MINUTES++;
}
if(MINUTES == 60){
MINUTES = 0;
}
}
}
void AVC_init(uint8_t quiet){
usart_quiet = quiet;
message_tx_head = message_tx_buffer;
message_tx_tail = message_tx_head;
message_rx_head = message_rx_buffer;
message_rx_tail = message_rx_head;
add_task_no_arg(AVC_process_received_messages, SYSTEM_20_ms, SYSTEM_5_ms, 0);
AVC_DDR &= ~(1<<RI);
AVC_DDR |= (1<<TO) | (1<<RE) | (1<<TE);
AVC_PORT &= ~( (1<<RI) | (1<<TO) | (1<<RE) | (1<<TE) );
//setup timer for avc communication 16 bits are
// needed to keep best resolution and full scale of data.
TCNT1 = 0; //count is 0;
TCCR1A = 0; // Normal mode
TCCR1B = 1<<CS10; // NO PRESCALLING
EICRA = (1<<ISC00); //any change triggeres intterupt
EIMSK = (1<<INT0); //enable pin interrupt INT0
TCNT1 = 0; //count is 0;
OCR1A = LINE_BUSY_CHECK;
TIMSK1 |= (1<<OCIE1A); //enable send ISR to watch for free/busy line
add_task_no_arg(status_update, SYSTEM_1_S, 0, 0);
}
MESSAGE* AVC_add_tx_transaction_from_list(MSG_ID id){
MESSAGE* msg;
while((msg = AVC_add_tx_transaction( pgm_read_word(&(message_identification_list[id].slave)),
pgm_read_byte(&(message_identification_list[id].broadcast)),
pgm_read_byte(&(message_identification_list[id].control)),
pgm_read_byte(&(message_identification_list[id].data_size)),
message_identification_list[id].data, 0) ) == NULL) {sei();}
if(!usart_quiet){
usart_put_c_str( PSTR("-->\r\n"));
usart_put_c_str( message_identification_list[id].description);
usart_put_c_str( PSTR("\r\n"));
}
return msg;
}
MESSAGE* AVC_add_tx_transaction(uint16_t address_arg, uint8_t broadcast_arg, uint8_t control_arg, uint8_t data_size_arg, uint8_t * data_arg, uint8_t print){
cli(); //we don't want to accidentaly update trasaction head AND tail at the same time.
//no room left to allocate tasks
MESSAGE* tx_tail = ++message_tx_tail;
message_tx_tail--;
// if at end, reset
if(tx_tail == message_tx_buffer + MAX_MESSAGE_CNT_TX)
tx_tail = message_tx_buffer;
//no room left in TX buffer
if( tx_tail == message_tx_head ){
sei();
return NULL;
}
else{
//fetch current item.
sei(); //enable interupts again. while we do things here... (tail will still be at old place so data won't be sent prematurely)
message_tx_tail->master_address = MY_ADDRESS;
message_tx_tail->slave_address = address_arg;
message_tx_tail->broadcast = broadcast_arg;
message_tx_tail->control = control_arg;
message_tx_tail->data_size = data_size_arg;
while(data_size_arg){
data_size_arg--;
message_tx_tail->data[data_size_arg] = pgm_read_byte(&(data_arg[data_size_arg]));
}
if(print && !usart_quiet){
usart_put_c_str( PSTR("-->\r\n"));
usart_put_c_str( PSTR("B: "));
usart_put_byte(broadcast_arg);
usart_put_c_str( PSTR("\r\nM: "));
usart_put_int_hex(MY_ADDRESS);
usart_put_c_str( PSTR("\r\nS: "));
usart_put_int_hex(address_arg);
usart_put_c_str( PSTR("\r\nC: "));
usart_put_byte_hex(control_arg);
usart_put_c_str( PSTR("\r\nL: "));
uint8_t data_s = data_size_arg;
usart_put_byte(data_s);
usart_put_c_str( PSTR("\r\nD: "));
uint8_t* data_ptr = message_tx_tail->data;
if(data_s > MAX_DATA_BUFFER)
data_s = MAX_DATA_BUFFER;
while(data_s > 0 ){
data_s--;
usart_put_byte_hex(*data_ptr);
usart_put_c(' ');
data_ptr++;
}
usart_put_c_str( PSTR("\r\n\r\n"));
}
cli();
//save for return value
MESSAGE* msg_ptr = message_tx_tail;
//increment tail to new.
message_tx_tail= tx_tail;
//**NOTE**
//we don't enable intterrupt as we MAY want to edit data quickly. DON'T forget to re-enable them!!!
return msg_ptr;
}
}
static MSG_ID find_message_id(MESSAGE* msg){
for(MSG_ID msg_id = 0; msg_id < MESSAGE_ID_SIZE; msg_id++){
//match master, slave, broadcast, control, and data length.
if( (msg->broadcast == pgm_read_byte(&(message_identification_list[msg_id].broadcast)) ) &&
(msg->master_address == pgm_read_word(&(message_identification_list[msg_id].master))) &&
(msg->slave_address == pgm_read_word(&(message_identification_list[msg_id].slave)) ) &&
(msg->control == pgm_read_byte(&(message_identification_list[msg_id].control)) ) &&
(msg->data_size == pgm_read_byte(&(message_identification_list[msg_id].data_size)) )){
uint8_t match = 1;
for(int i = 0; i < msg->data_size; i++){
if(pgm_read_byte(&(message_identification_list[msg_id].data_ignore[i])) || msg->data[i] == pgm_read_byte(&(message_identification_list[msg_id].data[i])) )
{}
else
{
match = 0;
break;
}
}
if(match){
return msg_id;
}
}
}
return MESSAGE_ID_SIZE;
}
void handle_message(MSG_ID id){
switch(id){
case CD_CH_LAN_CHECK:
{
MESSAGE* message;
while( (message = AVC_add_tx_transaction_from_list(RESP_LAN_CHECK)) == NULL){
sei();//release while we don't have something.
}
message->data[4] = message_rx_head->data[4];
sei();//release once we have altered what we need to.
}
break;
case CONSOLE_DISK_BUTTON_1:
{
MESSAGE* message;
while( (message = AVC_add_tx_transaction_from_list(RESP_DISK_BUTTON_1)) == NULL){
sei();
}
sei();
}
break;
case CONSOLE_DISK_BUTTON_2:
{
MESSAGE* message;
while( (message = AVC_add_tx_transaction_from_list(RESP_DISK_BUTTON_2_0)) == NULL){
sei();
}
sei();
while( (message = AVC_add_tx_transaction_from_list(RESP_DISK_BUTTON_2_1)) == NULL){
sei();
}
sei();
}
break;
case CONSOLE_DISK_PLAY:
{
if(!IS_PLAYING){
MESSAGE* message;
while( (message = AVC_add_tx_transaction_from_list(RESP_CONSOLE_DISK_PLAY_0)) == NULL){
sei();
}
sei();
while( (message = AVC_add_tx_transaction_from_list(RESP_CONSOLE_DISK_PLAY_1)) == NULL){
sei();
}
sei();
SECONDS = 0;
MINUTES = 0;
IS_PLAYING = 1;
bluetooth_play_song();
}
}
break;
case CONSOLE_DISK_STOP:
{
if(IS_PLAYING){
MESSAGE* message;
while( (message = AVC_add_tx_transaction_from_list(RESP_CONSOLE_DISK_STOP_0)) == NULL){
sei();
}
sei();
while( (message = AVC_add_tx_transaction_from_list(RESP_CONSOLE_DISK_STOP_1)) == NULL){
sei();
}
sei();
IS_PLAYING = 0;
bluetooth_pause_song();
}
}
break;
case CONSOLE_SEEK_UP:
{
if(IS_PLAYING){
bluetooth_next_song();
}
}
break;
case CONSOLE_SEEK_DOWN:
{
if(IS_PLAYING){
bluetooth_previous_song();
}
}
default:
break;
}
}
void AVC_process_received_messages(){
if(MSG_RECEIVED)
{
MSG_ID id = find_message_id(message_rx_head);
if(id == MESSAGE_ID_SIZE && !usart_quiet){
usart_put_c_str( PSTR("<--\r\n"));
usart_put_c_str( PSTR("B: "));
usart_put_byte(message_rx_head->broadcast);
usart_put_c_str( PSTR("\r\nM: "));
usart_put_int_hex(message_rx_head->master_address);
usart_put_c_str( PSTR("\r\nS: "));
usart_put_int_hex(message_rx_head->slave_address);
usart_put_c_str( PSTR("\r\nC: "));
usart_put_byte_hex(message_rx_head->control);
usart_put_c_str( PSTR("\r\nL: "));
uint8_t data_s = message_rx_head->data_size;
usart_put_byte(data_s);
usart_put_c_str( PSTR("\r\nD: "));
uint8_t* data_ptr = message_rx_head->data;
if(data_s > MAX_DATA_BUFFER)
data_s = MAX_DATA_BUFFER;
while(data_s > 0 ){
data_s--;
usart_put_byte_hex(*data_ptr);
usart_put_c(' ');
data_ptr++;
}
usart_put_c_str( PSTR("\r\n\r\n"));
}
else{
if(!usart_quiet){
usart_put_c_str( PSTR("<--\r\n"));
usart_put_c_str( PSTR("MSG: "));
usart_put_c_str( message_identification_list[id].description);
usart_put_c_str( PSTR("\r\n"));
}
handle_message(id);
}
remove_head_rx_msg();
}
}
void remove_head_rx_msg(){
//re-cover msg stack place;
cli();
message_rx_head++;
if(message_rx_head == message_rx_buffer + MAX_MESSAGE_CNT_RX)
message_rx_head = message_rx_buffer;
sei();
}
uint8_t AVC_Toyota_digits(uint8_t num){
uint8_t hex = 0;
hex |= num%10;
hex |= (num/10)<<4;
return hex;
}
/* The way this works, is via a well-defined switch case statement.
** Data is placed and sensed via the external interrupt pint on the
** microcontroller. When it is pulsed, if it is a rising edge, it triggers
** data capture. I did make an attempt at "outside of ISR" handling,
** but the requests just became unsynchronised and parity mismatch exploded.
**
** **********BUG LIST********
** ) For some reason, During one of the DATA_PAYLOAD instances, the parity
** check fails. I have yet to determine why, but it is not frequent enough
** to stop development entirely. I suspect it is just timing of data that
** could be tweaked a bit.
** *****FIX????: Turns out that this code is VERY time sensitive. It comes
** so close to being able to catch the bits in time, that I had to take care
** of (remove or make no_block) other ISRs to ensure the code could catch
** the bits in time. USART driver is now polling based for transmit, and
** utilizes the new task queue to do it's job. The timer for task_man is now
** no_block, which will mean that the timer could be off by up to several ms.
** The ONLY way I could see a better way would be to do this is with a faster
** osclillator :)
*/
ISR(INT0_vect){
uint16_t count = TCNT1; //grab timer value
RESET_TIMER(); //reset timer for value checking
if(REC_HIGH){
//insert room for bit, add to counter
data_bits <<=1;
if(FRAME_IS_IDLE && count > START_BIT_HOLD_LOW_CHECK ){
data_bits = 1;
bit_frame = START;
}
else if(count < BIT_POLL_LENGTH)
{
// Set new bit.
data_bits |= 0x0001;
parity = !parity;
}
// if(!FRAME_IS_ERROR && !FRAME_IS_FINISHED && !FRAME_IS_IDLE)
switch(bit_frame){
case IDLE:
break;
case START:
FRAMING_RESET();
FRAMING_NEXT();
break;
case BROADCAST:
broadcast = data_bits;
FRAMING_RESET();
FRAMING_NEXT();
break;
case MASTER_ADDR:
master_address = data_bits>>1;
FRAMING_NEXT();
FRAMING_PARITY_CHECK();
FRAMING_RESET();
break;
case SLAVE_ADDR:
slave_address = data_bits>>1;
FRAMING_NEXT();
FRAMING_PARITY_CHECK();
FRAMING_RESET();
if(FRAMING_FOR_ME){
FRAMING_SEND_ACK();
FRAMING_NEXT();
}
break;
case SLAVE_ACK:
FRAMING_RESET();
FRAMING_NEXT();
break;
case CONTROL:
control = data_bits>>1;
FRAMING_NEXT();
FRAMING_PARITY_CHECK();
FRAMING_RESET();
if(FRAMING_FOR_ME){
FRAMING_SEND_ACK();
FRAMING_NEXT();
}
break;
case CONTROL_ACK:
FRAMING_RESET();
FRAMING_NEXT();
break;
case DATA_SIZE:
data_size = data_bits>>1;
FRAMING_NEXT();
FRAMING_PARITY_CHECK();
FRAMING_READY_DATA();
FRAMING_RESET();
if(FRAMING_FOR_ME){
FRAMING_SEND_ACK();
FRAMING_NEXT();
}
break;
case DATA_SIZE_ACK:
FRAMING_RESET();
FRAMING_DATA_ACK_CHECK();
break;
case DATA_PAYLOAD:
data[data_count++] = data_bits>>1;
FRAMING_NEXT();
FRAMING_PARITY_CHECK();
FRAMING_RESET();
if(FRAMING_FOR_ME){
FRAMING_SEND_ACK();
FRAMING_DATA_ACK_CHECK();
}
break;
case DATA_PAYLOAD_ACK:
FRAMING_RESET();
FRAMING_DATA_ACK_CHECK(); //end of line, so we use DATA_SIZE_ACK+1.
break;
case FRAME_FINISHED:
break;
case FRAME_ERROR:
break;
default:
FRAMING_NEXT();
break;
}
}
else{
}
}
/* We will try periodlically checking the bus to see if it is active
** and if there are any outstanding transactions that need to be sent.
** If so, we will try to use the same ISR to both detect and send data
** by altering the OCR1A register to accomadate.
*/
ISR(TIMER1_COMPA_vect){
DISABLE_PIN_CHANGE();
//if we got here initially, bit_frame should be in IDLE state. Good to check anyways to be sure!
if(FRAME_IS_IDLE && READY_TO_TRANSMIT){
LOAD_GLOBALS(message_tx_head);
SEND_START_BIT();
SEND_BROADCAST_BIT();
//master address
SEND_ADDRESS(master_address);
SEND_PARITY();
SEND_ADDRESS(slave_address);
SEND_PARITY();
//ACK
ACKNOWLEDGE();
//control
SEND_CONTROL();
//parity bit
SEND_PARITY();
//ACK
ACKNOWLEDGE();
//data Size
SEND_BYTE(data_size);
//parity bit
SEND_PARITY();
//ACK
ACKNOWLEDGE();
//send all our data.
data_count = 0;
while(data_count < data_size){
uint8_t data_to_send = data[data_count++];
SEND_BYTE(data_to_send);
//parity bit
SEND_PARITY();
//ACK
ACKNOWLEDGE();
}
REMOVE_HEAD_TX_MSG();
}
ENABLE_PIN_CHANGE();
RESET_TIMER();
}
//This ISR for the COMPB value will be used to send the ACK needed for transmission.

76
code/src/AVC.h Normal file
View File

@ -0,0 +1,76 @@
#ifndef __AVC_OTHER_H
#define __AVC_OTHER_H
#include "AVC_messages.h"
#define MAX_DATA_BUFFER 20
#define MAX_MESSAGE_CNT_TX 5 //we *SHOULD* only ever queue a handful of messages at any given time.
//using the function provided, it will even stall (in main runtime) until addition successful
#define MAX_MESSAGE_CNT_RX 6 //This is also quite generous, as we have seen that it takes MANY messages to reach this limit.
#define AVC_DDR DDRD
#define AVC_PORT PORTD
#define AVC_PIN PIND
#define RI 2
#define TO 3
#define RE 4
#define TE 5
#define NORMAL_BIT_LENGTH (12*40) //
#define BIT_1_HOLD_LOW_LENGTH (12*20) // 240
#define BIT_0_HOLD_LOW_LENGTH (12*32) // 370
#define BIT_1_HOLD_HIGH_LENGTH (NORMAL_BIT_LENGTH - BIT_1_HOLD_LOW_LENGTH)
#define BIT_0_HOLD_HIGH_LENGTH (NORMAL_BIT_LENGTH - BIT_0_HOLD_LOW_LENGTH)
#define BIT_POLL_LENGTH (BIT_0_HOLD_LOW_LENGTH - ((BIT_0_HOLD_LOW_LENGTH - BIT_1_HOLD_LOW_LENGTH) / 2))
#define ACK_HOLD_TIME (BIT_1_HOLD_LOW_LENGTH)
#define ACK_CHECK_LENGTH ((BIT_0_HOLD_LOW_LENGTH - ((BIT_0_HOLD_LOW_LENGTH - BIT_1_HOLD_LOW_LENGTH) / 2)) - BIT_1_HOLD_LOW_LENGTH)
#define ACK_TIMEOUT (25*12)
#define START_BIT_LENGTH (12*186)
#define START_BIT_HOLD_LOW_LENGTH (12*168)
#define START_BIT_HOLD_LOW_CHECK (12*160)
#define LINE_BUSY_CHECK (12*200)
//AVC framing information to aid the receive parsing.
typedef enum avc_frames{ IDLE = 0,
START = 1,
BROADCAST = 2,
MASTER_ADDR_S = 14,
MASTER_ADDR = 15,
SLAVE_ADDR_S = 27,
SLAVE_ADDR = 28,
SLAVE_ACK = 29,
CONTROL_S = 33,
CONTROL = 34,
CONTROL_ACK = 35,
DATA_SIZE_S = 43,
DATA_SIZE = 44,
DATA_SIZE_ACK = 45,
DATA_PAYLOAD_S = 53,
DATA_PAYLOAD = 54,
DATA_PAYLOAD_ACK = 55,
FRAME_FINISHED = 56,
FRAME_ERROR = 57,
} AVC_FRAMES;
//AVC message structure for received messages, and those to be transmitted.
typedef struct message{
uint16_t master_address;
uint16_t slave_address;
uint8_t broadcast;
uint8_t control;
uint8_t data_size;
uint8_t data[MAX_DATA_BUFFER];
} MESSAGE;
void AVC_init(uint8_t quiet);
MESSAGE* AVC_add_tx_transaction(uint16_t address_arg, uint8_t broadcast_arg, uint8_t control_arg, uint8_t data_size_arg, uint8_t * data_arg, uint8_t print);
MESSAGE* AVC_add_tx_transaction_from_list(MSG_ID id);
uint8_t AVC_Toyota_digits(uint8_t num);
#endif

205
code/src/AVC_MACROS.h Normal file
View File

@ -0,0 +1,205 @@
#ifndef __AVC_MACROS_H
#define __AVC_MACROS_H
#define EN_RECEIVE(){ AVC_PORT &= ~((1<<TE) | (1<<RE)); }
#define EN_TRANSMIT(){ AVC_PORT |= (1<<TE); }
#define DISABLE_TRANSMIT(){ AVC_PORT &= ~(1<<TE); }
#define TRANSMIT_LOW() { AVC_PORT &= ~(1<<TO); EN_TRANSMIT();}
#define TRANSMIT_HIGH() { DISABLE_TRANSMIT();}
#define INPUT_IS_CLEAR (AVC_PIN&(1<<RI))
#define INPUT_IS_SET !(AVC_PIN&(1<<RI))
#define REC_HIGH (AVC_PIN&(1<<RI))
#define REC_LOW !(AVC_PIN&(1<<RI))
/********************************RECEIVE MACROS***************************/
#define MSG_RECEIVED ( message_rx_head != message_rx_tail )
#define FRAMING_FOR_ME (MY_ADDRESS == slave_address)
#define FRAME_IS_IDLE (bit_frame == IDLE)
#define FRAMING_ERROR_HANDLER() { if(!usart_quiet){usart_put_c_str(PSTR("Error: ")); usart_put_byte(bit_frame); usart_put_c_str(PSTR("[")); usart_put_byte_hex(control); usart_put_c_str(PSTR("]\r\n"));} FRAMING_RESTART(); return;}
#define FRAMING_FINISH_HANDLER() { ADD_RECEIVED_TRANSACTION(); FRAMING_RESTART(); return;}
#define FRAMING_RESET() {data_bits = 0; parity = 0;}
#define FRAMING_NEXT() {bit_frame++;}
#define FRAMING_PARITY_CHECK() {if(parity){FRAMING_ERROR_HANDLER();}}
#define FRAMING_READY_DATA() {data_count = 0;}
#define FRAMING_DATA_ACK_CHECK() {if(data_count == data_size){ bit_frame = FRAME_FINISHED; FRAMING_FINISH_HANDLER(); }else{ bit_frame = DATA_SIZE_ACK+1;}}
#define FRAMING_SEND_ACK() { \
TCNT1 = 0; \
while (INPUT_IS_CLEAR) { \
if (TCNT1 >= ACK_TIMEOUT) return; \
}\
TCNT1 = 0;\
TRANSMIT_LOW();\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH); \
TRANSMIT_HIGH(); \
}
#define FRAMING_RESTART() { bit_frame = IDLE;}
#define RESET_TIMER() { TCNT1 = 0;}
#define ADD_RECEIVED_TRANSACTION() {\
MESSAGE* rx_tail = ++message_rx_tail;\
message_rx_tail--;\
if(rx_tail == message_rx_buffer + MAX_MESSAGE_CNT_RX)\
rx_tail = message_rx_buffer;\
\
if( rx_tail == message_rx_head ){\
sei();\
return;\
}\
else{\
\
message_rx_tail->master_address = master_address;\
message_rx_tail->slave_address = slave_address;\
message_rx_tail->broadcast = broadcast;\
message_rx_tail->control = control;\
\
if(data_size > MAX_DATA_BUFFER)\
data_size = MAX_DATA_BUFFER;\
message_rx_tail->data_size = data_size;\
\
while(data_size > 0){\
data_size--;\
message_rx_tail->data[data_size] = data[data_size];\
}\
message_rx_tail = rx_tail;\
}\
}
/**********************SEND MACROS***********************/
#define READY_TO_TRANSMIT ( message_tx_head != message_tx_tail )
#define LOAD_GLOBALS(msg){\
broadcast = msg->broadcast;\
master_address = msg->master_address;\
slave_address = msg->slave_address;\
control = msg->control;\
data_size = msg->data_size ;\
for ( uint8_t i = 0; i < data_size; i++ )\
{\
data[i] = msg->data[i] ;\
}}
#define DISABLE_PIN_CHANGE() {EIMSK &= ~(1<<INT0);}
#define ENABLE_PIN_CHANGE() {EIMSK |= (1<<INT0);}
#define SEND_START_BIT() {\
RESET_TIMER();\
TRANSMIT_LOW();\
while(TCNT1 < START_BIT_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
while(TCNT1 < START_BIT_LENGTH);}
#define SEND_BROADCAST_BIT(){\
TRANSMIT_LOW();\
RESET_TIMER();\
if(broadcast)\
while(TCNT1 < BIT_1_HOLD_LOW_LENGTH);\
else\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
while(TCNT1 < NORMAL_BIT_LENGTH);}
#define SEND_ADDRESS(address){\
bit_mask = (1<<11);\
parity = 0;\
while(bit_mask){\
TRANSMIT_LOW();\
RESET_TIMER();\
if(address&bit_mask){\
parity = !parity;\
while(TCNT1 < BIT_1_HOLD_LOW_LENGTH);\
}\
else\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
bit_mask>>=1;\
while(TCNT1 < NORMAL_BIT_LENGTH);\
}}
#define SEND_CONTROL(){\
bit_mask = (1<<3);\
parity = 0;\
while(bit_mask){\
TRANSMIT_LOW();\
RESET_TIMER();\
if(control&bit_mask){\
parity = !parity;\
while(TCNT1 < BIT_1_HOLD_LOW_LENGTH);\
}\
else\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
bit_mask>>=1;\
while(TCNT1 < NORMAL_BIT_LENGTH);\
}}
#define SEND_BYTE(x){\
bit_mask = (1<<7);\
parity = 0;\
while(bit_mask){\
TRANSMIT_LOW();\
RESET_TIMER();\
if(x&bit_mask){\
parity = !parity;\
while(TCNT1 < BIT_1_HOLD_LOW_LENGTH);\
}\
else\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
bit_mask>>=1;\
while(TCNT1 < NORMAL_BIT_LENGTH);\
}}
#define SEND_PARITY(){\
TRANSMIT_LOW();\
RESET_TIMER();\
if(parity)\
while(TCNT1 < BIT_1_HOLD_LOW_LENGTH);\
else\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
while(TCNT1 < NORMAL_BIT_LENGTH);\
}
#define ACKNOWLEDGE() {\
if (broadcast)\
{\
RESET_TIMER();\
TRANSMIT_LOW();\
while ( TCNT1 < BIT_1_HOLD_LOW_LENGTH );\
TRANSMIT_HIGH();\
while ( INPUT_IS_SET );\
if ( TCNT1 > BIT_POLL_LENGTH)\
{\
while ( INPUT_IS_SET );\
}\
else{\
RESET_TIMER();\
OCR1A = LINE_BUSY_CHECK;\
ENABLE_PIN_CHANGE();\
if(!usart_quiet)\
usart_put_c_str(PSTR("ACK ERROR!\r\n"));\
return;\
}\
}\
else{\
RESET_TIMER();\
TRANSMIT_LOW();\
while(TCNT1 < BIT_0_HOLD_LOW_LENGTH);\
TRANSMIT_HIGH();\
while(TCNT1 < NORMAL_BIT_LENGTH);\
}}\
#define REMOVE_HEAD_TX_MSG() { \
message_tx_head++;\
if(message_tx_head == message_tx_buffer + MAX_MESSAGE_CNT_TX)\
message_tx_head = message_tx_buffer;}
#endif

51
code/src/AVC_messages.c Normal file
View File

@ -0,0 +1,51 @@
#include <avr/pgmspace.h>
#include "AVC_messages.h"
MSG_IDENTIFIER message_identification_list [] PROGMEM = {
{ AUDIO_AUX_IN_USE, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 4, {0x11, 0x01, 0x45, 0x01}, {}, "AUX in use" },
{ AUDIO_TUNER_IN_USE, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 4, {0x11, 0x01, 0x45, 0x60}, {}, "Tuner in use" },
{ AUDIO_TAPE_IN_USE, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 4, {0x11, 0x01, 0x45, 0x61}, {}, "Tape in use" },
{ AUDIO_CD_IN_USE, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 4, {0x11, 0x01, 0x45, 0x62}, {}, "CD in use" },
{ AUDIO_VOLUME_STATUS, 0, HU_ADDRESS, BROADCAST_ADDRESS , CONTROL_FLAGS, 16, {0x74, 0x31, 0xF1, 0x80, '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 0x03, 0x00}, {0, 0, 0, 0, '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 0, 0}, "Volume/Mixer Info"},
{ TUNER_STATUS, 0, HU_ADDRESS, BROADCAST_ADDRESS , CONTROL_FLAGS, 13, {0x60, 0x31, 0xF1, 0x01, '?', '?', '?', '?', '?', '?', 0x00, 0x00, 0x00}, {0, 0, 0, 0, '?', '?', '?', '?', '?', '?', 0, 0, 0}, "Tuner Status"},
{ CD_STATUS, 0, HU_ADDRESS, BROADCAST_ADDRESS , CONTROL_FLAGS, 11, {0x62, 0x31, 0xF1, 0x01, 0x10, '?', '?', '?', '?', 0x00, 0x80}, {0, 0, 0, 0, 0, '?', '?', '?', '?', 0, 0}, "CD Playing Status"},
{ CONSOLE_OFF, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 3, {0x11, 0x01, 0x46}, {}, "Console is off" },
{ LAN_STATUS, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 3, {0x00, 0x01, 0x0A}, {}, "LAN Status" },
{ LAN_REGISTER, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 3, {0x11, 0x01, 0x00}, {}, "LAN Register" },
{ LAN_INIT, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 3, {0x11, 0x01, 0x01}, {}, "LAN Restart" },
{ LAN_CHECK, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 4, {0x11, 0x01, 0x20, '?'}, {0, 0, 0, '?'}, "LAN Check" },
{ CD_CH_LAN_CHECK, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 5, {0x00, 0x11, 0x01, 0x20, '?'}, {0, 0, 0, 0, '?'}, "LAN Check For Me" },
{ RESP_LAN_CHECK, 1, MY_ADDRESS, HU_ADDRESS, CONTROL_FLAGS, 6, {0x00, 0x01, 0x11, 0x30, '?', 0x0}, {0, 0, 0, 0, '?', 0}, "LAN Check Response"},
{ SELF_REGISTER, 1, MY_ADDRESS, HU_ADDRESS, CONTROL_FLAGS, 5, {0x00, 0x01, 0x11, 0x10, 0x63}, {}, "Self-Register"},
{ CONSOLE_DISK_BUTTON_1, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x80}, {}, "Disk Button 1"},
{ RESP_DISK_BUTTON_1, 1, MY_ADDRESS, HU_ADDRESS, CONTROL_FLAGS, 5, {0x00, 0x63, 0x12, 0x50, 0x01}, {}, "Disk Response1"},
{ CONSOLE_DISK_BUTTON_2, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 6, {0x00, 0x11, 0x63, 0x42, 0x01, 0x00}, {}, "Disk Button 2"},
{ RESP_DISK_BUTTON_2_0, 1, MY_ADDRESS, HU_ADDRESS, CONTROL_FLAGS, 5, {0x00, 0x63, 0x12, 0x52, 0x01}, {}, "Disk Response2-0"},
{ RESP_DISK_BUTTON_2_1, 0, MY_ADDRESS, HU_ADDRESS, CONTROL_FLAGS, 11, {0x63, 0x31, 0xF1, 0x01, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x00, 0x80}, {}, "Disk Response2-1"},
{ CONSOLE_DISK_PLAY, 0, HU_ADDRESS, LAN_BROADCAST_ADDRESS, CONTROL_FLAGS, 4, {0x11, 0x01, 0x45, 0x63}, {}, "Console - PLAY"},
{ RESP_CONSOLE_DISK_PLAY_0, 0, MY_ADDRESS, BROADCAST_ADDRESS, CONTROL_FLAGS, 11, {0x63, 0x31, 0xF1, 0x01, 0x28, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80}, {}, "Response PLAY0"},
{ RESP_CONSOLE_DISK_PLAY_1, 0, MY_ADDRESS, BROADCAST_ADDRESS, CONTROL_FLAGS, 11, {0x63, 0x31, 0xF1, 0x01, 0x10, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80}, {}, "Response PLAY1"},
{ SELF_PLAYING_STATUS, 0, MY_ADDRESS, BROADCAST_ADDRESS, CONTROL_FLAGS, 11, {0x63, 0x31, 0xF1, 0x01, 0x10, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80}, {}, "ME: Play Status"},
{ CONSOLE_DISK_STOP, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 6, {0x00, 0x11, 0x63, 0x43, 0x01, 0x00}, {}, "Console - Stop" },
{ RESP_CONSOLE_DISK_STOP_0, 1, MY_ADDRESS, HU_ADDRESS, CONTROL_FLAGS, 5, {0x00, 0x63, 0x11, 0x53, 0x01 }, {}, "Response STOP0"},
{ RESP_CONSOLE_DISK_STOP_1, 0, MY_ADDRESS, BROADCAST_ADDRESS, CONTROL_FLAGS, 11, {0x63, 0x31, 0xF1, 0x00, 0x30, 0x00, 0x00,0x00, 0x00, 0x00, 0x80}, {}, "Response STOP1"},
{ CONSOLE_SEEK_UP, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x94}, {}, "Seek Up"},
{ CONSOLE_SEEK_DOWN, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x95}, {}, "Seek Down"},
{ CONSOLE_SCAN, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0xA6}, {}, "Scan"},
{ CONSOLE_BTN_1, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0xB0}, {}, "Button 1"},
{ CONSOLE_BTN_2, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0xA0}, {}, "Button 2"},
{ CONSOLE_BTN_3, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x91}, {}, "Button 3"},
{ CONSOLE_BTN_4, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x90}, {}, "Button 4"},
{ CONSOLE_BTN_5, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x99}, {}, "Button 5"},
{ CONSOLE_BTN_6, 1, HU_ADDRESS, MY_ADDRESS, CONTROL_FLAGS, 4, {0x00, 0x25, 0x63, 0x98}, {}, "Button 6"},
};

71
code/src/AVC_messages.h Normal file
View File

@ -0,0 +1,71 @@
#ifndef __AVC_MESSAGES_H
#define __AVC_MESSAGES_H
#define HU_ADDRESS 0x190
#define MY_ADDRESS 0x360 // CD Changer #1
#define BROADCAST_ADDRESS 0x01FF // All audio devices
#define LAN_BROADCAST_ADDRESS 0x0FFF
#define CONTROL_FLAGS 0xF
typedef enum MSG_ID{
AUDIO_AUX_IN_USE,
AUDIO_TUNER_IN_USE,
AUDIO_TAPE_IN_USE,
AUDIO_CD_IN_USE,
AUDIO_VOLUME_STATUS,
TUNER_STATUS,
CD_STATUS,
CONSOLE_OFF,
LAN_STATUS,
LAN_REGISTER,
LAN_INIT,
LAN_CHECK,
CD_CH_LAN_CHECK,
RESP_LAN_CHECK,
SELF_REGISTER,
CONSOLE_DISK_BUTTON_1,
RESP_DISK_BUTTON_1,
CONSOLE_DISK_BUTTON_2,
RESP_DISK_BUTTON_2_0,
RESP_DISK_BUTTON_2_1,
CONSOLE_DISK_PLAY,
RESP_CONSOLE_DISK_PLAY_0,
RESP_CONSOLE_DISK_PLAY_1,
SELF_PLAYING_STATUS,
CONSOLE_DISK_STOP,
RESP_CONSOLE_DISK_STOP_0,
RESP_CONSOLE_DISK_STOP_1,
CONSOLE_SEEK_UP,
CONSOLE_SEEK_DOWN,
CONSOLE_SCAN,
CONSOLE_BTN_1,
CONSOLE_BTN_2,
CONSOLE_BTN_3,
CONSOLE_BTN_4,
CONSOLE_BTN_5,
CONSOLE_BTN_6,
MESSAGE_ID_SIZE
}MSG_ID;
typedef struct MSG_IDENTIFIER{
MSG_ID msg_id;
uint8_t broadcast;
uint16_t master;
uint16_t slave;
uint8_t control;
uint8_t data_size;
uint8_t data[20];
uint8_t data_ignore[20];
char description[20];
}MSG_IDENTIFIER;
#endif

319
code/src/USART.c Normal file
View File

@ -0,0 +1,319 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stddef.h>
#include <avr/pgmspace.h>
#include "task_man.h"
#include "USART.h"
static uint8_t tx_buffer[MAX_TX_BUFFER];
static uint8_t rx_buffer[MAX_RX_BUFFER];
static uint8_t* tx_buff_head;
static uint8_t* tx_buff_tail;
static uint8_t* rx_buff_head;
static uint8_t* rx_buff_tail;
static no_arg_callback UART_callback = NULL;
enum TX_TYPE{POLLING, INTERRUPT};
static enum TX_TYPE tx_type = POLLING;
static uint8_t UART_escape = '\n';
void USART_INIT_INTERRUPT()
{
tx_type = INTERRUPT;
//initialize buffers
tx_buff_head = tx_buffer;
tx_buff_tail = tx_buffer;
rx_buff_head = rx_buffer;
rx_buff_tail = rx_buffer;
// get prescaller value
uint16_t ubbr = (((F_CPU / (USART_BAUDRATE * 16UL))) - 1);
// Set baud rate
UBRR0H = (uint8_t)(ubbr>>8);
UBRR0L = (uint8_t)ubbr;
// Set frame format to 8 data bits 00s in other fields indicate no parity, 1 stop bit.
UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
// Enable USART Periferal and interrupts
UCSR0B |= (1<<RXCIE0) | (1<<UDRIE0) | (1 << RXEN0) | (1 << TXEN0);
}
void USART_INIT_POLLING()
{
tx_type = POLLING;
//initialize buffers
tx_buff_head = tx_buffer;
tx_buff_tail = tx_buffer;
rx_buff_head = rx_buffer;
rx_buff_tail = rx_buffer;
// get prescaller value
uint16_t ubbr = (((F_CPU / (USART_BAUDRATE * 16UL))) - 1);
// Set baud rate
UBRR0H = (uint8_t)(ubbr>>8);
UBRR0L = (uint8_t)ubbr;
// Set frame format to 8 data bits 00s in other fields indicate no parity, 1 stop bit.
UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
// Enable USART Periferal and interrupts
UCSR0B = (1<<RXCIE0) | (1 << RXEN0) | (1 << TXEN0);
add_task_no_arg(USART_TRANSMIT_TASK, SYSTEM_2_ms, SYSTEM_5_ms, 0);
}
void UART_callback_register(no_arg_callback callback, uint8_t escape){
UART_callback = callback;
UART_escape = escape;
}
//called when data recieve is complete. MUST read from data to clear interrupt flag.
ISR(USART_RX_vect)
{
uint8_t error;
uint8_t data;
uint8_t status;
// read UART status register and UART data register
status = USART_STATUS;
data = USART_DATA;
//fetch any error
error = (status & ((1<<FE0)|(1<<DOR0)) );
//increment tail
uint8_t* rx_tail = rx_buff_tail + 1;
// if at end, reset
if(rx_tail == rx_buffer + MAX_RX_BUFFER)
rx_tail = rx_buffer;
//no room left in RX buffer
if( rx_tail == rx_buff_head ){
return;
}
else{
//fill next data slot.
*(rx_tail) = data;
rx_buff_tail=rx_tail;
//add callback if exists.
if(UART_callback != NULL && UART_escape == data){
add_task_no_arg(UART_callback, 0, 100, 0);
}
}
}
//called when data is empty.
ISR(USART_UDRE_vect)
{
//if empty, stop trying to send things.
if( tx_buff_head == tx_buff_tail ){
USART_CONTROL &= ~(1<<UDRIE0);
}
else{
tx_buff_head++;
//check to see if at end, if so, reset
if(tx_buff_head == tx_buffer + MAX_TX_BUFFER)
tx_buff_head = tx_buffer;
USART_DATA = *tx_buff_head;
}
}
void USART_TRANSMIT_TASK(){
// cli();
//if empty, stop trying to send things.
while( tx_buff_head != tx_buff_tail ){
{
while(!(UCSR0A & (1<<UDRE0)));
tx_buff_head++;
//check to see if at end, if so, reset
if(tx_buff_head == tx_buffer + MAX_TX_BUFFER){
tx_buff_head = tx_buffer;
}
USART_DATA = *tx_buff_head;
}
}
// sei();
}
//This will add a character to the transmit buffer, and send it.
uint8_t usart_put_c(char character){
//increment tail
uint8_t* tx_tail = ++tx_buff_tail;
tx_buff_tail--;
// if at end, reset
if(tx_tail == tx_buffer + MAX_TX_BUFFER)
tx_tail = tx_buffer;
//no room left in TX buffer
if( tx_tail == tx_buff_head ){
return UART_BUFFER_FULL;
}
else{
//fill next data slot, THEN increment to avoid race condition
*(tx_tail) = character;
tx_buff_tail=tx_tail;
if(tx_type == INTERRUPT){
// enable UDRE interrupt
USART_CONTROL |= (1<<UDRIE0);
}
}
return UART_GOOD;
}
//This will get a character from the recieve buffer.
uint8_t usart_get_c(){
//if empty, don't add anything to buffer.
if( rx_buff_head == rx_buff_tail ){
return UART_BUFFER_EMPTY;
}
else{
uint8_t* rx_head = rx_buff_head + 1;
//check to see if at end, if so, reset
if(rx_head == rx_buffer + MAX_RX_BUFFER)
rx_head = rx_buffer;
uint8_t data = *rx_head;
rx_buff_head = rx_head;
return data;
}
}
//Allows to direct a string as output;
uint8_t usart_put_str(char* str){
for(; *str != '\0'; str++){
if(usart_put_c(*str) != UART_GOOD)
return UART_BUFFER_FULL;
}
return UART_GOOD;
}
uint8_t usart_put_c_str(const char * str){
char c;
for(; (c = pgm_read_byte_near( str )); str++){
if(usart_put_c(c) != UART_GOOD)
return UART_BUFFER_FULL;
}
return UART_GOOD;
}
//prints \r\n onto usart bus;
uint8_t usart_put_nl(){
usart_put_c('\r');
usart_put_c('\n');
return UART_GOOD;
}
uint8_t usart_put_int(uint16_t integer){
char values[7];
int8_t i = 0;
do{
uint8_t val = integer%10;
values[i++] = val;
integer /= 10;
}while(integer);
do{
if(usart_put_c('0' + values[--i]) != UART_GOOD)
return 1;
}while(i>0);
return UART_GOOD;
}
uint8_t usart_put_int_hex(uint16_t integer){
char current = (integer>>12)&0x000F;
if(current > 0x9)
usart_put_c(('A'-10)+current);
else
usart_put_c('0'+current);
current = (integer>>8)&0x000F;
if(current > 0x9)
usart_put_c(('A'-10)+current);
else
usart_put_c('0'+current);
current = (integer>>4)&0x000F;
if(current > 0x9)
usart_put_c(('A'-10)+current);
else
usart_put_c('0'+current);
current = (integer)&0x000F;
if(current > 0x9)
usart_put_c(('A'-10)+current);
else
usart_put_c('0'+current);
return UART_GOOD;
}
uint8_t usart_put_byte(uint8_t byte){
char values[3];
int8_t i = 0;
do{
uint8_t val = byte%10;
values[i++] = val;
byte /= 10;
}while(byte);
do{
if(usart_put_c('0' + values[--i]) != UART_GOOD)
return 1;
}while(i>0);
return UART_GOOD;
}
uint8_t usart_put_byte_hex(uint8_t byte){
char current = (byte>>4)&0x000F;
if(current > 0x9)
usart_put_c(('A'-10)+current);
else
usart_put_c('0'+current);
current = (byte)&0x000F;
if(current > 0x9)
usart_put_c(('A'-10)+current);
else
usart_put_c('0'+current);
return UART_GOOD;
}
uint8_t usart_check_recv(){
//if empty, don't add anything to buffer.
if( rx_buff_head == rx_buff_tail ){
return UART_BUFFER_EMPTY;
}
else return UART_GOOD;
}

36
code/src/USART.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef __USART_H
#define __USART_H
#define USART_BAUDRATE 9600
#define USART_STATUS UCSR0A
#define USART_CONTROL UCSR0B
#define USART_DATA UDR0
#define MAX_TX_BUFFER 355
#define MAX_RX_BUFFER 50
enum UART_ERROR_CODES {UART_GOOD, UART_BUFFER_FULL, UART_BUFFER_EMPTY, USART_COMP_SHORT, USART_COMP_LONG};
void USART_INIT_INTERRUPT();
void USART_INIT_POLLING();
void USART_TRANSMIT_TASK(void);
void UART_callback_register(no_arg_callback callback, uint8_t escape);
uint8_t usart_put_c(char character);
uint8_t usart_put_str(char* str);
uint8_t usart_put_c_str(const char * str);
uint8_t usart_put_c_arr(char str[]);
uint8_t usart_put_int(uint16_t integer);
uint8_t usart_put_int_hex(uint16_t integer);
uint8_t usart_put_byte(uint8_t byte);
uint8_t usart_put_byte_hex(uint8_t byte);
uint8_t usart_put_nl(void);
uint8_t usart_get_c(void);
uint8_t usart_check_recv(void);
#endif

129
code/src/bluetooth.c Normal file
View File

@ -0,0 +1,129 @@
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/wdt.h>
#include "task_man.h"
#include "bluetooth.h"
#include "USART.h"
static MATCH_STATES match_state = NO_MATCH;
static uint8_t match_place = 0;
static char connected_mac_address[MAC_ADDRESS_LENGTH];
static void bluetooth_rec_callback(void);
void bluetooth_init(){
add_task_no_arg(bluetooth_rec_callback, SYSTEM_20_ms, SYSTEM_5_ms, 0);
}
void bluetooth_config(){
usart_put_c_str(PSTR("SET CONTROL ECHO 4\r\n"));
usart_put_c_str(PSTR("VOLUME 6\r\n"));
usart_put_c_str(PSTR("SET CONTROL MICBIAS 10 12\r\n"));
usart_put_c_str(PSTR("SET CONTROL CONFIG 100\r\n"));
usart_put_c_str(PSTR("SET PROFILE A2DP SINK\r\n"));
usart_put_c_str(PSTR("SET PROFILE AVRCP CONTROLLER\r\n"));
usart_put_c_str(PSTR("SET PROFILE HFP ON\r\n"));
usart_put_c_str(PSTR("SET BT AUTH * 2323\r\n"));
usart_put_c_str(PSTR("SET BT CLASS 240428\r\n"));
usart_put_c_str(PSTR("SET BT NAME Bluetooth Matrix\r\n"));
usart_put_c_str(PSTR("SET CONTROL AUTOCALL 0017 5000 A2DP\r\n"));
usart_put_c_str(PSTR("SET CONTROL RINGTONE 6,gfgfgf__gfgfgf______gfgfgf__gfgfgf\r\n"));
usart_put_c_str(PSTR("RESET\r\n"));
}
void bluetooth_next_song(){
usart_put_c_str(PSTR("@0 AVRCP FORWARD\r\n"));
}
void bluetooth_previous_song(){
usart_put_c_str(PSTR("@0 AVRCP BACKWARD\r\n"));
}
void bluetooth_pause_song(){
usart_put_c_str(PSTR("@0 AVRCP PAUSE\r\n"));
}
void bluetooth_play_song(){
usart_put_c_str(PSTR("@0 AVRCP PLAY\r\n"));
}
void bluetooth_rec_callback(){
uint8_t character;
const char* connect_str = PSTR("CONNECT 0 AVRCP 17\r\n");
const char* list_str = PSTR("LIST 0 CONNECTED L2CAP 48 0 0 0 0 0 ");
while((character = usart_get_c()) != UART_BUFFER_EMPTY){
switch(match_state){
case NO_MATCH:
match_place = 0;
if( character == pgm_read_byte_near(connect_str)){
match_state = MATCHING_CONNECT;
match_place++;
}
else if( character == pgm_read_byte_near(list_str)){
match_state = MATCHING_LIST;
match_place++;
}
break;
case MATCHING_CONNECT:
if( character == pgm_read_byte_near(connect_str + match_place)){
if(character == '\n'){
match_state = NO_MATCH;
usart_put_c_str(PSTR("LIST\r\n"));
}
else{
match_place++;
}
}
else{
match_state = NO_MATCH;
}
break;
case MATCHING_LIST:
{
uint8_t list_char = pgm_read_byte_near(list_str + match_place);
if( character == list_char){
match_place++;
}
else if(list_char == '\0'){
match_state = FETCHING_MAC;
connected_mac_address[0] = character;
match_place = 1;
}
else{
match_state = NO_MATCH;
}
break;
}
case FETCHING_MAC:
if(match_place < MAC_ADDRESS_LENGTH-1){
connected_mac_address[match_place] = character;
match_place++;
}
else{
connected_mac_address[match_place] = '\0';
usart_put_c_str(PSTR("CALL "));
usart_put_str(connected_mac_address);
usart_put_c_str(PSTR(" 111F HFP\r\n"));
match_state = NO_MATCH;
}
break;
}
}
}

20
code/src/bluetooth.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __BLUETOOTH_H
#define __BLUETOOTH_H
#define MAC_ADDRESS_LENGTH 18
void bluetooth_init(void);
void bluetooth_config(void);
void bluetooth_next_song(void);
void bluetooth_previous_song(void);
void bluetooth_pause_song(void);
void bluetooth_play_song(void);
typedef enum MATCH_STATES {
NO_MATCH,
MATCHING_CONNECT,
MATCHING_LIST,
FETCHING_MAC,
} MATCH_STATES;
#endif

38
code/src/main.c Normal file
View File

@ -0,0 +1,38 @@
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/wdt.h>
#include "task_man.h"
#include "USART.h"
#include "AVC.h"
#include "bluetooth.h"
int main(void)
{
// wdt_disable();
_delay_ms(1000);
init_task_man();
bluetooth_init();
USART_INIT_POLLING();
// USART_INIT_INTERRUPT();
AVC_init(1);
sei();
// usart_put_c('t');
_delay_ms(500);
AVC_add_tx_transaction_from_list(SELF_REGISTER);
sei();
add_task_no_arg(bluetooth_config, 0, SYSTEM_1_S, SYSTEM_1_S);
// wdt_enable( WDTO_2S );
while(1){
// Reset watchdog.
// wdt_reset();
process_tasks();
}
}

158
code/src/task_man.c Normal file
View File

@ -0,0 +1,158 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stddef.h>
#include "task_man.h"
#include "USART.h"
static task* task_array[MAX_TASK_CNT];
static task task_array_storage[MAX_TASK_CNT];
static task** task_array_head;
static task** task_array_tail;
static task* task_queue_head;
static volatile uint16_t system_time_keeper = 0;
void init_task_man(){
for(uint8_t i = 0; i < MAX_TASK_CNT; i++){
task_array[i] = &(task_array_storage[i]);
task_array_storage[i].next = NULL;
}
task_queue_head = NULL;
task_array_head = task_array;
task_array_tail = &(task_array[MAX_TASK_CNT-1]);
//setup timer for counting
TCNT0 = 0; //count is 0;
OCR0A = F_CPU/64000; //should resolve to 187 counts, or ~1mS
TCCR0A = 1<<WGM01; // CTC mode
TCCR0B = (1<<CS01)|(1<<CS00);//(1<<CS21)|(1<<CS20); // clk/32 12Mhz 12000000/64 = 187.5Khz Mhz; 1ms = .001 = x/187500 x = 187
TIMSK0 = 1<<OCIE0A;
}
ISR(TIMER0_COMPA_vect, ISR_NOBLOCK){
system_time_keeper++; // add ~1ms to time.
}
uint8_t add_task_no_arg(no_arg_callback function, uint16_t period, uint16_t min_service_time, uint16_t delay){
//no room left to allocate tasks
if( task_array_head > task_array_tail )
return TASK_ALLOCATOR_FULL;
else{
//allocate current task;
task * cur_task = *task_array_head;
//null the pointer in array to the task;
*task_array_head = NULL;
//increment to next allocator
task_array_head++;
//check to see what king of task based on period.
if(period)
cur_task->task_type = RECURRING;
else
cur_task->task_type = ONE_SHOT;
//set specifics about callback
cur_task->callback = function;
//initialze remaing members
cur_task->period = period;
cur_task->timer = delay;
cur_task->next = NULL;
//check to ensure we don't need to replace head, if so, do.
if(task_queue_head == NULL || (task_queue_head->timer > min_service_time && task_queue_head->timer > delay)){
cur_task->next = task_queue_head;
task_queue_head = cur_task;
}
else{
//traverse nodes, until we reach a node that excedes our min_service_time or excedes our initial delay.
task* previous = task_queue_head;
while(previous->next != NULL && previous->next->timer < min_service_time && ( delay == 0 || previous->next->timer <= delay)){
previous = previous->next;
}
cur_task->next = previous->next;
previous->next = cur_task;
}
}
return TASK_GOOD;
}
//we run this every time in our main loop to run tasks
void process_tasks(){
//we grab the time difference.
uint16_t time_diff = system_time_keeper;
//we reset the system timer.
system_time_keeper = 0;
//only run if difference in time.
if(time_diff){
//go through each node to update timer value.
task* previous = task_queue_head;
while(previous != NULL){
if(time_diff > previous->timer)
{
previous->timer = 0;
}
else{
previous->timer -= time_diff;
}
previous = previous->next;
}
}
//pop events off queue if ready.
if(task_queue_head !=NULL && task_queue_head->timer == 0)
{
task_queue_head->callback();
switch(task_queue_head->task_type){
case RECURRING:
//reset period counter
task_queue_head->timer = task_queue_head->period;
task* previous = task_queue_head;
task* cur_task = task_queue_head;
//update task position
while(previous->next != NULL && previous->next->timer <= task_queue_head->timer){
previous = previous->next;
}
if(previous != task_queue_head){
task_queue_head = task_queue_head->next;
cur_task->next = previous->next;
previous->next = cur_task;
}
break;
case ONE_SHOT:
//remove as we ran the task.
remove_head_task();
break;
}
}
}
void remove_head_task(){
//re-cover task stack place;
task_array_head--;
//place the task back into stack;
*task_array_head = task_queue_head;
//update task queue
task_queue_head = task_queue_head->next;
}

33
code/src/task_man.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef __TASK_MAN_H
#define __TASK_MAN_H
#define SYSTEM_1_S 1002
#define SYSTEM_5_ms 5
#define SYSTEM_2_ms 2
#define SYSTEM_20_ms 20
#define MAX_TASK_CNT 15
typedef void (*no_arg_callback)(void);
typedef enum TASK_TYPE {ONE_SHOT, RECURRING} TASK_TYPE;
enum TASK_ERROR_CODES {TASK_GOOD, TASK_ALLOCATOR_FULL};
typedef struct task{
TASK_TYPE task_type;
no_arg_callback callback;
uint16_t period;
uint16_t timer;
struct task* next;
}task;
void init_task_man(void);
uint8_t add_task_no_arg(no_arg_callback, uint16_t period, uint16_t min_service_time, uint16_t delay);
void process_tasks(void);
void remove_head_task(void);
#endif

33
eagle/.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
# Compiled source #
###################
*.#*
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

2778
eagle/AVC-LAN-2.brd Normal file

File diff suppressed because it is too large Load Diff

14460
eagle/AVC-LAN-2.sch Normal file

File diff suppressed because it is too large Load Diff

495
eagle/Bluetunes.lbr Normal file
View File

@ -0,0 +1,495 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE eagle SYSTEM "eagle.dtd">
<eagle version="6.2">
<drawing>
<settings>
<setting alwaysvectorfont="no"/>
<setting verticaltext="up"/>
</settings>
<grid distance="0.05" unitdist="inch" unit="inch" style="lines" multiple="1" display="yes" altdistance="0.025" altunitdist="inch" altunit="inch"/>
<layers>
<layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
<layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
<layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
<layer number="18" name="Vias" color="2" fill="1" visible="yes" active="yes"/>
<layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
<layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
<layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
<layer number="22" name="bPlace" color="7" fill="1" visible="yes" active="yes"/>
<layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
<layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/>
<layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
<layer number="26" name="bNames" color="7" fill="1" visible="yes" active="yes"/>
<layer number="27" name="tValues" color="7" fill="1" visible="yes" active="yes"/>
<layer number="28" name="bValues" color="7" fill="1" visible="yes" active="yes"/>
<layer number="29" name="tStop" color="7" fill="3" visible="no" active="yes"/>
<layer number="30" name="bStop" color="7" fill="6" visible="no" active="yes"/>
<layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/>
<layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
<layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
<layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
<layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
<layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
<layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="39" name="tKeepout" color="4" fill="11" visible="yes" active="yes"/>
<layer number="40" name="bKeepout" color="1" fill="11" visible="yes" active="yes"/>
<layer number="41" name="tRestrict" color="4" fill="10" visible="yes" active="yes"/>
<layer number="42" name="bRestrict" color="1" fill="10" visible="yes" active="yes"/>
<layer number="43" name="vRestrict" color="2" fill="10" visible="yes" active="yes"/>
<layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
<layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
<layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
<layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
<layer number="48" name="Document" color="7" fill="1" visible="yes" active="yes"/>
<layer number="49" name="Reference" color="7" fill="1" visible="yes" active="yes"/>
<layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
<layer number="52" name="bDocu" color="7" fill="1" visible="yes" active="yes"/>
<layer number="91" name="Nets" color="2" fill="1" visible="yes" active="yes"/>
<layer number="92" name="Busses" color="1" fill="1" visible="yes" active="yes"/>
<layer number="93" name="Pins" color="2" fill="1" visible="yes" active="yes"/>
<layer number="94" name="Symbols" color="4" fill="1" visible="yes" active="yes"/>
<layer number="95" name="Names" color="7" fill="1" visible="yes" active="yes"/>
<layer number="96" name="Values" color="7" fill="1" visible="yes" active="yes"/>
<layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"/>
<layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"/>
</layers>
<library>
<packages>
<package name="QFN-68">
<smd name="1" x="-3.95" y="3.2" dx="0.7" dy="0.2" layer="1"/>
<smd name="2" x="-3.95" y="2.8" dx="0.7" dy="0.2" layer="1"/>
<smd name="3" x="-3.95" y="2.4" dx="0.7" dy="0.2" layer="1"/>
<smd name="4" x="-3.95" y="2" dx="0.7" dy="0.2" layer="1"/>
<smd name="5" x="-3.95" y="1.6" dx="0.7" dy="0.2" layer="1"/>
<smd name="6" x="-3.95" y="1.2" dx="0.7" dy="0.2" layer="1"/>
<smd name="7" x="-3.95" y="0.8" dx="0.7" dy="0.2" layer="1"/>
<smd name="8" x="-3.95" y="0.4" dx="0.7" dy="0.2" layer="1"/>
<smd name="9" x="-3.95" y="0" dx="0.7" dy="0.2" layer="1"/>
<smd name="10" x="-3.95" y="-0.4" dx="0.7" dy="0.2" layer="1"/>
<smd name="11" x="-3.95" y="-0.8" dx="0.7" dy="0.2" layer="1"/>
<smd name="12" x="-3.95" y="-1.2" dx="0.7" dy="0.2" layer="1"/>
<smd name="13" x="-3.95" y="-1.6" dx="0.7" dy="0.2" layer="1"/>
<smd name="14" x="-3.95" y="-2" dx="0.7" dy="0.2" layer="1"/>
<smd name="15" x="-3.95" y="-2.4" dx="0.7" dy="0.2" layer="1"/>
<smd name="16" x="-3.95" y="-2.8" dx="0.7" dy="0.2" layer="1"/>
<smd name="17" x="-3.95" y="-3.2" dx="0.7" dy="0.2" layer="1"/>
<smd name="18" x="-3.2" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="19" x="-2.8" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="20" x="-2.4" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="21" x="-2" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="22" x="-1.6" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="23" x="-1.2" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="24" x="-0.8" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="25" x="-0.4" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="26" x="0" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="27" x="0.4" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="28" x="0.8" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="29" x="1.2" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="30" x="1.6" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="31" x="2" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="32" x="2.4" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="33" x="2.8" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="34" x="3.2" y="-3.95" dx="0.7" dy="0.2" layer="1" rot="R90"/>
<smd name="35" x="3.95" y="-3.2" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="36" x="3.95" y="-2.8" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="37" x="3.95" y="-2.4" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="38" x="3.95" y="-2" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="39" x="3.95" y="-1.6" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="40" x="3.95" y="-1.2" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="41" x="3.95" y="-0.8" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="42" x="3.95" y="-0.4" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="43" x="3.95" y="0" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="44" x="3.95" y="0.4" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="45" x="3.95" y="0.8" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="46" x="3.95" y="1.2" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="47" x="3.95" y="1.6" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="48" x="3.95" y="2" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="49" x="3.95" y="2.4" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="50" x="3.95" y="2.8" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="51" x="3.95" y="3.2" dx="0.7" dy="0.2" layer="1" rot="R180"/>
<smd name="52" x="3.2" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="53" x="2.8" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="54" x="2.4" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="55" x="2" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="56" x="1.6" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="57" x="1.2" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="58" x="0.8" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="59" x="0.4" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="60" x="0" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="61" x="-0.4" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="62" x="-0.8" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="63" x="-1.2" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="64" x="-1.6" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="65" x="-2" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="66" x="-2.4" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="67" x="-2.8" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="68" x="-3.2" y="3.95" dx="0.7" dy="0.2" layer="1" rot="R270"/>
<smd name="69" x="0" y="0" dx="6.2" dy="6.2" layer="1"/>
<wire x1="-3.2" y1="3.5" x2="-3.5" y2="3.2" width="0.127" layer="21"/>
<wire x1="-3.5" y1="3.2" x2="-3.5" y2="-3.5" width="0.127" layer="21"/>
<wire x1="-3.5" y1="-3.5" x2="3.5" y2="-3.5" width="0.127" layer="21"/>
<wire x1="3.5" y1="-3.5" x2="3.5" y2="3.5" width="0.127" layer="21"/>
<wire x1="3.5" y1="3.5" x2="-3.2" y2="3.5" width="0.127" layer="21"/>
</package>
<package name="FI212C">
<smd name="1" x="-0.65" y="0.875" dx="0.35" dy="0.9" layer="1" rot="R180"/>
<smd name="2" x="0" y="0.875" dx="0.35" dy="0.9" layer="1" rot="R180"/>
<smd name="3" x="0.65" y="0.875" dx="0.35" dy="0.9" layer="1" rot="R180"/>
<smd name="4" x="1.2" y="0" dx="0.35" dy="0.9" layer="1" rot="R270"/>
<smd name="5" x="0.65" y="-0.875" dx="0.35" dy="0.9" layer="1"/>
<smd name="6" x="0" y="-0.875" dx="0.35" dy="0.9" layer="1"/>
<smd name="7" x="-0.65" y="-0.875" dx="0.35" dy="0.9" layer="1"/>
<smd name="8" x="-1.2" y="0" dx="0.35" dy="0.9" layer="1" rot="R90"/>
<wire x1="-1" y1="-0.65" x2="1" y2="-0.65" width="0.127" layer="21"/>
<wire x1="1" y1="-0.65" x2="1" y2="0.65" width="0.127" layer="21"/>
<wire x1="1" y1="0.65" x2="-1" y2="0.65" width="0.127" layer="21"/>
<wire x1="-1" y1="0.65" x2="-1" y2="-0.65" width="0.127" layer="21"/>
<circle x="-0.55" y="0" radius="0.070709375" width="0.127" layer="21"/>
<text x="0.9" y="0.35" size="1.27" layer="21">UD</text>
</package>
<package name="ANT-2.45-CHP-T">
<smd name="P$1" x="-3.302" y="0" dx="2.54" dy="1.016" layer="1" rot="R90"/>
<smd name="P$2" x="3.302" y="0" dx="2.54" dy="1.016" layer="1" rot="R90"/>
<wire x1="-1.27" y1="0" x2="1.27" y2="0" width="0.127" layer="21"/>
<wire x1="0" y1="1.27" x2="1.27" y2="0" width="0.127" layer="21"/>
<wire x1="1.27" y1="0" x2="0" y2="-1.27" width="0.127" layer="21"/>
<wire x1="-3.175" y1="1.27" x2="-3.175" y2="-1.27" width="0.127" layer="21"/>
<wire x1="-3.175" y1="-1.27" x2="3.175" y2="-1.27" width="0.127" layer="21"/>
<wire x1="3.175" y1="-1.27" x2="3.175" y2="1.27" width="0.127" layer="21"/>
<wire x1="3.175" y1="1.27" x2="-3.175" y2="1.27" width="0.127" layer="21"/>
<polygon width="0.127" layer="41">
<vertex x="-4.699" y="5.461"/>
<vertex x="-4.699" y="0.254"/>
<vertex x="-3.937" y="0.254"/>
<vertex x="-3.937" y="1.397"/>
<vertex x="-2.667" y="1.397"/>
<vertex x="-2.667" y="-1.397"/>
<vertex x="-3.937" y="-1.397"/>
<vertex x="-3.937" y="-0.254"/>
<vertex x="-4.699" y="-0.254"/>
<vertex x="-4.699" y="-5.461"/>
<vertex x="7.366" y="-5.461"/>
<vertex x="7.366" y="-1.27"/>
<vertex x="3.937" y="-1.27"/>
<vertex x="3.937" y="-1.397"/>
<vertex x="2.667" y="-1.397"/>
<vertex x="2.667" y="1.397"/>
<vertex x="3.937" y="1.397"/>
<vertex x="3.937" y="-1.143"/>
<vertex x="7.366" y="-1.143"/>
<vertex x="7.366" y="5.461"/>
</polygon>
<rectangle x1="-4.699" y1="-5.461" x2="7.366" y2="5.461" layer="42"/>
</package>
<package name="26MHZ-CRYSTAL">
<smd name="P$1" x="-1.1" y="-0.8" dx="1.4" dy="1.15" layer="1"/>
<smd name="P$2" x="1.1" y="-0.8" dx="1.4" dy="1.15" layer="1"/>
<smd name="P$3" x="1.1" y="0.8" dx="1.4" dy="1.15" layer="1"/>
<smd name="P$4" x="-1.1" y="0.8" dx="1.4" dy="1.15" layer="1"/>
<wire x1="-2" y1="1.5" x2="-2" y2="-1.5" width="0.127" layer="21"/>
<wire x1="-2" y1="-1.5" x2="2" y2="-1.5" width="0.127" layer="21"/>
<wire x1="2" y1="-1.5" x2="2" y2="1.5" width="0.127" layer="21"/>
<wire x1="2" y1="1.5" x2="-2" y2="1.5" width="0.127" layer="21"/>
</package>
<package name="8-PIN">
</package>
</packages>
<symbols>
<symbol name="BLUETUNES">
<wire x1="-101.6" y1="60.96" x2="-101.6" y2="-63.5" width="0.254" layer="94"/>
<wire x1="-101.6" y1="60.96" x2="91.44" y2="60.96" width="0.254" layer="94"/>
<wire x1="91.44" y1="60.96" x2="91.44" y2="-63.5" width="0.254" layer="94"/>
<wire x1="-101.6" y1="-63.5" x2="91.44" y2="-63.5" width="0.254" layer="94"/>
<pin name="VREGIN_L" x="-38.1" y="63.5" length="short" rot="R270"/>
<pin name="VDD_ANA" x="-53.34" y="63.5" length="short" rot="R270"/>
<pin name="XTAL_IN" x="93.98" y="53.34" length="short" rot="R180"/>
<pin name="XTAL_OUT" x="93.98" y="40.64" length="short" rot="R180"/>
<pin name="LO_REF" x="93.98" y="-50.8" length="short" rot="R180"/>
<pin name="AIO[1]" x="93.98" y="-45.72" length="short" rot="R180"/>
<pin name="AIO[0]" x="93.98" y="-43.18" length="short" rot="R180"/>
<pin name="NC@1" x="-68.58" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="UART_TX" x="93.98" y="-30.48" length="short" rot="R180"/>
<pin name="UART_RX" x="93.98" y="-33.02" length="short" rot="R180"/>
<pin name="UART_CTS" x="93.98" y="-35.56" length="short" rot="R180"/>
<pin name="UART_RTS" x="93.98" y="-38.1" length="short" rot="R180"/>
<pin name="VDD_UART" x="73.66" y="63.5" length="short" rot="R270"/>
<pin name="PIO[9]" x="93.98" y="10.16" length="short" rot="R180"/>
<pin name="PIO[11]" x="93.98" y="15.24" length="short" rot="R180"/>
<pin name="VDD_PADS" x="76.2" y="63.5" length="short" rot="R270"/>
<pin name="VDD_CORE@1" x="-68.58" y="63.5" length="short" rot="R270"/>
<pin name="PIO[12]" x="93.98" y="17.78" length="short" rot="R180"/>
<pin name="PIO[13]" x="93.98" y="20.32" length="short" rot="R180"/>
<pin name="PIO[14]" x="93.98" y="22.86" length="short" rot="R180"/>
<pin name="PIO[8]" x="93.98" y="7.62" length="short" rot="R180"/>
<pin name="PIO[7]" x="93.98" y="5.08" length="short" rot="R180"/>
<pin name="PIO[6]" x="93.98" y="2.54" length="short" rot="R180"/>
<pin name="PIO[5]" x="93.98" y="0" length="short" rot="R180"/>
<pin name="PIO[4]" x="93.98" y="-2.54" length="short" rot="R180"/>
<pin name="RST#" x="93.98" y="-60.96" length="short" rot="R180"/>
<pin name="TEST_EN" x="93.98" y="-55.88" length="short" rot="R180"/>
<pin name="SPI_MOSI" x="93.98" y="-22.86" length="short" rot="R180"/>
<pin name="SPI_CLK" x="93.98" y="-17.78" length="short" rot="R180"/>
<pin name="SPI_CS#" x="93.98" y="-25.4" length="short" rot="R180"/>
<pin name="SPI_MISO" x="93.98" y="-20.32" length="short" rot="R180"/>
<pin name="LED[0]" x="93.98" y="30.48" length="short" rot="R180"/>
<pin name="LED[1]" x="93.98" y="33.02" length="short" rot="R180"/>
<pin name="VDD_CORE@2" x="-66.04" y="63.5" length="short" rot="R270"/>
<pin name="VREGENABLE_H" x="15.24" y="63.5" length="short" rot="R270"/>
<pin name="VDD_BUCK_CORE" x="-20.32" y="63.5" length="short" rot="R270"/>
<pin name="LX" x="-27.94" y="63.5" length="short" rot="R270"/>
<pin name="BAT_P" x="7.62" y="63.5" length="short" rot="R270"/>
<pin name="VDD_CHG" x="-2.54" y="63.5" length="short" rot="R270"/>
<pin name="NC@2" x="-66.04" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="NC@3" x="-63.5" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="NC@4" x="-60.96" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="NC@5" x="-58.42" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="NC@6" x="-55.88" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="MIC_BIAS" x="71.12" y="-66.04" length="short" rot="R90"/>
<pin name="VREGIN_L_AUDIO" x="30.48" y="63.5" length="short" rot="R270"/>
<pin name="VDD_AUDIO" x="45.72" y="63.5" length="short" rot="R270"/>
<pin name="MIC_B_P" x="45.72" y="-66.04" length="short" rot="R90"/>
<pin name="NC@7" x="-53.34" y="-66.04" length="short" direction="nc" rot="R90"/>
<pin name="MIC_B_N" x="55.88" y="-66.04" length="short" rot="R90"/>
<pin name="MIC_A_P" x="20.32" y="-66.04" length="short" rot="R90"/>
<pin name="MIC_A_N" x="30.48" y="-66.04" length="short" rot="R90"/>
<pin name="SPK_B_N" x="-20.32" y="-66.04" length="short" rot="R90"/>
<pin name="SPK_B_P" x="-12.7" y="-66.04" length="short" rot="R90"/>
<pin name="AU_REF_DCPL" x="-27.94" y="-66.04" length="short" rot="R90"/>
<pin name="SPK_A_N" x="5.08" y="-66.04" length="short" rot="R90"/>
<pin name="SPK_A_P" x="-2.54" y="-66.04" length="short" rot="R90"/>
<pin name="PIO[3]" x="93.98" y="-5.08" length="short" rot="R180"/>
<pin name="PIO[2]" x="93.98" y="-7.62" length="short" rot="R180"/>
<pin name="PIO[1]" x="93.98" y="-10.16" length="short" rot="R180"/>
<pin name="PIO[0]" x="93.98" y="-12.7" length="short" rot="R180"/>
<pin name="VDD_PIO" x="60.96" y="63.5" length="short" rot="R270"/>
<pin name="VDD_RADIO@2" x="-83.82" y="63.5" length="short" rot="R270"/>
<pin name="RF_P" x="-104.14" y="38.1" length="short"/>
<pin name="RF_N" x="-104.14" y="27.94" length="short"/>
<pin name="VDD_RADIO@1" x="-86.36" y="63.5" length="short" rot="R270"/>
<pin name="VDD_LO" x="-91.44" y="63.5" length="short" rot="R270"/>
<pin name="VREGENABLE_L" x="17.78" y="63.5" length="short" rot="R270"/>
<pin name="VSS_CNTR_PAD" x="-88.9" y="-66.04" length="short" rot="R90"/>
<text x="-27.94" y="-2.54" size="3.81" layer="97">BlueTunes ROM QFN</text>
<wire x1="-50.8" y1="35.56" x2="-40.64" y2="35.56" width="0.254" layer="94"/>
<wire x1="-40.64" y1="35.56" x2="-40.64" y2="33.02" width="0.254" layer="94"/>
<wire x1="-40.64" y1="33.02" x2="-40.64" y2="30.48" width="0.254" layer="94"/>
<wire x1="-40.64" y1="30.48" x2="-50.8" y2="30.48" width="0.254" layer="94"/>
<wire x1="-50.8" y1="30.48" x2="-50.8" y2="33.02" width="0.254" layer="94"/>
<text x="-48.26" y="31.75" size="1.778" layer="94">REG</text>
<wire x1="-50.8" y1="33.02" x2="-50.8" y2="35.56" width="0.254" layer="94"/>
<wire x1="-50.8" y1="33.02" x2="-53.34" y2="33.02" width="0.254" layer="94"/>
<wire x1="-53.34" y1="33.02" x2="-53.34" y2="46.99" width="0.254" layer="94"/>
<wire x1="-53.34" y1="46.99" x2="-54.61" y2="45.72" width="0.254" layer="94"/>
<wire x1="-53.34" y1="46.99" x2="-52.07" y2="45.72" width="0.254" layer="94"/>
<wire x1="-40.64" y1="33.02" x2="-38.1" y2="33.02" width="0.254" layer="94"/>
<wire x1="-38.1" y1="33.02" x2="-38.1" y2="46.99" width="0.254" layer="94"/>
<wire x1="-16.51" y1="35.56" x2="-6.35" y2="35.56" width="0.254" layer="94"/>
<wire x1="-6.35" y1="35.56" x2="-6.35" y2="33.02" width="0.254" layer="94"/>
<wire x1="-6.35" y1="33.02" x2="-6.35" y2="30.48" width="0.254" layer="94"/>
<wire x1="-6.35" y1="30.48" x2="-16.51" y2="30.48" width="0.254" layer="94"/>
<wire x1="-16.51" y1="30.48" x2="-16.51" y2="33.02" width="0.254" layer="94"/>
<text x="-13.97" y="31.75" size="1.778" layer="94">REG</text>
<wire x1="-16.51" y1="33.02" x2="-16.51" y2="35.56" width="0.254" layer="94"/>
<wire x1="-16.51" y1="33.02" x2="-27.94" y2="33.02" width="0.254" layer="94"/>
<wire x1="-27.94" y1="33.02" x2="-27.94" y2="54.61" width="0.254" layer="94"/>
<wire x1="-27.94" y1="54.61" x2="-29.21" y2="53.34" width="0.254" layer="94"/>
<wire x1="-27.94" y1="54.61" x2="-26.67" y2="53.34" width="0.254" layer="94"/>
<wire x1="-6.35" y1="33.02" x2="7.62" y2="33.02" width="0.254" layer="94"/>
<wire x1="7.62" y1="33.02" x2="7.62" y2="50.8" width="0.254" layer="94"/>
<wire x1="33.02" y1="35.56" x2="43.18" y2="35.56" width="0.254" layer="94"/>
<wire x1="43.18" y1="35.56" x2="43.18" y2="33.02" width="0.254" layer="94"/>
<wire x1="43.18" y1="33.02" x2="43.18" y2="30.48" width="0.254" layer="94"/>
<wire x1="43.18" y1="30.48" x2="33.02" y2="30.48" width="0.254" layer="94"/>
<wire x1="33.02" y1="30.48" x2="33.02" y2="33.02" width="0.254" layer="94"/>
<text x="35.56" y="31.75" size="1.778" layer="94">REG</text>
<wire x1="33.02" y1="33.02" x2="33.02" y2="35.56" width="0.254" layer="94"/>
<wire x1="33.02" y1="33.02" x2="30.48" y2="33.02" width="0.254" layer="94"/>
<wire x1="30.48" y1="33.02" x2="30.48" y2="39.37" width="0.254" layer="94"/>
<wire x1="43.18" y1="33.02" x2="45.72" y2="33.02" width="0.254" layer="94"/>
<wire x1="45.72" y1="33.02" x2="45.72" y2="45.72" width="0.254" layer="94"/>
<wire x1="44.45" y1="44.45" x2="45.72" y2="45.72" width="0.254" layer="94"/>
<wire x1="45.72" y1="45.72" x2="46.99" y2="44.45" width="0.254" layer="94"/>
</symbol>
<symbol name="FI212C">
<wire x1="-12.7" y1="10.16" x2="-12.7" y2="-10.16" width="0.254" layer="94"/>
<wire x1="-12.7" y1="-10.16" x2="12.7" y2="-10.16" width="0.254" layer="94"/>
<wire x1="12.7" y1="-10.16" x2="12.7" y2="10.16" width="0.254" layer="94"/>
<wire x1="12.7" y1="10.16" x2="-12.7" y2="10.16" width="0.254" layer="94"/>
<pin name="BAL@1" x="15.24" y="5.08" length="short" rot="R180"/>
<pin name="GND@1" x="-2.54" y="-12.7" length="short" rot="R90"/>
<pin name="BAL@2" x="15.24" y="-5.08" length="short" rot="R180"/>
<pin name="GND@2" x="0" y="-12.7" length="short" rot="R90"/>
<pin name="UNBAL" x="-15.24" y="0" length="short"/>
<pin name="DC" x="-15.24" y="5.08" length="short"/>
<pin name="NC" x="-15.24" y="-5.08" length="short" direction="nc"/>
<pin name="GND@3" x="2.54" y="-12.7" length="short" rot="R90"/>
<text x="-12.7" y="12.7" size="2.54" layer="97">FI212C245072-T</text>
</symbol>
<symbol name="ANT">
<pin name="P$1" x="0" y="-2.54" visible="off" length="short" rot="R90"/>
<wire x1="0" y1="-2.54" x2="0" y2="2.54" width="0.254" layer="94"/>
<wire x1="-2.54" y1="5.08" x2="0" y2="2.54" width="0.254" layer="94"/>
<wire x1="0" y1="5.08" x2="0" y2="2.54" width="0.254" layer="94"/>
<wire x1="0" y1="2.54" x2="2.54" y2="5.08" width="0.254" layer="94"/>
</symbol>
<symbol name="XTAL">
<pin name="P$1" x="5.08" y="0" visible="off" length="short" rot="R180"/>
<pin name="P$2" x="-5.08" y="0" visible="off" length="short"/>
<wire x1="-2.54" y1="2.54" x2="-2.54" y2="-2.54" width="0.254" layer="94"/>
<wire x1="2.54" y1="2.54" x2="2.54" y2="-2.54" width="0.254" layer="94"/>
<wire x1="-1.27" y1="3.81" x2="-1.27" y2="-3.81" width="0.254" layer="94"/>
<wire x1="-1.27" y1="-3.81" x2="1.27" y2="-3.81" width="0.254" layer="94"/>
<wire x1="1.27" y1="-3.81" x2="1.27" y2="3.81" width="0.254" layer="94"/>
<wire x1="1.27" y1="3.81" x2="-1.27" y2="3.81" width="0.254" layer="94"/>
<wire x1="-3.81" y1="5.08" x2="-3.81" y2="-5.08" width="0.254" layer="94"/>
<wire x1="-3.81" y1="-5.08" x2="3.81" y2="-5.08" width="0.254" layer="94"/>
<wire x1="3.81" y1="-5.08" x2="3.81" y2="5.08" width="0.254" layer="94"/>
<wire x1="3.81" y1="5.08" x2="-3.81" y2="5.08" width="0.254" layer="94"/>
<pin name="P$3" x="-2.54" y="-7.62" visible="off" length="short" rot="R90"/>
<pin name="P$4" x="2.54" y="-7.62" visible="off" length="short" rot="R90"/>
</symbol>
</symbols>
<devicesets>
<deviceset name="BLUETUNESROM">
<gates>
<gate name="G$1" symbol="BLUETUNES" x="0" y="0"/>
</gates>
<devices>
<device name="" package="QFN-68">
<connects>
<connect gate="G$1" pin="AIO[0]" pad="7"/>
<connect gate="G$1" pin="AIO[1]" pad="6"/>
<connect gate="G$1" pin="AU_REF_DCPL" pad="55"/>
<connect gate="G$1" pin="BAT_P" pad="38"/>
<connect gate="G$1" pin="LED[0]" pad="32"/>
<connect gate="G$1" pin="LED[1]" pad="33"/>
<connect gate="G$1" pin="LO_REF" pad="5"/>
<connect gate="G$1" pin="LX" pad="37"/>
<connect gate="G$1" pin="MIC_A_N" pad="52"/>
<connect gate="G$1" pin="MIC_A_P" pad="51"/>
<connect gate="G$1" pin="MIC_BIAS" pad="45"/>
<connect gate="G$1" pin="MIC_B_N" pad="50"/>
<connect gate="G$1" pin="MIC_B_P" pad="48"/>
<connect gate="G$1" pin="NC@1" pad="8"/>
<connect gate="G$1" pin="NC@2" pad="40"/>
<connect gate="G$1" pin="NC@3" pad="41"/>
<connect gate="G$1" pin="NC@4" pad="42"/>
<connect gate="G$1" pin="NC@5" pad="43"/>
<connect gate="G$1" pin="NC@6" pad="44"/>
<connect gate="G$1" pin="NC@7" pad="49"/>
<connect gate="G$1" pin="PIO[0]" pad="61"/>
<connect gate="G$1" pin="PIO[11]" pad="15"/>
<connect gate="G$1" pin="PIO[12]" pad="18"/>
<connect gate="G$1" pin="PIO[13]" pad="19"/>
<connect gate="G$1" pin="PIO[14]" pad="20"/>
<connect gate="G$1" pin="PIO[1]" pad="60"/>
<connect gate="G$1" pin="PIO[2]" pad="59"/>
<connect gate="G$1" pin="PIO[3]" pad="58"/>
<connect gate="G$1" pin="PIO[4]" pad="25"/>
<connect gate="G$1" pin="PIO[5]" pad="24"/>
<connect gate="G$1" pin="PIO[6]" pad="23"/>
<connect gate="G$1" pin="PIO[7]" pad="22"/>
<connect gate="G$1" pin="PIO[8]" pad="21"/>
<connect gate="G$1" pin="PIO[9]" pad="14"/>
<connect gate="G$1" pin="RF_N" pad="65"/>
<connect gate="G$1" pin="RF_P" pad="64"/>
<connect gate="G$1" pin="RST#" pad="26"/>
<connect gate="G$1" pin="SPI_CLK" pad="29"/>
<connect gate="G$1" pin="SPI_CS#" pad="30"/>
<connect gate="G$1" pin="SPI_MISO" pad="31"/>
<connect gate="G$1" pin="SPI_MOSI" pad="28"/>
<connect gate="G$1" pin="SPK_A_N" pad="56"/>
<connect gate="G$1" pin="SPK_A_P" pad="57"/>
<connect gate="G$1" pin="SPK_B_N" pad="53"/>
<connect gate="G$1" pin="SPK_B_P" pad="54"/>
<connect gate="G$1" pin="TEST_EN" pad="27"/>
<connect gate="G$1" pin="UART_CTS" pad="11"/>
<connect gate="G$1" pin="UART_RTS" pad="12"/>
<connect gate="G$1" pin="UART_RX" pad="10"/>
<connect gate="G$1" pin="UART_TX" pad="9"/>
<connect gate="G$1" pin="VDD_ANA" pad="2"/>
<connect gate="G$1" pin="VDD_AUDIO" pad="47"/>
<connect gate="G$1" pin="VDD_BUCK_CORE" pad="36"/>
<connect gate="G$1" pin="VDD_CHG" pad="39"/>
<connect gate="G$1" pin="VDD_CORE@1" pad="17"/>
<connect gate="G$1" pin="VDD_CORE@2" pad="34"/>
<connect gate="G$1" pin="VDD_LO" pad="67"/>
<connect gate="G$1" pin="VDD_PADS" pad="16"/>
<connect gate="G$1" pin="VDD_PIO" pad="62"/>
<connect gate="G$1" pin="VDD_RADIO@1" pad="66"/>
<connect gate="G$1" pin="VDD_RADIO@2" pad="63"/>
<connect gate="G$1" pin="VDD_UART" pad="13"/>
<connect gate="G$1" pin="VREGENABLE_H" pad="35"/>
<connect gate="G$1" pin="VREGENABLE_L" pad="68"/>
<connect gate="G$1" pin="VREGIN_L" pad="1"/>
<connect gate="G$1" pin="VREGIN_L_AUDIO" pad="46"/>
<connect gate="G$1" pin="VSS_CNTR_PAD" pad="69"/>
<connect gate="G$1" pin="XTAL_IN" pad="3"/>
<connect gate="G$1" pin="XTAL_OUT" pad="4"/>
</connects>
<technologies>
<technology name=""/>
</technologies>
</device>
</devices>
</deviceset>
<deviceset name="FI212C245072-T">
<gates>
<gate name="G$1" symbol="FI212C" x="0" y="0"/>
</gates>
<devices>
<device name="" package="FI212C">
<connects>
<connect gate="G$1" pin="BAL@1" pad="1"/>
<connect gate="G$1" pin="BAL@2" pad="3"/>
<connect gate="G$1" pin="DC" pad="6"/>
<connect gate="G$1" pin="GND@1" pad="2"/>
<connect gate="G$1" pin="GND@2" pad="4"/>
<connect gate="G$1" pin="GND@3" pad="8"/>
<connect gate="G$1" pin="NC" pad="7"/>
<connect gate="G$1" pin="UNBAL" pad="5"/>
</connects>
<technologies>
<technology name=""/>
</technologies>
</device>
</devices>
</deviceset>
<deviceset name="ANT-2.45-CHP-T">
<gates>
<gate name="G$1" symbol="ANT" x="0" y="0"/>
</gates>
<devices>
<device name="" package="ANT-2.45-CHP-T">
<connects>
<connect gate="G$1" pin="P$1" pad="P$1"/>
</connects>
<technologies>
<technology name=""/>
</technologies>
</device>
</devices>
</deviceset>
<deviceset name="26MHZ-XTAL">
<gates>
<gate name="G$1" symbol="XTAL" x="0" y="0"/>
</gates>
<devices>
<device name="" package="26MHZ-CRYSTAL">
<connects>
<connect gate="G$1" pin="P$1" pad="P$1"/>
<connect gate="G$1" pin="P$2" pad="P$3"/>
<connect gate="G$1" pin="P$3" pad="P$2"/>
<connect gate="G$1" pin="P$4" pad="P$4"/>
</connects>
<technologies>
<technology name=""/>
</technologies>
</device>
</devices>
</deviceset>
</devicesets>
</library>
</drawing>
</eagle>

BIN
eagle/avr-7.lbr Normal file

Binary file not shown.

BIN
eagle/buckReg.lbr Normal file

Binary file not shown.

6648
eagle/con-lumberg-mod.lbr Normal file

File diff suppressed because it is too large Load Diff

267
eagle/cstce-resonator.lbr Normal file
View File

@ -0,0 +1,267 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE eagle SYSTEM "eagle.dtd">
<eagle version="6.2">
<drawing>
<settings>
<setting alwaysvectorfont="no"/>
<setting verticaltext="up"/>
</settings>
<grid distance="0.05" unitdist="inch" unit="mm" style="lines" multiple="1" display="yes" altdistance="0.025" altunitdist="inch" altunit="inch"/>
<layers>
<layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
<layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
<layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
<layer number="18" name="Vias" color="2" fill="1" visible="yes" active="yes"/>
<layer number="19" name="Unrouted" color="6" fill="1" visible="no" active="yes"/>
<layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
<layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
<layer number="22" name="bPlace" color="7" fill="1" visible="no" active="yes"/>
<layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
<layer number="24" name="bOrigins" color="15" fill="1" visible="no" active="yes"/>
<layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
<layer number="26" name="bNames" color="7" fill="1" visible="no" active="yes"/>
<layer number="27" name="tValues" color="7" fill="1" visible="yes" active="yes"/>
<layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/>
<layer number="29" name="tStop" color="7" fill="3" visible="yes" active="yes"/>
<layer number="30" name="bStop" color="7" fill="6" visible="no" active="yes"/>
<layer number="31" name="tCream" color="7" fill="4" visible="yes" active="yes"/>
<layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
<layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
<layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
<layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
<layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
<layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="39" name="tKeepout" color="4" fill="11" visible="no" active="yes"/>
<layer number="40" name="bKeepout" color="1" fill="11" visible="no" active="yes"/>
<layer number="41" name="tRestrict" color="4" fill="10" visible="no" active="yes"/>
<layer number="42" name="bRestrict" color="1" fill="10" visible="no" active="yes"/>
<layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/>
<layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
<layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
<layer number="46" name="Milling" color="3" fill="1" visible="yes" active="yes"/>
<layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
<layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/>
<layer number="49" name="Reference" color="7" fill="1" visible="no" active="yes"/>
<layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
<layer number="52" name="bDocu" color="7" fill="1" visible="no" active="yes"/>
<layer number="91" name="Nets" color="2" fill="1" visible="yes" active="yes"/>
<layer number="92" name="Busses" color="1" fill="1" visible="yes" active="yes"/>
<layer number="93" name="Pins" color="2" fill="1" visible="yes" active="yes"/>
<layer number="94" name="Symbols" color="4" fill="1" visible="yes" active="yes"/>
<layer number="95" name="Names" color="7" fill="1" visible="yes" active="yes"/>
<layer number="96" name="Values" color="7" fill="1" visible="yes" active="yes"/>
<layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"/>
<layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"/>
<layer number="4" name="Route4" color="1" fill="4" visible="no" active="no"/>
<layer number="5" name="Route5" color="4" fill="4" visible="no" active="no"/>
<layer number="6" name="Route6" color="1" fill="8" visible="no" active="no"/>
<layer number="7" name="Route7" color="4" fill="8" visible="no" active="no"/>
<layer number="8" name="Route8" color="1" fill="2" visible="no" active="no"/>
<layer number="9" name="Route9" color="4" fill="2" visible="no" active="no"/>
<layer number="10" name="Route10" color="1" fill="7" visible="no" active="no"/>
<layer number="11" name="Route11" color="4" fill="7" visible="no" active="no"/>
<layer number="12" name="Route12" color="1" fill="5" visible="no" active="no"/>
<layer number="13" name="Route13" color="4" fill="5" visible="no" active="no"/>
<layer number="14" name="Route14" color="1" fill="6" visible="no" active="no"/>
<layer number="15" name="Route15" color="4" fill="6" visible="no" active="no"/>
<layer number="2" name="Route2" color="1" fill="3" visible="no" active="no"/>
<layer number="3" name="Route3" color="4" fill="3" visible="no" active="no"/>
</layers>
<library>
<description>&lt;b&gt;Murata Filters&lt;/b&gt;&lt;p&gt;
Distributor RS Components&lt;p&gt;
&lt;author&gt;Created by librarian@cadsoft.de&lt;/author&gt;</description>
<packages>
<package name="LCL">
<description>&lt;b&gt;FILTER&lt;/b&gt;</description>
<wire x1="-3.175" y1="1.905" x2="-3.175" y2="-1.905" width="0.254" layer="51"/>
<wire x1="-3.175" y1="-1.905" x2="3.175" y2="-1.905" width="0.254" layer="51"/>
<wire x1="3.175" y1="-1.905" x2="3.175" y2="1.905" width="0.254" layer="51"/>
<wire x1="3.175" y1="1.905" x2="-3.175" y2="1.905" width="0.254" layer="51"/>
<pad name="0" x="0" y="1.27" drill="0.8128" shape="octagon"/>
<pad name="1" x="-2.54" y="-1.27" drill="0.8128" shape="octagon"/>
<pad name="2" x="2.54" y="-1.27" drill="0.8128" shape="octagon"/>
<text x="-3.175" y="2.54" size="1.27" layer="25">&gt;NAME</text>
<text x="-3.175" y="-3.81" size="1.27" layer="27">&gt;VALUE</text>
</package>
<package name="CSTER12M">
<description>Source: http://search.murata.co.jp/Ceramy/CatalogshowpageAction.do?sDirnm=A07X&amp;sFilnm=81G07006&amp;sType=2&amp;sLang=en&amp;sNHinnm=CSTCR6M00G53Z-R0&amp;sCapt=Standard_Land_Pattern_Dimensions</description>
<wire x1="-2.2" y1="-0.95" x2="2.2" y2="-0.95" width="0.1016" layer="51"/>
<wire x1="2.2" y1="-0.95" x2="2.2" y2="0.95" width="0.1016" layer="21"/>
<wire x1="2.2" y1="0.95" x2="-2.2" y2="0.95" width="0.1016" layer="51"/>
<wire x1="-2.2" y1="0.95" x2="-2.2" y2="-0.95" width="0.1016" layer="21"/>
<smd name="1" x="-1.2" y="0" dx="0.4" dy="2.6" layer="1" stop="no" cream="no"/>
<smd name="2" x="0" y="0" dx="0.4" dy="2.6" layer="1" stop="no" cream="no"/>
<smd name="3" x="1.2" y="0" dx="0.4" dy="2.6" layer="1" stop="no" cream="no"/>
<text x="-2.54" y="1.524" size="1.27" layer="25">&gt;NAME</text>
<text x="-2.54" y="-2.794" size="1.27" layer="27">&gt;VALUE</text>
<rectangle x1="-0.2" y1="-1.3" x2="0.2" y2="1.3" layer="31"/>
<rectangle x1="-1.5" y1="-1.4" x2="-0.9" y2="1.4" layer="29"/>
<rectangle x1="1" y1="-1.3" x2="1.4" y2="1.3" layer="31"/>
<rectangle x1="-1.4" y1="-1.3" x2="-1" y2="1.3" layer="31"/>
<rectangle x1="-0.3" y1="-1.4" x2="0.3" y2="1.4" layer="29"/>
<rectangle x1="0.9" y1="-1.4" x2="1.5" y2="1.4" layer="29"/>
</package>
<package name="NFM3DC">
<description>&lt;b&gt;NFM3DC/NFM3DP&lt;/b&gt; Reflow Soldering&lt;p&gt;
Source: http://search.murata.co.jp/Ceramy/image/img/A03X/MT_NFE.pdf</description>
<wire x1="-1.5" y1="0.525" x2="1.5" y2="0.525" width="0.2032" layer="51"/>
<wire x1="1.5" y1="0.525" x2="1.5" y2="-0.525" width="0.2032" layer="51"/>
<wire x1="1.5" y1="-0.525" x2="-1.5" y2="-0.525" width="0.2032" layer="51"/>
<wire x1="-1.5" y1="-0.525" x2="-1.5" y2="0.525" width="0.2032" layer="51"/>
<smd name="1" x="-1.95" y="0" dx="1.4" dy="1" layer="1"/>
<smd name="2@1" x="0" y="-0.9" dx="1" dy="1.2" layer="1"/>
<smd name="3" x="1.95" y="0" dx="1.4" dy="1" layer="1"/>
<smd name="2@2" x="0" y="0.9" dx="1" dy="1.2" layer="1"/>
<text x="-1.778" y="1.778" size="1.27" layer="25">&gt;NAME</text>
<text x="-1.778" y="-3.048" size="1.27" layer="27">&gt;VALUE</text>
</package>
<package name="NFM21C">
<description>&lt;b&gt;NFM21C/NFR21G/NFM21P/NFL21S&lt;/b&gt;&lt;p&gt;
Source: http://search.murata.co.jp/Ceramy/image/img/PDF/ENG/L0111S0109NFM21C.pdf&lt;br&gt;
http://search.murata.co.jp/Ceramy/image/img/A03X/MT_NFE.pdf</description>
<wire x1="-0.9" y1="0.525" x2="0.9" y2="0.525" width="0.2032" layer="51"/>
<wire x1="0.9" y1="0.525" x2="0.9" y2="-0.525" width="0.2032" layer="51"/>
<wire x1="0.9" y1="-0.525" x2="-0.9" y2="-0.525" width="0.2032" layer="51"/>
<wire x1="-0.9" y1="-0.525" x2="-0.9" y2="0.525" width="0.2032" layer="51"/>
<smd name="1" x="-1.425" y="0" dx="1.4" dy="0.8" layer="1"/>
<smd name="2@1" x="0" y="-0.85" dx="0.6" dy="1.1" layer="1"/>
<smd name="3" x="1.425" y="0" dx="1.4" dy="0.8" layer="1"/>
<smd name="2@2" x="0" y="0.85" dx="0.6" dy="1.1" layer="1"/>
<text x="-1.778" y="1.778" size="1.27" layer="25">&gt;NAME</text>
<text x="-1.778" y="-3.048" size="1.27" layer="27">&gt;VALUE</text>
</package>
</packages>
<symbols>
<symbol name="LCL">
<wire x1="-2.54" y1="2.54" x2="-1.778" y2="2.032" width="0.1524" layer="94"/>
<wire x1="-1.778" y1="2.032" x2="-2.54" y2="1.016" width="0.1524" layer="94"/>
<wire x1="-2.54" y1="1.016" x2="-1.27" y2="1.27" width="0.1524" layer="94"/>
<wire x1="-1.27" y1="1.27" x2="-2.032" y2="0.254" width="0.1524" layer="94"/>
<wire x1="-2.032" y1="0.254" x2="-0.762" y2="0.508" width="0.1524" layer="94"/>
<wire x1="-0.762" y1="0.508" x2="-1.524" y2="-0.508" width="0.1524" layer="94"/>
<wire x1="-1.524" y1="-0.508" x2="-0.762" y2="-1.016" width="0.1524" layer="94"/>
<wire x1="2.54" y1="2.54" x2="1.778" y2="2.032" width="0.1524" layer="94"/>
<wire x1="1.778" y1="2.032" x2="2.54" y2="1.016" width="0.1524" layer="94"/>
<wire x1="2.54" y1="1.016" x2="1.27" y2="1.27" width="0.1524" layer="94"/>
<wire x1="1.27" y1="1.27" x2="2.032" y2="0.254" width="0.1524" layer="94"/>
<wire x1="2.032" y1="0.254" x2="0.762" y2="0.508" width="0.1524" layer="94"/>
<wire x1="0.762" y1="0.508" x2="1.524" y2="-0.508" width="0.1524" layer="94"/>
<wire x1="1.524" y1="-0.508" x2="0.762" y2="-1.016" width="0.1524" layer="94"/>
<text x="2.032" y="-2.794" size="1.778" layer="95">&gt;NAME</text>
<text x="-4.572" y="3.556" size="1.778" layer="96">&gt;VALUE</text>
<rectangle x1="-1.27" y1="-2.794" x2="1.27" y2="-2.286" layer="94"/>
<rectangle x1="-1.27" y1="-1.524" x2="1.27" y2="-1.016" layer="94"/>
<pin name="1" x="-5.08" y="2.54" visible="off" length="short" direction="pas"/>
<pin name="2" x="5.08" y="2.54" visible="off" length="short" direction="pas" rot="R180"/>
<pin name="GND" x="0" y="-5.08" visible="off" length="short" direction="pwr" swaplevel="1" rot="R90"/>
</symbol>
<symbol name="LVL">
<wire x1="-1.016" y1="-2.286" x2="1.016" y2="-1.524" width="0.1524" layer="94"/>
<wire x1="-2.54" y1="2.54" x2="-1.778" y2="2.032" width="0.1524" layer="94"/>
<wire x1="-1.778" y1="2.032" x2="-2.54" y2="1.016" width="0.1524" layer="94"/>
<wire x1="-2.54" y1="1.016" x2="-1.27" y2="1.27" width="0.1524" layer="94"/>
<wire x1="-1.27" y1="1.27" x2="-2.032" y2="0.254" width="0.1524" layer="94"/>
<wire x1="-2.032" y1="0.254" x2="-0.762" y2="0.508" width="0.1524" layer="94"/>
<wire x1="-0.762" y1="0.508" x2="-1.524" y2="-0.508" width="0.1524" layer="94"/>
<wire x1="-1.524" y1="-0.508" x2="-0.762" y2="-1.016" width="0.1524" layer="94"/>
<wire x1="2.54" y1="2.54" x2="1.778" y2="2.032" width="0.1524" layer="94"/>
<wire x1="1.778" y1="2.032" x2="2.54" y2="1.016" width="0.1524" layer="94"/>
<wire x1="2.54" y1="1.016" x2="1.27" y2="1.27" width="0.1524" layer="94"/>
<wire x1="1.27" y1="1.27" x2="2.032" y2="0.254" width="0.1524" layer="94"/>
<wire x1="2.032" y1="0.254" x2="0.762" y2="0.508" width="0.1524" layer="94"/>
<wire x1="0.762" y1="0.508" x2="1.524" y2="-0.508" width="0.1524" layer="94"/>
<wire x1="1.524" y1="-0.508" x2="0.762" y2="-1.016" width="0.1524" layer="94"/>
<text x="2.032" y="-2.794" size="1.778" layer="95">&gt;NAME</text>
<text x="-4.572" y="3.556" size="1.778" layer="96">&gt;VALUE</text>
<rectangle x1="-1.27" y1="-2.794" x2="1.27" y2="-2.286" layer="94"/>
<rectangle x1="-1.27" y1="-1.524" x2="1.27" y2="-1.016" layer="94"/>
<pin name="1" x="-5.08" y="2.54" visible="off" length="short" direction="pas"/>
<pin name="2" x="5.08" y="2.54" visible="off" length="short" direction="pas" rot="R180"/>
<pin name="GND" x="0" y="-5.08" visible="off" length="short" direction="pwr" swaplevel="1" rot="R90"/>
</symbol>
<symbol name="CST">
<wire x1="-5.08" y1="2.54" x2="5.08" y2="2.54" width="0.254" layer="94"/>
<wire x1="5.08" y1="2.54" x2="5.08" y2="0" width="0.254" layer="94"/>
<wire x1="5.08" y1="0" x2="5.08" y2="-5.08" width="0.254" layer="94"/>
<wire x1="5.08" y1="-5.08" x2="0" y2="-5.08" width="0.254" layer="94"/>
<wire x1="0" y1="-5.08" x2="-5.08" y2="-5.08" width="0.254" layer="94"/>
<wire x1="-5.08" y1="-5.08" x2="-5.08" y2="0" width="0.254" layer="94"/>
<wire x1="-5.08" y1="0" x2="-5.08" y2="2.54" width="0.254" layer="94"/>
<wire x1="-5.08" y1="0" x2="-3.81" y2="0" width="0.1524" layer="94"/>
<wire x1="-3.81" y1="0" x2="-1.27" y2="0" width="0.1524" layer="94"/>
<wire x1="-1.27" y1="0" x2="-1.27" y2="1.27" width="0.1524" layer="94"/>
<wire x1="-1.27" y1="0" x2="-1.27" y2="-1.27" width="0.1524" layer="94"/>
<wire x1="-0.508" y1="1.27" x2="-0.508" y2="-1.27" width="0.1524" layer="94"/>
<wire x1="-0.508" y1="-1.27" x2="0.508" y2="-1.27" width="0.1524" layer="94"/>
<wire x1="0.508" y1="-1.27" x2="0.508" y2="1.27" width="0.1524" layer="94"/>
<wire x1="0.508" y1="1.27" x2="-0.508" y2="1.27" width="0.1524" layer="94"/>
<wire x1="1.27" y1="1.27" x2="1.27" y2="0" width="0.1524" layer="94"/>
<wire x1="1.27" y1="0" x2="1.27" y2="-1.27" width="0.1524" layer="94"/>
<wire x1="1.27" y1="0" x2="3.81" y2="0" width="0.1524" layer="94"/>
<wire x1="3.81" y1="0" x2="5.08" y2="0" width="0.1524" layer="94"/>
<wire x1="0" y1="-5.08" x2="0" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="0" y1="-3.302" x2="-1.778" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="0" y1="-3.302" x2="1.778" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="1.778" y1="-2.286" x2="1.778" y2="-4.318" width="0.1524" layer="94"/>
<wire x1="2.54" y1="-2.286" x2="2.54" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="2.54" y1="-3.302" x2="2.54" y2="-4.318" width="0.1524" layer="94"/>
<wire x1="2.54" y1="-3.302" x2="3.81" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="3.81" y1="-3.302" x2="3.81" y2="0" width="0.1524" layer="94"/>
<wire x1="-1.778" y1="-2.286" x2="-1.778" y2="-4.318" width="0.1524" layer="94"/>
<wire x1="-2.54" y1="-2.286" x2="-2.54" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="-2.54" y1="-3.302" x2="-2.54" y2="-4.318" width="0.1524" layer="94"/>
<wire x1="-2.54" y1="-3.302" x2="-3.81" y2="-3.302" width="0.1524" layer="94"/>
<wire x1="-3.81" y1="-3.302" x2="-3.81" y2="0" width="0.1524" layer="94"/>
<circle x="-3.81" y="0" radius="0.254" width="0" layer="94"/>
<circle x="3.81" y="0" radius="0.254" width="0" layer="94"/>
<circle x="0" y="-3.302" radius="0.254" width="0" layer="94"/>
<text x="-5.08" y="3.81" size="1.778" layer="95">&gt;NAME</text>
<text x="2.54" y="-7.62" size="1.778" layer="96">&gt;VALUE</text>
<pin name="1" x="-7.62" y="0" visible="pad" length="short" direction="pas"/>
<pin name="2" x="0" y="-7.62" visible="pad" length="short" direction="pas" rot="R90"/>
<pin name="3" x="7.62" y="0" visible="pad" length="short" direction="pas" rot="R180"/>
</symbol>
<symbol name="C-FILTER">
<wire x1="-2.54" y1="0" x2="2.54" y2="0" width="0.254" layer="94"/>
<wire x1="-2.54" y1="1.778" x2="2.54" y2="1.778" width="0.254" layer="94" curve="106.260205"/>
<wire x1="-2.54" y1="-1.778" x2="2.54" y2="-1.778" width="0.254" layer="94" curve="-106.260205"/>
<wire x1="0" y1="-2.54" x2="0" y2="-0.635" width="0.254" layer="94"/>
<text x="-3.81" y="2.54" size="1.778" layer="95">&gt;NAME</text>
<text x="-3.81" y="5.08" size="1.778" layer="96">&gt;VALUE</text>
<pin name="1" x="-5.08" y="0" visible="off" length="short" direction="pas"/>
<pin name="3" x="5.08" y="0" visible="off" length="short" direction="pas" rot="R180"/>
<pin name="2@1" x="0" y="-5.08" visible="off" length="short" direction="pas" rot="R90"/>
<pin name="2@2" x="0" y="-2.54" visible="off" length="short" direction="pas" rot="R270"/>
</symbol>
</symbols>
<devicesets>
<deviceset name="CSTCR" prefix="Q">
<description>&lt;b&gt;Resonator&lt;/b&gt;&lt;p&gt;
Source: murata.co.jp</description>
<gates>
<gate name="G$1" symbol="CST" x="0" y="0"/>
</gates>
<devices>
<device name="" package="CSTER12M">
<connects>
<connect gate="G$1" pin="1" pad="1"/>
<connect gate="G$1" pin="2" pad="2"/>
<connect gate="G$1" pin="3" pad="3"/>
</connects>
<technologies>
<technology name="6M00G53Z">
<attribute name="MF" value="" constant="no"/>
<attribute name="MPN" value="CSTCC12M0" constant="no"/>
<attribute name="OC_FARNELL" value="1170434" constant="no"/>
<attribute name="OC_NEWARK" value="25M8759" constant="no"/>
</technology>
</technologies>
</device>
</devices>
</deviceset>
</devicesets>
</library>
</drawing>
</eagle>

BIN
eagle/rcl-2.lbr Normal file

Binary file not shown.

BIN
eagle/supply.lbr Normal file

Binary file not shown.

BIN
eagle/supply0.lbr Normal file

Binary file not shown.