0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// omap3530/assp/test/t_i2c.cpp
|
|
15 |
// Test code for I2C Driver
|
|
16 |
// This file is part of the Beagle Base port
|
|
17 |
//
|
|
18 |
|
|
19 |
#include <assp/omap3530_assp/omap3530_i2creg.h>
|
|
20 |
|
|
21 |
#include <kernel.h>
|
|
22 |
#include <nk_priv.h>
|
|
23 |
#include <assp.h>
|
|
24 |
|
|
25 |
DECLARE_STANDARD_EXTENSION()
|
|
26 |
{
|
|
27 |
_LIT(K, "T_I2C");
|
|
28 |
|
|
29 |
TDynamicDfcQue* dfcQueue;
|
|
30 |
TInt r = Kern::DynamicDfcQCreate(dfcQueue, 24, K);
|
|
31 |
__NK_ASSERT_ALWAYS(r == KErrNone);
|
|
32 |
|
|
33 |
I2c::TConfigPb ccb;
|
|
34 |
ccb.iUnit = I2c::E1;
|
|
35 |
ccb.iRole = I2c::EMaster;
|
|
36 |
ccb.iMode = I2c::E7Bit;
|
|
37 |
ccb.iExclusiveClient = (void*) InitExtension;
|
|
38 |
ccb.iRate = I2c::E400K;
|
|
39 |
ccb.iOwnAddress = 0x01;
|
|
40 |
ccb.iDfcQueue = dfcQueue;
|
|
41 |
ccb.iDeviceAddress = 0x4b;
|
|
42 |
I2c::THandle h4b = I2c::Open(ccb);
|
|
43 |
__NK_ASSERT_ALWAYS(h4b >= KErrNone);
|
|
44 |
|
|
45 |
ccb.iDeviceAddress = 0x49;
|
|
46 |
I2c::THandle h49 = I2c::Open(ccb);
|
|
47 |
__NK_ASSERT_ALWAYS(h49 >= KErrNone);
|
|
48 |
|
|
49 |
ccb.iUnit = I2c::E3;
|
|
50 |
ccb.iRate = I2c::E100K;
|
|
51 |
ccb.iDeviceAddress = 0x50;
|
|
52 |
I2c::THandle hEdid = I2c::Open(ccb);
|
|
53 |
__NK_ASSERT_ALWAYS(hEdid >= KErrNone);
|
|
54 |
|
|
55 |
const TUint8 KTotalRead = 128;
|
|
56 |
const TUint8 KReadPerTransfer = 16;
|
|
57 |
|
|
58 |
I2c::TTransferPb addressPhase;
|
|
59 |
addressPhase.iType = I2c::TTransferPb::EWrite;
|
|
60 |
addressPhase.iLength = 1;
|
|
61 |
|
|
62 |
I2c::TTransferPb dataPhase;
|
|
63 |
dataPhase.iType = I2c::TTransferPb::ERead;
|
|
64 |
dataPhase.iLength = KReadPerTransfer;
|
|
65 |
|
|
66 |
addressPhase.iNextPhase = &dataPhase; // a two phase transfer
|
|
67 |
|
|
68 |
TUint8 data[128];
|
|
69 |
|
|
70 |
for (TUint8 address = 0; address < KTotalRead; address += KReadPerTransfer)
|
|
71 |
{
|
|
72 |
addressPhase.iData = &address;
|
|
73 |
dataPhase.iData = &data[address];
|
|
74 |
|
|
75 |
r = I2c::TransferS(hEdid, addressPhase);
|
|
76 |
if (r != KErrNone)
|
|
77 |
{
|
|
78 |
Kern::Printf("*** Check that the DVI cable is connected ***");
|
|
79 |
break;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
I2c::Close(hEdid);
|
|
84 |
|
|
85 |
for (TInt i = 0; i < KTotalRead; i += 16)
|
|
86 |
{
|
|
87 |
Kern::Printf("%02x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
|
88 |
i, data[i + 0], data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6], data[i + 7],
|
|
89 |
data[i + 8], data[i + 9], data[i + 10], data[i + 11], data[i + 12], data[i + 13], data[i + 14], data[i + 15]);
|
|
90 |
}
|
|
91 |
|
|
92 |
TUint8 rd = I2cReg::ReadB(h4b, 0x7a); Kern::Printf("expect 0x20:%d", rd);
|
|
93 |
rd = I2cReg::ReadB(h4b, 0x7a); Kern::Printf("expect 0x03:%d", rd);
|
|
94 |
rd = I2cReg::ReadB(h4b, 0x8E); Kern::Printf("expect 0xE0:%d", rd);
|
|
95 |
rd = I2cReg::ReadB(h4b, 0x91); Kern::Printf("expect 0x05:%d", rd);
|
|
96 |
rd = I2cReg::ReadB(h49, 0x01); Kern::Printf("expect 0x03:%d", rd);
|
|
97 |
rd = I2cReg::ReadB(h49, 0x02); Kern::Printf("expect 0xc0:%d", rd);
|
|
98 |
rd = I2cReg::ReadB(h49, 0x03); Kern::Printf("expect 0x00:%d", rd);
|
|
99 |
rd = I2cReg::ReadB(h49, 0x04); Kern::Printf("expect 0x00:%d", rd);
|
|
100 |
rd = I2cReg::ReadB(h49, 0x05); Kern::Printf("expect 0x00:%d", rd);
|
|
101 |
rd = I2cReg::ReadB(h49, 0x06); Kern::Printf("expect 0x00:%d", rd);
|
|
102 |
rd = I2cReg::ReadB(h49, 0x07); Kern::Printf("expect 0x00:%d", rd);
|
|
103 |
rd = I2cReg::ReadB(h49, 0x08); Kern::Printf("expect 0x00:%d", rd);
|
|
104 |
rd = I2cReg::ReadB(h49, 0x09); Kern::Printf("expect 0x00:%d", rd);
|
|
105 |
rd = I2cReg::ReadB(h49, 0x0a); Kern::Printf("expect 0x00:%d", rd);
|
|
106 |
rd = I2cReg::ReadB(h49, 0x0b); Kern::Printf("expect 0x00:%d", rd);
|
|
107 |
rd = I2cReg::ReadB(h49, 0x0c); Kern::Printf("expect 0x00:%d", rd);
|
|
108 |
rd = I2cReg::ReadB(h49, 0x0d); Kern::Printf("expect 0x00:%d", rd);
|
|
109 |
rd = I2cReg::ReadB(h49, 0x0e); Kern::Printf("expect 0x00:%d", rd);
|
|
110 |
rd = I2cReg::ReadB(h49, 0x0f); Kern::Printf("expect 0x00:%d", rd);
|
|
111 |
rd = I2cReg::ReadB(h49, 0x10); Kern::Printf("expect 0x00:%d", rd);
|
|
112 |
rd = I2cReg::ReadB(h49, 0x11); Kern::Printf("expect 0x00:%d", rd);
|
|
113 |
rd = I2cReg::ReadB(h49, 0x12); Kern::Printf("expect 0x6c:%d", rd);
|
|
114 |
rd = I2cReg::ReadB(h49, 0x13); Kern::Printf("expect 0x6c:%d", rd);
|
|
115 |
rd = I2cReg::ReadB(h49, 0x14); Kern::Printf("expect 0x00:%d", rd);
|
|
116 |
rd = I2cReg::ReadB(h49, 0x15); Kern::Printf("expect 0x00:%d", rd);
|
|
117 |
rd = I2cReg::ReadB(h49, 0x16); Kern::Printf("expect 0x00:%d", rd);
|
|
118 |
rd = I2cReg::ReadB(h49, 0x17); Kern::Printf("expect 0x0c:%d", rd);
|
|
119 |
rd = I2cReg::ReadB(h49, 0x18); Kern::Printf("expect 0x00:%d", rd);
|
|
120 |
rd = I2cReg::ReadB(h49, 0x19); Kern::Printf("expect 0x00:%d", rd);
|
|
121 |
rd = I2cReg::ReadB(h49, 0x1a); Kern::Printf("expect 0x00:%d", rd);
|
|
122 |
rd = I2cReg::ReadB(h49, 0x1b); Kern::Printf("expect 0x2b:%d", rd);
|
|
123 |
rd = I2cReg::ReadB(h49, 0x1c); Kern::Printf("expect 0x2b:%d", rd);
|
|
124 |
rd = I2cReg::ReadB(h49, 0x1d); Kern::Printf("expect 0x00:%d", rd);
|
|
125 |
rd = I2cReg::ReadB(h49, 0x1e); Kern::Printf("expect 0x00:%d", rd);
|
|
126 |
rd = I2cReg::ReadB(h49, 0x1f); Kern::Printf("expect 0x00:%d", rd);
|
|
127 |
rd = I2cReg::ReadB(h49, 0x20); Kern::Printf("expect 0x00:%d", rd);
|
|
128 |
rd = I2cReg::ReadB(h49, 0x21); Kern::Printf("expect 0x00:%d", rd);
|
|
129 |
rd = I2cReg::ReadB(h49, 0x22); Kern::Printf("expect 0x24:%d", rd);
|
|
130 |
rd = I2cReg::ReadB(h49, 0x23); Kern::Printf("expect 0x0a:%d", rd);
|
|
131 |
rd = I2cReg::ReadB(h49, 0x24); Kern::Printf("expect 0x42:%d", rd);
|
|
132 |
rd = I2cReg::ReadB(h49, 0x25); Kern::Printf("expect 0x00:%d", rd);
|
|
133 |
|
|
134 |
rd = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", rd);
|
|
135 |
rd = I2cReg::ReadB(h4b, 0x2a); Kern::Printf("RTC_STATUS_REG:%d", rd);
|
|
136 |
I2cReg::WriteB(h4b, 0x2a, 0x80);
|
|
137 |
rd = I2cReg::ReadB(h4b, 0x2a); Kern::Printf("RTC_STATUS_REG:%d", rd);
|
|
138 |
|
|
139 |
rd = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", rd);
|
|
140 |
I2cReg::WriteB(h4b, 0x29, 0x01);
|
|
141 |
rd = I2cReg::ReadB(h4b, 0x3f); Kern::Printf("CFG_PWRANA2:%d", rd);
|
|
142 |
|
|
143 |
Kern::Printf("RTC_CTRL_REG:%d", rd);
|
|
144 |
rd = I2cReg::ReadB(h4b, 0x2a); Kern::Printf("RTC_STATUS_REG:%d", rd);
|
|
145 |
|
|
146 |
rd = I2cReg::ReadB(h4b, 0x1c); Kern::Printf("SECONDS_REG:%d", rd);
|
|
147 |
rd = I2cReg::ReadB(h4b, 0x1d); Kern::Printf("MINUTES_REG:%d", rd);
|
|
148 |
rd = I2cReg::ReadB(h4b, 0x1e); Kern::Printf("HOURS_REG:%d", rd);
|
|
149 |
rd = I2cReg::ReadB(h4b, 0x1f); Kern::Printf("DAYS_REG:%d", rd);
|
|
150 |
rd = I2cReg::ReadB(h4b, 0x20); Kern::Printf("MONTHS_REG:%d", rd);
|
|
151 |
rd = I2cReg::ReadB(h4b, 0x21); Kern::Printf("YEARS_REG:%d", rd);
|
|
152 |
rd = I2cReg::ReadB(h4b, 0x22); Kern::Printf("WEEKS_REG:%d", rd);
|
|
153 |
rd = I2cReg::ReadB(h4b, 0x23); Kern::Printf("ALARM_SECONDS_REG:%d", rd);
|
|
154 |
rd = I2cReg::ReadB(h4b, 0x24); Kern::Printf("ALARM_MINUTES_REG:%d", rd);
|
|
155 |
rd = I2cReg::ReadB(h4b, 0x25); Kern::Printf("ALARM_HOURS_REG:%d", rd);
|
|
156 |
rd = I2cReg::ReadB(h4b, 0x26); Kern::Printf("ALARM_DAYS_REG:%d", rd);
|
|
157 |
rd = I2cReg::ReadB(h4b, 0x27); Kern::Printf("ALARM_MONTHS_REG:%d", rd);
|
|
158 |
rd = I2cReg::ReadB(h4b, 0x28); Kern::Printf("ALARM_YEARS_REG:%d", rd);
|
|
159 |
rd = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", rd);
|
|
160 |
rd = I2cReg::ReadB(h4b, 0x2a); Kern::Printf("RTC_STATUS_REG:%d", rd);
|
|
161 |
rd = I2cReg::ReadB(h4b, 0x2b); Kern::Printf("RTC_INTERRUPTS_REG:%d", rd);
|
|
162 |
rd = I2cReg::ReadB(h4b, 0x2c); Kern::Printf("RTC_COMP_LSB_REG:%d", rd);
|
|
163 |
rd = I2cReg::ReadB(h4b, 0x2d); Kern::Printf("RTC_COMP_MSB_REG:%d", rd);
|
|
164 |
|
|
165 |
TUint8 ctrl = I2cReg::ReadB(h4b, 0x29);
|
|
166 |
ctrl &= ~0x01;
|
|
167 |
I2cReg::WriteB(h4b, 0x29, ctrl);
|
|
168 |
ctrl = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", ctrl);
|
|
169 |
|
|
170 |
I2cReg::WriteB(h4b, 0x28, 0x08);
|
|
171 |
I2cReg::WriteB(h4b, 0x27, 0x12);
|
|
172 |
I2cReg::WriteB(h4b, 0x26, 0x17);
|
|
173 |
I2cReg::WriteB(h4b, 0x25, 0x10);
|
|
174 |
I2cReg::WriteB(h4b, 0x24, 0x00);
|
|
175 |
I2cReg::WriteB(h4b, 0x23, 0x00);
|
|
176 |
I2cReg::WriteB(h4b, 0x22, 0x00);
|
|
177 |
I2cReg::WriteB(h4b, 0x21, 0x08);
|
|
178 |
I2cReg::WriteB(h4b, 0x20, 0x12);
|
|
179 |
I2cReg::WriteB(h4b, 0x1f, 0x16);
|
|
180 |
I2cReg::WriteB(h4b, 0x1e, 0x10);
|
|
181 |
I2cReg::WriteB(h4b, 0x1d, 0x17);
|
|
182 |
I2cReg::WriteB(h4b, 0x1c, 0x30);
|
|
183 |
|
|
184 |
ctrl |= 0x01;
|
|
185 |
I2cReg::WriteB(h4b, 0x29, ctrl);
|
|
186 |
ctrl = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", ctrl);
|
|
187 |
|
|
188 |
NKern::Sleep(2000);
|
|
189 |
|
|
190 |
rd = I2cReg::ReadB(h4b, 0x2a); Kern::Printf("RTC_STATUS_REG:%d", rd);
|
|
191 |
|
|
192 |
ctrl |= 0x40;
|
|
193 |
I2cReg::WriteB(h4b, 0x29, ctrl);
|
|
194 |
ctrl = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", ctrl);
|
|
195 |
|
|
196 |
rd = I2cReg::ReadB(h4b, 0x1c); Kern::Printf("SECONDS_REG:%d", rd);
|
|
197 |
rd = I2cReg::ReadB(h4b, 0x1d); Kern::Printf("MINUTES_REG:%d", rd);
|
|
198 |
rd = I2cReg::ReadB(h4b, 0x1e); Kern::Printf("HOURS_REG:%d", rd);
|
|
199 |
rd = I2cReg::ReadB(h4b, 0x1f); Kern::Printf("DAYS_REG:%d", rd);
|
|
200 |
rd = I2cReg::ReadB(h4b, 0x20); Kern::Printf("MONTHS_REG:%d", rd);
|
|
201 |
rd = I2cReg::ReadB(h4b, 0x21); Kern::Printf("YEARS_REG:%d", rd);
|
|
202 |
rd = I2cReg::ReadB(h4b, 0x22); Kern::Printf("WEEKS_REG:%d", rd);
|
|
203 |
rd = I2cReg::ReadB(h4b, 0x23); Kern::Printf("ALARM_SECONDS_REG:%d", rd);
|
|
204 |
rd = I2cReg::ReadB(h4b, 0x24); Kern::Printf("ALARM_MINUTES_REG:%d", rd);
|
|
205 |
rd = I2cReg::ReadB(h4b, 0x25); Kern::Printf("ALARM_HOURS_REG:%d", rd);
|
|
206 |
rd = I2cReg::ReadB(h4b, 0x26); Kern::Printf("ALARM_DAYS_REG:%d", rd);
|
|
207 |
rd = I2cReg::ReadB(h4b, 0x27); Kern::Printf("ALARM_MONTHS_REG:%d", rd);
|
|
208 |
rd = I2cReg::ReadB(h4b, 0x28); Kern::Printf("ALARM_YEARS_REG:%d", rd);
|
|
209 |
rd = I2cReg::ReadB(h4b, 0x29); Kern::Printf("RTC_CTRL_REG:%d", rd);
|
|
210 |
rd = I2cReg::ReadB(h4b, 0x2a); Kern::Printf("RTC_STATUS_REG:%d", rd);
|
|
211 |
rd = I2cReg::ReadB(h4b, 0x2b); Kern::Printf("RTC_INTERRUPTS_REG:%d", rd);
|
|
212 |
rd = I2cReg::ReadB(h4b, 0x2c); Kern::Printf("RTC_COMP_LSB_REG:%d", rd);
|
|
213 |
rd = I2cReg::ReadB(h4b, 0x2d); Kern::Printf("RTC_COMP_MSB_REG:%d", rd);
|
|
214 |
|
|
215 |
I2c::Close(h4b);
|
|
216 |
I2c::Close(h49);
|
|
217 |
dfcQueue->Destroy();
|
|
218 |
|
|
219 |
return KErrNone;
|
|
220 |
}
|