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

Commit a5aa38e

Browse files
committed
Merge pull request #177 from smaillet-ms/Add-SpiDevinceInfo-native
Add SpiDevinceInfo native layer support with reference STM32F4 implementation
2 parents 1ccd745 + 0b06b90 commit a5aa38e

File tree

11 files changed

+391
-153
lines changed

11 files changed

+391
-153
lines changed

CLR/Libraries/Windows_Devices/windows_devices_native.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@
1212

1313
static const CLR_RT_MethodHandler method_lookup[] =
1414
{
15+
NULL,
16+
NULL,
17+
NULL,
18+
NULL,
19+
NULL,
20+
NULL,
21+
NULL,
22+
NULL,
23+
NULL,
24+
NULL,
25+
NULL,
26+
NULL,
27+
NULL,
28+
NULL,
29+
NULL,
30+
NULL,
31+
NULL,
32+
NULL,
33+
NULL,
34+
NULL,
35+
NULL,
36+
NULL,
37+
NULL,
38+
NULL,
39+
NULL,
40+
NULL,
41+
NULL,
42+
NULL,
1543
NULL,
1644
NULL,
1745
NULL,
@@ -84,8 +112,8 @@ static const CLR_RT_MethodHandler method_lookup[] =
84112
NULL,
85113
NULL,
86114
NULL,
115+
Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::_ctor___VOID__I4,
87116
NULL,
88-
Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::get_ChipSelectLineCount___I4,
89117
NULL,
90118
NULL,
91119
NULL,
@@ -120,12 +148,13 @@ static const CLR_RT_MethodHandler method_lookup[] =
120148
NULL,
121149
NULL,
122150
NULL,
151+
NULL,
123152
};
124153

125154
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices =
126155
{
127156
"Windows.Devices",
128-
0xF71D0B80,
157+
0xDD62098A,
129158
method_lookup
130159
};
131160

CLR/Libraries/Windows_Devices/windows_devices_native.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@
1111
#define _WINDOWS_DEVICES_NATIVE_H_
1212

1313
#include <TinyCLR_Interop.h>
14+
15+
struct Library_windows_devices_native_Windows_Devices_Adc_AdcChannel
16+
{
17+
static const int FIELD__m_channelNumber = 1;
18+
static const int FIELD__m_controller = 2;
19+
static const int FIELD__m_provider = 3;
20+
static const int FIELD__m_disposed = 4;
21+
22+
23+
//--//
24+
25+
};
26+
27+
struct Library_windows_devices_native_Windows_Devices_Adc_AdcController
28+
{
29+
static const int FIELD__m_provider = 1;
30+
31+
32+
//--//
33+
34+
};
35+
1436
struct Library_windows_devices_native_Windows_Devices_Enumeration_DeviceInformation
1537
{
1638
static const int FIELD__m_id = 1;
@@ -123,7 +145,11 @@ struct Library_windows_devices_native_Windows_Devices_I2c_I2cTransferResult
123145

124146
struct Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo
125147
{
126-
TINYCLR_NATIVE_DECLARE(get_ChipSelectLineCount___I4);
148+
static const int FIELD__MinClockFrequency_ = 1;
149+
static const int FIELD__MaxClockFrequency_ = 2;
150+
static const int FIELD__ChipSelectLineCount_ = 3;
151+
152+
TINYCLR_NATIVE_DECLARE(_ctor___VOID__I4);
127153

128154
//--//
129155

@@ -145,11 +171,10 @@ struct Library_windows_devices_native_Windows_Devices_Spi_SpiConnectionSettings
145171
struct Library_windows_devices_native_Windows_Devices_Spi_SpiDevice
146172
{
147173
static const int FIELD_STATIC__s_SpiPrefix = 6;
148-
static const int FIELD_STATIC__s_busInfo = 7;
149174

150-
static const int FIELD__m_deviceId = 1;
151-
static const int FIELD__m_settings = 2;
152-
static const int FIELD__m_syncLock = 3;
175+
static const int FIELD__m_busInfo = 1;
176+
static const int FIELD__m_deviceId = 2;
177+
static const int FIELD__m_settings = 3;
153178
static const int FIELD__m_disposed = 4;
154179
static const int FIELD__m_mskPin = 5;
155180
static const int FIELD__m_misoPin = 6;

CLR/Libraries/Windows_Devices/windows_devices_native_Windows_Devices_Spi_SpiBusInfo.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44

5-
#include "windows_devices.h"
5+
#include "Windows_devices.h"
66

7-
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::get_ChipSelectLineCount___I4( CLR_RT_StackFrame& stack )
7+
// [MethodImplAttribute( MethodImplOptions.InternalCall )]
8+
// extern internal SpiBusInfo( int busNum );
9+
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::_ctor___VOID__I4( CLR_RT_StackFrame& stackFrame )
810
{
911
TINYCLR_HEADER();
1012

11-
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);
13+
// Arg[0] ==> implicit this pointer
14+
CLR_RT_HeapBlock* pThis = stackFrame.This();
15+
FAULT_ON_NULL( pThis );
1216

13-
stack.SetResult_I4( static_cast<INT32>(CPU_SPI_PortsCount()) );
17+
{ // use scope to bypass 'Warning: transfer of control bypasses initialization of port' (or similar depending on compiler)
18+
// Arg[1] ==> port
19+
UINT32 port = stackFrame.ArgN( 1 ).NumericByRef().s4;
20+
21+
pThis[ FIELD__MinClockFrequency_ ].NumericByRef().s4 = CPU_SPI_MinClockFrequency( port );
22+
pThis[ FIELD__MaxClockFrequency_ ].NumericByRef().s4 = CPU_SPI_MaxClockFrequency( port );
23+
pThis[ FIELD__ChipSelectLineCount_ ].NumericByRef().s4 = CPU_SPI_ChipSelectLineCount( port );
24+
}
1425

1526
TINYCLR_NOCLEANUP();
1627
}

CLR/Libraries/Windows_Devices/windows_devices_stub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::SetDriveMod
6060
TINYCLR_NOCLEANUP();
6161
}
6262

63-
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::get_ChipSelectLineCount___I4( CLR_RT_StackFrame& stack )
63+
HRESULT Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::_ctor___VOID__I4( CLR_RT_StackFrame& stack )
6464
{
6565
TINYCLR_HEADER();
6666
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());

DeviceCode/Drivers/Stubs/Processor/stubs_SPI/stubs_functions_SPI.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,17 @@ void CPU_SPI_GetPins( UINT32 spi_mod, GPIO_PIN& msk, GPIO_PIN& miso, GPIO_PIN& m
6666
return;
6767
}
6868

69+
UINT32 CPU_SPI_MinClockFrequency( UINT32 spi_mod )
70+
{
71+
return 0;
72+
}
73+
74+
UINT32 CPU_SPI_MaxClockFrequency( UINT32 spi_mod )
75+
{
76+
return 0;
77+
}
6978

79+
UINT32 CPU_SPI_ChipSelectLineCount( UINT32 spi_mod )
80+
{
81+
return 0;
82+
}

0 commit comments

Comments
 (0)