Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 00c27ad

Browse files
author
ColinA-MSFT
committed
Address code review feedback.
1 parent 9442370 commit 00c27ad

File tree

5 files changed

+46
-53
lines changed

5 files changed

+46
-53
lines changed

CLR/Libraries/Windows_Devices/windows_devices_native_Windows_Devices_Spi_SpiBusInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::get_ChipS
1010

1111
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);
1212

13-
SetResult_INT32( stack, static_cast<INT32>(CPU_SPI_PortsCount()) );
13+
stack.SetResult_I4( static_cast<INT32>(CPU_SPI_PortsCount()) );
1414

1515
TINYCLR_NOCLEANUP();
1616
}

CLR/Libraries/Windows_Devices/windows_devices_native_Windows_Devices_Spi_SpiDevice.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ typedef Library_windows_devices_native_Windows_Devices_Spi_SpiConnectionSettings
99
// NOTE: Must match enum in SpiEnums.cs
1010
enum SpiMode
1111
{
12-
SpiMode_Mode0 = 0,
13-
SpiMode_Mode1,
14-
SpiMode_Mode2,
15-
SpiMode_Mode3,
12+
SpiMode_Mode0 = 0,
13+
SpiMode_Mode1,
14+
SpiMode_Mode2,
15+
SpiMode_Mode3,
1616
};
1717

1818
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiDevice::InitNative___VOID( CLR_RT_StackFrame& stack )
@@ -228,8 +228,19 @@ HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiDevice::TransferIn
228228
CPU_SPI_Initialize();
229229

230230
// If full duplex, read start offset should be 0, otherwise start at the end of the "write" operation.
231-
BOOL readStartOffset = stack.Arg3().NumericByRef().u1 ? 0 : writeLength;
232-
if (!CPU_SPI_nWrite8_nRead8( config, writeData, writeLength, readData, readLength, readStartOffset ))
231+
int readStartOffset = stack.Arg3().NumericByRef().u1 ? 0 : writeLength;
232+
BOOL result = FALSE;
233+
234+
if (config.MD_16bits)
235+
{
236+
result = CPU_SPI_nWrite16_nRead16( config, (CLR_UINT16*)writeData, writeLength / 2, (CLR_UINT16*)readData, readLength / 2, readStartOffset / 2 );
237+
}
238+
else
239+
{
240+
result = CPU_SPI_nWrite8_nRead8( config, writeData, writeLength, readData, readLength, readStartOffset );
241+
}
242+
243+
if (!result)
233244
{
234245
TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION);
235246
}

CLR/Libraries/Windows_Devices/windows_devices_stub.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,83 @@
77
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioController::get_PinCount___I4( CLR_RT_StackFrame& stack )
88
{
99
TINYCLR_HEADER();
10-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
10+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
1111
TINYCLR_NOCLEANUP();
1212
}
1313

1414
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::get_DebounceTimeout___mscorlibSystemTimeSpan( CLR_RT_StackFrame& stack )
1515
{
1616
TINYCLR_HEADER();
17-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
17+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
1818
TINYCLR_NOCLEANUP();
1919
}
2020

2121
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::set_DebounceTimeout___VOID__mscorlibSystemTimeSpan( CLR_RT_StackFrame& stack )
2222
{
2323
TINYCLR_HEADER();
24-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
24+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
2525
TINYCLR_NOCLEANUP();
2626
}
2727

2828
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack )
2929
{
3030
TINYCLR_HEADER();
31-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
31+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
3232
TINYCLR_NOCLEANUP();
3333
}
3434

3535
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::Write___VOID__WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack )
3636
{
3737
TINYCLR_HEADER();
38-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
38+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
3939
TINYCLR_NOCLEANUP();
4040
}
4141

4242
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::InitNative___BOOLEAN__I4( CLR_RT_StackFrame& stack )
4343
{
4444
TINYCLR_HEADER();
45-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
45+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
4646
TINYCLR_NOCLEANUP();
4747
}
4848

4949
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID( CLR_RT_StackFrame& stack )
5050
{
5151
TINYCLR_HEADER();
52-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
52+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
5353
TINYCLR_NOCLEANUP();
5454
}
5555

5656
HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::SetDriveModeInternal___VOID__WindowsDevicesGpioGpioPinDriveMode( CLR_RT_StackFrame& stack )
5757
{
5858
TINYCLR_HEADER();
59-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
59+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
6060
TINYCLR_NOCLEANUP();
6161
}
6262

6363
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::get_ChipSelectLineCount___I4( CLR_RT_StackFrame& stack )
6464
{
6565
TINYCLR_HEADER();
66-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
66+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
6767
TINYCLR_NOCLEANUP();
6868
}
6969

7070
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiDevice::InitNative___VOID( CLR_RT_StackFrame& stack )
7171
{
7272
TINYCLR_HEADER();
73-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
73+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
7474
TINYCLR_NOCLEANUP();
7575
}
7676

7777
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiDevice::DisposeNative___VOID( CLR_RT_StackFrame& stack )
7878
{
7979
TINYCLR_HEADER();
80-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
80+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
8181
TINYCLR_NOCLEANUP();
8282
}
8383

8484
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiDevice::TransferInternal___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN( CLR_RT_StackFrame& stack )
8585
{
8686
TINYCLR_HEADER();
87-
TINYCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
87+
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
8888
TINYCLR_NOCLEANUP();
8989
}

Framework/Core/Windows/Devices/Spi/SpiBusInfo.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ namespace Windows.Devices.Spi
99
/// </summary>
1010
public sealed class SpiBusInfo
1111
{
12-
/// <summary>
13-
/// Initializes a new instance of SpiBusInfo.
14-
/// </summary>
15-
internal SpiBusInfo()
16-
{
17-
}
18-
1912
/// <summary>
2013
/// Gets the number of chip select lines available on the bus.
2114
/// </summary>
@@ -34,6 +27,7 @@ public int MinClockFrequency
3427
{
3528
get
3629
{
30+
// TODO: Issue #143: Implement this in HAL.
3731
throw new NotImplementedException();
3832
}
3933
}
@@ -46,6 +40,7 @@ public int MaxClockFrequency
4640
{
4741
get
4842
{
43+
// TODO: Issue #143: Implement this in HAL.
4944
throw new NotImplementedException();
5045
}
5146
}

Framework/Core/Windows/Devices/Spi/SpiDevice.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public sealed class SpiDevice : IDisposable
1111
private readonly string m_deviceId;
1212
private readonly SpiConnectionSettings m_settings;
1313

14-
private object m_syncLock = new object();
1514
private bool m_disposed = false;
1615
private int m_mskPin = -1;
1716
private int m_misoPin = -1;
@@ -65,15 +64,12 @@ public string DeviceId
6564
{
6665
get
6766
{
68-
lock (m_syncLock)
67+
if (m_disposed)
6968
{
70-
if (m_disposed)
71-
{
72-
throw new ObjectDisposedException();
73-
}
74-
75-
return m_deviceId.Substring(0);
69+
throw new ObjectDisposedException();
7670
}
71+
72+
return m_deviceId.Substring(0);
7773
}
7874
}
7975

@@ -85,16 +81,13 @@ public SpiConnectionSettings ConnectionSettings
8581
{
8682
get
8783
{
88-
lock (m_syncLock)
84+
if (m_disposed)
8985
{
90-
if (m_disposed)
91-
{
92-
throw new ObjectDisposedException();
93-
}
94-
95-
// We must return a copy so the caller can't accidentally mutate our internal settings.
96-
return new SpiConnectionSettings(m_settings);
86+
throw new ObjectDisposedException();
9787
}
88+
89+
// We must return a copy so the caller can't accidentally mutate our internal settings.
90+
return new SpiConnectionSettings(m_settings);
9891
}
9992
}
10093

@@ -237,14 +230,11 @@ public void TransferFullDuplex(byte[] writeBuffer, byte[] readBuffer)
237230
/// </summary>
238231
public void Dispose()
239232
{
240-
lock (m_syncLock)
233+
if (!m_disposed)
241234
{
242-
if (!m_disposed)
243-
{
244-
Dispose(true);
245-
GC.SuppressFinalize(this);
246-
m_disposed = true;
247-
}
235+
Dispose(true);
236+
GC.SuppressFinalize(this);
237+
m_disposed = true;
248238
}
249239
}
250240

@@ -275,10 +265,7 @@ private void Dispose(bool disposing)
275265
{
276266
if (disposing)
277267
{
278-
lock (m_syncLock)
279-
{
280-
DisposeNative();
281-
}
268+
DisposeNative();
282269
}
283270
}
284271
}

0 commit comments

Comments
 (0)