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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nrfs/include/internal/requests/nrfs_pmic_reqs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum {
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),
NRFS_PMIC_POFWARN_TH = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x0B),
NRFS_PMIC_POFWARN_STATUS = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_PMIC, 0x0C),
};

#ifdef __cplusplus
Expand Down
21 changes: 20 additions & 1 deletion nrfs/include/internal/services/nrfs_pmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ typedef struct __NRFS_PACKED {
/** @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. */
/** Response value: PMIC register content (TEST_IF)
* or VDETPOF5V0 STATUSANA (POFWARN status).
*/
uint8_t val;
} nrfs_pmic_rsp_data_t;

/** @brief PMIC RFFE ON request structure. */
Expand Down Expand Up @@ -146,6 +149,22 @@ typedef struct __NRFS_PACKED {
nrfs_pmic_info_rsp_data_t data; /**< Data of the notification. */
} nrfs_pmic_info_rsp_t;

/** @brief PMIC POFWARN subscribe/threshold set request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
/** Per-subscriber POFWARN threshold in decivolts.
* 0 = unsubscribe, 18..49 = 1.8..4.9V (subscribes to notification).
*/
uint8_t threshold;
} nrfs_pmic_pofwarn_th_req_t;

/** @brief PMIC POFWARN status get request structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
nrfs_ctx_t ctx; /**< Context of the message. */
} nrfs_pmic_pofwarn_status_req_t;

/** @brief PMIC service notification structure. */
typedef struct __NRFS_PACKED {
nrfs_hdr_t hdr; /**< Header of the message. */
Expand Down
36 changes: 36 additions & 0 deletions nrfs/include/services/nrfs_pmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ typedef enum __NRFS_PACKED {
NRFS_PMIC_EVT_REJECT = 1, /** Request rejected. */
NRFS_PMIC_EVT_TEST_IF_RSP = 2, /** Response for TEST_IF request */
NRFS_PMIC_EVT_INFO_RSP = 3, /** Response for INFO IF request */
NRFS_PMIC_EVT_POFWARN = 4, /** Power-fail warning */
NRFS_PMIC_EVT_POFWARN_TH_SET = 5, /** POFWARN TH set */
NRFS_PMIC_EVT_POFWARN_STATUS = 6, /** POFWARN status */
} nrfs_pmic_evt_type_t;

/** @brief PMIC Service response data structure. */
Expand Down Expand Up @@ -263,6 +266,39 @@ nrfs_err_t nrfs_pmic_test_if_read(uint16_t addr, void * p_context);
*/
nrfs_err_t nrfs_pmic_test_if_write(uint16_t addr, uint8_t val, void * p_context);

/**
Comment thread
kpuusaari marked this conversation as resolved.
* @brief Function for subscribing to POFWARN notification
*
* Sets the power-fail warning threshold voltage and subscribes
* the caller to the POFWARN notification. Each subscriber
* maintains its own threshold. Set @p volts to 0 to unsubscribe.
*
* @param[in] volts Threshold voltage value (decivolts). 0 to unsubscribe.
* @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_pofwarn_th_set(int volts, void *p_context);

/**
Comment thread
kpuusaari marked this conversation as resolved.
* @brief Function for reading POFWARN status for this subscriber
*
* Returns the current POFWARN comparator status relative to the subscriber's
* own threshold. The subscriber must have set a threshold via
* @ref nrfs_pmic_pofwarn_th_set before calling this function.
*
* @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_pofwarn_status_get(void *p_context);

#ifdef __cplusplus
}
#endif
Expand Down
47 changes: 47 additions & 0 deletions nrfs/src/services/nrfs_pmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,35 @@ nrfs_err_t nrfs_pmic_test_if_write(uint16_t addr, uint8_t val, void *p_context)
return nrfs_backend_send(&req, sizeof(req));
}

nrfs_err_t nrfs_pmic_pofwarn_th_set(int volts, void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}

nrfs_pmic_pofwarn_th_req_t req;

NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_POFWARN_TH);
req.ctx.ctx = (uint32_t)p_context;
req.threshold = volts;

return nrfs_backend_send(&req, sizeof(req));
}

nrfs_err_t nrfs_pmic_pofwarn_status_get(void *p_context)
{
if (!m_cb.is_initialized) {
return NRFS_ERR_INVALID_STATE;
}

nrfs_pmic_pofwarn_status_req_t req;

NRFS_SERVICE_HDR_FILL(&req, NRFS_PMIC_POFWARN_STATUS);
req.ctx.ctx = (uint32_t)p_context;

return nrfs_backend_send(&req, sizeof(req));
}

nrfs_err_t nrfs_pmic_info_read(void *p_context)
{
if (!m_cb.is_initialized) {
Expand Down Expand Up @@ -351,6 +380,24 @@ void nrfs_pmic_service_notify(void *p_notification, size_t size)
info_evt.info = p_rsp_info->data;
m_cb.handler(&info_evt, (void *)p_rsp_info->ctx.ctx);
break;
case NRFS_PMIC_POFWARN_TH:
nrfs_pmic_evt_t *p_pofwarn_evt;

p_pofwarn_evt = (nrfs_pmic_evt_t *)p_data->payload;

evt.type = p_pofwarn_evt->type;
m_cb.handler(&evt, (void *)p_data->ctx.ctx);
break;

case NRFS_PMIC_POFWARN_STATUS:
nrfs_pmic_rsp_t *p_status_rsp;

p_status_rsp = (nrfs_pmic_rsp_t *)p_notification;
evt.type = NRFS_PMIC_EVT_POFWARN_STATUS;
evt.val = p_status_rsp->data.val;
m_cb.handler(&evt, (void *)p_status_rsp->ctx.ctx);
break;

default:
break;
}
Expand Down