nrfxlib API 0.1.0
Loading...
Searching...
No Matches
nrf_802154_nrfx_addons.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35#ifndef NRF_802154_NRFX_ADDONS_H__
36#define NRF_802154_NRFX_ADDONS_H__
37
38#include "nrfx.h"
39#include "nrf_802154_config.h"
40#include "nrf_802154_const.h"
41
42/* The usage of ED_RSSISCALE is described imprecisely in the nRF product specifications. The meaning of
43 this constant is the following: If we calculate ed_scaled = EDSAMPLE * ED_RSSISCALE, then
44 it is guaranteed that in the range 0-255 ed_scaled maps linearly to the ED power in dBm. This means,
45 that the maximum value in EDSAMPLE which can be reported in compliance with the 802.15.4 specification is
46 255/ED_RSSISCALE. */
47
48#if defined (NRF52833_XXAA) || defined(NRF5340_XXAA)
49#define ED_RSSIOFFS (-93)
50#define ED_RSSISCALE 4
51#else
52#define ED_RSSIOFFS (-92)
53#define ED_RSSISCALE 4
54#endif
55
56#define EDSAMPLE_MIN_REPORTED_VALUE (PHY_MIN_RECEIVER_SENSITIVITY - ED_RSSIOFFS + 10)
57#define EDSAMPLE_MAX_REPORTED_VALUE (ED_RESULT_MAX / ED_RSSISCALE)
58
60#define ED_DBM_MIN (PHY_MIN_RECEIVER_SENSITIVITY + 10)
61
63#define ED_DBM_MAX (EDSAMPLE_MAX_REPORTED_VALUE + ED_RSSIOFFS)
64
65static inline uint8_t nrf_802154_addons_energy_level_from_dbm_calculate(int8_t ed_dbm)
66{
67 uint32_t r;
68
69 if (ed_dbm < ED_DBM_MIN)
70 {
71 return 0;
72 }
73
74 r = ((uint32_t)(ed_dbm - ED_DBM_MIN)) * ED_RESULT_MAX / (ED_DBM_MAX - ED_DBM_MIN);
75
76 if (r > ED_RESULT_MAX)
77 {
78 r = ED_RESULT_MAX;
79 }
80
81 return r;
82}
83
84#endif // NRF_802154_NRFX_ADDONS_H__
#define ED_RESULT_MAX
Maximal ED result.
Definition: nrf_802154_const.h:185
#define ED_DBM_MIN
Definition: nrf_802154_nrfx_addons.h:60
#define ED_DBM_MAX
Definition: nrf_802154_nrfx_addons.h:63
static uint8_t nrf_802154_addons_energy_level_from_dbm_calculate(int8_t ed_dbm)
Definition: nrf_802154_nrfx_addons.h:65