Skip to content

Commit 9aebdd0

Browse files
committed
lorawan: pass pointer callback to callback invocation
This allows to make use of CONTAINER_OF() macro when registered 'struct lorawan_downlink_cb' is part of another structure. Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
1 parent 70fc4a3 commit 9aebdd0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

include/zephyr/lorawan/lorawan.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ struct lorawan_join_config {
170170
/** Flag to indicate receiving on any port */
171171
#define LW_RECV_PORT_ANY UINT16_MAX
172172

173+
struct lorawan_downlink_cb;
174+
175+
/**
176+
* @brief Defines the downlink callback handler function signature.
177+
*
178+
* @param cb Pointer to registered callback
179+
* @param port Port message was sent on
180+
* @param flags Downlink data flags (see @ref lorawan_dl_flags)
181+
* @param rssi Received signal strength in dBm
182+
* @param snr Signal to Noise ratio in dBm
183+
* @param len Length of data received, will be 0 for ACKs
184+
* @param data Data received, will be NULL for ACKs
185+
*/
186+
typedef void (*lorawan_downlink_cb_t)(struct lorawan_downlink_cb *cb,
187+
uint8_t port, uint8_t flags,
188+
int16_t rssi, int8_t snr,
189+
uint8_t len, const uint8_t *data);
190+
173191
/**
174192
* @brief LoRaWAN downlink callback parameters
175193
*/
@@ -187,16 +205,8 @@ struct lorawan_downlink_cb {
187205
*
188206
* @note Callbacks are run on the system workqueue,
189207
* and should therefore be as short as possible.
190-
*
191-
* @param port Port message was sent on
192-
* @param flags Downlink data flags (see @ref lorawan_dl_flags)
193-
* @param rssi Received signal strength in dBm
194-
* @param snr Signal to Noise ratio in dBm
195-
* @param len Length of data received, will be 0 for ACKs
196-
* @param data Data received, will be NULL for ACKs
197208
*/
198-
void (*cb)(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, uint8_t len,
199-
const uint8_t *data);
209+
lorawan_downlink_cb_t cb;
200210
/** Node for callback list */
201211
sys_snode_t node;
202212
};

subsys/lorawan/lorawan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ static void mcps_indication_handler(McpsIndication_t *mcps_indication)
184184
SYS_SLIST_FOR_EACH_CONTAINER(&dl_callbacks, cb, node) {
185185
if ((cb->port == LW_RECV_PORT_ANY) ||
186186
(cb->port == mcps_indication->Port)) {
187-
cb->cb(mcps_indication->Port, flags, mcps_indication->Rssi,
187+
cb->cb(cb,
188+
mcps_indication->Port, flags, mcps_indication->Rssi,
188189
mcps_indication->Snr, mcps_indication->BufferSize,
189190
mcps_indication->Buffer);
190191
}

0 commit comments

Comments
 (0)