This commit is contained in:
Rafał 2024-04-19 14:40:12 +02:00 committed by GitHub
commit 47c8f763f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
46 changed files with 3465 additions and 0 deletions

9
nrfs/CHANGELOG.md Normal file
View File

@ -0,0 +1,9 @@
# Changelog
All notable changes to this project are documented in this file.
## [1.0.0] - 19.03.2024
### Added
- initial release
### Changed
### Fixed

31
nrfs/README.md Normal file
View File

@ -0,0 +1,31 @@
# nRF Services
## Overview
NRFS (nRF Services) is a library used for accessing services provided by the System Controller core.
The number of available services may vary depending on your device. Check the product specification
to see what services are available for the specific chip.
## Supported SoCs and SiPs
* nRF54H20
## Directories
```
nrfs
├── helpers # helper files, shared between Local Domains and System Controller
├── include
│ ├── internal # internal data structures definitions
│ │ ├── backends
│ │ ├── requests
│ │ └── services
│ └── services # nRF Services API declaration
├── src
│ ├── internal
│ │ └── backends # IPC configuration files
│ └── services # nRF Services API implementation
└── zephyr
```

106
nrfs/helpers/dvfs_oppoint.c Normal file
View File

@ -0,0 +1,106 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "dvfs_oppoint.h"
#include "nrfs_config.h"
#include <zephyr/kernel.h>
#define MOVE_AND_MASK_32(x, mask, move) (((uint32_t)(x) << move) & (uint32_t)mask)
#if !NRFS_UNIT_TESTS_ENABLED && NRF_SECURE
/* TODO: Use MDK when HM-21530 is fixed */
#define ABB_TRIM_LOCKRANGE_LOCKRANGELOWN_Pos_L \
(0UL) /*!< Position of LOCKRANGELOWN field. */
#define ABB_TRIM_LOCKRANGE_LOCKRANGELOWN_Msk_L (0xFFUL << ABB_TRIM_LOCKRANGE_LOCKRANGELOWN_Pos_L)
#define ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHN_Pos_L \
(8UL) /*!< Position of LOCKRANGEHIGHN field. */
#define ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHN_Msk_L (0xFFUL << ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHN_Pos_L)
#define ABB_TRIM_LOCKRANGE_LOCKRANGELOWP_Pos_L \
(16UL) /*!< Position of LOCKRANGELOWP field. */
#define ABB_TRIM_LOCKRANGE_LOCKRANGELOWP_Msk_L (0xFFUL << ABB_TRIM_LOCKRANGE_LOCKRANGELOWP_Pos_L)
#define ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHP_Pos_L \
(24UL) /*!< Position of LOCKRANGEHIGHP field. */
#define ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHP_Msk_L (0xFFUL << ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHP_Pos_L)
#define ABB_LOCKRANGE(low_n, high_n, low_p, high_p) \
(MOVE_AND_MASK_32((low_n), \
(ABB_TRIM_LOCKRANGE_LOCKRANGELOWN_Msk_L), \
(ABB_TRIM_LOCKRANGE_LOCKRANGELOWN_Pos_L)) | \
MOVE_AND_MASK_32((high_n), \
(ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHN_Msk_L), \
(ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHN_Pos_L)) | \
MOVE_AND_MASK_32((low_p), \
(ABB_TRIM_LOCKRANGE_LOCKRANGELOWP_Msk_L), \
(ABB_TRIM_LOCKRANGE_LOCKRANGELOWP_Pos_L)) | \
MOVE_AND_MASK_32((high_p), \
(ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHP_Msk_L), \
(ABB_TRIM_LOCKRANGE_LOCKRANGEHIGHP_Pos_L)))
#define ABB_RINGO(ringo_target_n, ringo_target_p) \
(MOVE_AND_MASK_32((ringo_target_n), \
(ABB_TRIM_RINGO_RINGOTARGETVALN_Msk), \
(ABB_TRIM_RINGO_RINGOTARGETVALN_Pos)) | \
MOVE_AND_MASK_32((ringo_target_p), \
(ABB_TRIM_RINGO_RINGOTARGETVALP_Msk), \
(ABB_TRIM_RINGO_RINGOTARGETVALP_Pos)))
#else
#define ABB_LOCKRANGE(low_n, high_n, low_p, high_p) (0)
#define ABB_RINGO(ringo_target_n, ringo_target_p) (0)
#endif
static const struct dvfs_oppoint_data dvfs_oppoints_data[DVFS_FREQ_COUNT] = {
/* ABB oppoint 0.8V */
{
.freq_setting = DVFS_FREQ_HIGH,
.opp_mv = DVFS_HIGH_OPPOINT_MV,
.abb_ringo = ABB_RINGO(524, 519),
.abb_lockrange = ABB_LOCKRANGE(105, 202, 102, 211),
.abb_pvtmoncycles = 2,
.new_f_mult = 20,
.new_f_trim_entry = 0,
.max_hsfll_freq = 320,
},
/* ABB oppoint 0.6V */
{
.freq_setting = DVFS_FREQ_MEDLOW,
.opp_mv = DVFS_MEDLOW_OPPOINT_MV,
.abb_ringo = ABB_RINGO(424, 389),
.abb_lockrange = ABB_LOCKRANGE(75, 168, 65, 176),
.abb_pvtmoncycles = 4,
.new_f_mult = 8,
.new_f_trim_entry = 5,
.max_hsfll_freq = 128,
},
/* ABB oppoint 0.5V */
{
.freq_setting = DVFS_FREQ_LOW,
.opp_mv = DVFS_LOW_OPPOINT_MV,
.abb_ringo = ABB_RINGO(471, 414),
.abb_lockrange = ABB_LOCKRANGE(73, 206, 60, 203),
.abb_pvtmoncycles = 9,
.new_f_mult = 4,
.new_f_trim_entry = 3,
.max_hsfll_freq = 64,
},
};
const struct dvfs_oppoint_data *get_dvfs_oppoint_data(enum dvfs_frequency_setting oppoint)
{
if (oppoint >= DVFS_FREQ_COUNT) {
return &dvfs_oppoints_data[DVFS_FREQ_COUNT - 1];
}
return &dvfs_oppoints_data[oppoint];
}
uint16_t get_frequency_for_frequency_setting(enum dvfs_frequency_setting freq_setting)
{
return dvfs_oppoints_data[freq_setting].max_hsfll_freq;
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef DVFS_OPPOINT_H
#define DVFS_OPPOINT_H
#include <nrfs_common.h>
#include <internal/services/nrfs_dvfs.h>
#ifdef __cplusplus
extern "C" {
#endif
struct dvfs_oppoint_data {
enum dvfs_frequency_setting freq_setting;
uint16_t opp_mv;
uint32_t abb_ringo;
uint32_t abb_lockrange;
uint32_t abb_pvtmoncycles;
uint32_t new_f_mult;
uint32_t new_f_trim_entry;
uint16_t max_hsfll_freq;
};
#define DVFS_HIGH_OPPOINT_MV ((uint16_t)800)
#define DVFS_MEDLOW_OPPOINT_MV ((uint16_t)600)
#define DVFS_LOW_OPPOINT_MV ((uint16_t)500)
/**
* @brief Get the DVFS operating point (oppoint) data object.
*
* @param oppoint desired operating point.
* @return struct dvfs_oppoint_data* pointer to the oppoint data structure.
* @return NULL pointer when oppoint is invalid.
*/
const struct dvfs_oppoint_data *get_dvfs_oppoint_data(enum dvfs_frequency_setting oppoint);
/**
* @brief Get the frequency for frequency setting object.
*
* @param freq_setting item from enum dvfs_frequency_setting.
* @return uint16_t frequency in MHz.
*/
uint16_t get_frequency_for_frequency_setting(enum dvfs_frequency_setting freq_setting);
#ifdef __cplusplus
}
#endif
#endif /* DVFS_OPPOINT_H */

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_BACKEND_H
#define NRFS_BACKEND_H
#include <nrfs_common.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Function for sending a message over the chosen transport backend.
*
* This function is used by services to send requests to the System Controller.
*
* @param[in] message Pointer to the message payload.
* @param[in] size Message payload size.
*
* @retval NRFS_SUCCESS Message sent successfully.
* @retval NRFS_ERR_IPC Backend returned error during message sending.
*/
nrfs_err_t nrfs_backend_send(void *message, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_BACKEND_H */

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_CALLBACKS_H
#define NRFS_CALLBACKS_H
#include <nrfs_common.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Service callback type. */
typedef void (*nrfs_service_cb_t)(void *p_notification, size_t size);
/**
* @brief Function for notifying the Temperature service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_temp_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the Reset service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_reset_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the MRAM latency service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_mram_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the USB VBUS detector service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_usb_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the PMIC service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_pmic_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the System Diagnostics service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_diag_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the DVFS service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_dvfs_service_notify(void *p_notification, size_t size);
/**
* @brief Function for notifying the clock service about incoming message.
*
* This function is called internally by the dispatcher when the corresponding message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_clock_service_notify(void *p_notification, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_CALLBACKS_H */

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_CTX_H
#define NRFS_CTX_H
#include <nrfs_common.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct __NRFS_PACKED {
uint32_t ctx;
} nrfs_ctx_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_CTX_H */

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_DISPATCHER_H
#define NRFS_DISPATCHER_H
#include <nrfs_common.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Function for notifying the dispatcher about incoming message.
*
* This function is called internally by the backend when a message arrives.
*
* @param[in] p_notification Pointer to the notification payload.
* @param[in] size Notification payload size.
*/
void nrfs_dispatcher_notify(void *message, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_DISPATCHER_H */

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_HDR_H
#define NRFS_HDR_H
#include <internal/nrfs_phy.h>
#include <internal/requests/nrfs_temp_reqs.h>
#include <internal/requests/nrfs_mram_reqs.h>
#include <internal/requests/nrfs_reset_reqs.h>
#include <internal/requests/nrfs_usb_reqs.h>
#include <internal/requests/nrfs_pmic_reqs.h>
#include <internal/requests/nrfs_dvfs_reqs.h>
#include <internal/requests/nrfs_diag_reqs.h>
#include <internal/requests/nrfs_clock_reqs.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct __NRFS_PACKED {
uint16_t req;
} nrfs_hdr_t;
#define NRFS_HDR_GET(_p_phy) ((nrfs_hdr_t *)((_p_phy)->p_buffer))
#define NRFS_HDR_FILL(p_hdr, _req) ((p_hdr)->req = (uint16_t)(_req))
#define NRFS_SERVICE_HDR_FILL(p_srv_req, _req) NRFS_HDR_FILL(&(p_srv_req)->hdr, _req)
#define NRFS_HDR_NO_RSP_GET(_p_hdr) NRFS_NO_RSP_GET((_p_hdr)->req)
#define NRFS_HDR_NO_RSP_SET(_p_hdr) NRFS_NO_RSP_SET((_p_hdr)->req)
#define NRFS_HDR_FILTER_ERR_GET(_p_hdr) NRFS_FILTER_ERR_GET((_p_hdr)->req)
#define NRFS_HDR_FILTER_ERR_SET(_p_hdr) NRFS_FILTER_ERR_SET((_p_hdr)->req)
/* Warning! All "UNSOLICITED" features are not supported. This is intended for possible future use. */
#define NRFS_HDR_UNSOLICITED_GET(_p_hdr) NRFS_UNSOLICITED_GET((_p_hdr)->req)
/* Warning! All "UNSOLICITED" features are not supported. This is intended for possible future use. */
#define NRFS_HDR_UNSOLICITED_SET(_p_hdr) NRFS_UNSOLICITED_SET((_p_hdr)->req)
#ifdef __cplusplus
}
#endif
#endif /* NRFS_HDR_H */

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_PHY_H
#define NRFS_PHY_H
#include <nrfs_common.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
void *p_buffer;
uint32_t size;
uint8_t domain_id;
} nrfs_phy_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_PHY_H */

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_CLOCK_REQS_H
#define NRFS_CLOCK_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_CLOCK_REQ_SUBSCRIBE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_CLOCK, 0x01),
NRFS_CLOCK_REQ_UNSUBSCRIBE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_CLOCK, 0x02),
NRFS_CLOCK_REQ_LFCLK_SRC = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_CLOCK, 0x03),
NRFS_CLOCK_REQ_HSFLL_MODE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_CLOCK, 0x04),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_CLOCK_REQS_H */

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_DIAG_REQS_H
#define NRFS_DIAG_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_DIAG_REG = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_DIAG, 0x01),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_DIAG_REQS_H */

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_DVFS_REQS_H
#define NRFS_DVFS_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_DVFS_REQ_INIT_PREPARE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_DVFS, 0x01),
NRFS_DVFS_REQ_INIT_COMPLETE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_DVFS, 0x02),
NRFS_DVFS_REQ_OPPOINT = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_DVFS, 0x03),
NRFS_DVFS_REQ_READY_TO_SCALE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_DVFS, 0x04),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_DVFS_REQS_H */

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_MRAM_REQS_H
#define NRFS_MRAM_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_MRAM_REQ_SET_LATENCY = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_MRAM, 0x01),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_MRAM_REQS_H */

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_PMIC_REQS_H
#define NRFS_PMIC_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_PMIC_RFFE_ON = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x01),
NRFS_PMIC_RFFE_OFF = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x02),
NRFS_PMIC_SIM_ON = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x03),
NRFS_PMIC_SIM_OFF = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x04),
NRFS_PMIC_BLE_RADIO_ON = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x05),
NRFS_PMIC_BLE_RADIO_OFF = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x06),
NRFS_PMIC_PWM_DEFAULT = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x07),
NRFS_PMIC_PWM_GHOST_AVOID = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x08),
NRFS_PMIC_TEST_IF = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x09),
NRFS_PMIC_INFO = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x0A),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_PMIC_REQS_H */

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/* clang-format off */
#ifndef NRFS_REQS_COMMON_H
#define NRFS_REQS_COMMON_H
#define NRFS_REQUEST_ID_BITS 7uL
#define NRFS_NO_RSP_BITS 1uL
#define NRFS_SERVICE_ID_BITS 6uL
#define NRFS_FILTER_ERR_BITS 1uL
#define NRFS_UNSOLICITED_BITS 1uL
#define NRFS_REQUEST_ID_BITPOS 0uL
#define NRFS_NO_RSP_BITPOS (NRFS_REQUEST_ID_BITS)
#define NRFS_SERVICE_ID_BITPOS (NRFS_REQUEST_ID_BITS + NRFS_NO_RSP_BITS)
#define NRFS_FILTER_ERR_BITPOS (NRFS_REQUEST_ID_BITS + NRFS_NO_RSP_BITS + NRFS_SERVICE_ID_BITS)
#define NRFS_UNSOLICITED_BITPOS (NRFS_REQUEST_ID_BITS + NRFS_NO_RSP_BITS + NRFS_SERVICE_ID_BITS + NRFS_FILTER_ERR_BITS)
#define NRFS_REQUEST_ID_MASK (((1 << NRFS_REQUEST_ID_BITS) - 1) << NRFS_REQUEST_ID_BITPOS)
#define NRFS_NO_RSP_MASK (((1 << NRFS_NO_RSP_BITS) - 1) << NRFS_NO_RSP_BITPOS)
#define NRFS_SERVICE_ID_MASK (((1 << NRFS_SERVICE_ID_BITS) - 1) << NRFS_SERVICE_ID_BITPOS)
#define NRFS_FILTER_ERR_MASK (((1 << NRFS_FILTER_ERR_BITS) - 1) << NRFS_FILTER_ERR_BITPOS)
#define NRFS_UNSOLICITED_MASK (((1 << NRFS_UNSOLICITED_BITS) - 1) << NRFS_UNSOLICITED_BITPOS)
#define NRFS_REQUEST_ID_DEF(_srv_id, _req_id) (((uint16_t)(_srv_id) << NRFS_SERVICE_ID_BITPOS) | \
((uint16_t)(_req_id) << NRFS_REQUEST_ID_BITPOS))
#define NRFS_REQUEST_ID_GET(_req) (((_req) & (NRFS_REQUEST_ID_MASK | NRFS_SERVICE_ID_MASK)))
#define NRFS_SERVICE_ID_GET(_req) (((_req) & NRFS_SERVICE_ID_MASK) >> NRFS_SERVICE_ID_BITPOS)
#define NRFS_NO_RSP_GET(_req) (((_req) & NRFS_NO_RSP_MASK) >> NRFS_NO_RSP_BITPOS)
#define NRFS_NO_RSP_SET(_req) ((_req) |= NRFS_NO_RSP_MASK)
#define NRFS_FILTER_ERR_GET(_req) (((_req) & NRFS_FILTER_ERR_MASK) >> NRFS_FILTER_ERR_BITPOS)
#define NRFS_FILTER_ERR_SET(_req) ((_req) |= NRFS_FILTER_ERR_MASK)
/* Warning! All "UNSOLICITED" features are not supported. This is intended for possible future use. */
#define NRFS_UNSOLICITED_GET(_req) (((_req) & NRFS_UNSOLICITED_MASK) >> NRFS_UNSOLICITED_BITPOS)
/* Warning! All "UNSOLICITED" features are not supported. This is intended for possible future use. */
#define NRFS_UNSOLICITED_SET(_req) ((_req) |= NRFS_UNSOLICITED_MASK)
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_SERVICE_ID_TEMP,
NRFS_SERVICE_ID_MRAM,
NRFS_SERVICE_ID_RESET,
NRFS_SERVICE_ID_USB,
NRFS_SERVICE_ID_PMIC,
NRFS_SERVICE_ID_DVFS,
NRFS_SERVICE_ID_DIAG,
NRFS_SERVICE_ID_CLOCK,
};
#ifdef __cplusplus
}
#endif
/* clang-format on */
#endif /* NRFS_REQS_COMMON_H */

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_RESET_REQS_H
#define NRFS_RESET_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_RESET_REQ = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_RESET, 0x01),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_RESET_REQS_H */

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_TEMP_REQS_H
#define NRFS_TEMP_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_TEMP_REQ_MEASURE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_TEMP, 0x01),
NRFS_TEMP_REQ_SUBSCRIBE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_TEMP, 0x02),
NRFS_TEMP_REQ_UNSUBSCRIBE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_TEMP, 0x03),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_TEMP_REQS_H */

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_USB_REQS_H
#define NRFS_USB_REQS_H
#include "nrfs_reqs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
NRFS_USB_REQ_ENABLE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_USB, 0x01),
NRFS_USB_REQ_DISABLE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_USB, 0x02),
};
#ifdef __cplusplus
}
#endif
#endif /* NRFS_USB_REQS_H */

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_CLOCK_H
#define NRFS_INTERNAL_CLOCK_H
#include <zephyr/sys/util_macro.h>
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Clock service event reason.
*
* @note The values are in bit position intervals so that they can be used as masked values.
*/
typedef enum __NRFS_PACKED {
NRFS_CLOCK_EVENT_REASON_LFCLK_ACCURACY_CHANGED = BIT(0),
NRFS_CLOCK_EVENT_REASON_LFCLK_PRECISION_CHANGED = BIT(1),
NRFS_CLOCK_EVENT_REASON_LFCLK_NO_CHANGE = BIT(2),
NRFS_CLOCK_EVENT_REASON_ALL = 0xFF
} nrfs_clock_evt_reason_t;
/** @brief Clock source option. */
typedef enum __NRFS_PACKED {
NRFS_CLOCK_SRC_LFCLK_DEFAULT = 0,
NRFS_CLOCK_SRC_LFCLK_LFRC,
NRFS_CLOCK_SRC_LFCLK_LFLPRC,
NRFS_CLOCK_SRC_LFCLK_SYNTH,
NRFS_CLOCK_SRC_LFCLK_XO_DEFAULT,
NRFS_CLOCK_SRC_LFCLK_XO_DEFAULT_HP,
NRFS_CLOCK_SRC_LFCLK_XO_PIERCE,
NRFS_CLOCK_SRC_LFCLK_XO_PIERCE_HP,
NRFS_CLOCK_SRC_LFCLK_XO_PIXO,
NRFS_CLOCK_SRC_LFCLK_XO_EXT_SINE,
NRFS_CLOCK_SRC_LFCLK_XO_EXT_SINE_HP,
NRFS_CLOCK_SRC_LFCLK_XO_EXT_SQUARE,
} nrfs_clock_src_t;
/** @brief HSFLL120 Mode options. */
typedef enum __NRFS_PACKED {
NRFS_CLOCK_HSFLL_MODE_OPEN = 0,
NRFS_CLOCK_HSFLL_MODE_CLOSED,
}nrfs_clock_hsfll_mode_t;
/** @brief Clock service notification data structure. */
typedef struct __NRFS_PACKED {
nrfs_clock_evt_reason_t reason; /**< Reason for the event. */
nrfs_clock_src_t src; /**< New clock source. */
} nrfs_clock_rsp_data_t;
/** @brief Clock service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_clock_rsp_data_t data; /**< Data of the notification. */
} nrfs_clock_rsp_t;
/** @brief Subscribe request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
uint8_t event_mask; /**< Events to be subscribed to. */
} nrfs_clock_subscribe_t;
/** @brief Unsubscribe request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_clock_unsubscribe_t;
/** @brief LFCLK source request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_clock_src_t src; /**< LFCLK source. */
} nrfs_clock_lfclk_src_req_t;
/** @brief HSFLL mode request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_clock_hsfll_mode_t mode;
} nrfs_clock_hsfll_mode_req_t;
/** @brief HSFLL mode notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_clock_hsfll_mode_t data;
} nrfs_clock_hsfll_mode_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_CLOCK_H */

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_DIAG_H
#define NRFS_DIAG_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief System Diagnostics register access type. */
typedef enum __NRFS_PACKED {
DIAG_REG_READ = 0, /** Register read */
DIAG_REG_WRITE, /** Register write */
DIAG_REG_INVALID, /** Register access invalid */
} diag_reg_access_type_t;
/** @brief System Diagnostics register access. */
typedef struct __NRFS_PACKED {
diag_reg_access_type_t access_type; /** Register access type. */
uint32_t addr; /** Register address. */
uint32_t val; /** Register value. */
} diag_reg_access_t;
/** @brief System Diagnostics service notification data structure. */
typedef struct __NRFS_PACKED {
diag_reg_access_type_t access_type; /** Register access type. */
uint32_t addr; /** Register address. */
uint32_t val; /** Register value. */
} nrfs_diag_rsp_data_t;
/** @brief System Diagnostics register request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
diag_reg_access_t reg; /**< Register access. */
} nrfs_diag_reg_req_t;
/** @brief System Diagnostics service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_diag_rsp_data_t data; /**< Data of the notification. */
} nrfs_diag_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_DIAG_H */

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_DVFS_H
#define NRFS_INTERNAL_DVFS_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
enum __NRFS_PACKED dvfs_frequency_setting {
DVFS_FREQ_HIGH = 0,
DVFS_FREQ_MEDLOW = 1,
DVFS_FREQ_LOW = 2,
DVFS_FREQ_COUNT
};
/** @brief Dynamic Voltage and Frequency Scaling service notification data structure. */
typedef struct __NRFS_PACKED {
bool scaling_prepare; /**< true if given response is a request for scaling preparation,
* false if given response is just a confirmation.
*/
enum dvfs_frequency_setting freq; /**< Maximum allowed HSFLL frequency oppoint. */
} nrfs_dvfs_rsp_data_t;
/** @brief Dynamic Voltage and Frequency Scaling service request data structure. */
typedef struct __NRFS_PACKED {
enum dvfs_frequency_setting target_freq; /** Requested frequency oppoint. */
} nrfs_dvfs_opp_req_data_t;
/** @brief Dynamic Voltage and Frequency Scaling operating frequency change request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_dvfs_opp_req_data_t data; /**< Data of the request. */
} nrfs_dvfs_opp_req_t;
/** @brief Dynamic Voltage and Frequency Scaling general request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_dvfs_req_t;
/** @brief Dynamic Voltage and Frequency Scaling service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_dvfs_rsp_data_t data; /**< Data of the notification. */
} nrfs_dvfs_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_DVFS_H */

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_GENERIC_H
#define NRFS_INTERNAL_GENERIC_H
#include <internal/nrfs_hdr.h>
#include <internal/nrfs_ctx.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Structure describing generic request or notification. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
uint8_t payload[]; /**< Message payload. */
} nrfs_generic_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_GENERIC_H */

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_MRAM_H
#define NRFS_INTERNAL_MRAM_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief MRAM set latency requests. */
typedef enum __NRFS_PACKED {
MRAM_LATENCY_ALLOWED,
MRAM_LATENCY_NOT_ALLOWED,
MRAM_LATENCY_INTERNAL_REQ
} mram_latency_request_t;
/** @brief MRAM set latency data structure. */
typedef struct __NRFS_PACKED {
mram_latency_request_t mram_latency_request;
} nrfs_mram_set_latency_data_t;
/** @brief MRAM set latency request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_mram_set_latency_data_t data; /**< Data of the request. */
} nrfs_mram_set_latency_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_MRAM_H */

View File

@ -0,0 +1,160 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_PMIC_H
#define NRFS_INTERNAL_PMIC_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief PMIC SIM selection. */
typedef enum __NRFS_PACKED {
PMIC_SIM1 = 1, /** SIM1 */
PMIC_SIM2 = 2 /** SIM2 */
} pmic_sim_t;
/** @brief PMIC BLE RADIO TX power. */
typedef enum __NRFS_PACKED {
PMIC_BLE_RADIO_TXPOWER_POS10DBM, /** +10 dBm */
PMIC_BLE_RADIO_TXPOWER_POS9DBM, /** +9 dBm */
PMIC_BLE_RADIO_TXPOWER_POS8DBM, /** +8 dBm */
PMIC_BLE_RADIO_TXPOWER_POS7DBM, /** +7 dBm */
PMIC_BLE_RADIO_TXPOWER_POS6DBM, /** +6 dBm */
PMIC_BLE_RADIO_TXPOWER_POS5DBM, /** +5 dBm */
PMIC_BLE_RADIO_TXPOWER_POS4DBM, /** +4 dBm */
PMIC_BLE_RADIO_TXPOWER_POS3DBM, /** +3 dBm */
PMIC_BLE_RADIO_TXPOWER_POS2DBM, /** +2 dBm */
PMIC_BLE_RADIO_TXPOWER_POS1DBM, /** +1 dBm */
PMIC_BLE_RADIO_TXPOWER_0DBM, /** 0 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG1DBM, /** -1 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG2DBM, /** -2 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG4DBM, /** -4 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG8DBM, /** -8 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG12DBM, /** -12 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG16DBM, /** -16 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG20DBM, /** -20 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG30DBM, /** -30 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG40DBM, /** -40 dBm */
PMIC_BLE_RADIO_TXPOWER_NEG70DBM /** -70 dBm */
} pmic_ble_radio_txpower_t;
/** @brief PMIC TEST IF register access type. */
typedef enum __NRFS_PACKED {
PMIC_REG_READ, /** Register read */
PMIC_REG_WRITE, /** Register write */
PMIC_REG_INVALID, /** Register access invalid */
} pmic_reg_access_type_t;
/** @brief PMIC TEST IF register access. */
typedef struct __NRFS_PACKED {
pmic_reg_access_type_t access_type; /** Register access type */
uint16_t addr; /** Register address */
uint8_t val; /** Register value for writes */
} pmic_reg_access_t;
/** @brief PMIC service notification data structure. */
typedef struct __NRFS_PACKED {
pmic_reg_access_type_t access_type; /** Register access type */
uint8_t val; /** Register value of 8-bit register. */
} nrfs_pmic_rsp_data_t;
/** @brief PMIC RFFE ON request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_rffe_on_req_t;
/** @brief PMIC RFFE OFF request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_rffe_off_req_t;
/** @brief PMIC SIM ON request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
pmic_sim_t sim; /**< SIM to enable. */
} nrfs_pmic_sim_on_req_t;
/** @brief PMIC SIM OFF request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
pmic_sim_t sim; /**< SIM to disable. */
} nrfs_pmic_sim_off_req_t;
/** @brief PMIC BLE RADIO ON request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
pmic_ble_radio_txpower_t txpower; /**< Needed BLE Radio TX Power. */
} nrfs_pmic_ble_radio_on_req_t;
/** @brief PMIC BLE RADIO OFF request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_ble_radio_off_req_t;
/** @brief PMIC PWM default set request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_pwm_default_req_t;
/** @brief PMIC PWM ghost avoid set request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_pwm_ghost_avoid_req_t;
/** @brief PMIC TEST IF request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
pmic_reg_access_t reg; /**< PMIC register access. */
} nrfs_pmic_test_if_req_t;
/** @brief PMIC INFO request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_info_req_t;
/** @brief PMIC available info. */
typedef enum __NRFS_PACKED {
PMIC_NOT_AVAILABLE,
PMIC_AVAILABLE
} pmic_available_t;
/** @brief PMIC info data structure. */
typedef struct __NRFS_PACKED {
pmic_available_t pmic_available;
} nrfs_pmic_info_rsp_data_t;
/** @brief PMIC service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_pmic_info_rsp_data_t data; /**< Data of the notification. */
} nrfs_pmic_info_rsp_t;
/** @brief PMIC service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_pmic_rsp_data_t data; /**< Data of the notification. */
} nrfs_pmic_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_PMIC_H */

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_RESET_H
#define NRFS_INTERNAL_RESET_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Reset request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_reset_req_t;
/** @brief Reset service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. This is left for compatibility purposes. Should always be zero. */
} nrfs_reset_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_RESET_H */

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_TEMP_H
#define NRFS_INTERNAL_TEMP_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Subscribe request data structure. */
typedef struct __NRFS_PACKED {
uint16_t measure_rate_ms; /** Maximal acceptable time between subsequent temperature checks. */
int32_t lower_threshold; /** Temperature lower threshold in a raw 2's complement signed format,
* causing notification to be sent when crossed.
*/
int32_t upper_threshold; /** Temperature upper threshold in a raw 2's complement signed format,
* causing notification to be sent when crossed.
*/
} nrfs_temp_subscribe_data_t;
/** @brief Temperature service notification data structure. */
typedef struct __NRFS_PACKED {
int32_t raw_temp; /** Raw temperature in a 2's complement signed value representation. */
} nrfs_temp_rsp_data_t;
/** @brief Temperature measure request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_temp_measure_t;
/** @brief Subscribe request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_temp_subscribe_data_t data; /**< Data of the request. */
} nrfs_temp_subscribe_t;
/** @brief Unsubscribe request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_temp_unsubscribe_t;
/** @brief Temperature service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_temp_rsp_data_t data; /**< Data of the notification. */
} nrfs_temp_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_TEMP_H */

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_INTERNAL_USB_H
#define NRFS_INTERNAL_USB_H
#include <internal/services/nrfs_generic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief USB VBUS detector service notification data structure for enable request. */
typedef struct __NRFS_PACKED {
bool pll_ok; /** True, when USBHSPLL PLL is locked. */
bool vreg_ok; /** True, when VREGUSB 0V8 and 3V3 voltages are settled. */
bool vbus_detected; /** True, when VBUS is detected. */
} nrfs_usb_rsp_data_t;
/** @brief USB VBUS detector service enable request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_usb_enable_req_t;
/** @brief USB VBUS detector service disable request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_usb_disable_req_t;
/** @brief USB VBUS detector service notification structure for enable request. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
nrfs_usb_rsp_data_t data; /**< Data of the notification. */
} nrfs_usb_rsp_t;
#ifdef __cplusplus
}
#endif
#endif /* NRFS_INTERNAL_USB_H */

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_COMMON_H
#define NRFS_COMMON_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define __NRFS_PACKED __attribute__((__packed__))
/**
* @brief Macro for getting the number of elements in an array.
*
* @param[in] array Name of the array.
*
* @return Array element count.
*/
#define NRFS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
/** @brief Return codes. */
typedef enum __NRFS_PACKED {
NRFS_SUCCESS, /**< Success. */
NRFS_ERR_INVALID_STATE, /**< Invalid state. */
NRFS_ERR_IPC, /**< IPC error. */
} nrfs_err_t;
#endif /* NRFS_COMMON_H */

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_CLOCK_H
#define NRFS_CLOCK_H
#include <internal/services/nrfs_clock.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Clock service event types. */
typedef enum __NRFS_PACKED {
NRFS_CLOCK_EVT_APPLIED, /** Request applied successfully. */
NRFS_CLOCK_EVT_REJECT, /** Request rejected. */
NRFS_CLOCK_EVT_CHANGE, /** Clock event changed. */
} nrfs_clock_evt_type_t;
/** @brief Clock service event. */
typedef struct {
nrfs_clock_evt_type_t type; /** Event type. */
nrfs_clock_rsp_data_t data; /** Event data. */
} nrfs_clock_evt_t;
/** @brief Clock service event handler type. */
typedef void (*nrfs_clock_evt_handler_t)(nrfs_clock_evt_t const * p_evt, void * context);
/**
* @brief Function for initializing the clock service.
*
* @param[in] handler Function called as a response to the request.
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_clock_init(nrfs_clock_evt_handler_t handler);
/**
* @brief Function for uninitializing the clock service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_clock_uninit(void);
/**
* @brief Function for subscribing to events in the clock service.
*
* @note If subscription is already active, calling this function again
* will overwrite the subscription parameters.
*
* @param[in] event_mask Mask of events to be subscribed to. Use values of nrfs_clock_evt_reason_t.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_clock_subscribe(uint8_t event_mask, void * p_context);
/**
* @brief Function for unsubscribing from events in the clock service.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_clock_unsubscribe(void);
/**
* @brief Function for setting LFCLK source.
*
* @param[in] src LFCLK source to be set.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_clock_lfclk_src_set(nrfs_clock_src_t src, void * p_context);
/**
* @brief Function for setting LFCLK source with no response.
*
* @param[in] src LFCLK source to be set.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_clock_lfclk_src_set_no_rsp(nrfs_clock_src_t src, void * p_context);
/**
* @brief Function for setting HSFLL_120 mode.
*
* @param[in] mode HSFLL mode to be set.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_clock_hsfll_mode_set(nrfs_clock_hsfll_mode_t mode, void * p_context);
/**
* @brief Function for setting HSFLL_120 mode with no response.
*
* @param[in] mode HSFLL mode to be set.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_clock_hsfll_mode_set_no_rsp(nrfs_clock_hsfll_mode_t mode, void * p_context);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_CLOCK_H */

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_DIAG_H__
#define NRFS_DIAG_H__
#include <internal/services/nrfs_diag.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief System Diagnostics Service response notification types. */
typedef enum __NRFS_PACKED {
NRFS_DIAG_EVT_APPLIED = 0, /** Request applied succesfully */
NRFS_DIAG_EVT_REJECT, /** Request rejected. */
NRFS_DIAG_EVT_REG_RSP, /** Response for register request */
} nrfs_diag_evt_type_t;
/** @brief System Diagnostics Service response data structure. */
typedef struct __NRFS_PACKED {
nrfs_diag_evt_type_t type; /** Event type. */
struct {
diag_reg_access_type_t access_type; /** Register access type. */
uint32_t addr; /** Register address. */
uint32_t val; /** Register value. */
} reg; /** Register request. */
} nrfs_diag_evt_t;
/** @brief System Diagnostics Service response handler type. */
typedef void (*nrfs_diag_response_handler_t)(nrfs_diag_evt_t const * p_evt, void * p_context);
/**
* @brief Function for initializing the System Diagnostics service.
*
* @param[in] handler Function called as a response to the request
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_diag_init(nrfs_diag_response_handler_t handler);
/**
* @brief Function for uninitializing the System Diagnostics service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_diag_uninit(void);
/**
* @brief Function for reading a register
*
* Value of register read will be available for handler.
*
* @param[in] addr 32-bit register address
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_diag_reg_read(uint32_t addr, void * p_context);
/**
* @brief Function for writing a register
*
* @param[in] addr 32-bit register address
* @param[in] val 32-bit value to be written to the register
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_diag_reg_write(uint32_t addr, uint32_t val, void * p_context);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_DIAG_H__ */

View File

@ -0,0 +1,118 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_DVFS_H
#define NRFS_DVFS_H
#include <internal/services/nrfs_dvfs.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Dynamic Voltage and Frequency Scaling service event types. */
typedef enum __NRFS_PACKED {
NRFS_DVFS_EVT_REJECT, /** General purpose event for rejected requests. */
NRFS_DVFS_EVT_INIT_PREPARATION, /** ABB Oppoint has been set correctly. Ready for second step of initialization sequence. */
NRFS_DVFS_EVT_INIT_DONE, /** ABB Oppoint has been set correctly. Initialization sequence completed. */
NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED, /** Request for operating frequency change has been registered. Please standby. */
NRFS_DVFS_EVT_OPPOINT_SCALING_PREPARE, /** Prepare for voltage scaling. Awaiting the @p nrfs_dvfs_ready_to_scale response. */
NRFS_DVFS_EVT_OPPOINT_SCALING_DONE, /** Voltage scaling done, new oppoint can be applied. */
} nrfs_dvfs_evt_type_t;
/** @brief Dynamic Voltage and Frequency Scaling service event. */
typedef struct {
nrfs_dvfs_evt_type_t type; /** Event type. */
enum dvfs_frequency_setting freq; /** Maximum allowed HSFLL frequency oppoint.
* For the @p NRFS_DVFS_EVT_OPPOINT_SCALING_PREPARE
* this oppoint dictates, which oppoint needs to be prepared. */
} nrfs_dvfs_evt_t;
/** @brief Dynamic Voltage and Frequency Scaling service event handler type. */
typedef void (*nrfs_dvfs_evt_handler_t)(nrfs_dvfs_evt_t const * p_evt, void * context);
/**
* @brief Function for initializing the Dynamic Voltage and Frequency Scaling service.
*
* @param[in] handler Function called as a response to the request.
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_dvfs_init(nrfs_dvfs_evt_handler_t handler);
/**
* @brief Function for uninitializing the Dynamic Voltage and Frequency Scaling service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_dvfs_uninit(void);
/**
* @brief Function for requesting the first step of the init sequence. This will trigger proper ABB Oppoint setting.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_dvfs_init_prepare_request(void * p_context);
/**
* @brief Function for requesting the second step of the init sequence. This will trigger proper ABB Oppoint setting.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_dvfs_init_complete_request(void * p_context);
/**
* @brief Function for requesting an operating frequency change.
* @note The @p target_freq requirement might not be met by the system
* until the NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED response is triggered.
*
* @param[in] target_freq Minimal required frequency oppoint
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_dvfs_oppoint_request(enum dvfs_frequency_setting target_freq, void * p_context);
/**
* @brief Function for requesting an operating frequency change.
* @note The response @p NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED will not be triggered.
*
* @param[in] target_freq Minimal required frequency oppoint
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_dvfs_oppoint_request_no_rsp(enum dvfs_frequency_setting target_freq, void * p_context);
/**
* @brief Function for notifying that the requested oppoint has been prepared.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_dvfs_ready_to_scale(void * p_context);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_DVFS_H */

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_MRAM_H
#define NRFS_MRAM_H
#include <internal/services/nrfs_mram.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief MRAM latency service response notification types. */
typedef enum __NRFS_PACKED {
NRFS_MRAM_LATENCY_REQ_APPLIED, /** sent only as a response to
the request MRAM_LATENCY_NOT_ALLOWED */
NRFS_MRAM_LATENCY_REQ_REJECTED, /** Request rejected. */
} nrfs_mram_latency_evt_type_t;
/** @brief MRAM latency service response data structure. */
typedef struct {
nrfs_mram_latency_evt_type_t type;
} nrfs_mram_latency_evt_t;
/** @brief MRAM latency event handler type. */
typedef void (*nrfs_mram_latency_evt_handler_t)(nrfs_mram_latency_evt_t const * p_evt,
void * context);
/**
* @brief Function for initializing the MRAM latency service.
*
* @param[in] handler Function called as a response to the request.
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_mram_init(nrfs_mram_latency_evt_handler_t handler);
/**
* @brief Function for uninitializing the MRAM latency service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_mram_uninit(void);
/**
* @brief Function for requesting a new acceptable MRAM latency.
*
* @param[in] mram_latency_request Enum value: MRAM_LATENCY_ALLOWED
MRAM_LATENCY_NOT_ALLOWED
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_mram_set_latency(mram_latency_request_t mram_latency_request, void * p_context);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_MRAM_H */

View File

@ -0,0 +1,270 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_PMIC_H
#define NRFS_PMIC_H
#include <internal/services/nrfs_pmic.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief PMIC Service response notification types. */
typedef enum __NRFS_PACKED {
NRFS_PMIC_EVT_APPLIED, /** Request applied succesfully */
NRFS_PMIC_EVT_REJECT, /** Request rejected. */
NRFS_PMIC_EVT_TEST_IF_RSP, /** Response for TEST_IF request */
NRFS_PMIC_EVT_INFO_RSP, /** Response for INFO IF request */
} nrfs_pmic_evt_type_t;
/** @brief PMIC Service response data structure. */
typedef struct {
nrfs_pmic_evt_type_t type; /** Event type. */
pmic_reg_access_type_t access_type; /** Register access type */
uint8_t val; /** Register read value used by PMIC_TEST_IF request */
} nrfs_pmic_evt_t;
/** @brief PMIC Service info response data structure. */
typedef struct {
nrfs_pmic_evt_type_t type; /** Event type. */
nrfs_pmic_info_rsp_data_t info;
} nrfs_pmic_info_evt_t;
/** @brief PMIC Service event handler type. */
typedef void (*nrfs_pmic_evt_handler_t)(void const *p_evt, void * p_context);
/**
* @brief Function for initializing the PMIC service.
*
* @param[in] handler Function called as a response to the request
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_pmic_init(nrfs_pmic_evt_handler_t handler);
/**
* @brief Function for uninitializing the PMIC service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_pmic_uninit(void);
/**
* @brief Function for requesting power ON RFFE interface
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_rffe_on(void * p_context);
/**
* @brief Function for requesting power ON RFFE interface with no response
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_rffe_on_no_rsp(void);
/**
* @brief Function for requesting power OFF RFFE interface
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_rffe_off(void * p_context);
/**
* @brief Function for requesting power OFF RFFE interface with no response
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_rffe_off_no_rsp(void);
/**
* @brief Function for requesting power ON SIM interface
*
* @param[in] sim Requested SIM to power ON.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_sim_on(pmic_sim_t sim, void * p_context);
/**
* @brief Function for requesting power ON SIM interface with no response
*
* @param[in] sim Requested SIM to power ON.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_sim_on_no_rsp(pmic_sim_t sim);
/**
* @brief Function for requesting power OFF SIM interface
*
* @param[in] sim Requested SIM to power OFF.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_sim_off(pmic_sim_t sim, void * p_context);
/**
* @brief Function for requesting power OFF SIM interface with no response
*
* @param[in] sim Requested SIM to power OFF.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_sim_off_no_rsp(pmic_sim_t sim);
/**
* @brief Function for requesting power ON BLE radio
*
* @param[in] txpower Needed TX power
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_ble_radio_on(pmic_ble_radio_txpower_t txpower, void * p_context);
/**
* @brief Function for requesting power ON BLE radio with no response
*
* @param[in] txpower Needed TX power
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_ble_radio_on_no_rsp(pmic_ble_radio_txpower_t txpower);
/**
* @brief Function for requesting power OFF BLE radio
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_ble_radio_off(void * p_context);
/**
* @brief Function for requesting power OFF BLE radio with no response
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_ble_radio_off_no_rsp(void);
/**
* @brief Function for setting default PWM settings to DCDC converters
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_pwm_default_set(void * p_context);
/**
* @brief Function for setting default PWM settings to DCDC converters with no response
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_pwm_default_set_no_rsp(void);
/**
* @brief Function for setting ghost avoidance PWM settings to DCDC converters
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_pwm_ghost_avoid_set(void * p_context);
/**
* @brief Function for setting ghost avoidance PWM settings to DCDC converters with no response
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_pwm_ghost_avoid_set_no_rsp(void);
/**
* @brief Function for checking PMIC existence
*
* Value will be available for handler.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_info_read(void * p_context);
/**
* @brief Function for reading PMIC register
*
* Value of register read will be available for handler.
*
* @param[in] addr 16-bit register address
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_test_if_read(uint16_t addr, void * p_context);
/**
* @brief Function for writing PMIC register
*
* @param[in] addr 16-bit register address
* @param[in] val 8-bit value to be written to PMIC register
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_pmic_test_if_write(uint16_t addr, uint8_t val, void * p_context);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_PMIC_H */

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_RESET_H
#define NRFS_RESET_H
#include <internal/services/nrfs_reset.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Reset service event types. */
typedef enum __NRFS_PACKED {
NRFS_RESET_EVT_DONE, /** Reset done. */
NRFS_RESET_EVT_REJECT, /** Request rejected. */
} nrfs_reset_evt_type_t;
/** @brief Reset service event. */
typedef struct {
nrfs_reset_evt_type_t type; /** Event type. */
} nrfs_reset_evt_t;
/** @brief Reset service event handler type. */
typedef void (*nrfs_reset_evt_handler_t)(nrfs_reset_evt_t const * p_evt);
/**
* @brief Function for initializing the RESET service.
*
* @param[in] handler Function called as a response to the request.
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_reset_init(nrfs_reset_evt_handler_t handler);
/**
* @brief Function for uninitializing the RESET service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_reset_uninit(void);
/**
* @brief Function for requesting a reset of all services.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_request_reset(void);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_RESET_H */

View File

@ -0,0 +1,131 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_TEMP_H
#define NRFS_TEMP_H
#include <internal/services/nrfs_temp.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Temperature service event types. */
typedef enum __NRFS_PACKED {
NRFS_TEMP_EVT_MEASURE_DONE, /** Temperature measurement done. */
NRFS_TEMP_EVT_CHANGE, /** Temperature threshold crossed. */
NRFS_TEMP_EVT_REJECT, /** Request rejected. */
} nrfs_temp_evt_type_t;
/** @brief Temperature service event. */
typedef struct {
nrfs_temp_evt_type_t type; /** Event type. */
int32_t raw_temp; /** Raw temperature in a 2's complement signed value representation.
* Valid for @p NRFS_TEMP_EVT_MEASURE_DONE and @p NRFS_TEMP_EVT_CHANGE. */
} nrfs_temp_evt_t;
/** @brief Temperature service event handler type. */
typedef void (*nrfs_temp_evt_handler_t)(nrfs_temp_evt_t const * p_evt, void * context);
/**
* @brief Function for initializing the Temperature service.
*
* @param[in] handler Function called as a response to the request.
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_temp_init(nrfs_temp_evt_handler_t handler);
/**
* @brief Function for uninitializing the Temperature service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_temp_uninit(void);
/**
* @brief Function for requesting a temperature measurement in Temperature service.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_temp_measure_request(void * p_context);
/**
* @brief Function for subscribing to the temperature monitoring in Temperature service.
*
* @note If subscription is already active, calling this function again
* will overwrite the subscription parameters.
*
* @param[in] measure_rate_ms Maximal acceptable time between subsequent temperature checks.
* @param[in] lower_threshold Temperature lower threshold in a raw 2's complement signed format.
* @param[in] upper_threshold Temperature upper threshold in a raw 2's complement signed format.
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_temp_subscribe(uint16_t measure_rate_ms,
int32_t lower_threshold,
int32_t upper_threshold,
void * p_context);
/**
* @brief Function for unsubscribing from the temperature monitoring in Temperature service.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_temp_unsubscribe(void);
/**
* @brief Function for converting the temperature value from raw data to Celsius scale.
*
* The returned temperature value is in Celsius scale, multiplied by 100.
* For example, the actual temperature of 25.75[C] will be returned as a 2575 signed integer.
* Measurement accuracy is 0.25[C].
*
* @param[in] raw_temp Temperature value in a 2's complement signed value representation.
*
* @return Temperature in Celsius scale.
*/
static inline int32_t nrfs_temp_from_raw(int32_t raw_temp)
{
/* Raw temperature is a 2's complement signed value. Moreover, it is represented
* by 0.25[C] intervals, so division by 4 is needed. To preserve
* fractional part, raw value is multiplied by 100 before division.*/
return (raw_temp * 100) / 4;
}
/**
* @brief Function for converting a temperature value from Celsius scale to raw data.
*
* The returned temperature value is a 2's complement signed value representation.
* For example, actual temperature of 25.75[C] should be provided as 2575 signed integer,
* and will be returned as a 103 integer.
* During conversion, the accuracy will be reduced to 0.25[C] steps.
*
* @param[in] temp_c Temperature value in Celsius scale, multiplied by 100.
*
* @return Temperature in RAW format.
*/
static inline int32_t nrfs_temp_to_raw(int32_t temp_c)
{
return (temp_c * 4) / 100;
}
#ifdef __cplusplus
}
#endif
#endif /* NRFS_TEMP_H */

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef NRFS_USB_H
#define NRFS_USB_H
#include <internal/services/nrfs_usb.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief USB VBUS detector service event types. */
typedef enum __NRFS_PACKED {
NRFS_USB_EVT_VBUS_STATUS_CHANGE, /** VBUS voltage detection status has changed. */
NRFS_USB_EVT_REJECT, /** Request rejected. */
} nrfs_usb_evt_type_t;
/** @brief USB VBUS detector service event. */
typedef struct {
nrfs_usb_evt_type_t type; /** Event type. */
bool vbus_detected; /** True if USB VBUS voltage is detected. */
bool vregusb_ok; /** True if VREG is running OK. */
bool usbhspll_ok; /** True if PLL is running OK. */
} nrfs_usb_evt_t;
/** @brief USB VBUS detector service event handler type. */
typedef void (*nrfs_usb_evt_handler_t)(nrfs_usb_evt_t const * p_evt, void * context);
/**
* @brief Function for initializing the USB VBUS detector service.
*
* @param[in] handler Function called as a response to the request.
*
* @retval NRFS_SUCCESS Service initialized successfully.
* @retval NRFS_ERR_INVALID_STATE Service was already initialized.
*/
nrfs_err_t nrfs_usb_init(nrfs_usb_evt_handler_t handler);
/**
* @brief Function for uninitializing the USB VBUS detector service.
*
* @warning Notifications from previous requests are dropped after service uninitialization.
*/
void nrfs_usb_uninit(void);
/**
* @brief Function for requesting USBHSPLL and VREGUSB to be enabled and configured in USB VBUS detector service.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_usb_enable_request(void * p_context);
/**
* @brief Function for requesting USBHSPLL and VREGUSB to be disabled in USB VBUS detector service.
*
* @param[in] p_context Opaque user data that will be passed to registered callback.
*
* @retval NRFS_SUCCESS Request sent successfully.
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
* @retval NRFS_ERR_IPC Backend returned error during request sending.
*/
nrfs_err_t nrfs_usb_disable_request(void * p_context);
#ifdef __cplusplus
}
#endif
#endif /* NRFS_USB_H */

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_dispatcher.h>
#include <internal/nrfs_callbacks.h>
#include <internal/services/nrfs_generic.h>
#include "nrfs_config.h"
static const nrfs_service_cb_t services_callbacks[] = {
#ifdef NRFS_TEMP_SERVICE_ENABLED
[NRFS_SERVICE_ID_TEMP] = nrfs_temp_service_notify,
#else
[NRFS_SERVICE_ID_TEMP] = NULL,
#endif
#ifdef NRFS_MRAM_SERVICE_ENABLED
[NRFS_SERVICE_ID_MRAM] = nrfs_mram_service_notify,
#else
[NRFS_SERVICE_ID_MRAM] = NULL,
#endif
#ifdef NRFS_RESET_SERVICE_ENABLED
[NRFS_SERVICE_ID_RESET] = nrfs_reset_service_notify,
#else
[NRFS_SERVICE_ID_RESET] = NULL,
#endif
#ifdef NRFS_VBUS_DETECTOR_SERVICE_ENABLED
[NRFS_SERVICE_ID_USB] = nrfs_usb_service_notify,
#else
[NRFS_SERVICE_ID_USB] = NULL,
#endif
#ifdef NRFS_PMIC_SERVICE_ENABLED
[NRFS_SERVICE_ID_PMIC] = nrfs_pmic_service_notify,
#else
[NRFS_SERVICE_ID_PMIC] = NULL,
#endif
#ifdef NRFS_DVFS_SERVICE_ENABLED
[NRFS_SERVICE_ID_DVFS] = nrfs_dvfs_service_notify,
#else
[NRFS_SERVICE_ID_DVFS] = NULL,
#endif
#ifdef NRFS_DIAG_SERVICE_ENABLED
[NRFS_SERVICE_ID_DIAG] = nrfs_diag_service_notify,
#else
[NRFS_SERVICE_ID_DIAG] = NULL,
#endif
#ifdef NRFS_CLOCK_SERVICE_ENABLED
[NRFS_SERVICE_ID_CLOCK] = nrfs_clock_service_notify,
#else
[NRFS_SERVICE_ID_CLOCK] = NULL,
#endif
};
/* Warning! All "UNSOLICITED" features are not supported. This is intended for possible future use. */
void __attribute__((weak)) nrfs_unsolicited_handler(void *p_buffer, size_t size)
{
(void)p_buffer;
(void)size;
}
void nrfs_dispatcher_notify(void *p_notification, size_t size)
{
nrfs_hdr_t *p_hdr = (nrfs_hdr_t *)p_notification;
if (NRFS_HDR_UNSOLICITED_GET(p_hdr)) {
void *p_buffer = ((nrfs_generic_t *)p_notification)->payload;
nrfs_unsolicited_handler(p_buffer, size - sizeof(nrfs_generic_t));
} else {
uint8_t srv_id = NRFS_SERVICE_ID_GET(p_hdr->req);
if ((srv_id < NRFS_ARRAY_SIZE(services_callbacks)) &&
(services_callbacks[srv_id] != NULL)) {
services_callbacks[srv_id](p_notification, size);
} else {
/* TODO: error! unknown service */
}
}
}

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_clock.h>
typedef struct {
nrfs_clock_evt_handler_t handler;
bool is_initialized;
} nrfs_clock_cb_t;
static nrfs_clock_cb_t m_cb;
void nrfs_clock_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_clock_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_CLOCK_EVT_REJECT;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
nrfs_clock_rsp_t *p_rsp = (nrfs_clock_rsp_t *)p_notification;
evt.data = p_rsp->data;
switch (p_data->hdr.req) {
case NRFS_CLOCK_REQ_SUBSCRIBE:
evt.type = NRFS_CLOCK_EVT_CHANGE;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
case NRFS_CLOCK_REQ_LFCLK_SRC:
case NRFS_CLOCK_REQ_HSFLL_MODE:
evt.type = NRFS_CLOCK_EVT_APPLIED;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
default:
break;
}
}
nrfs_err_t nrfs_clock_init(nrfs_clock_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_clock_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_clock_subscribe(uint8_t event_mask, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_clock_subscribe_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_CLOCK_REQ_SUBSCRIBE);
req.ctx.ctx = (uint32_t)p_context;
req.event_mask = event_mask;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_clock_unsubscribe(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_clock_subscribe_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_CLOCK_REQ_UNSUBSCRIBE);
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_clock_lfclk_src_set(nrfs_clock_src_t src, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_clock_lfclk_src_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_CLOCK_REQ_LFCLK_SRC);
req.src = src;
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_clock_lfclk_src_set_no_rsp(nrfs_clock_src_t src, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_clock_lfclk_src_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_CLOCK_REQ_LFCLK_SRC);
NRFS_HDR_NO_RSP_SET(&req.hdr);
req.src = src;
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_clock_hsfll_mode_set(const nrfs_clock_hsfll_mode_t mode, void * p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_clock_hsfll_mode_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_CLOCK_REQ_HSFLL_MODE);
req.mode = mode;
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_clock_hsfll_mode_set_no_rsp(const nrfs_clock_hsfll_mode_t mode, void * p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_clock_hsfll_mode_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_CLOCK_REQ_HSFLL_MODE);
NRFS_HDR_NO_RSP_SET(&req.hdr);
req.mode = mode;
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}

View File

@ -0,0 +1,93 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_diag.h>
typedef struct {
nrfs_diag_response_handler_t handler;
bool is_initialized;
} nrfs_diag_cb_t;
static nrfs_diag_cb_t m_cb;
nrfs_err_t nrfs_diag_init(nrfs_diag_response_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_diag_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_diag_reg_read(uint32_t addr, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_diag_reg_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DIAG_REG);
req.ctx.ctx = (uint32_t)p_context;
req.reg.access_type = DIAG_REG_READ;
req.reg.addr = addr;
req.reg.val = 0;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_diag_reg_write(uint32_t addr, uint32_t val, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_diag_reg_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DIAG_REG);
req.ctx.ctx = (uint32_t)p_context;
req.reg.access_type = DIAG_REG_WRITE;
req.reg.addr = addr;
req.reg.val = val;
return nrfs_backend_send(&req, sizeof(req));
}
void nrfs_diag_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_diag_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_DIAG_EVT_REJECT;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
switch (p_data->hdr.req) {
case NRFS_DIAG_REG:
nrfs_diag_rsp_t *p_rsp = (nrfs_diag_rsp_t *)p_notification;
evt.type = NRFS_DIAG_EVT_REG_RSP;
evt.reg.addr = p_rsp->data.addr;
evt.reg.val = p_rsp->data.val;
evt.reg.access_type = p_rsp->data.access_type;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
default:
break;
}
}

View File

@ -0,0 +1,151 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_dvfs.h>
typedef struct {
nrfs_dvfs_evt_handler_t handler;
bool is_initialized;
} nrfs_dvfs_cb_t;
static nrfs_dvfs_cb_t m_cb;
void nrfs_dvfs_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_dvfs_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_DVFS_EVT_REJECT;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
nrfs_dvfs_rsp_t *p_rsp = (nrfs_dvfs_rsp_t *)p_notification;
evt.freq = p_rsp->data.freq;
switch (p_data->hdr.req) {
case NRFS_DVFS_REQ_INIT_PREPARE:
evt.type = NRFS_DVFS_EVT_INIT_PREPARATION;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
case NRFS_DVFS_REQ_INIT_COMPLETE:
evt.type = NRFS_DVFS_EVT_INIT_DONE;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
case NRFS_DVFS_REQ_OPPOINT:
if (p_rsp->data.scaling_prepare == true) {
evt.type = NRFS_DVFS_EVT_OPPOINT_SCALING_PREPARE;
} else {
evt.type = NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED;
}
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
case NRFS_DVFS_REQ_READY_TO_SCALE:
evt.type = NRFS_DVFS_EVT_OPPOINT_SCALING_DONE;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
default:
break;
}
}
nrfs_err_t nrfs_dvfs_init(nrfs_dvfs_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_dvfs_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_dvfs_init_prepare_request(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_dvfs_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DVFS_REQ_INIT_PREPARE);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_dvfs_init_complete_request(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_dvfs_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DVFS_REQ_INIT_COMPLETE);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_dvfs_oppoint_request(enum dvfs_frequency_setting target_freq, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_dvfs_opp_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DVFS_REQ_OPPOINT);
req.ctx.ctx = (uint32_t)p_context;
req.data.target_freq = target_freq;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_dvfs_oppoint_request_no_rsp(enum dvfs_frequency_setting target_freq,
void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_dvfs_opp_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DVFS_REQ_OPPOINT);
NRFS_HDR_NO_RSP_SET(&req.hdr);
req.ctx.ctx = (uint32_t)p_context;
req.data.target_freq = target_freq;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_dvfs_ready_to_scale(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_dvfs_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_DVFS_REQ_READY_TO_SCALE);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_mram.h>
typedef struct {
nrfs_mram_latency_evt_handler_t handler;
bool is_initialized;
} nrfs_mram_cb_t;
static nrfs_mram_cb_t m_cb;
nrfs_err_t nrfs_mram_init(nrfs_mram_latency_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_mram_latency_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_mram_set_latency(mram_latency_request_t mram_latency_request, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_mram_set_latency_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_MRAM_REQ_SET_LATENCY);
req.ctx.ctx = (uint32_t)p_context;
req.data.mram_latency_request = mram_latency_request;
return nrfs_backend_send(&req, sizeof(req));
}
void nrfs_mram_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_mram_latency_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_MRAM_LATENCY_REQ_REJECTED;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
switch (p_data->hdr.req) {
case NRFS_MRAM_REQ_SET_LATENCY: /* sent only as a response to
the request MRAM_LATENCY_NOT_ALLOWED */
evt.type = NRFS_MRAM_LATENCY_REQ_APPLIED;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
break;
default:
break;
}
}

View File

@ -0,0 +1,357 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_pmic.h>
typedef struct {
nrfs_pmic_evt_handler_t handler;
bool is_initialized;
} nrfs_pmic_cb_t;
static nrfs_pmic_cb_t m_cb;
nrfs_err_t nrfs_pmic_init(nrfs_pmic_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_pmic_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_pmic_rffe_on(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_rffe_on_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_RFFE_ON);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_rffe_on_no_rsp(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_rffe_on_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_RFFE_ON);
NRFS_HDR_NO_RSP_SET(&req.hdr);
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_rffe_off(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_rffe_off_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_RFFE_OFF);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_rffe_off_no_rsp(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_rffe_off_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_RFFE_OFF);
NRFS_HDR_NO_RSP_SET(&req.hdr);
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_sim_on(pmic_sim_t sim, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_sim_on_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_SIM_ON);
req.ctx.ctx = (uint32_t)p_context;
req.sim = sim;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_sim_on_no_rsp(pmic_sim_t sim)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_sim_on_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_SIM_ON);
NRFS_HDR_NO_RSP_SET(&req.hdr);
req.sim = sim;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_sim_off(pmic_sim_t sim, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_sim_off_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_SIM_OFF);
req.ctx.ctx = (uint32_t)p_context;
req.sim = sim;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_sim_off_no_rsp(pmic_sim_t sim)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_sim_off_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_SIM_OFF);
NRFS_HDR_NO_RSP_SET(&req.hdr);
req.sim = sim;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_ble_radio_on(pmic_ble_radio_txpower_t txpower, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_ble_radio_on_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_BLE_RADIO_ON);
req.ctx.ctx = (uint32_t)p_context;
req.txpower = txpower;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_ble_radio_on_no_rsp(pmic_ble_radio_txpower_t txpower)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_ble_radio_on_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_BLE_RADIO_ON);
NRFS_HDR_NO_RSP_SET(&req.hdr);
req.txpower = txpower;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_ble_radio_off(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_ble_radio_off_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_BLE_RADIO_OFF);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_ble_radio_off_no_rsp(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_ble_radio_off_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_BLE_RADIO_OFF);
NRFS_HDR_NO_RSP_SET(&req.hdr);
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_pwm_default_set(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_pwm_default_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_PWM_DEFAULT);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_pwm_default_set_no_rsp(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_pwm_default_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_PWM_DEFAULT);
NRFS_HDR_NO_RSP_SET(&req.hdr);
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_pwm_ghost_avoid_set(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_pwm_ghost_avoid_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_PWM_GHOST_AVOID);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_pwm_ghost_avoid_set_no_rsp(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_pwm_ghost_avoid_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_PWM_GHOST_AVOID);
NRFS_HDR_NO_RSP_SET(&req.hdr);
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_test_if_read(uint16_t addr, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_test_if_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_TEST_IF);
req.ctx.ctx = (uint32_t)p_context;
req.reg.access_type = PMIC_REG_READ;
req.reg.addr = addr;
req.reg.val = 0;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_test_if_write(uint16_t addr, uint8_t val, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_test_if_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_TEST_IF);
req.ctx.ctx = (uint32_t)p_context;
req.reg.access_type = PMIC_REG_WRITE;
req.reg.addr = addr;
req.reg.val = val;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_pmic_info_read(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_pmic_info_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_INFO);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
void nrfs_pmic_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_pmic_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_PMIC_EVT_REJECT;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
switch (p_data->hdr.req) {
case NRFS_PMIC_RFFE_ON:
case NRFS_PMIC_RFFE_OFF:
case NRFS_PMIC_SIM_ON:
case NRFS_PMIC_SIM_OFF:
case NRFS_PMIC_BLE_RADIO_ON:
case NRFS_PMIC_BLE_RADIO_OFF:
case NRFS_PMIC_PWM_DEFAULT:
case NRFS_PMIC_PWM_GHOST_AVOID:
evt.type = NRFS_PMIC_EVT_APPLIED;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
break;
case NRFS_PMIC_TEST_IF:
nrfs_pmic_rsp_t *p_rsp = (nrfs_pmic_rsp_t *)p_notification;
evt.type = NRFS_PMIC_EVT_TEST_IF_RSP;
evt.val = p_rsp->data.val;
evt.access_type = p_rsp->data.access_type;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
case NRFS_PMIC_INFO:
nrfs_pmic_info_rsp_t *p_rsp_info = (nrfs_pmic_info_rsp_t *)p_notification;
nrfs_pmic_info_evt_t info_evt;
info_evt.type = NRFS_PMIC_EVT_INFO_RSP;
info_evt.info = p_rsp_info->data;
m_cb.handler(&info_evt, (void *)p_rsp_info->ctx.ctx);
break;
default:
break;
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_reset.h>
typedef struct {
nrfs_reset_evt_handler_t handler;
bool is_initialized;
} nrfs_reset_cb_t;
static nrfs_reset_cb_t m_cb;
void nrfs_reset_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_reset_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_RESET_EVT_REJECT;
m_cb.handler(&evt);
return;
}
switch (p_data->hdr.req) {
case NRFS_RESET_REQ:
evt.type = NRFS_RESET_EVT_DONE;
m_cb.handler(&evt);
break;
default:
break;
}
}
nrfs_err_t nrfs_reset_init(nrfs_reset_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_reset_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_request_reset(void)
{
nrfs_reset_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_RESET_REQ);
req.ctx.ctx = (uint32_t)0;
return nrfs_backend_send(&req, sizeof(req));
}

View File

@ -0,0 +1,110 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_temp.h>
typedef struct {
nrfs_temp_evt_handler_t handler;
bool is_initialized;
} nrfs_temp_cb_t;
static nrfs_temp_cb_t m_cb;
void nrfs_temp_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_temp_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_TEMP_EVT_REJECT;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
nrfs_temp_rsp_t *p_rsp = (nrfs_temp_rsp_t *)p_notification;
evt.raw_temp = p_rsp->data.raw_temp;
switch (p_data->hdr.req) {
case NRFS_TEMP_REQ_MEASURE:
evt.type = NRFS_TEMP_EVT_MEASURE_DONE;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
case NRFS_TEMP_REQ_SUBSCRIBE:
evt.type = NRFS_TEMP_EVT_CHANGE;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
default:
break;
}
}
nrfs_err_t nrfs_temp_init(nrfs_temp_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_temp_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_temp_measure_request(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_temp_measure_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_TEMP_REQ_MEASURE);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_temp_subscribe(uint16_t measure_rate_ms,
int32_t lower_threshold,
int32_t upper_threshold,
void * p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_temp_subscribe_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_TEMP_REQ_SUBSCRIBE);
req.ctx.ctx = (uint32_t)p_context;
req.data.measure_rate_ms = measure_rate_ms;
req.data.lower_threshold = lower_threshold;
req.data.upper_threshold = upper_threshold;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_temp_unsubscribe(void)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_temp_subscribe_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_TEMP_REQ_UNSUBSCRIBE);
return nrfs_backend_send(&req, sizeof(req));
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <internal/nrfs_backend.h>
#include <internal/nrfs_callbacks.h>
#include <nrfs_usb.h>
typedef struct {
nrfs_usb_evt_handler_t handler;
bool is_initialized;
} nrfs_usb_cb_t;
static nrfs_usb_cb_t m_cb;
void nrfs_usb_service_notify(void *p_notification, size_t size)
{
if (!m_cb.handler || !m_cb.is_initialized) {
return;
}
nrfs_usb_evt_t evt;
nrfs_generic_t *p_data = (nrfs_generic_t *)p_notification;
if (NRFS_HDR_FILTER_ERR_GET(&p_data->hdr)) {
evt.type = NRFS_USB_EVT_REJECT;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
return;
}
nrfs_usb_rsp_t *p_rsp = (nrfs_usb_rsp_t *)p_notification;
switch (p_data->hdr.req) {
case NRFS_USB_REQ_ENABLE:
evt.type = NRFS_USB_EVT_VBUS_STATUS_CHANGE;
evt.usbhspll_ok = p_rsp->data.pll_ok;
evt.vregusb_ok = p_rsp->data.vreg_ok;
evt.vbus_detected = p_rsp->data.vbus_detected;
m_cb.handler(&evt, (void *)p_rsp->ctx.ctx);
break;
default:
break;
}
}
nrfs_err_t nrfs_usb_init(nrfs_usb_evt_handler_t handler)
{
if (m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
m_cb.handler = handler;
m_cb.is_initialized = true;
return NRFS_SUCCESS;
}
void nrfs_usb_uninit(void)
{
m_cb.is_initialized = false;
}
nrfs_err_t nrfs_usb_enable_request(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_usb_enable_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_USB_REQ_ENABLE);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}
nrfs_err_t nrfs_usb_disable_request(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}
nrfs_usb_disable_req_t req;
NRFS_SERVICE_HDR_FILL(&req, NRFS_USB_REQ_DISABLE);
req.ctx.ctx = (uint32_t)p_context;
return nrfs_backend_send(&req, sizeof(req));
}