-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: lte_link_control: refactor into modules
Divides the LTE Link Controller into modules. Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
- Loading branch information
1 parent
cdbb02a
commit 13b4862
Showing
56 changed files
with
4,523 additions
and
1,682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
menuconfig LOCATION | ||
bool "Location" | ||
select LTE_LC_PSM | ||
select LTE_LC_XMODEMSLEEP | ||
|
||
if LOCATION | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
zephyr_library_sources(event_handler_list.c) | ||
zephyr_library_sources(helpers.c) | ||
zephyr_library_sources(work_q.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <string.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <modem/lte_lc.h> | ||
|
||
#include <common/event_handler_list.h> | ||
|
||
LOG_MODULE_DECLARE(lte_lc, CONFIG_LTE_LINK_CONTROL_LOG_LEVEL); | ||
|
||
static K_MUTEX_DEFINE(list_mtx); | ||
|
||
/**@brief List element for event handler list. */ | ||
struct event_handler { | ||
sys_snode_t node; | ||
lte_lc_evt_handler_t handler; | ||
}; | ||
|
||
static sys_slist_t handler_list; | ||
|
||
/** | ||
* @brief Find the handler from the event handler list. | ||
* | ||
* @return The node or NULL if not found and its previous node in @p prev_out. | ||
*/ | ||
static struct event_handler *event_handler_list_node_find(struct event_handler **prev_out, | ||
lte_lc_evt_handler_t handler) | ||
{ | ||
struct event_handler *prev = NULL, *curr; | ||
|
||
SYS_SLIST_FOR_EACH_CONTAINER(&handler_list, curr, node) { | ||
if (curr->handler == handler) { | ||
*prev_out = prev; | ||
return curr; | ||
} | ||
prev = curr; | ||
} | ||
return NULL; | ||
} | ||
|
||
/**@brief Add the handler in the event handler list if not already present. */ | ||
int event_handler_list_handler_append(lte_lc_evt_handler_t handler) | ||
{ | ||
struct event_handler *to_ins; | ||
|
||
k_mutex_lock(&list_mtx, K_FOREVER); | ||
|
||
/* Check if handler is already registered. */ | ||
if (event_handler_list_node_find(&to_ins, handler) != NULL) { | ||
LOG_DBG("Handler already registered. Nothing to do"); | ||
k_mutex_unlock(&list_mtx); | ||
return 0; | ||
} | ||
|
||
/* Allocate memory and fill. */ | ||
to_ins = (struct event_handler *)k_malloc(sizeof(struct event_handler)); | ||
if (to_ins == NULL) { | ||
k_mutex_unlock(&list_mtx); | ||
return -ENOBUFS; | ||
} | ||
memset(to_ins, 0, sizeof(struct event_handler)); | ||
to_ins->handler = handler; | ||
|
||
/* Insert handler in the list. */ | ||
sys_slist_append(&handler_list, &to_ins->node); | ||
k_mutex_unlock(&list_mtx); | ||
return 0; | ||
} | ||
|
||
/**@brief Remove the handler from the event handler list if registered. */ | ||
int event_handler_list_handler_remove(lte_lc_evt_handler_t handler) | ||
{ | ||
struct event_handler *curr, *prev = NULL; | ||
|
||
k_mutex_lock(&list_mtx, K_FOREVER); | ||
|
||
/* Check if the handler is registered before removing it. */ | ||
curr = event_handler_list_node_find(&prev, handler); | ||
if (curr == NULL) { | ||
LOG_WRN("Handler not registered. Nothing to do"); | ||
k_mutex_unlock(&list_mtx); | ||
return 0; | ||
} | ||
|
||
/* Remove the handler from the list. */ | ||
sys_slist_remove(&handler_list, &prev->node, &curr->node); | ||
k_free(curr); | ||
|
||
k_mutex_unlock(&list_mtx); | ||
return 0; | ||
} | ||
|
||
/**@brief dispatch events. */ | ||
void event_handler_list_dispatch(const struct lte_lc_evt *const evt) | ||
{ | ||
struct event_handler *curr, *tmp; | ||
|
||
if (event_handler_list_is_empty()) { | ||
return; | ||
} | ||
|
||
k_mutex_lock(&list_mtx, K_FOREVER); | ||
|
||
/* Dispatch events to all registered handlers */ | ||
LOG_DBG("Dispatching event: type=%d", evt->type); | ||
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&handler_list, curr, tmp, node) { | ||
LOG_DBG(" - handler=0x%08X", (uint32_t)curr->handler); | ||
curr->handler(evt); | ||
} | ||
LOG_DBG("Done"); | ||
|
||
k_mutex_unlock(&list_mtx); | ||
} | ||
|
||
/**@brief Test if the handler list is empty. */ | ||
bool event_handler_list_is_empty(void) | ||
{ | ||
return sys_slist_is_empty(&handler_list); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#include <common/helpers.h> | ||
|
||
LOG_MODULE_DECLARE(lte_lc, CONFIG_LTE_LINK_CONTROL_LOG_LEVEL); | ||
|
||
int string_to_int(const char *str_buf, int base, int *output) | ||
{ | ||
int temp; | ||
char *end_ptr; | ||
|
||
__ASSERT_NO_MSG(str_buf != NULL); | ||
|
||
errno = 0; | ||
temp = strtol(str_buf, &end_ptr, base); | ||
|
||
if (end_ptr == str_buf || *end_ptr != '\0' || | ||
((temp == LONG_MAX || temp == LONG_MIN) && errno == ERANGE)) { | ||
return -ENODATA; | ||
} | ||
|
||
*output = temp; | ||
|
||
return 0; | ||
} | ||
|
||
int string_param_to_int(struct at_parser *parser, size_t idx, int *output, int base) | ||
{ | ||
int err; | ||
char str_buf[16]; | ||
size_t len = sizeof(str_buf); | ||
|
||
__ASSERT_NO_MSG(parser != NULL); | ||
__ASSERT_NO_MSG(output != NULL); | ||
|
||
err = at_parser_string_get(parser, idx, str_buf, &len); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
if (string_to_int(str_buf, base, output)) { | ||
return -ENODATA; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int plmn_param_string_to_mcc_mnc(struct at_parser *parser, size_t idx, int *mcc, int *mnc) | ||
{ | ||
int err; | ||
char str_buf[7]; | ||
size_t len = sizeof(str_buf); | ||
|
||
err = at_parser_string_get(parser, idx, str_buf, &len); | ||
if (err) { | ||
LOG_ERR("Could not get PLMN, error: %d", err); | ||
return err; | ||
} | ||
|
||
str_buf[len] = '\0'; | ||
|
||
/* Read MNC and store as integer. The MNC starts as the fourth character | ||
* in the string, following three characters long MCC. | ||
*/ | ||
err = string_to_int(&str_buf[3], 10, mnc); | ||
if (err) { | ||
LOG_ERR("Could not get MNC, error: %d", err); | ||
return err; | ||
} | ||
|
||
/* NUL-terminate MCC, read and store it. */ | ||
str_buf[3] = '\0'; | ||
|
||
err = string_to_int(str_buf, 10, mcc); | ||
if (err) { | ||
LOG_ERR("Could not get MCC, error: %d", err); | ||
return err; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.