diff --git a/examples/lock-app/silabs/SiWx917/BUILD.gn b/examples/lock-app/silabs/SiWx917/BUILD.gn index c02458d38f86b2..1f9ecd55197c04 100644 --- a/examples/lock-app/silabs/SiWx917/BUILD.gn +++ b/examples/lock-app/silabs/SiWx917/BUILD.gn @@ -200,7 +200,7 @@ efr32_executable("lock_app") { if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli || use_wf200 || use_SiWx917) { - #sources += [ "${examples_plat_dir}/uart.cpp" ] + sources += [ "${examples_plat_dir}/uart.cpp" ] } if (chip_build_libshell) { diff --git a/examples/lock-app/silabs/SiWx917/include/EventHandlerLibShell.h b/examples/lock-app/silabs/SiWx917/include/EventHandlerLibShell.h index 3ad9f11cbf2fdc..e915e472750da4 100644 --- a/examples/lock-app/silabs/SiWx917/include/EventHandlerLibShell.h +++ b/examples/lock-app/silabs/SiWx917/include/EventHandlerLibShell.h @@ -27,13 +27,13 @@ class EventData class AlarmEventData : public EventData { public: - DlAlarmCode alarmCode; + AlarmCodeEnum alarmCode; }; class DoorStateEventData : public EventData { public: - DlDoorState doorState; + DoorStateEnum doorState; }; CHIP_ERROR RegisterLockEvents(); diff --git a/examples/lock-app/silabs/SiWx917/include/LockManager.h b/examples/lock-app/silabs/SiWx917/include/LockManager.h index b451921f804bc4..70a4ceba2438e9 100644 --- a/examples/lock-app/silabs/SiWx917/include/LockManager.h +++ b/examples/lock-app/silabs/SiWx917/include/LockManager.h @@ -141,25 +141,26 @@ class LockManager typedef void (*Callback_fn_completed)(Action_t); void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB); - bool Lock(chip::EndpointId endpointId, const Optional & pin, DlOperationError & err); - bool Unlock(chip::EndpointId endpointId, const Optional & pin, DlOperationError & err); + bool Lock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); + bool Unlock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user); bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, - const chip::CharSpan & userName, uint32_t uniqueId, DlUserStatus userStatus, DlUserType usertype, - DlCredentialRule credentialRule, const DlCredential * credentials, size_t totalCredentials); + const chip::CharSpan & userName, uint32_t uniqueId, UserStatusEnum userStatus, UserTypeEnum usertype, + CredentialRuleEnum credentialRule, const CredentialStruct * credentials, size_t totalCredentials); - bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, + bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, EmberAfPluginDoorLockCredentialInfo & credential); bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, chip::FabricIndex modifier, - DlCredentialStatus credentialStatus, DlCredentialType credentialType, const chip::ByteSpan & credentialData); + DlCredentialStatus credentialStatus, CredentialTypeEnum credentialType, + const chip::ByteSpan & credentialData); DlStatus GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, EmberAfPluginDoorLockWeekDaySchedule & schedule); DlStatus SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, DlScheduleStatus status, - DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute); + DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute); DlStatus GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, EmberAfPluginDoorLockYearDaySchedule & schedule); @@ -170,16 +171,16 @@ class LockManager DlStatus GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule); DlStatus SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime, - uint32_t localEndTime, DlOperatingMode operatingMode); + uint32_t localEndTime, OperatingModeEnum operatingMode); bool IsValidUserIndex(uint16_t userIndex); - bool IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type); + bool IsValidCredentialIndex(uint16_t credentialIndex, CredentialTypeEnum type); bool IsValidWeekdayScheduleIndex(uint8_t scheduleIndex); bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex); bool IsValidHolidayScheduleIndex(uint8_t scheduleIndex); bool setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, - DlOperationError & err); + OperationErrorEnum & err); const char * lockStateToString(DlLockState lockState) const; bool ReadConfigValues(); @@ -206,7 +207,7 @@ class LockManager char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE]; uint8_t mCredentialData[kMaxCredentials][kMaxCredentialSize]; - DlCredential mCredentials[kMaxUsers][kMaxCredentialsPerUser]; + CredentialStruct mCredentials[kMaxUsers][kMaxCredentialsPerUser]; static LockManager sLock; SI917DoorLock::LockInitParams::LockParam LockParams; diff --git a/examples/lock-app/silabs/SiWx917/src/AppTask.cpp b/examples/lock-app/silabs/SiWx917/src/AppTask.cpp index 0582eed798470c..fd8d49a8260b1e 100644 --- a/examples/lock-app/silabs/SiWx917/src/AppTask.cpp +++ b/examples/lock-app/silabs/SiWx917/src/AppTask.cpp @@ -59,8 +59,8 @@ #endif // ENABLE_WSTK_LEDS using chip::app::Clusters::DoorLock::DlLockState; -using chip::app::Clusters::DoorLock::DlOperationError; -using chip::app::Clusters::DoorLock::DlOperationSource; +using chip::app::Clusters::DoorLock::OperationErrorEnum; +using chip::app::Clusters::DoorLock::OperationSourceEnum; using namespace chip; using namespace ::chip::DeviceLayer; @@ -423,7 +423,7 @@ void AppTask::UpdateClusterState(intptr_t context) bool unlocked = LockMgr().NextState(); DlLockState newState = unlocked ? DlLockState::kUnlocked : DlLockState::kLocked; - DlOperationSource source = DlOperationSource::kUnspecified; + OperationSourceEnum source = OperationSourceEnum::kUnspecified; // write the new lock value EmberAfStatus status = diff --git a/examples/lock-app/silabs/SiWx917/src/EventHandlerLibShell.cpp b/examples/lock-app/silabs/SiWx917/src/EventHandlerLibShell.cpp index 02979f56238a23..ef79290bd1961f 100644 --- a/examples/lock-app/silabs/SiWx917/src/EventHandlerLibShell.cpp +++ b/examples/lock-app/silabs/SiWx917/src/EventHandlerLibShell.cpp @@ -104,7 +104,7 @@ CHIP_ERROR AlarmEventHandler(int argc, char ** argv) AlarmEventData * data = Platform::New(); data->eventId = Events::DoorLockAlarm::Id; - data->alarmCode = static_cast(atoi(argv[0])); + data->alarmCode = static_cast(atoi(argv[0])); DeviceLayer::PlatformMgr().ScheduleWork(EventWorkerFunction, reinterpret_cast(data)); @@ -136,7 +136,7 @@ CHIP_ERROR DoorStateEventHandler(int argc, char ** argv) DoorStateEventData * data = Platform::New(); data->eventId = Events::DoorStateChange::Id; - data->doorState = static_cast(atoi(argv[0])); + data->doorState = static_cast(atoi(argv[0])); DeviceLayer::PlatformMgr().ScheduleWork(EventWorkerFunction, reinterpret_cast(data)); diff --git a/examples/lock-app/silabs/SiWx917/src/LockManager.cpp b/examples/lock-app/silabs/SiWx917/src/LockManager.cpp index 0ef26ec0337b6b..3ceba52e8a6f5e 100644 --- a/examples/lock-app/silabs/SiWx917/src/LockManager.cpp +++ b/examples/lock-app/silabs/SiWx917/src/LockManager.cpp @@ -104,9 +104,9 @@ bool LockManager::IsValidUserIndex(uint16_t userIndex) return (userIndex < kMaxUsers); } -bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type) +bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, CredentialTypeEnum type) { - if (DlCredentialType::kProgrammingPIN == type) + if (CredentialTypeEnum::kProgrammingPIN == type) { return (0 == credentialIndex); // 0 is required index for Programming PIN } @@ -144,7 +144,7 @@ bool LockManager::ReadConfigValues() sizeof(mCredentialData), outLen); SILABSConfig::ReadConfigValueBin(SILABSConfig::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), - sizeof(DlCredential) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser, + sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser, outLen); SILABSConfig::ReadConfigValueBin(SILABSConfig::kConfigKey_WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), @@ -283,12 +283,12 @@ void LockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) } } -bool LockManager::Lock(chip::EndpointId endpointId, const Optional & pin, DlOperationError & err) +bool LockManager::Lock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) { return setLockState(endpointId, DlLockState::kLocked, pin, err); } -bool LockManager::Unlock(chip::EndpointId endpointId, const Optional & pin, DlOperationError & err) +bool LockManager::Unlock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) { return setLockState(endpointId, DlLockState::kUnlocked, pin, err); } @@ -306,14 +306,14 @@ bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, Ember const auto & userInDb = mLockUsers[userIndex]; user.userStatus = userInDb.userStatus; - if (DlUserStatus::kAvailable == user.userStatus) + if (UserStatusEnum::kAvailable == user.userStatus) { ChipLogDetail(Zcl, "Found unoccupied user [endpoint=%d]", endpointId); return true; } user.userName = chip::CharSpan(userInDb.userName.data(), userInDb.userName.size()); - user.credentials = chip::Span(mCredentials[userIndex], userInDb.credentials.size()); + user.credentials = chip::Span(mCredentials[userIndex], userInDb.credentials.size()); user.userUniqueId = userInDb.userUniqueId; user.userType = userInDb.userType; user.credentialRule = userInDb.credentialRule; @@ -336,8 +336,8 @@ bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, Ember } bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, - const chip::CharSpan & userName, uint32_t uniqueId, DlUserStatus userStatus, DlUserType usertype, - DlCredentialRule credentialRule, const DlCredential * credentials, size_t totalCredentials) + const chip::CharSpan & userName, uint32_t uniqueId, UserStatusEnum userStatus, UserTypeEnum usertype, + CredentialRuleEnum credentialRule, const CredentialStruct * credentials, size_t totalCredentials) { ChipLogProgress(Zcl, "Door Lock App: LockManager::SetUser " @@ -383,14 +383,14 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: mCredentials[userIndex][i].CredentialIndex = i + 1; } - userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); + userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); // Save user information in NVM flash SILABSConfig::WriteConfigValueBin(SILABSConfig::kConfigKey_LockUser, reinterpret_cast(&mLockUsers), sizeof(EmberAfPluginDoorLockUserInfo) * LockParams.numberOfUsers); SILABSConfig::WriteConfigValueBin(SILABSConfig::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), - sizeof(DlCredential) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser); + sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser); SILABSConfig::WriteConfigValueBin(SILABSConfig::kConfigKey_LockUserName, reinterpret_cast(mUserNames), sizeof(mUserNames)); @@ -400,11 +400,11 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: return true; } -bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, +bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, EmberAfPluginDoorLockCredentialInfo & credential) { - if (DlCredentialType::kProgrammingPIN == credentialType) + if (CredentialTypeEnum::kProgrammingPIN == credentialType) { VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false); // programming pin index is only index allowed to contain 0 @@ -443,11 +443,11 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential } bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, - chip::FabricIndex modifier, DlCredentialStatus credentialStatus, DlCredentialType credentialType, + chip::FabricIndex modifier, DlCredentialStatus credentialStatus, CredentialTypeEnum credentialType, const chip::ByteSpan & credentialData) { - if (DlCredentialType::kProgrammingPIN == credentialType) + if (CredentialTypeEnum::kProgrammingPIN == credentialType) { VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false); // programming pin index is only index allowed to contain 0 @@ -509,7 +509,7 @@ DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we } DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, - DlScheduleStatus status, DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, + DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute) { @@ -609,7 +609,7 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho } DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, - uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) + uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode) { VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed @@ -650,7 +650,7 @@ const char * LockManager::lockStateToString(DlLockState lockState) const } bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, - DlOperationError & err) + OperationErrorEnum & err) { // Assume pin is required until told otherwise @@ -681,7 +681,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat // Check the PIN code for (uint8_t i = 0; i < kMaxCredentials; i++) { - if (mLockCredentials[i].credentialType != DlCredentialType::kPin || + if (mLockCredentials[i].credentialType != CredentialTypeEnum::kPin || mLockCredentials[i].status == DlCredentialStatus::kAvailable) { continue; @@ -704,6 +704,6 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat "[endpointId=%d]", lockStateToString(lockState), endpointId); - err = DlOperationError::kInvalidCredential; + err = OperationErrorEnum::kInvalidCredential; return false; } diff --git a/examples/lock-app/silabs/SiWx917/src/ZclCallbacks.cpp b/examples/lock-app/silabs/SiWx917/src/ZclCallbacks.cpp index 9c1812a90c0a04..778637e250a5a5 100644 --- a/examples/lock-app/silabs/SiWx917/src/ZclCallbacks.cpp +++ b/examples/lock-app/silabs/SiWx917/src/ZclCallbacks.cpp @@ -58,7 +58,8 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfDoorLockClusterInitCallback(EndpointId endpoint) {} -bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err) +bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, + OperationErrorEnum & err) { ChipLogProgress(Zcl, "Door Lock App: Lock Command endpoint=%d", endpointId); bool status = LockMgr().Lock(endpointId, pinCode, err); @@ -70,7 +71,7 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const O } bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional & pinCode, - DlOperationError & err) + OperationErrorEnum & err) { ChipLogProgress(Zcl, "Door Lock App: Unlock Command endpoint=%d", endpointId); bool status = LockMgr().Unlock(endpointId, pinCode, err); @@ -82,7 +83,7 @@ bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const return status; } -bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, +bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, EmberAfPluginDoorLockCredentialInfo & credential) { return LockMgr().GetCredential(endpointId, credentialIndex, credentialType, credential); @@ -90,7 +91,7 @@ bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t cr bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, chip::FabricIndex modifier, DlCredentialStatus credentialStatus, - DlCredentialType credentialType, const chip::ByteSpan & credentialData) + CredentialTypeEnum credentialType, const chip::ByteSpan & credentialData) { return LockMgr().SetCredential(endpointId, credentialIndex, creator, modifier, credentialStatus, credentialType, credentialData); @@ -103,8 +104,8 @@ bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userInde bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, const chip::CharSpan & userName, uint32_t uniqueId, - DlUserStatus userStatus, DlUserType usertype, DlCredentialRule credentialRule, - const DlCredential * credentials, size_t totalCredentials) + UserStatusEnum userStatus, UserTypeEnum usertype, CredentialRuleEnum credentialRule, + const CredentialStruct * credentials, size_t totalCredentials) { return LockMgr().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, credentialRule, @@ -130,7 +131,7 @@ DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t h } DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, - DlScheduleStatus status, DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, + DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute) { return LockMgr().SetWeekdaySchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, endHour, @@ -144,7 +145,7 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t y } DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, - uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) + uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode) { return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); } diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 990a43d59d66c7..94dfddc296b309 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -18,6 +18,8 @@ import("${chip_root}/src/lib/lib.gni") import("${chip_root}/src/platform/device.gni") import("${efr32_sdk_build_root}/SiWx917_sdk.gni") +silabs_common_plat_dir = "${chip_root}/examples/platform/silabs" + config("chip_examples_project_config") { include_dirs = [ "project_include" ] @@ -44,7 +46,7 @@ source_set("efr-matter-shell") { if (chip_build_libshell) { defines = [ "ENABLE_CHIP_SHELL" ] - sources = [ "matter_shell.cpp" ] + sources = [ "${silabs_common_plat_dir}/matter_shell.cpp" ] include_dirs = [ "." ] public_deps = [ @@ -66,8 +68,8 @@ config("attestation-credentials-config") { source_set("efr32-attestation-credentials") { sources = [ - "../SilabsDeviceAttestationCreds.cpp", - "../SilabsDeviceAttestationCreds.h", + "${silabs_common_plat_dir}/SilabsDeviceAttestationCreds.cpp", + "${silabs_common_plat_dir}/SilabsDeviceAttestationCreds.h", ] public_deps = [ diff --git a/examples/platform/silabs/SiWx917/uart.cpp b/examples/platform/silabs/SiWx917/uart.cpp index d264e9644e9f08..068fba75d46fc1 100644 --- a/examples/platform/silabs/SiWx917/uart.cpp +++ b/examples/platform/silabs/SiWx917/uart.cpp @@ -16,69 +16,135 @@ * limitations under the License. */ #include "AppConfig.h" +#include "USART.h" #include "matter_shell.h" - +#include "rsi_rom_egpio.h" +#include "siwx917_utils.h" #ifdef __cplusplus extern "C" { #endif #include "assert.h" #include "rsi_board.h" #include "uart.h" -#include "uartdrv.h" #include #include -#if !defined(MIN) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#endif +extern ARM_DRIVER_USART Driver_USART0; +static ARM_DRIVER_USART * UARTdrv = &Driver_USART0; + +ARM_USART_CAPABILITIES drv_capabilities; +ARM_USART_STATUS status; + +#define BUFFER_SIZE 1 +uint8_t rx_buffer; + +#define BAUD_VALUE 115200 #define UART_CONSOLE_ERR -1 // Negative value in case of UART Console action failed. Triggers a failure for PW_RPC -void uartConsoleInit(void) +void ARM_USART_SignalEvent(uint32_t event); + +void Read_Capabilities(void) { - // UART init is already done + drv_capabilities = UARTdrv->GetCapabilities(); } -void USART_IRQHandler(void) +void ARM_USART_SignalEvent(uint32_t event) { + switch (event) + { + case ARM_USART_EVENT_SEND_COMPLETE: + break; + case ARM_USART_EVENT_RECEIVE_COMPLETE: #ifdef ENABLE_CHIP_SHELL - chip::NotifyShellProcessFromISR(); -#endif -#if defined(SL_WIFI) - /* TODO */ -#elif !defined(PW_RPC_ENABLED) - otSysEventSignalPending(); -#endif - -#if (defined(EFR32MG24) || defined(MGM24)) - EUSART_IntClear(SL_UARTDRV_EUSART_VCOM_PERIPHERAL, EUSART_IF_RXFL); -#endif + chip::NotifyShellProcessFromISR(); +#endif; + case ARM_USART_EVENT_TRANSFER_COMPLETE: + case ARM_USART_EVENT_TX_COMPLETE: + case ARM_USART_EVENT_TX_UNDERFLOW: + case ARM_USART_EVENT_RX_OVERFLOW: + case ARM_USART_EVENT_RX_TIMEOUT: + case ARM_USART_EVENT_RX_BREAK: + case ARM_USART_EVENT_RX_FRAMING_ERROR: + case ARM_USART_EVENT_RX_PARITY_ERROR: + case ARM_USART_EVENT_CTS: + case ARM_USART_EVENT_DSR: + case ARM_USART_EVENT_DCD: + case ARM_USART_EVENT_RI: + } } -/* - * @brief Callback triggered when a UARTDRV DMA buffer is full - */ -static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, uint8_t * data, UARTDRV_Count_t transferCount) +void uartConsoleInit(void) { - (void) transferStatus; + int32_t status = 0; + Read_Capabilities(); - uint8_t writeSize = (transferCount - lastCount); - if (RemainingSpace(&sReceiveFifo) >= writeSize) + status = UARTdrv->Initialize(ARM_USART_SignalEvent); + // Setting the GPIO 30 of the radio board (TX) + RSI_EGPIO_HostPadsGpioModeEnable(30); + + // Initialized board UART + DEBUGINIT(); + if (status != ARM_DRIVER_OK) + { + DEBUGOUT("\r\n UART Initialization Failed, Error Code : %d\r\n", status); + } + else { - WriteToFifo(&sReceiveFifo, data + lastCount, writeSize); - lastCount = 0; + DEBUGOUT("\r\n UART Initialization Success\r\n"); } - UARTDRV_Receive(vcom_handle, data, transferCount, UART_rx_callback); + // Power up the UART peripheral + status = UARTdrv->PowerControl(ARM_POWER_FULL); + if (status != ARM_DRIVER_OK) + { + DEBUGOUT("\r\n Failed to Set Power to UART, Error Code : %d\r\n", status); + } + else + { + DEBUGOUT("\r\n Configured Power to UART \r\n"); + } -#ifdef ENABLE_CHIP_SHELL - chip::NotifyShellProcessFromISR(); -#endif -#if defined(SL_WIFI) - /* TODO */ -#elif !defined(PW_RPC_ENABLED) - otSysEventSignalPending(); -#endif + // Enable Receiver and Transmitter lines + status = UARTdrv->Control(ARM_USART_CONTROL_TX, 1); + if (status != ARM_DRIVER_OK) + { + DEBUGOUT("\r\n Failed to Set Transmitter lines to UART, Error Code : %d\r\n", status); + } + else + { + DEBUGOUT("\r\n Set Transmitter lines to UART is sucess \r\n"); + } + + status = UARTdrv->Control(ARM_USART_CONTROL_RX, 1); + if (status != ARM_DRIVER_OK) + { + DEBUGOUT("\r\n Failed to Set Receiver lines to UART, Error Code : %d \r\n", status); + } + else + { + DEBUGOUT("\r\n Set Receiver lines to UART\r\n"); + } + + UARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 | + ARM_USART_FLOW_CONTROL_NONE, + BAUD_VALUE); + if (status != ARM_DRIVER_OK) + { + DEBUGOUT("\r\n Failed to Receive data , Error Code : %d \r\n", status); + } + else + { + DEBUGOUT("\r\n Receives data success \r\n"); + } + + // Creating the receive event as a temp buffer + // this is not used anywhere + status = UARTdrv->Receive(&rx_buffer, 1); + + NVIC_EnableIRQ(USART0_IRQn); + + NVIC_SetPriority(USART0_IRQn, 7); } /* @@ -88,16 +154,17 @@ static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, ui */ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength) { + int32_t status = 0; if (Buf == NULL || BufLength < 1) { return UART_CONSOLE_ERR; } - // Add Terminating char at the end of buffer - Buf[BufLength] = '\0'; - - Board_UARTPutSTR((uint8_t *) Buf); - + status = UARTdrv->Send(Buf, BufLength); + if (status != ARM_DRIVER_OK) + { + return status; + } return BufLength; } @@ -108,19 +175,16 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength) */ int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead) { - uint32_t data; - + int32_t status = 0; if (Buf == NULL || NbBytesToRead < 1) { return UART_CONSOLE_ERR; } - - while (--NbBytesToRead >= 0) + status = UARTdrv->Receive(Buf, NbBytesToRead); + if (status != ARM_DRIVER_OK) { - data = Board_UARTGetChar(); - *Buf++ = (char) data; + return status; } - return NbBytesToRead; } diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn index d3fc4a4ee01127..e63e51c94f89b4 100644 --- a/src/lib/shell/BUILD.gn +++ b/src/lib/shell/BUILD.gn @@ -53,6 +53,11 @@ static_library("shell") { "MainLoopEFR32.cpp", "streamer_efr32.cpp", ] + } else if (chip_device_platform == "SiWx917") { + sources += [ + "MainLoopEFR32.cpp", + "streamer_efr32.cpp", + ] } else if (chip_device_platform == "k32w0") { sources += [ "MainLoopDefault.cpp", diff --git a/src/platform/silabs/Logging.cpp b/src/platform/silabs/Logging.cpp index c6b0013f566a73..e163eeff48dcf9 100644 --- a/src/platform/silabs/Logging.cpp +++ b/src/platform/silabs/Logging.cpp @@ -19,11 +19,13 @@ #include #include +#ifndef BRD4325A #include "rail_types.h" #ifdef RAIL_ASSERT_DEBUG_STRING #include "rail_assert_error_codes.h" #endif +#endif // BRD4325A #ifdef BRD4325A // For SiWx917 Platform only #include "core_cm4.h" @@ -514,6 +516,7 @@ extern "C" void vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBu *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; } +#ifndef BRD4325A extern "C" void RAILCb_AssertFailed(RAIL_Handle_t railHandle, uint32_t errorCode) { #ifdef RAIL_ASSERT_DEBUG_STRING @@ -533,5 +536,6 @@ extern "C" void RAILCb_AssertFailed(RAIL_Handle_t railHandle, uint32_t errorCode while (1) ; } +#endif // BRD4325A #endif // HARD_FAULT_LOG_ENABLE && SILABS_LOG_ENABLED diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 1c1af73ad6e1eb..8382b29c091261 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -129,6 +129,7 @@ template("efr32_sdk") { "TINYCRYPT_PRIMITIVES", "OPTIMIZE_TINYCRYPT_ASM", "RS91X_BLE_ENABLE=1", + "__error_t_defined", ] if (use_system_view) { @@ -190,7 +191,6 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/emdrv/uartdrv/inc", "${efr32_sdk_root}/platform/emdrv/uartdrv/config", "${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_usart", - "${efr32_sdk_root}/platform/common/errno/inc", ] } @@ -284,6 +284,10 @@ template("efr32_sdk") { "${wisemcu_sdk_root}/third_party/freertos/tasks.c", "${wisemcu_sdk_root}/third_party/freertos/timers.c", + # USART + "${wisemcu_sdk_root}/platforms/si91x/drivers/cmsis_driver/UDMA.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/cmsis_driver/USART.c", + # mbedtls "${chip_root}/third_party/mbedtls/repo/library/aes.c", "${chip_root}/third_party/mbedtls/repo/library/asn1parse.c",