diff options
-rw-r--r-- | firmware/mas.c | 164 | ||||
-rw-r--r-- | firmware/mas.h | 54 | ||||
-rw-r--r-- | firmware/test/i2c/Makefile | 44 | ||||
-rw-r--r-- | firmware/test/i2c/app.lds | 23 | ||||
-rw-r--r-- | firmware/test/i2c/crt0.S | 49 | ||||
-rw-r--r-- | firmware/test/i2c/main.c | 128 |
6 files changed, 462 insertions, 0 deletions
diff --git a/firmware/mas.c b/firmware/mas.c new file mode 100644 index 0000000000..decfff612b --- /dev/null +++ b/firmware/mas.c | |||
@@ -0,0 +1,164 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "i2c.h" | ||
20 | #include "debug.h" | ||
21 | #include "mas.h" | ||
22 | |||
23 | /* note: 'len' is number of 32-bit words, not number of bytes! */ | ||
24 | int mas_readmem(int bank, int addr, unsigned long* dest, int len) | ||
25 | { | ||
26 | int i; | ||
27 | unsigned char buf[16]; | ||
28 | |||
29 | i=0; | ||
30 | buf[i++] = MAS_DATA_WRITE; | ||
31 | buf[i++] = bank?0xf0:0xe0; | ||
32 | buf[i++] = 0x00; | ||
33 | buf[i++] = (len & 0xff00) >> 8; | ||
34 | buf[i++] = len & 0xff; | ||
35 | buf[i++] = (addr & 0xff00) >> 8; | ||
36 | buf[i++] = addr & 0xff; | ||
37 | |||
38 | /* send read command */ | ||
39 | if (i2c_write(MAS_DEV_WRITE,buf,i)) | ||
40 | { | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | return mas_devread(dest, len); | ||
45 | } | ||
46 | |||
47 | /* note: 'len' is number of 32-bit words, not number of bytes! */ | ||
48 | int mas_writemem(int bank, int addr, unsigned long* src, int len) | ||
49 | { | ||
50 | int i, j; | ||
51 | unsigned char buf[60]; | ||
52 | unsigned char* ptr = (unsigned char*)src; | ||
53 | |||
54 | i=0; | ||
55 | buf[i++] = MAS_DATA_WRITE; | ||
56 | buf[i++] = bank; | ||
57 | buf[i++] = 0x00; | ||
58 | buf[i++] = (len & 0xff00) >> 8; | ||
59 | buf[i++] = len & 0xff; | ||
60 | buf[i++] = (addr & 0xff00) >> 8; | ||
61 | buf[i++] = addr & 0xff; | ||
62 | |||
63 | j = 0; | ||
64 | while(len--) { | ||
65 | buf[i++] = ptr[j*4+1]; | ||
66 | buf[i++] = ptr[j*4+0]; | ||
67 | buf[i++] = 0; | ||
68 | buf[i++] = ptr[j*4+2]; | ||
69 | j += 4; | ||
70 | } | ||
71 | |||
72 | /* send write command */ | ||
73 | if (i2c_write(MAS_DEV_WRITE,buf,i)) | ||
74 | { | ||
75 | return -1; | ||
76 | } | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | int mas_readreg(int reg) | ||
82 | { | ||
83 | int i; | ||
84 | unsigned char buf[16]; | ||
85 | |||
86 | i=0; | ||
87 | buf[i++] = MAS_DATA_WRITE; | ||
88 | buf[i++] = 0xd0 | reg >> 4; | ||
89 | buf[i++] = (reg & 0x0f) << 4; | ||
90 | |||
91 | /* send read command */ | ||
92 | if (i2c_write(MAS_DEV_WRITE,buf,i)) | ||
93 | { | ||
94 | return -1; | ||
95 | } | ||
96 | |||
97 | if(mas_devread((unsigned long *)buf, 1)) | ||
98 | { | ||
99 | return -2; | ||
100 | } | ||
101 | |||
102 | return buf[0] | buf[1] << 8 | buf[3] << 16; | ||
103 | } | ||
104 | |||
105 | int mas_writereg(int reg, unsigned short val) | ||
106 | { | ||
107 | int i; | ||
108 | unsigned char buf[16]; | ||
109 | |||
110 | i=0; | ||
111 | buf[i++] = MAS_DATA_WRITE; | ||
112 | buf[i++] = 0x90 | reg >> 4; | ||
113 | buf[i++] = ((reg & 0x0f) << 4) | (val & 0x0f); | ||
114 | buf[i++] = (val >> 12) & 0xff; | ||
115 | buf[i++] = (val >> 4) & 0xff; | ||
116 | |||
117 | /* send write command */ | ||
118 | if (i2c_write(MAS_DEV_WRITE,buf,i)) | ||
119 | { | ||
120 | return -1; | ||
121 | } | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | /* note: 'len' is number of 32-bit words, not number of bytes! */ | ||
126 | int mas_devread(unsigned long *dest, int len) | ||
127 | { | ||
128 | unsigned char* ptr = (unsigned char*)dest; | ||
129 | int ret = 0; | ||
130 | int i; | ||
131 | |||
132 | /* handle read-back */ | ||
133 | i2c_start(); | ||
134 | i2c_outb(MAS_DEV_WRITE); | ||
135 | if (i2c_getack()) { | ||
136 | i2c_outb(MAS_DATA_READ); | ||
137 | if (i2c_getack()) { | ||
138 | i2c_start(); | ||
139 | i2c_outb(MAS_DEV_READ); | ||
140 | if (i2c_getack()) { | ||
141 | for (i=0;len;i++) { | ||
142 | len--; | ||
143 | ptr[i*4+1] = i2c_inb(0); | ||
144 | ptr[i*4+0] = i2c_inb(0); | ||
145 | ptr[i*4+3] = i2c_inb(0); | ||
146 | if(len) | ||
147 | ptr[i*4+2] = i2c_inb(0); | ||
148 | else | ||
149 | ptr[i*4+2] = i2c_inb(1); /* NAK the last byte */ | ||
150 | } | ||
151 | } | ||
152 | else | ||
153 | ret = -3; | ||
154 | } | ||
155 | else | ||
156 | ret = -2; | ||
157 | } | ||
158 | else | ||
159 | ret = -1; | ||
160 | |||
161 | i2c_stop(); | ||
162 | |||
163 | return ret; | ||
164 | } | ||
diff --git a/firmware/mas.h b/firmware/mas.h new file mode 100644 index 0000000000..65e23f1498 --- /dev/null +++ b/firmware/mas.h | |||
@@ -0,0 +1,54 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef _MAS_H_ | ||
20 | #define _MAS_H_ | ||
21 | |||
22 | #define MAS_BANK_D0 0 | ||
23 | #define MAS_BANK_D1 1 | ||
24 | |||
25 | /* | ||
26 | MAS I2C defs | ||
27 | */ | ||
28 | #define MAS_ADR 0x3a | ||
29 | #define MAS_DEV_WRITE (MAS_ADR | 0x00) | ||
30 | #define MAS_DEV_READ (MAS_ADR | 0x01) | ||
31 | |||
32 | /* registers..*/ | ||
33 | #define MAS_DATA_WRITE 0x68 | ||
34 | #define MAS_DATA_READ 0x69 | ||
35 | #define MAS_CONTROL 0x6a | ||
36 | |||
37 | /* | ||
38 | * MAS register | ||
39 | */ | ||
40 | #define MAS_REG_DCCF 0x8e | ||
41 | #define MAS_REG_MUTE 0xaa | ||
42 | #define MAS_REG_PIODATA 0xc8 | ||
43 | #define MAS_REG_StartUpConfig 0xe6 | ||
44 | #define MAS_REG_KPRESCALE 0xe7 | ||
45 | #define MAS_REG_KBASS 0x6b | ||
46 | #define MAS_REG_KTREBLE 0x6f | ||
47 | |||
48 | int mas_readmem(int bank, int addr, unsigned long* dest, int len); | ||
49 | int mas_writemem(int bank, int addr, unsigned long* src, int len); | ||
50 | int mas_devread(unsigned long *buf, int len); | ||
51 | int mas_readreg(int reg); | ||
52 | int mas_writereg(int reg, unsigned short val); | ||
53 | |||
54 | #endif | ||
diff --git a/firmware/test/i2c/Makefile b/firmware/test/i2c/Makefile new file mode 100644 index 0000000000..831299f787 --- /dev/null +++ b/firmware/test/i2c/Makefile | |||
@@ -0,0 +1,44 @@ | |||
1 | CC = sh-elf-gcc | ||
2 | LD = sh-elf-ld | ||
3 | AR = sh-elf-ar | ||
4 | AS = sh-elf-as | ||
5 | OC = sh-elf-objcopy | ||
6 | |||
7 | INCLUDES=-I../../ | ||
8 | |||
9 | CFLAGS = -g -Wall -m1 -nostdlib -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns -fno-builtin $(INCLUDES) | ||
10 | AFLAGS += -small -relax | ||
11 | |||
12 | OBJS= crt0.o main.o ../../lcd.o ../../i2c.o ../../mas.o ../../debug.o | ||
13 | |||
14 | %.o: %.S | ||
15 | $(CC) -o $@ $(CFLAGS) $(INCLUDES) $(DEFS) -c $< | ||
16 | |||
17 | |||
18 | all : archos.mod | ||
19 | |||
20 | main.o: main.c | ||
21 | |||
22 | archos.elf : $(OBJS) app.lds | ||
23 | $(CC) -nostartfiles -o archos.elf $(OBJS) -lgcc -Tapp.lds -Wl,-Map,archos.map | ||
24 | |||
25 | archos.bin : archos.elf | ||
26 | $(OC) -O binary archos.elf archos.bin | ||
27 | |||
28 | archos.asm: archos.bin | ||
29 | sh2d -sh1 archos.bin > archos.asm | ||
30 | |||
31 | archos.mod : archos.bin | ||
32 | scramble archos.bin archos.mod | ||
33 | |||
34 | archos.mod.gz : archos.mod | ||
35 | gzip -f archos.mod | ||
36 | |||
37 | dist: | ||
38 | tar czvf dist.tar.gz Makefile main.c start.s app.lds | ||
39 | |||
40 | clean: | ||
41 | -rm -f *.x *.i *.o *.elf *.bin *.map *.mod *.bak *~ | ||
42 | |||
43 | install: | ||
44 | mount /mnt/archos; cp archos.mod /mnt/archos; umount /mnt/archos | ||
diff --git a/firmware/test/i2c/app.lds b/firmware/test/i2c/app.lds new file mode 100644 index 0000000000..4b7e5f4c6f --- /dev/null +++ b/firmware/test/i2c/app.lds | |||
@@ -0,0 +1,23 @@ | |||
1 | ENTRY(start) | ||
2 | OUTPUT_FORMAT(elf32-sh) | ||
3 | SECTIONS | ||
4 | { | ||
5 | .text 0x09018000 : | ||
6 | { | ||
7 | *(.rodata) | ||
8 | *(.text) | ||
9 | } | ||
10 | |||
11 | .data : | ||
12 | { | ||
13 | *(.data) | ||
14 | } | ||
15 | |||
16 | .bss : | ||
17 | { | ||
18 | *(.bss) | ||
19 | _end = . + 0x8000; | ||
20 | _stack = . + 0x9000; | ||
21 | _edata = .; | ||
22 | } | ||
23 | } | ||
diff --git a/firmware/test/i2c/crt0.S b/firmware/test/i2c/crt0.S new file mode 100644 index 0000000000..5f0ef2d64e --- /dev/null +++ b/firmware/test/i2c/crt0.S | |||
@@ -0,0 +1,49 @@ | |||
1 | .section .text | ||
2 | .global start | ||
3 | start: | ||
4 | mov.l stack_k,r15 | ||
5 | |||
6 | ! zero out bss | ||
7 | mov.l edata_k,r0 | ||
8 | mov.l end_k,r1 | ||
9 | mov #0,r2 | ||
10 | start_l: | ||
11 | mov.l r2,@r0 | ||
12 | add #4,r0 | ||
13 | cmp/ge r0,r1 | ||
14 | bt start_l | ||
15 | nop | ||
16 | |||
17 | #if defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY) | ||
18 | mov.l set_fpscr_k, r1 | ||
19 | jsr @r1 | ||
20 | mov #0,r4 | ||
21 | lds r3,fpscr | ||
22 | #endif /* defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */ | ||
23 | |||
24 | ! call the mainline | ||
25 | mov.l main_k,r0 | ||
26 | jsr @r0 | ||
27 | nop | ||
28 | .hoo: | ||
29 | bra .hoo | ||
30 | |||
31 | .align 2 | ||
32 | #if defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) | ||
33 | set_fpscr_k: | ||
34 | .long ___set_fpscr | ||
35 | #endif /* defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(SH4_SINGLE_ONLY) */ | ||
36 | stack_k: | ||
37 | .long _stack | ||
38 | edata_k: | ||
39 | .long _edata | ||
40 | end_k: | ||
41 | .long _end | ||
42 | main_k: | ||
43 | .long _main | ||
44 | |||
45 | #ifdef __ELF__ | ||
46 | .section .stack,"aw" | ||
47 | #else | ||
48 | .section .stack | ||
49 | #endif | ||
diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c new file mode 100644 index 0000000000..588236aff1 --- /dev/null +++ b/firmware/test/i2c/main.c | |||
@@ -0,0 +1,128 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "i2c.h" | ||
20 | #include "mas.h" | ||
21 | #include "sh7034.h" | ||
22 | #include "debug.h" | ||
23 | |||
24 | int strlen(unsigned char* str) | ||
25 | { | ||
26 | int i=0; | ||
27 | while (*str++) | ||
28 | i++; | ||
29 | return i; | ||
30 | } | ||
31 | |||
32 | int main(void) | ||
33 | { | ||
34 | char buf[40]; | ||
35 | char str[32]; | ||
36 | int i=0; | ||
37 | |||
38 | /* Clear it all! */ | ||
39 | SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER); | ||
40 | |||
41 | /* This enables the serial Rx interrupt, to be able to exit into the | ||
42 | debugger when you hit CTRL-C */ | ||
43 | SCR1 |= 0x40; | ||
44 | SCR1 &= ~0x80; | ||
45 | asm ("ldc\t%0,sr" : : "r"(0<<4)); | ||
46 | |||
47 | debugf("Olle: %d\n", 7); | ||
48 | |||
49 | i2c_init(); | ||
50 | debug("I2C Init done\n"); | ||
51 | i=mas_readmem(MAS_BANK_D1,0xff6,(unsigned long*)buf,2); | ||
52 | if (i) { | ||
53 | debugf("Error - mas_readmem() returned %d\n", i); | ||
54 | while(1); | ||
55 | } | ||
56 | |||
57 | i = buf[0] | buf[1] << 8; | ||
58 | debugf("MAS version: %x\n", i); | ||
59 | i = buf[4] | buf[5] << 8; | ||
60 | debugf("MAS revision: %x\n", i); | ||
61 | |||
62 | i=mas_readmem(MAS_BANK_D1,0xff9,(unsigned long*)buf,7); | ||
63 | if (i) { | ||
64 | debugf("Error - mas_readmem() returned %d\n", i); | ||
65 | while(1); | ||
66 | } | ||
67 | |||
68 | for(i = 0;i < 7;i++) | ||
69 | { | ||
70 | str[i*2+1] = buf[i*4]; | ||
71 | str[i*2] = buf[i*4+1]; | ||
72 | } | ||
73 | str[i*2] = 0; | ||
74 | debugf("Description: %s\n", str); | ||
75 | |||
76 | i=mas_readreg(0xe6); | ||
77 | if (i < 0) { | ||
78 | debugf("Error - mas_readreg() returned %d\n", i); | ||
79 | while(1); | ||
80 | } | ||
81 | |||
82 | debugf("Register 0xe6: %x\n", i); | ||
83 | |||
84 | |||
85 | debugf("Writing register 0xaa\n"); | ||
86 | |||
87 | i=mas_writereg(0xaa, 0x1); | ||
88 | if (i < 0) { | ||
89 | debugf("Error - mas_writereg() returned %d\n", i); | ||
90 | while(1); | ||
91 | } | ||
92 | |||
93 | i=mas_readreg(0xaa); | ||
94 | if (i < 0) { | ||
95 | debugf("Error - mas_readreg() returned %d\n", i); | ||
96 | while(1); | ||
97 | } | ||
98 | |||
99 | debugf("Register 0xaa: %x\n", i); | ||
100 | |||
101 | debugf("Writing register 0xaa again\n"); | ||
102 | |||
103 | i=mas_writereg(0xaa, 0); | ||
104 | if (i < 0) { | ||
105 | debugf("Error - mas_writereg() returned %d\n", i); | ||
106 | while(1); | ||
107 | } | ||
108 | |||
109 | i=mas_readreg(0xaa); | ||
110 | if (i < 0) { | ||
111 | debugf("Error - mas_readreg() returned %d\n", i); | ||
112 | while(1); | ||
113 | } | ||
114 | |||
115 | debugf("Register 0xaa: %x\n", i); | ||
116 | |||
117 | while(1); | ||
118 | } | ||
119 | |||
120 | extern const void stack(void); | ||
121 | |||
122 | const void* vectors[] __attribute__ ((section (".vectors"))) = | ||
123 | { | ||
124 | main, /* Power-on reset */ | ||
125 | stack, /* Power-on reset (stack pointer) */ | ||
126 | main, /* Manual reset */ | ||
127 | stack /* Manual reset (stack pointer) */ | ||
128 | }; | ||