1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Minimalistic serial driver |
|
15 * |
|
16 * TODO: Handle multiple Units, hardcoded FIFO Size |
|
17 */ |
|
18 |
|
19 #include "syborg_serial.h" |
|
20 |
|
21 //#define DPRINT(x) Kern::Printf(x) |
|
22 //#define DPRINT2(x,y) Kern::Printf(x,y) |
|
23 |
|
24 #define DPRINT(x) |
|
25 #define DPRINT2(x,y) |
|
26 |
|
27 // --------------------------------------------------------------- |
|
28 // --------------------------------------------------------------- |
|
29 |
|
30 DDriverSyborgComm::DDriverSyborgComm() |
|
31 { |
|
32 iVersion=TVersion(KCommsMajorVersionNumber,KCommsMinorVersionNumber,KCommsBuildVersionNumber); |
|
33 } |
|
34 |
|
35 TInt DDriverSyborgComm::Install() |
|
36 { |
|
37 DPRINT("DDriverSyborgComm::Install"); |
|
38 return SetName(&KPddName); |
|
39 } |
|
40 |
|
41 void DDriverSyborgComm::GetCaps(TDes8 &aDes) const |
|
42 { |
|
43 DPRINT("DDriverSyborgComm::GetCaps"); |
|
44 |
|
45 TCommCaps3 capsBuf; |
|
46 TCommCapsV03 &c=capsBuf(); |
|
47 c.iRate=KCapsBps110|KCapsBps150|KCapsBps300|KCapsBps600|KCapsBps1200|KCapsBps2400|KCapsBps4800|KCapsBps9600|KCapsBps19200|KCapsBps38400|KCapsBps57600|KCapsBps115200|KCapsBps230400; |
|
48 c.iDataBits=KCapsData5|KCapsData6|KCapsData7|KCapsData8; |
|
49 c.iStopBits=KCapsStop1|KCapsStop2; |
|
50 c.iParity=KCapsParityNone|KCapsParityEven|KCapsParityOdd; |
|
51 c.iHandshake=KCapsObeyXoffSupported|KCapsSendXoffSupported|KCapsObeyCTSSupported|KCapsFailCTSSupported|KCapsObeyDSRSupported|KCapsFailDSRSupported|KCapsObeyDCDSupported|KCapsFailDCDSupported|KCapsFreeRTSSupported|KCapsFreeDTRSupported; |
|
52 c.iSignals=KCapsSignalCTSSupported|KCapsSignalDSRSupported|KCapsSignalDCDSupported|KCapsSignalRTSSupported|KCapsSignalDTRSupported; |
|
53 c.iSIR=0; |
|
54 c.iNotificationCaps=KNotifyDataAvailableSupported|KNotifySignalsChangeSupported; |
|
55 c.iFifo=KCapsHasFifo; |
|
56 c.iRoleCaps=0; |
|
57 c.iFlowControlCaps=0; |
|
58 c.iBreakSupported=ETrue; |
|
59 aDes.FillZ(aDes.MaxLength()); |
|
60 aDes=capsBuf.Left(Min(capsBuf.Length(),aDes.MaxLength())); |
|
61 } |
|
62 |
|
63 TInt DDriverSyborgComm::Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer) |
|
64 { |
|
65 DPRINT("DDriverSyborgComm::Create"); |
|
66 |
|
67 DCommSyborgSoc* pD=new DCommSyborgSoc; |
|
68 aChannel=pD; |
|
69 TInt r=KErrNoMemory; |
|
70 if (pD) |
|
71 r=pD->DoCreate(aUnit,anInfo); |
|
72 return r; |
|
73 } |
|
74 |
|
75 TInt DDriverSyborgComm::Validate(TInt aUnit, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
76 { |
|
77 DPRINT("DDriverSyborgComm::Validate"); |
|
78 if ((!Kern::QueryVersionSupported(iVersion,aVer)) || |
|
79 (!Kern::QueryVersionSupported(aVer,TVersion(KMinimumLddMajorVersion,KMinimumLddMinorVersion,KMinimumLddBuild)))) |
|
80 return KErrNotSupported; |
|
81 return KErrNone; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------- |
|
85 // --------------------------------------------------------------- |
|
86 |
|
87 DCommSyborgSoc::DCommSyborgSoc() |
|
88 { |
|
89 } |
|
90 |
|
91 DCommSyborgSoc::~DCommSyborgSoc() |
|
92 { |
|
93 Interrupt::Unbind(iIrq); |
|
94 } |
|
95 |
|
96 TInt DCommSyborgSoc::DoCreate(TInt aUnit, const TDesC8* /*anInfo*/) |
|
97 { |
|
98 DPRINT2("DCommSyborgSoc::DoCreate %d",aUnit); |
|
99 switch(aUnit) |
|
100 { |
|
101 case 0: |
|
102 iPortAddr = KHwBaseUart0; |
|
103 iIrq = EIntSerial0; |
|
104 break; |
|
105 case 1: |
|
106 iPortAddr = KHwBaseUart1; |
|
107 iIrq = EIntSerial1; |
|
108 break; |
|
109 case 2: |
|
110 iPortAddr = KHwBaseUart2; |
|
111 iIrq = EIntSerial2; |
|
112 break; |
|
113 case 3: |
|
114 iPortAddr = KHwBaseUart3; |
|
115 iIrq = EIntSerial3; |
|
116 break; |
|
117 default: |
|
118 iPortAddr = KHwBaseUart0; |
|
119 iIrq = EIntSerial0; |
|
120 break; |
|
121 } |
|
122 |
|
123 Interrupt::Bind(EIntSerial0,Isr,this); |
|
124 |
|
125 return KErrNone; |
|
126 |
|
127 } |
|
128 |
|
129 TInt DCommSyborgSoc::Start() |
|
130 { |
|
131 DPRINT("DCommSyborgSoc::Start"); |
|
132 WriteReg(iPortAddr, SERIAL_INT_ENABLE, 0x1); |
|
133 Interrupt::Enable(iIrq); |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 void DCommSyborgSoc::Stop(TStopMode aMode) |
|
138 { |
|
139 DPRINT("DCommSyborgSoc::Stop"); |
|
140 WriteReg(iPortAddr, SERIAL_INT_ENABLE, 0x0); |
|
141 Interrupt::Disable(iIrq); |
|
142 } |
|
143 |
|
144 void DCommSyborgSoc::Break(TBool aState) |
|
145 { |
|
146 DPRINT("DCommSyborgSoc::Break"); |
|
147 } |
|
148 |
|
149 void DCommSyborgSoc::EnableTransmit() |
|
150 { |
|
151 DPRINT("DCommSyborgSoc::EnableTransmit"); |
|
152 while (Kern::PowerGood()) |
|
153 { |
|
154 TInt r=TransmitIsr(); |
|
155 if (r<0) |
|
156 break; |
|
157 WriteReg(iPortAddr, SERIAL_DATA, r); |
|
158 } |
|
159 } |
|
160 |
|
161 TUint DCommSyborgSoc::Signals() const |
|
162 { |
|
163 DPRINT("DCommSyborgSoc::Signals"); |
|
164 return(0); |
|
165 } |
|
166 |
|
167 void DCommSyborgSoc::SetSignals(TUint aSetMask, TUint aClearMask) |
|
168 { |
|
169 DPRINT("DCommSyborgSoc::SetSignals"); |
|
170 } |
|
171 |
|
172 TInt DCommSyborgSoc::ValidateConfig(const TCommConfigV01 &aConfig) const |
|
173 { |
|
174 DPRINT("DCommSyborgSoc::ValidateConfig"); |
|
175 return KErrNone; |
|
176 } |
|
177 |
|
178 void DCommSyborgSoc::Configure(TCommConfigV01 &aConfig) |
|
179 { |
|
180 DPRINT("DCommSyborgSoc::Configure"); |
|
181 } |
|
182 |
|
183 void DCommSyborgSoc::Caps(TDes8 &aCaps) const |
|
184 { |
|
185 DPRINT("DCommSyborgSoc::Caps"); |
|
186 TCommCaps3 capsBuf; |
|
187 TCommCapsV03 &c=capsBuf(); |
|
188 c.iRate=KCapsBps110|KCapsBps150|KCapsBps300|KCapsBps600|KCapsBps1200|KCapsBps2400|KCapsBps4800|KCapsBps9600|KCapsBps19200|KCapsBps38400|KCapsBps57600|KCapsBps115200|KCapsBps230400; |
|
189 c.iDataBits=KCapsData5|KCapsData6|KCapsData7|KCapsData8; |
|
190 c.iStopBits=KCapsStop1|KCapsStop2; |
|
191 c.iParity=KCapsParityNone|KCapsParityEven|KCapsParityOdd; |
|
192 c.iHandshake=KCapsObeyXoffSupported|KCapsSendXoffSupported|KCapsObeyCTSSupported|KCapsFailCTSSupported|KCapsObeyDSRSupported|KCapsFailDSRSupported|KCapsObeyDCDSupported|KCapsFailDCDSupported|KCapsFreeRTSSupported|KCapsFreeDTRSupported; |
|
193 c.iSignals=KCapsSignalCTSSupported|KCapsSignalDSRSupported|KCapsSignalDCDSupported|KCapsSignalRTSSupported|KCapsSignalDTRSupported; |
|
194 c.iSIR=0; |
|
195 c.iNotificationCaps=KNotifyDataAvailableSupported|KNotifySignalsChangeSupported; |
|
196 c.iFifo=KCapsHasFifo; |
|
197 c.iRoleCaps=0; |
|
198 c.iFlowControlCaps=0; |
|
199 c.iBreakSupported=ETrue; |
|
200 aCaps.FillZ(aCaps.MaxLength()); |
|
201 aCaps=capsBuf.Left(Min(capsBuf.Length(),aCaps.MaxLength())); |
|
202 } |
|
203 |
|
204 TInt DCommSyborgSoc::DisableIrqs() |
|
205 { |
|
206 DPRINT("DCommSyborgSoc::DisableIrqs"); |
|
207 return NKern::DisableAllInterrupts(); |
|
208 } |
|
209 |
|
210 void DCommSyborgSoc::RestoreIrqs(TInt aIrq) |
|
211 { |
|
212 DPRINT("DCommSyborgSoc::RestoreIrqs"); |
|
213 NKern::RestoreInterrupts(aIrq); |
|
214 } |
|
215 |
|
216 TDfcQue* DCommSyborgSoc::DfcQ(TInt /*aUnit*/) |
|
217 { |
|
218 return Kern::DfcQue0(); |
|
219 } |
|
220 |
|
221 void DCommSyborgSoc::CheckConfig(TCommConfigV01& aConfig) |
|
222 { |
|
223 DPRINT("DCommSyborgSoc::CheckConfig"); |
|
224 } |
|
225 |
|
226 void DCommSyborgSoc::Isr(TAny* aPtr) |
|
227 { |
|
228 DCommSyborgSoc& d=*(DCommSyborgSoc*)aPtr; |
|
229 TUint rx[32]; |
|
230 TInt rxi=0; |
|
231 |
|
232 DPRINT2("DCommSyborgSoc::Isr %x",d.iIrq); |
|
233 |
|
234 // Is now auto clear |
|
235 // WriteReg(d.iPortAddr, SERIAL_CLEAR_INT, 0x0); // clear interrupts |
|
236 |
|
237 while(ReadReg(d.iPortAddr, SERIAL_FIFO_COUNT)!=0) { |
|
238 TUint ch = ReadReg(d.iPortAddr, SERIAL_DATA); |
|
239 rx[rxi++]=ch; |
|
240 } |
|
241 d.ReceiveIsr(rx,rxi,0); |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------------- |
|
245 // --------------------------------------------------------------- |
|
246 |
|
247 DECLARE_STANDARD_PDD() |
|
248 { |
|
249 DPRINT("DECLARE_STANDARD_PDD()"); |
|
250 return new DDriverSyborgComm; |
|
251 } |
|
252 |
|