├── src ├── start.S ├── Makefile.src ├── default_lowlevel.h ├── default_lowlevel.c └── isr.c ├── doc ├── adc.gnumeric ├── mc13224v.img ├── pow-rssi-lqi.gnumeric ├── lqi-pdr │ ├── README │ ├── 1000pkt-64len.csv │ ├── plot.asy │ └── 1000pkt-64len.txt ├── buck ├── cal1.dump └── autoack ├── tools ├── rimecollect-rrd │ ├── default.rrdtmpl │ ├── meshstat.cgi │ └── collect2rrd.pl ├── ftditools │ └── Makefile ├── run-kermit ├── test-grid │ ├── erase-all.pl │ ├── reset-all.pl │ ├── load-all.pl │ ├── open-terms.pl │ └── burn-macs.pl ├── map2dot.pl ├── burn-mac.pl ├── bin2macbin.pl ├── rftestrx2pcap.pl ├── rftestrx2pcap.py └── mc1322x-load.pl ├── .gitignore ├── CREDITS ├── lib ├── Makefile.lib ├── include │ ├── gpio-util.h │ ├── mc1322x.h │ ├── rtc.h │ ├── kbi.h │ ├── utils.h │ ├── packet.h │ ├── pwm.h │ ├── nvm.h │ ├── asm.h │ └── i2c.h ├── gpio-util.c ├── nvm.c ├── tmr.c ├── gpio.c ├── uart1.c ├── uart2.c └── adc.c ├── TODO ├── board ├── Makefile.board ├── m12.h ├── redbee-r1.h ├── redbee-dev.h ├── redbee-usb.h ├── freescale-ncb.h ├── econotag.h ├── redbee-econotag.h ├── std_conf.h └── quahogcon.h ├── tests ├── Makefile ├── put.h ├── tests.h ├── romimg.c ├── uart1-loopback.c ├── led.h ├── blink-blue.c ├── blink-green.c ├── blink-red.c ├── blink-white.c ├── u1u2-loopback.c ├── blink-allio.c ├── adc.c ├── wdt.c ├── config.h ├── put.c ├── xtal-trim.c ├── tests.c ├── pwm.c ├── nvm-read.c ├── rftest-rx.c ├── nvm-write.c ├── autoack-rx.c ├── tmr.c ├── rftest-tx.c ├── tmr-ints.c ├── printf.c ├── per.c └── autoack-tx.c ├── COPYING ├── README └── Makefile.include /src/start.S: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malvira/libmc1322x/HEAD/src/start.S -------------------------------------------------------------------------------- /doc/adc.gnumeric: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malvira/libmc1322x/HEAD/doc/adc.gnumeric -------------------------------------------------------------------------------- /doc/mc13224v.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malvira/libmc1322x/HEAD/doc/mc13224v.img -------------------------------------------------------------------------------- /tools/rimecollect-rrd/default.rrdtmpl: -------------------------------------------------------------------------------- 1 | -s 1 DS:GPIO29:GAUGE:600:U:U RRA:LAST:0.99:1:3600 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *.s 4 | *.a 5 | *.elf 6 | *.bin 7 | *.map 8 | tests/obj_* 9 | 10 | -------------------------------------------------------------------------------- /doc/pow-rssi-lqi.gnumeric: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malvira/libmc1322x/HEAD/doc/pow-rssi-lqi.gnumeric -------------------------------------------------------------------------------- /doc/lqi-pdr/README: -------------------------------------------------------------------------------- 1 | grep count 1000pkt-64len.txt | cut -d ' ' -f 2,5 | sed 's/ /,/g' | 2 | sort -n > 1000pkt-64len.csv 3 | 4 | then: 5 | 6 | asy plot.asy 7 | gv plot.eps 8 | -------------------------------------------------------------------------------- /tools/ftditools/Makefile: -------------------------------------------------------------------------------- 1 | INSTALL= /usr/local/bin 2 | 3 | ################ 4 | 5 | LDLIBS = -lftdi 6 | 7 | TARGETS = bbmc 8 | 9 | CFLAGS = -Wall -Wextra #-Werror 10 | 11 | all: $(TARGETS) 12 | 13 | clean: 14 | -rm -f $(TARGETS) 15 | 16 | install: all 17 | cp bbmc $(INSTALL) -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | MC13224v library code, test routines, and handy tools 2 | 3 | http://mc1322x.devl.org 4 | Mariano Alvira mar@devl.org 5 | 6 | Parts of the build system came from U-boot and Darrel Harmon's 7 | "darrell's loader" for the AT91RM9200. Other parts from the Contiki 8 | OS. 9 | 10 | -------------------------------------------------------------------------------- /tools/run-kermit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/kermit + 2 | 3 | echo "Opening \%1 at \%2 baud..." 4 | 5 | set line \%1 6 | if failure { echo "Couldn't open \%1" , exit } 7 | set carrier-watch off 8 | set flow-control none 9 | set speed \%2 10 | set serial 8n1 11 | set key \127 \8 12 | connect 13 | quit 14 | -------------------------------------------------------------------------------- /doc/buck: -------------------------------------------------------------------------------- 1 | no buck 2 | ------- 3 | vsupply, 4 | 3.6, rftest-rx 46mA 5 | 3.27, rftest-rx 42mA 6 | 3.03, rftest-rx, 39.5mA 7 | 2.56, rftest-rx 35mA 8 | 2.2, rftest-rx 32mA 9 | 10 | buck 11 | ----- 12 | 3.58V, 39mA 13 | 3.3, 37mA 14 | vsupply 3.03, rftest, 35.3mA 15 | 2.47, 32.9mA 16 | 2.2V, 31.2mA 17 | 18 | might have a hard time starting up everything in the <2.7V range 19 | -------------------------------------------------------------------------------- /tools/test-grid/erase-all.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | 4 | my $terms = shift; 5 | 6 | if (! $terms) { 7 | print "Usage: num-devices\n"; 8 | die; 9 | } 10 | 11 | for (my $t=0; $t<$terms; $t++) { 12 | my $dev_num = 2 * $t + 1; 13 | my $ftdi_num = $terms - $t - 1; 14 | my $cmd = "bbmc -l redbee-econotag -i $ftdi_num erase &"; 15 | print "$cmd\n"; 16 | system($cmd); 17 | } 18 | -------------------------------------------------------------------------------- /tools/test-grid/reset-all.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | 4 | my $terms = shift; 5 | 6 | if (! $terms) { 7 | print "Usage: num-devices\n"; 8 | die; 9 | } 10 | 11 | for (my $t=0; $t<$terms; $t++) { 12 | my $dev_num = 2 * $t + 1; 13 | my $ftdi_num = $terms - $t - 1; 14 | my $cmd = "bbmc -l redbee-econotag -i $ftdi_num reset &"; 15 | print "$cmd\n"; 16 | system($cmd); 17 | } 18 | -------------------------------------------------------------------------------- /doc/lqi-pdr/1000pkt-64len.csv: -------------------------------------------------------------------------------- 1 | 1,6 2 | 5,4 3 | 5,6 4 | 5,6 5 | 6,3 6 | 30,5 7 | 45,3 8 | 51,9 9 | 162,6 10 | 170,7 11 | 308,6 12 | 317,6 13 | 506,8 14 | 511,7 15 | 596,7 16 | 602,7 17 | 674,9 18 | 743,8 19 | 788,8 20 | 842,9 21 | 859,9 22 | 951,9 23 | 898,10 24 | 976,12 25 | 978,19 26 | 981,13 27 | 988,30 28 | 991,17 29 | 992,12 30 | 993,16 31 | 993,19 32 | 994,15 33 | 995,19 34 | 995,19 35 | 998,30 36 | 999,38 37 | 1000,34 38 | 1000,40 39 | 1000,46 40 | 1000,47 41 | 1000,54 42 | -------------------------------------------------------------------------------- /tools/test-grid/load-all.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | 4 | my $bin = shift; 5 | my $terms = shift; 6 | 7 | if (! $terms) { 8 | print "Usage: $0 file.bin num-devices\n"; 9 | die; 10 | } 11 | 12 | for (my $t=0; $t<$terms; $t++) { 13 | my $dev_num = 2 * $t + 1; 14 | my $ftdi_num = $terms - $t - 1; 15 | my $cmd = "mc1322x-load.pl -e -f $bin -t /dev/ttyUSB$dev_num -c 'bbmc -l redbee-econotag -i $ftdi_num reset' &"; 16 | print "$cmd\n"; 17 | system($cmd); 18 | } 19 | -------------------------------------------------------------------------------- /lib/Makefile.lib: -------------------------------------------------------------------------------- 1 | # Hey Emacs, this is a -*- makefile -*- 2 | 3 | CFLAGS += -I$(MC1322X)/lib/include 4 | 5 | # By default, link all objects 6 | LIBOBJS ?= $(patsubst %.c,%.o,$(wildcard $(MC1322X)/lib/*.c)) 7 | 8 | $(MC1322X)/lib/libmc1322x.a: $(LIBOBJS) 9 | $(call pretty,AR,$@) 10 | @rm -f $@ 11 | $Q$(AR) $(ARFLAGS) $@ $^ 12 | 13 | TARGET_OBJ += $(MC1322X)/lib/libmc1322x.a 14 | 15 | ifneq ($(MAKECMDGOALS),clean) 16 | -include $(wildcard $(MC1322X)/lib/*.d) 17 | endif 18 | 19 | clean:: 20 | rm -f $(MC1322X)/lib/*.{o,d,a} 21 | -------------------------------------------------------------------------------- /lib/include/gpio-util.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GPIO_UTIL_H 3 | #define GPIO_UTIL_H 4 | 5 | #include 6 | #include 7 | 8 | void gpio_select_function(uint8_t gpio, uint8_t func); 9 | void gpio_reg_set(volatile uint32_t* reg, uint8_t bit); 10 | void gpio_reg_clear(volatile uint32_t* reg, uint8_t bit); 11 | 12 | #define PAD_DIR_INPUT 0 13 | #define PAD_DIR_OUTPUT 1 14 | void gpio_set_pad_dir(uint8_t gpio, uint8_t dir); 15 | 16 | #undef gpio_set 17 | #undef gpio_reset 18 | #undef gpio_read 19 | 20 | //#define gpio_set gpio_set_ian 21 | //#define gpio_reset gpio_reset_ian 22 | //#define gpio_read gpio_read_ian 23 | 24 | void gpio_set(uint8_t gpio); 25 | void gpio_reset(uint8_t gpio); 26 | bool gpio_read(uint8_t gpio); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /doc/lqi-pdr/plot.asy: -------------------------------------------------------------------------------- 1 | import graph; 2 | size(350,250,IgnoreAspect); 3 | 4 | file fin=input("./1000pkt-64len.csv"); 5 | fin.csv(); 6 | real[][] A=fin.dimension(0,2); 7 | real[][] pdr=transpose(A); 8 | 9 | int[] lqi = sequence(100); 10 | 11 | int f (int lqi) 12 | { 13 | if(lqi <= 6) { 14 | return (int)((real)lqi*.8); 15 | } else if(lqi <= 11) { 16 | return (lqi-6)*18; 17 | } else if (lqi <= 30) { 18 | return (int)((real)(lqi-11) * 0.5 + 90); 19 | } else { 20 | return 100; 21 | } 22 | } 23 | 24 | int[] f_lqi = map(f,lqi); 25 | 26 | draw(graph(pdr[1],pdr[0]/10)); 27 | draw(graph(lqi,f_lqi), red); 28 | 29 | ylimits(0,100); 30 | xlimits(0,100); 31 | xaxis("\rm LQI",BottomTop,LeftTicks("$%.1f$",10,begin=false,end=false,extend=true,pTick=dotted)); 32 | yaxis("\rm Packet Deliver Ratio (\%)",LeftRight,RightTicks("$%#.1f$",8,begin=false,end=false,extend=true,pTick=dotted, ptick=dotted)); 33 | -------------------------------------------------------------------------------- /doc/cal1.dump: -------------------------------------------------------------------------------- 1 | (gdb) x/40x 0x4051e4 2 | 0x4051e4 : 0x80003048 0x00000f78 0x8000304c 0x00607707 3 | 0x4051f4 : 0x00000000 0x000161a8 0x8000a050 0x0000047b 4 | 0x405204 : 0x8000a054 0x0000007b 0x00005dc0 0x00000000 5 | 0x405214 : 0x00000000 0x00000000 0x00000000 0x00000000 6 | 0x405224 : 0x00000000 0x80009400 0x00000017 0x8000a050 7 | 0x405234 : 0x00000000 0x8000a054 0x00000000 0x80003048 8 | 0x405244 : 0x00000f00 0x00000000 0x00000000 0x10000108 9 | 0x405254 : 0x03180002 0x00042000 0x30000528 0x07380006 10 | 0x405264 : 0x0000fd01 0xc60081ff 0xb90f0000 0xc51e0000 11 | 0x405274: 0x00901200 0x05030080 0x00900480 0x00010180 12 | -------------------------------------------------------------------------------- /tools/map2dot.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Try: 4 | # gcc -static -o test test.c -Wl,--print-map | perl parse-map.pl | unflatten -l 3 | dot -Tpng > map.png 5 | # 6 | # This won't show all edges! An archive member is only listed the first 7 | # time it needs to get included. But this shows at least one reason why each 8 | # archive member appears in the final object. 9 | 10 | my $flag = 0; 11 | my $line = ""; 12 | print "digraph map {\n"; 13 | print "rankdir = LR;"; 14 | while(<>) 15 | { 16 | $flag++ if /^Archive member included because of file \(symbol\)$/; 17 | $flag++ if /^$/; 18 | next unless $flag == 2; 19 | 20 | chomp ($line .= $_); 21 | if ($line =~ /^(\S+)\s+(\S+)\s+\(([^)]+)\)$/s) { 22 | $line = ""; 23 | my $archive_member = $1; 24 | my $because_file = $2; 25 | my $because_symbol = $3; 26 | $archive_member =~ s|.*/([^/]+)|$1|; 27 | $because_file =~ s|.*/([^/]+)|$1|; 28 | print "\"$because_file\" -> \"$archive_member\";\n"; 29 | } 30 | } 31 | print "}\n"; 32 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - fix license for printf.c (take from newlib instead of glibc) 2 | 3 | - fix license for start.S (find a BSD version) 4 | 5 | - openocd flashing 6 | use run_algorithm to hook ROM NVM functions 7 | see flash/stm32x.c 8 | 9 | - add timestamp to received packets 10 | 11 | - add a way to set modes: tx_only, rx_only, txrx. (so you can be lazy 12 | and have blocks of code that don't need to handle rx packets) 13 | 14 | - beacon sync 15 | 16 | - CCA and ED. 17 | 18 | - auto-acking and ack managment 19 | keep a set of bit fields, one bit per sequence number (DSN), so 32 bytes 20 | total. 21 | Set them all to 1 initially. When a DSN is sent, clear the bit. Set 22 | the bit when the ack is received. 23 | Do anything special with sent but unacked packets? Maybe, so you can 24 | retransmit them. 25 | 26 | Dosen't look like contiki ever uses 802.15.4 acking: grep ACKFRAME 27 | 28 | not much point to implement it here unless you also plan to use in 29 | in contiki (pretty substantial change to core Contiki). 30 | 31 | also you ack the data after checking it's for you. so autoack relies 32 | on setting up the hardware addressing. 33 | 34 | -------------------------------------------------------------------------------- /tools/test-grid/open-terms.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use integer; 5 | 6 | my $start = shift; 7 | my $end = shift; 8 | 9 | if (! $end) { 10 | print "Usage: $0 first-term-num last-term-num\n"; 11 | die; 12 | } 13 | 14 | my $COLS = 4; 15 | 16 | my $index = 0; 17 | 18 | for (my $n=$start; $n <= $end; $n += 2) { 19 | #print "$n\n"; 20 | 21 | open(OUT, ">/tmp/USB$n.ini"); 22 | my $dev = "/dev/ttyUSB$n"; 23 | print OUT <> 4); 15 | $mac_l = ($iab & 0xf) << 28; 16 | } 17 | 18 | if (! $terms) { 19 | print "Usage: $0 flasher.bin num-devices\n"; 20 | die; 21 | } 22 | 23 | for (my $t=0; $t<$terms; $t++) { 24 | my $dev_num = 2 * $t + 1; 25 | $mac_l |= $dev_num; 26 | #stupid 32-bit thing... 27 | my $mac; 28 | printf("mac_h %x\n", $mac_h); 29 | printf("mac_l %x\n", $mac_l); 30 | my @words; 31 | for(my $i=0; $i<4; $i++) { 32 | push @words, ($mac_h >> ($i * 8)) & 0xff; 33 | } 34 | for(my $i=0; $i<4; $i++) { 35 | push @words, ($mac_l >> ($i * 8)) & 0xff; 36 | } 37 | reverse @words; 38 | foreach my $byte (@words) { 39 | printf("%02X",$byte); 40 | } 41 | print "\n"; 42 | 43 | my $word1 = sprintf("%02X%02X%02X%02X",$words[4],$words[5],$words[6],$words[7]); 44 | my $word2 = sprintf("%02X%02X%02X%02X",$words[0],$words[1],$words[2],$words[3]); 45 | 46 | my $ftdi_num = $terms - $t - 1; 47 | 48 | my $cmd = "../burn-mac.pl --iab=a8c --term=/dev/ttyUSB$dev_num --index=$ftdi_num $bin $dev_num"; 49 | print "$cmd\n"; 50 | system($cmd); 51 | } 52 | -------------------------------------------------------------------------------- /board/Makefile.board: -------------------------------------------------------------------------------- 1 | # -*- makefile -*- 2 | 3 | ALL_BOARDS = redbee-dev redbee-r1 redbee-usb redbee-econotag quahogcon freescale-ncb m12 4 | 5 | OBJDIR = obj_$(BOARD) 6 | CFLAGS += -I. -I$(OBJDIR) -I$(MC1322X)/board -DBOARD=$(BOARD) 7 | 8 | OBJDIR_COBJS = $(addprefix $(OBJDIR)/, $(COBJS)) 9 | 10 | # Create directory and board.h include 11 | $(OBJDIR)/board.h: 12 | $(call pretty,GEN,$@) 13 | @mkdir -p $(dir $@) 14 | $(Q)echo '/* This file was automatically generated */' > $(OBJDIR)/board.h 15 | $(Q)echo '#include "$(BOARD).h"' >> $(OBJDIR)/board.h 16 | 17 | # $(OBJDIR)/board.a contains all the objects defined in COBJS 18 | ifdef COBJS 19 | $(OBJDIR)/board.a: $(OBJDIR)/board.h $(OBJDIR_COBJS) 20 | $(call pretty,AR,$@) 21 | @rm -f $@ 22 | $Q$(AR) $(ARFLAGS) $@ $(OBJDIR_COBJS) 23 | else 24 | $(OBJDIR)/board.a: $(OBJDIR)/board.h 25 | $(call pretty,AR (empty),$@) 26 | @rm -f $@ 27 | $Q$(AR) $(ARFLAGS) $@ 28 | endif 29 | 30 | TARGET_OBJ += $(OBJDIR)/board.a 31 | 32 | # And is built from files in the parent directory 33 | $(OBJDIR)/%.o: %.c $(OBJDIR)/board.h $(FORCE_C_DEPENDS) 34 | $(call pretty,CC,$@) 35 | @mkdir -p $(dir $@) 36 | $Q$(CC) $(CFLAGS) $(CFLAGS_THUMB) -MMD -c -o $@ $< 37 | @$(FINALIZE_DEPENDENCY) 38 | 39 | $(OBJDIR)/%.o: %.S $(OBJDIR)/board.h 40 | $(call pretty,AS,$@) 41 | @mkdir -p $(dir $@) 42 | $(CC) $(AFLAGS) -MMD -c -o $@ $< 43 | @$(FINALIZE_DEPENDENCY) 44 | 45 | $(OBJDIR)/%.dis: $(OBJDIR)/%.o 46 | $(call pretty,OBJDUMP,$@) 47 | $Q$(OBJDUMP) -d $< > $@ || rm -f $@ 48 | 49 | ifneq ($(MAKECMDGOALS),clean) 50 | -include $(wildcard $(OBJDIR)/*.d) 51 | endif 52 | 53 | clean:: 54 | rm -rf obj_* 55 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | MC1322X := .. 2 | 3 | # all off the common objects for each target 4 | # a COBJ is made for EACH board and goes the obj_$(BOARD)_board directory 5 | # board specific code is OK in these files 6 | COBJS := tests.o put.o 7 | 8 | # all of the target programs to build 9 | TARGETS := blink-red blink-green blink-blue blink-white blink-allio \ 10 | uart1-loopback \ 11 | u1u2-loopback \ 12 | tmr tmr-ints \ 13 | sleep \ 14 | printf \ 15 | asm \ 16 | adc \ 17 | pwm \ 18 | wdt \ 19 | xtal-trim 20 | 21 | # these targets are built with space reserved for variables needed by ROM services 22 | # this space is initialized with a rom call to rom_data_init 23 | TARGETS_WITH_ROM_VARS := nvm-read nvm-write romimg flasher \ 24 | rftest-rx rftest-tx \ 25 | autoack-rx autoack-tx \ 26 | per 27 | 28 | ################################################## 29 | # you shouldn't need to edit anything below here # 30 | ################################################## 31 | 32 | # This Makefile includes the default rule at the top 33 | # it needs to be included first 34 | -include $(MC1322X)/Makefile.include 35 | 36 | # this rule will become the default_goal if 37 | # $(MC1322X)/Makefile.include doesn't exist it will try to update the 38 | # submodule, check if $(MC1322X) exists, and if it does 39 | # try make again 40 | submodule: 41 | git submodule update --init 42 | if [ ! -d $(MC1322X) ] ; then echo "*** cannot find MC1322X directory $(MC1322X)" ; exit 2; fi 43 | $(MAKE) 44 | 45 | .PHONY: submodule 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /lib/gpio-util.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "gpio-util.h" 6 | 7 | void gpio_select_function(uint8_t gpio, uint8_t func) { 8 | uint32_t mask = 3; 9 | uint8_t major, minor, shift; 10 | volatile uint32_t *base = GPIO_FUNC_SEL0; 11 | uint32_t value; 12 | major = gpio >> 4; 13 | minor = gpio & 0xF; 14 | shift = 2 * minor; 15 | 16 | value = base[major]; 17 | value &= ~(mask << shift); 18 | value |= (func << shift); 19 | base[major] = value; 20 | } 21 | 22 | void gpio_reg_set(volatile uint32_t* reg, uint8_t bit) { 23 | uint8_t major, minor; 24 | major = bit / 32; 25 | minor = bit % 32; 26 | *(reg + major) |= (1UL << minor); 27 | } 28 | 29 | void gpio_reg_clear(volatile uint32_t* reg, uint8_t bit) { 30 | uint8_t major, minor; 31 | major = bit / 32; 32 | minor = bit % 32; 33 | *(reg + major) &= ~(1UL << minor); 34 | } 35 | 36 | void gpio_set_pad_dir(uint8_t gpio, uint8_t dir) { 37 | uint8_t major, minor; 38 | major = gpio / 32; 39 | minor = gpio % 32; 40 | if (dir) gpio_reg_set(GPIO_PAD_DIR0 + major, minor); 41 | else gpio_reg_clear(GPIO_PAD_DIR0 + major, minor); 42 | } 43 | 44 | void gpio_set(uint8_t gpio) { 45 | uint8_t major, minor; 46 | major = gpio / 32; 47 | minor = gpio % 32; 48 | *(GPIO_DATA_SET0 + major) = (1UL << minor); 49 | } 50 | 51 | void gpio_reset(uint8_t gpio) { 52 | uint8_t major, minor; 53 | major = gpio / 32; 54 | minor = gpio % 32; 55 | *(GPIO_DATA_RESET0 + major) = (1UL << minor); 56 | } 57 | 58 | bool gpio_read(uint8_t gpio) { 59 | uint8_t major, minor; 60 | major = gpio / 32; 61 | minor = gpio % 32; 62 | return (*(GPIO_DATA0 + major) >> minor) & 1; 63 | } 64 | -------------------------------------------------------------------------------- /doc/autoack: -------------------------------------------------------------------------------- 1 | The known details about autoacking. 2 | 3 | 1) Auto-acking is disabled if promiscuous mode in enabled. Auto-acking 4 | is enabled when promiscuous mode is disabled. A more proper name 5 | for this bit would be promiscuous/#autoack. 6 | 7 | 2) If promiscuous mode is disabled and a recieved packet 1) matches 8 | the address filters and 2) has the ack request bit set, then an 9 | auto-ack will be sent (provided you do item 3 properly). The 10 | sequence number is stuffed and transmitted automatically. Note: you 11 | must have the address set properly in the maca hardware. That means 12 | the EUI registers for long addressing and the PANID and short 13 | addr. for short addressing. 14 | 15 | 3) You must wait 200 maca clocks or so after receiving a packet that 16 | needs an ack. This is necessary for the maca to do it's thing. If 17 | you don't wait enough then it either will not send the ack, or if 18 | you wait a little more (but not enough), the ack DSN will be zero. 19 | 20 | 4) The following must be set properly, TXACKDELAY, RXACKDELAY, 21 | RXEND. The best way to set these is to use a scope and the TX_ON 22 | and RX_ON signals. You set TXACKDELAY so that the ack is 23 | transmitted 12 symbols after the received packet (192 us). You set 24 | RXACKDELAY to start before the ack is due to arrive (I'm doing 25 | 100us before). And you set RXEND to be long enough to receive the 26 | ACK (I'm doing a 700us window or so). 27 | 28 | 4b) CCA has its own set of timings. 29 | 30 | 5) The transmitter must set TXSEQNR before MACA_DMATX. 31 | 32 | 6) The status of the next "action complete" on the TX side tells you 33 | if the ack was received or not. Status will be 0 (success) if you 34 | got the ack and 5 (no_ack) if you did not. 35 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | -------------------------------------------------------------------------------- /tools/rimecollect-rrd/meshstat.cgi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # CGI script that creates a fill-out form 4 | # and echoes back its values. 5 | 6 | use CGI qw/:standard/; 7 | 8 | # configs 9 | 10 | # paths 11 | my $meshpath = "/home/malvira/work"; 12 | my $wwwpath = "/var/www"; 13 | my $hostname = "hotdog.redwirellc.com"; 14 | 15 | # aliases 16 | my %aliases = ( 17 | "2.0" => { 18 | alias => "Lower Door", 19 | ds=> { 20 | "GPIO29" => "Lock (0 - locked, 1 - unlocked)", 21 | }, 22 | }, 23 | "4.0" => { 24 | alias => "Upper Door", 25 | }, 26 | "1.0" => { 27 | alias => "Hotdog (datasink)", 28 | }, 29 | ); 30 | 31 | opendir(MESHDIR, $meshpath); 32 | my @files = readdir(MESHDIR); 33 | 34 | print header; 35 | print start_html('Collect Mesh'); 36 | 37 | 38 | foreach my $file (@files) { 39 | next if $file !~ /([\d\.]+)\.rrd$/; 40 | my $addr = $1; 41 | print hr; 42 | print h1("$addr: $aliases{$addr}{'alias'}"); 43 | my @info = split(/\n/,qx(rrdtool info $meshpath/$addr.rrd)); 44 | 45 | my %dses; 46 | foreach my $info (@info) { 47 | next if $info !~ /ds\[([\w\d]+)\]\.([\w\d_]+)\s+=\s+([\w\d]+)/; 48 | $dses{$1}{$2} = $3; 49 | } 50 | 51 | my $lastupdate = qx(rrdtool lastupdate $meshpath/$addr.rrd); 52 | $lastupdate =~ /([\w\d]+)\s+(\d+):\s+([\w\d]+)/; 53 | print localtime($2) . " $1 $3
"; 54 | 55 | foreach my $ds (keys(%dses)) { 56 | print h2("$ds: $aliases{$addr}{'ds'}{$ds}"); 57 | qx(rrdtool graph $wwwpath/$addr-$ds.png --start end-60min DEF:$ds=$meshpath/$addr.rrd:$ds:LAST LINE2:$ds#00a000:\"$ds\"); 58 | print img({src=>"http://$hostname/$addr-$ds.png"}); 59 | } 60 | 61 | } 62 | 63 | print hr; 64 | 65 | print end_html; 66 | 67 | #/var/www/demo.png --title="Door" --start end-60min 68 | # --imginfo '' 69 | # DEF:door=/home/malvira/work/2.0.rrd:GPIO29:LAST 70 | # LINE2:door#00a000:"Door lock"> 71 | -------------------------------------------------------------------------------- /tools/burn-mac.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use Getopt::Long; 4 | 5 | my $oui; 6 | my $addr = "0x1e000"; 7 | my $iab; 8 | my $term = "/dev/ttyUSB1"; 9 | my $index = 0; 10 | 11 | GetOptions ('iab=s' => \$iab, 12 | 'oui=s' => \$oui, 13 | 'term=s' => \$term, 14 | 'index=s' => \$index, 15 | ) or die 'bad options'; 16 | 17 | my $bin = shift; 18 | my $address = shift; 19 | 20 | if (!defined($address) || !defined($bin)) { 21 | print "Usage: $0 [--iab=a8c | --oui=abcdef | --term device] flasher.bin address\n"; 22 | print " iab is 12-bit and address is 28-bit e.g. --iab=a8c 1234567\n"; 23 | print " oui is 24-bit and address is 40-bit e.g. --oui=abcdef 123456789a\n"; 24 | exit; 25 | } 26 | 27 | my $mac_h; 28 | my $mac_l; 29 | 30 | if(defined($iab)) { 31 | $iab = hex($iab); 32 | $address = hex($address); 33 | $mac_h = 0x0050C200 | ($iab >> 4); 34 | $mac_l = (($iab & 0xf) << 28) | $address; 35 | } else { 36 | $address =~ /(.*?)(.{0,8})$/; 37 | my ($addr_h, $addr_l) = ($1, $2); 38 | if(!$addr_h) { $addr_h = 0 }; 39 | $oui = hex($oui); 40 | $addr_l = hex($addr_l); 41 | $addr_h = hex($addr_h); 42 | $mac_h = ($oui << 8) | $addr_h; 43 | $mac_l = $addr_l; 44 | } 45 | 46 | printf("mach %x macl %x\n", $mac_h, $mac_l); 47 | 48 | my @words; 49 | for(my $i=0; $i<4; $i++) { 50 | push @words, ($mac_l >> ($i * 8)) & 0xff; 51 | } 52 | for(my $i=0; $i<4; $i++) { 53 | push @words, ($mac_h >> ($i * 8)) & 0xff; 54 | } 55 | reverse @words; 56 | #foreach my $byte (@words) { 57 | # printf("%02X",$byte); 58 | #} 59 | #print "\n"; 60 | 61 | my $word1 = sprintf("%02X%02X%02X%02X",$words[4],$words[5],$words[6],$words[7]); 62 | my $word2 = sprintf("%02X%02X%02X%02X",$words[0],$words[1],$words[2],$words[3]); 63 | 64 | my $cmd = "mc1322x-load.pl -e -f $bin -z -t $term -c 'bbmc -i $index -l redbee-econotag reset' $addr,0x$word1,0x$word2 &"; 65 | print "$cmd\n"; 66 | system($cmd); 67 | 68 | -------------------------------------------------------------------------------- /tools/rimecollect-rrd/collect2rrd.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | use strict; 3 | my $verbose = 1; 4 | 5 | #### 6 | # Feed data on stdin from a RIME collect sink 7 | # 8 | # Enters data into rimeaddr.rrd 9 | # 10 | # Creates rimeaddr.rrd from a template if data shows up from a source and 11 | # rimeaddr.rrd doesn't exist 12 | # 13 | # default template is read from default.rrdtmpl 14 | # 15 | # if rimeaddr.rrdtmpl exisits, that is used instead. 16 | 17 | #### 18 | # 19 | # Templates are shell scripts that create the desired rrd 20 | # 21 | 22 | #### 23 | # Data messages are in the form of: 24 | # 25 | # Sink got message from 1.0, seqno 109, hops 0: len 12 'GPIO29-High' 26 | # 27 | # 28 | 29 | my $datapattern = 'Sink got message from ([\d\.]+), seqno \d+, hops \d+: len \d+ \'([\w\d]+-[\w\d]+)\''; 30 | 31 | sub rrdcreate { 32 | my ($newrrd_filename, $tmpl_filename) = @_; 33 | open FILE, "$tmpl_filename" or die $!; 34 | my $tmpl = ; 35 | chomp $tmpl; 36 | print "using template $tmpl found in $tmpl_filename\n" if $verbose; 37 | `rrdtool create $newrrd_filename $tmpl`; 38 | } 39 | 40 | while(<>) { 41 | 42 | next if($_ !~ /$datapattern/); 43 | print("rimeaddr $1 data $2\n") if $verbose; 44 | 45 | my ($ds,$data) = split(/-/,$2); 46 | print("ds: $ds, data: $data\n") if $verbose; 47 | 48 | if(-e "$1.rrd") { 49 | # an rrd already exists for this device 50 | # do an update 51 | `rrdtool update $1.rrd -t $ds N:$data` 52 | } else { 53 | # an rrd for this device doesn't exist yet 54 | # find a template and make it 55 | my $tmpl = "DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:6:10"; 56 | print "creating new rrd $1.rrd... " if $verbose; 57 | if(-e "$1.rrdtmpl") { 58 | rrdcreate("$1.rrd","$1.rrdtmpl"); 59 | `rrdtool update $1.rrd -t $ds N:$data` 60 | } elsif(-e "default.rrdtmpl") { 61 | rrdcreate("$1.rrd","default.rrdtmpl"); 62 | `rrdtool update $1.rrd -t $ds N:$data` 63 | } else { 64 | print "can't create rrd for $1: no template found\n"; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/put.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef PUT_H 37 | #define PUT_H 38 | 39 | void putchr(char c); 40 | void putstr(char *s); 41 | void put_hex(uint8_t x); 42 | void put_hex16(uint16_t x); 43 | void put_hex32(uint32_t x); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libmc1322x is a library, build system, test code, and utilities for 2 | using the mc13224v from Freescale. 3 | 4 | Getting Started 5 | --------------- 6 | $ cd tests 7 | $ make 8 | 9 | this will build all the test files in libmc1322x/tests for each board 10 | defined in libmc1322x/board. You will have programs like: 11 | 12 | rftest-tx_redbee-dev.bin 13 | rftest-tx_redbee-r1.bin 14 | 15 | rftest-rx_redbee-dev.bin 16 | rftest-rx_redbee-r1.bin 17 | 18 | if you only wanted to build binaries for one board you can do: 19 | 20 | $ make BOARD=redbee-dev 21 | 22 | You can use mc1322x-load.pl in libmc1322x/tools to run your code: 23 | 24 | $ ../tools/mc1322x-load.pl -f rftest-tx_redbee-dev.bin 25 | 26 | 27 | Incorporating libmc1322x into your own code 28 | ------------------------------------------- 29 | 30 | The best way to incorporate libmc1322x into your code is as a git 31 | submodule: 32 | 33 | $ mkdir newproject 34 | $ cd newproject 35 | $ git init 36 | 37 | Initialized empty Git repository in /home/malvira/newproject/.git/ 38 | 39 | $ git submodule add git://git.devl.org/git/malvira/libmc1322x.git 40 | 41 | This will add libmc1322x to your repository. Now to setup the 42 | Makefile: 43 | 44 | $ cp libmc1322x/tests/Makefile . 45 | 46 | You need to edit the Makefile to point MC1322X to your libmc1322x 47 | submodule: 48 | 49 | Change line 1 50 | 51 | MC1322X := .. 52 | 53 | to 54 | 55 | MC1322X := libmc1322x 56 | 57 | and edit COBJS and TARGETS accordings. COBJS are all of your common 58 | code for any of your programs. TARGETS are the names of your programs. 59 | 60 | For instance, you can have a common routine that prints a welcome 61 | message that is used by two programs a and b. You would add common.o 62 | to COBJS: 63 | 64 | COBJS:= common.o 65 | 66 | and your target line would read: 67 | 68 | TARGETS := a b 69 | 70 | COBJS are made for each board --- so it is ok to have board specific 71 | code in there. As an example, tests uses this in tests.c to print the 72 | name of the board in the welcome message. You could also use this to 73 | change your GPIO mappings between boards. 74 | 75 | -------------------------------------------------------------------------------- /tests/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef TESTS_H 37 | #define TESTS_H 38 | 39 | #include "put.h" 40 | #include "led.h" 41 | 42 | #define NL "\033[K\r\n" 43 | 44 | void print_welcome(char* testname); 45 | void dump_regs(uint32_t base, uint32_t len); 46 | void print_packet(volatile packet_t *p); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/default_lowlevel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef LOWLEVEL_H 37 | #define LOWLEVEL_H 38 | 39 | #include "crm.h" 40 | 41 | #define trim_xtal() pack_XTAL_CNTL(CTUNE_4PF, CTUNE, FTUNE, IBIAS) 42 | 43 | void default_vreg_init(void); 44 | void buck_init(void); 45 | void m12_init(void); 46 | 47 | void irq_register_timer_handler(int timer, void (*isr)(void)); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /tests/romimg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "tests.h" 40 | #include "config.h" 41 | 42 | void main(void) { 43 | volatile uint8_t *data; 44 | 45 | uart_init(UART1, 115200); 46 | 47 | for(data = DUMP_BASE; data < ((uint8_t *)(DUMP_BASE+DUMP_LEN)); data++) { 48 | uart1_putc(*data); 49 | } 50 | 51 | while(1); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /tests/uart1-loopback.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "tests.h" 40 | #include "config.h" 41 | 42 | void main(void) { 43 | 44 | uart_init(UART1, 115200); 45 | 46 | while(1) { 47 | if(uart1_can_get()) { 48 | /* Receive buffer isn't empty */ 49 | /* read a byte and write it to the transmit buffer */ 50 | uart1_putc(uart1_getc()); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /tests/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef LED_H 37 | #define LED_H 38 | 39 | #define LED_YELLOW ((1ULL << LED_RED) | (1ULL << LED_GREEN) ) 40 | #define LED_PURPLE ((1ULL << LED_RED) | (1ULL << LED_BLUE)) 41 | #define LED_CYAN ( (1ULL << LED_GREEN) | (1ULL << LED_BLUE)) 42 | #define LED_WHITE ((1ULL << LED_RED) | (1ULL << LED_GREEN) | (1ULL << LED_BLUE)) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/include/mc1322x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef MC1322X_H 37 | #define MC1322X_H 38 | 39 | #include "isr.h" 40 | #include "gpio.h" 41 | #include "crm.h" 42 | #include "nvm.h" 43 | #include "tmr.h" 44 | #include "kbi.h" 45 | #include "maca.h" 46 | #include "packet.h" 47 | #include "uart.h" 48 | #include "utils.h" 49 | #include "asm.h" 50 | #include "i2c.h" 51 | #include "rtc.h" 52 | #include "adc.h" 53 | #include "pwm.h" 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /tests/blink-blue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #define DELAY 400000 40 | 41 | #define LED (1ULL << LED_BLUE) 42 | 43 | void main(void) { 44 | volatile uint32_t i; 45 | 46 | gpio_pad_dir(LED); 47 | 48 | while(1) { 49 | 50 | gpio_data(LED); 51 | 52 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #define DELAY 400000 40 | 41 | #define LED (1ULL << LED_GREEN) 42 | 43 | void main(void) { 44 | volatile uint32_t i; 45 | 46 | gpio_pad_dir(LED); 47 | 48 | while(1) { 49 | 50 | gpio_data(LED); 51 | 52 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #define DELAY 400000 40 | 41 | #define LED (1ULL << LED_RED) 42 | 43 | void main(void) { 44 | volatile uint32_t i; 45 | 46 | gpio_pad_dir(LED); 47 | 48 | while(1) { 49 | 50 | gpio_data(LED); 51 | 52 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "led.h" 40 | 41 | #define DELAY 400000 42 | 43 | #define LED LED_WHITE 44 | 45 | void main(void) { 46 | volatile uint32_t i; 47 | 48 | gpio_pad_dir(LED); 49 | 50 | while(1) { 51 | 52 | gpio_data(LED); 53 | 54 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "tests.h" 40 | #include "config.h" 41 | 42 | void main(void) { 43 | 44 | GPIO->PAD_PU_SEL.U2RX = 1; 45 | 46 | uart_init(UART1, 115200); 47 | uart_init(UART2, 115200); 48 | 49 | while(1) { 50 | if(uart1_can_get()) { 51 | /* Receive buffer isn't empty */ 52 | /* read a byte and write it to the transmit buffer */ 53 | uart2_putc(uart1_getc()); 54 | } 55 | if(uart2_can_get()) { 56 | uart1_putc(uart2_getc()); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /lib/include/rtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef RTC_H 37 | #define RTC_H 38 | 39 | /* Init RTC (and calibrate, if using ring oscillator) */ 40 | void rtc_init_osc(int use_32khz); 41 | 42 | #ifdef USE_32KHZ 43 | #define rtc_init() rtc_init_osc(USE_32KHZ) 44 | #else 45 | #define rtc_init() rtc_init_osc(0) 46 | #endif 47 | 48 | /* Calibrate the ring oscillator */ 49 | void rtc_calibrate(void); 50 | 51 | /* Delay for the specified number of milliseconds by polling RTC */ 52 | void rtc_delay_ms(uint32_t msec); 53 | 54 | /* Calibrated frequency of the RTC, in Hz */ 55 | extern int rtc_freq; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /board/m12.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_M12_H 37 | #define BOARD_M12_H 38 | 39 | /* XTAL TUNE parameters */ 40 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 41 | /* for details about how to make this measurement */ 42 | 43 | /* Econotag also needs an addtional 12pf on board */ 44 | /* Coarse tune: add 4pf */ 45 | #define CTUNE_4PF 1 46 | /* Coarse tune: add 0-15 pf (CTUNE is 4 bits) */ 47 | #define CTUNE 3 48 | /* Fine tune: add FTUNE * 156fF (FTUNE is 5bits) */ 49 | #define FTUNE 3 50 | 51 | #define vreg_init buck_init 52 | #define board_init m12_init 53 | #include 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /tools/bin2macbin.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use File::Copy; 5 | use Getopt::Long; 6 | use File::Basename; 7 | 8 | my $cmd; 9 | my $oui; 10 | my $iab; 11 | 12 | GetOptions ('iab=s' => \$iab, 13 | 'oui=s' => \$oui, 14 | ) or die 'bad options'; 15 | 16 | my $address = shift; 17 | my $infile = shift; 18 | my $outfile = shift; 19 | 20 | if (!defined($address) || !defined($infile)) { 21 | print "Usage: $0 [--iab=a8c | --oui=abcdef ] address infile [outfile]\n"; 22 | print " iab is 12-bit and address is 28-bit e.g. --iab=a8c 1234567\n"; 23 | print " oui is 24-bit and address is 40-bit e.g. --oui=abcdef 123456789a\n"; 24 | print "\n"; 25 | print " if outfile is not specified, for infile foo.bin outfile will be\n"; 26 | print " foo-[macaddress].bin e.g:\n"; 27 | print " for --iab=a8c 1234567 foo.bin -> foo-0050c2a8c1234567.bin\n"; 28 | print " for --oui=abcdef 123456789a foo.bin -> foo-abcdef123456789a.bin\n"; 29 | exit; 30 | } 31 | 32 | my $mac_h; 33 | my $mac_l; 34 | 35 | if(defined($iab)) { 36 | $iab = hex($iab); 37 | $address = hex($address); 38 | $mac_h = 0x0050C200 | ($iab >> 4); 39 | $mac_l = (($iab & 0xf) << 28) | $address; 40 | } else { 41 | $address =~ /(.*?)(.{0,8})$/; 42 | my ($addr_h, $addr_l) = ($1, $2); 43 | if(!$addr_h) { $addr_h = 0 }; 44 | $oui = hex($oui); 45 | $addr_l = hex($addr_l); 46 | $addr_h = hex($addr_h); 47 | $mac_h = ($oui << 8) | $addr_h; 48 | $mac_l = $addr_l; 49 | } 50 | 51 | printf("mach %x macl %x\n", $mac_h, $mac_l); 52 | 53 | my @words; 54 | for(my $i=0; $i<4; $i++) { 55 | push @words, ($mac_l >> ($i * 8)) & 0xff; 56 | } 57 | for(my $i=0; $i<4; $i++) { 58 | push @words, ($mac_h >> ($i * 8)) & 0xff; 59 | } 60 | reverse @words; 61 | #foreach my $byte (@words) { 62 | # printf("%02X",$byte); 63 | #} 64 | #print "\n"; 65 | 66 | if(!defined($outfile)) 67 | { 68 | my $basename = basename($infile,(".bin")); 69 | $outfile = sprintf("-%08x%08x.bin",$mac_h, $mac_l); 70 | $outfile = $basename . $outfile; 71 | print "outfile $outfile\n"; 72 | } 73 | 74 | copy($infile, $outfile) or die("Couldn't copy $infile to $outfile"); 75 | $cmd = sprintf("echo -n -e '\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X' | dd of=$outfile bs=1 seek=122872 conv=notrunc", 76 | $words[7],$words[6],$words[5],$words[4], 77 | $words[3],$words[2],$words[1],$words[0]); 78 | 79 | print "$cmd\n"; 80 | system("bash -c \"$cmd\""); 81 | 82 | 83 | -------------------------------------------------------------------------------- /tests/blink-allio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #define DELAY 400000 40 | 41 | void main(void) { 42 | 43 | *GPIO_FUNC_SEL0 = 0xffffffff; 44 | *GPIO_FUNC_SEL1 = 0xffffffff; 45 | *GPIO_FUNC_SEL2 = 0xffffffff; 46 | *GPIO_FUNC_SEL3 = 0xffffffff; 47 | 48 | *GPIO_PAD_DIR0 = 0xffffffff; 49 | *GPIO_PAD_DIR1 = 0xffffffff; 50 | 51 | volatile uint32_t i; 52 | 53 | while(1) { 54 | 55 | *GPIO_DATA0 = 0xffffffff; 56 | *GPIO_DATA1 = 0xffffffff; 57 | 58 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_REDBEE_R1_H 37 | #define BOARD_REDBEE_R1_H 38 | 39 | #define GPIO_LED_RED GPIO_08 40 | #define GPIO_LED_GREEN GPIO_09 41 | #define GPIO_LED_BLUE GPIO_10 42 | 43 | #define LED_RED 8 44 | #define LED_GREEN 9 45 | #define LED_BLUE 10 46 | 47 | /* XTAL TUNE parameters */ 48 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 49 | /* for details about how to make this measurement */ 50 | 51 | /* Coarse tune: add 4pf */ 52 | #define CTUNE_4PF 1 53 | /* Coarse tune: add 0-15 pf */ 54 | #define CTUNE 3 55 | /* Fine tune: add FTUNE * 156fF (FTUNE is 4bits) */ 56 | #define FTUNE 2 57 | 58 | #include 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /board/redbee-dev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_REDBEE_DEV_H 37 | #define BOARD_REDBEE_DEV_H 38 | 39 | #define GPIO_LED_RED GPIO_23 40 | #define GPIO_LED_GREEN GPIO_24 41 | #define GPIO_LED_BLUE GPIO_25 42 | 43 | #define LED_RED 23 44 | #define LED_GREEN 24 45 | #define LED_BLUE 25 46 | 47 | /* XTAL TUNE parameters */ 48 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 49 | /* for details about how to make this measurement */ 50 | 51 | /* Coarse tune: add 4pf */ 52 | #define CTUNE_4PF 1 53 | /* Coarse tune: add 0-15 pf */ 54 | #define CTUNE 3 55 | /* Fine tune: add FTUNE * 156fF (FTUNE is 4bits) */ 56 | #define FTUNE 6 57 | 58 | #include 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /board/redbee-usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_REDBEE_USB_H 37 | #define BOARD_REDBEE_USB_H 38 | 39 | #define GPIO_LED_RED GPIO_23 40 | #define GPIO_LED_GREEN GPIO_24 41 | #define GPIO_LED_BLUE GPIO_25 42 | 43 | #define LED_RED 23 44 | #define LED_GREEN 24 45 | #define LED_BLUE 25 46 | 47 | /* XTAL TUNE parameters */ 48 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 49 | /* for details about how to make this measurement */ 50 | 51 | /* Coarse tune: add 4pf */ 52 | #define CTUNE_4PF 1 53 | /* Coarse tune: add 0-15 pf */ 54 | #define CTUNE 3 55 | /* Fine tune: add FTUNE * 156fF (FTUNE is 4bits) */ 56 | #define FTUNE 14 57 | 58 | #include 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /board/freescale-ncb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_FREESCALE_NCB_H 37 | #define BOARD_FREESCALE_NCB_H 38 | 39 | #define GPIO_LED_RED GPIO_23 40 | #define GPIO_LED_GREEN GPIO_24 41 | #define GPIO_LED_BLUE GPIO_25 42 | 43 | #define LED_RED 23 44 | #define LED_GREEN 24 45 | #define LED_BLUE 25 46 | 47 | /* XTAL TUNE parameters */ 48 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 49 | /* for details about how to make this measurement */ 50 | 51 | /* Coarse tune: add 4pf */ 52 | #define CTUNE_4PF 1 53 | /* Coarse tune: add 0-15 pf */ 54 | #define CTUNE 8 55 | /* Fine tune: add FTUNE * 156fF (FTUNE is 4bits) */ 56 | #define FTUNE 15 57 | 58 | #include 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /tests/adc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "config.h" 41 | #include "adc.h" 42 | 43 | int main(void) 44 | { 45 | uint8_t c; 46 | 47 | trim_xtal(); 48 | uart_init(UART1, 115200); 49 | adc_init(); 50 | 51 | printf("adc test\r\n"); 52 | 53 | printf("\x1B[2J"); // clear screen 54 | 55 | for (c=0; c<=7; c++) { 56 | adc_setup_chan(c); 57 | } 58 | 59 | for(;;) { 60 | printf("\x1B[H"); // cursor home 61 | printf("# Value\r\n"); 62 | for (c=0; c and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef KBI_H 37 | #define KBI_H 38 | 39 | #define enable_irq_kbi(k) (set_bit(*CRM_WU_CNTL,(EXT_WU_IEN+k-4))) 40 | #define disable_irq_kbi(k) (clear_bit(*CRM_WU_CNTL,(EXT_WU_IEN+k-4))) 41 | 42 | #define kbi_evnt(k) (bit_is_set(*CRM_STATUS,(EXT_WU_EVT+k-4))) 43 | 44 | #define kbi_edge(k) (set_bit(*CRM_WU_CNTL,(EXT_WU_EDGE+k-4))) 45 | #define kbi_level(k) (clear_bit(*CRM_WU_CNTL,(EXT_WU_EDGE+k-4))) 46 | 47 | #define kbi_pol_neg(k) (clear_bit(*CRM_WU_CNTL,(EXT_WU_POL+k-4))) 48 | #define kbi_pol_pos(k) (set_bit(*CRM_WU_CNTL,(EXT_WU_POL+k-4))) 49 | 50 | /* you have to clear these events by writing a one to them */ 51 | 52 | #define clear_kbi_evnt(k) (set_bit(*CRM_STATUS,(EXT_WU_EVT+k-4))) 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /tests/wdt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "config.h" 41 | 42 | #define DELAY 400000 43 | 44 | #define LED GPIO_LED_RED 45 | 46 | void main(void) { 47 | volatile uint32_t i; 48 | 49 | uart_init(UART1, 115200); 50 | 51 | printf("reset\n\r"); 52 | 53 | /* set the watchdog timer timeout to 1 sec */ 54 | cop_timeout_ms(1000); 55 | 56 | /* enable the watchdog timer */ 57 | CRM->COP_CNTLbits.COP_EN = 1; 58 | 59 | GPIO->PAD_DIR.LED = 1; 60 | 61 | while(1) { 62 | /* uncomment cop_service for normal operation */ 63 | //cop_service(); 64 | 65 | GPIO->DATA.LED = 1; 66 | 67 | for(i=0; iDATA.LED = 0; 70 | 71 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef CONFIG_H 37 | #define CONFIG_H 38 | 39 | /* nvm interface */ 40 | #define NVM_INTERFACE gNvmInternalInterface_c 41 | /*#define NVM_INTERFACE gNvmExternalInterface_c */ 42 | 43 | /* nvm-read */ 44 | #define READ_ADDR 0x1f000 45 | #define READ_NBYTES 1024 46 | 47 | /* nvm-write */ 48 | #define WRITE_NBYTES 8 49 | #define WRITE_ADDR 0x1e000 50 | #define WRITEVAL0 0xdeadbeef 51 | #define WRITEVAL1 0xdeadbeef 52 | 53 | /* romimg */ 54 | #define DUMP_BASE 0x00000000 55 | #define DUMP_LEN 0x00014000 56 | 57 | /* flasher */ 58 | /* if both BOOT_OK and BOOT_SECURE are 0 then flash image will not be bootable */ 59 | /* if both are 1 then flash image will be secure */ 60 | #define BOOT_OK 1 61 | #define BOOT_SECURE 0 62 | 63 | /* sleep */ 64 | #undef USE_32KHZ /* board should have a HAS_32KHZ define */ 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /board/econotag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_REDBEE_ECONOTAG_H 37 | #define BOARD_REDBEE_ECONOTAG_H 38 | 39 | #define GPIO_LED_RED GPIO_44 40 | #define GPIO_LED_GREEN GPIO_45 41 | #define GPIO_LED_BLUE GPIO_43 /* don't have a blue LED so we use IO43 */ 42 | 43 | #define LED_RED 44 44 | #define LED_GREEN 45 45 | #define LED_BLUE 43 /* don't have a blue LED so we reuse red */ 46 | 47 | /* XTAL TUNE parameters */ 48 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 49 | /* for details about how to make this measurement */ 50 | 51 | /* Econotag also needs an addtional 12pf on board */ 52 | /* Coarse tune: add 4pf */ 53 | #define CTUNE_4PF 1 54 | /* Coarse tune: add 0-15 pf (CTUNE is 4 bits) */ 55 | #define CTUNE 11 56 | /* Fine tune: add FTUNE * 156fF (FTUNE is 5bits) */ 57 | #define FTUNE 7 58 | 59 | #include 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /board/redbee-econotag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_REDBEE_ECONOTAG_H 37 | #define BOARD_REDBEE_ECONOTAG_H 38 | 39 | #define GPIO_LED_RED GPIO_44 40 | #define GPIO_LED_GREEN GPIO_45 41 | #define GPIO_LED_BLUE GPIO_43 /* don't have a blue LED so we use IO43 */ 42 | 43 | #define LED_RED 44 44 | #define LED_GREEN 45 45 | #define LED_BLUE 43 /* don't have a blue LED so we reuse red */ 46 | 47 | /* XTAL TUNE parameters */ 48 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 49 | /* for details about how to make this measurement */ 50 | 51 | /* Econotag also needs an addtional 12pf on board */ 52 | /* Coarse tune: add 4pf */ 53 | #define CTUNE_4PF 1 54 | /* Coarse tune: add 0-15 pf (CTUNE is 4 bits) */ 55 | #define CTUNE 11 56 | /* Fine tune: add FTUNE * 156fF (FTUNE is 5bits) */ 57 | #define FTUNE 7 58 | 59 | #include 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/nvm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include "nvm.h" 37 | 38 | nvmErr_t (*nvm_detect) 39 | (nvmInterface_t nvmInterface,nvmType_t* pNvmType) 40 | = (void *) 0x00006cb9; 41 | 42 | nvmErr_t (*nvm_read) 43 | (nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes) 44 | = (void *) 0x00006d69; 45 | 46 | nvmErr_t (*nvm_write) 47 | (nvmInterface_t nvmInterface, nvmType_t nvmType ,void *pSrc, uint32_t address, uint32_t numBytes) 48 | = (void *) 0x00006ec5; 49 | 50 | nvmErr_t (*nvm_erase) 51 | (nvmInterface_t nvmInterface, nvmType_t nvmType ,uint32_t sectorBitfield) 52 | = (void*) 0x00006e05; 53 | 54 | nvmErr_t (*nvm_verify) 55 | (nvmInterface_t nvmInterface, nvmType_t nvmType, void *pSrc, uint32_t address, uint32_t numBytes) 56 | = (void*) 0x00006f85; 57 | 58 | void(*nvm_setsvar) 59 | (uint32_t zero_for_awesome) 60 | = (void *)0x00007085; 61 | -------------------------------------------------------------------------------- /lib/include/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef UTILS_H 37 | #define UTILS_H 38 | 39 | #define mem32(x) ((volatile uint32_t *)(x)) 40 | #define mem16(x) ((volatile uint16_t *)(x)) 41 | 42 | #define CAT2(x, y, z) x##y##z 43 | 44 | #define STR(x) #x 45 | #define STR2(x) STR(x) 46 | 47 | #define bit(bit) (1 << bit) 48 | #define bit_is_set(val, bit) (((val & (1 << bit)) >> bit) == 1) 49 | #define clear_bit(val, bit) (val = (val & ~(1 << bit))) 50 | #define set_bit(val, bit) (val = (val | (1 << bit))) 51 | 52 | #define ones(num) ( (1ULL << num) - 1 ) 53 | #define bit_mask(length, shift) (ones(length) << shift) 54 | #define get_field(val, field) ((val & field##_MASK) >> field) 55 | //#define bitfield(name, length, shift) ( #define #name length #define #name##_MASK bit_mask(length, shift)) 56 | #define bitfield(name, length, shift) ( define #name length ) 57 | 58 | #endif /* UTILS_H */ 59 | -------------------------------------------------------------------------------- /tests/put.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | const uint8_t hex[16]={'0','1','2','3','4','5','6','7', 40 | '8','9','a','b','c','d','e','f'}; 41 | 42 | void putchr(char c) { 43 | while(*UART1_UTXCON == 31); 44 | /* wait for there to be room in the buffer */ 45 | // while( *UART1_UTXCON == 0 ) { continue; } 46 | *UART1_UDATA = c; 47 | } 48 | 49 | void putstr(char *s) { 50 | while(s && *s!=0) { 51 | putchr(*s++); 52 | } 53 | } 54 | 55 | void put_hex(uint8_t x) 56 | { 57 | putchr(hex[x >> 4]); 58 | putchr(hex[x & 15]); 59 | } 60 | 61 | void put_hex16(uint16_t x) 62 | { 63 | put_hex((x >> 8) & 0xFF); 64 | put_hex((x) & 0xFF); 65 | } 66 | 67 | void put_hex32(uint32_t x) 68 | { 69 | put_hex((x >> 24) & 0xFF); 70 | put_hex((x >> 16) & 0xFF); 71 | put_hex((x >> 8) & 0xFF); 72 | put_hex((x) & 0xFF); 73 | } 74 | -------------------------------------------------------------------------------- /tests/xtal-trim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "config.h" 41 | #include "tests.h" 42 | 43 | int main(void) 44 | { 45 | uint8_t ctune_4pf, ctune, ftune; 46 | 47 | ctune_4pf = 0; 48 | ctune = 0; 49 | ftune = 0; 50 | 51 | uart_init(UART1, 115200); 52 | 53 | print_welcome("pwm test\r\n"); 54 | pack_XTAL_CNTL(ctune_4pf, ctune, ftune, IBIAS); 55 | 56 | for(;;) { 57 | switch(uart1_getc()) { 58 | case '[': if(ctune > 0) ctune -= 1; break; 59 | case ']': if(ctune < 15) ctune += 1; break; 60 | case '-': if(ftune > 0) ftune -= 1; break; 61 | case '=': if(ftune < 31) ftune += 1; break; 62 | case ' ': if(ctune_4pf) { ctune_4pf = 0; } else { ctune_4pf = 1;} break; 63 | } 64 | 65 | printf("ctune_4pf %d; ctune %d; ftune %d\n\r", ctune_4pf, ctune, ftune); 66 | pack_XTAL_CNTL(ctune_4pf, ctune, ftune, IBIAS); 67 | 68 | } 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /tools/rftestrx2pcap.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use Device::SerialPort; 4 | use Term::ReadKey; 5 | use Getopt::Long; 6 | use Time::HiRes qw(usleep gettimeofday); 7 | 8 | use strict; 9 | 10 | my $filename = ''; 11 | my $second = ''; 12 | my $term = '/dev/ttyUSB0'; 13 | my $baud = '115200'; 14 | my $verbose; 15 | 16 | GetOptions ( 17 | 'terminal=s' => \$term, 18 | 'baud=s' => \$baud, 19 | ); 20 | 21 | $| = 1; 22 | 23 | # TODO: add help argument 24 | # print "Example usage: rftestrx2pcap.pl -t /dev/ttyS0 -b 9600\n"; 25 | # exit; 26 | 27 | my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n"; 28 | # next test will die at runtime unless $ob 29 | 30 | $ob->baudrate($baud); 31 | $ob->parity('none'); 32 | $ob->databits(8); 33 | $ob->stopbits(1); 34 | $ob->read_const_time(1000); # 1 second per unfulfilled "read" call 35 | 36 | my $str = ''; 37 | my ($sec, $usec, $len); 38 | my @frame; 39 | 40 | my $magic = 0xa1b2c3d4; 41 | my $major = 2; 42 | my $minor = 4; 43 | my $zone = 0; 44 | my $sig = 0; 45 | my $snaplen = 0xffff; 46 | my $network = 230; # 802.15.4 no FCS 47 | 48 | my $newpacket = 0; 49 | my $len = 0; 50 | my $file_empty = 1; 51 | 52 | print pack('LSSLLLL',($magic,$major,$minor,$zone,$sig,$snaplen,$network)); 53 | 54 | while(1) { 55 | my ($count, $c) = $ob->read(1); 56 | 57 | if (defined($count) && ($count != 0)) { 58 | $str .= $c; 59 | # match if ends in \n or \r and process line 60 | if(($str =~ /\n$/) || 61 | ($str =~ /\r$/)) { 62 | if($str =~ /^rftest-rx --- len 0x(\w\w)/) { 63 | #new packet 64 | ($sec, $usec) = gettimeofday; 65 | $len = hex($1); 66 | print STDERR "rftestline: $sec $usec $len $str"; 67 | $newpacket = 1; 68 | } elsif($str =~ /^\w+/) { 69 | # dataline, write out pcap entry 70 | $str =~ /(.+)/; 71 | chomp $str; 72 | my @data = split(' ',$1); 73 | 74 | # do header if this is a new packet 75 | if($newpacket == 1) { 76 | $newpacket = 0; 77 | print pack('LLLL',($sec,$usec,$len,$len)); 78 | print STDERR "new packet: $sec $usec $len " . ($len) . "\n\r"; 79 | # This header starts the file 80 | if ($file_empty == 1) { 81 | $file_empty = 0; 82 | } 83 | } 84 | # packet payload (don't start the file with a payload) 85 | if ($file_empty == 0) { 86 | print STDERR "dataline: "; 87 | print STDERR $str . "\n\r"; 88 | 89 | foreach my $data (@data) { 90 | print pack ('C',hex($data)); 91 | } 92 | } 93 | 94 | } 95 | $str = ''; 96 | } 97 | } 98 | } 99 | 100 | $ob -> close or die "Close failed: $!\n"; 101 | ReadMode 0; 102 | undef $ob; # closes port AND frees memory in perl 103 | exit; 104 | 105 | -------------------------------------------------------------------------------- /lib/include/packet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef PACKET_H 37 | #define PACKET_H 38 | 39 | /* does not include 2 byte FCS checksum */ 40 | #ifndef MAX_PAYLOAD_SIZE 41 | #define MAX_PAYLOAD_SIZE 125 42 | #endif 43 | 44 | #define PACKET_STATS 0 45 | 46 | struct packet { 47 | uint8_t length; /* does not include FCS checksum */ 48 | volatile struct packet * left; 49 | volatile struct packet * right; 50 | /* offset into data for first byte of the packet payload */ 51 | /* On TX this should be 0 */ 52 | /* On RX this should be 1 since the maca puts the length as the first byte*/ 53 | uint8_t offset; 54 | uint8_t lqi; 55 | uint8_t status; 56 | uint32_t rx_time; 57 | #if PACKET_STATS 58 | uint8_t seen; 59 | uint8_t post_tx; 60 | uint8_t get_free; 61 | uint8_t rxd; 62 | #endif 63 | uint8_t data[MAX_PAYLOAD_SIZE+2+1]; /* +2 for FCS; + 1 since maca returns the length as the first byte */ 64 | }; 65 | typedef struct packet packet_t; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /board/std_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef STDCONF_H 37 | #define STDCONF_H 38 | 39 | #include 40 | 41 | #ifndef vreg_init 42 | #define vreg_init() default_vreg_init() 43 | #endif 44 | 45 | 46 | #ifndef GPIO_LED_RED 47 | #define GPIO_LED_RED GPIO_40 48 | #endif 49 | #ifndef GPIO_LED_GREEN 50 | #define GPIO_LED_GREEN GPIO_41 51 | #endif 52 | #ifndef GPIO_LED_BLUE 53 | #define GPIO_LED_BLUE GPIO_42 54 | #endif 55 | 56 | #ifndef LED_RED 57 | #define LED_RED 40 58 | #endif 59 | #ifndef LED_GREEN 60 | #define LED_GREEN 41 61 | #endif 62 | #ifndef LED_BLUE 63 | #define LED_BLUE 42 64 | #endif 65 | 66 | 67 | /* XTAL TUNE parameters */ 68 | /* recommended defaults from the datasheet */ 69 | 70 | /* Coarse tune: add 4pf */ 71 | #ifndef CTUNE_4PF 72 | #define CTUNE_4PF 1 73 | #endif 74 | /* Coarse tune: add 0-7 pf */ 75 | #ifndef CTUNE 76 | #define CTUNE 5 77 | #endif 78 | /* Fine tune: add FTUNE * 156fF (FTUNE is 4bits) */ 79 | #ifndef FTUNE 80 | #define FTUNE 16 81 | #endif 82 | /* datasheet recommends taht you don't change this */ 83 | #ifndef IBIAS 84 | #define IBIAS 0x1F 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /tests/tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "put.h" 40 | #include "tests.h" 41 | 42 | void print_welcome(char* testname) { 43 | printf("mc1322x-test: %s\n\r",testname); 44 | printf("board: %s\n\r", STR2(BOARD)); 45 | } 46 | 47 | void print_packet(volatile packet_t *p) { 48 | volatile uint8_t i,j,k; 49 | #define PER_ROW 16 50 | if(p) { 51 | printf("len 0x%02x lqi 0x%02x rx_time 0x%08x", p->length, p->lqi, (int)p->rx_time); 52 | for(j=0, k=0; j <= ( (p->length) / PER_ROW ); j++) { 53 | printf("\n\r"); 54 | for(i=0; i < PER_ROW; i++, k++) { 55 | if(k >= p->length ) { 56 | printf("\n\r"); 57 | return; 58 | } 59 | printf("%02x ",p->data[j*PER_ROW + i + p->offset]); 60 | } 61 | } 62 | } 63 | printf("\n\r"); 64 | return; 65 | } 66 | 67 | void dump_regs(uint32_t base, uint32_t len) { 68 | volatile uint32_t i; 69 | 70 | printf("base +0 +4 +8 +c +10 +14 +18 +1c \n\r"); 71 | for (i = 0; i < len; i ++) { 72 | if ((i & 7) == 0) { 73 | printf("%02lx",(uint32_t)(4 * i)); 74 | } 75 | printf(" %08lx",(uint32_t)*mem32(base+(4*i))); 76 | if ((i & 7) == 7) 77 | printf(NL); 78 | } 79 | printf(NL); 80 | } 81 | -------------------------------------------------------------------------------- /lib/include/pwm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef PWM_H 37 | #define PWM_H 38 | 39 | /* Initialize PWM output. 40 | timer_num = 0, 1, 2, 3 41 | rate = desired rate in Hz, 42 | duty = desired duty cycle. 0=always off, 65536=always on. 43 | enable_timer = whether to actually run the timer, versus just configuring it 44 | Returns actual PWM rate. */ 45 | uint32_t pwm_init_ex(int timer_num, uint32_t rate, uint32_t duty, int enable_timer); 46 | 47 | /* Initialize PWM output, helper macros 48 | timer = TMR0, TMR1, TMR2, TMR2 49 | rate = desired rate in Hz, 50 | duty = desired duty cycle. 0=always off, 65536=always on. 51 | Returns actual PWM rate. */ 52 | #define pwm_init(timer,rate,duty) pwm_init_ex(TMR_NUM(timer), rate, duty, 1) 53 | #define pwm_init_stopped(timer,rate,duty) pwm_init_ex(TMR_NUM(timer), rate, duty, 0) 54 | 55 | /* Change duty cycle. Safe to call at any time. 56 | timer_num = 0, 1, 2, 3 57 | duty = desired duty cycle. 0=always off, 65536=always on. 58 | */ 59 | void pwm_duty_ex(int timer_num, uint32_t duty); 60 | 61 | /* Change duty cycle. Safe to call at any time. 62 | timer = TMR0, TMR1, TMR2, TMR2 63 | duty = desired duty cycle. 0=always off, 65536=always on. 64 | */ 65 | #define pwm_duty(timer,duty) pwm_duty_ex(TMR_NUM(timer), duty) 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /tests/pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "config.h" 41 | #include "pwm.h" 42 | #include "rtc.h" 43 | 44 | int main(void) 45 | { 46 | int x = 32768; 47 | 48 | trim_xtal(); 49 | uart_init(UART1, 115200); 50 | rtc_init(); 51 | 52 | printf("pwm test\r\n"); 53 | pwm_init_stopped(TMR0, 12000000, x); 54 | pwm_init_stopped(TMR1, 12000000, x); 55 | TMR0->ENBL |= TMR_ENABLE_BIT(TMR0) | TMR_ENABLE_BIT(TMR1); 56 | 57 | for(;;) { 58 | printf("duty %d = %d%%\r\n", x, ((x * 100 + 32768) / 65536)); 59 | switch(uart1_getc()) { 60 | case '[': x -= 1; break; 61 | case ']': x += 1; break; 62 | case '-': x -= 32; break; 63 | case '=': x += 32; break; 64 | case '_': x -= 512; break; 65 | case '+': x += 512; break; 66 | 67 | case '`': x = 65535 * 0/10; break; 68 | case '1': x = 65535 * 1/10; break; 69 | case '2': x = 65535 * 2/10; break; 70 | case '3': x = 65535 * 3/10; break; 71 | case '4': x = 65535 * 4/10; break; 72 | case '5': x = 65535 * 5/10; break; 73 | case '6': x = 65535 * 6/10; break; 74 | case '7': x = 65535 * 7/10; break; 75 | case '8': x = 65535 * 8/10; break; 76 | case '9': x = 65535 * 9/10; break; 77 | case '0': x = 65535 * 10/10; break; 78 | 79 | } 80 | x &= 65535; 81 | pwm_duty(TMR0, x); 82 | } 83 | } 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/default_lowlevel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | void default_vreg_init(void) { 40 | volatile uint32_t i; 41 | *CRM_SYS_CNTL = 0x00000018; /* set default state */ 42 | *CRM_VREG_CNTL = 0x00000f04; /* bypass the buck */ 43 | for(i=0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */ 44 | // while((((*(volatile uint32_t *)(0x80003018))>>17) & 1) !=1) { continue; } /* wait for the bypass to take */ 45 | *CRM_VREG_CNTL = 0x00000ff8; /* start the regulators */ 46 | } 47 | 48 | void buck_init(void) { 49 | CRM->SYS_CNTLbits.PWR_SOURCE = 1; 50 | CRM->VREG_CNTLbits.BUCK_SYNC_REC_EN = 1; 51 | CRM->VREG_CNTLbits.BUCK_BYPASS_EN = 0; 52 | CRM->VREG_CNTLbits.BUCK_EN = 1; 53 | while(CRM->STATUSbits.VREG_BUCK_RDY == 0) { continue; } 54 | CRM->VREG_CNTLbits.VREG_1P5V_SEL = 3; 55 | CRM->VREG_CNTLbits.VREG_1P5V_EN = 3; 56 | CRM->VREG_CNTLbits.VREG_1P8V_EN = 1; 57 | while(CRM->STATUSbits.VREG_1P5V_RDY == 0) { continue; } 58 | while(CRM->STATUSbits.VREG_1P8V_RDY == 0) { continue; } 59 | } 60 | 61 | void m12_init(void) { 62 | /* configure pullups for low power */ 63 | GPIO->FUNC_SEL.GPIO_63 = 3; 64 | GPIO->PAD_PU_SEL.GPIO_63 = 0; 65 | GPIO->FUNC_SEL.SS = 3; 66 | GPIO->PAD_PU_SEL.SS = 1; 67 | GPIO->FUNC_SEL.VREF2H = 3; 68 | GPIO->PAD_PU_SEL.VREF2H = 1; 69 | GPIO->FUNC_SEL.U1RTS = 3; 70 | GPIO->PAD_PU_SEL.U1RTS = 1; 71 | } 72 | -------------------------------------------------------------------------------- /board/quahogcon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef BOARD_QUAHOG10_H 37 | #define BOARD_QUAHOG10_H 38 | 39 | #define LED_REDBANK_0 (0x1ULL << 2) 40 | #define LED_REDBANK_1 (0x1ULL << 0) 41 | #define LED_REDBANK_2 (0x1ULL << 28) 42 | #define LED_REDBANK_3 (0x1ULL << 25) 43 | #define LED_REDBANK_4 (0x1ULL << 43) 44 | 45 | #define LED_CENTERRED (0x1ULL << 12) 46 | #define LED_CENTERGREEN (0x1ULL << 13) 47 | 48 | #define LED_SIDERED (0x1ULL << 12) 49 | #define LED_SIDEGREEN (0x1ULL << 21) 50 | #define LED_SIDEYELLOW (0x1ULL << 35) 51 | 52 | // Buttons in GPIO mode 53 | #define BUTTON1_OUT (0x1ULL << 23) 54 | #define BUTTON1_IN (0x1ULL << 27) 55 | #define BUTTON2_OUT (0x1ULL << 22) 56 | #define BUTTON2_IN (0x1ULL << 26) 57 | 58 | #define GPIO_LED_RED GPIO_12 59 | #define GPIO_LED_GREEN GPIO_21 60 | #define GPIO_LED_BLUE GPIO_35 61 | 62 | #define LED_RED 12 63 | #define LED_GREEN 21 64 | #define LED_BLUE 35 65 | 66 | /* XTAL TUNE parameters */ 67 | /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ 68 | /* for details about how to make this measurement */ 69 | 70 | /* Econotag also needs an addtional 12pf on board */ 71 | /* Coarse tune: add 4pf */ 72 | #define CTUNE_4PF 1 73 | /* Coarse tune: add 0-15 pf (CTUNE is 4 bits) */ 74 | #define CTUNE 11 75 | /* Fine tune: add FTUNE * 156fF (FTUNE is 5bits) */ 76 | #define FTUNE 7 77 | 78 | #include 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /tests/nvm-read.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | void main(void) { 44 | nvmType_t type=0; 45 | nvmErr_t err; 46 | uint32_t buf[READ_NBYTES/4]; 47 | uint32_t i; 48 | 49 | uart_init(UART1, 115200); 50 | 51 | print_welcome("nvm-read"); 52 | 53 | vreg_init(); 54 | // buck_init(); 55 | while(CRM->STATUSbits.VREG_1P5V_RDY == 0) { continue; } 56 | while(CRM->STATUSbits.VREG_1P8V_RDY == 0) { continue; } 57 | 58 | printf("Sys cntl %08x\n\r", (unsigned int)CRM->SYS_CNTL); 59 | printf("vreg cntl %08x\n\r", (unsigned int)CRM->VREG_CNTL); 60 | printf("crm status %08x\n\r", (unsigned int)CRM->STATUS); 61 | 62 | if(NVM_INTERFACE == gNvmInternalInterface_c) 63 | { 64 | printf("Detecting internal nvm\n\r"); 65 | } else { 66 | printf("Setting up gpio\r\n"); 67 | /* set SPI func */ 68 | GPIO->FUNC_SEL.GPIO_04 = 1; 69 | GPIO->FUNC_SEL.GPIO_05 = 1; 70 | GPIO->FUNC_SEL.GPIO_06 = 1; 71 | GPIO->FUNC_SEL.GPIO_07 = 1; 72 | printf("Detecting external nvm\n\r"); 73 | } 74 | 75 | err = nvm_detect(NVM_INTERFACE, &type); 76 | 77 | printf("nvm_detect returned: 0x%02x type is: 0x%08x\r\n", err, (unsigned int)type); 78 | 79 | nvm_setsvar(0); 80 | 81 | err = nvm_read(NVM_INTERFACE, type, (uint8_t *)buf, READ_ADDR, READ_NBYTES); 82 | printf("nvm_read returned: 0x%02x\r\n", err); 83 | 84 | for(i=0; i<16/4; i++) { 85 | printf("0x%08x\r\n", (unsigned int)buf[i]); 86 | } 87 | 88 | 89 | while(1) {continue;}; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /lib/include/nvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef NVM_H 37 | #define NVM_H 38 | 39 | #include 40 | 41 | typedef enum 42 | { 43 | gNvmType_NoNvm_c, 44 | gNvmType_SST_c, 45 | gNvmType_ST_c, 46 | gNvmType_ATM_c, 47 | gNvmType_Max_c 48 | } nvmType_t; 49 | 50 | 51 | typedef enum 52 | { 53 | gNvmErrNoError_c = 0, 54 | gNvmErrInvalidInterface_c, 55 | gNvmErrInvalidNvmType_c, 56 | gNvmErrInvalidPointer_c, 57 | gNvmErrWriteProtect_c, 58 | gNvmErrVerifyError_c, 59 | gNvmErrAddressSpaceOverflow_c, 60 | gNvmErrBlankCheckError_c, 61 | gNvmErrRestrictedArea_c, 62 | gNvmErrMaxError_c 63 | } nvmErr_t; 64 | 65 | typedef enum 66 | { 67 | gNvmInternalInterface_c, 68 | gNvmExternalInterface_c, 69 | gNvmInterfaceMax_c 70 | } nvmInterface_t; 71 | 72 | /* ROM code seems to be THUMB */ 73 | /* need to be in a THUMB block before calling them */ 74 | extern nvmErr_t (*nvm_detect)(nvmInterface_t nvmInterface,nvmType_t* pNvmType); 75 | extern nvmErr_t (*nvm_read)(nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes); 76 | extern nvmErr_t (*nvm_write)(nvmInterface_t nvmInterface, nvmType_t nvmType ,void *pSrc, uint32_t address, uint32_t numBytes); 77 | /* sector bit field selects which sector to erase */ 78 | /* SST flash has 32 sectors 4096 bytes each */ 79 | /* bit 0 is the first sector, bit 31 is the last */ 80 | extern nvmErr_t (*nvm_erase)(nvmInterface_t nvmInterface, nvmType_t nvmType ,uint32_t sectorBitfield); 81 | extern nvmErr_t (*nvm_verify)(nvmInterface_t nvmInterface, nvmType_t nvmType, void *pSrc, uint32_t address, uint32_t numBytes); 82 | extern void(*nvm_setsvar)(uint32_t zero_for_awesome); 83 | #endif //NVM_H 84 | -------------------------------------------------------------------------------- /tests/rftest-rx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | #define LED LED_GREEN 44 | 45 | void maca_rx_callback(volatile packet_t *p) { 46 | (void)p; 47 | gpio_data_set(1ULL<< LED); 48 | gpio_data_reset(1ULL<< LED); 49 | } 50 | 51 | void main(void) { 52 | volatile packet_t *p; 53 | volatile uint8_t chan; 54 | 55 | gpio_data(0); 56 | 57 | gpio_pad_dir_set( 1ULL << LED ); 58 | /* read from the data register instead of the pad */ 59 | /* this is needed because the led clamps the voltage low */ 60 | gpio_data_sel( 1ULL << LED); 61 | 62 | /* trim the reference osc. to 24MHz */ 63 | trim_xtal(); 64 | 65 | uart_init(UART1, 115200); 66 | 67 | vreg_init(); 68 | 69 | maca_init(); 70 | 71 | /* sets up tx_on, should be a board specific item */ 72 | // *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2)); 73 | gpio_pad_dir_set( 1ULL << 44 ); 74 | 75 | set_power(0x0f); /* 0dbm */ 76 | chan = 0; 77 | set_channel(chan); /* channel 11 */ 78 | 79 | print_welcome("rftest-rx"); 80 | while(1) { 81 | 82 | /* call check_maca() periodically --- this works around */ 83 | /* a few lockup conditions */ 84 | check_maca(); 85 | 86 | if((p = rx_packet())) { 87 | /* print and free the packet */ 88 | printf("rftest-rx --- "); 89 | print_packet(p); 90 | free_packet(p); 91 | } 92 | 93 | if(uart1_can_get()) { 94 | uart1_getc(); 95 | chan++; 96 | if(chan >= 16) { chan = 0; } 97 | set_channel(chan); 98 | printf("channel: %d\n\r", chan); 99 | } 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /tests/nvm-write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | void main(void) { 44 | nvmType_t type=0; 45 | nvmErr_t err; 46 | uint32_t buf[WRITE_NBYTES/4]; 47 | uint32_t i; 48 | 49 | uart_init(UART1, 115200); 50 | 51 | print_welcome("nvm-write"); 52 | 53 | vreg_init(); 54 | 55 | if(NVM_INTERFACE == gNvmInternalInterface_c) 56 | { 57 | printf("Detecting internal nvm\n\r"); 58 | } else { 59 | printf("Setting up gpio\r\n"); 60 | /* set SPI func */ 61 | GPIO->FUNC_SEL.GPIO_04 = 1; 62 | GPIO->FUNC_SEL.GPIO_05 = 1; 63 | GPIO->FUNC_SEL.GPIO_06 = 1; 64 | GPIO->FUNC_SEL.GPIO_07 = 1; 65 | printf("Detecting external nvm\n\r"); 66 | } 67 | 68 | err = nvm_detect(NVM_INTERFACE, &type); 69 | 70 | printf("nvm_detect returned: 0x%02x type is: 0x%08x\r\n", err, (unsigned int)type); 71 | 72 | buf[0] = WRITEVAL0; 73 | buf[1] = WRITEVAL1; 74 | 75 | err = nvm_erase(NVM_INTERFACE, type, 1 << WRITE_ADDR/4096); 76 | printf("nvm_erase returned: 0x%02x\r\n", err); 77 | 78 | err = nvm_write(NVM_INTERFACE, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES); 79 | printf("nvm_write returned: 0x%02x\r\n", err); 80 | 81 | printf("writing\n\r"); 82 | for(i=0; i 3 | 4 | import sys,os,time 5 | from struct import * 6 | import re 7 | import serial 8 | 9 | if len(sys.argv) < 3: 10 | sys.stderr.write( "Usage: %s tty channel [outfile]\n" %(sys.argv[0])) 11 | sys.stderr.write( " channel = 11-26\n") 12 | sys.exit(2) 13 | 14 | # change the channel 15 | # rftest-rx increments it's channel everytime you send a character and returns "channel: num" 16 | # send a character until we get to the right channel 17 | 18 | try: 19 | serport = serial.Serial(sys.argv[1], 115200, timeout=1) 20 | except IOError: 21 | print "error opening port" 22 | sys.exit(2) 23 | 24 | chan = '' 25 | while chan != int(sys.argv[2]) - 11: 26 | serport.write(' ') 27 | chanstr = '' 28 | while 1: 29 | chanstr += serport.read(1) 30 | m = re.match(".*channel: (\w+)\s+", chanstr) 31 | if m is not None: 32 | chan = int(m.group(1)) 33 | break 34 | 35 | try: 36 | sys.stderr.write('writing to file %s \n' % (sys.argv[3])) 37 | outfile = open(sys.argv[3], 'w+b') 38 | except IndexError: 39 | outfile = sys.stdout 40 | 41 | sys.stderr.write("RX: 0\r") 42 | 43 | ### PCAP setup 44 | MAGIC = 0xa1b2c3d4; 45 | MAJOR = 2; 46 | MINOR = 4; 47 | ZONE = 0; 48 | SIG = 0; 49 | SNAPLEN = 0xffff; 50 | NETWORK = 230; # 802.15.4 no FCS 51 | 52 | # output overall PCAP header 53 | outfile.write(pack(' and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include "tmr.h" 39 | 40 | /* Initialize timer. This just counts and interrupts, doesn't drive an output. 41 | timer_num = 0, 1, 2, 3 42 | rate = desired rate in Hz, 43 | enable_int = whether to enable an interrupt on every cycle 44 | Returns actual timer rate. */ 45 | uint32_t timer_setup_ex(int timer_num, uint32_t rate, int enable_int) 46 | { 47 | uint32_t actual_rate; 48 | volatile struct TMR_struct *timer = TMR_ADDR(timer_num); 49 | int log_divisor = 0; 50 | uint32_t period; 51 | 52 | /* Turn timer off */ 53 | TMR0->ENBL &= ~(1 << timer_num); 54 | 55 | /* Calculate optimal rate */ 56 | for (log_divisor = 0; log_divisor < 8; log_divisor++) 57 | { 58 | int denom = (rate * (1 << log_divisor)); 59 | period = (REF_OSC + denom/2) / denom; 60 | if (period <= 65535) 61 | break; 62 | } 63 | if (log_divisor >= 8) 64 | { 65 | period = 65535; 66 | log_divisor = 7; 67 | } 68 | 69 | if (period < 2) period = 2; 70 | 71 | actual_rate = REF_OSC / (period * (1 << log_divisor)); 72 | 73 | /* Set up timer */ 74 | 75 | timer->LOAD = 0; 76 | timer->CMPLD1 = (period - 1); 77 | timer->COMP1 = timer->CMPLD1; 78 | timer->CNTR = timer->LOAD; 79 | timer->SCTRL = 0; 80 | timer->CSCTRLbits = (struct TMR_CSCTRL) { 81 | .CL1 = 0x01, // Reload COMP1 when COMP1 matches 82 | }; 83 | timer->CTRLbits = (struct TMR_CTRL) { 84 | .COUNT_MODE = 1, // Count rising edge of primary source 85 | .PRIMARY_CNT_SOURCE = 8 + log_divisor, // Peripheral clock divided by (divisor) 86 | .LENGTH = 1, // At compare, reset to LOAD 87 | }; 88 | 89 | TMR0->ENBL |= (1 << timer_num); 90 | 91 | if (enable_int) { 92 | enable_irq(TMR); 93 | timer->SCTRLbits.TCFIE = 1; 94 | } 95 | 96 | return actual_rate; 97 | } 98 | -------------------------------------------------------------------------------- /lib/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | inline void gpio_pad_dir(volatile uint64_t data) 40 | { 41 | *GPIO_PAD_DIR0 = (data & 0xffffffff); 42 | *GPIO_PAD_DIR1 = (data >> 32); 43 | } 44 | 45 | inline void gpio_data(volatile uint64_t data) 46 | { 47 | *GPIO_DATA0 = (data & 0xffffffff); 48 | *GPIO_DATA1 = (data >> 32); 49 | } 50 | 51 | inline uint64_t gpio_data_get(volatile uint64_t bits) { 52 | uint64_t rdata = 0; 53 | 54 | rdata = *GPIO_DATA0 & (bits & 0xffffffff); 55 | rdata |= (*GPIO_DATA1 & (bits >> 32)) << 32; 56 | 57 | return rdata; 58 | } 59 | 60 | inline void gpio_pad_pu_en(volatile uint64_t data) 61 | { 62 | *GPIO_PAD_PU_EN0 = (data & 0xffffffff); 63 | *GPIO_PAD_PU_EN1 = (data >> 32); 64 | } 65 | 66 | inline void gpio_data_sel(volatile uint64_t data) 67 | { 68 | *GPIO_DATA_SEL0 = (data & 0xffffffff); 69 | *GPIO_DATA_SEL1 = (data >> 32); 70 | } 71 | 72 | inline void gpio_pad_pu_sel(volatile uint64_t data) 73 | { 74 | *GPIO_PAD_PU_SEL0 = (data & 0xffffffff); 75 | *GPIO_PAD_PU_SEL1 = (data >> 32); 76 | } 77 | 78 | inline void gpio_data_set(volatile uint64_t data) 79 | { 80 | *GPIO_DATA_SET0 = (data & 0xffffffff); 81 | *GPIO_DATA_SET1 = (data >> 32); 82 | } 83 | 84 | inline void gpio_data_reset(volatile uint64_t data) 85 | { 86 | *GPIO_DATA_RESET0 = (data & 0xffffffff); 87 | *GPIO_DATA_RESET1 = (data >> 32); 88 | } 89 | 90 | inline void gpio_pad_dir_set(volatile uint64_t data) 91 | { 92 | *GPIO_PAD_DIR_SET0 = (data & 0xffffffff); 93 | *GPIO_PAD_DIR_SET1 = (data >> 32); 94 | } 95 | 96 | inline void gpio_pad_dir_reset(volatile uint64_t data) 97 | { 98 | *GPIO_PAD_DIR_RESET0 = (data & 0xffffffff); 99 | *GPIO_PAD_DIR_RESET1 = (data >> 32); 100 | } 101 | -------------------------------------------------------------------------------- /tests/autoack-rx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | #define LED LED_GREEN 44 | 45 | void maca_rx_callback(volatile packet_t *p) { 46 | (void)p; 47 | gpio_data_set(1ULL<< LED); 48 | gpio_data_reset(1ULL<< LED); 49 | } 50 | 51 | void main(void) { 52 | volatile packet_t *p; 53 | volatile uint8_t t=20; 54 | uint8_t chan; 55 | char c; 56 | 57 | gpio_data(0); 58 | 59 | gpio_pad_dir_set( 1ULL << LED ); 60 | /* read from the data register instead of the pad */ 61 | /* this is needed because the led clamps the voltage low */ 62 | gpio_data_sel( 1ULL << LED); 63 | 64 | /* trim the reference osc. to 24MHz */ 65 | trim_xtal(); 66 | 67 | uart_init(UART1, 115200); 68 | 69 | vreg_init(); 70 | 71 | maca_init(); 72 | 73 | /* sets up tx_on, should be a board specific item */ 74 | *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2)); 75 | gpio_pad_dir_set( 1ULL << 44 ); 76 | 77 | set_power(0x0f); /* 0dbm */ 78 | chan = 0; 79 | set_channel(chan); /* channel 11 */ 80 | 81 | *MACA_MACPANID = 0xaaaa; 82 | *MACA_MAC16ADDR = 0x1111; 83 | *MACA_TXACKDELAY = 68; /* 68 puts the tx ack at about the correct spot */ 84 | set_prm_mode(AUTOACK); 85 | 86 | print_welcome("rftest-rx"); 87 | while(1) { 88 | 89 | /* call check_maca() periodically --- this works around */ 90 | /* a few lockup conditions */ 91 | check_maca(); 92 | 93 | if((p = rx_packet())) { 94 | /* print and free the packet */ 95 | printf("autoack-rx --- "); 96 | print_packet(p); 97 | free_packet(p); 98 | } 99 | 100 | if(uart1_can_get()) { 101 | c = uart1_getc(); 102 | if(c == 'z') t++; 103 | if(c == 'x') t--; 104 | *MACA_TXACKDELAY = t; 105 | printf("tx ack delay: %d\n\r", t); 106 | } 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /lib/include/asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #ifndef ASM_H 37 | #define ASM_H 38 | 39 | /* Structure-based register definitions */ 40 | /* Example use: 41 | ASM->KEY0 = 0xaabbccdd; 42 | ASM->CONTROL1bits = (struct ASM_CONTROL1) { 43 | .MASK_IRQ = 1, 44 | .CBC = 1, 45 | }; 46 | ASM->CONTROL1bits.SELF_TEST = 1; 47 | */ 48 | 49 | struct ASM_struct { 50 | uint32_t KEY0; 51 | uint32_t KEY1; 52 | uint32_t KEY2; 53 | uint32_t KEY3; 54 | uint32_t DATA0; 55 | uint32_t DATA1; 56 | uint32_t DATA2; 57 | uint32_t DATA3; 58 | uint32_t CTR0; 59 | uint32_t CTR1; 60 | uint32_t CTR2; 61 | uint32_t CTR3; 62 | uint32_t CTR0_RESULT; 63 | uint32_t CTR1_RESULT; 64 | uint32_t CTR2_RESULT; 65 | uint32_t CTR3_RESULT; 66 | uint32_t CBC0_RESULT; 67 | uint32_t CBC1_RESULT; 68 | uint32_t CBC2_RESULT; 69 | uint32_t CBC3_RESULT; 70 | 71 | union { 72 | uint32_t CONTROL0; 73 | struct ASM_CONTROL0 { 74 | uint32_t :24; 75 | uint32_t START:1; 76 | uint32_t CLEAR:1; 77 | uint32_t LOAD_MAC:1; 78 | uint32_t :4; 79 | uint32_t CLEAR_IRQ:1; 80 | } CONTROL0bits; 81 | }; 82 | union { 83 | uint32_t CONTROL1; 84 | struct ASM_CONTROL1 { 85 | uint32_t ON:1; 86 | uint32_t NORMAL_MODE:1; 87 | uint32_t BYPASS:1; 88 | uint32_t :21; 89 | uint32_t CBC:1; 90 | uint32_t CTR:1; 91 | uint32_t SELF_TEST:1; 92 | uint32_t :4; 93 | uint32_t MASK_IRQ:1; 94 | } CONTROL1bits; 95 | }; 96 | union { 97 | uint32_t STATUS; 98 | struct ASM_STATUS { 99 | uint32_t :24; 100 | uint32_t DONE:1; 101 | uint32_t TEST_PASS:1; 102 | uint32_t :6; 103 | } STATUSbits; 104 | }; 105 | 106 | uint32_t reserved; 107 | 108 | uint32_t MAC0; 109 | uint32_t MAC1; 110 | uint32_t MAC2; 111 | uint32_t MAC3; 112 | }; 113 | 114 | static volatile struct ASM_struct * const ASM = (void *) (0x80008000); 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /tests/tmr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "tests.h" 40 | #include "config.h" 41 | 42 | #define LED LED_YELLOW 43 | 44 | void main(void) { 45 | 46 | /* pin direction */ 47 | gpio_pad_dir_set(LED_WHITE); 48 | /* all LEDs off */ 49 | gpio_data_reset(LED_WHITE); 50 | 51 | /* timer setup */ 52 | /* CTRL */ 53 | #define COUNT_MODE 1 /* use rising edge of primary source */ 54 | #define PRIME_SRC 0xf /* Perip. clock with 128 prescale (for 24Mhz = 187500Hz)*/ 55 | #define SEC_SRC 0 /* don't need this */ 56 | #define ONCE 0 /* keep counting */ 57 | #define LEN 1 /* count until compare then reload with value in LOAD */ 58 | #define DIR 0 /* count up */ 59 | #define CO_INIT 0 /* other counters cannot force a re-initialization of this counter */ 60 | #define OUT_MODE 0 /* OFLAG is asserted while counter is active */ 61 | 62 | *TMR_ENBL = 0; /* tmrs reset to enabled */ 63 | *TMR0_SCTRL = 0; 64 | *TMR0_LOAD = 0; /* reload to zero */ 65 | *TMR0_COMP_UP = 18750; /* trigger a reload at the end */ 66 | *TMR0_CMPLD1 = 18750; /* compare 1 triggered reload level, 10HZ maybe? */ 67 | *TMR0_CNTR = 0; /* reset count register */ 68 | *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE); 69 | *TMR_ENBL = 0xf; /* enable all the timers --- why not? */ 70 | 71 | while(1) { 72 | 73 | /* blink on */ 74 | gpio_data_set(LED); 75 | 76 | while((*TMR0_SCTRL >> 15) == 0) { continue; } 77 | *TMR0_SCTRL = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */ 78 | 79 | /* blink off */ 80 | gpio_data_reset(LED); 81 | 82 | while((*TMR0_SCTRL >> 15) == 0) { continue; } 83 | *TMR0_SCTRL = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */ 84 | 85 | }; 86 | } 87 | -------------------------------------------------------------------------------- /tests/rftest-tx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | #define LED LED_RED 44 | 45 | /* 802.15.4 PSDU is 127 MAX */ 46 | /* 2 bytes are the FCS */ 47 | /* therefore 125 is the max payload length */ 48 | #define PAYLOAD_LEN 16 49 | #define DELAY 100000 50 | 51 | void fill_packet(volatile packet_t *p) { 52 | static volatile uint8_t count=0; 53 | volatile uint8_t i; 54 | p->length = PAYLOAD_LEN; 55 | p->offset = 0; 56 | for(i=0; idata[i] = count++; 58 | } 59 | 60 | /* acks get treated differently, even in promiscuous mode */ 61 | /* setting the third bit makes sure that we never send an ack */ 62 | /* or any valid 802.15.4-2006 packet */ 63 | p->data[0] |= (1 << 3); 64 | } 65 | 66 | void main(void) { 67 | volatile uint32_t i; 68 | volatile packet_t *p; 69 | 70 | /* trim the reference osc. to 24MHz */ 71 | trim_xtal(); 72 | 73 | uart_init(UART1, 115200); 74 | 75 | vreg_init(); 76 | 77 | maca_init(); 78 | 79 | set_channel(0); /* channel 11 */ 80 | // set_power(0x0f); /* 0xf = -1dbm, see 3-22 */ 81 | // set_power(0x11); /* 0x11 = 3dbm, see 3-22 */ 82 | set_power(0x12); /* 0x12 is the highest, not documented */ 83 | 84 | /* sets up tx_on, should be a board specific item */ 85 | *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2)); 86 | gpio_pad_dir_set( 1ULL << 44 ); 87 | 88 | print_welcome("rftest-tx"); 89 | 90 | while(1) { 91 | 92 | /* call check_maca() periodically --- this works around */ 93 | /* a few lockup conditions */ 94 | check_maca(); 95 | 96 | while((p = rx_packet())) { 97 | if(p) free_packet(p); 98 | } 99 | 100 | p = get_free_packet(); 101 | if(p) { 102 | fill_packet(p); 103 | 104 | printf("rftest-tx --- "); 105 | print_packet(p); 106 | 107 | tx_packet(p); 108 | 109 | for(i=0; i and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | 38 | static void (*tmr_isr_funcs[4])(void) = { 39 | tmr0_isr, 40 | tmr1_isr, 41 | tmr2_isr, 42 | tmr3_isr 43 | }; 44 | 45 | void irq_register_timer_handler(int timer, void (*isr)(void)) 46 | { 47 | tmr_isr_funcs[timer] = isr; 48 | } 49 | 50 | 51 | __attribute__ ((section (".irq"))) 52 | __attribute__ ((interrupt("IRQ"))) 53 | void irq(void) 54 | { 55 | uint32_t pending; 56 | 57 | while ((pending = *NIPEND)) { 58 | 59 | if(bit_is_set(pending, INT_NUM_TMR)) { 60 | /* dispatch to individual timer isrs if they exist */ 61 | /* timer isrs are responsible for determining if they 62 | * caused an interrupt */ 63 | /* and clearing their own interrupt flags */ 64 | if (tmr_isr_funcs[0] != 0) { (tmr_isr_funcs[0])(); } 65 | if (tmr_isr_funcs[1] != 0) { (tmr_isr_funcs[1])(); } 66 | if (tmr_isr_funcs[2] != 0) { (tmr_isr_funcs[2])(); } 67 | if (tmr_isr_funcs[3] != 0) { (tmr_isr_funcs[3])(); } 68 | } 69 | 70 | if(bit_is_set(pending, INT_NUM_MACA)) { 71 | if(maca_isr != 0) { maca_isr(); } 72 | } 73 | if(bit_is_set(pending, INT_NUM_UART1)) { 74 | if(uart1_isr != 0) { uart1_isr(); } 75 | } 76 | if(bit_is_set(pending, INT_NUM_UART2)) { 77 | if(uart2_isr != 0) { uart2_isr(); } 78 | } 79 | if(bit_is_set(pending, INT_NUM_CRM)) { 80 | if(rtc_wu_evt() && (rtc_isr != 0)) { rtc_isr(); } 81 | if(kbi_evnt(4) && (kbi4_isr != 0)) { kbi4_isr(); } 82 | if(kbi_evnt(5) && (kbi5_isr != 0)) { kbi5_isr(); } 83 | if(kbi_evnt(6) && (kbi6_isr != 0)) { kbi6_isr(); } 84 | if(kbi_evnt(7) && (kbi7_isr != 0)) { kbi7_isr(); } 85 | 86 | if (CRM->STATUSbits.CAL_DONE && CRM->CAL_CNTLbits.CAL_IEN && cal_isr) 87 | { 88 | CRM->STATUSbits.CAL_DONE = 0; 89 | cal_isr(); 90 | } 91 | } 92 | if(bit_is_set(pending, INT_NUM_ASM)) { 93 | if(asm_isr != 0) { asm_isr(); } 94 | } 95 | if (bit_is_set(pending, INT_NUM_I2C)) { 96 | if (i2c_isr != 0) { i2c_isr(); } 97 | } 98 | 99 | *INTFRC = 0; /* stop forcing interrupts */ 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /tests/tmr-ints.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "tests.h" 40 | #include "config.h" 41 | 42 | volatile uint8_t led; 43 | 44 | #define LED LED_PURPLE 45 | #define led_init() do { gpio_pad_dir_set(LED_WHITE); gpio_data_reset(LED_WHITE); } while(0); 46 | #define led_on() do { led = 1; gpio_data_set(LED); } while(0); 47 | #define led_off() do { led = 0; gpio_data_reset(LED); } while(0); 48 | 49 | void toggle_led(void) { 50 | if(0 == led) { 51 | led_on(); 52 | led = 1; 53 | 54 | } else { 55 | led_off(); 56 | } 57 | } 58 | 59 | void tmr0_isr(void) { 60 | 61 | toggle_led(); 62 | *TMR0_SCTRL = 0; 63 | *TMR0_CSCTRL = 0x0040; /* clear compare flag */ 64 | 65 | } 66 | 67 | 68 | void main(void) { 69 | 70 | /* pin direction */ 71 | led_init(); 72 | 73 | /* timer setup */ 74 | /* CTRL */ 75 | #define COUNT_MODE 1 /* use rising edge of primary source */ 76 | #define PRIME_SRC 0xf /* Perip. clock with 128 prescale (for 24Mhz = 187500Hz)*/ 77 | #define SEC_SRC 0 /* don't need this */ 78 | #define ONCE 0 /* keep counting */ 79 | #define LEN 1 /* count until compare then reload with value in LOAD */ 80 | #define DIR 0 /* count up */ 81 | #define CO_INIT 0 /* other counters cannot force a re-initialization of this counter */ 82 | #define OUT_MODE 0 /* OFLAG is asserted while counter is active */ 83 | 84 | *TMR_ENBL = 0; /* tmrs reset to enabled */ 85 | *TMR0_SCTRL = 0; 86 | *TMR0_CSCTRL = 0x0040; 87 | *TMR0_LOAD = 0; /* reload to zero */ 88 | *TMR0_COMP_UP = 18750; /* trigger a reload at the end */ 89 | *TMR0_CMPLD1 = 18750; /* compare 1 triggered reload level, 10HZ maybe? */ 90 | *TMR0_CNTR = 0; /* reset count register */ 91 | *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE); 92 | *TMR_ENBL = 0xf; /* enable all the timers --- why not? */ 93 | 94 | led_on(); 95 | 96 | enable_irq(TMR); 97 | 98 | while(1) { 99 | /* sit here and let the interrupts do the work */ 100 | continue; 101 | }; 102 | } 103 | -------------------------------------------------------------------------------- /tests/printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include "tests.h" 43 | #include "config.h" 44 | 45 | #define print_size(x) do { \ 46 | printf("sizeof("); \ 47 | printf(#x); \ 48 | printf("): %d\n", sizeof(x)); \ 49 | } while(0) 50 | 51 | #if (__linux__) 52 | FILE *stderr; 53 | 54 | void __assert_fail(void) { 55 | return; 56 | } 57 | 58 | int fputs(const char *s, FILE *stream) { 59 | return 0; 60 | } 61 | 62 | size_t fwrite(const void *ptr, size_t size, size_t nmemb, 63 | FILE *stream) { 64 | return 0; 65 | } 66 | #endif 67 | 68 | 69 | 70 | int main(void) 71 | { 72 | char *ptr = "Hello world!"; 73 | char *np = 0; 74 | int i = 5; 75 | unsigned int bs = sizeof(int)*8; 76 | int mi; 77 | // char buf[80]; 78 | 79 | uart_init(UART1, 115200); 80 | 81 | print_size(int8_t); 82 | print_size(uint8_t); 83 | print_size(int16_t); 84 | print_size(uint16_t); 85 | print_size(int32_t); 86 | print_size(uint32_t); 87 | print_size(int64_t); 88 | print_size(uint64_t); 89 | 90 | mi = (1 << (bs-1)) + 1; 91 | printf("%s\n", ptr); 92 | printf("printf test\n"); 93 | printf("%s is null pointer\n", np); 94 | printf("%d = 5\n", i); 95 | printf("%d = - max int\n", mi); 96 | printf("char %c = 'a'\n", 'a'); 97 | printf("hex %x = ff\n", 0xff); 98 | printf("hex %02x = 00\n", 0); 99 | printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); 100 | printf("%d %s(s)", 0, "message"); 101 | printf("\n"); 102 | printf("%d %s(s) with %%\n", 0, "message"); 103 | 104 | printf("sqrt(5) * 100 = %d\n", (int) (sqrt(5)*100)); 105 | 106 | // sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf); 107 | // sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf); 108 | // sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf); 109 | // sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf); 110 | // sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf); 111 | // sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf); 112 | // sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf); 113 | // sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf); 114 | 115 | while(1) { continue; } 116 | } 117 | 118 | /* 119 | * this should display (on 32bit int machine) : 120 | * 121 | * Hello world! 122 | * printf test 123 | * (null) is null pointer 124 | * 5 = 5 125 | * -2147483647 = - max int 126 | * char a = 'a' 127 | * hex ff = ff 128 | * hex 00 = 00 129 | * signed -3 = unsigned 4294967293 = hex fffffffd 130 | * 0 message(s) 131 | * 0 message(s) with % 132 | * justif: "left " 133 | * justif: " right" 134 | * 3: 0003 zero padded 135 | * 3: 3 left justif. 136 | * 3: 3 right justif. 137 | * -3: -003 zero padded 138 | * -3: -3 left justif. 139 | * -3: -3 right justif. 140 | */ 141 | -------------------------------------------------------------------------------- /Makefile.include: -------------------------------------------------------------------------------- 1 | # Hey Emacs, this is a -*- makefile -*- 2 | 3 | # Set up a default target in case the user didn't already have one. 4 | # "all" means to build .bin for all defined targets for the currently-defined board 5 | all: $(addsuffix _$(BOARD).bin, $(TARGETS) $(TARGETS_WITH_ROM_VARS)) 6 | .PHONY: all 7 | 8 | # Pretty print output. Use "make Q=" to see full commands 9 | Q ?= @ 10 | define pretty 11 | @printf "%8s %s\n" "$1" "$2" 12 | endef 13 | 14 | # Don't delete intermediate targets 15 | .SECONDARY: 16 | 17 | ##### 18 | # Tools and flags 19 | 20 | # Set up cross compiler and toolchain definitions. 21 | CROSS_COMPILE ?= arm-none-eabi- 22 | AS = $(CROSS_COMPILE)as 23 | LD = $(CROSS_COMPILE)ld 24 | CC = $(CROSS_COMPILE)gcc 25 | CPP = $(CC) -E 26 | AR = $(CROSS_COMPILE)ar 27 | NM = $(CROSS_COMPILE)nm 28 | STRIP = $(CROSS_COMPILE)strip 29 | OBJCOPY = $(CROSS_COMPILE)objcopy 30 | OBJDUMP = $(CROSS_COMPILE)objdump 31 | RANLIB = $(CROSS_COMPILE)ranlib 32 | 33 | # Build CFLAGS and prepend it to user-supplied CFLAGS 34 | CFLAGS_PLAT ?= -march=armv4t -mtune=arm7tdmi-s -mlong-calls -msoft-float \ 35 | -mthumb-interwork -fno-strict-aliasing -fno-common -ffixed-r8 \ 36 | -ffunction-sections -ffreestanding -fno-builtin -nodefaultlibs 37 | CFLAGS_WARN ?= -Wcast-align -Wall -Wstrict-prototypes -Wextra 38 | CFLAGS_OPT ?= -Os 39 | CFLAGS_DEBUG ?= -g -DDEBUG -Werror 40 | CFLAGS_MISC ?= -pipe 41 | CFLAGS := $(CFLAGS_PLAT) $(CFLAGS_WARN) $(CFLAGS_OPT) $(CFLAGS_DEBUG) $(CFLAGS_MISC) $(CFLAGS) 42 | 43 | # Thumb flags, used for building most objects 44 | CFLAGS_THUMB ?= -mthumb -mcallee-super-interworking 45 | 46 | # Linker flags 47 | LINKERSCRIPT ?= $(MC1322X)/mc1322x.lds 48 | LDFLAGS ?= -T $(LINKERSCRIPT) -nostartfiles -static -export-dynamic -u_start -Wl,-Map=$(@:.elf=.map) 49 | 50 | # Assembler flags 51 | AFLAGS ?= -Wa,-gstabs $(CFLAGS) 52 | 53 | # Misc tool options 54 | OBJCOPYFLAGS ?= --gap-fill=0xff 55 | ARFLAGS = cr 56 | 57 | ##### 58 | 59 | include $(MC1322X)/board/Makefile.board 60 | include $(MC1322X)/lib/Makefile.lib 61 | include $(MC1322X)/src/Makefile.src 62 | 63 | ##### 64 | # Rule for building ELF files. We use both a wildcard rule that links 65 | # $(SRCLIB) as well as target-specific rules that link $(SRCLIB_ROMVARS) 66 | 67 | # Normal targets (wildcard rule): 68 | %_$(BOARD).elf: $(OBJDIR)/%.o $(TARGET_OBJ) $(SRCLIB) 69 | $(call pretty,LINK,$@) 70 | $Q$(CC) $(LDFLAGS) -o $@ -Wl,--start-group $^ -lm -Wl,--end-group 71 | 72 | # Targets that need space for rom variables: 73 | define build_elf_rule 74 | $(1)_$$(BOARD).elf: $$(OBJDIR)/$(1).o $$(TARGET_OBJ) $$(SRCLIB_ROMVARS) 75 | $$(call pretty,LINK (romvars),$$@) 76 | $$Q$$(CC) $$(LDFLAGS) -o $$@ -Wl,--start-group $$^ -lm -Wl,--end-group 77 | endef 78 | $(foreach t, $(TARGETS_WITH_ROM_VARS), $(eval $(call build_elf_rule,$(t)))) 79 | 80 | 81 | # Generic rules 82 | %.srec: %.elf 83 | $(call pretty,OBJCOPY,$@) 84 | $Q$(OBJCOPY) $(OBJCOPYFLAGS) -O srec $< $@ 85 | 86 | %.ihex: %.elf 87 | $(call pretty,OBJCOPY,$@) 88 | $Q$(OBJCOPY) $(OBJCOPYFLAGS) -O ihex $< $@ 89 | 90 | %.bin: %.elf 91 | $(call pretty,OBJCOPY,$@) 92 | $Q$(OBJCOPY) $(OBJCOPYFLAGS) -O binary $< $@ 93 | 94 | %.dis: %.elf 95 | $(call pretty,OBJDUMP,$@) 96 | $Q$(OBJDUMP) -Sd $< > $@ || rm -f $@ 97 | 98 | %.dis: %.o 99 | $(call pretty,OBJDUMP,$@) 100 | $Q$(OBJDUMP) -d $< > $@ || rm -f $@ 101 | 102 | %.o: %.c $(FORCE_C_DEPENDS) 103 | $(call pretty,CC,$@) 104 | $Q$(CC) $(CFLAGS) $(CFLAGS_THUMB) -MMD -c -o $@ $< 105 | @$(FINALIZE_DEPENDENCY) 106 | 107 | %.o: %.S 108 | $(call pretty,AS,$@) 109 | $Q$(CC) $(AFLAGS) -MMD -c -o $@ $< 110 | @$(FINALIZE_DEPENDENCY) 111 | 112 | # Fix the dependencies generated for a particular target .o 113 | # See http://make.paulandlesley.org/autodep.html#advanced 114 | define FINALIZE_DEPENDENCY 115 | cp $(@:.o=.d) $(@:.o=.$$$$); \ 116 | sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 117 | -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \ 118 | rm -f $(@:.o=.$$$$) 119 | endef 120 | 121 | clean:: 122 | rm -f *.{o,d,a,bin,elf,ihex,srec,dis,map,bak} *~ 123 | 124 | .PHONY: clean 125 | 126 | ############################## 127 | 128 | # If no single board was specified, invoke make recursively for each 129 | # board in $(BOARDS), or $(ALL_BOARDS) if that wasn't specified either. 130 | # This is at the end so that it can override all other targets. 131 | ifndef BOARD 132 | ifneq ($(MAKECMDGOALS),clean) 133 | .DEFAULT_GOAL=mc1322x-default 134 | BOARDS ?= $(ALL_BOARDS) 135 | define build_board 136 | @echo "Building for board: $(1)" 137 | @$(MAKE) --no-print-directory BOARD=$(1) $(2) 138 | 139 | endef 140 | $(MAKECMDGOALS): 141 | $(foreach b, $(BOARDS), $(call build_board,$(b),$@)) 142 | mc1322x-default: 143 | $(foreach b, $(BOARDS), $(call build_board,$(b),)) 144 | endif 145 | endif 146 | -------------------------------------------------------------------------------- /lib/include/i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011, Hedde Bosman 3 | * 4 | * I2C communication device drivers for mc1322x 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * $Id$ 31 | */ 32 | 33 | #ifndef I2C_H 34 | #define I2C_H 35 | 36 | #include 37 | #include "isr.h" 38 | #include "gpio.h" 39 | 40 | #define I2C_NON_BLOCKING 1 41 | 42 | /* The I2C Interrupt Service Routine */ 43 | void i2c_isr (void); 44 | 45 | /* Enable the I2C module */ 46 | void i2c_enable(void); 47 | 48 | /* Disable the I2C module */ 49 | void i2c_disable(void); 50 | 51 | 52 | 53 | /* Returns 1 if the I2C bus is active (we or some other device are transferring data) */ 54 | uint8_t i2c_busy(void); 55 | 56 | /* Returns 1 if our data is sent or received */ 57 | uint8_t i2c_transferred(void); // indicates success of data last transfer (send or receive) 58 | 59 | 60 | 61 | /* start receiving data from 'slave_address' of length 'byte_ctr' and store it in 'rx_buf' 62 | * @parameter slave_addr 7bits (and will be padded with the 'receive bit') 63 | * @parameter byte_ctr the number of bytes expected to be received 64 | * @parameter rx_buf the buffer in which the received bytes will be stored. 65 | * 66 | * IFDEF I2C_NON_BLOCKING THEN THIS FUNCTION RETURNS IMMEDIATLY BUT THE TRANSFER WILL ONLY 67 | * BE COMPLETE WHEN i2c_transferred IS 1 68 | */ 69 | void i2c_receiveinit( uint8_t slave_address, uint8_t byte_ctr, uint8_t *rx_buf); 70 | 71 | /* start sending data to 'slave_address' of length 'byte_ctr' found in the buffer 'rx_buf' 72 | * @parameter slave_addr 7bits (and will be padded with the 'send bit') 73 | * @parameter byte_ctr the number of bytes to be sent 74 | * @parameter tx_buf the buffer in which the bytes to be sent are stored 75 | * 76 | * IFDEF I2C_NON_BLOCKING THEN THIS FUNCTION RETURNS IMMEDIATLY BUT THE TRANSFER WILL ONLY 77 | * BE COMPLETE WHEN i2c_transferred IS 1 78 | */ 79 | void i2c_transmitinit(uint8_t slave_address, uint8_t byte_ctr, uint8_t *tx_buf); 80 | 81 | 82 | #ifndef I2C_NON_BLOCKING 83 | #define I2C_NON_BLOCKING 1 84 | #endif 85 | 86 | #if I2C_NON_BLOCKING 87 | uint8_t i2c_receive(void); 88 | void i2c_transmit(void); 89 | #endif 90 | 91 | // TODO: see if this is better fit in platform definition 92 | #define I2C_SDA 13 //SDA == P5.1 // GPIO 13 93 | #define I2C_SCL 12 //SCL == P5.2 // GPIO 12 94 | 95 | // TODO: this could use a nice struct with bit members... 96 | 97 | #define I2C_BASE (0x80006000) 98 | 99 | #define I2CADR ((volatile uint8_t *) ( I2C_BASE + 0x00 )) 100 | #define I2CFDR ((volatile uint8_t *) ( I2C_BASE + 0x04 )) 101 | #define I2CCR ((volatile uint8_t *) ( I2C_BASE + 0x08 )) 102 | #define I2CSR ((volatile uint8_t *) ( I2C_BASE + 0x0C )) 103 | #define I2CDR ((volatile uint8_t *) ( I2C_BASE + 0x10 )) 104 | #define I2CDFSRR ((volatile uint8_t *) ( I2C_BASE + 0x14 )) 105 | #define I2CCKER ((volatile uint8_t *) ( I2C_BASE + 0x18 )) 106 | 107 | // TODO: fix nice structs 108 | 109 | // i2c CR 110 | #define I2C_MEN 0x80 111 | #define I2C_MIEN 0x40 112 | #define I2C_MSTA 0x20 113 | #define I2C_MTX 0x10 114 | #define I2C_TXAK 0x08 115 | #define I2C_RSTA 0x04 116 | #define I2C_BCST 0x01 117 | 118 | // i2c SR 119 | #define I2C_MCF 0x80 120 | #define I2C_MAAS 0x40 121 | #define I2C_MBB 0x20 122 | #define I2C_MAL 0x10 123 | #define I2C_BCSTM 0x08 124 | #define I2C_SRW 0x04 125 | #define I2C_MIF 0x02 126 | #define I2C_RXAK 0x01 127 | 128 | // i2c digital filter sample rate register 129 | #define I2C_DFSR 0x3f // default = 0x10 130 | 131 | // i2c CKER 132 | #define I2C_CKEN 0x01 133 | 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /lib/uart1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | volatile char u1_tx_buf[UART1_TX_BUFFERSIZE]; 40 | volatile uint32_t u1_tx_head, u1_tx_tail; 41 | 42 | #if UART1_RX_BUFFERSIZE > 32 43 | volatile char u1_rx_buf[UART1_RX_BUFFERSIZE-32]; 44 | volatile uint32_t u1_rx_head, u1_rx_tail; 45 | #endif 46 | 47 | void uart1_isr(void) { 48 | 49 | #if UART1_RX_BUFFERSIZE > 32 50 | if (*UART1_USTAT & ( 1 << 6)) { //receive interrupt 51 | while( *UART1_URXCON != 0 ) { //flush the hardware fifo into the software buffer 52 | uint32_t u1_rx_tail_next; 53 | u1_rx_tail_next = u1_rx_tail+1; 54 | if (u1_rx_tail_next >= sizeof(u1_rx_buf)) 55 | u1_rx_tail_next = 0; 56 | if (u1_rx_head != u1_rx_tail_next) { 57 | u1_rx_buf[u1_rx_tail]= *UART1_UDATA; 58 | u1_rx_tail = u1_rx_tail_next; 59 | } else { //buffer is full, flush the fifo 60 | while (*UART1_URXCON !=0) { if (*UART1_UDATA) { } } 61 | } 62 | } 63 | return; 64 | } 65 | #endif 66 | 67 | while( *UART1_UTXCON != 0 ) { 68 | if (u1_tx_head == u1_tx_tail) { 69 | #if UART1_RX_BUFFERSIZE > 32 70 | *UART1_UCON |= (1 << 13); /*disable tx interrupt */ 71 | #else 72 | disable_irq(UART1); 73 | #endif 74 | return; 75 | } 76 | 77 | *UART1_UDATA = u1_tx_buf[u1_tx_tail]; 78 | u1_tx_tail++; 79 | if (u1_tx_tail >= sizeof(u1_tx_buf)) 80 | u1_tx_tail = 0; 81 | } 82 | } 83 | 84 | void uart1_putc(char c) { 85 | /* disable UART1 since */ 86 | /* UART1 isr modifies u1_tx_head and u1_tx_tail */ 87 | #if UART1_RX_BUFFERSIZE > 32 88 | *UART1_UCON |= (1 << 13); /*disable tx interrupt */ 89 | #else 90 | disable_irq(UART1); 91 | #endif 92 | 93 | if( (u1_tx_head == u1_tx_tail) && 94 | (*UART1_UTXCON != 0)) { 95 | *UART1_UDATA = c; 96 | } else { 97 | u1_tx_buf[u1_tx_head] = c; 98 | u1_tx_head += 1; 99 | if (u1_tx_head >= sizeof(u1_tx_buf)) 100 | u1_tx_head = 0; 101 | if (u1_tx_head == u1_tx_tail) { /* drop chars when no room */ 102 | #if UART1_DROP_CHARS 103 | if (u1_tx_head) { u1_tx_head -=1; } else { u1_tx_head = sizeof(u1_tx_buf); } 104 | #else 105 | { 106 | uint32_t u1_tx_tail_save=u1_tx_tail; 107 | /* Back up head to show buffer not empty, and enable tx interrupt */ 108 | u1_tx_head--; 109 | #if UART1_RX_BUFFERSIZE > 32 110 | *UART1_UCON &= ~(1 << 13); /*enable tx interrupt */ 111 | #else 112 | enable_irq(UART1); 113 | #endif 114 | /* Tail will change after one character goes out */ 115 | while (u1_tx_tail_save == u1_tx_tail) ; 116 | /* Restore head to character we just stuffed */ 117 | u1_tx_head++; 118 | return; 119 | } 120 | #endif /* UART1_DROP_CHARS */ 121 | } 122 | 123 | #if UART1_RX_BUFFERSIZE > 32 124 | *UART1_UCON &= ~(1 << 13); /*enable tx interrupt */ 125 | #else 126 | enable_irq(UART1); 127 | #endif 128 | 129 | } 130 | } 131 | 132 | uint8_t uart1_getc(void) { 133 | #if UART1_RX_BUFFERSIZE > 32 134 | /* First pull from the ram buffer */ 135 | uint8_t c=0; 136 | if (u1_rx_head != u1_rx_tail) { 137 | c = u1_rx_buf[u1_rx_head++]; 138 | if (u1_rx_head >= sizeof(u1_rx_buf)) 139 | u1_rx_head=0; 140 | return c; 141 | } 142 | #endif 143 | /* Then pull from the hardware fifo */ 144 | while(uart1_can_get() == 0) { continue; } 145 | return *UART1_UDATA; 146 | } 147 | -------------------------------------------------------------------------------- /lib/uart2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | volatile char u2_tx_buf[UART2_TX_BUFFERSIZE]; 40 | volatile uint32_t u2_tx_head, u2_tx_tail; 41 | 42 | #if UART2_RX_BUFFERSIZE > 32 43 | volatile char u2_rx_buf[UART2_RX_BUFFERSIZE-32]; 44 | volatile uint32_t u2_rx_head, u2_rx_tail; 45 | #endif 46 | 47 | void uart2_isr(void) { 48 | 49 | #if UART2_RX_BUFFERSIZE > 32 50 | if (*UART2_USTAT & ( 1 << 6)) { //receive interrupt 51 | while( *UART2_URXCON != 0 ) { //flush the hardware fifo into the software buffer 52 | uint32_t u2_rx_tail_next; 53 | u2_rx_tail_next = u2_rx_tail+1; 54 | if (u2_rx_tail_next >= sizeof(u2_rx_buf)) 55 | u2_rx_tail_next = 0; 56 | if (u2_rx_head != u2_rx_tail_next) { 57 | u2_rx_buf[u2_rx_tail]= *UART2_UDATA; 58 | u2_rx_tail = u2_rx_tail_next; 59 | } else { //buffer is full, flush the fifo 60 | while (*UART2_URXCON !=0) { if (*UART2_UDATA) { } } 61 | } 62 | } 63 | return; 64 | } 65 | #endif 66 | 67 | while( *UART2_UTXCON != 0 ) { 68 | if (u2_tx_head == u2_tx_tail) { 69 | #if UART2_RX_BUFFERSIZE > 32 70 | *UART2_UCON |= (1 << 13); /*disable tx interrupt */ 71 | #else 72 | disable_irq(UART2); 73 | #endif 74 | return; 75 | } 76 | *UART2_UDATA = u2_tx_buf[u2_tx_tail]; 77 | u2_tx_tail++; 78 | if (u2_tx_tail >= sizeof(u2_tx_buf)) 79 | u2_tx_tail = 0; 80 | } 81 | 82 | } 83 | 84 | void uart2_putc(char c) { 85 | /* disable UART2 since */ 86 | /* UART2 isr modifies u2_tx_head and u2_tx_tail */ 87 | #if UART2_RX_BUFFERSIZE > 32 88 | *UART2_UCON |= (1 << 13); /*disable tx interrupt */ 89 | #else 90 | disable_irq(UART2); 91 | #endif 92 | 93 | if( (u2_tx_head == u2_tx_tail) && 94 | (*UART2_UTXCON != 0)) { 95 | *UART2_UDATA = c; 96 | } else { 97 | u2_tx_buf[u2_tx_head] = c; 98 | u2_tx_head += 1; 99 | if (u2_tx_head >= sizeof(u2_tx_buf)) 100 | u2_tx_head = 0; 101 | if (u2_tx_head == u2_tx_tail) { /* drop chars when no room */ 102 | #if UART2_DROP_CHARS 103 | if (u2_tx_head) { u2_tx_head -=1; } else { u2_tx_head = sizeof(u2_tx_buf); } 104 | #else 105 | { 106 | uint32_t u2_tx_tail_save=u2_tx_tail; 107 | /* Back up head to show buffer not empty, and enable tx interrupt */ 108 | u2_tx_head--; 109 | #if UART2_RX_BUFFERSIZE > 32 110 | *UART2_UCON &= ~(1 << 13); /*enable tx interrupt */ 111 | #else 112 | enable_irq(UART2); 113 | #endif 114 | /* Tail will change after one character goes out */ 115 | while (u2_tx_tail_save == u2_tx_tail) ; 116 | /* Restore head to character we just stuffed */ 117 | u2_tx_head++; 118 | return; 119 | } 120 | #endif /* UART2_DROP_CHARS */ 121 | } 122 | 123 | #if UART2_RX_BUFFERSIZE > 32 124 | *UART2_UCON &= ~(1 << 13); /*enable tx interrupt */ 125 | #else 126 | enable_irq(UART2); 127 | #endif 128 | 129 | } 130 | } 131 | 132 | uint8_t uart2_getc(void) { 133 | #if UART2_RX_BUFFERSIZE > 32 134 | /* First pull from the ram buffer */ 135 | uint8_t c=0; 136 | if (u2_rx_head != u2_rx_tail) { 137 | c = u2_rx_buf[u2_rx_head++]; 138 | if (u2_rx_head >= sizeof(u2_rx_buf)) 139 | u2_rx_head=0; 140 | return c; 141 | } 142 | #endif 143 | /* Then pull from the hardware fifo */ 144 | while(uart2_can_get() == 0) { continue; } 145 | return *UART2_UDATA; 146 | } 147 | -------------------------------------------------------------------------------- /lib/adc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include "mc1322x.h" 38 | 39 | //#define ADC_CHANS_ENABLED 0x3F // channels 0-5 enabled 40 | //#define ADC_CHANS_ENABLED 0x7E // channels 1-6 enabled 41 | //#define ADC_CHANS_ENABLED (1 << 6) // only channel 6 enabled 42 | #define ADC_CHANS_ENABLED 0x1FF // all channels, including battery reference voltage 43 | 44 | //#define ADC_PRESCALE_VALUE 24 // divide by 24 for 1MHz. 45 | 46 | #define ADC_SAMPLE_FREQ 400 // Hz (minimum of ~366.21 Hz) 47 | #define ADC_PRESCALE_VALUE (REF_OSC / ADC_SAMPLE_FREQ) 48 | 49 | #define ADC_USE_TIMER 0 50 | #define ADC_USE_INTERRUPTS 0 // incomplete support 51 | 52 | uint16_t adc_reading[NUM_ADC_CHAN]; 53 | 54 | void ADC_flush(void) { 55 | while(ADC->FIFO_STATUSbits.EMPTY == 0) ADC->FIFO_READ; 56 | } 57 | 58 | uint16_t ADC_READ(void) { 59 | while(ADC->FIFO_STATUSbits.EMPTY); // loop while empty 60 | return ADC->FIFO_READ; // upper 4 bits are channel number 61 | } 62 | 63 | 64 | void adc_service(void) { 65 | uint16_t value; 66 | uint8_t channel; 67 | while (ADC->FIFO_STATUSbits.EMPTY == 0) { 68 | value = ADC->FIFO_READ; 69 | channel = value >> 12; 70 | if (channel < NUM_ADC_CHAN) adc_reading[channel] = value & 0xFFF; 71 | } 72 | } 73 | 74 | #define _adc_setup_chan(x) do { \ 75 | if ( channel == x ) { \ 76 | ADC->SEQ_1bits.CH##x = 1; \ 77 | GPIO->FUNC_SEL.ADC##x = 1; \ 78 | GPIO->PAD_DIR.ADC##x = 0; \ 79 | GPIO->PAD_KEEP.ADC##x = 0; \ 80 | GPIO->PAD_PU_EN.ADC##x = 0; \ 81 | }} while (0) 82 | 83 | void adc_setup_chan(uint8_t channel) { 84 | _adc_setup_chan(0); 85 | _adc_setup_chan(1); 86 | _adc_setup_chan(2); 87 | _adc_setup_chan(3); 88 | _adc_setup_chan(4); 89 | _adc_setup_chan(5); 90 | _adc_setup_chan(6); 91 | _adc_setup_chan(7); 92 | } 93 | 94 | void adc_init(void) { 95 | ADC->CLOCK_DIVIDER = 80; // 300 KHz 96 | ADC->PRESCALE = ADC_PRESCALE_VALUE - 1; // divide by 24 for 1MHz. 97 | 98 | ADC->CONTROL = 1; 99 | 100 | // The ON-TIME must always be 10µs or greater - typical On-Time value = 0x000A (10dec) 101 | ADC->ON_TIME = 10; 102 | 103 | /* 104 | NOTE 105 | The ADC analog block requires 6 ADC_Clocks per conversion, and the 106 | ADC_Clock must 300kHz or less. With 6 clocks/conversion and a 33.33µs 107 | clock period: 108 | * The ADC convert time must always be 20µs or greater 109 | * If the ADC_Clock is a frequency lower than 300kHz, the convert time 110 | must always be 6 ADC_Clock periods or greater 111 | * For override mode, extend convert time to 40µs minimum or greater 112 | For the convert time: 113 | * This delay is a function of the Prescale Clock (typically 1 MHz) 114 | * The register must be initialized for proper operation 115 | * For a 20µs convert time with 1MHz, value = 0x0014 (20dec) 116 | * If convert time is insufficient, inaccurate sample data will result 117 | */ 118 | ADC->CONVERT_TIME = 1000000 / (115200 / 8) - 1; 119 | 120 | ADC->MODE = 0; // Automatic 121 | 122 | #if ADC_USE_INTERRUPTS 123 | ADC->FIFO_CONTROL = 7; 124 | #else 125 | ADC->FIFO_CONTROL = 0; 126 | #endif 127 | 128 | #if ADC_USE_TIMER 129 | ADC->SR_1_HIGH = 0x0000; 130 | ADC->SR_1_LOW = (REF_OSC / ADC_PRESCALE_VALUE) / (115200 / 8) + 1; 131 | #endif 132 | 133 | ADC->SEQ_1 = 0; 134 | #if ADC_USE_TIMER 135 | ADC->SEQ_1bits.SEQ_MODE = 1; // sequence based on Timer 1 136 | #else 137 | ADC->SEQ_1bits.SEQ_MODE = 0; // sequence based on convert time. 138 | #endif 139 | ADC->SEQ_1bits.BATT = 1; 140 | 141 | ADC->CONTROL = 0xF001 142 | //#if ADC_USE_TIMER 143 | | (1 << 1) // Timer 1 enable 144 | //#endif 145 | ; 146 | ADC->OVERRIDE = (1 << 8); 147 | 148 | } 149 | -------------------------------------------------------------------------------- /tests/per.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | /* This program communicates with itself and determines the packet */ 44 | /* error rate (PER) under a variety of powers and packet sizes */ 45 | /* Each test the packets are sent and received as fast as possible */ 46 | 47 | /* The program first scans on channel 11 and attempts to open a test */ 48 | /* session with a node. After opening a session, the nodes begin the */ 49 | /* test sequence */ 50 | 51 | /* how long to wait between session requests */ 52 | #define SESSION_REQ_TIMEOUT 10000 /* phony seconds */ 53 | 54 | enum STATES { 55 | SCANNING, 56 | MAX_STATE 57 | }; 58 | 59 | typedef uint32_t ptype_t; 60 | enum PACKET_TYPE { 61 | PACKET_SESS_REQ, 62 | MAX_PACKET_TYPE 63 | }; 64 | /* get protocol level packet type */ 65 | /* this is not 802.15.4 packet type */ 66 | ptype_t get_packet_type(packet_t * p __attribute__((unused))) { 67 | return MAX_PACKET_TYPE; 68 | } 69 | 70 | typedef uint32_t session_id_t; 71 | 72 | 73 | 74 | /* phony get_time */ 75 | uint32_t get_time(void) { 76 | static volatile int32_t cur_time = 0; 77 | cur_time++; 78 | return cur_time; 79 | } 80 | 81 | 82 | #define random_short_addr() (*MACA_RANDOM & ones(sizeof(uint16_t)*8)) 83 | 84 | void build_session_req(volatile packet_t *p) { 85 | static uint8_t count = 0; 86 | p->length = 4; p->offset = 0; 87 | p->data[0] = 0xff; 88 | p->data[1] = 0x01; 89 | p->data[2] = 0x02; 90 | p->data[3] = count++; 91 | return; 92 | } 93 | 94 | void session_req(uint16_t addr __attribute__((unused))) { 95 | static volatile int time = 0; 96 | volatile packet_t *p; 97 | 98 | if((get_time() - time) > SESSION_REQ_TIMEOUT) { 99 | time = get_time(); 100 | if((p = get_free_packet())) { 101 | build_session_req(p); 102 | tx_packet(p); 103 | } 104 | } 105 | return; 106 | } 107 | 108 | session_id_t open_session(uint16_t addr __attribute((unused))) { return 0; } 109 | 110 | void main(void) { 111 | uint32_t state; 112 | volatile packet_t *p; 113 | session_id_t sesid; 114 | ptype_t type; 115 | uint16_t addr, my_addr; 116 | 117 | /* trim the reference osc. to 24MHz */ 118 | pack_XTAL_CNTL(CTUNE_4PF, CTUNE, FTUNE, IBIAS); 119 | 120 | uart_init(UART1, 115200); 121 | 122 | vreg_init(); 123 | 124 | maca_init(); 125 | 126 | set_power(0x0f); /* 0dbm */ 127 | set_channel(0); /* channel 11 */ 128 | 129 | /* generate a random short address */ 130 | my_addr = random_short_addr(); 131 | 132 | /* sets up tx_on, should be a board specific item */ 133 | *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2)); 134 | gpio_pad_dir_set( 1ULL << 44 ); 135 | 136 | print_welcome("Packet error test"); 137 | 138 | state = SCANNING; 139 | while(1) { 140 | 141 | switch(state) { 142 | case SCANNING: 143 | if((p = rx_packet())) { 144 | /* extract what we need and free the packet */ 145 | printf("Recv: "); 146 | print_packet(p); 147 | type = get_packet_type((packet_t *) p); 148 | addr = 0; /* FIXME */ 149 | free_packet(p); 150 | /* pick a new address if someone else is using ours */ 151 | if(addr == my_addr) { 152 | my_addr = random_short_addr(); 153 | printf("DUP addr received, changing to new addr 0x%x02\n\r",my_addr); 154 | } 155 | /* if we have a packet */ 156 | /* check if it's a session request beacon */ 157 | if(type == PACKET_SESS_REQ) { 158 | /* try to start a session */ 159 | sesid = open_session(addr); 160 | } 161 | } else { 162 | session_req(my_addr); 163 | } 164 | break; 165 | default: 166 | break; 167 | } 168 | 169 | 170 | } 171 | 172 | } 173 | 174 | -------------------------------------------------------------------------------- /tools/mc1322x-load.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use Device::SerialPort; 4 | use Term::ReadKey; 5 | use Getopt::Long; 6 | use Time::HiRes qw(usleep); 7 | 8 | use strict; 9 | 10 | my $filename = ''; 11 | my $second = ''; 12 | my $term = '/dev/ttyUSB0'; 13 | my $baud = '115200'; 14 | my $verbose; 15 | my $rts = 'none'; 16 | my $command = ''; 17 | my $first_delay = 50; 18 | my $second_delay = 100; 19 | my $do_exit; 20 | my $zerolen; 21 | my $ownlen; 22 | 23 | GetOptions ('file=s' => \$filename, 24 | 'secondfile=s' => \$second, 25 | 'zerolen' => \$zerolen, 26 | 'l|ownlen' => \$ownlen, 27 | 'terminal=s' => \$term, 28 | 'verbose' => \$verbose, 29 | 'u|baud=s' => \$baud, 30 | 'rts=s' => \$rts, 31 | 'command=s' => \$command, 32 | 'a=s' => \$first_delay, 33 | 'b=s' => \$second_delay, 34 | 'exit' => \$do_exit, 35 | ) or die 'bad options'; 36 | 37 | $| = 1; 38 | 39 | if($filename eq '') { 40 | print "Example usage: mc1322x-load.pl -f foo.bin -t /dev/ttyS0 -b 9600\n"; 41 | print " or : mc1322x-load.pl -f flasher.bin -s flashme.bin 0x1e000,0x11223344,0x55667788\n"; 42 | print " or : mc1322x-load.pl -f flasher.bin -z 0x1e000,0x11223344,0x55667788\n"; 43 | print " -f required: binary file to load\n"; 44 | print " -s optional: secondary binary file to send\n"; 45 | print " -z optional: send a zero length file as secondary\n"; 46 | print " -l optional: secondary file contains len in first 4 Bytes (little endian)\n"; 47 | print " -t, terminal default: /dev/ttyUSB0\n"; 48 | print " -u, --baud baud rate default: 115200\n"; 49 | print " -r [none|rts] flow control default: none\n"; 50 | print " -c command to run for autoreset: \n"; 51 | print " e.g. -c 'bbmc -l redbee-econotag -i 0 reset'\n"; 52 | print " -e exit instead of dropping to terminal display\n"; 53 | print " -a first intercharacter delay, passed to usleep\n"; 54 | print " -b second intercharacter delay, passed to usleep\n"; 55 | print "\n"; 56 | print "anything on the command line is sent\n"; 57 | print "after all of the files.\n\n"; 58 | exit; 59 | } 60 | 61 | if (!(-e $filename)) { die "file $filename not found\n"; } 62 | if (($second ne '') && !(-e $second)) { die "secondary file $second not found\n"; } 63 | 64 | my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n"; 65 | # next test will die at runtime unless $ob 66 | 67 | $ob->baudrate($baud); 68 | $ob->parity('none'); 69 | $ob->databits(8); 70 | $ob->stopbits(1); 71 | if($rts eq 'rts') { 72 | $ob->handshake('rts'); 73 | } else { 74 | $ob->handshake('none'); 75 | } 76 | $ob->read_const_time(1000); # 1 second per unfulfilled "read" call 77 | $ob->rts_active(1); 78 | 79 | my $s = 0; 80 | my $reset = 0; 81 | my $size = 0; 82 | 83 | while(1) { 84 | 85 | my $c; my $count; my $ret = ''; my $test=''; 86 | 87 | if($s == 1) { print "secondary send...\n"; } 88 | 89 | $ob->write(pack('C','0')); 90 | 91 | if(($command ne '') && 92 | ($reset eq 0)) { 93 | $reset++; 94 | system($command); 95 | } 96 | 97 | if($s == 1) { 98 | $test = 'ready'; 99 | } else { 100 | $test = 'CONNECT'; 101 | } 102 | 103 | until($ret =~ /$test$/) { 104 | ($count,$c) = $ob->read(1); 105 | if ($count == 0) { 106 | print '.'; 107 | $ob->write(pack('C','0')); 108 | next; 109 | } 110 | $ret .= $c; 111 | } 112 | print $ret . "\n"; 113 | 114 | if (-e $filename || (defined($zerolen) && ($s == 1))) { 115 | 116 | if ($s == 0) { 117 | $size = -s $filename; 118 | } else { 119 | if (defined($zerolen)) { 120 | $size = 0; 121 | } else { 122 | if (defined($ownlen)) { 123 | $size = -s $filename; 124 | } else { 125 | $size = (-s $filename) + 4; 126 | } 127 | } 128 | } 129 | 130 | print ("Size: $size bytes\n"); 131 | $ob->write(pack('V',$size)); 132 | 133 | if(($s == 0) || 134 | ((!defined($zerolen)) && ($s == 1))) { 135 | open(FILE, $filename) or die($!); 136 | print "Sending $filename\n"; 137 | 138 | if ($s == 1) { 139 | if (defined($ownlen)) { 140 | read(FILE, my $packed_length, 4); 141 | $size = unpack('V', $packed_length); 142 | } else { 143 | $size = -s $filename; 144 | } 145 | print ("Prog-Size: $size bytes\n"); 146 | $ob->write(pack('V',$size)); 147 | } 148 | 149 | my $i = 1; 150 | while(read(FILE, $c, 1)) { 151 | $i++; 152 | usleep($first_delay) if ( $s == 0 ) && ($first_delay != 0); 153 | usleep($second_delay) if ( $s == 1 ) && ($second_delay != 0); 154 | $ob->write($c); 155 | } 156 | } 157 | } 158 | 159 | last if ($s==1); 160 | if((-e $second) || defined($zerolen)) { 161 | $s=1; $filename = $second; 162 | } else { 163 | last; 164 | } 165 | 166 | } 167 | 168 | print "done sending files.\n"; 169 | 170 | if(scalar(@ARGV)!=0) { 171 | print "sending " ; 172 | print @ARGV; 173 | print ",\n"; 174 | 175 | $ob->write(@ARGV); 176 | $ob->write(','); 177 | } 178 | 179 | if(defined($do_exit)) { 180 | exit; 181 | } 182 | 183 | my $c; my $count; 184 | while(1) { 185 | ($count, $c) = $ob->read(1); 186 | print $c if (defined($count) && ($count != 0)); 187 | } 188 | 189 | $ob -> close or die "Close failed: $!\n"; 190 | ReadMode 0; 191 | undef $ob; # closes port AND frees memory in perl 192 | exit; 193 | 194 | -------------------------------------------------------------------------------- /tests/autoack-tx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, Mariano Alvira and other contributors 3 | * to the MC1322x project (http://mc1322x.devl.org) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the Institute nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * This file is part of libmc1322x: see http://mc1322x.devl.org 31 | * for details. 32 | * 33 | * 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tests.h" 41 | #include "config.h" 42 | 43 | #define LED LED_RED 44 | 45 | /* 802.15.4 PSDU is 127 MAX */ 46 | /* 2 bytes are the FCS */ 47 | /* therefore 125 is the max payload length */ 48 | #define PAYLOAD_LEN 16 49 | #define DELAY 100000 50 | 51 | void fill_packet(volatile packet_t *p) { 52 | static volatile uint8_t count=0; 53 | 54 | p->length = 16; 55 | p->offset = 0; 56 | p->data[0] = 0x71; /* 0b 10 01 10 000 1 1 0 0 001 data, ack request, short addr */ 57 | p->data[1] = 0x98; /* 0b 10 01 10 000 1 1 0 0 001 data, ack request, short addr */ 58 | p->data[2] = count++; /* dsn */ 59 | p->data[3] = 0xaa; /* pan */ 60 | p->data[4] = 0xaa; 61 | p->data[5] = 0x11; /* dest. short addr. */ 62 | p->data[6] = 0x11; 63 | p->data[7] = 0x22; /* src. short addr. */ 64 | p->data[8] = 0x22; 65 | 66 | /* payload */ 67 | p->data[9] = 'a'; 68 | p->data[10] = 'c'; 69 | p->data[11] = 'k'; 70 | p->data[12] = 't'; 71 | p->data[13] = 'e'; 72 | p->data[14] = 's'; 73 | p->data[15] = 't'; 74 | 75 | } 76 | 77 | void maca_tx_callback(volatile packet_t *p) { 78 | switch(p->status) { 79 | case 0: 80 | printf("TX OK\n\r"); 81 | break; 82 | case 3: 83 | printf("CRC ERR\n\r"); 84 | break; 85 | case 5: 86 | printf("NO ACK\n\r"); 87 | break; 88 | default: 89 | printf("unknown status: %d\n", (int)p->status); 90 | } 91 | } 92 | 93 | void main(void) { 94 | volatile packet_t *p; 95 | char c; 96 | uint16_t r=30; /* start reception 100us before ack should arrive */ 97 | uint16_t end=180; /* 750 us receive window*/ 98 | 99 | /* trim the reference osc. to 24MHz */ 100 | trim_xtal(); 101 | 102 | uart_init(UART1, 115200); 103 | 104 | vreg_init(); 105 | 106 | maca_init(); 107 | 108 | set_channel(0); /* channel 11 */ 109 | // set_power(0x0f); /* 0xf = -1dbm, see 3-22 */ 110 | // set_power(0x11); /* 0x11 = 3dbm, see 3-22 */ 111 | set_power(0x12); /* 0x12 is the highest, not documented */ 112 | 113 | /* sets up tx_on, should be a board specific item */ 114 | GPIO->FUNC_SEL_44 = 1; 115 | GPIO->PAD_DIR_SET_44 = 1; 116 | 117 | GPIO->FUNC_SEL_45 = 2; 118 | GPIO->PAD_DIR_SET_45 = 1; 119 | 120 | *MACA_RXACKDELAY = r; 121 | 122 | printf("rx warmup: %d\n\r", (int)(*MACA_WARMUP & 0xfff)); 123 | 124 | *MACA_RXEND = end; 125 | 126 | printf("rx end: %d\n\r", (int)(*MACA_RXEND & 0xfff)); 127 | 128 | set_prm_mode(AUTOACK); 129 | 130 | print_welcome("rftest-tx"); 131 | 132 | while(1) { 133 | 134 | /* call check_maca() periodically --- this works around */ 135 | /* a few lockup conditions */ 136 | check_maca(); 137 | 138 | while((p = rx_packet())) { 139 | if(p) { 140 | printf("RX: "); 141 | print_packet(p); 142 | free_packet(p); 143 | } 144 | } 145 | 146 | if(uart1_can_get()) { 147 | c = uart1_getc(); 148 | 149 | switch(c) { 150 | case 'z': 151 | r++; 152 | if(r > 4095) { r = 0; } 153 | *MACA_RXACKDELAY = r; 154 | printf("rx ack delay: %d\n\r", r); 155 | break; 156 | case 'x': 157 | if(r == 0) { r = 4095; } else { r--; } 158 | *MACA_RXACKDELAY = r; 159 | printf("rx ack delay: %d\n\r", r); 160 | break; 161 | case 'q': 162 | end++; 163 | if(r > 4095) { r = 0; } 164 | *MACA_RXEND = end; 165 | printf("rx end: %d\n\r", end); 166 | break; 167 | case 'w': 168 | end--; 169 | if(r == 0) { r = 4095; } else { r--; } 170 | *MACA_RXEND = end; 171 | printf("rx end: %d\n\r", end); 172 | break; 173 | default: 174 | p = get_free_packet(); 175 | if(p) { 176 | fill_packet(p); 177 | 178 | printf("autoack-tx --- "); 179 | print_packet(p); 180 | 181 | tx_packet(p); 182 | } 183 | break; 184 | } 185 | } 186 | 187 | } 188 | 189 | } 190 | --------------------------------------------------------------------------------