-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CHIP stack module. #6967
Add CHIP stack module. #6967
Conversation
240cd4d
to
9d8fd91
Compare
(#6931): CHIP initialization should be posted to chip thread, in order to avoid racing problemsconnectedhomeip/src/stack/Stack.h Lines 207 to 217 in 0eeefa6
This comment was generated by todo based on a
|
(#6931): CHIP shutdown should be posted to chip thread, in order to avoid racing problemsconnectedhomeip/src/stack/Stack.h Lines 232 to 242 in 0eeefa6
This comment was generated by todo based on a
|
This PR adds more code than it removes... |
I'm also not convinced it's a step forward in maintainability. Now everyone will have to wrap their head around all of the metaprogramming to understand how to build a ChipStack. We should keep it simple. |
exit(err); | ||
} | ||
|
||
err = Crypto::add_entropy_source(app_entropy_source, NULL, 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crypto tests sound as if they may want an entropy source. Event loop also seems potentially important.
I would understand 'esp tests do not use wifi' because qemu, however this should be documented and probably a separate PR from the stack module unless it interferes with that...and if it does please explain why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This are duplicated in PlatformManagerImpl::_InitChipStack
connectedhomeip/src/platform/ESP32/PlatformManagerImpl.cpp
Lines 56 to 107 in 82a8544
CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) | |
{ | |
CHIP_ERROR err; | |
wifi_init_config_t cfg; | |
uint8_t ap_mac[6]; | |
wifi_mode_t mode; | |
// Make sure the LwIP core lock has been initialized | |
err = Internal::InitLwIPCoreLock(); | |
SuccessOrExit(err); | |
err = esp_netif_init(); | |
SuccessOrExit(err); | |
// Arrange for the ESP event loop to deliver events into the CHIP Device layer. | |
err = esp_event_loop_create_default(); | |
SuccessOrExit(err); | |
esp_netif_create_default_wifi_ap(); | |
esp_netif_create_default_wifi_sta(); | |
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL); | |
SuccessOrExit(err); | |
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL); | |
SuccessOrExit(err); | |
// Initialize the ESP WiFi layer. | |
cfg = WIFI_INIT_CONFIG_DEFAULT(); | |
err = esp_wifi_init(&cfg); | |
SuccessOrExit(err); | |
esp_wifi_get_mode(&mode); | |
if ((mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA)) | |
{ | |
esp_fill_random(ap_mac, sizeof(ap_mac)); | |
/* Bit 0 of the first octet of MAC Address should always be 0 */ | |
ap_mac[0] &= (uint8_t) ~0x01; | |
err = esp_wifi_set_mac(ESP_IF_WIFI_AP, ap_mac); | |
SuccessOrExit(err); | |
} | |
// Call _InitChipStack() on the generic implementation base class | |
// to finish the initialization process. | |
err = Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_InitChipStack(); | |
SuccessOrExit(err); | |
err = chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16); | |
SuccessOrExit(err); | |
exit: | |
return err; | |
} |
(#7076): esp_wifi_init is pretty unstable on esp32_qemuconnectedhomeip/src/include/platform/internal/GenericPlatformManagerImpl.cpp Lines 98 to 101 in 97b1b16
This comment was generated by todo based on a
|
(#7076): esp_wifi_init is pretty unstable on esp32_qemuconnectedhomeip/src/platform/ESP32/PlatformManagerImpl.cpp Lines 91 to 94 in 97b1b16
This comment was generated by todo based on a
|
* remove duplicated initialization code, in the following files: * PlatformManagerImpl::_InitChipStack in src/platform/ESP32/PlatformManagerImpl.cpp * app_main in src/test_driver/esp32/main/main_app.cpp * Do not create socket during tests. * ESP32 frees socket async, but system layer is shutdown before socket is freed, so all socket are leaked when shutting down chip stack. * This is fine for production, but tests are running in a batch, creating too many sockets will exhaust the socket pool. * Make PlatformManagerImpl::_InitChipStack reentrant * Same reason as above, tests are running in a batch, but there is no way to shutdown PlatformManager, so _InitChipStack is skipped on the following test cases.
Size increase report for "nrfconnect-example-build" from ebd9e0a
Full report output
|
Size increase report for "esp32-example-build" from ebd9e0a
Full report output
|
Size increase report for "gn_qpg6100-example-build" from ebd9e0a
Full report output
|
static constexpr size_t kMaxTcpActiveConnectionCount = 4; | ||
static constexpr size_t kMaxTcpPendingPackets = 4; | ||
|
||
using transport = chip::TransportMgr< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we generally start type names with a capital letter. Change to "Transport"?
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
#if CHIP_DEVICE_LAYER_TARGET_DARWIN | ||
err = PersistedStorage::KeyValueStoreMgrImpl().Init("chip.store"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea: Should we add Init
method to the common KeyValueStoreMgr
interface, add some "storageLocation" parameter to StackParameters
and unify this initialization code by implementing DefaultStorageConfiguration
when the device layer is present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good suggestion, but this PR is only refactoring current code, I'd like it to be changed as less as possible. We can do it in the following up PRs.
|
||
#pragma once | ||
|
||
#include <stack/Stack.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self-reference?
#include <transport/TransportMgr.h> | ||
#include <transport/raw/UDP.h> | ||
|
||
#if CONFIG_DEVICE_LAYER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just include ChipDeviceLayer.h
(unconditionally) which includes all necessary configs and PlatformManager.h
.
ReturnErrorOnFailure(Platform::MemoryInit()); | ||
#if CONFIG_DEVICE_LAYER | ||
// Initialize the CHIP stack. | ||
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().InitChipStack()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: For some reason, currently ThreadStackMgr().InitThreadStack();
is also needed for Thread devices, so it either should be started here or incorporated into InitChipStack()
when CHIP_DEVICE_CONFIG_ENABLE_THREAD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that ThreadStackMgr().InitThreadStack()
is called after InitChipStack()
for platforms with thread support. Maybe we should separate hardware initialization and chip stack initialization, and leave InitChipStack()
outside chip stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why ThreadStackManager can't be initialized by InitChipStack (which initializes other platform components). Maybe it's because ThreadStackManager can post events to the CHIP thread and the intention was not to initialize ThreadStackManager before the CHIP thread is started. Anyway, in case you plan to move the CHIP thread creation to the CHIP stack it would make sense to initialize ThreadStackManager in the comon code, too.
To the comment, "2. Create the CHIP thread", per #6561, do we absolutely need a CHIP thread? Ideally, in the simples desktop or mobile app or in the simplest RTOS system, we could have a single thread that provides the animating context for a number of different sources of work. |
/rebase |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This stale pull request has been automatically closed. Thank you for your contributions. |
@kghost Will the work be continued at some point? |
Problem
CHIP stack initialization and shutdown are spread around. There are lots of duplicated code in all test cases and applications.
Change overview
This PR add a centralized class to initialize and shutdown all chip stack singletons.
Testing
This PR is a refactor, unit tests are used for verify.
I have manually tested echo requester/responder and im requester/responder. All verified are working.