summaryrefslogtreecommitdiff
path: root/firmware/test/i2c/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/i2c/main.c')
-rw-r--r--firmware/test/i2c/main.c128
1 files changed, 128 insertions, 0 deletions
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
24int strlen(unsigned char* str)
25{
26 int i=0;
27 while (*str++)
28 i++;
29 return i;
30}
31
32int 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
120extern const void stack(void);
121
122const 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};