Skip to content

Commit

Permalink
Add a 'bootloader' MCU power state
Browse files Browse the repository at this point in the history
  • Loading branch information
lmnotran committed Oct 12, 2023
1 parent fc30740 commit 05b4a5e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/platforms/simulation/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ otError otPlatSetMcuPowerState(otInstance *aInstance, otPlatMcuPowerState aState
{
case OT_PLAT_MCU_POWER_STATE_ON:
case OT_PLAT_MCU_POWER_STATE_LOW_POWER:
case OT_PLAT_MCU_POWER_STATE_BOOTLOADER:
gPlatMcuPowerState = aState;
break;

Expand Down
13 changes: 11 additions & 2 deletions include/openthread/platform/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void otPlatWakeHost(void);
* The power state primarily determines how the host should interact with the NCP and whether the host needs an
* external trigger (a "poke") to NCP before it can communicate with the NCP or not.
*
* After a reset, the MCU power state MUST be `OT_PLAT_POWER_STATE_ON`.
* After a reset, the MCU power state MUST be `OT_PLAT_MCU_POWER_STATE_ON`.
*
*/
typedef enum
Expand Down Expand Up @@ -160,6 +160,15 @@ typedef enum
*
*/
OT_PLAT_MCU_POWER_STATE_OFF = 2,

/**
* NCP's MCU can enter bootloader mode.
*
* When the NCP's desired power state is set to `BOOTLOADER`, MCU enters its bootloader mode.
*
*/
OT_PLAT_MCU_POWER_STATE_BOOTLOADER = 3,

} otPlatMcuPowerState;

/**
Expand All @@ -183,7 +192,7 @@ otError otPlatSetMcuPowerState(otInstance *aInstance, otPlatMcuPowerState aState
* This is only applicable and used for NCP configuration when `OPENTHREAD_CONFIG_NCP_ENABLE_MCU_POWER_STATE_CONTROL`
* is enabled.
*
* After a reset, the power state MUST return `OT_PLAT_POWER_STATE_ON`. During operation, power state SHOULD only
* After a reset, the power state MUST return `OT_PLAT_MCU_POWER_STATE_ON`. During operation, power state SHOULD only
* change through an explicit successful call to `otPlatSetMcuPowerState()`.
*
* @param[in] aInstance A pointer to OpenThread instance.
Expand Down
1 change: 1 addition & 0 deletions src/lib/spinel/spinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ const char *spinel_mcu_power_state_to_cstr(uint8_t mcu_power_state)
{SPINEL_MCU_POWER_STATE_ON, "MCU_POWER_STATE_ON"},
{SPINEL_MCU_POWER_STATE_LOW_POWER, "MCU_POWER_STATE_LOW_POWER"},
{SPINEL_MCU_POWER_STATE_OFF, "MCU_POWER_STATE_OFF"},
{SPINEL_MCU_POWER_STATE_BOOTLOADER, "MCU_POWER_STATE_BOOTLOADER"},
{0, NULL},
};

Expand Down
7 changes: 4 additions & 3 deletions src/lib/spinel/spinel.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,10 @@ typedef enum

typedef enum
{
SPINEL_MCU_POWER_STATE_ON = 0,
SPINEL_MCU_POWER_STATE_LOW_POWER = 1,
SPINEL_MCU_POWER_STATE_OFF = 2,
SPINEL_MCU_POWER_STATE_ON = 0,
SPINEL_MCU_POWER_STATE_LOW_POWER = 1,
SPINEL_MCU_POWER_STATE_OFF = 2,
SPINEL_MCU_POWER_STATE_BOOTLOADER = 3,
} spinel_mcu_power_state_t;

// The `spinel_power_state_t` enumeration and `POWER_STATE`
Expand Down
8 changes: 8 additions & 0 deletions src/ncp/ncp_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,10 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MCU_POWER_STATE>(void
case OT_PLAT_MCU_POWER_STATE_OFF:
state = SPINEL_MCU_POWER_STATE_OFF;
break;

case OT_PLAT_MCU_POWER_STATE_BOOTLOADER:
state = SPINEL_MCU_POWER_STATE_BOOTLOADER;
break;
}

return mEncoder.WriteUint8(state);
Expand Down Expand Up @@ -2021,6 +2025,10 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MCU_POWER_STATE>(void
powerState = OT_PLAT_MCU_POWER_STATE_OFF;
break;

case SPINEL_MCU_POWER_STATE_BOOTLOADER:
powerState = OT_PLAT_MCU_POWER_STATE_BOOTLOADER;
break;

default:
ExitNow(error = OT_ERROR_INVALID_ARGS);
}
Expand Down
1 change: 1 addition & 0 deletions src/posix/platform/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ otError otPlatSetMcuPowerState(otInstance *aInstance, otPlatMcuPowerState aState
{
case OT_PLAT_MCU_POWER_STATE_ON:
case OT_PLAT_MCU_POWER_STATE_LOW_POWER:
case OT_PLAT_MCU_POWER_STATE_BOOTLOADER:
gPlatMcuPowerState = aState;
break;

Expand Down

0 comments on commit 05b4a5e

Please sign in to comment.