mgmt: mcumgr: Add event ID index callback function

Adds a function which gets the callback ID index of a given
event ID.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-06-12 13:05:21 +01:00 committed by Fabio Baltieri
parent a9a6df9b50
commit 6c541e1af0
2 changed files with 32 additions and 0 deletions

View file

@ -227,6 +227,15 @@ struct mgmt_evt_op_cmd_arg {
};
};
/**
* @brief Get event ID index from event.
*
* @param event Event to get ID index from.
*
* @return Event index.
*/
uint8_t mgmt_evt_get_index(uint32_t event);
/**
* @brief This function is called to notify registered callbacks about mcumgr notifications/events.
*

View file

@ -5,6 +5,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <assert.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/device.h>
@ -167,6 +168,28 @@ enum mgmt_cb_return mgmt_callback_notify(uint32_t event, void *data, size_t data
return return_status;
}
uint8_t mgmt_evt_get_index(uint32_t event)
{
uint8_t index = 0;
event &= MGMT_EVT_OP_ID_ALL;
__ASSERT((event != 0), "Event cannot be 0.");
while (index < 16) {
if (event & 0x1) {
break;
}
++index;
event = event >> 1;
}
event = event >> 1;
__ASSERT((event == 0), "Event cannot contain multiple values.");
return index;
}
#endif
/* Processes all registered MCUmgr handlers at start up and registers them */