Merge branch 'libmc13-9f82e068' into update-libmc1322x

ico
Mariano Alvira 2011-02-17 14:39:20 -05:00
commit 2e33e1694a
14 changed files with 46099 additions and 0 deletions

9
cpu/mc1322x/.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
*.o
*.d
*.s
*.a
*.elf
*.bin
*.map
tests/obj_*

View File

@ -0,0 +1,145 @@
# Hey Emacs, this is a -*- makefile -*-
# Set up a default target in case the user didn't already have one.
# "all" means to build .bin for all defined targets for the currently-defined board
all: $(addsuffix _$(BOARD).bin, $(TARGETS) $(TARGETS_WITH_ROM_VARS))
.PHONY: all
# Pretty print output. Use "make Q=" to see full commands
Q ?= @
define pretty
@printf "%8s %s\n" "$1" "$2"
endef
# Don't delete intermediate targets
.SECONDARY:
#####
# Tools and flags
# Set up cross compiler and toolchain definitions.
CROSS_COMPILE ?= arm-none-eabi-
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB = $(CROSS_COMPILE)ranlib
# Build CFLAGS and prepend it to user-supplied CFLAGS
CFLAGS_PLAT ?= -march=armv4t -mtune=arm7tdmi-s -mlong-calls -msoft-float \
-mthumb-interwork -fno-strict-aliasing -fno-common -ffixed-r8 \
-ffunction-sections -ffreestanding -fno-builtin -nodefaultlibs
CFLAGS_WARN ?= -Wcast-align -Wall -Wstrict-prototypes -Wextra
CFLAGS_OPT ?= -Os
CFLAGS_DEBUG ?= -g -DDEBUG -Werror
CFLAGS_MISC ?= -pipe
CFLAGS := $(CFLAGS_PLAT) $(CFLAGS_WARN) $(CFLAGS_OPT) $(CFLAGS_DEBUG) $(CFLAGS_MISC) $(CFLAGS)
# Thumb flags, used for building most objects
CFLAGS_THUMB ?= -mthumb -mcallee-super-interworking
# Linker flags
LINKERSCRIPT ?= $(MC1322X)/mc1322x.lds
LDFLAGS ?= -T $(LINKERSCRIPT) -nostartfiles -static -export-dynamic -u_start -Wl,-Map=$(@:.elf=.map)
# Assembler flags
AFLAGS ?= -Wa,-gstabs $(CFLAGS)
# Misc tool options
OBJCOPYFLAGS ?= --gap-fill=0xff
ARFLAGS = cr
#####
include $(MC1322X)/board/Makefile.board
include $(MC1322X)/lib/Makefile.lib
include $(MC1322X)/src/Makefile.src
#####
# Rule for building ELF files. We use both a wildcard rule that links
# $(SRCLIB) as well as target-specific rules that link $(SRCLIB_ROMVARS)
# Normal targets (wildcard rule):
%_$(BOARD).elf: $(OBJDIR)/%.o $(TARGET_OBJ) $(SRCLIB)
$(call pretty,LINK,$@)
$Q$(CC) $(LDFLAGS) -o $@ -Wl,--start-group $^ -lm -Wl,--end-group
# Targets that need space for rom variables:
define build_elf_rule
$(1)_$$(BOARD).elf: $$(OBJDIR)/$(1).o $$(TARGET_OBJ) $$(SRCLIB_ROMVARS)
$$(call pretty,LINK (romvars),$$@)
$$Q$$(CC) $$(LDFLAGS) -o $$@ -Wl,--start-group $$^ -lm -Wl,--end-group
endef
$(foreach t, $(TARGETS_WITH_ROM_VARS), $(eval $(call build_elf_rule,$(t))))
# Generic rules
%.srec: %.elf
$(call pretty,OBJCOPY,$@)
$Q$(OBJCOPY) $(OBJCOPYFLAGS) -O srec $< $@
%.ihex: %.elf
$(call pretty,OBJCOPY,$@)
$Q$(OBJCOPY) $(OBJCOPYFLAGS) -O ihex $< $@
%.bin: %.elf
$(call pretty,OBJCOPY,$@)
$Q$(OBJCOPY) $(OBJCOPYFLAGS) -O binary $< $@
%.dis: %.elf
$(call pretty,OBJDUMP,$@)
$Q$(OBJDUMP) -Sd $< > $@ || rm -f $@
%.dis: %.o
$(call pretty,OBJDUMP,$@)
$Q$(OBJDUMP) -d $< > $@ || rm -f $@
%.o: %.c $(FORCE_C_DEPENDS)
$(call pretty,CC,$@)
$Q$(CC) $(CFLAGS) $(CFLAGS_THUMB) -MMD -c -o $@ $<
@$(FINALIZE_DEPENDENCY)
%.o: %.S
$(call pretty,AS,$@)
$Q$(CC) $(AFLAGS) -MMD -c -o $@ $<
@$(FINALIZE_DEPENDENCY)
# Fix the dependencies generated for a particular target .o
# See http://make.paulandlesley.org/autodep.html#advanced
define FINALIZE_DEPENDENCY
cp $(@:.o=.d) $(@:.o=.$$$$); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
rm -f $(@:.o=.$$$$)
endef
clean::
rm -f *.{o,d,a,bin,elf,ihex,srec,dis,map,bak} *~
.PHONY: clean
##############################
# If no single board was specified, invoke make recursively for each
# board in $(BOARDS), or $(ALL_BOARDS) if that wasn't specified either.
# This is at the end so that it can override all other targets.
ifndef BOARD
ifneq ($(MAKECMDGOALS),clean)
.DEFAULT_GOAL=mc1322x-default
BOARDS ?= $(ALL_BOARDS)
define build_board
@echo "Building for board: $(1)"
@$(MAKE) --no-print-directory BOARD=$(1) $(2)
endef
$(MAKECMDGOALS):
$(foreach b, $(BOARDS), $(call build_board,$(b),$@))
mc1322x-default:
$(foreach b, $(BOARDS), $(call build_board,$(b),))
endif
endif

74
cpu/mc1322x/README Normal file
View File

@ -0,0 +1,74 @@
libmc1322x is a library, build system, test code, and utilities for
using the mc13224v from Freescale.
Getting Started
---------------
$ cd tests
$ make
this will build all the test files in libmc1322x/tests for each board
defined in libmc1322x/board. You will have programs like:
rftest-tx_redbee-dev.bin
rftest-tx_redbee-r1.bin
rftest-rx_redbee-dev.bin
rftest-rx_redbee-r1.bin
if you only wanted to build binaries for one board you can do:
$ make BOARD=redbee-dev
You can use mc1322x-load.pl in libmc1322x/tools to run your code:
$ ../tools/mc1322x-load.pl -f rftest-tx_redbee-dev.bin
Incorporating libmc1322x into your own code
-------------------------------------------
The best way to incorporate libmc1322x into your code is as a git
submodule:
$ mkdir newproject
$ cd newproject
$ git init
Initialized empty Git repository in /home/malvira/newproject/.git/
$ git submodule add git://git.devl.org/git/malvira/libmc1322x.git
This will add libmc1322x to your repository. Now to setup the
Makefile:
$ cp libmc1322x/tests/Makefile .
You need to edit the Makefile to point MC1322X to your libmc1322x
submodule:
Change line 1
MC1322X := ..
to
MC1322X := libmc1322x
and edit COBJS and TARGETS accordings. COBJS are all of your common
code for any of your programs. TARGETS are the names of your programs.
For instance, you can have a common routine that prints a welcome
message that is used by two programs a and b. You would add common.o
to COBJS:
COBJS:= common.o
and your target line would read:
TARGETS := a b
COBJS are made for each board --- so it is ok to have board specific
code in there. As an example, tests uses this in tests.c to print the
name of the board in the welcome message. You could also use this to
change your GPIO mappings between boards.

11
cpu/mc1322x/doc/cal1.dump Normal file
View File

@ -0,0 +1,11 @@
(gdb) x/40x 0x4051e4
0x4051e4 <gRadioTOCCal1>: 0x80003048 0x00000f78 0x8000304c 0x00607707
0x4051f4 <gRadioTOCCal1+16>: 0x00000000 0x000161a8 0x8000a050 0x0000047b
0x405204 <gRadioTOCCal1+32>: 0x8000a054 0x0000007b 0x00005dc0 0x00000000
0x405214 <gu8BuckEnable>: 0x00000000 0x00000000 0x00000000 0x00000000
0x405224 <buffer_radio_init+12>: 0x00000000 0x80009400 0x00000017 0x8000a050
0x405234 <gRadioTOCCal5+12>: 0x00000000 0x8000a054 0x00000000 0x80003048
0x405244 <gRadioTOCCal5+28>: 0x00000f00 0x00000000 0x00000000 0x10000108
0x405254 <mLineParams+8>: 0x03180002 0x00042000 0x30000528 0x07380006
0x405264 <??isPageDeleted>: 0x0000fd01 0xc60081ff 0xb90f0000 0xc51e0000
0x405274: 0x00901200 0x05030080 0x00900480 0x00010180

View File

@ -0,0 +1,85 @@
0x4051b4 is the base that all the radioinit entries get offset from
r7 base
(gdb) x/128x $r7
0x4051b4 <gRadioTOCCal2_None24MHz_c>: 0x80009000 0x80050300 0x80009004 0x00000101
0x4051c4 <gRadioTOCCal2_None24MHz_c+16>: 0x80009008 0x00000000 0x8000900c 0x00000000
0x4051d4 <gRadioTOCCal2_None24MHz_c+32>: 0x80009020 0x0000000c 0x80009000 0xc0050300
0x4051e4 <gRadioTOCCal1>: 0x80003048 0x00000f78 0x8000304c 0x00607707
0x4051f4 <gRadioTOCCal1+16>: 0x00000000 0x000161a8 0x8000a050 0x0000047b
0x405204 <gRadioTOCCal1+32>: 0x8000a054 0x0000007b 0x00005dc0 0x00000000
0x405214 <gu8BuckEnable>: 0x00000000 0x00000000 0x00000000 0x00000000
0x405224 <buffer_radio_init+12>: 0x00000000 0x80009400 0x00000017 0x8000a050
0x405234 <gRadioTOCCal5+12>: 0x00000000 0x8000a054 0x00000000 0x80003048
0x405244 <gRadioTOCCal5+28>: 0x00000f00 0x00000000 0x00000000 0x10000108
0x405254 <mLineParams+8>: 0x03180002 0x00042000 0x30000528 0x07380006
0x405264 <??isPageDeleted>: 0x0000fd01 0xc60081ff 0xb90f0000 ---Type <return> to continue, or q <return> to quit---
0xc51e0000
0x405274: 0x00901200 0x05030080 0x00900480 0x00010180
0x405284: 0x00900800 0x0300fc80 0x8000900c 0x200400fc
0x405294: 0x0c800090 0x901500fc 0x03008000 0x3048c005
0x4052a4: 0x0f788000 0x304c0000 0x77078000 0x1000fb60
0x4052b4: 0x000161a8 0x8000a050 0x0000047b 0x8000a054
0x4052c4: 0x0300e07b 0x17800094 0x500300fd 0xfc8000a0
0x4052d4: 0xa0540300 0x00fc8000 0x00304805 0xf60f0080
0x4052e4: 0x01081400 0x00021000 0x20000318 0x05280004
0x4052f4: 0x00063000 0x00010738 0x00000000 0x00000000
0x405304: 0x00000000 0x00000000 0x00000000 0x00000000
(gdb) x/128x $r4
0x402b54 <gBuckEnable_c>: 0x80003000 0x00000019 0x80003048 0x00000ffb
0x402b64 <gBuckByPass_c>: 0x80003000 0x00000018 0x80003048 0x00000f04
0x402b74 <gBuckByPass_c+16>: 0x00000000 0x000161a8 0x80003048 0x00000ffc
0x402b84 <gRadioTOCCal2_24MHz_c>: 0x80009000 0x80050100 0x80009400 0x00020017
0x402b94 <gRadioTOCCal3_c+8>: 0x80009a04 0x8185a0a4 0x80009a00 0x8c900025
0x402ba4 <gRadioTOCCal3_c+24>: 0x00000000 0x00011194 0x80009a00 0x8c900021
0x402bb4 <gRadioTOCCal3_c+40>: 0x80009a00 0x8c900027 0x00000000 0x00011194
0x402bc4 <gRadioTOCCal3_c+56>: 0x80009a00 0x8c90002b 0x80009a00 0x8c90002f
0x402bd4 <gRadioTOCCal3_c+72>: 0x00000000 0x00011194 0x80009a00 0x8c900000
0x402be4 <gRadioTOCCal4_None24MHz_c>: 0x80009000 0x80050300 0x80004118 0x00180012
0x402bf4 <gRadioInit_RegReplacement_c+8>: 0x80009204 0x00000605 0x80009208 0x00000504
0x402c04 <gRadioInit_RegReplacement_c+24>: 0x8000920c 0x00001111 ---Type <return> to continue, or q <return> to quit---
0x80009210 0x0fc40000
0x402c14 <gRadioInit_RegReplacement_c+40>: 0x80009300 0x20046000 0x80009304 0x4005580c
0x402c24 <gRadioInit_RegReplacement_c+56>: 0x80009308 0x40075801 0x8000930c 0x4005d801
0x402c34 <gRadioInit_RegReplacement_c+72>: 0x80009310 0x5a45d800 0x80009314 0x4a45d800
0x402c44 <gRadioInit_RegReplacement_c+88>: 0x80009318 0x40044000 0x80009380 0x00106000
0x402c54 <gRadioInit_RegReplacement_c+104>: 0x80009384 0x00083806 0x80009388 0x00093807
0x402c64 <gRadioInit_RegReplacement_c+120>: 0x8000938c 0x0009b804 0x80009390 0x000db800
0x402c74 <gRadioInit_RegReplacement_c+136>: 0x80009394 0x00093802 0x8000a008 0x00000015
0x402c84 <gRadioInit_RegReplacement_c+152>: 0x8000a018 0x00000002 0x8000a01c 0x0000000f
0x402c94 <gRadioInit_RegReplacement_c+168>: 0x80009424 0x0000aaa0 0x80009434 0x01002020
0x402ca4 <gRadioInit_RegReplacement_c+184>: 0x80009438 0x016800fe 0x8000943c 0x8e578248
0x402cb4 <gRadioInit_RegReplacement_c+200>: 0x80009440 0x000000dd 0x80009444 0x00000946
---Type <return> to continue, or q <return> to quit---
0x402cc4 <gRadioInit_RegReplacement_c+216>: 0x80009448 0x0000035a 0x8000944c 0x00100010
0x402cd4 <gRadioInit_RegReplacement_c+232>: 0x80009450 0x00000515 0x80009460 0x00397feb
0x402ce4 <gRadioInit_RegReplacement_c+248>: 0x80009464 0x00180358 0x8000947c 0x00000455
0x402cf4 <gRadioInit_RegReplacement_c+264>: 0x800094e0 0x00000001 0x800094e4 0x00020003
0x402d04 <gRadioInit_RegReplacement_c+280>: 0x800094e8 0x00040014 0x800094ec 0x00240034
0x402d14 <gRadioInit_RegReplacement_c+296>: 0x800094f0 0x00440144 0x800094f4 0x02440344
0x402d24 <gRadioInit_RegReplacement_c+312>: 0x800094f8 0x04440544 0x80009470 0x0ee7fc00
0x402d34 <gRadioInit_RegReplacement_c+328>: 0x8000981c 0x00000082 0x80009828 0x0000002a
0x402d44 <RadioInit>: 0x0006b5f8 0x0015000c 0x21fa4f39 0xf7fd0089
(gdb) x/128x $r5
0x405210 <ram_init_val>: 0x00000000 0x00000000 0x00000000 0x00000000
0x405220 <buffer_radio_init+8>: 0x00000000 0x00000000 0x80009400 0x00000017
0x405230 <gRadioTOCCal5+8>: 0x8000a050 0x00000000 0x8000a054 0x00000000
0x405240 <gRadioTOCCal5+24>: 0x80003048 0x00000f00 0x00000000 0x00000000
0x405250 <mLineParams+4>: 0x10000108 0x03180002 0x00042000 0x30000528
0x405260 <mLineParams+20>: 0x07380006 0x0000fd01 0xc60081ff 0xb90f0000
0x405270: 0xc51e0000 0x00901200 0x05030080 0x00900480
0x405280: 0x00010180 0x00900800 0x0300fc80 0x8000900c
0x405290: 0x200400fc 0x0c800090 0x901500fc 0x03008000
0x4052a0: 0x3048c005 0x0f788000 0x304c0000 0x77078000
0x4052b0: 0x1000fb60 0x000161a8 0x8000a050 0x0000047b
0x4052c0: 0x8000a054 0x0300e07b 0x17800094 0x500300fd
0x4052d0: 0xfc8000a0 0xa0540300 0x00fc8000 0x00304805
0x4052e0: 0xf60f0080 0x01081400 0x00021000 0x20000318
0x4052f0: 0x05280004 0x00063000 0x00010738 0x00000000
0x405300: 0x00000000 0x00000000 0x00000000 0x00000000
0x405310: 0x00000000 0x00000000 0x00000000 0x00000000

View File

@ -0,0 +1,41 @@
1,6
5,4
5,6
5,6
6,3
30,5
45,3
51,9
162,6
170,7
308,6
317,6
506,8
511,7
596,7
602,7
674,9
743,8
788,8
842,9
859,9
951,9
898,10
976,12
978,19
981,13
988,30
991,17
992,12
993,16
993,19
994,15
995,19
995,19
998,30
999,38
1000,34
1000,40
1000,46
1000,47
1000,54
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

View File

@ -0,0 +1,51 @@
1000 packet bursts
64 byte payload
==================
count 995 avg lqi 19
count 1000 avg lqi 46
count 1000 avg lqi 54
count 162 avg lqi 6
count 994 avg lqi 15
count 999 avg lqi 38
count 45 avg lqi 3
count 951 avg lqi 9
count 992 avg lqi 12
count 991 avg lqi 17
count 1000 avg lqi 47
count 1000 avg lqi 40
count 995 avg lqi 19
count 1000 avg lqi 34
count 674 avg lqi 9
count 976 avg lqi 12
count 981 avg lqi 13
count 859 avg lqi 9
lqi_total = 0
lqi_total = 0
count 5 avg lqi 6
lqi_total = 0
count 788 avg lqi 8
lqi_total = 0
count 743 avg lqi 8
count 308 avg lqi 6
count 317 avg lqi 6
count 30 avg lqi 5
count 1 avg lqi 6
count 842 avg lqi 9
count 898 avg lqi 10
lqi_total = 0
count 6 avg lqi 3
count 5 avg lqi 6
count 596 avg lqi 7
count 511 avg lqi 7
count 602 avg lqi 7
count 988 avg lqi 30
count 998 avg lqi 30
count 978 avg lqi 19
lqi_total = 0
count 170 avg lqi 7
count 5 avg lqi 4
count 506 avg lqi 8
count 993 avg lqi 16
count 993 avg lqi 19
count 51 avg lqi 9

View File

@ -0,0 +1,7 @@
grep count 1000pkt-64len.txt | cut -d ' ' -f 2,5 | sed 's/ /,/g' |
sort -n > 1000pkt-64len.csv
then:
asy plot.asy
gv plot.eps

View File

@ -0,0 +1,31 @@
import graph;
size(350,250,IgnoreAspect);
file fin=input("./1000pkt-64len.csv");
real[][] A=dimension(csv(fin),0,2);
real[][] pdr=transpose(A);
int[] lqi = sequence(100);
int f (int lqi)
{
if(lqi <= 6) {
return (int)((real)lqi*.8);
} else if(lqi <= 11) {
return (lqi-6)*18;
} else if (lqi <= 30) {
return (int)((real)(lqi-11) * 0.5 + 90);
} else {
return 100;
}
}
int[] f_lqi = map(f,lqi);
draw(graph(pdr[1],pdr[0]/10));
draw(graph(lqi,f_lqi), red);
ylimits(0,100);
xlimits(0,100);
xaxis("\rm LQI",BottomTop,LeftTicks("$%.1f$",10,begin=false,end=false,extend=true,pTick=dotted));
yaxis("\rm Packet Deliver Ratio (\%)",LeftRight,RightTicks("$%#.1f$",8,begin=false,end=false,extend=true,pTick=dotted, ptick=dotted));

Binary file not shown.

284
cpu/mc1322x/doc/radioinit Normal file
View File

@ -0,0 +1,284 @@
Entries in ram are processed by SMACinitfrommemory and executeentry
(which does the work). I suspect that these entries are loaded in from
the rom from the rom_data_init call in the beginning stub. For now
we'll do the simple thing of performing the actions they do, but for
real it would be better to load out from ROM and execute the entries
in a similar way. That way, if the cal data changes in the ROM, our
code should still work.
When radioinit first starts it seems to do checks for a 24MHZ clock
and if the buck should be enabled. Assuming 24MHZ and no buck the next
things it does is 5 entries in cal1 (40 bytes, 4 bytes per word, = 10
words, 2 words per entry = 5 entrys)
0x80003048
0x00000f78
0x8000304c
0x00607707
the next entry is zero addr with val 0x000161a8... this is a delay
entry. Loop here 0x000161a8 times. then return.
0x00000000
0x000161a8
Then two more memory stuffs:
0x8000a050
0x0000047b
0x8000a054
0x0000007b
then it seems like the emulator dies on the stack munging they do at
the end of InitFromMemory... but I think I've decoded the entry
enough to figure out the rest.
then they do one entry of r4 base + 48 (gRadioTOCCal2_24MHz_c[0])
0x80009000
0x80050100
then they do 11 entries in cal3 and reg replacment (first two have delays)
0x402b8c <gRadioTOCCal3_c>: 0x80009400 0x00020017 0x80009a04 0x8185a0a4
0x402b9c <gRadioTOCCal3_c+16>: 0x80009a00 0x8c900025 0x00000000 0x00011194
0x402bac <gRadioTOCCal3_c+32>: 0x80009a00 0x8c900021 0x80009a00 0x8c900027
0x402bbc <gRadioTOCCal3_c+48>: 0x00000000 0x00011194 0x80009a00 0x8c90002b
0x402bcc <gRadioTOCCal3_c+64>: 0x80009a00 0x8c90002f 0x00000000 0x00011194
0x402bdc <gRadioTOCCal3_c+80>: 0x80009a00 0x8c900000
then 4 entries from r5+24 (buffer_radio_init and cal5)
0x80009400 0x00000017
0x405230 <gRadioTOCCal5+8>: 0x8000a050 0x00000000 0x8000a054 0x00000000
0x405240 <gRadioTOCCal5+24>: 0x80003048 0x00000f00
then 43 entries from r4+152 (reg replacement)
0x402bec <gRadioInit_RegReplacement_c>: 0x80004118 0x00180012 0x80009204 0x00000605
0x402bfc <gRadioInit_RegReplacement_c+16>: 0x80009208 0x00000504 0x8000920c 0x00001111
0x402c0c <gRadioInit_RegReplacement_c+32>: 0x80009210 0x0fc40000 0x80009300 0x20046000
0x402c1c <gRadioInit_RegReplacement_c+48>: 0x80009304 0x4005580c 0x80009308 0x40075801
0x402c2c <gRadioInit_RegReplacement_c+64>: 0x8000930c 0x4005d801 0x80009310 0x5a45d800
0x402c3c <gRadioInit_RegReplacement_c+80>: 0x80009314 0x4a45d800 0x80009318 0x40044000
0x402c4c <gRadioInit_RegReplacement_c+96>: 0x80009380 0x00106000 0x80009384 0x00083806
0x402c5c <gRadioInit_RegReplacement_c+112>: 0x80009388 0x00093807 0x8000938c 0x0009b804
0x402c6c <gRadioInit_RegReplacement_c+128>: 0x80009390 0x000db800 0x80009394 0x00093802
0x402c7c <gRadioInit_RegReplacement_c+144>: 0x8000a008 0x00000015 0x8000a018 0x00000002
0x402c8c <gRadioInit_RegReplacement_c+160>: 0x8000a01c 0x0000000f 0x80009424 0x0000aaa0
0x402c9c <gRadioInit_RegReplacement_c+176>: 0x80009434 0x01002020 0x80009438 0x016800fe
0x402cac <gRadioInit_RegReplacement_c+192>: 0x8000943c 0x8e578248 0x80009440 0x000000dd
0x402cbc <gRadioInit_RegReplacement_c+208>: 0x80009444 0x00000946 0x80009448 0x0000035a
0x402ccc <gRadioInit_RegReplacement_c+224>: 0x8000944c 0x00100010 0x80009450 0x00000515
0x402cdc <gRadioInit_RegReplacement_c+240>: 0x80009460 0x00397feb 0x80009464 0x00180358
0x402cec <gRadioInit_RegReplacement_c+256>: 0x8000947c 0x00000455 0x800094e0 0x00000001
0x402cfc <gRadioInit_RegReplacement_c+272>: 0x800094e4 0x00020003 0x800094e8 0x00040014
0x402d0c <gRadioInit_RegReplacement_c+288>: 0x800094ec 0x00240034 0x800094f0 0x00440144
0x402d1c <gRadioInit_RegReplacement_c+304>: 0x800094f4 0x02440344 0x800094f8 0x04440544
0x402d2c <gRadioInit_RegReplacement_c+320>: 0x80009470 0x0ee7fc00 0x8000981c 0x00000082
0x402d3c <gRadioInit_RegReplacement_c+336>: 0x80009828 0x0000002a
then flash init. (hrmm.. this might be important)
then flyback init.
then maybe buckbypass sequence... 4 entries from r4+16
0x402b64 <gBuckByPass_c>: 0x80003000 0x00000018 0x80003048 0x00000f04
0x402b74 <gBuckByPass_c+16>: 0x00000000 0x000161a8 0x80003048 0x00000ffc
RadioInit is (roughly):
SMAC_InitFromMemory(gRadioTOCCal1,40);
SMAC_InitFromMemory(gRadioTOCCal2_24MHz_c,8);
SMAC_InitFromMemory(gRadioTOCCal3_c,88);
SMAC_InitFromMemory(gRadioTOCCal5,32);
SMAC_InitFromMemory(gRadioInit_RegReplacement_c,344);
SMAC_InitFromFlash(0x1F000);
SMAC_InitFlybackSettings();
SMAC_InitFromMemory(gBuckByPass_c,16);
fill_ram_struct(&u8RamValues);
uint8_t i;
uint8_t buffer_radio_init[16];
for(i=0; i<16; i++) {
buffer_radio_init[i] = get_ctov(i,u8RamValues[3]);
}
Some kind of success!
This replacment works:
// RadioInit(PLATFORM_CLOCK, gDigitalClock_PN_c, u32LoopDiv); // need this to work
/* my replacment for RadioInit, flyback and vreg have been separated out */
radio_init();
// SMAC_InitFromMemory(gRadioTOCCal1,40);
// *(volatile uint32_t *)0x80009000 = 0x80050100;
// SMAC_InitFromMemory(gRadioTOCCal2_24MHz_c,8);
// SMAC_InitFromMemory(gRadioTOCCal3_c,88);
// SMAC_InitFromMemory(gRadioTOCCal5,32);
// SMAC_InitFromMemory(gRadioInit_RegReplacement_c,344);
// SMAC_InitFromFlash(0x1F000);
// SMAC_InitFlybackSettings();
flyback_init();
// SMAC_InitFromMemory(gBuckByPass_c,16);
vreg_init();
*((uint32_t *)&u8RamValues) = 0x4c20030a;
fill_ram_struct(&u8RamValues);
for(j=0; j<16; j++) {
// buffer_radio_init[j] = get_ctov(j,u8RamValues[3]);
buffer_radio_init[j] = get_ctov(j,0x4c); //0x4c loads the right values into buffer_radio_init... but why isn't RamValues correct?
}
Which means my radio_init, and vreg_init are good. It also means that
my intreprtation of buffer_radio_init is correct. It may also mean
that u8RamValues isn't important since I just set it's value.
That means I only have InitFromFlash to replace now!
Actually, I should test if that is necessary --- I still find it a
little hard to believe that they put essential data on NVM --- except
they could set codeprotect so that clods won't erase it on accident.
See PLM/LibInterface/NVM.h for some docs. Looks like they put a
standard SST, ST, or Atmel spi flash in there (note the comment about
continuous read mode).
MACPHY.a might use a ROM service for the flash init:
0000f97c g F *ABS* 00000000 InitFromFlash
ac: 4668 mov r0, sp
ae: f7ff fffe bl 0 <GetInitTranslationTablePtr>
b2: 4669 mov r1, sp
b4: 780a ldrb r2, [r1, #0]
b6: 0001 lsls r1, r0, #0
b8: 20f8 movs r0, #248
ba: 0240 lsls r0, r0, #9
bc: f7ff fffe bl 0 <InitFromFlash>
uint32_t InitFromFlash(uint32_t nvmAddress, uint32_t nLength);
Which looks like InitFromFlash(0x1F00,?);
Good news! It doesn't look like InitFromFlash is necessary. It might
just be a hook for them to patch the init that is grabbed from rom or
something.
Checking if buffer_radio_init is important. If so, then I need to
figure out how it's used and, preferably, what it means.
So buffer_radio_init is necessary for their code to work. I'm not sure
if it is necessary for the radio of if it's necessary for there app.
Now I need to figure these out:
(void)MLMEPAOutputAdjust(gu8CurrentPowerLevel);
MLMESetChannelRequest((channel_num_t)gu8CurrentChannel);
#define gPowerLevel_m30dBm_c 0x00
#define gPowerLevel_m28dBm_c 0x01
#define gPowerLevel_m26dBm_c 0x02
#define gPowerLevel_m24dBm_c 0x03
#define gPowerLevel_m22dBm_c 0x04
#define gPowerLevel_m20dBm_c 0x05
#define gPowerLevel_m18dBm_c 0x06
#define gPowerLevel_m16dBm_c 0x07
#define gPowerLevel_m14dBm_c 0x08
#define gPowerLevel_m12dBm_c 0x09
#define gPowerLevel_m10dBm_c 0x0a
#define gPowerLevel_m8dBm_c 0x0b
#define gPowerLevel_m6dBm_c 0x0c
#define gPowerLevel_m4dBm_c 0x0d
#define gPowerLevel_m2dBm_c 0x0e
#define gPowerLevel_0dBm_c 0x0f
#define gPowerLevel_2dBm_c 0x10
#define gPowerLevel_4dBm_c 0x11
#define gPowerLevel_6dBm_c 0x12
gu8CurrentPowerLevel is set to gPowerLevel_0dBm_c = 0x0f
some kind of look-up table for setpower
004037e4 <gPSMVAL_c>:
4037e4: 0000080f .word 0x0000080f
4037e8: 0000080f .word 0x0000080f
4037ec: 0000080f .word 0x0000080f
4037f0: 0000080f .word 0x0000080f
4037f4: 0000081f .word 0x0000081f
4037f8: 0000081f .word 0x0000081f
4037fc: 0000081f .word 0x0000081f
403800: 0000080f .word 0x0000080f
403804: 0000080f .word 0x0000080f
403808: 0000080f .word 0x0000080f
40380c: 0000001f .word 0x0000001f
403810: 0000000f .word 0x0000000f
403814: 0000000f .word 0x0000000f
403818: 00000816 .word 0x00000816
40381c: 0000001b .word 0x0000001b
403820: 0000000b .word 0x0000000b
403824: 00000802 .word 0x00000802
403828: 00000817 .word 0x00000817
40382c: 00000003 .word 0x00000003
00403830 <gPAVAL_c>:
403830: 000022c0 .word 0x000022c0
403834: 000022c0 .word 0x000022c0
403838: 000022c0 .word 0x000022c0
40383c: 00002280 .word 0x00002280
403840: 00002303 .word 0x00002303
403844: 000023c0 .word 0x000023c0
403848: 00002880 .word 0x00002880
40384c: 000029f0 .word 0x000029f0
403850: 000029f0 .word 0x000029f0
403854: 000029f0 .word 0x000029f0
403858: 000029c0 .word 0x000029c0
40385c: 00002bf0 .word 0x00002bf0
403860: 000029f0 .word 0x000029f0
403864: 000028a0 .word 0x000028a0
403868: 00002800 .word 0x00002800
40386c: 00002ac0 .word 0x00002ac0
403870: 00002880 .word 0x00002880
403874: 00002a00 .word 0x00002a00
403878: 00002b00 .word 0x00002b00
0040387c <gAIMVAL_c>:
40387c: 000123a0 .word 0x000123a0
403880: 000163a0 .word 0x000163a0
403884: 0001a3a0 .word 0x0001a3a0
403888: 0001e3a0 .word 0x0001e3a0
40388c: 000223a0 .word 0x000223a0
403890: 000263a0 .word 0x000263a0
403894: 0002a3a0 .word 0x0002a3a0
403898: 0002e3a0 .word 0x0002e3a0
40389c: 000323a0 .word 0x000323a0
4038a0: 000363a0 .word 0x000363a0
4038a4: 0003a3a0 .word 0x0003a3a0
4038a8: 0003a3a0 .word 0x0003a3a0
4038ac: 0003e3a0 .word 0x0003e3a0
4038b0: 000423a0 .word 0x000423a0
4038b4: 000523a0 .word 0x000523a0
4038b8: 000423a0 .word 0x000423a0
4038bc: 0004e3a0 .word 0x0004e3a0
4038c0: 0004e3a0 .word 0x0004e3a0
4038c4: 0004e3a0 .word 0x0004e3a0
Ok, rftest-rx and tx are working but the range isn't very good. I
suspect that InitFromFlash is a factory trim for each part. Since I'm
not doing that then the range and reliability are suffering. Getting
the NVM to work should probably be my next step.
Debugging with JLink has shown there absolutely is init entries in the
flash set in the factory that are important. e.g. this is where the
0x00607707 number get turned into something more like 0x00685...

44889
cpu/mc1322x/doc/ws-dis Normal file

File diff suppressed because it is too large Load Diff

431
cpu/mc1322x/lib/printf.c Normal file
View File

@ -0,0 +1,431 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id$
*/
/**
* \file printf-stdarg.c
*
* \brief sprintf functions to replace newlib for AVR32 UC3.
*
* \author $Author: umanzoli $
*
* Created on : 17-mar-2009
*
* $Id$
*/
/*
* Copyright 2001, 2002 Georges Menie (www.menie.org)
* stdarg version contributed by Christian Ettinger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <mc1322x.h>
#include <stdint.h>
#define __putc(x) uart1_putc(x)
/**
* Structure to hold data to be passed to print function with format.
* Aka print context.
*/
struct __print_ctx_t
{
//! pointer to next char to be filled.
char* _ptr;
//! maximum length of the buffer.
size_t _max_len;
};
typedef struct __print_ctx_t _print_ctx_t;
/**
* Pad string to right
*/
#define _PRINTFMT_PAD_RIGHT 1
/**
* Pad the number with zeroes
*/
#define _PRINTFMT_PAD_ZERO 2
/**
* The following should be enough for 32 bit int
*/
#define _PRINTFMT_INT_BUF_LEN 12
/**
* Print a character to stdout (if string is null)
* otherwise, put the character at the end of the provided string.
*/
static void __print_char( _print_ctx_t* ctx, char c )
{
if( ctx ) {
if( c == '\r' || c == '\n' ) {
if( ctx->_max_len > 1 ) {
*(ctx->_ptr)='\r';
ctx->_max_len--;
ctx->_ptr++;
*(ctx->_ptr)='\n';
ctx->_max_len--;
ctx->_ptr++;
} else {
*(ctx->_ptr)='\n';
ctx->_max_len--;
ctx->_ptr++;
}
} else {
if( ctx->_max_len ) {
*(ctx->_ptr)=c;
ctx->_max_len--;
ctx->_ptr++;
}
}
} else {
__putc( (uint8_t)c );
}
}
/**
* Print a string to a given string.
*/
static int __print_str( _print_ctx_t* ctx,
const char *string,
int width,
int pad,
int print_limit,
bool is_number )
{
int pc = 0;
int padchar = ' ';
int i, len;
if( width > 0 ) {
register int len = 0;
register const char *ptr;
for( ptr = string; *ptr; ++ptr )
++len;
if( len >= width )
width = 0;
else
width -= len;
if( pad & _PRINTFMT_PAD_ZERO )
padchar = '0';
}
if( !( pad & _PRINTFMT_PAD_RIGHT ) ) {
for( ; width > 0; --width ) {
__print_char( ctx, padchar );
++pc;
}
}
// The string to print is not the result of a number conversion to ascii.
if( false == is_number ) {
// For a string, printlimit is the max number of characters to display.
for( ; print_limit && *string; ++string, --print_limit ) {
__print_char( ctx, *string );
++pc;
}
}
// The string to print represents an integer number.
if( true == is_number ) {
// In this case, printlimit is the min number of digits to print.
// If the length of the number to print is less than the min nb of i
// digits to display, we add 0 before printing the number.
len = strlen( string );
if( len < print_limit ) {
i = print_limit - len;
for( ; i; i-- ) {
__print_char( ctx, '0' );
++pc;
}
}
}
/*
* Else: The string to print is not the result of a number conversion to ascii.
* For a string, printlimit is the max number of characters to display.
*/
for( ; print_limit && *string; ++string, --print_limit ) {
__print_char( ctx, *string );
++pc;
}
for( ; width > 0; --width ) {
__print_char( ctx, padchar );
++pc;
}
return pc;
}
/**
* Print a number to the given string, with the given base.
*/
static int __print_int( _print_ctx_t* ctx,
int i,
int b,
int sg,
int width,
int pad,
int letbase,
int print_limit )
{
char print_buf[_PRINTFMT_INT_BUF_LEN];
register char *s;
register int t, neg = 0, pc = 0;
register unsigned int u = i;
if( i == 0 ) {
print_buf[0] = '0';
print_buf[1] = '\0';
return __print_str( ctx, print_buf, width, pad, print_limit, true );
}
if( sg && b == 10 && i < 0 ) {
neg = 1;
u = -i;
}
s = print_buf + _PRINTFMT_INT_BUF_LEN - 1;
*s = '\0';
while( u ) {
t = u % b;
if( t >= 10 )
t += letbase - '0' - 10;
*--s = t + '0';
u /= b;
}
if( neg ) {
if( width && ( pad & _PRINTFMT_PAD_ZERO ) ) {
__print_char( ctx, '-' );
++pc;
--width;
} else {
*--s = '-';
}
}
return pc + __print_str( ctx, s, width, pad, print_limit, true );
}
/*
#if __GNUC__
int fprintf( __FILE *stream, const char *format, ... )
{
return 0;
}
#endif
*/
/**
* Print the given arguments, with given format onto string out.
*/
static int __print_fmt( _print_ctx_t* ctx, const char *format, va_list args )
{
int width;
int pad;
int print_limit;
int pc = 0;
char scr[2];
for( ; *format != 0; ++format ) {
if( *format == '%' ) {
++format;
width = pad = print_limit = 0;
if( *format == '\0' ) {
break;
}
if( *format == '%' ) {
goto out;
}
if( *format == '-' ) {
++format;
pad = _PRINTFMT_PAD_RIGHT;
}
while( *format == '0' ) {
++format;
pad |= _PRINTFMT_PAD_ZERO;
}
for( ; *format >= '0' && *format <= '9'; ++format ) {
width *= 10;
width += *format - '0';
}
if( *format == '.' ) {
++format;
for( ; *format >= '0' && *format <= '9'; ++format ) {
print_limit *= 10;
print_limit += *format - '0';
}
}
if( 0 == print_limit ) {
print_limit--;
}
if( *format == 'l' ) {
++format;
}
if( *format == 's' ) {
register char *s = (char *) va_arg( args, int );
pc += __print_str( ctx,
s ? s : "(null)",
width,
pad,
print_limit,
false );
continue;
}
if( *format == 'd' ) {
pc += __print_int( ctx, va_arg( args, int ), 10, 1, width, pad, 'a', print_limit );
continue;
}
if( ( *format == 'x' ) || ( *format == 'p' ) ) {
pc += __print_int( ctx, va_arg( args, int ), 16, 0, width, pad, 'a', print_limit );
continue;
}
if( *format == 'X' ) {
pc += __print_int( ctx, va_arg( args, int ), 16, 0, width, pad, 'A', print_limit );
continue;
}
if( *format == 'u' ) {
pc += __print_int( ctx, va_arg( args, int ), 10, 0, width, pad, 'a', print_limit );
continue;
}
if( *format == 'c' ) {
// char are converted to int then pushed on the stack
scr[0] = (char) va_arg( args, int );
scr[1] = '\0';
pc += __print_str( ctx, scr, width, pad, print_limit, false );
continue;
}
} else {
out:
__print_char( ctx, *format );
++pc;
}
}
if( ctx && ctx->_max_len ) {
*(ctx->_ptr) = '\0';
}
return pc;
}
#define BLOCK_MEM_SIZE 1024
int sprintf( char *out, const char *format, ... )
{
int retval = 0;
_print_ctx_t ctx;
va_list args;
ctx._ptr = out;
ctx._max_len = BLOCK_MEM_SIZE;
va_start( args, format );
retval = __print_fmt( &ctx, format, args );
va_end( args );
return retval;
}
int printf( const char *format, ... )
{
int retval = 0;
// memory_t* buf;
va_list args;
/*
buf = memory_alloc( 10 );
if( buf ) {
_print_ctx_t ctx;
ctx._ptr = (char*)buf->_data;
ctx._max_len = BLOCK_MEM_SIZE;
va_start( args, format );
retval = __print_fmt( &ctx, format, args );
va_end( args );
buf->_len = strlen( (const char*)buf->_data );
// LCD_WriteString( ll, buf );
ll++;
ll &= 0x03;
if( uart_task_send( buf ) == false ) {
memory_free( buf );
}
}
*/
va_start( args, format );
retval = __print_fmt( NULL, format, args );
va_end( args );
return retval;
}

View File

@ -0,0 +1,41 @@
# Hey Emacs, this is a -*- makefile -*-
CFLAGS += -I$(MC1322X)/src
ISR ?= $(MC1322X)/src/isr.o
SRC_OBJS += $(MC1322X)/src/default_lowlevel.o $(ISR)
# Two libraries, one with ROM variable space reserved, one without
START_ROMVARS ?= $(MC1322X)/src/start-romvars.o
SRCLIB_ROMVARS = $(MC1322X)/src/src-romvars.a
$(SRCLIB_ROMVARS): $(SRC_OBJS) $(START_ROMVARS)
$(call pretty,AR,$@)
@rm -f $@
$Q$(AR) $(ARFLAGS) $@ $^
START ?= $(MC1322X)/src/start.o
SRCLIB = $(MC1322X)/src/src.a
$(SRCLIB): $(SRC_OBJS) $(START)
$(call pretty,AR,$@)
@rm -f $@
$Q$(AR) $(ARFLAGS) $@ $^
# ISR is built without thumb
$(ISR): $(ISR:.o=.c)
$(call pretty,CC (isr),$@)
$Q$(CC) $(CFLAGS) -MMD -c -o $@ $<
@$(FINALIZE_DEPENDENCY)
# start-romvars.o is built from start.S with the right flags
$(MC1322X)/src/start-romvars.o: $(MC1322X)/src/start.S
$(call pretty,CC (romvars),$@)
$Q$(CC) $(AFLAGS) -MMD -DUSE_ROM_VARS -c -o $@ $<
@$(FINALIZE_DEPENDENCY)
ifneq ($(MAKECMDGOALS),clean)
-include $(wildcard $(MC1322X)/src/*.d)
endif
clean::
rm -f $(MC1322X)/src/*.{o,d,a}