Skip to content

Commit fae1542

Browse files
ppelikan-nordicrlubos
authored andcommitted
nrfs: add GDFS service
Signed-off-by: Paweł Pelikan <[email protected]>
1 parent 8097b08 commit fae1542

File tree

8 files changed

+255
-2
lines changed

8 files changed

+255
-2
lines changed

nrfs/include/internal/nrfs_callbacks.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ void nrfs_clock_service_notify(void *p_notification, size_t size);
106106
*/
107107
void nrfs_gdpwr_service_notify(void *p_notification, size_t size);
108108

109+
/**
110+
* @brief Function for notifying the GDFS service about incoming message.
111+
*
112+
* This function is called internally by the dispatcher when the corresponding message arrives.
113+
*
114+
* @param[in] p_notification Pointer to the notification payload.
115+
* @param[in] size Notification payload size.
116+
*/
117+
void nrfs_gdfs_service_notify(void *p_notification, size_t size);
118+
109119
#ifdef __cplusplus
110120
}
111121
#endif

nrfs/include/internal/nrfs_hdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include <internal/requests/nrfs_clock_reqs.h>
1313
#include <internal/requests/nrfs_diag_reqs.h>
1414
#include <internal/requests/nrfs_dvfs_reqs.h>
15+
#include <internal/requests/nrfs_gdfs_reqs.h>
1516
#include <internal/requests/nrfs_gdpwr_reqs.h>
1617
#include <internal/requests/nrfs_mram_reqs.h>
1718
#include <internal/requests/nrfs_pmic_reqs.h>
1819
#include <internal/requests/nrfs_reset_reqs.h>
1920
#include <internal/requests/nrfs_temp_reqs.h>
2021
#include <internal/requests/nrfs_usb_reqs.h>
2122

22-
2323
#ifdef __cplusplus
2424
extern "C" {
2525
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef NRFS_GDFS_REQS_H
8+
#define NRFS_GDFS_REQS_H
9+
10+
#include "nrfs_reqs_common.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
enum {
17+
NRFS_GDFS_REQ_FREQ = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_GDFS, 0x01),
18+
};
19+
20+
#ifdef __cplusplus
21+
}
22+
#endif
23+
24+
#endif /* NRFS_GDFS_REQS_H */

nrfs/include/internal/requests/nrfs_reqs_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ enum {
6161
NRFS_SERVICE_ID_PMIC,
6262
NRFS_SERVICE_ID_RESET,
6363
NRFS_SERVICE_ID_TEMP,
64-
NRFS_SERVICE_ID_USB
64+
NRFS_SERVICE_ID_USB,
65+
NRFS_SERVICE_ID_GDFS
6566
};
6667

6768
#ifdef __cplusplus
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef NRFS_INTERNAL_GDFS_H
8+
#define NRFS_INTERNAL_GDFS_H
9+
10+
#include <internal/services/nrfs_generic.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
enum __NRFS_PACKED gdfs_frequency_setting {
17+
GDFS_FREQ_HIGH = 0,
18+
GDFS_FREQ_MEDHIGH = 1,
19+
GDFS_FREQ_MEDLOW = 2,
20+
GDFS_FREQ_LOW = 3,
21+
GDFS_FREQ_COUNT
22+
};
23+
24+
/** @brief Global Domain Frequency Scaling service request data structure. */
25+
typedef struct __NRFS_PACKED {
26+
enum gdfs_frequency_setting target_freq; /** Requested frequency oppoint. */
27+
} nrfs_gdfs_req_data_t;
28+
29+
/** @brief Global Domain Frequency Scaling frequency change request structure. */
30+
typedef struct __NRFS_PACKED {
31+
nrfs_hdr_t hdr; /**< Header of the message. */
32+
nrfs_ctx_t ctx; /**< Context of the message. */
33+
nrfs_gdfs_req_data_t data; /**< Data of the request. */
34+
} nrfs_gdfs_req_t;
35+
36+
/** @brief Global Domain Frequency Scaling service notification structure. */
37+
typedef struct __NRFS_PACKED {
38+
nrfs_hdr_t hdr; /**< Header of the message. */
39+
nrfs_ctx_t ctx; /**< Context of the message. */
40+
} nrfs_gdfs_rsp_t;
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif /* NRFS_INTERNAL_GDFS_H */

nrfs/include/services/nrfs_gdfs.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef NRFS_GDFS_H
8+
#define NRFS_GDFS_H
9+
10+
#include <internal/services/nrfs_gdfs.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
/** @brief Global Domain Frequency Scaling service event types. */
17+
typedef enum __NRFS_PACKED {
18+
NRFS_GDFS_EVT_REJECT, /** General purpose event for rejected requests. */
19+
NRFS_GDFS_EVT_FREQ_CONFIRMED, /** Frequency has been acheived. */
20+
} nrfs_gdfs_evt_type_t;
21+
22+
/** @brief Global Domain Frequency Scaling service event. */
23+
typedef struct {
24+
nrfs_gdfs_evt_type_t type; /** Event type. */
25+
} nrfs_gdfs_evt_t;
26+
27+
/** @brief Global Domain Frequency Scaling service event handler type. */
28+
typedef void (*nrfs_gdfs_evt_handler_t)(nrfs_gdfs_evt_t const * p_evt, void * context);
29+
30+
/**
31+
* @brief Function for initializing the Global Domain Frequency Scaling service.
32+
*
33+
* @param[in] handler Function called as a response to the request.
34+
*
35+
* @retval NRFS_SUCCESS Service initialized successfully.
36+
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
37+
*/
38+
nrfs_err_t nrfs_gdfs_init(nrfs_gdfs_evt_handler_t handler);
39+
40+
/**
41+
* @brief Function for uninitializing the Global Domain Frequency Scaling service.
42+
*
43+
* @warning Notifications from previous requests are dropped after service uninitialization.
44+
*/
45+
void nrfs_gdfs_uninit(void);
46+
47+
/**
48+
* @brief Function for requesting a frequency change.
49+
* @note The @p target_freq requirement might not be met by the system
50+
* until the NRFS_GDFS_EVT_FREQ_CONFIRMED response is triggered.
51+
*
52+
* @param[in] target_freq Minimal required frequency
53+
* @param[in] p_context Opaque user data that will be passed to registered callback.
54+
*
55+
* @retval NRFS_SUCCESS Request sent successfully.
56+
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
57+
* @retval NRFS_ERR_IPC Backend returned error during request sending.
58+
*/
59+
nrfs_err_t nrfs_gdfs_request_freq(enum gdfs_frequency_setting target_freq, void * p_context);
60+
61+
/**
62+
* @brief Function for requesting a frequency change.
63+
* @note The response @p NRFS_GDFS_EVT_FREQ_CONFIRMED will not be triggered.
64+
*
65+
* @param[in] target_freq Minimal required frequency
66+
* @param[in] p_context Opaque user data that will be passed to registered callback.
67+
*
68+
* @retval NRFS_SUCCESS Request sent successfully.
69+
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
70+
* @retval NRFS_ERR_IPC Backend returned error during request sending.
71+
*/
72+
nrfs_err_t nrfs_gdfs_request_freq_no_rsp(enum gdfs_frequency_setting target_freq, void * p_context);
73+
74+
#ifdef __cplusplus
75+
}
76+
#endif
77+
78+
#endif /* NRFS_GDFS_H */

nrfs/src/internal/nrfs_dispatcher.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ static const nrfs_service_cb_t services_callbacks[] = {
5555
#else
5656
[NRFS_SERVICE_ID_GDPWR] = NULL,
5757
#endif
58+
#ifdef NRFS_GDFS_SERVICE_ENABLED
59+
[NRFS_SERVICE_ID_GDFS] = nrfs_gdfs_service_notify,
60+
#else
61+
[NRFS_SERVICE_ID_GDFS] = NULL,
62+
#endif
5863
};
5964

6065
/* Warning! All "UNSOLICITED" features are not supported. This is intended for possible future use. */

nrfs/src/services/nrfs_gdfs.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <internal/nrfs_backend.h>
8+
#include <internal/nrfs_callbacks.h>
9+
#include <nrfs_gdfs.h>
10+
11+
typedef struct {
12+
nrfs_gdfs_evt_handler_t handler;
13+
bool is_initialized;
14+
} nrfs_gdfs_cb_t;
15+
static nrfs_gdfs_cb_t m_cb;
16+
17+
void nrfs_gdfs_service_notify(void *p_notification, size_t size)
18+
{
19+
if (!m_cb.handler || !m_cb.is_initialized) {
20+
return;
21+
}
22+
23+
nrfs_gdfs_evt_t evt;
24+
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
25+
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
26+
evt.type = NRFS_GDFS_EVT_REJECT;
27+
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
28+
return;
29+
}
30+
31+
nrfs_gdfs_rsp_t *p_rsp = (nrfs_gdfs_rsp_t *)p_notification;
32+
switch (p_data->hdr.req) {
33+
case NRFS_GDFS_REQ_FREQ:
34+
evt.type = NRFS_GDFS_EVT_FREQ_CONFIRMED;
35+
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
36+
break;
37+
38+
default:
39+
break;
40+
}
41+
}
42+
43+
nrfs_err_t nrfs_gdfs_init(nrfs_gdfs_evt_handler_t handler)
44+
{
45+
if (m_cb.is_initialized) {
46+
return NRFS_ERR_INVALID_STATE;
47+
}
48+
49+
m_cb.handler = handler;
50+
m_cb.is_initialized = true;
51+
return NRFS_SUCCESS;
52+
}
53+
54+
void nrfs_gdfs_uninit(void)
55+
{
56+
m_cb.is_initialized = false;
57+
}
58+
59+
nrfs_err_t nrfs_gdfs_request_freq(enum gdfs_frequency_setting target_freq, void *p_context)
60+
{
61+
if (!m_cb.is_initialized) {
62+
return NRFS_ERR_INVALID_STATE;
63+
}
64+
65+
nrfs_gdfs_req_t req;
66+
67+
NRFS_SERVICE_HDR_FILL(&req, NRFS_GDFS_REQ_FREQ);
68+
req.ctx.ctx = (uint32_t)p_context;
69+
req.data.target_freq = target_freq;
70+
71+
return nrfs_backend_send(&req, sizeof(req));
72+
}
73+
74+
nrfs_err_t nrfs_gdfs_request_freq_no_rsp(enum gdfs_frequency_setting target_freq,
75+
void *p_context)
76+
{
77+
if (!m_cb.is_initialized) {
78+
return NRFS_ERR_INVALID_STATE;
79+
}
80+
81+
nrfs_gdfs_req_t req;
82+
83+
NRFS_SERVICE_HDR_FILL(&req, NRFS_GDFS_REQ_FREQ);
84+
NRFS_HDR_NO_RSP_SET(&req.hdr);
85+
req.ctx.ctx = (uint32_t)p_context;
86+
req.data.target_freq = target_freq;
87+
88+
return nrfs_backend_send(&req, sizeof(req));
89+
}

0 commit comments

Comments
 (0)