Skip to content

Commit 0c03fa8

Browse files
[linux] Land the First (1st) of Nine (9) Phases for the Linux DeviceLayer Adapation (project-chip#614)
* [linux] Add initial Linux platform DeviceLayer. - Adds Device Layer for Linux. - Uses SystemLayer Sockets. - Entropy and time implementations. - Stub out ble, connectivity, and configuration / storage for follow-on PR. - Uses pthreads for mutex and tasks. - Uses std::chrono for monotonic system time. * [linux] Add PlatformMgr tests. * [linux] Add CircleCI target for linux device layer. * [linux] Add fixme reference to LWIP ifdef. * Restyled by clang-format * [linux] fix header order; fix build After the latest rebase, the following error was coming up: ``` ../../src/include/platform/ConnectivityManager.h:252:40: fatal error: platform/CHIP_DEVICE_LAYER_TARGET/ConnectivityManagerImpl.h: No such file or directory 252 | #define CONNECTIVITYMANAGERIMPL_HEADER <platform/CHIP_DEVICE_LAYER_TARGET/ConnectivityManagerImpl.h> ``` Though CHIP_DEVICE_LAYER_TARGET=Linux is set using AC_SUBST in configure.ac, the definition, which was working fine before, was mysteriously getting lost. It turns out the header re-ordering PR was the root cause of the issue. The fix was to change all sources in src/platform/Linux to move this include first: #include <platform/internal/CHIPDeviceLayerInternal.h> The error did not lead to the fix in an obvious way, so the issue is being documented here. * [linux] Update linux-embedded target to follow circleci matrix template. * [linux] Fix naming nits. Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 9c558bf commit 0c03fa8

35 files changed

+2935
-394
lines changed

.circleci/config.yml

+102-348
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config/executors/@executors.yml

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ esp32-build:
1010
esp32-qemu-build:
1111
docker:
1212
- image: connectedhomeip/chip-build-esp32-qemu:0.2.11
13+
linux-embedded:
14+
environment:
15+
BOOTSTRAP_ARGUMENTS: " --with-device-layer=linux"
16+
docker:
17+
- image: connectedhomeip/chip-build:0.2.11
1318
mbedtls-build:
1419
environment:
1520
BOOTSTRAP_ARGUMENTS: " --with-crypto=mbedtls"

.circleci/config/jobs/test.yml

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ steps:
3636
command:
3737
scripts/tools/run_if.sh "main-build clang-build" "$BUILD_TYPE"
3838
scripts/tests/openssl_tests.sh
39+
- run:
40+
name: Run Platform Tests
41+
command:
42+
scripts/tools/run_if.sh "linux-embedded" "$BUILD_TYPE"
43+
make -C build/default/src/platform check
3944
- run:
4045
name: Run All Unit & Functional Tests
4146
command:

.circleci/config/workflows/Main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
name: Build CHIP [<< matrix.builder >>]
44
matrix:
55
parameters:
6-
builder: ["main-build", "mbedtls-build", "clang-build"]
6+
builder: ["main-build", "mbedtls-build", "clang-build", "linux-embedded"]
77
filters:
88
branches:
99
ignore:
@@ -12,7 +12,7 @@ jobs:
1212
name: Run Tests [<< matrix.builder >>]
1313
matrix:
1414
parameters:
15-
builder: ["main-build", "mbedtls-build", "clang-build"]
15+
builder: ["main-build", "mbedtls-build", "clang-build", "linux-embedded"]
1616
requires:
1717
- Build CHIP [<< matrix.builder >>]
1818
filters:

configure.ac

+20-18
Original file line numberDiff line numberDiff line change
@@ -965,17 +965,11 @@ AC_DEFINE_UNQUOTED([CONFIG_NETWORK_LAYER_INET],[${CONFIG_NETWORK_LAYER_INET}],[D
965965
AC_MSG_CHECKING([device layer])
966966
AC_ARG_WITH(device-layer,
967967
[AS_HELP_STRING([--with-device-layer=LAYER],
968-
[Specify the target environment for the CHIP Device Layer. Choose one of: efr32, esp32, nrf5, or none @<:@default=none@:>@.])],
968+
[Specify the target environment for the CHIP Device Layer. Choose one of: efr32, esp32, nrf5, linux, or none @<:@default=none@:>@.])],
969969
[
970970
case "${with_device_layer}" in
971971
972-
esp32|none)
973-
;;
974-
975-
nrf5|none)
976-
;;
977-
978-
efr32|none)
972+
efr32|esp32|nrf5|linux|none)
979973
;;
980974
981975
*)
@@ -987,39 +981,41 @@ AC_ARG_WITH(device-layer,
987981
[with_device_layer=none])
988982
AC_MSG_RESULT(${with_device_layer})
989983

984+
# Disable all device layer targets by default
985+
CHIP_DEVICE_LAYER_TARGET_LINUX=0
986+
CHIP_DEVICE_LAYER_TARGET_ESP32=0
987+
CHIP_DEVICE_LAYER_TARGET_NRF5=0
988+
CHIP_DEVICE_LAYER_TARGET_EFR32=0
989+
990990
case "${with_device_layer}" in
991+
linux)
992+
CONFIG_DEVICE_LAYER=1
993+
CHIP_DEVICE_LAYER_TARGET=Linux
994+
CHIP_DEVICE_LAYER_TARGET_LINUX=1
995+
;;
996+
991997
esp32)
992998
CONFIG_DEVICE_LAYER=1
993999
CHIP_DEVICE_LAYER_TARGET=ESP32
9941000
CHIP_DEVICE_LAYER_TARGET_ESP32=1
995-
CHIP_DEVICE_LAYER_TARGET_NRF5=0
996-
CHIP_DEVICE_LAYER_TARGET_EFR32=0
9971001
;;
9981002

9991003
nrf5)
10001004
CONFIG_DEVICE_LAYER=1
10011005
CHIP_DEVICE_LAYER_TARGET=nRF5
10021006
CHIP_DEVICE_LAYER_TARGET_NRF5=1
1003-
CHIP_DEVICE_LAYER_TARGET_ESP32=0
1004-
CHIP_DEVICE_LAYER_TARGET_EFR32=0
10051007
;;
10061008

10071009
efr32)
10081010
CONFIG_DEVICE_LAYER=1
10091011
CHIP_DEVICE_LAYER_TARGET=EFR32
10101012
CHIP_DEVICE_LAYER_TARGET_EFR32=1
1011-
CHIP_DEVICE_LAYER_TARGET_NRF5=0
1012-
CHIP_DEVICE_LAYER_TARGET_ESP32=0
10131013
;;
10141014

10151015
none)
10161016
CONFIG_DEVICE_LAYER=0
10171017
CHIP_DEVICE_LAYER_TARGET=NONE
1018-
CHIP_DEVICE_LAYER_TARGET_ESP32=0
1019-
CHIP_DEVICE_LAYER_TARGET_NRF5=0
1020-
CHIP_DEVICE_LAYER_TARGET_EFR32=0
10211018
;;
1022-
10231019
esac
10241020

10251021
AC_SUBST(CONFIG_DEVICE_LAYER)
@@ -1041,6 +1037,10 @@ AC_SUBST(CHIP_DEVICE_LAYER_TARGET_NRF5)
10411037
AM_CONDITIONAL([CHIP_DEVICE_LAYER_TARGET_NRF5], [test "${CHIP_DEVICE_LAYER_TARGET_NRF5}" = 1])
10421038
AC_DEFINE_UNQUOTED([CHIP_DEVICE_LAYER_TARGET_NRF5],[${CHIP_DEVICE_LAYER_TARGET_NRF5}],[Define to 1 if you want to build the CHIP Device Layer for Nordic nRF5* platforms.])
10431039

1040+
AC_SUBST(CHIP_DEVICE_LAYER_TARGET_LINUX)
1041+
AM_CONDITIONAL([CHIP_DEVICE_LAYER_TARGET_LINUX], [test "${CHIP_DEVICE_LAYER_TARGET_LINUX}" = 1])
1042+
AC_DEFINE_UNQUOTED([CHIP_DEVICE_LAYER_TARGET_LINUX],[${CHIP_DEVICE_LAYER_TARGET_LINUX}],[Define to 1 if you want to build the CHIP Device Layer for Linux platforms.])
1043+
10441044
if test "${CONFIG_DEVICE_LAYER}" = 1; then
10451045
AC_DEFINE_UNQUOTED([BLE_PLATFORM_CONFIG_INCLUDE],
10461046
[<platform/${CHIP_DEVICE_LAYER_TARGET}/BlePlatformConfig.h>],
@@ -2090,6 +2090,7 @@ src/lib/core/tests/Makefile
20902090
src/lib/support/Makefile
20912091
src/lib/support/tests/Makefile
20922092
src/platform/Makefile
2093+
src/platform/tests/Makefile
20932094
src/qrcodetool/Makefile
20942095
tests/Makefile
20952096
])
@@ -2116,6 +2117,7 @@ AC_MSG_NOTICE([
21162117
Target architecture : ${target_cpu}
21172118
Target OS : ${target_os}
21182119
Target style : ${CHIP_TARGET_STYLE}
2120+
Device layer : ${CHIP_DEVICE_LAYER_TARGET}
21192121
Cryptographic implementation : ${CHIP_CRYPTO}
21202122
Target network layer : ${with_network_layer}
21212123
Target network system(s) : ${CONFIG_TARGET_NETWORKS}

src/include/platform/ConnectivityManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ template <class>
3535
class GenericPlatformManagerImpl;
3636
template <class>
3737
class GenericPlatformManagerImpl_FreeRTOS;
38+
template <class>
39+
class GenericPlatformManagerImpl_POSIX;
3840
} // namespace Internal
3941

4042
class ConnectivityManagerImpl;
@@ -183,6 +185,8 @@ class ConnectivityManager
183185
friend class Internal::GenericPlatformManagerImpl;
184186
template <class>
185187
friend class Internal::GenericPlatformManagerImpl_FreeRTOS;
188+
template <class>
189+
friend class Internal::GenericPlatformManagerImpl_POSIX;
186190
friend class Internal::NetworkProvisioningServerImpl;
187191
template <class>
188192
friend class Internal::GenericNetworkProvisioningServerImpl;

src/include/platform/PlatformManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class GenericPlatformManagerImpl;
5858
template <class>
5959
class GenericPlatformManagerImpl_FreeRTOS;
6060
template <class>
61+
class GenericPlatformManagerImpl_POSIX;
62+
template <class>
6163
class GenericConnectivityManagerImpl_Thread;
6264
template <class>
6365
class GenericThreadStackManagerImpl_OpenThread;
@@ -104,6 +106,8 @@ class PlatformManager
104106
template <class>
105107
friend class Internal::GenericPlatformManagerImpl_FreeRTOS;
106108
template <class>
109+
friend class Internal::GenericPlatformManagerImpl_POSIX;
110+
template <class>
107111
friend class Internal::GenericConnectivityManagerImpl_Thread;
108112
template <class>
109113
friend class Internal::GenericThreadStackManagerImpl_OpenThread;

src/include/platform/internal/GenericPlatformManagerImpl.ipp

+21-24
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* GenericPlatformManagerImpl<> template.
2323
*/
2424

25-
2625
#ifndef GENERIC_PLATFORM_MANAGER_IMPL_IPP
2726
#define GENERIC_PLATFORM_MANAGER_IMPL_IPP
2827

@@ -45,7 +44,7 @@ template class GenericPlatformManagerImpl<PlatformManagerImpl>;
4544

4645
extern CHIP_ERROR InitEntropy();
4746

48-
template<class ImplClass>
47+
template <class ImplClass>
4948
CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_InitChipStack(void)
5049
{
5150
CHIP_ERROR err;
@@ -101,7 +100,7 @@ exit:
101100
return err;
102101
}
103102

104-
template<class ImplClass>
103+
template <class ImplClass>
105104
CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_AddEventHandler(PlatformManager::EventHandlerFunct handler, intptr_t arg)
106105
{
107106
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -116,25 +115,25 @@ CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_AddEventHandler(PlatformManag
116115
}
117116
}
118117

119-
eventHandler = (AppEventHandler *)malloc(sizeof(AppEventHandler));
118+
eventHandler = (AppEventHandler *) malloc(sizeof(AppEventHandler));
120119
VerifyOrExit(eventHandler != NULL, err = CHIP_ERROR_NO_MEMORY);
121120

122-
eventHandler->Next = mAppEventHandlerList;
121+
eventHandler->Next = mAppEventHandlerList;
123122
eventHandler->Handler = handler;
124-
eventHandler->Arg = arg;
123+
eventHandler->Arg = arg;
125124

126125
mAppEventHandlerList = eventHandler;
127126

128127
exit:
129128
return err;
130129
}
131130

132-
template<class ImplClass>
131+
template <class ImplClass>
133132
void GenericPlatformManagerImpl<ImplClass>::_RemoveEventHandler(PlatformManager::EventHandlerFunct handler, intptr_t arg)
134133
{
135134
AppEventHandler ** eventHandlerIndirectPtr;
136135

137-
for (eventHandlerIndirectPtr = &mAppEventHandlerList; *eventHandlerIndirectPtr != NULL; )
136+
for (eventHandlerIndirectPtr = &mAppEventHandlerList; *eventHandlerIndirectPtr != NULL;)
138137
{
139138
AppEventHandler * eventHandler = (*eventHandlerIndirectPtr);
140139

@@ -150,18 +149,18 @@ void GenericPlatformManagerImpl<ImplClass>::_RemoveEventHandler(PlatformManager:
150149
}
151150
}
152151

153-
template<class ImplClass>
152+
template <class ImplClass>
154153
void GenericPlatformManagerImpl<ImplClass>::_ScheduleWork(AsyncWorkFunct workFunct, intptr_t arg)
155154
{
156155
ChipDeviceEvent event;
157-
event.Type = DeviceEventType::kCallWorkFunct;
156+
event.Type = DeviceEventType::kCallWorkFunct;
158157
event.CallWorkFunct.WorkFunct = workFunct;
159-
event.CallWorkFunct.Arg = arg;
158+
event.CallWorkFunct.Arg = arg;
160159

161160
Impl()->PostEvent(&event);
162161
}
163162

164-
template<class ImplClass>
163+
template <class ImplClass>
165164
void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent * event)
166165
{
167166
#if CHIP_PROGRESS_LOGGING
@@ -208,23 +207,24 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
208207
#endif // CHIP_PROGRESS_LOGGING
209208
}
210209

211-
template<class ImplClass>
210+
template <class ImplClass>
212211
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToSystemLayer(const ChipDeviceEvent * event)
213212
{
213+
// TODO(#788): remove ifdef LWIP once SystemLayer event APIs are generally available
214+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
214215
CHIP_ERROR err = CHIP_NO_ERROR;
215216

216217
// Invoke the System Layer's event handler function.
217-
err = SystemLayer.HandleEvent(*event->ChipSystemLayerEvent.Target,
218-
event->ChipSystemLayerEvent.Type,
218+
err = SystemLayer.HandleEvent(*event->ChipSystemLayerEvent.Target, event->ChipSystemLayerEvent.Type,
219219
event->ChipSystemLayerEvent.Argument);
220220
if (err != CHIP_SYSTEM_NO_ERROR)
221221
{
222-
ChipLogError(DeviceLayer, "Error handling CHIP System Layer event (type %d): %s",
223-
event->Type, ErrorStr(err));
222+
ChipLogError(DeviceLayer, "Error handling CHIP System Layer event (type %d): %s", event->Type, ErrorStr(err));
224223
}
224+
#endif
225225
}
226226

227-
template<class ImplClass>
227+
template <class ImplClass>
228228
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToDeviceLayer(const ChipDeviceEvent * event)
229229
{
230230
// Dispatch the event to all the components in the Device Layer.
@@ -237,19 +237,17 @@ void GenericPlatformManagerImpl<ImplClass>::DispatchEventToDeviceLayer(const Chi
237237
ConnectivityMgr().OnPlatformEvent(event);
238238
}
239239

240-
template<class ImplClass>
240+
template <class ImplClass>
241241
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToApplication(const ChipDeviceEvent * event)
242242
{
243243
// Dispatch the event to each of the registered application event handlers.
244-
for (AppEventHandler * eventHandler = mAppEventHandlerList;
245-
eventHandler != NULL;
246-
eventHandler = eventHandler->Next)
244+
for (AppEventHandler * eventHandler = mAppEventHandlerList; eventHandler != NULL; eventHandler = eventHandler->Next)
247245
{
248246
eventHandler->Handler(event, eventHandler->Arg);
249247
}
250248
}
251249

252-
template<class ImplClass>
250+
template <class ImplClass>
253251
void GenericPlatformManagerImpl<ImplClass>::HandleMessageLayerActivityChanged(bool messageLayerIsActive)
254252
{
255253
GenericPlatformManagerImpl<ImplClass> & self = PlatformMgrImpl();
@@ -269,4 +267,3 @@ void GenericPlatformManagerImpl<ImplClass>::HandleMessageLayerActivityChanged(bo
269267
} // namespace chip
270268

271269
#endif // GENERIC_PLATFORM_MANAGER_IMPL_IPP
272-

0 commit comments

Comments
 (0)