Project

General

Profile

Revision 484

moved another test

View differences:

trunk/code/projects/colonet/testing/robot_routine_reg_test/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 = atmega128
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 = 16000000
52

  
53

  
54
# Output format. (can be srec, ihex, binary)
55
FORMAT = ihex
56

  
57

  
58
# Target file name (without extension).
59
TARGET = robot_routine_reg_test
60

  
61

  
62
# List C source files here. (C dependencies are automatically generated.)
63
SRC = $(wildcard *.c)
64
#$(TARGET).c 
65

  
66

  
67
# List Assembler source files here.
68
#     Make them always end in a capital .S.  Files ending in a lowercase .s
69
#     will not be considered source files but generated files (assembler
70
#     output from the compiler), and will be deleted upon "make clean"!
71
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
72
#     it will preserve the spelling of the filenames, and gcc itself does
73
#     care about how the name is spelled on its command-line.
74
ASRC = 
75

  
76

  
77
# Optimization level, can be [0, 1, 2, 3, s]. 
78
#     0 = turn off optimization. s = optimize for size.
79
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
80
OPT = s
81

  
82

  
83
# Debugging format.
84
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
85
#     AVR Studio 4.10 requires dwarf-2.
86
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
87
DEBUG = dwarf-2
88

  
89

  
90
# List any extra directories to look for include files here.
91
#     Each directory must be seperated by a space.
92
#     Use forward slashes for directory separators.
93
#     For a directory that has spaces, enclose it in quotes.
94
EXTRAINCDIRS = c:/roboclub_repository/emarinel/code/colonet/lib c:/roboclub_repository/emarinel/code/firefly_plus_lib 
95

  
96
# Compiler flag to set the C Standard level.
97
#     c89   = "ANSI" C
98
#     gnu89 = c89 plus GCC extensions
99
#     c99   = ISO C99 standard (not yet fully implemented)
100
#     gnu99 = c99 plus GCC extensions
101
CSTANDARD = -std=gnu99
102

  
103

  
104
# Place -D or -U options here
105
CDEFS = -DF_CPU=$(F_CPU)UL
106

  
107

  
108
# Place -I options here
109
CINCS =
110

  
111

  
112

  
113
#---------------- Compiler Options ----------------
114
#  -g*:          generate debugging information
115
#  -O*:          optimization level
116
#  -f...:        tuning, see GCC manual and avr-libc documentation
117
#  -Wall...:     warning level
118
#  -Wa,...:      tell GCC to pass this to the assembler.
119
#    -adhlns...: create assembler listing
120
CFLAGS = -g$(DEBUG)
121
CFLAGS += $(CDEFS) $(CINCS)
122
CFLAGS += -O$(OPT)
123
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
124
CFLAGS += -Wall -Wstrict-prototypes
125
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
126
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
127
CFLAGS += $(CSTANDARD)
128

  
129

  
130
#---------------- Assembler Options ----------------
131
#  -Wa,...:   tell GCC to pass this to the assembler.
132
#  -ahlms:    create listing
133
#  -gstabs:   have the assembler create line number information; note that
134
#             for use in COFF files, additional information about filenames
135
#             and function names needs to be present in the assembler source
136
#             files -- see avr-libc docs [FIXME: not yet described there]
137
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
138

  
139

  
140
#---------------- Library Options ----------------
141
# Minimalistic printf version
142
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
143

  
144
# Floating point printf version (requires MATH_LIB = -lm below)
145
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
146

  
147
# If this is left blank, then it will use the Standard printf version.
148
PRINTF_LIB = 
149
#PRINTF_LIB = $(PRINTF_LIB_MIN)
150
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
151

  
152

  
153
# Minimalistic scanf version
154
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
155

  
156
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
157
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
158

  
159
# If this is left blank, then it will use the Standard scanf version.
160
SCANF_LIB = 
161
#SCANF_LIB = $(SCANF_LIB_MIN)
162
#SCANF_LIB = $(SCANF_LIB_FLOAT)
163

  
164

  
165
MATH_LIB = -lm
166

  
167

  
168

  
169
#---------------- External Memory Options ----------------
170

  
171
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
172
# used for variables (.data/.bss) and heap (malloc()).
173
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
174

  
175
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
176
# only used for heap (malloc()).
177
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
178

  
179
EXTMEMOPTS =
180

  
181

  
182

  
183
#---------------- Linker Options ----------------
184
#  -Wl,...:     tell GCC to pass this to linker.
185
#    -Map:      create map file
186
#    --cref:    add cross reference to  map file
187
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
188
LDFLAGS += $(EXTMEMOPTS)
189
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
190

  
191

  
192

  
193
#---------------- Programming Options (avrdude) ----------------
194

  
195
# Programming hardware: alf avr910 avrisp bascom bsd 
196
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
197
#
198
# Type: avrdude -c ?
199
# to get a full listing.
200
#
201
AVRDUDE_PROGRAMMER = avrisp
202

  
203
# com1 = serial port. Use lpt1 to connect to parallel port.
204
AVRDUDE_PORT = com1
205
# programmer connected to serial device
206

  
207
AVRDUDE_WRITE_FLASH = -b 9600 -U flash:w:$(TARGET).hex
208
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
209

  
210

  
211
# Uncomment the following if you want avrdude's erase cycle counter.
212
# Note that this counter needs to be initialized first using -Yn,
213
# see avrdude manual.
214
#AVRDUDE_ERASE_COUNTER = -y
215

  
216
# Uncomment the following if you do /not/ wish a verification to be
217
# performed after programming the device.
218
AVRDUDE_NO_VERIFY = -V
219

  
220
# Increase verbosity level.  Please use this when submitting bug
221
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
222
# to submit bug reports.
223
#AVRDUDE_VERBOSE = -v -v
224

  
225
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
226
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
227
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
228
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
229

  
230

  
231

  
232
#---------------- Debugging Options ----------------
233

  
234
# For simulavr only - target MCU frequency.
235
DEBUG_MFREQ = $(F_CPU)
236

  
237
# Set the DEBUG_UI to either gdb or insight.
238
# DEBUG_UI = gdb
239
DEBUG_UI = insight
240

  
241
# Set the debugging back-end to either avarice, simulavr.
242
DEBUG_BACKEND = avarice
243
#DEBUG_BACKEND = simulavr
244

  
245
# GDB Init Filename.
246
GDBINIT_FILE = __avr_gdbinit
247

  
248
# When using avarice settings for the JTAG
249
JTAG_DEV = /dev/com1
250

  
251
# Debugging port used to communicate between GDB / avarice / simulavr.
252
DEBUG_PORT = 4242
253

  
254
# Debugging host used to communicate between GDB / avarice / simulavr, normally
255
#     just set to localhost unless doing some sort of crazy debugging when 
256
#     avarice is running on a different computer.
257
DEBUG_HOST = localhost
258

  
259

  
260

  
261
#============================================================================
262

  
263

  
264
# Define programs and commands.
265
SHELL = sh
266
CC = avr-gcc
267
OBJCOPY = avr-objcopy
268
OBJDUMP = avr-objdump
269
SIZE = avr-size
270
NM = avr-nm
271
AVRDUDE = avrdude
272
REMOVE = rm -f
273
COPY = cp
274
WINSHELL = cmd
275

  
276

  
277
# Define Messages
278
# English
279
MSG_ERRORS_NONE = Errors: none
280
MSG_BEGIN = -------- begin --------
281
MSG_END = --------  end  --------
282
MSG_SIZE_BEFORE = Size before: 
283
MSG_SIZE_AFTER = Size after:
284
MSG_COFF = Converting to AVR COFF:
285
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
286
MSG_FLASH = Creating load file for Flash:
287
MSG_EEPROM = Creating load file for EEPROM:
288
MSG_EXTENDED_LISTING = Creating Extended Listing:
289
MSG_SYMBOL_TABLE = Creating Symbol Table:
290
MSG_LINKING = Linking:
291
MSG_COMPILING = Compiling:
292
MSG_ASSEMBLING = Assembling:
293
MSG_CLEANING = Cleaning project:
294

  
295

  
296

  
297

  
298
# Define all object files.
299
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
300

  
301
# Define all listing files.
302
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
303

  
304

  
305
# Compiler flags to generate dependency files.
306
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
307

  
308

  
309
# Combine all necessary flags and optional flags.
310
# Add target processor to flags.
311
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
312
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
313

  
314

  
315

  
316

  
317

  
318
# Default target.
319
all: begin gccversion sizebefore build sizeafter end
320

  
321
build: elf hex eep lss sym
322

  
323
elf: $(TARGET).elf
324
hex: $(TARGET).hex
325
eep: $(TARGET).eep
326
lss: $(TARGET).lss 
327
sym: $(TARGET).sym
328

  
329

  
330

  
331
# Eye candy.
332
# AVR Studio 3.x does not check make's exit code but relies on
333
# the following magic strings to be generated by the compile job.
334
begin:
335
	@echo
336
	@echo $(MSG_BEGIN)
337

  
338
end:
339
	@echo $(MSG_END)
340
	@echo
341

  
342

  
343
# Display size of file.
344
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
345
ELFSIZE = $(SIZE) -A $(TARGET).elf
346
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
347

  
348
sizebefore:
349
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
350
	$(AVRMEM) 2>/dev/null; echo; fi
351

  
352
sizeafter:
353
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
354
	$(AVRMEM) 2>/dev/null; echo; fi
355

  
356

  
357

  
358
# Display compiler version information.
359
gccversion : 
360
	@$(CC) --version
361

  
362

  
363

  
364
# Program the device.  
365
program: $(TARGET).hex $(TARGET).eep
366
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
367

  
368

  
369
# Generate avr-gdb config/init file which does the following:
370
#     define the reset signal, load the target file, connect to target, and set 
371
#     a breakpoint at main().
372
gdb-config: 
373
	@$(REMOVE) $(GDBINIT_FILE)
374
	@echo define reset >> $(GDBINIT_FILE)
375
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
376
	@echo end >> $(GDBINIT_FILE)
377
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
378
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
379
ifeq ($(DEBUG_BACKEND),simulavr)
380
	@echo load  >> $(GDBINIT_FILE)
381
endif	
382
	@echo break main >> $(GDBINIT_FILE)
383
	
384
debug: gdb-config $(TARGET).elf
385
ifeq ($(DEBUG_BACKEND), avarice)
386
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
387
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
388
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
389
	@$(WINSHELL) /c pause
390
	
391
else
392
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
393
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
394
endif
395
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
396
	
397

  
398

  
399

  
400
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
401
COFFCONVERT=$(OBJCOPY) --debugging \
402
--change-section-address .data-0x800000 \
403
--change-section-address .bss-0x800000 \
404
--change-section-address .noinit-0x800000 \
405
--change-section-address .eeprom-0x810000 
406

  
407

  
408
coff: $(TARGET).elf
409
	@echo
410
	@echo $(MSG_COFF) $(TARGET).cof
411
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
412

  
413

  
414
extcoff: $(TARGET).elf
415
	@echo
416
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
417
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
418

  
419

  
420

  
421
# Create final output files (.hex, .eep) from ELF output file.
422
%.hex: %.elf
423
	@echo
424
	@echo $(MSG_FLASH) $@
425
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
426

  
427
%.eep: %.elf
428
	@echo
429
	@echo $(MSG_EEPROM) $@
430
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
431
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
432

  
433
# Create extended listing file from ELF output file.
434
%.lss: %.elf
435
	@echo
436
	@echo $(MSG_EXTENDED_LISTING) $@
437
	$(OBJDUMP) -h -S $< > $@
438

  
439
# Create a symbol table from ELF output file.
440
%.sym: %.elf
441
	@echo
442
	@echo $(MSG_SYMBOL_TABLE) $@
443
	$(NM) -n $< > $@
444

  
445

  
446

  
447
# Link: create ELF output file from object files.
448
.SECONDARY : $(TARGET).elf
449
.PRECIOUS : $(OBJ)
450
%.elf: $(OBJ)
451
	@echo
452
	@echo $(MSG_LINKING) $@
453
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
454

  
455

  
456
# Compile: create object files from C source files.
457
%.o : %.c
458
	@echo
459
	@echo $(MSG_COMPILING) $<
460
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
461

  
462

  
463
# Compile: create assembler files from C source files.
464
%.s : %.c
465
	$(CC) -S $(ALL_CFLAGS) $< -o $@
466

  
467

  
468
# Assemble: create object files from assembler source files.
469
%.o : %.S
470
	@echo
471
	@echo $(MSG_ASSEMBLING) $<
472
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
473

  
474
# Create preprocessed source for use in sending a bug report.
475
%.i : %.c
476
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
477

  
478

  
479
# Target: clean project.
480
clean: begin clean_list end
481

  
482
clean_list :
483
	@echo
484
	@echo $(MSG_CLEANING)
485
	$(REMOVE) $(TARGET).hex
486
	$(REMOVE) $(TARGET).eep
487
	$(REMOVE) $(TARGET).cof
488
	$(REMOVE) $(TARGET).elf
489
	$(REMOVE) $(TARGET).map
490
	$(REMOVE) $(TARGET).sym
491
	$(REMOVE) $(TARGET).lss
492
	$(REMOVE) $(OBJ)
493
	$(REMOVE) $(LST)
494
	$(REMOVE) $(SRC:.c=.s)
495
	$(REMOVE) $(SRC:.c=.d)
496
	$(REMOVE) .dep/*
497

  
498

  
499

  
500
# Include the dependency files.
501
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
502

  
503

  
504
# Listing of phony targets.
505
.PHONY : all begin finish end sizebefore sizeafter gccversion \
506
build elf hex eep lss sym coff extcoff \
507
clean clean_list program debug gdb-config
508

  
trunk/code/projects/colonet/testing/robot_routine_reg_test/localization.h
1
#ifndef _LOCALIZATION_H_
2
#define _LOCALIZATION_H_
3

  
4
// Max number of robots possible
5
#define MAX_ROBOTS 4
6

  
7
unsigned char sensors[MAX_ROBOTS][MAX_ROBOTS];
8

  
9
typedef struct{
10
  //actual row of sensor values -- need to be able to have up to
11
  //max_robots
12
  unsigned char row[MAX_ROBOTS];
13
  //actual length of the row
14
  unsigned char len;
15
  //'index' value of the row -- which robot it's for
16
  unsigned char row_num;
17
  
18
} SensorRow;
19

  
20
void addSensor (int maxBom, int self, int other, int NUM_BOTS);
21
unsigned char getSelfSensor (unsigned char self, unsigned char other, 
22
			     int NUM_BOTS);
23
 
24
#endif
trunk/code/projects/colonet/testing/robot_routine_reg_test/time.c
1
/*
2
time.c
3
anything that requires a delay
4
mostly delay_ms
5

  
6
author: Robotics Club, Colony Project
7

  
8
*/
9
#include <avr/interrupt.h>
10
#include <avr/signal.h>
11
#include <avr/delay.h>
12
#include "time.h"
13
//#include "help.h"
14
#include "serial.h"
15

  
16

  
17
static volatile int _rtc_val = 0;
18
static void (*_rtc_f)(void) = 0;
19

  
20
/*
21
delay_ms
22

  
23
delays for ms milliseconds
24

  
25
accuracy is unknown (off by tens of nanoseconds every 15 ms)
26
*/
27
void delay_ms(int ms) 
28
{
29
	for(; ms > 15; ms-=15)
30
		_delay_ms(15);
31
	_delay_ms(ms);
32
}
33

  
34
void pause_ms(int ms)
35
{
36
	delay_ms(ms);
37
}
38

  
39
void pause(int ms)
40
{
41
	delay_ms(ms);
42
}
43

  
44
void sleep_ms(int ms)
45
{
46
	delay_ms(ms);
47
}
48

  
49
void sleep(int ms)
50
{
51
	delay_ms(ms);
52
}
53

  
54
/*
55
void rtc_init(void)
56
call this function to start the real time timer
57
use rtc() to get the time value and rtc_resest() to reset
58

  
59
requires global interrupts to be enabled for proper use
60
(I bit of SREG register should be set)
61

  
62
uses TIMER0 on asynchronous mode
63
*/
64

  
65
void rtc_init(int prescale_opt, unsigned char ocr_val, void (*rtc_func)(void)){
66
	int mask = _BV(TCN0UB) + _BV(OCR0UB) + _BV(TCR0UB);
67
	char tmp;
68
	
69
	TIMSK &= ~(_BV(OCIE0) + _BV(TOIE0)); //1. disable interrupts
70
	ASSR |= _BV(AS0); //2. selecting clock source (external)
71
	
72
	//3. writing new values to TCCR, TCNT, OCR
73
	TCNT0 = 0;
74
	OCR0 = ocr_val;
75
	TCCR0 = (0x01 << 3) + (prescale_opt & 0x07); //setting CTC mode, prescaler is lowest 3 bits
76
	
77
	//4. waiting for busy bits to clear
78
	tmp = ASSR;
79
	while( tmp & mask ){
80
		tmp = ASSR;
81
	}
82
	
83
	TIFR &= ~(_BV(OCF0) + _BV(TOV0)); //5. clearing the interrupt flags
84
	TIMSK |= _BV(OCIE0); // + _BV(TOIE0); //6. enabling interrupts
85
	
86
	_rtc_f = rtc_func;
87
}
88

  
89
int rtc(void){
90
	return _rtc_val;
91
}
92

  
93
void rtc_reset(void){
94
	_rtc_val = 0;
95
}
96

  
97
SIGNAL (SIG_OUTPUT_COMPARE0){
98
	_rtc_val++;
99
	
100
	if(_rtc_f != 0)
101
		_rtc_f();
102
}
trunk/code/projects/colonet/testing/robot_routine_reg_test/servo.c
1
/*  
2
	servo.c - Contains functions and interrupts necessary to activate servos
3
	author:  Tom Lauwers
4
	
5
	3/1/06 Iain
6
		Man, I don't know what a servo is. 
7
*/
8
#include <avr/io.h>
9
#include <avr/signal.h>
10
#include "servo.h"
11
#include "dio.h"
12
#include "lights.h"
13
#include "lcd.h"
14
//16000 c/ms
15
//i dunno must be 2^k
16
//9C40 ~ 20ms
17
//#A000 ~ 20.48 but prolly wont work
18
#define SERVO_PERIOD 0xA000
19
//needs be 1ms
20
//is 1.024ms
21
#define SERVO_CONSTANT 0x800
22

  
23
/* dirty dirty
24
unsigned int servo_vals[4] = {0,0,0,0}; // Stores the set servo values
25
int current_servo = 0;  // Stores which servo is current in the interrupt routine
26
*/
27
unsigned int servo_vals[8] = {0,0,0,0,0,0,0,0}; // Stores the set servo values
28
int phase_time=0;
29
int phase_base=0;
30
int servos_on = 0;      // Stores which servos are enabled
31
int servos_enabled=0; //which are high
32
int servo_flag = 0;     // Stores whether or not servos are enabled
33

  
34
/* Timer 1 output compare B interrupt.  Does the following:
35
	Checks to see if the current servo is 4, in which case just need
36
	to set low servo 3's signal and return.
37
	Else, check to see if the current servo is enabled, and set it's signal high
38
	Then, set the previous servo's signal low
39
	Now, set the next output compare to occur for some time from now 
40
	specified by the current servo's value
41
*/
42
SIGNAL (SIG_OUTPUT_COMPARE3B)
43
{
44
	lcd_putchar('i');
45
	if(servo_flag == 0)
46
		return;
47
	
48
	int i;
49
	if(phase_time == 0){
50
		lcd_putchar('p');
51
		for(i=0;i<8;i++){
52
			if(servos_on & _BV(i))
53
				digital_output((_PORT_E << 3) +i,1);
54
		}
55
		servos_enabled = servos_on;
56
		phase_base = OCR3B;
57
	}
58

  
59
	unsigned int min=~0;
60
	for(i=0;i<8;i++){
61
		if(_BV(i) & servos_enabled){
62
			if(SERVO_CONSTANT*servo_vals[i] <= phase_time){
63
				digital_output((_PORT_E << 3) + i,0);
64
				servos_enabled &= ~_BV(i);
65
			}
66
			else if(SERVO_CONSTANT*servo_vals[i] < min) {
67
				min = servo_vals[i];
68
			}
69
		}
70
	}
71
	if(!servos_enabled){
72
		OCR3B = phase_base + SERVO_PERIOD;
73
		phase_time = 0;
74
	}
75
	else {
76
		OCR3B = phase_base + min;
77
		phase_time = min;
78
	}
79
	
80
}	
81

  
82
//currently the light must be initted b4
83
void init_servo()
84
{
85
	//1010 1001
86
	TCCR3A = 0;  // COM## set to noninvert, WGM 1:0 set to 1
87
	//0000 1100
88
	TCCR3B = 0x02;  // High bits to 0, WGM 3:2 set to 1, prescaler to 8
89
	
90
	lcd_init();
91
	ETIMSK |= 0x08;
92
	servo_flag = 1;
93
	OCR3B = 0x80;
94
	lcd_putchar('i');
95
}
96

  
97
// Enable a servo specified by config
98
void enable_servo(int config)
99
{
100
	servos_on |= _BV(config);
101
}
102

  
103
// Disable a servo specified by config
104
void disable_servo(int config)
105
{
106
	servos_on &= (0xFF-_BV(config));
107
}
108

  
109
// Disables the timer1 interrupt, disabling the servos
110
void disable_servos()
111
{
112
	// Disables interrupts
113
	ETIMSK &= ~0x08;
114
	servo_flag=0;
115

  
116
}
117

  
118
// Enables the timer1 interrupt, enabling the servos
119
void enable_servos()
120
{
121
	// Enable interrupts on output compare B
122
	ETIMSK |= 0x08;
123
	servo_flag=1;
124
}
125
// Set a servo to a value.  Automatically enables the servo.
126
void set_servo(int servo, int value)
127
{
128
	enable_servo(servo);
129
	servo_vals[servo] = value;
130
}
131

  
trunk/code/projects/colonet/testing/robot_routine_reg_test/firefly+_lib.c
1
#include "firefly+_lib.h"
2

  
3

  
4
void serial_test( void );
5
void lcd_test(void);
6
void orb_test( void );
7

  
8

  
9

  
10
void motor_test (void) {
11

  
12
	
13

  
14

  
15

  
16
}
17
void orb_test( void ) {
18
	int orbs[13] = { ORB_OFF, RED, ORANGE, YELLOW, LIME, GREEN, CYAN, BLUE, PURPLE, PINK, PURPLE, MAGENTA, WHITE };
19
	int orb_select = 0;
20
	
21
	orb_init();
22
	
23
	
24
	while(1) {
25
		orb_set_color(orbs[orb_select]);
26
		delay_ms(1000);
27
		orb_select++;
28
		if(orb_select == 14)
29
			orb_select = 0;
30
	}
31

  
32
	return;
33

  
34
}
35

  
36

  
37
void lcd_test(void) {
38
	int i;
39
	lcd_init();
40
	
41
	for(i = 32; i <= 126; i++) {
42
		lcd_putchar(i);
43
		delay_ms(250);
44
	}
45
	
46
	
47
	return;
48
	
49
}
50

  
51
/*
52
prints all printable characters to the serial
53

  
54
baud rate is 115200
55
*/
56
void serial_test( void ) {
57
	int i;
58
	
59
	serial_init(BAUD115200);
60
	
61
	for(i = 32; i <= 126; i++) {
62
		serial_putchar(i);
63
		delay_ms(250);
64
	}
65

  
66
	return;
67
}
68

  
69

  
70

  
71

  
trunk/code/projects/colonet/testing/robot_routine_reg_test/analog.c
1
/*
2
	analog.c - Contains the function implementations for manipulating the ADC
3
	on the firefly+ board
4
	
5
	author:  CMU Robotics Club, Colony Project
6
	code mostly taken from fwr analog file (author: Tom Lauwers)
7
*/
8

  
9
#include <avr/delay.h>
10
#include <avr/interrupt.h>
11
#include <avr/signal.h>
12
#include "analog.h"
13

  
14
void analog_init(void){
15

  
16
	/*
17
		ADC Status Register A
18
		Bit 7 - ADEN is set (enables analog)
19
		Bit 6 - Start conversion bit is set (must be done once for free-running mode)
20
		Bit 5 - Enable Auto Trigger (for free running mode)
21
		Bit 3 - Enable ADC Interrupt (required to run free-running mode)
22
		Bits 2-0 - Set to create a clock divisor of 128, to make ADC clock = 16,000,000/128
23
	*/
24
	ADCSRA |= 0xEF;
25

  
26
	/*
27
		ADMUX register
28
		Bit 7,6 - Set voltage reference to AVcc (0b01)
29
		Bit 5 - Set ADLAR bit for left adjust to do simple 8-bit reads
30
		Bit 4 - X
31
		Bit 3:0 - Sets the current channel
32
	*/
33
	ADMUX = 0x67;
34
}	
35

  
36
unsigned int analog8(int which){
37
	ADMUX = 0x60 + which;
38
	_delay_ms(1); // need at least 130 us between conversions (for fwr robot, how much for new avr?)
39
	return ADCH;
40
}
41

  
42
unsigned int analog10(int which){
43
	unsigned int adc_h = 0;
44
	unsigned int adc_l = 0;
45
	
46
	ADMUX = 0x60 + which;
47
	_delay_ms(1);
48
	adc_l = ADCL; /* highest 2 bits of ADCL -> least 2 bits of analog val */
49
	adc_h = ADCH; /* ADCH -> 8 highest bits of analog val */
50
	
51
	return (adc_h << 2) | (adc_l >> 6);
52
}
53

  
54
int wheel(void){
55
	return analog8(WHEEL_PORT);
56
}
57

  
58
int battery(void){
59
	return analog8(BATT_PORT) * 500 / 255; /* 5 volts is the max, 255 is the max 8bit number */
60
}
61

  
62
SIGNAL (SIG_ADC)
63
{
64
	// This is just here to catch ADC interrupts because ADC is free running.  
65
	// No code needs to be in here.
66
}
trunk/code/projects/colonet/testing/robot_routine_reg_test/lcd.c
1
/*
2

  
3
lcd-ar2.c - implementation for lcd functions
4

  
5
Author: CMU Robotics Club, Colony Project
6

  
7
This uses SPI.
8

  
9
lcd_init MUST be called before anything can be used.
10

  
11
*/
12

  
13
#include <avr/io.h>
14
#include "lcd.h"
15
#include "time.h"
16

  
17
/*
18
FontLookup - a lookup table for all characters
19
*/
20
static const unsigned char FontLookup [][5] =
21
{
22
    { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
23
    { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
24
    { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
25
    { 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #
26
    { 0x24, 0x2a, 0x7f, 0x2a, 0x12 },   // $
27
	{ 0x23, 0x13, 0x08, 0x64, 0x62 },   // %
28
    { 0x36, 0x49, 0x55, 0x22, 0x50 },   // &
29
    { 0x00, 0x05, 0x03, 0x00, 0x00 },   // '
30
    { 0x00, 0x1c, 0x22, 0x41, 0x00 },   // (
31
    { 0x00, 0x41, 0x22, 0x1c, 0x00 },   // )
32
    { 0x14, 0x08, 0x3E, 0x08, 0x14 },   // *
33
    { 0x08, 0x08, 0x3E, 0x08, 0x08 },   // +
34
    { 0x00, 0x00, 0x50, 0x30, 0x00 },   // ,
35
    { 0x10, 0x10, 0x10, 0x10, 0x10 },   // -
36
    { 0x00, 0x60, 0x60, 0x00, 0x00 },   // .
37
    { 0x20, 0x10, 0x08, 0x04, 0x02 },   // /
38
    { 0x3E, 0x51, 0x49, 0x45, 0x3E },   // 0
39
    { 0x00, 0x42, 0x7F, 0x40, 0x00 },   // 1
40
    { 0x42, 0x61, 0x51, 0x49, 0x46 },   // 2
41
    { 0x21, 0x41, 0x45, 0x4B, 0x31 },   // 3
42
    { 0x18, 0x14, 0x12, 0x7F, 0x10 },   // 4
43
    { 0x27, 0x45, 0x45, 0x45, 0x39 },   // 5
44
    { 0x3C, 0x4A, 0x49, 0x49, 0x30 },   // 6
45
    { 0x01, 0x71, 0x09, 0x05, 0x03 },   // 7
46
    { 0x36, 0x49, 0x49, 0x49, 0x36 },   // 8
47
    { 0x06, 0x49, 0x49, 0x29, 0x1E },   // 9
48
    { 0x00, 0x36, 0x36, 0x00, 0x00 },   // :
49
    { 0x00, 0x56, 0x36, 0x00, 0x00 },   // ;
50
    { 0x08, 0x14, 0x22, 0x41, 0x00 },   // <
51
    { 0x14, 0x14, 0x14, 0x14, 0x14 },   // =
52
    { 0x00, 0x41, 0x22, 0x14, 0x08 },   // >
53
    { 0x02, 0x01, 0x51, 0x09, 0x06 },   // ?
54
    { 0x32, 0x49, 0x59, 0x51, 0x3E },   // @
55
    { 0x7E, 0x11, 0x11, 0x11, 0x7E },   // A
56
    { 0x7F, 0x49, 0x49, 0x49, 0x36 },   // B
57
    { 0x3E, 0x41, 0x41, 0x41, 0x22 },   // C
58
    { 0x7F, 0x41, 0x41, 0x22, 0x1C },   // D
59
    { 0x7F, 0x49, 0x49, 0x49, 0x41 },   // E
60
    { 0x7F, 0x09, 0x09, 0x09, 0x01 },   // F
61
    { 0x3E, 0x41, 0x49, 0x49, 0x7A },   // G
62
    { 0x7F, 0x08, 0x08, 0x08, 0x7F },   // H
63
    { 0x00, 0x41, 0x7F, 0x41, 0x00 },   // I
64
    { 0x20, 0x40, 0x41, 0x3F, 0x01 },   // J
65
    { 0x7F, 0x08, 0x14, 0x22, 0x41 },   // K
66
    { 0x7F, 0x40, 0x40, 0x40, 0x40 },   // L
67
    { 0x7F, 0x02, 0x0C, 0x02, 0x7F },   // M
68
    { 0x7F, 0x04, 0x08, 0x10, 0x7F },   // N
69
    { 0x3E, 0x41, 0x41, 0x41, 0x3E },   // O
70
    { 0x7F, 0x09, 0x09, 0x09, 0x06 },   // P
71
    { 0x3E, 0x41, 0x51, 0x21, 0x5E },   // Q
72
    { 0x7F, 0x09, 0x19, 0x29, 0x46 },   // R
73
    { 0x46, 0x49, 0x49, 0x49, 0x31 },   // S
74
    { 0x01, 0x01, 0x7F, 0x01, 0x01 },   // T
75
    { 0x3F, 0x40, 0x40, 0x40, 0x3F },   // U
76
    { 0x1F, 0x20, 0x40, 0x20, 0x1F },   // V
77
    { 0x3F, 0x40, 0x38, 0x40, 0x3F },   // W
78
    { 0x63, 0x14, 0x08, 0x14, 0x63 },   // X
79
    { 0x07, 0x08, 0x70, 0x08, 0x07 },   // Y
80
    { 0x61, 0x51, 0x49, 0x45, 0x43 },   // Z
81
    { 0x00, 0x7F, 0x41, 0x41, 0x00 },   // [
82
    { 0x02, 0x04, 0x08, 0x10, 0x20 },   // backslash
83
    { 0x00, 0x41, 0x41, 0x7F, 0x00 },   // ]
84
    { 0x04, 0x02, 0x01, 0x02, 0x04 },   // ^
85
    { 0x40, 0x40, 0x40, 0x40, 0x40 },   // _
86
    { 0x00, 0x01, 0x02, 0x04, 0x00 },   // '
87
    { 0x20, 0x54, 0x54, 0x54, 0x78 },   // a
88
    { 0x7F, 0x48, 0x44, 0x44, 0x38 },   // b
89
    { 0x38, 0x44, 0x44, 0x44, 0x20 },   // c
90
    { 0x38, 0x44, 0x44, 0x48, 0x7F },   // d
91
    { 0x38, 0x54, 0x54, 0x54, 0x18 },   // e
92
    { 0x08, 0x7E, 0x09, 0x01, 0x02 },   // f
93
    { 0x0C, 0x52, 0x52, 0x52, 0x3E },   // g
94
    { 0x7F, 0x08, 0x04, 0x04, 0x78 },   // h
95
    { 0x00, 0x44, 0x7D, 0x40, 0x00 },   // i
96
    { 0x20, 0x40, 0x44, 0x3D, 0x00 },   // j
97
    { 0x7F, 0x10, 0x28, 0x44, 0x00 },   // k
98
    { 0x00, 0x41, 0x7F, 0x40, 0x00 },   // l
99
    { 0x7C, 0x04, 0x18, 0x04, 0x78 },   // m
100
    { 0x7C, 0x08, 0x04, 0x04, 0x78 },   // n
101
    { 0x38, 0x44, 0x44, 0x44, 0x38 },   // o
102
    { 0x7C, 0x14, 0x14, 0x14, 0x08 },   // p
103
    { 0x08, 0x14, 0x14, 0x18, 0x7C },   // q
104
    { 0x7C, 0x08, 0x04, 0x04, 0x08 },   // r
105
    { 0x48, 0x54, 0x54, 0x54, 0x20 },   // s
106
    { 0x04, 0x3F, 0x44, 0x40, 0x20 },   // t
107
    { 0x3C, 0x40, 0x40, 0x20, 0x7C },   // u
108
    { 0x1C, 0x20, 0x40, 0x20, 0x1C },   // v
109
    { 0x3C, 0x40, 0x30, 0x40, 0x3C },   // w
110
    { 0x44, 0x28, 0x10, 0x28, 0x44 },   // x
111
    { 0x0C, 0x50, 0x50, 0x50, 0x3C },   // y
112
    { 0x44, 0x64, 0x54, 0x4C, 0x44 },    // z
113
    { 0x00, 0x08, 0x36, 0x41, 0x41 },   // {
114
    { 0x00, 0x00, 0x7F, 0x00, 0x00 },   // |
115
    { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
116
    { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
117
    { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
118
};
119

  
120

  
121
/*
122
initializes the LCD
123
*/
124
void lcd_init(void)
125
{
126
	LCDDDR |= (D_C | SCE | SDI | SCK);
127
	LCDRESETDDR |= RST;
128

  
129
	LCDPORT &= ~(D_C | SCE | SDI | SCK);
130
	
131
	SPCR |= 0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
132
	SPSR |= 0x01;       // a continuation of the above
133

  
134
	LCDRESETPORT |= RST;
135
	delay_ms(10);
136
	LCDRESETPORT &= (~RST);
137
	delay_ms(100);
138
	LCDRESETPORT |= RST;
139
	
140
    lcd_putbyte( 0x21 );  // LCD Extended Commands.
141
    lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
142
    lcd_putbyte( 0x06 );  // Set Temp coefficent.
143
    lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
144
    lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
145
    lcd_putbyte( 0x0C );  // LCD in normal mode.
146
	
147
	LCDPORT |= D_C;		//put it in init instead of main
148
	
149
	lcd_clear_screen();
150
	
151
}
152

  
153
/*
154
clear the lcd screen
155
*/
156
void lcd_clear_screen( void ) {
157
	int i;
158
	for (i = 0; i < 504; i++)
159
			lcd_putbyte(0x0);
160
	
161
	lcd_gotoxy(0,0);
162

  
163
}
164

  
165

  
166
/*
167
print a byte on the lcd screen
168
*/
169
void lcd_putbyte(unsigned char b)
170
{
171
	SPDR = b;
172
	while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
173
}
174

  
175
/*
176
print a character on the lcd
177
*/
178
void lcd_putchar(char c)
179
{
180
	int i;
181
	
182
	for (i = 0; i < 5; i++)
183
		lcd_putbyte(FontLookup[c-32][i]);
184
	lcd_putbyte(0);
185

  
186
}
187

  
188
/*
189
print an entire string to the lcd
190
*/
191
void lcd_putstr(char *s)
192
{
193
	char *t = s;
194
	while (*t != 0)
195
	{
196
		lcd_putchar(*t);
197
		t++;
198
	}
199
}
200

  
201
/*
202
go to coordinate x, y
203
y: vertically - 1 char
204
x: horizontally - 1 pixel
205

  
206
multiply x by 6 if want to move 1 entire character
207

  
208
origin (0,0) is at top left corner of lcd screen
209
*/
210
void lcd_gotoxy(int x, int y)
211
{
212
  LCDPORT &= ~(D_C);
213
  lcd_putbyte(0x40 | (y & 0x07));
214
  lcd_putbyte(0x80 | (x & 0x7f));
215
  LCDPORT |= D_C;
216
}
217

  
218
/*
219
prints an int to the lcd
220

  
221
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
222
*/
223
void lcd_putint(int value ) {
224
	unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
225

  
226
        /* convert int to ascii  */ 
227
        if(value<0) { lcd_putchar('-'); value=-value; }    
228
        do { position--; *(lcd_data+position)=(value%radix)+'0'; value/=radix;  } while(value); 
229

  
230
    
231
        /* start displaying the number */
232
        for(;position<=(sizeof(lcd_data)-1);position++)
233
          {
234
            
235
            lcd_putchar(lcd_data[position]);
236
          }
237

  
238
return;
239
}
trunk/code/projects/colonet/testing/robot_routine_reg_test/servo.h
1
/*  
2
	servo.h - Contains function prototypes for servo activation
3
	author:  Tom Lauwers
4
*/
5
#ifndef _SERVO_H_
6
#define _SERVO_H_
7

  
8
// Information on functions available in servo.c
9
void init_servo(void);
10
void enable_servos(void);
11
void enable_servo(int config);
12
void set_servo(int servo, int value);
13
void disable_servos(void);
14
void disable_servo(int );
15

  
16
#endif
trunk/code/projects/colonet/testing/robot_routine_reg_test/time.h
1
/*
2
time.h
3

  
4
provisional (Suresh)
5

  
6
*/
7

  
8
#ifndef _TIME_H_
9
#define _TIME_H_
10

  
11
#define TIMER_OFF         0x00
12
#define PRESCALE_NONE     0x01
13
#define PRESCALE_DIV_8    0x02
14
#define PRESCALE_DIV_32   0x03
15
#define PRESCALE_DIV_64   0x04
16
#define PRESCALE_DIV_128  0x05
17
#define PRESCALE_DIV_256  0x06
18
#define PRESCALE_DIV_1024 0x07
19

  
20
/*
21
delay_ms(int ms)
22
pause_ms(int ms)
23
sleep_ms(int ms)
24
pause(int ms)
25
sleep(int ms)
26

  
27
all have the same behavior
28
pauses the calling process for the specified
29
amount of time in milliseconds
30
*/
31
void delay_ms(int ms) ;
32
void pause_ms(int ms);
33
void pause(int ms);
34
void sleep_ms(int ms);
35
void sleep(int ms);
36

  
37
/*
38
void rtc_init(void)
39
call this function to initialize the real time clock
40
real time clock requires global interrupts to be enabled
41
*/
42
void rtc_init(int prescale_opt, unsigned char ocr_val, void (*rtc_func)(void));
43

  
44
/*
45
void rtc_reset(void)
46
use this to reset the real time value
47
rtc_init() should be called beforehand
48
*/
49
void rtc_reset(void);
50

  
51
/*
52
int rtc(void)
53
returns the current value of the real time clock (in seconds)
54
rtc_init() should be called beforehand
55

  
56
the returned amount is the number of seconds that have past since the
57
last call to rtc_init() or rtc_reset()
58
*/
59
int rtc(void);
60

  
61
#endif
trunk/code/projects/colonet/testing/robot_routine_reg_test/colonet.c
1
/** @file colonet.c
2
 * @brief Colonet library for colony robots
3

  
4
 * @author Eugene Marinelli
5
 * @date 10/26/06
6
 * 
7
 * @bug Handler registration not tested
8
 * @bug Request reponding not implemented - only accepts commands.
9
 */
10

  
11
#include <firefly+_lib.h>
12

  
13
#include "colonet.h"
14

  
15
typedef struct {
16
  unsigned char msgId; //is this necessary?
17
  void (*handler)(void);
18
} UserHandler;
19

  
20
/* Globals (internal) */
21
static UserHandler user_handlers[USER_DEFINED_MSG_TOTAL];
22

  
23
/* Internal function prototypes */
24
void packet_string_to_struct(ColonetPacket* dest_pkt, char* pkt_buf);
25
unsigned int two_bytes_to_int(char high, char low);
26

  
27
/* Public functions */
28
int colonet_handle_message(unsigned char robot_id, char* pkt_buf)
29
{
30
  ColonetPacket pkt;
31
  unsigned char* args; //up to 7 char args
32
  unsigned int int_args[3]; //up to 3 int (2-byte) args
33

  
34
  packet_string_to_struct(&pkt, pkt_buf);
35

  
36
  if(pkt.msg_dest != GLOBAL_DEST && pkt.msg_dest != robot_id){ 
37
    //message not intended for us
38
    return 1;
39
  }
40

  
41
  args = pkt.data;
42
  
43
  /* Hack - could be done more 1337ly with casting, but this way we don't have
44
   * to worry about little/big endian stuff */
45
  int_args[0] = two_bytes_to_int(args[0], args[1]);
46
  int_args[1] = two_bytes_to_int(args[2], args[3]);
47
  int_args[2] = two_bytes_to_int(args[4], args[5]);
48

  
49
  if(pkt.msg_type == COLONET_REQUEST){
50
    switch(pkt.msg_code){
51
      //Sharp
52
    case READ_DISTANCE:
53
      break;
54
    case LINEARIZE_DISTANCE:
55
      break;
56
    case LOG_DISTANCE:
57
      break;
58

  
59
      //Serial
60
    case SERIAL_GETCHAR:
61
      break;
62
    case SERIAL_GETCHAR_NB:
63
      break;
64
    case SERIAL1_GETCHAR:
65
      break;
66
    case SERIAL1_GETCHAR_NB:
67
      break;
68

  
69
      //Analog
70
    case ANALOG8:
71
      break;
72
    case ANALOG10:
73
      break;
74
    case WHEEL:
75
      break;
76
    case BATTERY:
77
      break;
78

  
79
      //BOM
80
    case GETMAXBOM:
81
      break;
82

  
83
      //Dio
84
    case DIGITAL_INPUT:
85
      break;
86
    case BUTTON1_READ:
87
      break;
88
    case BUTTON2_READ:
89
      break;
90

  
91
      //Bumper
92
    case DETECT_BUMP:
93
      break;
94
    }
95

  
96
    /* TODO - send back data! */
97

  
98
  }else if(pkt.msg_type == COLONET_COMMAND){
99
    if(pkt.msg_code >= USER_DEFINED_MSG_ID_START && 
100
       pkt.msg_code <= USER_DEFINED_MSG_ID_END){
101
      if (user_handlers[pkt.msg_code - USER_DEFINED_MSG_ID_START].handler) {
102
        /* Call the user's handler function if it the function's address
103
         * is non-zero (has been set) */
104
        user_handlers[pkt.msg_code - USER_DEFINED_MSG_ID_START].handler();
105
      }
106

  
107
      return 0;
108
    }
109

  
110
    switch(pkt.msg_code){
111
    default:
112
      printf("%s: Error - message code %d not implemented\n", __FUNCTION__,
113
             pkt.msg_code);
114
      return -1;
115
      break;
116

  
117
      //Buzzer
118
    case BUZZER_INIT:
119
      buzzer_init();
120
      break;
121
    case BUZZER_SET_VAL:
122
      buzzer_set_val(args[0]);
123
      break;
124
    case BUZZER_SET_FREQ:
125
      buzzer_set_freq(args[0]);
126
      break;
127
    case BUZZER_CHIRP:
128
      buzzer_chirp(int_args[0], int_args[1]);
129
      break;
130
    case BUZZER_OFF:
131
      buzzer_off();
132
      break;
133
      
134
      //LCD
135
    case LCD_INIT:
136
      lcd_init();
137
      break;
138
    case LCD_CLEAR_SCREEN:
139
      lcd_clear_screen();
140
      break;
141
    case LCD_PUTBYTE:
142
      lcd_putbyte(args[0]);
143
      break;
144
    case LCD_PUTCHAR:
145
      lcd_putchar((char)args[0]);
146
      break;
147
    case LCD_PUTSTR:
148
      lcd_putstr((char*)args);
149
      break;
150
    case LCD_GOTOXY: 
151
      lcd_gotoxy(int_args[0], int_args[1]);
152
      break;
153
    case LCD_PUTINT: 
154
      lcd_putint(int_args[0]);
155
      break;
156
    case ORB_INIT:
157
      orb_init();
158
      break;
159
      //Orb
160
    case ORB_SET:
161
      orb_set(args[0], args[1], args[2]);
162
      break;
163
    case ORB_SET_COLOR:
164
      orb_set_color(int_args[0]);
165
      break;
166
    case ORB_DISABLE:
167
      orb_disable();
168
      break;
169
    case ORB_ENABLE:
170
      orb_enable();
171
      break;
172
    case ORB_SET_DIO:
173
      orb_set_dio(int_args[0], int_args[1], int_args[2]);
174
      break;
175
    case LED_INIT:
176
      led_init();
177
      break;
178
    case LED_USER:
179
      led_user(int_args[0]);
180
      break;
181
    case ORB_SEND:
182
      //orb_send();
183
      break;
184
      //Motors
185
    case MOTORS_INIT:
186
      motors_init();
187
      break;
188
    case MOTOR1_SET:
189
      motor1_set(int_args[0], int_args[1]);
190
      break;
191
    case MOTOR2_SET:
192
      motor2_set(int_args[0], int_args[1]);
193
      break;
194
    case MOTORS_OFF:
195
      motors_off();
196
      break;
197

  
198
      /*
199
    case MOVE:
200
      
201
      break;
202
      */
203

  
204
      //SERIAL
205
    case SERIAL_INIT:
206
      serial_init(int_args[0]);
207
      break;
208
    case SERIAL_PUTCHAR:
209
      serial_putchar((char)args[0]);
210
      break;
211
    case SERIAL1_INIT:
212
      serial1_init(int_args[0]);
213
      break;
214
    case SERIAL1_PUTCHAR:
215
      serial1_putchar((char)args[0]);
216
      break;
217
    case PRINTF:
218
      printf("%s", pkt.data);
219
      break;
220
    case KILL_ROBOT:
221
      motors_off();
222
      buzzer_off();
223
      exit(0); //kill the robot
224
      break;
225
      //Time
226
    case DELAY_MS:
227
      delay_ms(int_args[0]);
228
      break;
229

  
230
      //Analog
231
    case ANALOG_INIT:
232
      analog_init();
233
      break;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff