drivers: modem: gsm_ppp: Use DTS
Convert the gsm_ppp driver to use DTS. Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
parent
6c98d41ba6
commit
9d2f8a1124
19 changed files with 87 additions and 29 deletions
|
@ -29,9 +29,6 @@ config MODEM_GSM_SIMCOM
|
|||
|
||||
endchoice
|
||||
|
||||
config MODEM_GSM_UART_NAME
|
||||
string "UART device name the modem is connected to"
|
||||
|
||||
config MODEM_GSM_RX_STACK_SIZE
|
||||
int "Size of the stack allocated for receiving data from modem"
|
||||
default 512
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_gsm_ppp
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL);
|
||||
|
||||
|
@ -24,6 +26,7 @@ LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL);
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#define GSM_UART_NODE DT_INST_BUS(0)
|
||||
#define GSM_CMD_READ_BUF 128
|
||||
#define GSM_CMD_AT_TIMEOUT K_SECONDS(2)
|
||||
#define GSM_CMD_SETUP_TIMEOUT K_SECONDS(6)
|
||||
|
@ -522,8 +525,7 @@ static struct net_if *ppp_net_if(void)
|
|||
static void set_ppp_carrier_on(struct gsm_modem *gsm)
|
||||
{
|
||||
static const struct ppp_api *api;
|
||||
const struct device *ppp_dev =
|
||||
device_get_binding(CONFIG_NET_PPP_DRV_NAME);
|
||||
const struct device *ppp_dev = DEVICE_DT_GET(DT_INST(0, zephyr_gsm_ppp));
|
||||
struct net_if *iface = gsm->iface;
|
||||
int ret;
|
||||
|
||||
|
@ -821,7 +823,7 @@ static void mux_setup(struct k_work *work)
|
|||
{
|
||||
struct gsm_modem *gsm = CONTAINER_OF(work, struct gsm_modem,
|
||||
gsm_configure_work);
|
||||
const struct device *uart = device_get_binding(CONFIG_MODEM_GSM_UART_NAME);
|
||||
const struct device *uart = DEVICE_DT_GET(GSM_UART_NODE);
|
||||
int ret;
|
||||
|
||||
/* We need to call this to reactivate mux ISR. Note: This is only called
|
||||
|
@ -980,7 +982,7 @@ void gsm_ppp_start(const struct device *dev)
|
|||
|
||||
/* Re-init underlying UART comms */
|
||||
int r = modem_iface_uart_init_dev(&gsm->context.iface,
|
||||
device_get_binding(CONFIG_MODEM_GSM_UART_NAME));
|
||||
DEVICE_DT_GET(GSM_UART_NODE));
|
||||
if (r) {
|
||||
LOG_ERR("modem_iface_uart_init returned %d", r);
|
||||
return;
|
||||
|
@ -1057,7 +1059,7 @@ static int gsm_init(const struct device *dev)
|
|||
gsm->gsm_data.rx_rb_buf_len = sizeof(gsm->gsm_rx_rb_buf);
|
||||
|
||||
r = modem_iface_uart_init(&gsm->context.iface, &gsm->gsm_data,
|
||||
device_get_binding(CONFIG_MODEM_GSM_UART_NAME));
|
||||
DEVICE_DT_GET(GSM_UART_NODE));
|
||||
if (r < 0) {
|
||||
LOG_DBG("iface uart error %d", r);
|
||||
return r;
|
||||
|
@ -1091,5 +1093,5 @@ static int gsm_init(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
DEVICE_DEFINE(gsm_ppp, GSM_MODEM_DEVICE_NAME, gsm_init, NULL, &gsm, NULL,
|
||||
DEVICE_DT_DEFINE(DT_INST(0, zephyr_gsm_ppp), gsm_init, NULL, &gsm, NULL,
|
||||
POST_KERNEL, CONFIG_MODEM_GSM_INIT_PRIORITY, NULL);
|
||||
|
|
|
@ -862,7 +862,7 @@ static int ppp_start(const struct device *dev)
|
|||
|
||||
dev_name = mux->name;
|
||||
#elif IS_ENABLED(CONFIG_MODEM_GSM_PPP)
|
||||
dev_name = CONFIG_MODEM_GSM_UART_NAME;
|
||||
dev_name = DT_BUS_LABEL(DT_INST(0, zephyr_gsm_ppp));
|
||||
#else
|
||||
dev_name = CONFIG_NET_PPP_UART_NAME;
|
||||
#endif
|
||||
|
|
8
dts/bindings/modem/zephyr,gsm-ppp.yaml
Normal file
8
dts/bindings/modem/zephyr,gsm-ppp.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (c) 2021 G-Technologies Sdn. Bhd.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: GSM PPP modem
|
||||
|
||||
compatible: "zephyr,gsm-ppp"
|
||||
|
||||
include: uart-device.yaml
|
|
@ -7,8 +7,6 @@
|
|||
#ifndef GSM_PPP_H_
|
||||
#define GSM_PPP_H_
|
||||
|
||||
#define GSM_MODEM_DEVICE_NAME "modem_gsm"
|
||||
|
||||
/** @cond INTERNAL_HIDDEN */
|
||||
struct device;
|
||||
void gsm_ppp_start(const struct device *dev);
|
||||
|
|
|
@ -87,17 +87,27 @@ Modem
|
|||
The Modem support is quite similar to WIFI, you need a board with an embedded
|
||||
Modem support or you can add a shield. Currently, the overlay was created to
|
||||
allow modems with PPP support. This was tested using ``SIMcom SIM808 EVB``.
|
||||
Additionally you need fill ``CONFIG_MODEM_GSM_UART_NAME`` with the UART label
|
||||
``CONFIG_MODEM_GSM_APN`` with the correspondent Access Point Name (APN) at
|
||||
:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file.
|
||||
Additionally you need fill ``CONFIG_MODEM_GSM_APN`` with the correspondent Access
|
||||
Point Name (APN) at
|
||||
:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file. A
|
||||
DTC overlay file should be used to configure the glue between the modem and the
|
||||
uart port. It can reside at boards directory, with the board name, or it can be
|
||||
a special designator like defined at ``arduino.overlay``.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/cloud/tagoio_http_post
|
||||
:board: [sam4e_xpro | frdm_k64f]
|
||||
:board: sam4e_xpro
|
||||
:gen-args: -DOVERLAY_CONFIG=overlay-modem.conf
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/cloud/tagoio_http_post
|
||||
:board: frdm_k64f
|
||||
:gen-args: -DOVERLAY_CONFIG=overlay-modem.conf -DDTC_OVERLAY_FILE=arduino.overlay
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
In a terminal window you can check if communication is happen:
|
||||
|
||||
.. code-block:: console
|
||||
|
|
15
samples/net/cloud/tagoio_http_post/arduino.overlay
Normal file
15
samples/net/cloud/tagoio_http_post/arduino.overlay
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2021 G-Technologies Sdn. Bhd.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&arduino_serial {
|
||||
status = "okay";
|
||||
current-speed = <115200>;
|
||||
|
||||
gsm: gsm-modem {
|
||||
compatible = "zephyr,gsm-ppp";
|
||||
label = "gsm_ppp";
|
||||
};
|
||||
};
|
15
samples/net/cloud/tagoio_http_post/boards/sam4e_xpro.overlay
Normal file
15
samples/net/cloud/tagoio_http_post/boards/sam4e_xpro.overlay
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2021 G-Technologies Sdn. Bhd.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&usart1 {
|
||||
status = "okay";
|
||||
current-speed = <115200>;
|
||||
|
||||
gsm: gsm-modem {
|
||||
compatible = "zephyr,gsm-ppp";
|
||||
label = "gsm_ppp";
|
||||
};
|
||||
};
|
|
@ -7,7 +7,6 @@ CONFIG_MODEM_SHELL=y
|
|||
CONFIG_MODEM_CMD_HANDLER_MAX_PARAM_COUNT=20
|
||||
CONFIG_MODEM_GSM_PPP=y
|
||||
CONFIG_MODEM_GSM_RX_STACK_SIZE=1024
|
||||
CONFIG_MODEM_GSM_UART_NAME="<your board UART port label>"
|
||||
CONFIG_MODEM_GSM_APN="<your Access Point Name (APN)>"
|
||||
|
||||
# Network management events
|
||||
|
|
|
@ -16,4 +16,7 @@ tests:
|
|||
platform_allow: frdm_k64f nucleo_f767zi
|
||||
sample.net.cloud.tagoio_http_post.modem:
|
||||
extra_args: OVERLAY_CONFIG="overlay-modem.conf"
|
||||
platform_allow: sam4e_xpro frdm_k64f
|
||||
platform_allow: sam4e_xpro
|
||||
sample.net.cloud.tagoio_http_post.modem.arduino:
|
||||
extra_args: OVERLAY_CONFIG="overlay-modem.conf" DTC_OVERLAY_FILE="arduino.overlay"
|
||||
platform_allow: frdm_k64f
|
||||
|
|
|
@ -6,4 +6,8 @@
|
|||
&uart2 {
|
||||
status = "okay";
|
||||
current-speed = <115200>;
|
||||
gsm: gsm-modem {
|
||||
compatible = "zephyr,gsm-ppp";
|
||||
label = "gsm_ppp";
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,7 +4,6 @@ CONFIG_SERIAL=y
|
|||
# GSM modem support
|
||||
CONFIG_MODEM=y
|
||||
CONFIG_MODEM_GSM_PPP=y
|
||||
CONFIG_MODEM_GSM_UART_NAME="UART_1"
|
||||
|
||||
# PPP networking support
|
||||
CONFIG_NET_PPP=y
|
||||
|
|
|
@ -2,6 +2,8 @@ common:
|
|||
harness: net
|
||||
depends_on: serial-net
|
||||
tags: net ppp modem gsm
|
||||
platform_allow: frdm_k64f
|
||||
extra_args: DTC_OVERLAY_FILE="boards/frdm_uart2_dts.overlay"
|
||||
sample:
|
||||
description: Sample for generic GSM modem
|
||||
name: Generic GSM modem using PPP
|
||||
|
|
|
@ -93,13 +93,14 @@ static void event_handler(struct net_mgmt_event_callback *cb,
|
|||
int main(void)
|
||||
{
|
||||
const struct device *uart_dev =
|
||||
device_get_binding(CONFIG_MODEM_GSM_UART_NAME);
|
||||
DEVICE_DT_GET(DT_BUS(DT_INST(0, zephyr_gsm_ppp)));
|
||||
|
||||
gsm_dev = device_get_binding(GSM_MODEM_DEVICE_NAME);
|
||||
gsm_dev = DEVICE_DT_GET(DT_INST(0, zephyr_gsm_ppp));
|
||||
|
||||
LOG_INF("Board '%s' APN '%s' UART '%s' device %p (%s)",
|
||||
CONFIG_BOARD, CONFIG_MODEM_GSM_APN,
|
||||
CONFIG_MODEM_GSM_UART_NAME, uart_dev, GSM_MODEM_DEVICE_NAME);
|
||||
DT_BUS_LABEL(DT_INST(0, zephyr_gsm_ppp)), uart_dev,
|
||||
gsm_dev->name);
|
||||
|
||||
net_mgmt_init_event_callback(&mgmt_cb, event_handler,
|
||||
NET_EVENT_L4_CONNECTED |
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
&arduino_serial {
|
||||
status = "okay";
|
||||
label = "arduino_serial";
|
||||
|
||||
current-speed = <115200>;
|
||||
gsm: gsm-modem {
|
||||
compatible = "zephyr,gsm-ppp";
|
||||
label = "gsm_ppp";
|
||||
};
|
||||
};
|
||||
|
|
|
@ -15,7 +15,6 @@ CONFIG_SERIAL=y
|
|||
CONFIG_MODEM=y
|
||||
CONFIG_MODEM_SHELL=y
|
||||
CONFIG_MODEM_GSM_PPP=y
|
||||
CONFIG_MODEM_GSM_UART_NAME="arduino_serial"
|
||||
CONFIG_MODEM_GSM_APN="<Your Access Point Network>"
|
||||
|
||||
# PPP networking support
|
||||
|
|
|
@ -139,10 +139,10 @@ void main(void)
|
|||
|
||||
#elif defined(CONFIG_MODEM_GSM_PPP)
|
||||
const struct device *uart_dev =
|
||||
device_get_binding(CONFIG_MODEM_GSM_UART_NAME);
|
||||
DEVICE_DT_GET(DT_BUS(DT_INST(0, zephyr_gsm_ppp)));
|
||||
|
||||
LOG_INF("APN '%s' UART '%s' device %p", CONFIG_MODEM_GSM_APN,
|
||||
CONFIG_MODEM_GSM_UART_NAME, uart_dev);
|
||||
DT_BUS_LABEL(DT_INST(0, zephyr_gsm_ppp)), uart_dev);
|
||||
#endif
|
||||
|
||||
net_mgmt_init_event_callback(&mgmt_cb, event_handler, EVENT_MASK);
|
||||
|
|
|
@ -15,4 +15,3 @@ CONFIG_MODEM_HL7800_APN_NAME="internet"
|
|||
CONFIG_MODEM_HL7800_RAT_M1=y
|
||||
CONFIG_MODEM_WNCM14A2A=y
|
||||
CONFIG_MODEM_GSM_PPP=y
|
||||
CONFIG_MODEM_GSM_UART_NAME="TEST_UART_CTLR"
|
||||
|
|
|
@ -45,3 +45,8 @@ test_quectel_bg9x: quectel_bg9x {
|
|||
mdm-power-gpios = <&test_gpio 0 0>;
|
||||
mdm-reset-gpios = <&test_gpio 0 0>;
|
||||
};
|
||||
|
||||
test_gsm_ppp: gsm_ppp {
|
||||
compatible = "zephyr,gsm-ppp";
|
||||
label = "gsm_ppp";
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue