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

Commit bc2b73c

Browse files
committed
merge with upstream dev branch
2 parents ea85a2e + 2e10ea7 commit bc2b73c

File tree

63 files changed

+1593
-4975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1593
-4975
lines changed

CLR/Diagnostics/Info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void CLR_Debug::Emit( const char *text, int len )
208208
if(!CLR_EE_DBG_IS( Enabled ) || HalSystemConfig.DebugTextPort != HalSystemConfig.DebuggerPorts[ 0 ])
209209
{
210210
#if !defined(PLATFORM_WINDOWS) && !defined(PLATFORM_WINCE)
211-
DebuggerPort_Write( HalSystemConfig.DebugTextPort, s_buffer, s_chars ); // skip null terminator
211+
DebuggerPort_Write( HalSystemConfig.DebugTextPort, s_buffer, s_chars, 0 ); // skip null terminator and don't bother retrying
212212
DebuggerPort_Flush( HalSystemConfig.DebugTextPort ); // skip null terminator
213213
#endif
214214
}

CLR/Libraries/CorLib/corlib_native_System_String.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,23 @@ HRESULT Library_corlib_native_System_String::FromCharArray( CLR_RT_StackFrame& s
547547
CLR_RT_HeapBlock_Array* array;
548548
CLR_UINT32 len;
549549

550-
array = stack.Arg1().DereferenceArray(); if(!array) TINYCLR_SET_AND_LEAVE(S_OK);
551-
len = array->m_numOfElements ;
550+
array = stack.Arg1().DereferenceArray();
551+
if (!array || array->m_numOfElements == 0)
552+
{
553+
TINYCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_String::CreateInstance(stack.Arg0(), ""));
554+
}
555+
else
556+
{
557+
len = array->m_numOfElements;
552558

553-
if(length == -1) length = len - startIndex;
559+
if (length == -1)
560+
length = len - startIndex;
554561

555-
if(CLR_RT_HeapBlock_Array::CheckRange( startIndex, length, len ) == false) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
562+
if (CLR_RT_HeapBlock_Array::CheckRange(startIndex, length, len) == false)
563+
TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
556564

557-
TINYCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_String::CreateInstance( stack.Arg0(), (CLR_UINT16*)array->GetElement( startIndex ), length ));
565+
TINYCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_String::CreateInstance(stack.Arg0(), (CLR_UINT16*)array->GetElement(startIndex), length));
566+
}
558567

559568
TINYCLR_NOCLEANUP();
560569
}

CLR/Libraries/CorLib/corlib_native_System_Text_UTF8Encoding.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,39 @@ HRESULT Library_corlib_native_System_Text_UTF8Encoding::GetBytes___I4__STRING__I
3232
NATIVE_PROFILE_CLR_CORE();
3333
TINYCLR_HEADER();
3434

35-
size_t cMaxBytes;
3635
LPCSTR str = stack.Arg1().RecoverString();
3736
CLR_INT32 strIdx = stack.Arg2().NumericByRef().s4;
3837
CLR_INT32 strCnt = stack.Arg3().NumericByRef().s4;
3938
CLR_RT_HeapBlock_Array* pArrayBytes = stack.Arg4().DereferenceArray();
4039
CLR_INT32 byteIdx = stack.Arg5().NumericByRef().s4;
4140

41+
const CLR_UINT8* i;
42+
const CLR_UINT8* j;
43+
CLR_RT_UnicodeHelper uh;
44+
int strLength;
45+
4246
FAULT_ON_NULL(str);
4347
FAULT_ON_NULL(pArrayBytes);
4448

45-
cMaxBytes = hal_strlen_s(str);
49+
uh.SetInputUTF8(str);
50+
strLength = uh.CountNumberOfCharacters();
51+
if (strLength < 0)
52+
TINYCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE);
53+
54+
if ((strIdx + strCnt) > (CLR_INT32)strLength)
55+
TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
56+
57+
uh.ConvertFromUTF8(strIdx, true);
58+
i = uh.m_inputUTF8;
59+
uh.ConvertFromUTF8(strCnt, true);
60+
j = uh.m_inputUTF8;
4661

47-
if((strIdx + strCnt) > (CLR_INT32)cMaxBytes ) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
48-
if((byteIdx + strCnt) > (CLR_INT32)pArrayBytes->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
62+
if ((byteIdx + j - i) > (CLR_INT32)pArrayBytes->m_numOfElements)
63+
TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);
4964

50-
memcpy(pArrayBytes->GetElement(byteIdx), &str[strIdx], strCnt);
65+
memcpy(pArrayBytes->GetElement(byteIdx), i, j - i);
5166

52-
stack.SetResult_I4(strCnt);
67+
stack.SetResult_I4(j - i);
5368

5469
TINYCLR_NOCLEANUP();
5570
}

CLR/Libraries/Windows_Devices/windows_devices_native.cpp

Lines changed: 62 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,
@@ -85,7 +113,38 @@ static const CLR_RT_MethodHandler method_lookup[] =
85113
NULL,
86114
NULL,
87115
NULL,
88-
Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::get_ChipSelectLineCount___I4,
116+
NULL,
117+
NULL,
118+
NULL,
119+
NULL,
120+
NULL,
121+
NULL,
122+
NULL,
123+
NULL,
124+
NULL,
125+
NULL,
126+
NULL,
127+
NULL,
128+
NULL,
129+
NULL,
130+
NULL,
131+
NULL,
132+
NULL,
133+
NULL,
134+
NULL,
135+
NULL,
136+
NULL,
137+
NULL,
138+
NULL,
139+
NULL,
140+
NULL,
141+
NULL,
142+
NULL,
143+
NULL,
144+
NULL,
145+
NULL,
146+
Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo::_ctor___VOID__I4,
147+
NULL,
89148
NULL,
90149
NULL,
91150
NULL,
@@ -120,12 +179,13 @@ static const CLR_RT_MethodHandler method_lookup[] =
120179
NULL,
121180
NULL,
122181
NULL,
182+
NULL,
123183
};
124184

125185
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices =
126186
{
127187
"Windows.Devices",
128-
0xF71D0B80,
188+
0x240D5E7D,
129189
method_lookup
130190
};
131191

CLR/Libraries/Windows_Devices/windows_devices_native.h

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

1313
#include <TinyCLR_Interop.h>
14+
struct Library_windows_devices_native_Windows_Devices_Adc_AdcChannel
15+
{
16+
static const int FIELD__m_channelNumber = 1;
17+
static const int FIELD__m_controller = 2;
18+
static const int FIELD__m_provider = 3;
19+
static const int FIELD__m_disposed = 4;
20+
21+
22+
//--//
23+
24+
};
25+
26+
struct Library_windows_devices_native_Windows_Devices_Adc_AdcController
27+
{
28+
static const int FIELD__m_provider = 1;
29+
30+
31+
//--//
32+
33+
};
34+
1435
struct Library_windows_devices_native_Windows_Devices_Enumeration_DeviceInformation
1536
{
1637
static const int FIELD__m_id = 1;
@@ -121,9 +142,37 @@ struct Library_windows_devices_native_Windows_Devices_I2c_I2cTransferResult
121142

122143
};
123144

145+
struct Library_windows_devices_native_Windows_Devices_Pwm_PwmController
146+
{
147+
static const int FIELD__m_provider = 1;
148+
149+
150+
//--//
151+
152+
};
153+
154+
struct Library_windows_devices_native_Windows_Devices_Pwm_PwmPin
155+
{
156+
static const int FIELD__m_pinNumber = 1;
157+
static const int FIELD__m_controller = 2;
158+
static const int FIELD__m_provider = 3;
159+
static const int FIELD__m_started = 4;
160+
static const int FIELD__m_disposed = 5;
161+
static const int FIELD__m_dutyCycle = 6;
162+
static const int FIELD__m_polarity = 7;
163+
164+
165+
//--//
166+
167+
};
168+
124169
struct Library_windows_devices_native_Windows_Devices_Spi_SpiBusInfo
125170
{
126-
TINYCLR_NATIVE_DECLARE(get_ChipSelectLineCount___I4);
171+
static const int FIELD__MinClockFrequency_ = 1;
172+
static const int FIELD__MaxClockFrequency_ = 2;
173+
static const int FIELD__ChipSelectLineCount_ = 3;
174+
175+
TINYCLR_NATIVE_DECLARE(_ctor___VOID__I4);
127176

128177
//--//
129178

@@ -145,11 +194,10 @@ struct Library_windows_devices_native_Windows_Devices_Spi_SpiConnectionSettings
145194
struct Library_windows_devices_native_Windows_Devices_Spi_SpiDevice
146195
{
147196
static const int FIELD_STATIC__s_SpiPrefix = 6;
148-
static const int FIELD_STATIC__s_busInfo = 7;
149197

150-
static const int FIELD__m_deviceId = 1;
151-
static const int FIELD__m_settings = 2;
152-
static const int FIELD__m_syncLock = 3;
198+
static const int FIELD__m_busInfo = 1;
199+
static const int FIELD__m_deviceId = 2;
200+
static const int FIELD__m_settings = 3;
153201
static const int FIELD__m_disposed = 4;
154202
static const int FIELD__m_mskPin = 5;
155203
static const int FIELD__m_misoPin = 6;

CLR/Libraries/Windows_Devices/windows_devices_native_Windows_Devices_Gpio_GpioPin.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::get_Debounc
4848
{
4949
TINYCLR_HEADER();
5050

51+
GPIO_PIN pin;
5152
CLR_INT64 value;
5253
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);
5354

@@ -56,7 +57,8 @@ HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::get_Debounc
5657
TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED);
5758
}
5859

59-
value = (CLR_INT64)::CPU_GPIO_GetDebounce() * TIME_CONVERSION__TO_MILLISECONDS;
60+
pin = (GPIO_PIN)( pThis[ FIELD__m_pinNumber ].NumericByRefConst().u4 );
61+
value = (CLR_INT64)::CPU_GPIO_GetPinDebounce( pin ) * TIME_CONVERSION__TO_MILLISECONDS;
6062
stack.SetResult_I8( value );
6163
stack.TopValue().ChangeDataType( DATATYPE_TIMESPAN );
6264

@@ -67,6 +69,7 @@ HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::set_Debounc
6769
{
6870
TINYCLR_HEADER();
6971

72+
GPIO_PIN pin;
7073
CLR_INT64 value;
7174
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);
7275

@@ -76,12 +79,11 @@ HRESULT Library_windows_devices_native_Windows_Devices_Gpio_GpioPin::set_Debounc
7679
}
7780

7881
value = (CLR_INT64_TEMP_CAST) stack.Arg1().NumericByRef().s8 / TIME_CONVERSION__TO_MILLISECONDS;
79-
80-
// TODO: Issue #101 Set debounce individually per pin once the HAL has that capability.
81-
//if (!::CPU_GPIO_SetDebounce( value ))
82-
//{
83-
// TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
84-
//}
82+
pin = (GPIO_PIN)( pThis[ FIELD__m_pinNumber ].NumericByRefConst().u4 );
83+
if (!::CPU_GPIO_SetPinDebounce( pin, value ))
84+
{
85+
TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
86+
}
8587
TINYCLR_SET_AND_LEAVE(stack.NotImplementedStub());
8688

8789
TINYCLR_NOCLEANUP();

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+
}

DeviceCode/Initialization/tinyhal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ void debug_printf( const char* format, ... )
618618
DebuggerPort_Flush( HalSystemConfig.DebugTextPort );
619619

620620
// write string
621-
DebuggerPort_Write( HalSystemConfig.DebugTextPort, buffer, len );
621+
DebuggerPort_Write( HalSystemConfig.DebugTextPort, buffer, len, 0 );
622622

623623
// flush new characters
624624
DebuggerPort_Flush( HalSystemConfig.DebugTextPort );

0 commit comments

Comments
 (0)