Revision 134
Removed old crusty code
trunk/cardbox/swipebox/Makefile | ||
---|---|---|
1 |
# Hey Emacs, this is a -*- makefile -*- |
|
2 |
#---------------------------------------------------------------------------- |
|
3 |
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. |
|
4 |
# |
|
5 |
# Released to the Public Domain |
|
6 |
# |
|
7 |
# Additional material for this makefile was written by: |
|
8 |
# Peter Fleury |
|
9 |
# Tim Henigan |
|
10 |
# Colin O'Flynn |
|
11 |
# Reiner Patommel |
|
12 |
# Markus Pfaff |
|
13 |
# Sander Pool |
|
14 |
# Frederik Rouleau |
|
15 |
# |
|
16 |
#---------------------------------------------------------------------------- |
|
17 |
# On command line: |
|
18 |
# |
|
19 |
# make all = Make software. |
|
20 |
# |
|
21 |
# make clean = Clean out built project files. |
|
22 |
# |
|
23 |
# make coff = Convert ELF to AVR COFF. |
|
24 |
# |
|
25 |
# make extcoff = Convert ELF to AVR Extended COFF. |
|
26 |
# |
|
27 |
# make program = Download the hex file to the device, using avrdude. |
|
28 |
# Please customize the avrdude settings below first! |
|
29 |
# |
|
30 |
# make debug = Start either simulavr or avarice as specified for debugging, |
|
31 |
# with avr-gdb or avr-insight as the front end for debugging. |
|
32 |
# |
|
33 |
# make filename.s = Just compile filename.c into the assembler code only. |
|
34 |
# |
|
35 |
# make filename.i = Create a preprocessed source file for use in submitting |
|
36 |
# bug reports to the GCC project. |
|
37 |
# |
|
38 |
# To rebuild project do "make clean" then "make all". |
|
39 |
#---------------------------------------------------------------------------- |
|
40 |
|
|
41 |
|
|
42 |
# MCU name |
|
43 |
MCU = attiny2313 |
|
44 |
|
|
45 |
|
|
46 |
# Processor frequency. |
|
47 |
# This will define a symbol, F_CPU, in all source code files equal to the |
|
48 |
# processor frequency. You can then use this symbol in your source code to |
|
49 |
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
|
50 |
# automatically to create a 32-bit value in your source code. |
|
51 |
F_CPU = 8000000 |
|
52 |
|
|
53 |
|
|
54 |
# Output format. (can be srec, ihex, binary) |
|
55 |
FORMAT = ihex |
|
56 |
|
|
57 |
|
|
58 |
# Target file name (without extension). |
|
59 |
TARGET = main |
|
60 |
|
|
61 |
# List C source files here. (C dependencies are automatically generated.) |
|
62 |
//SRC = $(wildcard *.c) |
|
63 |
SRC = main.c |
|
64 |
|
|
65 |
# List Assembler source files here. |
|
66 |
# Make them always end in a capital .S. Files ending in a lowercase .s |
|
67 |
# will not be considered source files but generated files (assembler |
|
68 |
# output from the compiler), and will be deleted upon "make clean"! |
|
69 |
# Even though the DOS/Win* filesystem matches both .s and .S the same, |
|
70 |
# it will preserve the spelling of the filenames, and gcc itself does |
|
71 |
# care about how the name is spelled on its command-line. |
|
72 |
ASRC = |
|
73 |
|
|
74 |
|
|
75 |
# Optimization level, can be [0, 1, 2, 3, s]. |
|
76 |
# 0 = turn off optimization. s = optimize for size. |
|
77 |
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
|
78 |
OPT = s |
|
79 |
|
|
80 |
|
|
81 |
# Debugging format. |
|
82 |
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
|
83 |
# AVR Studio 4.10 requires dwarf-2. |
|
84 |
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
|
85 |
DEBUG = |
|
86 |
|
|
87 |
|
|
88 |
# List any extra directories to look for include files here. |
|
89 |
# Each directory must be seperated by a space. |
|
90 |
# Use forward slashes for directory separators. |
|
91 |
# For a directory that has spaces, enclose it in quotes. |
|
92 |
#EXTRAINCDIRS = C:\WinAVR\include\fwr |
|
93 |
|
|
94 |
|
|
95 |
# Compiler flag to set the C Standard level. |
|
96 |
# c89 = "ANSI" C |
|
97 |
# gnu89 = c89 plus GCC extensions |
|
98 |
# c99 = ISO C99 standard (not yet fully implemented) |
|
99 |
# gnu99 = c99 plus GCC extensions |
|
100 |
CSTANDARD = -std=gnu99 |
|
101 |
|
|
102 |
|
|
103 |
# Place -D or -U options here |
|
104 |
CDEFS = -DF_CPU=$(F_CPU)UL |
|
105 |
|
|
106 |
|
|
107 |
# Place -I options here |
|
108 |
CINCS = |
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
#---------------- Compiler Options ---------------- |
|
113 |
# -g*: generate debugging information |
|
114 |
# -O*: optimization level |
|
115 |
# -f...: tuning, see GCC manual and avr-libc documentation |
|
116 |
# -Wall...: warning level |
|
117 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
118 |
# -adhlns...: create assembler listing |
|
119 |
#CFLAGS = -g$(DEBUG) |
|
120 |
CFLAGS += $(CDEFS) $(CINCS) |
|
121 |
CFLAGS += -O$(OPT) |
|
122 |
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
|
123 |
CFLAGS += -Wall -Wstrict-prototypes |
|
124 |
CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
|
125 |
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
|
126 |
CFLAGS += $(CSTANDARD) |
|
127 |
|
|
128 |
|
|
129 |
#---------------- Assembler Options ---------------- |
|
130 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
131 |
# -ahlms: create listing |
|
132 |
# -gstabs: have the assembler create line number information; note that |
|
133 |
# for use in COFF files, additional information about filenames |
|
134 |
# and function names needs to be present in the assembler source |
|
135 |
# files -- see avr-libc docs [FIXME: not yet described there] |
|
136 |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
|
137 |
|
|
138 |
|
|
139 |
#---------------- Library Options ---------------- |
|
140 |
# Minimalistic printf version |
|
141 |
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
|
142 |
|
|
143 |
# Floating point printf version (requires MATH_LIB = -lm below) |
|
144 |
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
|
145 |
|
|
146 |
# If this is left blank, then it will use the Standard printf version. |
|
147 |
PRINTF_LIB = |
|
148 |
#PRINTF_LIB = $(PRINTF_LIB_MIN) |
|
149 |
#PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
|
150 |
|
|
151 |
|
|
152 |
# Minimalistic scanf version |
|
153 |
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
|
154 |
|
|
155 |
# Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
|
156 |
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
|
157 |
|
|
158 |
# If this is left blank, then it will use the Standard scanf version. |
|
159 |
SCANF_LIB = |
|
160 |
#SCANF_LIB = $(SCANF_LIB_MIN) |
|
161 |
#SCANF_LIB = $(SCANF_LIB_FLOAT) |
|
162 |
|
|
163 |
|
|
164 |
MATH_LIB = -lm |
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
#---------------- External Memory Options ---------------- |
|
169 |
|
|
170 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
171 |
# used for variables (.data/.bss) and heap (malloc()). |
|
172 |
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
|
173 |
|
|
174 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
175 |
# only used for heap (malloc()). |
|
176 |
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
|
177 |
|
|
178 |
EXTMEMOPTS = |
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
#---------------- Linker Options ---------------- |
|
183 |
# -Wl,...: tell GCC to pass this to linker. |
|
184 |
# -Map: create map file |
|
185 |
# --cref: add cross reference to map file |
|
186 |
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
|
187 |
LDFLAGS += $(EXTMEMOPTS) |
|
188 |
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
#---------------- Programming Options (avrdude) ---------------- |
|
193 |
|
|
194 |
# Programming hardware: alf avr910 avrisp bascom bsd |
|
195 |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
|
196 |
# |
|
197 |
# Type: avrdude -c ? |
|
198 |
# to get a full listing. |
|
199 |
# |
|
200 |
AVRDUDE_PROGRAMMER = avrispmkII |
|
201 |
|
|
202 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
|
203 |
AVRDUDE_PORT = usb |
|
204 |
# programmer connected to serial device |
|
205 |
|
|
206 |
AVRDUDE_WRITE_FLASH = -b 19200 -U flash:w:$(TARGET).hex #speed was 4800 |
|
207 |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
|
208 |
|
|
209 |
|
|
210 |
# Uncomment the following if you want avrdude's erase cycle counter. |
|
211 |
# Note that this counter needs to be initialized first using -Yn, |
|
212 |
# see avrdude manual. |
|
213 |
#AVRDUDE_ERASE_COUNTER = -y |
|
214 |
|
|
215 |
# Uncomment the following if you do /not/ wish a verification to be |
|
216 |
# performed after programming the device. |
|
217 |
#AVRDUDE_NO_VERIFY = -V |
|
218 |
|
|
219 |
# Increase verbosity level. Please use this when submitting bug |
|
220 |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
|
221 |
# to submit bug reports. |
|
222 |
#AVRDUDE_VERBOSE = -v -v |
|
223 |
|
|
224 |
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -F |
|
225 |
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
|
226 |
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
|
227 |
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
#---------------- Debugging Options ---------------- |
|
232 |
|
|
233 |
# For simulavr only - target MCU frequency. |
|
234 |
DEBUG_MFREQ = $(F_CPU) |
|
235 |
|
|
236 |
# Set the DEBUG_UI to either gdb or insight. |
|
237 |
# DEBUG_UI = gdb |
|
238 |
DEBUG_UI = insight |
|
239 |
|
|
240 |
# Set the debugging back-end to either avarice, simulavr. |
|
241 |
DEBUG_BACKEND = avarice |
|
242 |
#DEBUG_BACKEND = simulavr |
|
243 |
|
|
244 |
# GDB Init Filename. |
|
245 |
GDBINIT_FILE = __avr_gdbinit |
|
246 |
|
|
247 |
# When using avarice settings for the JTAG |
|
248 |
JTAG_DEV = /dev/com1 |
|
249 |
|
|
250 |
# Debugging port used to communicate between GDB / avarice / simulavr. |
|
251 |
DEBUG_PORT = 4242 |
|
252 |
|
|
253 |
# Debugging host used to communicate between GDB / avarice / simulavr, normally |
|
254 |
# just set to localhost unless doing some sort of crazy debugging when |
|
255 |
# avarice is running on a different computer. |
|
256 |
DEBUG_HOST = localhost |
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
#============================================================================ |
|
261 |
|
|
262 |
|
|
263 |
# Define programs and commands. |
|
264 |
SHELL = sh |
|
265 |
CC = avr-gcc |
|
266 |
OBJCOPY = avr-objcopy |
|
267 |
OBJDUMP = avr-objdump |
|
268 |
SIZE = avr-size |
|
269 |
NM = avr-nm |
|
270 |
AVRDUDE = avrdude |
|
271 |
REMOVE = rm -f |
|
272 |
COPY = cp |
|
273 |
WINSHELL = cmd |
|
274 |
|
|
275 |
|
|
276 |
# Define Messages |
|
277 |
# English |
|
278 |
MSG_ERRORS_NONE = Errors: none |
|
279 |
MSG_BEGIN = -------- begin -------- |
|
280 |
MSG_END = -------- end -------- |
|
281 |
MSG_SIZE_BEFORE = Size before: |
|
282 |
MSG_SIZE_AFTER = Size after: |
|
283 |
MSG_COFF = Converting to AVR COFF: |
|
284 |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
|
285 |
MSG_FLASH = Creating load file for Flash: |
|
286 |
MSG_EEPROM = Creating load file for EEPROM: |
|
287 |
MSG_EXTENDED_LISTING = Creating Extended Listing: |
|
288 |
MSG_SYMBOL_TABLE = Creating Symbol Table: |
|
289 |
MSG_LINKING = Linking: |
|
290 |
MSG_COMPILING = Compiling: |
|
291 |
MSG_ASSEMBLING = Assembling: |
|
292 |
MSG_CLEANING = Cleaning project: |
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
# Define all object files. |
|
298 |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
|
299 |
|
|
300 |
# Define all listing files. |
|
301 |
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
|
302 |
|
|
303 |
|
|
304 |
# Compiler flags to generate dependency files. |
|
305 |
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
|
306 |
|
|
307 |
|
|
308 |
# Combine all necessary flags and optional flags. |
|
309 |
# Add target processor to flags. |
|
310 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
|
311 |
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
# Default target. |
|
318 |
all: begin gccversion sizebefore build sizeafter end |
|
319 |
|
|
320 |
build: elf hex eep lss sym |
|
321 |
|
|
322 |
elf: $(TARGET).elf |
|
323 |
hex: $(TARGET).hex |
|
324 |
eep: $(TARGET).eep |
|
325 |
lss: $(TARGET).lss |
|
326 |
sym: $(TARGET).sym |
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
# Eye candy. |
|
331 |
# AVR Studio 3.x does not check make's exit code but relies on |
|
332 |
# the following magic strings to be generated by the compile job. |
|
333 |
begin: |
|
334 |
@echo |
|
335 |
@echo $(MSG_BEGIN) |
|
336 |
|
|
337 |
end: |
|
338 |
@echo $(MSG_END) |
|
339 |
@echo |
|
340 |
|
|
341 |
|
|
342 |
# Display size of file. |
|
343 |
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
|
344 |
ELFSIZE = $(SIZE) -A $(TARGET).elf |
|
345 |
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) |
|
346 |
|
|
347 |
sizebefore: |
|
348 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
|
349 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
350 |
|
|
351 |
sizeafter: |
|
352 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
|
353 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
# Display compiler version information. |
|
358 |
gccversion : |
|
359 |
@$(CC) --version |
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
# Program the device. |
|
364 |
program: $(TARGET).hex $(TARGET).eep |
|
365 |
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
|
366 |
|
|
367 |
|
|
368 |
# Generate avr-gdb config/init file which does the following: |
|
369 |
# define the reset signal, load the target file, connect to target, and set |
|
370 |
# a breakpoint at main(). |
|
371 |
gdb-config: |
|
372 |
@$(REMOVE) $(GDBINIT_FILE) |
|
373 |
@echo define reset >> $(GDBINIT_FILE) |
|
374 |
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
|
375 |
@echo end >> $(GDBINIT_FILE) |
|
376 |
@echo file $(TARGET).elf >> $(GDBINIT_FILE) |
|
377 |
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
|
378 |
ifeq ($(DEBUG_BACKEND),simulavr) |
|
379 |
@echo load >> $(GDBINIT_FILE) |
|
380 |
endif |
|
381 |
@echo break main >> $(GDBINIT_FILE) |
|
382 |
|
|
383 |
debug: gdb-config $(TARGET).elf |
|
384 |
ifeq ($(DEBUG_BACKEND), avarice) |
|
385 |
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
|
386 |
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
|
387 |
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
|
388 |
@$(WINSHELL) /c pause |
|
389 |
|
|
390 |
else |
|
391 |
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
|
392 |
$(DEBUG_MFREQ) --port $(DEBUG_PORT) |
|
393 |
endif |
|
394 |
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
|
400 |
COFFCONVERT=$(OBJCOPY) --debugging \ |
|
401 |
--change-section-address .data-0x800000 \ |
|
402 |
--change-section-address .bss-0x800000 \ |
|
403 |
--change-section-address .noinit-0x800000 \ |
|
404 |
--change-section-address .eeprom-0x810000 |
|
405 |
|
|
406 |
|
|
407 |
coff: $(TARGET).elf |
|
408 |
@echo |
|
409 |
@echo $(MSG_COFF) $(TARGET).cof |
|
410 |
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
|
411 |
|
|
412 |
|
|
413 |
extcoff: $(TARGET).elf |
|
414 |
@echo |
|
415 |
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
|
416 |
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
# Create final output files (.hex, .eep) from ELF output file. |
|
421 |
%.hex: %.elf |
|
422 |
@echo |
|
423 |
@echo $(MSG_FLASH) $@ |
|
424 |
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
|
425 |
|
|
426 |
%.eep: %.elf |
|
427 |
@echo |
|
428 |
@echo $(MSG_EEPROM) $@ |
|
429 |
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
|
430 |
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
|
431 |
|
|
432 |
# Create extended listing file from ELF output file. |
|
433 |
%.lss: %.elf |
|
434 |
@echo |
|
435 |
@echo $(MSG_EXTENDED_LISTING) $@ |
|
436 |
$(OBJDUMP) -h -S $< > $@ |
|
437 |
|
|
438 |
# Create a symbol table from ELF output file. |
|
439 |
%.sym: %.elf |
|
440 |
@echo |
|
441 |
@echo $(MSG_SYMBOL_TABLE) $@ |
|
442 |
$(NM) -n $< > $@ |
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
# Link: create ELF output file from object files. |
|
447 |
.SECONDARY : $(TARGET).elf |
|
448 |
.PRECIOUS : $(OBJ) |
|
449 |
%.elf: $(OBJ) |
|
450 |
@echo |
|
451 |
@echo $(MSG_LINKING) $@ |
|
452 |
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
|
453 |
|
|
454 |
|
|
455 |
# Compile: create object files from C source files. |
|
456 |
%.o : %.c |
|
457 |
@echo |
|
458 |
@echo $(MSG_COMPILING) $< |
|
459 |
$(CC) -c $(ALL_CFLAGS) $< -o $@ |
|
460 |
|
|
461 |
|
|
462 |
# Compile: create assembler files from C source files. |
|
463 |
%.s : %.c |
|
464 |
$(CC) -S $(ALL_CFLAGS) $< -o $@ |
|
465 |
|
|
466 |
|
|
467 |
# Assemble: create object files from assembler source files. |
|
468 |
%.o : %.S |
|
469 |
@echo |
|
470 |
@echo $(MSG_ASSEMBLING) $< |
|
471 |
$(CC) -c $(ALL_ASFLAGS) $< -o $@ |
|
472 |
|
|
473 |
# Create preprocessed source for use in sending a bug report. |
|
474 |
%.i : %.c |
|
475 |
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
|
476 |
|
|
477 |
|
|
478 |
# Target: clean project. |
|
479 |
clean: begin clean_list end |
|
480 |
|
|
481 |
clean_list : |
|
482 |
@echo |
|
483 |
@echo $(MSG_CLEANING) |
|
484 |
$(REMOVE) $(TARGET).hex |
|
485 |
$(REMOVE) $(TARGET).eep |
|
486 |
$(REMOVE) $(TARGET).cof |
|
487 |
$(REMOVE) $(TARGET).elf |
|
488 |
$(REMOVE) $(TARGET).map |
|
489 |
$(REMOVE) $(TARGET).sym |
|
490 |
$(REMOVE) $(TARGET).lss |
|
491 |
$(REMOVE) $(OBJ) |
|
492 |
$(REMOVE) $(LST) |
|
493 |
$(REMOVE) $(SRC:.c=.s) |
|
494 |
$(REMOVE) $(SRC:.c=.d) |
|
495 |
$(REMOVE) .dep/* |
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
# Include the dependency files. |
|
500 |
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
|
501 |
|
|
502 |
|
|
503 |
# Listing of phony targets. |
|
504 |
.PHONY : all begin finish end sizebefore sizeafter gccversion \ |
|
505 |
build elf hex eep lss sym coff extcoff \ |
|
506 |
clean clean_list program debug gdb-config |
|
507 |
|
trunk/cardbox/swipebox/timer.c.old | ||
---|---|---|
1 |
/** @file timer.c |
|
2 |
* |
|
3 |
* @brief Implements the timer functions. See timer.h for full details |
|
4 |
* |
|
5 |
* @author Kevin Woo (kwoo) |
|
6 |
*/ |
|
7 |
|
|
8 |
#include "timer.h" |
|
9 |
|
|
10 |
#include <avr/io.h> |
|
11 |
#include <avr/interrupt.h> |
|
12 |
|
|
13 |
volatile char seconds; //Seconds elapsed |
|
14 |
volatile char minutes; //Minutes exlapsed |
|
15 |
char timeout_flag; //Indicates that timeout has occured |
|
16 |
|
|
17 |
//Initializes all the timer1 registers |
|
18 |
void init_timer() { |
|
19 |
//Clears the control registers for timer 1 |
|
20 |
TCCR1A = 0x00; |
|
21 |
TCCR1B = 0x00; |
|
22 |
TCCR1C = 0x00; |
|
23 |
TIMSK = 0x00; |
|
24 |
|
|
25 |
/***** |
|
26 |
* Output control register A set to clear timer on compare match. |
|
27 |
* Output control register B not connected. |
|
28 |
* WGM is in normal operation. |
|
29 |
* Clock is divided by 256. (This sets it to disconnected, connects |
|
30 |
* in start_timer to above value). |
|
31 |
*****/ |
|
32 |
TCCR1A |= _BV(COM1A1); |
|
33 |
|
|
34 |
//Compares at 1 second with an 8MHz Clock and a 256 prescale. (31250) |
|
35 |
OCR1AH = 0x7A; |
|
36 |
OCR1AL = 0x12; |
|
37 |
|
|
38 |
//Enable the output compare register 1A interrupt |
|
39 |
TIMSK |= _BV(OCIE1A); |
|
40 |
|
|
41 |
timeout_flag = 0; |
|
42 |
|
|
43 |
return; |
|
44 |
} |
|
45 |
|
|
46 |
void start_timer() { |
|
47 |
//Enables the timer. Sets prescale to 256. |
|
48 |
TCCR1B |= _BV(CS12); |
|
49 |
|
|
50 |
return; |
|
51 |
} |
|
52 |
|
|
53 |
void stop_timer() { |
|
54 |
//Disables timer. |
|
55 |
TCCR1B &= ~_BV(CS12); |
|
56 |
seconds = 0; |
|
57 |
minutes = 0; |
|
58 |
|
|
59 |
return; |
|
60 |
} |
|
61 |
|
|
62 |
void reset_timer() { |
|
63 |
seconds = 0; |
|
64 |
minutes = 0; |
|
65 |
return; |
|
66 |
} |
|
67 |
|
|
68 |
ISR(TIMER1_COMP1_vect) { |
|
69 |
if (seconds == 59) { |
|
70 |
minutes++; |
|
71 |
seconds = 0; |
|
72 |
} else { |
|
73 |
seconds++; |
|
74 |
} |
|
75 |
} |
trunk/cardbox/swipebox/uartio.c.old | ||
---|---|---|
1 |
/** @file uart.c |
|
2 |
* |
|
3 |
* @brief Implements UART functionality in hardware |
|
4 |
* |
|
5 |
* @author Kevin Woo (kwoo) |
|
6 |
*/ |
|
7 |
|
|
8 |
#include "uart.h" |
|
9 |
|
|
10 |
char received_byte; //Byte received |
|
11 |
char *transmit_data; //String to send |
|
12 |
char transmit_size; //Size of string that we are sending |
|
13 |
char byte_ready; //New byte has been received |
|
14 |
char transmitting; |
|
15 |
|
|
16 |
static void init_uart(int baud) { |
|
17 |
/* Set baud rate */ |
|
18 |
UBRRH = (unsigned char)(baud>>8); |
|
19 |
UBRRL = (unsigned char)baud; |
|
20 |
|
|
21 |
/* Enable RX/TX and RX/TX Interrupt */ |
|
22 |
UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN); |
|
23 |
|
|
24 |
/* Asynchronous mode, 1 bit stop, 8bit transmissions */ |
|
25 |
UCSRC = _BV(UCSZ1) | _BV(UCSZ0) | ~_BV(USBS); |
|
26 |
|
|
27 |
/* Enable RX pin as input */ |
|
28 |
PORTD &= ~RX; |
|
29 |
|
|
30 |
/* Enable TX pin as output */ |
|
31 |
DDRD |= TX; |
|
32 |
|
|
33 |
/* Enable the TXEN pin as output */ |
|
34 |
DDRB |= TX_EN; |
|
35 |
|
|
36 |
/* RX Status Variables */ |
|
37 |
received_byte = 0; //Initialize first byte |
|
38 |
byte_ready = 0; //Byte is not ready to be read |
|
39 |
|
|
40 |
/* TX Status Variables */ |
|
41 |
transmitting = 0; |
|
42 |
transmit_size = 0; |
|
43 |
} |
|
44 |
|
|
45 |
static char uart_get_byte(char *output_byte) { |
|
46 |
if (byte_ready) { |
|
47 |
*output_byte = received_byte; |
|
48 |
byte_ready = 0; |
|
49 |
return 0; |
|
50 |
} else { |
|
51 |
return -1; |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
static void uart_send_bytes(char *data, int size) { |
|
56 |
//Waits until current transmit is done |
|
57 |
while (transmitting); |
|
58 |
|
|
59 |
uart_enable_transmit(UART_TX_ON); |
|
60 |
transmitting = 1; |
|
61 |
transmit_size = size; |
|
62 |
transmit_data = data; |
|
63 |
return; |
|
64 |
} |
|
65 |
|
|
66 |
static void uart_enable_transmit(char state) { |
|
67 |
if (state == UART_TX_ON) { |
|
68 |
PINB |= TX_EN; |
|
69 |
} else { |
|
70 |
PINB &= ~TX_EN; |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
ISR(UART_RX_vect) { |
|
75 |
received_byte = UDR; |
|
76 |
byte_ready = 1; |
|
77 |
} |
|
78 |
|
|
79 |
ISR(UART_TX_vect) { |
|
80 |
static volatile char position = 0; |
|
81 |
if (transmitting) { |
|
82 |
if (position < transmit_size) { |
|
83 |
UDR = transmit_data[position]; |
|
84 |
position++; |
|
85 |
} else { |
|
86 |
position = 0; |
|
87 |
transmitting = 0; |
|
88 |
uart_enable_transmit(UART_TX_OFF); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
trunk/cardbox/swipebox/uart.h | ||
---|---|---|
1 |
/** @file uart.h |
|
2 |
* |
|
3 |
* @brief Initializes UART functions using the UART hardware module |
|
4 |
* |
|
5 |
* @author Kevin Woo (kwoo) |
|
6 |
*/ |
|
7 |
|
|
8 |
#ifndef UART_H |
|
9 |
#define UART_H |
|
10 |
|
|
11 |
#include <avr/io.h> |
|
12 |
#include <avr/interrupt.h> |
|
13 |
|
|
14 |
/** **/ |
|
15 |
#define UART_TX_OFF 0 |
|
16 |
#define UART_TX_ON 1 |
|
17 |
|
|
18 |
/** @brief RX Pin for the UART **/ |
|
19 |
#define RX _BV(PD0) |
|
20 |
#define TX _BV(PD1) |
|
21 |
#define TX_EN _BV(PB1) |
|
22 |
|
|
23 |
|
|
24 |
/** @brief The most recently received byte **/ |
|
25 |
//extern char received_byte; |
|
26 |
/** @brief If the value in received_byte has been read or not **/ |
|
27 |
//extern char byte_ready; |
|
28 |
//extern char *transmit_data; |
|
29 |
//extern char transmit_size; |
|
30 |
//extern char transmitting; |
|
31 |
|
|
32 |
/** @brief Initializes the UART registers and sets it to the buad rate which msut be the |
|
33 |
* value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps) |
|
34 |
**/ |
|
35 |
static inline void init_uart(int baud); |
|
36 |
/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1 |
|
37 |
* otherwise it returns 0 |
|
38 |
**/ |
|
39 |
static char uart_get_byte(char *output_byte); |
|
40 |
/** @brief Sends a character array of size size. If we are currently transmitting it will block until the |
|
41 |
* the current transmit is done. |
|
42 |
**/ |
|
43 |
static void uart_send_byte(char data); |
|
44 |
static inline void uart_enable_transmit(void); |
|
45 |
static inline void uart_disable_transmit(void); |
|
46 |
#endif |
trunk/cardbox/swipebox/rewrite/timer.h | ||
---|---|---|
1 |
/** @file timer.h |
|
2 |
* |
|
3 |
* @breif Timer functions |
|
4 |
* |
|
5 |
* @author Kevin Woo (kwoo) |
|
6 |
*/ |
|
7 |
|
|
8 |
#ifndef TIMER_H |
|
9 |
#define TIMER_H |
|
10 |
|
|
11 |
/** @brief Max time that we can wait for a full packet from the server before we timeout */ |
|
12 |
#define TIME_OUT 5 |
|
13 |
|
|
14 |
/** @brief Seconds that have elapsed since the timer started */ |
|
15 |
//extern volatile char seconds; |
|
16 |
/** @brief Minutes that have elapsed since the timer started */ |
|
17 |
//extern volatile char minutes; |
|
18 |
//extern char timeout_flag; |
|
19 |
|
|
20 |
/** @brief Sets the registers to use the timer for couting in real time */ |
|
21 |
static inline void init_timer(void); |
|
22 |
/** @brief Starts the timer from last position*/ |
|
23 |
static inline void start_timer(void); |
|
24 |
/** @brief Stops the timer from counting*/ |
|
25 |
static inline void stop_timer(void); |
|
26 |
/** @brief Resets the values of the timer to 0*/ |
|
27 |
static inline void reset_timer(void); |
|
28 |
|
|
29 |
#endif |
trunk/cardbox/swipebox/rewrite/USI_UART_config.h | ||
---|---|---|
1 |
/***************************************************************************** |
|
2 |
* |
|
3 |
* Copyright (C) 2003 Atmel Corporation |
|
4 |
* |
|
5 |
* File : USI_UART_config.h |
|
6 |
* Compiler : IAR EWAAVR 2.28a |
|
7 |
* Created : 18.07.2002 by JLL |
|
8 |
* Modified : 02-10-2003 by LTA |
|
9 |
* |
|
10 |
* Support mail : avr@atmel.com |
|
11 |
* |
|
12 |
* AppNote : AVR307 - Half duplex UART using the USI Interface |
|
13 |
* |
|
14 |
* Description : Header file for USI_UART driver |
|
15 |
* |
|
16 |
* |
|
17 |
****************************************************************************/ |
|
18 |
|
|
19 |
#ifndef __USI_UART_config_h |
|
20 |
#define __USI_UART_config_h |
|
21 |
|
|
22 |
//********** USI UART Defines **********// |
|
23 |
|
|
24 |
//#define SYSTEM_CLOCK 14745600 |
|
25 |
//#define SYSTEM_CLOCK 11059200 |
|
26 |
#define SYSTEM_CLOCK 8000000 |
|
27 |
//#define SYSTEM_CLOCK 7372800 |
|
28 |
//#define SYSTEM_CLOCK 3686400 |
|
29 |
//#define SYSTEM_CLOCK 2000000 |
|
30 |
//#define SYSTEM_CLOCK 1843200 |
|
31 |
//#define SYSTEM_CLOCK 1000000 |
|
32 |
|
|
33 |
//#define BAUDRATE 115200 |
|
34 |
//#define BAUDRATE 57600 |
|
35 |
//#define BAUDRATE 28800 |
|
36 |
//#define BAUDRATE 19200 |
|
37 |
//#define BAUDRATE 14400 |
|
38 |
#define BAUDRATE 9600 |
|
39 |
|
|
40 |
//#define TIMER_PRESCALER 1 |
|
41 |
#define TIMER_PRESCALER 8 |
|
42 |
|
|
43 |
#define UART_RX_BUFFER_SIZE 4 /* 2,4,8,16,32,64,128 or 256 bytes */ |
|
44 |
#define UART_TX_BUFFER_SIZE 4 |
|
45 |
|
|
46 |
|
|
47 |
//********** USI_UART Prototypes **********// |
|
48 |
static unsigned char RxStream[100]; |
|
49 |
|
|
50 |
static unsigned char RxIndex; |
|
51 |
static unsigned char USI_UART_Receive_Bytes( void ); |
|
52 |
static inline unsigned char USI_UART_Data_In_Receive_Buffer( void ); |
|
53 |
static inline unsigned char Bit_Reverse( unsigned char ); |
|
54 |
static inline void USI_UART_Initialise_Receiver( void ); |
|
55 |
//Don't use these |
|
56 |
void USI_UART_Initialise_Transmitter( void ); |
|
57 |
void USI_UART_Transmit_Byte( unsigned char ); |
|
58 |
void USI_UART_Flush_Buffers( void ); |
|
59 |
//End |
|
60 |
|
|
61 |
#endif |
trunk/cardbox/swipebox/rewrite/USI_UART.c | ||
---|---|---|
1 |
|
|
2 |
/***************************************************************************** |
|
3 |
* |
|
4 |
* Copyright (C) 2003 Atmel Corporation |
|
5 |
* |
|
6 |
* File : USI_UART.c |
|
7 |
* Compiler : IAR EWAAVR 2.28a |
|
8 |
* Created : 18.07.2002 by JLL |
|
9 |
* Modified : 02-10-2003 by LTA |
|
10 |
* |
|
11 |
* Support mail : avr@atmel.com |
|
12 |
* |
|
13 |
* Supported devices : ATtiny26 |
|
14 |
* |
|
15 |
* Application Note : AVR307 - Half duplex UART using the USI Interface |
|
16 |
* |
|
17 |
* Description : Functions for USI_UART_receiver and USI_UART_transmitter. |
|
18 |
* Uses Pin Change Interrupt to detect incomming signals. |
|
19 |
* |
|
20 |
* |
|
21 |
****************************************************************************/ |
|
22 |
|
|
23 |
//#include <avr/io.h> // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h. |
|
24 |
//#include <iotiny26.h> |
|
25 |
//#include <avr/interrupt.h> |
|
26 |
//#include <avr/signal.h> |
|
27 |
//#include "USI_UART_config.h" |
|
28 |
|
|
29 |
|
|
30 |
//********** USI UART Defines **********// |
|
31 |
#define RXPIN PB5 |
|
32 |
#define CLKPIN PB7 |
|
33 |
|
|
34 |
#define STARTFLAG 0x45 //100 0101 //0x0B //01011 |
|
35 |
#define NSTARTFLAG 0x3A //011 1010 //0x14 //10100 |
|
36 |
#define STOPFLAG 0x1F //001 1111 0x1F //11111 |
|
37 |
#define NSTOPFLAG 0x60 //110 0000 0x00 //00000 |
|
38 |
#define REVSTART 0x51 //101 0001 0x1A //11010 |
|
39 |
#define NREVSTART 0x2E //010 1110 0x05 //00101 |
|
40 |
|
|
41 |
#define DATA_BITS 7 |
|
42 |
#define START_BIT 7 |
|
43 |
#define STOP_BIT 7 |
|
44 |
#define HALF_FRAME 7 |
|
45 |
|
|
46 |
|
|
47 |
#define USI_COUNTER_MAX_COUNT 16 |
|
48 |
#define INTERRUPT_STARTUP_DELAY (0x11 / TIMER_PRESCALER) |
|
49 |
|
|
50 |
#define USI_COUNTER_SEED_RECEIVE ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) ) |
|
51 |
|
|
52 |
/* General defines */ |
|
53 |
#define TRUE 1 |
|
54 |
#define FALSE 0 |
|
55 |
|
|
56 |
//********** Static Variables **********// |
|
57 |
|
|
58 |
/*__no_init __regvar static unsigned char USI_UART_TxData[15]; // Tells the compiler to store the byte to be transmitted in registry. |
|
59 |
*/ |
|
60 |
//static unsigned char USI_UART_TxData; |
|
61 |
//static unsigned char UART_RxByte; // UART buffers. Size is definable in the header file. |
|
62 |
|
|
63 |
|
|
64 |
static volatile union USI_UART_status // Status byte holding flags. |
|
65 |
{ |
|
66 |
unsigned char status; |
|
67 |
struct |
|
68 |
{ |
|
69 |
unsigned char wait_Card:1; |
|
70 |
unsigned char wait_Start:1; |
|
71 |
unsigned char ongoing_Reception_Of_Package:1; |
|
72 |
unsigned char reception_Buffer_Overflow:1; |
|
73 |
unsigned char data_Ready:1; |
|
74 |
unsigned char flag5:1; |
|
75 |
unsigned char flag6:1; |
|
76 |
unsigned char flag7:1; |
|
77 |
}; |
|
78 |
} USI_UART_status = {0}; |
|
79 |
|
|
80 |
|
|
81 |
//********** USI_UART functions **********// |
|
82 |
|
|
83 |
// Reverses the order of bits in a byte. |
|
84 |
// I.e. MSB is swapped with LSB, etc. |
|
85 |
static inline unsigned char Bit_Reverse5( unsigned char x ) |
|
86 |
{ |
|
87 |
unsigned char c = x&0x04; |
|
88 |
// x = x<<3; |
|
89 |
x = ((x >> 1) & 0x09) | ((x << 1) & 0x12); |
|
90 |
x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c; |
|
91 |
// x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); |
|
92 |
|
|
93 |
return x; |
|
94 |
} |
|
95 |
|
|
96 |
static inline unsigned char Bit_Reverse( unsigned char x ) |
|
97 |
{ |
|
98 |
unsigned char c=0; |
|
99 |
|
|
100 |
c |=0x01&(x>>6); |
|
101 |
c |=0x02&(x>>4); |
|
102 |
c |=0x04&(x>>2); |
|
103 |
c |=0x08&(x>>0); |
|
104 |
c |=0x10&(x<<2); |
|
105 |
c |=0x20&(x<<4); |
|
106 |
c |=0x40&(x<<6); |
|
107 |
|
|
108 |
|
|
109 |
// unsigned char c = x&0x08; |
|
110 |
// x = x<<3; |
|
111 |
// x = ((x >> 1) & 0x09) | ((x << 1) & 0x12); |
|
112 |
// x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c; |
|
113 |
// x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); |
|
114 |
|
|
115 |
// return x; |
|
116 |
|
|
117 |
return c; |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
// Initialise USI for UART reception. |
|
123 |
// Note that this function only enables pinchange interrupt on the USI Data Input pin. |
|
124 |
// The USI is configured to read data within the pinchange interrupt. |
|
125 |
static inline void USI_UART_Initialise_Receiver( void ) { |
|
126 |
// Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt) |
|
127 |
PORTB |= _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4); |
|
128 |
// Set USI DI, DO and SCK pins as inputs. |
|
129 |
DDRB &= ~( _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4)); |
|
130 |
// Disable USI. |
|
131 |
USICR = 0; |
|
132 |
// Clear pin change interrupt flag. |
|
133 |
EIFR = _BV(PCIF); |
|
134 |
PCMSK |= _BV(RXPIN); |
|
135 |
// Enable pin change interrupt for PB7:0. |
|
136 |
GIMSK |= _BV(PCIE); |
|
137 |
|
|
138 |
USI_UART_status.data_Ready=FALSE; |
|
139 |
USI_UART_status.wait_Card=TRUE; |
|
140 |
USI_UART_status.wait_Start=FALSE; |
|
141 |
USI_UART_status.ongoing_Reception_Of_Package = FALSE; |
|
142 |
RxIndex=0; |
|
143 |
} |
|
144 |
|
|
145 |
// Returns a byte from the receive buffer. Waits if buffer is empty. |
|
146 |
static inline unsigned char USI_UART_Receive_Bytes(void) { |
|
147 |
|
|
148 |
while ( !USI_UART_status.data_Ready ); // Wait for incomming data |
|
149 |
|
|
150 |
USI_UART_status.data_Ready=FALSE; |
|
151 |
return RxIndex; // Reverse the order of the bits in the data byte before it returns data from the buffer. |
|
152 |
} |
|
153 |
|
|
154 |
// Check if there is data in the receive buffer. |
|
155 |
static inline unsigned char USI_UART_Data_In_Receive_Buffer(void) { |
|
156 |
return (USI_UART_status.data_Ready); |
|
157 |
} |
|
158 |
|
|
159 |
// ********** Interrupt Handlers ********** // |
|
160 |
|
|
161 |
// The pin change interrupt is used to detect USI_UART reseption. |
|
162 |
// It is here the USI is configured to sample the UART signal. |
|
163 |
|
|
164 |
ISR(PCINT_vect) |
|
165 |
{ |
|
166 |
if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) ))) // If the USI DI pin is low, then it is likely that it |
|
167 |
{ // was this pin that generated the pin change interrupt. |
|
168 |
USICR = (0<<USISIE) | (1<<USIOIE) | // Enable USI Counter OVF interrupt. |
|
169 |
(0<<USIWM1) | (1<<USIWM0) | // Select Three Wire mode. |
|
170 |
(0<<USICS1) | (1<<USICS0) | (0<<USICLK) | // Select Timer0 OVER as USI Clock source. |
|
171 |
(0<<USITC); |
|
172 |
// Note that enabling the USI will also disable the pin change interrupt. |
|
173 |
USISR = 0xF0 | USI_COUNTER_SEED_RECEIVE; // Clear all USI interrupt flags and preload the USI counter to generate interrupt. |
|
174 |
PCMSK |= _BV(CLKPIN); |
|
175 |
PCMSK &= ~_BV(RXPIN); |
|
176 |
|
|
177 |
//GIMSK &= ~(1<<PCIE); // Disable pin change interrupt for PB3:0. |
|
178 |
USI_UART_status.wait_Start = TRUE; |
|
179 |
USI_UART_status.wait_Card = FALSE; |
|
180 |
|
|
181 |
} |
|
182 |
else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN)))) |
|
183 |
{ |
|
184 |
// PORTD |= (1<<PD4); |
|
185 |
if((USIDR&0x7F)==(NREVSTART)) /////////////MAYBE SHOULD BE REVSTART |
|
186 |
{ |
|
187 |
USI_UART_status.wait_Start = FALSE; |
|
188 |
USI_UART_status.ongoing_Reception_Of_Package = TRUE; |
|
189 |
USISR = 0xF0 | USI_COUNTER_SEED_RECEIVE; // Clear all USI interrupt flags, preload the USI counter to generate an interrupt |
|
190 |
GIMSK &= ~(1<<PCIE); |
|
191 |
PCMSK &=~(1<<CLKPIN); |
|
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register. |
|
197 |
// The interrupt is used for both transmission and reception. |
|
198 |
ISR(SIG_USI_OVERFLOW) { |
|
199 |
|
|
200 |
led_on(LED_YELLOW); |
|
201 |
|
|
202 |
if(USI_UART_status.ongoing_Reception_Of_Package) { |
|
203 |
char b; |
|
204 |
|
|
205 |
//Byte comes in inverted and backwards, invert and reverse it to make it correct |
|
206 |
b=Bit_Reverse(~USIDR)&0x0F; |
|
207 |
|
|
208 |
//End character |
|
209 |
if(b>9) { |
|
210 |
USICR = 0; // Disable USI. |
|
211 |
EIFR = _BV(PCIF); // Clear pin change interrupt flag. |
|
212 |
USI_UART_status.data_Ready=TRUE; |
|
213 |
} else { |
|
214 |
//RxStream[RxIndex] = b; // Store received data in buffer. Note that the data must be bit reversed before used. |
|
215 |
//RxIndex=RxIndex+1; |
|
216 |
|
|
217 |
//WARNING: This is potentially dangerous if the card is larger than we expect. We should probably put some checks in here |
|
218 |
// to prevent buffer |
|
219 |
packet[RxIndex + HEADER_OFFSET] = b; |
|
220 |
RxIndex++; |
|
221 |
USISR = 0xF0 | USI_COUNTER_SEED_RECEIVE; // Clear all USI interrupt flags and Preload the USI counter to generate interrupt. |
|
222 |
} |
|
223 |
|
|
224 |
} |
|
225 |
|
|
226 |
led_on(LED_GREEN); |
|
227 |
} |
trunk/cardbox/swipebox/rewrite/uart.c | ||
---|---|---|
1 |
#include "uart.h" |
|
2 |
#include <avr/io.h> |
|
3 |
|
|
4 |
/** @file uart.c |
|
5 |
* |
|
6 |
* @brief Implements UART functionality in hardware |
|
7 |
* |
|
8 |
* @author Kevin Woo (kwoo) |
|
9 |
*/ |
|
10 |
static void init_uart(int baud) { |
|
11 |
/* Set baud rate */ |
|
12 |
UBRRH = (unsigned char)(baud>>8); |
|
13 |
UBRRL = (unsigned char)baud; |
|
14 |
|
|
15 |
UCSRB = 0; |
|
16 |
UCSRC = 0; |
|
17 |
|
|
18 |
/* Enable RX/TX and RX/TX Interrupt */ |
|
19 |
UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN); |
|
20 |
|
|
21 |
/* Asynchronous mode, 1 bit stop, 8bit transmissions */ |
|
22 |
UCSRC = _BV(UCSZ1) | _BV(UCSZ0); |
|
23 |
|
|
24 |
/* Enable RX pin as input */ |
|
25 |
PORTD &= ~RX; |
|
26 |
|
|
27 |
/* Enable TX pin as output */ |
|
28 |
DDRD |= TX; |
|
29 |
|
|
30 |
/* Enable the TXEN pin as output */ |
|
31 |
DDRB |= TX_EN; |
|
32 |
|
|
33 |
/* RX Status Variables */ |
|
34 |
received_byte = 0; //Initialize first byte |
|
35 |
byte_ready = 0; //Byte is not ready to be read |
|
36 |
|
|
37 |
/* TX Status Variables */ |
|
38 |
transmitting = 0; |
|
39 |
transmit_size = 0; |
|
40 |
} |
|
41 |
|
|
42 |
static char uart_get_byte(char *output_byte) { |
|
43 |
while (!byte_ready) { |
|
44 |
if (seconds == TIME_OUT) { |
|
45 |
timeout_flag = 1; |
|
46 |
return; |
|
47 |
} |
|
48 |
} |
|
49 |
*output_byte = received_byte; |
|
50 |
return received_byte; |
|
51 |
|
|
52 |
|
|
53 |
/* |
|
54 |
if (byte_ready) { |
|
55 |
*output_byte = received_byte; |
|
56 |
byte_ready = 0; |
|
57 |
return 0; |
|
58 |
} else { |
|
59 |
return -1; |
|
60 |
} |
|
61 |
*/ |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
static void uart_puts (char* str, int len){ |
|
66 |
for(int i=0;i<len;i++){ |
|
67 |
uart_send_byte('@');//trash byte //TODO: figure out whats going on here |
|
68 |
uart_send_byte(str[i]); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
static void uart_send_byte (char data) { |
|
73 |
//Wait for the UART line to not be busy sending |
|
74 |
while (!(UCSRA & (1 << UDRE))); |
|
75 |
|
|
76 |
//Enable RS485 Converter, give it time to turn on |
|
77 |
uart_enable_transmit(); |
|
78 |
_delay_loop_2(8000); //Approxmiately 2ms |
|
79 |
//led_on(LED_RED); |
|
80 |
UDR = data; |
|
81 |
//led_on(LED_YELLOW); |
|
82 |
|
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
static void uart_enable_transmit() { |
|
87 |
PINB |= TX_EN; |
|
88 |
} |
|
89 |
|
|
90 |
static void uart_disable_transmit() { |
|
91 |
PINB &= ~TX_EN; |
|
92 |
} |
|
93 |
|
|
94 |
ISR(USART_RX_vect) { |
|
95 |
while(1); |
|
96 |
received_byte = UDR; |
|
97 |
byte_ready = 1; |
|
98 |
} |
|
99 |
|
|
100 |
ISR(USART_TX_vect) { |
|
101 |
//static volatile char loc = 1; |
|
102 |
//if (transmitting) { |
|
103 |
//if (loc < transmit_size) { |
|
104 |
// UDR = transmit_data[loc]; |
|
105 |
// loc++; |
|
106 |
//} else { |
|
107 |
// loc = 1; |
|
108 |
//transmitting = 0; |
|
109 |
_delay_loop_2(8000); //Approxmiately 2ms |
|
110 |
uart_disable_transmit(); |
|
111 |
//led_on(LED_GREEN); |
|
112 |
//} |
|
113 |
//} |
|
114 |
} |
trunk/cardbox/swipebox/rewrite/Makefile | ||
---|---|---|
1 |
# Hey Emacs, this is a -*- makefile -*- |
|
2 |
#---------------------------------------------------------------------------- |
|
3 |
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. |
|
4 |
# |
|
5 |
# Released to the Public Domain |
|
6 |
# |
|
7 |
# Additional material for this makefile was written by: |
|
8 |
# Peter Fleury |
|
9 |
# Tim Henigan |
|
10 |
# Colin O'Flynn |
|
11 |
# Reiner Patommel |
|
12 |
# Markus Pfaff |
|
13 |
# Sander Pool |
|
14 |
# Frederik Rouleau |
|
15 |
# |
|
16 |
#---------------------------------------------------------------------------- |
|
17 |
# On command line: |
|
18 |
# |
|
19 |
# make all = Make software. |
|
20 |
# |
|
21 |
# make clean = Clean out built project files. |
|
22 |
# |
|
23 |
# make coff = Convert ELF to AVR COFF. |
|
24 |
# |
|
25 |
# make extcoff = Convert ELF to AVR Extended COFF. |
|
26 |
# |
|
27 |
# make program = Download the hex file to the device, using avrdude. |
|
28 |
# Please customize the avrdude settings below first! |
|
29 |
# |
|
30 |
# make debug = Start either simulavr or avarice as specified for debugging, |
|
31 |
# with avr-gdb or avr-insight as the front end for debugging. |
|
32 |
# |
|
33 |
# make filename.s = Just compile filename.c into the assembler code only. |
|
34 |
# |
|
35 |
# make filename.i = Create a preprocessed source file for use in submitting |
|
36 |
# bug reports to the GCC project. |
|
37 |
# |
|
38 |
# To rebuild project do "make clean" then "make all". |
|
39 |
#---------------------------------------------------------------------------- |
|
40 |
|
|
41 |
|
|
42 |
# MCU name |
|
43 |
MCU = attiny2313 |
|
44 |
|
|
45 |
|
|
46 |
# Processor frequency. |
|
47 |
# This will define a symbol, F_CPU, in all source code files equal to the |
|
48 |
# processor frequency. You can then use this symbol in your source code to |
|
49 |
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
|
50 |
# automatically to create a 32-bit value in your source code. |
|
51 |
F_CPU = 8000000 |
|
52 |
|
|
53 |
|
|
54 |
# Output format. (can be srec, ihex, binary) |
|
55 |
FORMAT = ihex |
|
56 |
|
|
57 |
|
|
58 |
# Target file name (without extension). |
|
59 |
TARGET = main |
|
60 |
|
|
61 |
# List C source files here. (C dependencies are automatically generated.) |
|
62 |
#SRC = $(wildcard *.c) |
|
63 |
SRC = main.c uart.c USI_UART.c |
|
64 |
|
|
65 |
# List Assembler source files here. |
|
66 |
# Make them always end in a capital .S. Files ending in a lowercase .s |
|
67 |
# will not be considered source files but generated files (assembler |
|
68 |
# output from the compiler), and will be deleted upon "make clean"! |
|
69 |
# Even though the DOS/Win* filesystem matches both .s and .S the same, |
|
70 |
# it will preserve the spelling of the filenames, and gcc itself does |
|
71 |
# care about how the name is spelled on its command-line. |
|
72 |
ASRC = |
|
73 |
|
|
74 |
|
|
75 |
# Optimization level, can be [0, 1, 2, 3, s]. |
|
76 |
# 0 = turn off optimization. s = optimize for size. |
|
77 |
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
|
78 |
OPT = s |
|
79 |
|
|
80 |
|
|
81 |
# Debugging format. |
|
82 |
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
|
83 |
# AVR Studio 4.10 requires dwarf-2. |
|
84 |
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
|
85 |
DEBUG = |
|
86 |
|
|
87 |
|
|
88 |
# List any extra directories to look for include files here. |
|
89 |
# Each directory must be seperated by a space. |
|
90 |
# Use forward slashes for directory separators. |
|
91 |
# For a directory that has spaces, enclose it in quotes. |
|
92 |
#EXTRAINCDIRS = C:\WinAVR\include\fwr |
|
93 |
|
|
94 |
|
|
95 |
# Compiler flag to set the C Standard level. |
|
96 |
# c89 = "ANSI" C |
|
97 |
# gnu89 = c89 plus GCC extensions |
|
98 |
# c99 = ISO C99 standard (not yet fully implemented) |
|
99 |
# gnu99 = c99 plus GCC extensions |
|
100 |
CSTANDARD = -std=gnu99 |
|
101 |
|
|
102 |
|
|
103 |
# Place -D or -U options here |
|
104 |
CDEFS = -DF_CPU=$(F_CPU)UL |
|
105 |
|
|
106 |
|
|
107 |
# Place -I options here |
|
108 |
CINCS = |
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
#---------------- Compiler Options ---------------- |
|
113 |
# -g*: generate debugging information |
|
114 |
# -O*: optimization level |
|
115 |
# -f...: tuning, see GCC manual and avr-libc documentation |
|
116 |
# -Wall...: warning level |
|
117 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
118 |
# -adhlns...: create assembler listing |
|
119 |
#CFLAGS = -g$(DEBUG) |
|
120 |
CFLAGS += $(CDEFS) $(CINCS) |
|
121 |
CFLAGS += -O$(OPT) |
|
122 |
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
|
123 |
CFLAGS += -Wall -Wstrict-prototypes |
|
124 |
CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
|
125 |
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
|
126 |
CFLAGS += $(CSTANDARD) |
|
127 |
|
|
128 |
|
|
129 |
#---------------- Assembler Options ---------------- |
|
130 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
131 |
# -ahlms: create listing |
|
132 |
# -gstabs: have the assembler create line number information; note that |
|
133 |
# for use in COFF files, additional information about filenames |
|
134 |
# and function names needs to be present in the assembler source |
|
135 |
# files -- see avr-libc docs [FIXME: not yet described there] |
|
136 |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
|
137 |
|
|
138 |
|
|
139 |
#---------------- Library Options ---------------- |
|
140 |
# Minimalistic printf version |
|
141 |
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
|
142 |
|
|
143 |
# Floating point printf version (requires MATH_LIB = -lm below) |
|
144 |
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
|
145 |
|
|
146 |
# If this is left blank, then it will use the Standard printf version. |
|
147 |
PRINTF_LIB = |
|
148 |
#PRINTF_LIB = $(PRINTF_LIB_MIN) |
|
149 |
#PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
|
150 |
|
|
151 |
|
|
152 |
# Minimalistic scanf version |
|
153 |
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
|
154 |
|
|
155 |
# Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
|
156 |
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
|
157 |
|
|
158 |
# If this is left blank, then it will use the Standard scanf version. |
|
159 |
SCANF_LIB = |
|
160 |
#SCANF_LIB = $(SCANF_LIB_MIN) |
|
161 |
#SCANF_LIB = $(SCANF_LIB_FLOAT) |
|
162 |
|
|
163 |
|
|
164 |
MATH_LIB = -lm |
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
#---------------- External Memory Options ---------------- |
|
169 |
|
|
170 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
171 |
# used for variables (.data/.bss) and heap (malloc()). |
|
172 |
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
|
173 |
|
|
174 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
175 |
# only used for heap (malloc()). |
|
176 |
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
|
177 |
|
|
178 |
EXTMEMOPTS = |
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
#---------------- Linker Options ---------------- |
|
183 |
# -Wl,...: tell GCC to pass this to linker. |
|
184 |
# -Map: create map file |
|
185 |
# --cref: add cross reference to map file |
|
186 |
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
|
187 |
LDFLAGS += $(EXTMEMOPTS) |
|
188 |
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
#---------------- Programming Options (avrdude) ---------------- |
|
193 |
|
|
194 |
# Programming hardware: alf avr910 avrisp bascom bsd |
|
195 |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
|
196 |
# |
|
197 |
# Type: avrdude -c ? |
|
198 |
# to get a full listing. |
|
199 |
# |
|
200 |
AVRDUDE_PROGRAMMER = avrispmkII |
|
201 |
|
|
202 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
|
203 |
AVRDUDE_PORT = usb |
|
204 |
# programmer connected to serial device |
|
205 |
|
|
206 |
AVRDUDE_WRITE_FLASH = -b 19200 -U flash:w:$(TARGET).hex #speed was 4800 |
|
207 |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
|
208 |
|
|
209 |
|
|
210 |
# Uncomment the following if you want avrdude's erase cycle counter. |
|
211 |
# Note that this counter needs to be initialized first using -Yn, |
|
212 |
# see avrdude manual. |
|
213 |
#AVRDUDE_ERASE_COUNTER = -y |
|
214 |
|
|
215 |
# Uncomment the following if you do /not/ wish a verification to be |
|
216 |
# performed after programming the device. |
|
217 |
#AVRDUDE_NO_VERIFY = -V |
|
218 |
|
|
219 |
# Increase verbosity level. Please use this when submitting bug |
|
220 |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
|
221 |
# to submit bug reports. |
|
222 |
#AVRDUDE_VERBOSE = -v -v |
|
223 |
|
|
224 |
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -F |
|
225 |
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
|
226 |
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
|
227 |
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
#---------------- Debugging Options ---------------- |
|
232 |
|
|
233 |
# For simulavr only - target MCU frequency. |
|
234 |
DEBUG_MFREQ = $(F_CPU) |
|
235 |
|
|
236 |
# Set the DEBUG_UI to either gdb or insight. |
|
237 |
# DEBUG_UI = gdb |
|
238 |
DEBUG_UI = insight |
|
239 |
|
|
240 |
# Set the debugging back-end to either avarice, simulavr. |
|
241 |
DEBUG_BACKEND = avarice |
|
242 |
#DEBUG_BACKEND = simulavr |
|
243 |
|
|
244 |
# GDB Init Filename. |
|
245 |
GDBINIT_FILE = __avr_gdbinit |
|
246 |
|
|
247 |
# When using avarice settings for the JTAG |
|
248 |
JTAG_DEV = /dev/com1 |
|
249 |
|
|
250 |
# Debugging port used to communicate between GDB / avarice / simulavr. |
|
251 |
DEBUG_PORT = 4242 |
|
252 |
|
|
253 |
# Debugging host used to communicate between GDB / avarice / simulavr, normally |
|
254 |
# just set to localhost unless doing some sort of crazy debugging when |
|
255 |
# avarice is running on a different computer. |
|
256 |
DEBUG_HOST = localhost |
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
#============================================================================ |
|
261 |
|
|
262 |
|
|
263 |
# Define programs and commands. |
|
264 |
SHELL = sh |
|
265 |
CC = avr-gcc |
|
266 |
OBJCOPY = avr-objcopy |
|
267 |
OBJDUMP = avr-objdump |
|
268 |
SIZE = avr-size |
|
269 |
NM = avr-nm |
|
270 |
AVRDUDE = avrdude |
|
271 |
REMOVE = rm -f |
|
272 |
COPY = cp |
|
273 |
WINSHELL = cmd |
|
274 |
|
|
275 |
|
|
276 |
# Define Messages |
|
277 |
# English |
|
278 |
MSG_ERRORS_NONE = Errors: none |
|
279 |
MSG_BEGIN = -------- begin -------- |
|
280 |
MSG_END = -------- end -------- |
|
281 |
MSG_SIZE_BEFORE = Size before: |
|
282 |
MSG_SIZE_AFTER = Size after: |
|
283 |
MSG_COFF = Converting to AVR COFF: |
|
284 |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
|
285 |
MSG_FLASH = Creating load file for Flash: |
|
286 |
MSG_EEPROM = Creating load file for EEPROM: |
|
287 |
MSG_EXTENDED_LISTING = Creating Extended Listing: |
|
288 |
MSG_SYMBOL_TABLE = Creating Symbol Table: |
|
289 |
MSG_LINKING = Linking: |
|
290 |
MSG_COMPILING = Compiling: |
|
291 |
MSG_ASSEMBLING = Assembling: |
|
292 |
MSG_CLEANING = Cleaning project: |
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
# Define all object files. |
|
298 |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
|
299 |
|
|
300 |
# Define all listing files. |
|
301 |
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
|
302 |
|
|
303 |
|
|
304 |
# Compiler flags to generate dependency files. |
|
305 |
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
|
306 |
|
Also available in: Unified diff