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

Commit 2e10ea7

Browse files
committed
Merge pull request #189 from smaillet-ms/Fix-DebugPrint-Timeout
Fixed delays due to debug port buffer fills when no debugger present.
2 parents 1e40961 + e7c0d49 commit 2e10ea7

File tree

10 files changed

+52
-54
lines changed

10 files changed

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

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 );

DeviceCode/include/COM_decl.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ extern INT32 g_DebuggerPort_SslCtx_Handle;
1212
BOOL DebuggerPort_Initialize ( COM_HANDLE ComPortNum );
1313
BOOL DebuggerPort_Uninitialize( COM_HANDLE ComPortNum );
1414

15-
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size );
15+
// max retries is the number of retries if the first attempt fails, thus the maximum
16+
// total number of attempts is maxRretries + 1 since it always tries at least once.
17+
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size, int maxRetries = 99 );
1618
int DebuggerPort_Read ( COM_HANDLE ComPortNum, char* Data, size_t size );
1719
BOOL DebuggerPort_Flush( COM_HANDLE ComPortNum );
1820
BOOL DebuggerPort_IsSslSupported( COM_HANDLE ComPortNum );
1921
BOOL DebuggerPort_UpgradeToSsl( COM_HANDLE ComPortNum, UINT32 flags );
2022
BOOL DebuggerPort_IsUsingSsl( COM_HANDLE ComPortNum );
2123

22-
23-
2424
struct IDebuggerPortSslConfig
2525
{
2626
BOOL (*GetCertificateAuthority)( UINT8** caCert, UINT32* pCertLen );
@@ -30,16 +30,9 @@ struct IDebuggerPortSslConfig
3030

3131
extern IDebuggerPortSslConfig g_DebuggerPortSslConfig;
3232

33-
//--//
34-
3533
void CPU_ProtectCommunicationGPIOs( BOOL On );
3634

37-
//--//
38-
3935
void CPU_InitializeCommunication();
40-
4136
void CPU_UninitializeCommunication();
4237

43-
//--//
44-
4538
#endif // _DRIVERS_COM_DIRECTOR_DECL_H_

DeviceCode/pal/COM/ComDirector.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ BOOL DebuggerPort_Uninitialize( COM_HANDLE ComPortNum )
4141
return FALSE;
4242
}
4343

44-
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size )
44+
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size, int maxRetries )
4545
{
4646
NATIVE_PROFILE_PAL_COM();
4747

4848
UINT32 transport = ExtractTransport(ComPortNum);
4949
const char* dataTmp = Data;
5050
INT32 totWrite = 0;
51-
int retries = 100;
51+
int retries = maxRetries + 1;
5252

53-
while(size > 0 && retries--)
53+
while(size > 0 && retries > 0 )
5454
{
5555
int ret = 0;
5656

@@ -66,20 +66,26 @@ int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size )
6666
ret = SOCKETS_Write( ConvertCOM_SockPort(ComPortNum), dataTmp, size );
6767
break;
6868
}
69+
6970
if(ret < 0)
70-
{
71+
{ // error condition, bug out
7172
break;
7273
}
7374
else if(ret == 0)
74-
{
75-
// if interrupts are off and our buffer is full then there is nothing we can do
76-
if(!INTERRUPTS_ENABLED_STATE()) break;
75+
{ // didn't send any data ( assume buffer full )
76+
--retries;
77+
78+
// if interrupts are off and buffer is full or out of retries
79+
// then there is nothing more to do.
80+
if(!INTERRUPTS_ENABLED_STATE() || retries <= 0 )
81+
break;
7782

7883
Events_WaitForEvents(0, 1);
7984
}
8085
else
81-
{
82-
retries = 50; // reset retries
86+
{ // succesfully transmitted at least some of the data
87+
// update counters and loop back to try sending more
88+
retries = maxRetries + 1;
8389
size -= ret;
8490
dataTmp += ret;
8591
totWrite += ret;
@@ -89,7 +95,6 @@ int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size )
8995
return totWrite;
9096
}
9197

92-
9398
int DebuggerPort_Read( COM_HANDLE ComPortNum, char* Data, size_t size )
9499
{
95100
NATIVE_PROFILE_PAL_COM();

DeviceCode/pal/COM/stubs/ComDirector_stubs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BOOL DebuggerPort_Uninitialize( COM_HANDLE ComPortNum )
1919
}
2020

2121

22-
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size )
22+
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size, int maxRetries )
2323
{
2424
NATIVE_PROFILE_PAL_COM();
2525
return 0;

DeviceCode/pal/COM/usb/usb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void USB_debug_printf( const char*format, ... )
2424
DebuggerPort_Flush( USART_DEFAULT_PORT );
2525

2626
// write string
27-
DebuggerPort_Write( USART_DEFAULT_PORT, buffer, len );
27+
DebuggerPort_Write( USART_DEFAULT_PORT, buffer, len, 0 );
2828

2929
// flush new characters
3030
DebuggerPort_Flush( USART_DEFAULT_PORT );

DeviceCode/pal/tinycrt/tinycrt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int hal_vfprintf( COM_HANDLE stream, const char* format, va_list arg )
120120
case USART_TRANSPORT:
121121
case USB_TRANSPORT:
122122
case SOCKET_TRANSPORT:
123-
DebuggerPort_Write( stream, buffer, chars ); // skip null terminator
123+
DebuggerPort_Write( stream, buffer, chars, 0 ); // skip null terminator
124124
break;
125125

126126
#if !defined(BUILD_RTM)

Solutions/MCBSTM32F400/ManagedCode/Hardware/CPU.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ namespace Microsoft.SPOT.Hardware.MCBSTM32F400
1111
/* Specifies valid hardware I/O pins. */
1212
public static class Pins
1313
{
14-
public const Cpu.Pin GPIO_A8 = (Cpu.Pin) 8; // GPIO Port A Pin 8
15-
public const Cpu.Pin GPIO_B14 = (Cpu.Pin) 30; // GPIO Port B Pin 14
16-
public const Cpu.Pin GPIO_B15 = (Cpu.Pin) 31; // GPIO Port B Pin 15
17-
public const Cpu.Pin GPIO_D3 = (Cpu.Pin) 51; // GPIO Port D Pin 3
18-
public const Cpu.Pin GPIO_F6 = (Cpu.Pin) 86; // GPIO Port F Pin 6
19-
public const Cpu.Pin GPIO_F7 = (Cpu.Pin) 87; // GPIO Port F Pin 7
20-
public const Cpu.Pin GPIO_F8 = (Cpu.Pin) 88; // GPIO Port F Pin 8
21-
public const Cpu.Pin GPIO_F10 = (Cpu.Pin) 90; // GPIO Port F Pin 10
22-
public const Cpu.Pin GPIO_G6_LED = (Cpu.Pin) 102; // GPIO Port G Pin 6
23-
public const Cpu.Pin GPIO_G7_LED = (Cpu.Pin) 103; // GPIO Port G Pin 7
24-
public const Cpu.Pin GPIO_G8_LED = (Cpu.Pin) 104; // GPIO Port G Pin 8
25-
public const Cpu.Pin GPIO_H2_LED = (Cpu.Pin) 114; // GPIO Port H Pin 2
26-
public const Cpu.Pin GPIO_H3_LED = (Cpu.Pin) 115; // GPIO Port H Pin 3
27-
public const Cpu.Pin GPIO_H6_LED = (Cpu.Pin) 118; // GPIO Port H Pin 6
28-
public const Cpu.Pin GPIO_H7_LED = (Cpu.Pin) 119; // GPIO Port H Pin 7
29-
public const Cpu.Pin GPIO_H15 = (Cpu.Pin) 127; // GPIO Port H Pin 15
30-
public const Cpu.Pin GPIO_I1 = (Cpu.Pin) 129; // GPIO Port I Pin 1
31-
public const Cpu.Pin GPIO_I8 = (Cpu.Pin) 136; // GPIO Port I Pin 8
32-
public const Cpu.Pin GPIO_I10_LED = (Cpu.Pin) 138; // GPIO Port I Pin 10
14+
public const Cpu.Pin GPIO_A8 = (Cpu.Pin) 8; // GPIO Port A Pin 8
15+
public const Cpu.Pin GPIO_B14 = (Cpu.Pin) 30; // GPIO Port B Pin 14
16+
public const Cpu.Pin GPIO_B15 = (Cpu.Pin) 31; // GPIO Port B Pin 15
17+
public const Cpu.Pin GPIO_D3 = (Cpu.Pin) 51; // GPIO Port D Pin 3
18+
public const Cpu.Pin GPIO_F6 = (Cpu.Pin) 86; // GPIO Port F Pin 6
19+
public const Cpu.Pin GPIO_F7 = (Cpu.Pin) 87; // GPIO Port F Pin 7
20+
public const Cpu.Pin GPIO_F8 = (Cpu.Pin) 88; // GPIO Port F Pin 8
21+
public const Cpu.Pin GPIO_F10 = (Cpu.Pin) 90; // GPIO Port F Pin 10
22+
public const Cpu.Pin GPIO_G6_LED = (Cpu.Pin) 102; // GPIO Port G Pin 6
23+
public const Cpu.Pin GPIO_G7_LED = (Cpu.Pin) 103; // GPIO Port G Pin 7
24+
public const Cpu.Pin GPIO_G8_LED = (Cpu.Pin) 104; // GPIO Port G Pin 8
25+
public const Cpu.Pin GPIO_H2_LED = (Cpu.Pin) 114; // GPIO Port H Pin 2
26+
public const Cpu.Pin GPIO_H3_LED = (Cpu.Pin) 115; // GPIO Port H Pin 3
27+
public const Cpu.Pin GPIO_H6_LED = (Cpu.Pin) 118; // GPIO Port H Pin 6
28+
public const Cpu.Pin GPIO_H7_LED = (Cpu.Pin) 119; // GPIO Port H Pin 7
29+
public const Cpu.Pin GPIO_H15 = (Cpu.Pin) 127; // GPIO Port H Pin 15
30+
public const Cpu.Pin GPIO_I1 = (Cpu.Pin) 129; // GPIO Port I Pin 1
31+
public const Cpu.Pin GPIO_I8 = (Cpu.Pin) 136; // GPIO Port I Pin 8
32+
public const Cpu.Pin GPIO_I10_LED = (Cpu.Pin) 138; // GPIO Port I Pin 10
3333

3434
public const Cpu.Pin GPIO_NONE = Cpu.Pin.GPIO_NONE;
3535
}
@@ -40,26 +40,26 @@ public static class SerialPorts
4040
public const string COM1 = "COM1";
4141
}
4242

43-
/* Specifies valid baud rates for hardware serial ports */
43+
/* Specifies valid baud rates for hardware serial ports */
4444
public static class BaudRates
4545
{
46-
public const BaudRate Baud9600 = BaudRate.Baudrate9600; // Baudrate 9600
46+
public const BaudRate Baud9600 = BaudRate.Baudrate9600; // Baudrate 9600
4747
public const BaudRate Baud19200 = BaudRate.Baudrate19200; // Baudrate 19200
4848
public const BaudRate Baud38400 = BaudRate.Baudrate38400; // Baudrate 38400
4949
public const BaudRate Baud57600 = BaudRate.Baudrate57600; // Baudrate 57600
5050
public const BaudRate Baud115200 = BaudRate.Baudrate115200; // Baudrate 115200
5151
public const BaudRate Baud230400 = BaudRate.Baudrate230400; // Baudrate 230400
5252
}
5353

54-
/* Specifies resistor modes for GPIO ports */
54+
/* Specifies resistor modes for GPIO ports */
5555
public static class ResistorModes
5656
{
5757
public const Port.ResistorMode PullUp = Port.ResistorMode.PullUp; // Internal Resistor Pull-Up
58-
public const Port.ResistorMode PullDown = Port.ResistorMode.PullDown; // Internal Resistor Pull-Down
58+
public const Port.ResistorMode PullDown = Port.ResistorMode.PullDown; // Internal Resistor Pull-Down
5959
public const Port.ResistorMode Disabled = Port.ResistorMode.Disabled; // Internal Resistor Disabled
60-
60+
6161
}
62-
/* Specifies interrupt modes for GPIO ports */
62+
/* Specifies interrupt modes for GPIO ports */
6363
public static class InterruptModes
6464
{
6565
public const Port.InterruptMode InterruptEdgeLow = Port.InterruptMode.InterruptEdgeLow ;
@@ -69,8 +69,8 @@ public static class InterruptModes
6969
public const Port.InterruptMode InterruptEdgeLevelLow = Port.InterruptMode.InterruptEdgeLevelLow;
7070
public const Port.InterruptMode InterruptNone = Port.InterruptMode.InterruptNone;
7171
}
72-
73-
/* Specified valid SPI ports */
72+
73+
/* Specified valid SPI ports */
7474
public static class SPI_Devices
7575
{
7676
public const Microsoft.SPOT.Hardware.SPI.SPI_module SPI3 = Microsoft.SPOT.Hardware.SPI.SPI_module.SPI3; // SPI Module SPI3

Solutions/Windows2/TinyCLR/Com.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BOOL DebuggerPort_Uninitialize( COM_HANDLE ComPortNum )
1919
return EmulatorNative::GetIComDriver()->Uninitialize( ComPortNum );
2020
}
2121

22-
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size )
22+
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size, int maxRetries )
2323
{
2424
return EmulatorNative::GetIComDriver()->Write( ComPortNum, (IntPtr)(char*)Data, (unsigned int)size );
2525
}

Solutions/Windows2/TinyCLR/Various.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ int hal_vfprintf( COM_HANDLE stream, const char* format, va_list arg )
506506
case USART_TRANSPORT:
507507
case USB_TRANSPORT:
508508
case SOCKET_TRANSPORT:
509-
DebuggerPort_Write( stream, buffer, chars ); // skip null terminator
509+
DebuggerPort_Write( stream, buffer, chars, 0 ); // skip null terminator
510510
break;
511511

512512
case LCD_TRANSPORT:

0 commit comments

Comments
 (0)