Skip to content

Commit

Permalink
applications: nrf_desktop: Add DVFS module support for conf chan and smp
Browse files Browse the repository at this point in the history
Add support in nrf_desktop  DVFS module for: smp transfer
and config channel events.
DVFS module  upscales cores frequency to 320MHz when
config channel or smp transfer is used.

JIRA: NCSDK-27380

Signed-off-by: Jan Zyczkowski <[email protected]>
  • Loading branch information
zycz authored and nordicjm committed Aug 16, 2024
1 parent acc0b64 commit 8765c75
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
29 changes: 24 additions & 5 deletions applications/nrf_desktop/src/modules/Kconfig.dvfs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,42 @@ config DESKTOP_DVFS_RETRY_BUSY_TIMEOUT_MS
default 1
range 1 10000
help
Timeout in milliseconds specifying time after which DVFS module will retry DVFS frequency change.
This timeout is applied in case another DVFS change request is still in progress which causes the current request to fail.
Timeout in milliseconds specifying time after which DVFS module will retry
DVFS frequency change. This timeout is applied in case another DVFS change
request is still in progress which causes the current request to fail.

config DESKTOP_DVFS_RETRY_INIT_TIMEOUT_MS
int "Retry timeout"
default 500
range 1 10000
help
Timeout in milliseconds specifying time after which DVFS module will retry DVFS frequency change.
This timeout is applied in case DVFS is not yet initialized which causes the current request to fail.
Timeout in milliseconds specifying time after which DVFS module will retry
DVFS frequency change. This timeout is applied in case DVFS is not yet initialized
which causes the current request to fail.

config DESKTOP_DVFS_RETRY_COUNT
int "Number of retries"
default 5
range 1 255
help
Number of retries of DVFS frequency change after which DVFS module will report MODULE_STATE_ERROR.
Number of retries of DVFS frequency change after which DVFS module will report
MODULE_STATE_ERROR.

config DESKTOP_DVFS_SMP_TRANSFER_TIMEOUT_MS
int "SMP transfer timeout"
default 5000
range 1 65535
help
Timeout in milliseconds specifying time after which DVFS module will go back to
low frequency after receiving SMP transfer event.

config DESKTOP_DVFS_CONFIG_CHANNEL_TIMEOUT_MS
int "Config channel timeout"
default 5000
range 1 65535
help
Timeout in milliseconds specifying time after which DVFS module will go back to
low frequency after reciving config event.

module = DESKTOP_DVFS
module-str = DVFS
Expand Down
42 changes: 41 additions & 1 deletion applications/nrf_desktop/src/modules/dvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/

#include <caf/events/ble_common_event.h>
#include <caf/events/ble_smp_event.h>

#include "usb_event.h"
#include "config_event.h"

#define MODULE dvfs
#include <caf/events/module_state_event.h>
Expand Down Expand Up @@ -37,11 +39,15 @@ enum dvfs_state {
DVFS_STATE_INITIALIZING,
DVFS_STATE_LLPM_CONNECTED,
DVFS_STATE_USB_CONNECTED,
DVFS_STATE_CONFIG_CHANNEL,
DVFS_STATE_SMP_TRANSFER,
DVFS_STATE_COUNT
};

static const uint8_t dvfs_high_freq_bitmask = BIT(DVFS_STATE_INITIALIZING) |
BIT(DVFS_STATE_USB_CONNECTED);
BIT(DVFS_STATE_USB_CONNECTED) |
BIT(DVFS_STATE_CONFIG_CHANNEL) |
BIT(DVFS_STATE_SMP_TRANSFER);
static const uint8_t dvfs_medlow_freq_bitmask = BIT(DVFS_STATE_LLPM_CONNECTED);

/* Binary mask tracking which states are requested.
Expand All @@ -66,6 +72,12 @@ struct dvfs_state_timeout {
};

static struct dvfs_state_timeout dvfs_state_timeouts[DVFS_STATE_COUNT] = {
[DVFS_STATE_CONFIG_CHANNEL] = {
.timeout_ms = CONFIG_DESKTOP_DVFS_CONFIG_CHANNEL_TIMEOUT_MS,
},
[DVFS_STATE_SMP_TRANSFER] = {
.timeout_ms = CONFIG_DESKTOP_DVFS_SMP_TRANSFER_TIMEOUT_MS,
}
};

static const char *get_dvfs_frequency_setting_name(enum dvfs_frequency_setting setting)
Expand All @@ -84,6 +96,8 @@ static const char *get_dvfs_state_name(enum dvfs_state state)
case DVFS_STATE_INITIALIZING: return "DVFS_STATE_INITIALIZING";
case DVFS_STATE_LLPM_CONNECTED: return "DVFS_STATE_LLPM_CONNECTED";
case DVFS_STATE_USB_CONNECTED: return "DVFS_STATE_USB_CONNECTED";
case DVFS_STATE_CONFIG_CHANNEL: return "DVFS_STATE_CONFIG_CHANNEL";
case DVFS_STATE_SMP_TRANSFER: return "DVFS_STATE_SMP_TRANSFER";
default: return "Unknown";
}
}
Expand Down Expand Up @@ -281,6 +295,26 @@ static bool app_event_handler(const struct app_event_header *aeh)
return false;
}

if (IS_ENABLED(CONFIG_CAF_BLE_SMP_TRANSFER_EVENTS) && is_ble_smp_transfer_event(aeh)) {
process_dvfs_states(DVFS_STATE_SMP_TRANSFER, true);
struct dvfs_state_timeout *smp_transfer_timeout =
&dvfs_state_timeouts[DVFS_STATE_SMP_TRANSFER];
(void) k_work_reschedule(&(smp_transfer_timeout->timeout_work),
K_MSEC(smp_transfer_timeout->timeout_ms));

return false;
}

if (IS_ENABLED(CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE) && is_config_event(aeh)) {
process_dvfs_states(DVFS_STATE_CONFIG_CHANNEL, true);
struct dvfs_state_timeout *config_channel_timeout =
&dvfs_state_timeouts[DVFS_STATE_CONFIG_CHANNEL];
(void) k_work_reschedule(&(config_channel_timeout->timeout_work),
K_MSEC(config_channel_timeout->timeout_ms));

return false;
}

/* If event is unhandled, unsubscribe. */
__ASSERT_NO_MSG(false);

Expand All @@ -296,3 +330,9 @@ APP_EVENT_SUBSCRIBE(MODULE, ble_peer_event);
#if CONFIG_DESKTOP_USB_ENABLE
APP_EVENT_SUBSCRIBE(MODULE, usb_state_event);
#endif
#if CONFIG_CAF_BLE_SMP_TRANSFER_EVENTS
APP_EVENT_SUBSCRIBE(MODULE, ble_smp_transfer_event);
#endif
#if CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE
APP_EVENT_SUBSCRIBE_EARLY(MODULE, config_event);
#endif

0 comments on commit 8765c75

Please sign in to comment.