Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/sdfw/sdfw_services/dvfs_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef DVFS_SERVICE_H__
#define DVFS_SERVICE_H__

#include <stddef.h>
#include <stdint.h>

#include <sdfw/sdfw_services/ssf_errno.h>

int ssf_dvfs_set_oppoint(uint8_t opp);

#endif /* DVFS_SERVICE_H__ */
1 change: 1 addition & 0 deletions subsys/sdfw_services/services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_subdirectory_ifdef(CONFIG_SSF_ENC_FW_SERVICE_ENABLED enc_fw)
add_subdirectory_ifdef(CONFIG_SSF_EXTMEM_SERVICE_ENABLED extmem)
add_subdirectory_ifdef(CONFIG_SSF_PSA_CRYPTO_SERVICE_ENABLED psa_crypto)
add_subdirectory_ifdef(CONFIG_SSF_SUIT_SERVICE_ENABLED suit_service)
add_subdirectory_ifdef(CONFIG_SSF_DVFS_SERVICE_ENABLED dvfs)
1 change: 1 addition & 0 deletions subsys/sdfw_services/services/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ rsource "enc_fw/Kconfig"
rsource "extmem/Kconfig"
rsource "psa_crypto/Kconfig"
rsource "suit_service/Kconfig"
rsource "dvfs/Kconfig"
4 changes: 2 additions & 2 deletions subsys/sdfw_services/services/device_info/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
zephyr_sources(device_info_service.c)

generate_and_add_cbor_files(device_info_service.cddl zcbor_generated
device_info_service_req
device_info_service_rsp
device_info_req
device_info_resp
)
12 changes: 12 additions & 0 deletions subsys/sdfw_services/services/dvfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

zephyr_sources(dvfs_service.c)

generate_and_add_cbor_files(dvfs_service.cddl zcbor_generated
dvfs_oppoint_req
dvfs_oppoint_rsp
)
13 changes: 13 additions & 0 deletions subsys/sdfw_services/services/dvfs/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

service_name = DVFS
service_default_enabled = y
service_id = 0xDD
service_version = 1
service_buffer_size = 32
service_name_str = DVFS
rsource "../Kconfig.template.service"
62 changes: 62 additions & 0 deletions subsys/sdfw_services/services/dvfs/dvfs_service.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include <sdfw/sdfw_services/dvfs_service.h>

#include "dvfs_service_decode.h"
#include "dvfs_service_encode.h"
#include "dvfs_service_types.h"
#include <sdfw/sdfw_services/ssf_client.h>
#include <sdfw/sdfw_services/ssf_errno.h>
#include "ssf_client_os.h"

SSF_CLIENT_SERVICE_DEFINE(dvfs_srvc, DVFS, cbor_encode_dvfs_oppoint_req,
cbor_decode_dvfs_oppoint_rsp);

int ssf_dvfs_set_oppoint(uint8_t opp)
{
int ret = -SSF_ENODATA;

if (opp >= dvfs_oppoint_DVFS_FREQ_HIGH_c && opp <= dvfs_oppoint_DVFS_FREQ_LOW_c) {
const uint8_t *rsp_pkt;

int stat = stat_INTERNAL_ERROR_c;

struct dvfs_oppoint_req dvfs_request = {
.dvfs_oppoint_req_data
.dvfs_oppoint_choice = opp,
};

struct dvfs_oppoint_rsp dvfs_response;

ret = ssf_client_send_request(&dvfs_srvc, &dvfs_request,
&dvfs_response, &rsp_pkt);
if (ret == 0) {
if (dvfs_response.dvfs_oppoint_rsp_status.stat_choice ==
stat_SUCCESS_c) {
stat = dvfs_response.dvfs_oppoint_rsp_status.stat_choice;
if (stat == stat_SUCCESS_c) {
printk("DVFS scaling done, new frequency setting %d\n",
dvfs_response.dvfs_oppoint_rsp_data
.dvfs_oppoint_choice);
ret = 0;
} else {
ret = -SSF_EPROTO;
}
} else {
ret = -SSF_EBADMSG;
}

ssf_client_decode_done(rsp_pkt);
}
}

return ret;
}
28 changes: 28 additions & 0 deletions subsys/sdfw_services/services/dvfs/dvfs_service.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;
; Copyright (c) 2024 Nordic Semiconductor ASA
;
; SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
;

; .. include_startingpoint_dvfs_cddl_rst

stat = (SUCCESS: 0) /
(INTERNAL_ERROR: 16781313)

dvfs_oppoint = (DVFS_FREQ_HIGH: 0) /
(DVFS_FREQ_MEDLOW: 1) /
(DVFS_FREQ_LOW: 2)

dvfs_oppoint_req = (
1,
data: dvfs_oppoint,
)

; DVFS service response.
dvfs_oppoint_rsp = (
1,
data: dvfs_oppoint,
status: stat,
)

; .. include_endingpoint_dvfs_cddl_rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

#
# Generated using cmake macro generate_and_add_cbor_files.
#

zephyr_sources(
dvfs_service_decode.c
dvfs_service_encode.c
)

zephyr_include_directories(.)
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/*
* Generated using zcbor version 0.9.1
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "zcbor_decode.h"
#include "dvfs_service_decode.h"
#include "zcbor_print.h"

#if DEFAULT_MAX_QTY != 3
#error "The type file was generated with a different default_max_qty than this file"
#endif

#define log_result(state, result, func) \
do { \
if (!result) { \
zcbor_trace_file(state); \
zcbor_log("%s error: %s\r\n", func, \
zcbor_error_str(zcbor_peek_error(state))); \
} else { \
zcbor_log("%s success\r\n", func); \
} \
} while (0)

static bool decode_dvfs_oppoint(zcbor_state_t *state, struct dvfs_oppoint_r *result);
static bool decode_stat(zcbor_state_t *state, struct stat_r *result);
static bool decode_dvfs_oppoint_rsp(zcbor_state_t *state, struct dvfs_oppoint_rsp *result);
static bool decode_dvfs_oppoint_req(zcbor_state_t *state, struct dvfs_oppoint_req *result);

static bool decode_dvfs_oppoint(zcbor_state_t *state, struct dvfs_oppoint_r *result)
{
zcbor_log("%s\r\n", __func__);

bool res = ((
(((zcbor_uint_decode(state, &(*result).dvfs_oppoint_choice,
sizeof((*result).dvfs_oppoint_choice)))) &&
((((((*result).dvfs_oppoint_choice == dvfs_oppoint_DVFS_FREQ_HIGH_c) && ((1))) ||
(((*result).dvfs_oppoint_choice == dvfs_oppoint_DVFS_FREQ_MEDLOW_c) && ((1))) ||
(((*result).dvfs_oppoint_choice == dvfs_oppoint_DVFS_FREQ_LOW_c) && ((1)))) ||
(zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false))))));

log_result(state, res, __func__);
return res;
}

static bool decode_stat(zcbor_state_t *state, struct stat_r *result)
{
zcbor_log("%s\r\n", __func__);

bool res = (((((zcbor_uint_decode(state, &(*result).stat_choice,
sizeof((*result).stat_choice)))) &&
((((((*result).stat_choice == stat_SUCCESS_c) && ((1))) ||
(((*result).stat_choice == stat_INTERNAL_ERROR_c) && ((1)))) ||
(zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false))))));

log_result(state, res, __func__);
return res;
}

static bool decode_dvfs_oppoint_rsp(zcbor_state_t *state, struct dvfs_oppoint_rsp *result)
{
zcbor_log("%s\r\n", __func__);

bool res = (((((zcbor_uint32_expect(state, (1)))) &&
((decode_dvfs_oppoint(state, (&(*result).dvfs_oppoint_rsp_data)))) &&
((decode_stat(state, (&(*result).dvfs_oppoint_rsp_status)))))));

log_result(state, res, __func__);
return res;
}

static bool decode_dvfs_oppoint_req(zcbor_state_t *state, struct dvfs_oppoint_req *result)
{
zcbor_log("%s\r\n", __func__);

bool res = (((((zcbor_uint32_expect(state, (1)))) &&
((decode_dvfs_oppoint(state, (&(*result).dvfs_oppoint_req_data)))))));

log_result(state, res, __func__);
return res;
}

int cbor_decode_dvfs_oppoint_req(const uint8_t *payload, size_t payload_len,
struct dvfs_oppoint_req *result, size_t *payload_len_out)
{
zcbor_state_t states[3];

return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
(zcbor_decoder_t *)decode_dvfs_oppoint_req,
sizeof(states) / sizeof(zcbor_state_t), 2);
}

int cbor_decode_dvfs_oppoint_rsp(const uint8_t *payload, size_t payload_len,
struct dvfs_oppoint_rsp *result, size_t *payload_len_out)
{
zcbor_state_t states[3];

return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
(zcbor_decoder_t *)decode_dvfs_oppoint_rsp,
sizeof(states) / sizeof(zcbor_state_t), 3);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/*
* Generated using zcbor version 0.9.1
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/

#ifndef DVFS_SERVICE_DECODE_H__
#define DVFS_SERVICE_DECODE_H__

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "dvfs_service_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#if DEFAULT_MAX_QTY != 3
#error "The type file was generated with a different default_max_qty than this file"
#endif

int cbor_decode_dvfs_oppoint_req(const uint8_t *payload, size_t payload_len,
struct dvfs_oppoint_req *result, size_t *payload_len_out);

int cbor_decode_dvfs_oppoint_rsp(const uint8_t *payload, size_t payload_len,
struct dvfs_oppoint_rsp *result, size_t *payload_len_out);

#ifdef __cplusplus
}
#endif

#endif /* DVFS_SERVICE_DECODE_H__ */
Loading