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

Commit 109feae

Browse files
committed
Added support for solution level extensibility for communication transports via generic transport interfaces
- Added new GENERIC_TRANSPORT - Added new case to all COM redirector APIs to support GENERIC_TRANSPORT handles redirecting to GenericPort_xxx APIS - Added new GenericPort_xxx APIS to lookup an interface in a table based on the port number and then call through the interface 's function pointer. This allows extensibility without requiring the definition of new transport types. - added Common CortexMx ITM trace port channel 0 Generic port implementation - Added support for using ITM0 Generic port to MCBSTM32F400
1 parent 44a5810 commit 109feae

File tree

17 files changed

+510
-127
lines changed

17 files changed

+510
-127
lines changed

DeviceCode/Cores/arm/Processors/CortexMx/GlobalLock/dotNetMF.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<PropertyGroup>
33
<AssemblyName>GlobalLock_hal_Cortex</AssemblyName>
44
<ProjectGuid>{A839EEC5-C737-48C5-958B-BBF12920AA41}</ProjectGuid>
5-
<Description>Cortex-M3 Global lock</Description>
5+
<Description>Cortex-Mx Global lock</Description>
66
<Level>HAL</Level>
77
<LibraryFile>GlobalLock_hal_Cortex.$(LIB_EXT)</LibraryFile>
8-
<ProjectPath>$(SPOCLIENT)\DeviceCode\Cores\arm\Processors\CortexMx\dotNetMF.proj</ProjectPath>
8+
<ProjectPath>$(SPOCLIENT)\DeviceCode\Cores\arm\Processors\CortexMx\GlobalLock\dotNetMF.proj</ProjectPath>
99
<ManifestFile>GlobalLock_hal_Cortex.$(LIB_EXT).manifest</ManifestFile>
1010
<Documentation>
1111
</Documentation>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <tinyhal.h>
2+
3+
#include "cmsis_generic.h"
4+
5+
// only one "generic" port supported for ITM tracing messages to hardware debugger
6+
// so pInstance is ignored
7+
static int ItmPort_Write( void* pInstance, const char* Data, size_t size )
8+
{
9+
for( int i = 0; i< size; ++i )
10+
ITM_SendChar( Data[i] );
11+
12+
return size;
13+
}
14+
15+
static IGenericPort const ItmPortItf =
16+
{
17+
// default returns TRUE
18+
NULL, //BOOL (*Initialize)( void* pInstance );
19+
20+
// default returns TRUE
21+
NULL, //BOOL (*Uninitialize)( void* pInstance );
22+
23+
// default return 0
24+
ItmPort_Write, //int (*Write)( void* pInstance, const char* Data, size_t size );
25+
26+
// defualt return 0
27+
NULL, //int (*Read)( void* pInstance, char* Data, size_t size );
28+
29+
// default return TRUE
30+
NULL, //BOOL (*Flush)( void* pInstance );
31+
32+
// default do nothing
33+
NULL, //void (*ProtectPins)( void* pInstance, BOOL On );
34+
35+
// default return FALSE
36+
NULL, //BOOL (*IsSslSupported)( void* pInstance );
37+
38+
// default return FALSE
39+
NULL, //BOOL (*UpgradeToSsl)( void* pInstance, const UINT8* pCACert, UINT32 caCertLen, const UINT8* pDeviceCert, UINT32 deviceCertLen, LPCSTR szTargetHost );
40+
41+
// default return FALSE
42+
NULL, //BOOL (*IsUsingSsl)( void* pInstance );
43+
};
44+
45+
extern const GenericPortTableEntry Itm0GenericPort =
46+
{
47+
ItmPortItf,
48+
NULL
49+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<AssemblyName>CortexMx_ItmPort</AssemblyName>
4+
<ProjectGuid>{E30D2587-7481-4ECB-A961-16A8BA3DECB9}</ProjectGuid>
5+
<Description>Cortex-Mx Generic ITM port</Description>
6+
<Level>HAL</Level>
7+
<LibraryFile>CortexMx_ItmPort.$(LIB_EXT)</LibraryFile>
8+
<ProjectPath>$(SPOCLIENT)\DeviceCode\Cores\arm\Processors\CortexMx\ItmPort\dotNetMF.proj</ProjectPath>
9+
<ManifestFile>CortexMx_ItmPort.$(LIB_EXT).manifest</ManifestFile>
10+
<Documentation>
11+
</Documentation>
12+
<PlatformIndependent>False</PlatformIndependent>
13+
<Required>False</Required>
14+
<IgnoreDefaultLibPath>False</IgnoreDefaultLibPath>
15+
<IsStub>False</IsStub>
16+
<Directory>DeviceCode\Cores\arm\Processors\CortexMx</Directory>
17+
<OutputType>Library</OutputType>
18+
<PlatformIndependentBuild>false</PlatformIndependentBuild>
19+
<Version>4.0.0.0</Version>
20+
</PropertyGroup>
21+
<Import Project="$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Settings" />
22+
<PropertyGroup />
23+
<ItemGroup>
24+
<Compile Include="ItmPort.cpp" />
25+
</ItemGroup>
26+
<Import Project="$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Targets" />
27+
</Project>

DeviceCode/Targets/Native/STM32F4/processor_selector.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#elif defined(PLATFORM_ARM_STM32F4)
2323
#define STM32F4XX
2424
#else
25-
ERROR - WE SHOULD NOT INCLUDE THIS HEADER IF NOT BUILDING A STM32F2/F4 PLATFORM
25+
ERROR - WE SHOULD NOT INCLUDE THIS HEADER IF NOT BUILDING AN STM32F2/F4 PLATFORM
2626
#endif
2727

2828
/////////////////////////////////////////////////////////
@@ -61,9 +61,11 @@ ERROR - WE SHOULD NOT INCLUDE THIS HEADER IF NOT BUILDING A STM32F2/F4 PLATFORM
6161
//
6262

6363
// Port definitions
64-
#define ITM_VIRTUAL_COMPORTNUM 0
64+
#ifndef ITM_GENERIC_PORTNUM
65+
#define ITM_GENERIC_PORTNUM 0
66+
#endif
6567

66-
#define ITM0 ConvertCOM_ComHandle( ITM_VIRTUAL_COMPORTNUM )
68+
#define ITM0 ConvertCOM_GenericHandle( ITM_GENERIC_PORTNUM )
6769
#define COM1 ConvertCOM_ComHandle(1)
6870
#define COM2 ConvertCOM_ComHandle(2)
6971
#define COM3 ConvertCOM_ComHandle(3)

DeviceCode/include/COM_decl.h

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,70 @@
55
#ifndef _DRIVERS_COM_DIRECTOR_DECL_H_
66
#define _DRIVERS_COM_DIRECTOR_DECL_H_ 1
77

8-
//--//
8+
// The functionality of Generic ports is triggered by
9+
// defining TOTAL_GENERIC_PORTS to a value > 0 in the
10+
// solution's platform_selector.h header file
11+
// Otherwise, the implementation of these functions is
12+
// just a stub that returns values indicating failure
13+
// as they should never be called.
14+
15+
BOOL GenericPort_Initialize( int portNum );
16+
BOOL GenericPort_Uninitialize( int portNum );
17+
int GenericPort_Write( int portNum, const char* Data, size_t size );
18+
int GenericPort_Read( int portNum, char* Data, size_t size );
19+
BOOL GenericPort_Flush( int portNum );
20+
void GenericPort_ProtectPins( int portNum, BOOL On );
21+
BOOL GenericPort_IsSslSupported( int portNum );
22+
BOOL GenericPort_UpgradeToSsl( int portNum, const UINT8* pCACert, UINT32 caCertLen, const UINT8* pDeviceCert, UINT32 deviceCertLen, LPCSTR szTargetHost );
23+
BOOL GenericPort_IsUsingSsl( int portNum );
24+
25+
// interface table for a generic port
26+
// any NULL entries in the table indicates default handling is desired
27+
struct IGenericPort
28+
{
29+
// default returns TRUE
30+
BOOL (*Initialize)( void* pInstance );
31+
32+
// default returns TRUE
33+
BOOL (*Uninitialize)( void* pInstance );
34+
35+
// default return 0
36+
int (*Write)( void* pInstance, const char* Data, size_t size );
37+
38+
// defualt return 0
39+
int (*Read)( void* pInstance, char* Data, size_t size );
40+
41+
// default return TRUE
42+
BOOL (*Flush)( void* pInstance );
43+
44+
// default do nothing
45+
void (*ProtectPins)( void* pInstance, BOOL On );
46+
47+
// default return FALSE
48+
BOOL (*IsSslSupported)( void* pInstance );
49+
50+
// default return FALSE
51+
BOOL (*UpgradeToSsl)( void* pInstance, const UINT8* pCACert, UINT32 caCertLen, const UINT8* pDeviceCert, UINT32 deviceCertLen, LPCSTR szTargetHost );
52+
53+
// default return FALSE
54+
BOOL (*IsUsingSsl)( void* pInstance );
55+
};
56+
57+
struct GenericPortTableEntry
58+
{
59+
IGenericPort const& Port;
60+
void* pInstance;
61+
};
62+
63+
#if TOTAL_GENERIC_PORTS > 0
64+
// ConvertCOM_GenericPort( ComPortHandle ) produces an index into this table
65+
// This table is provided by the solution to allow customization and extensibility
66+
// at the solution level. Individual port "drivers" can provide a common
67+
// GenericPortTableEntry structure implementation yet still remain independent of
68+
// the actual solution since the solution owns the table, and ordering and thus the
69+
// handle definitions as well.
70+
extern GenericPortTableEntry const* const g_GenericPorts[ TOTAL_GENERIC_PORTS ];
71+
#endif
972

1073
extern INT32 g_DebuggerPort_SslCtx_Handle;
1174

DeviceCode/include/tinyhal.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ struct GPIO_FLAG
183183
#define STANDARD_USART_MIN_BAUDRATE 75
184184
#define STANDARD_USART_MAX_BAUDRATE 2304000
185185

186-
// Defines a type representing both a port type or "transport" and a port number
186+
// COM_HANDLE Defines a type representing both a port type or "transport" and a port number
187187
// The COM_HANDLE is a multi bit field value with the following bit fields usage
188188
// |--------+--------+--------+--------|
189189
// |33222222|22221111|111111 | |
190-
// |10987654|32109876|54321098|76543210|
190+
// |10987654|32109876|54321098|76543210| bit position
191191
// |--------+--------+--------+--------|
192192
// |00000000|00000000|TTTTTTTT|pppppppp| ( transport != USB_TRANSPORT )
193193
// |--------+--------+--------+--------|
@@ -203,12 +203,20 @@ struct GPIO_FLAG
203203
// LCD_TRANSPORT => 5
204204
// FLASH_WRITE_TRANSPORT => 6
205205
// MESSAGING_TRANSPORT => 7
206+
// GENERIC_TRANSPORT => 8
206207
// p => port instance number
207-
// Port instances in the handle are 1 based. (e.g. p == 0 is invalid )
208+
// Port instances in the handle are 1 based. (e.g. p == 0 is invalid except when T == 0 )
208209
// c -> Controller instance number ( USB_TRANSPORT only )
209210
//
210-
// NULL_PORT => T==0 && p == 0
211-
//
211+
// NULL_PORT => T==0 && p == 0
212+
//
213+
// GENERIC_TRANSPORT is any custom port that isn't one of the above, they
214+
// are implemneted for the DebugPort_xxxx apis and the port number is
215+
// and index into a const global table of port interfaces (structure of
216+
// function pointers) These allow custom extensions to the normal transports
217+
// without needing to continue defining additional transport types and modifiying
218+
// switch on transport code. To keep compatibility high and code churn low, the
219+
// previous legacy transports remain.
212220
typedef INT32 COM_HANDLE;
213221

214222
#define TRANSPORT_SHIFT 8
@@ -222,6 +230,7 @@ typedef INT32 COM_HANDLE;
222230
#define ExtractEventFromTransport(x) (ExtractTransport(x) == USART_TRANSPORT ? SYSTEM_EVENT_FLAG_COM_IN: \
223231
ExtractTransport(x) == USB_TRANSPORT ? SYSTEM_EVENT_FLAG_USB_IN: \
224232
ExtractTransport(x) == SOCKET_TRANSPORT ? SYSTEM_EVENT_FLAG_SOCKET: \
233+
ExtractTransport(x) == GENERIC_TRANSPORT ? SYSTEM_EVENT_FLAG_GENERIC_PORT: \
225234
ExtractTransport(x) == DEBUG_TRANSPORT ? SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY: \
226235
ExtractTransport(x) == MESSAGING_TRANSPORT ? SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY: \
227236
0) \
@@ -248,11 +257,14 @@ typedef INT32 COM_HANDLE;
248257

249258
#define MESSAGING_TRANSPORT (7 << TRANSPORT_SHIFT)
250259

260+
#define GENERIC_TRANSPORT (8 << TRANSPORT_SHIFT)
261+
251262
#define COM_IsSerial(x) (((x) & TRANSPORT_MASK) == USART_TRANSPORT)
252263
#define COM_IsUsb(x) (((x) & TRANSPORT_MASK) == USB_TRANSPORT)
253264
#define COM_IsSock(x) (((x) & TRANSPORT_MASK) == SOCKET_TRANSPORT)
254265
#define COM_IsDebug(x) (((x) & TRANSPORT_MASK) == DEBUG_TRANSPORT)
255266
#define COM_IsMessaging(x) (((x) & TRANSPORT_MASK) == MESSAGING_TRANSPORT)
267+
#define COM_IsGeneric(x) (((x) & TRANSPORT_MASK) == GENERIC_TRANSPORT)
256268

257269
// Extracts a USART port number from a USART COM_HANDLE
258270
#define ConvertCOM_ComPort(x) (((x) & PORT_NUMBER_MASK) - 1)
@@ -272,9 +284,12 @@ typedef INT32 COM_HANDLE;
272284
// Extracts a Debug transport port id from a DEBUG_TRANSPORT COM_HANDLE
273285
#define ConvertCOM_DebugPort(x) (((x) & PORT_NUMBER_MASK) - 1)
274286

275-
// Extracts a messaging transport port id from a MESSAGING_TRASNPORT COM_HANDLE
287+
// Extracts a messaging transport port id from a MESSAGING_TRANSPORT COM_HANDLE
276288
#define ConvertCOM_MessagingPort(x) (((x) & PORT_NUMBER_MASK) - 1)
277289

290+
// Extracts a generic transport port id from a GENERIC_TRANSPORT COM_HANDLE
291+
#define ConvertCOM_GenericPort(x) (((x) & PORT_NUMBER_MASK) - 1)
292+
278293
// Creates a COM_HANDLE value for a platform specific USART port number
279294
#define ConvertCOM_ComHandle(x) ((COM_HANDLE)((x) + USART_TRANSPORT + 1))
280295

@@ -289,10 +304,11 @@ typedef INT32 COM_HANDLE;
289304
// Creates a COM_HANDLE value for a platform specific port number
290305
#define ConvertCOM_DebugHandle(x) ((COM_HANDLE)((x) + DEBUG_TRANSPORT + 1))
291306

292-
// Creates a COM_HANDLE value for a platform specific MESsAGING port number
307+
// Creates a COM_HANDLE value for a platform specific MESSAGING port number
293308
#define ConvertCOM_MessagingHandle(x)((COM_HANDLE)((x) + MESSAGING_TRANSPORT + 1))
294309

295-
//--//
310+
// Creates a COM_HANDLE value for a platform specific GENERIC port number
311+
#define ConvertCOM_GenericHandle(x)((COM_HANDLE)((x) + GENERIC_TRANSPORT + 1))
296312

297313
typedef UINT32 FLASH_WORD;
298314

@@ -638,7 +654,7 @@ void ApplicationEntryPoint();
638654
#define SYSTEM_EVENT_FLAG_TIMER1 0x00000020
639655
#define SYSTEM_EVENT_FLAG_TIMER2 0x00000040
640656
#define SYSTEM_EVENT_FLAG_BUTTON 0x00000080
641-
#define SYSTEM_EVENT_FLAG_UNUSED_0x00000100 0x00000100
657+
#define SYSTEM_EVENT_FLAG_GENERIC_PORT 0x00000100
642658
#define SYSTEM_EVENT_FLAG_UNUSED_0x00000200 0x00000200
643659
#define SYSTEM_EVENT_FLAG_UNUSED_0x00000400 0x00000400
644660
#define SYSTEM_EVENT_FLAG_NETWORK 0x00000800

0 commit comments

Comments
 (0)