Skip to content

Commit

Permalink
reworked silabs main.cpp to follow template. Moved functionality to m…
Browse files Browse the repository at this point in the history
…atterconfig.cpp
  • Loading branch information
Sarthak-Shaha committed Mar 21, 2024
1 parent 7f14133 commit 24aa844
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 78 deletions.
71 changes: 67 additions & 4 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
#include "wfx_rsi.h"
#endif /* SLI_SI91X_MCU_INTERFACE */

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;

#include <crypto/CHIPCryptoPAL.h>
// If building with the EFR32-provided crypto backend, we can use the
// opaque keystore
Expand All @@ -75,6 +71,37 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
#include <performance_test_commands.h>
#endif

#include <AppTask.h>

#include <DeviceInfoProviderImpl.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <examples/platform/silabs/SilabsDeviceAttestationCreds.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#include "FreeRTOSConfig.h"
#include "event_groups.h"
#include "task.h"

/**********************************************************
* Defines
*********************************************************/

#define MAIN_TASK_STACK_SIZE (1024 * 5)
#define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1)

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
using namespace ::chip::Credentials::Silabs;
using namespace chip::DeviceLayer::Silabs;

TaskHandle_t main_Task;
void application_start(void * unused);
volatile int apperror_cnt;
static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

#if CHIP_ENABLE_OPENTHREAD
#include <inet/EndPointStateOpenThread.h>
#include <openthread/cli.h>
Expand Down Expand Up @@ -129,6 +156,42 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

void SilabsMatterConfig::app_init()
{
GetPlatform().Init();

xTaskCreate(application_start, "main_task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &main_Task);
SILABS_LOG("Starting scheduler");
GetPlatform().StartScheduler();

// Should never get here.
chip::Platform::MemoryShutdown();
SILABS_LOG("vTaskStartScheduler() failed");
appError(CHIP_ERROR_INTERNAL);
}

void application_start(void * unused)
{
CHIP_ERROR err = SilabsMatterConfig::InitMatter(BLE_DEV_NAME);
if (err != CHIP_NO_ERROR)
appError(err);

gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

SILABS_LOG("Starting App Task");
err = AppTask::GetAppTask().StartAppTask();
if (err != CHIP_NO_ERROR)
appError(err);

vTaskDelete(main_Task);
}

#if SILABS_OTA_ENABLED
void SilabsMatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
Expand Down
1 change: 1 addition & 0 deletions examples/platform/silabs/MatterConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SilabsMatterConfig
{
public:
static CHIP_ERROR InitMatter(const char * appName);
static void app_init();

private:
static CHIP_ERROR InitOpenThread(void);
Expand Down
76 changes: 8 additions & 68 deletions examples/platform/silabs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <AppTask.h>

#include "AppConfig.h"

#include <DeviceInfoProviderImpl.h>
#include "sl_component_catalog.h"
#include <MatterConfig.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <examples/platform/silabs/SilabsDeviceAttestationCreds.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "event_groups.h"
#include "task.h"

/**********************************************************
* Defines
*********************************************************/

#define MAIN_TASK_STACK_SIZE (1024 * 5)
#define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1)

using namespace ::chip;
using namespace ::chip::DeviceLayer;
using namespace ::chip::Credentials;
using namespace chip::DeviceLayer::Silabs;
#include "sl_system_kernel.h"
#include "sl_system_init.h"

TaskHandle_t main_Task;
void application_start(void * unused);
volatile int apperror_cnt;
static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

// ================================================================================
// Main Code
// ================================================================================
int main(void)
{
GetPlatform().Init();

xTaskCreate(application_start, "main_task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &main_Task);

SILABS_LOG("Starting scheduler");
GetPlatform().StartScheduler();

// Should never get here.
chip::Platform::MemoryShutdown();
SILABS_LOG("vTaskStartScheduler() failed");
appError(CHIP_ERROR_INTERNAL);
}

void application_start(void * unused)
{
CHIP_ERROR err = SilabsMatterConfig::InitMatter(BLE_DEV_NAME);
if (err != CHIP_NO_ERROR)
appError(err);

gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
sl_system_init();

SILABS_LOG("Starting App Task");
err = AppTask::GetAppTask().StartAppTask();
if (err != CHIP_NO_ERROR)
appError(err);
// Initialize the application. For example, create periodic timer(s) or
// task(s) if the kernel is present.
SilabsMatterConfig::app_init();

vTaskDelete(main_Task);
}
}
3 changes: 0 additions & 3 deletions src/platform/silabs/platformAbstraction/GsdkSpam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ extern "C" {

#include "sl_component_catalog.h"
#include "sl_mbedtls.h"
#include "sl_system_init.h"
#if SILABS_LOG_OUT_UART || ENABLE_CHIP_SHELL || CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
#include "uart.h"
#endif
Expand All @@ -68,8 +67,6 @@ SilabsPlatform::SilabsButtonCb SilabsPlatform::mButtonCallback = nullptr;

CHIP_ERROR SilabsPlatform::Init(void)
{
sl_system_init();

mRebootCause = RMU_ResetCauseGet();
// Clear register so it does accumualate the causes of each reset
RMU_ResetCauseClear();
Expand Down
3 changes: 0 additions & 3 deletions src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extern "C" {
#include "sl_event_handler.h"
#include "sl_si91x_led.h"
#include "sl_si91x_led_config.h"
#include "sl_system_init.h"
void soc_pll_config(void);
}

Expand All @@ -50,8 +49,6 @@ CHIP_ERROR SilabsPlatform::Init(void)
{
mButtonCallback = nullptr;

sl_system_init();

// TODO: Setting the highest priority for SVCall_IRQn to avoid the HardFault issue
NVIC_SetPriority(SVCall_IRQn, CORE_INTERRUPT_HIGHEST_PRIORITY);

Expand Down

0 comments on commit 24aa844

Please sign in to comment.