drivers: modem: Added simcom sim7080 modem driver.
Implemented driver for the simcom sim7080 modem. This driver features Socket offloading, TCP, UDP, DNS, SMS, GPS and FTP. Signed-off-by: Lukas Gehreke <lk.gehreke@gmail.com>
This commit is contained in:
parent
11f936c87e
commit
53dea67733
12 changed files with 2910 additions and 3 deletions
|
@ -38,3 +38,8 @@ if (CONFIG_MODEM_HL7800)
|
|||
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip)
|
||||
zephyr_library_sources(hl7800.c)
|
||||
endif()
|
||||
|
||||
if (CONFIG_MODEM_SIM7080)
|
||||
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip)
|
||||
zephyr_library_sources(simcom-sim7080.c)
|
||||
endif()
|
||||
|
|
|
@ -145,5 +145,6 @@ source "drivers/modem/Kconfig.wncm14a2a"
|
|||
source "drivers/modem/Kconfig.gsm"
|
||||
|
||||
source "drivers/modem/Kconfig.hl7800"
|
||||
source "drivers/modem/Kconfig.simcom-sim7080"
|
||||
|
||||
endif # MODEM
|
||||
|
|
73
drivers/modem/Kconfig.simcom-sim7080
Normal file
73
drivers/modem/Kconfig.simcom-sim7080
Normal file
|
@ -0,0 +1,73 @@
|
|||
# Simcom sim7080 driver options
|
||||
|
||||
# Copyright (C) 2021 metraTec GmbH
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config MODEM_SIM7080
|
||||
bool "Sim7080 Driver"
|
||||
select MODEM_CONTEXT
|
||||
select MODEM_CMD_HANDLER
|
||||
select MODEM_IFACE_UART
|
||||
select MODEM_SOCKET
|
||||
select NET_OFFLOAD
|
||||
select NET_SOCKETS_OFFLOAD
|
||||
imply GPIO
|
||||
help
|
||||
Enables the driver for the Sim7080 modem.
|
||||
|
||||
if MODEM_SIM7080
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_RX_STACK_SIZE
|
||||
int "Stack size for the simcom sim7080 modem driver rx thread"
|
||||
default 1028
|
||||
help
|
||||
This stack is used by the simcom SIM7080 RX thread.
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_RX_WORKQ_STACK_SIZE
|
||||
int "Stack size for the simcom sim7080 modem driver work queue"
|
||||
default 2048
|
||||
help
|
||||
This stack is used by the work queue.
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_INIT_PRIORITY
|
||||
int "simcom sim7080 driver init priority"
|
||||
default 80
|
||||
help
|
||||
simcom sim7080 druver initialization priority.
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_LTE_BANDS
|
||||
string "LTE bands the driver can use"
|
||||
default "8,20,28"
|
||||
help
|
||||
Comma separated list of usable lte bands.
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_APN
|
||||
string "APN for establishing a network connection"
|
||||
default "internet"
|
||||
help
|
||||
This setting is used to set the APN name for the network connection
|
||||
context. This value is specific to the network provider and may
|
||||
need to be changed.
|
||||
|
||||
choice MODEM_SIMCOM_SIM7080_RAT
|
||||
bool "Radio Access Technology Mode"
|
||||
default MODEM_SIMCOM_SIM7080_RAT_NB1
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_RAT_NB1
|
||||
bool "NB-IoT"
|
||||
help
|
||||
Enable LTE NB-IoT mode.
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_RAT_M1
|
||||
bool "Cat-M1"
|
||||
help
|
||||
Enable Cat-M1 mode.
|
||||
|
||||
config MODEM_SIMCOM_SIM7080_RAT_GSM
|
||||
bool "GSM"
|
||||
help
|
||||
Enable GSM mode.
|
||||
|
||||
endchoice
|
||||
|
||||
endif # MODEM_SIM7080
|
2384
drivers/modem/simcom-sim7080.c
Normal file
2384
drivers/modem/simcom-sim7080.c
Normal file
File diff suppressed because it is too large
Load diff
188
drivers/modem/simcom-sim7080.h
Normal file
188
drivers/modem/simcom-sim7080.h
Normal file
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* Copyright (C) 2021 metraTec GmbH
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef SIMCOM_SIM7080_H
|
||||
#define SIMCOM_SIM7080_H
|
||||
|
||||
#include <kernel.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <zephyr.h>
|
||||
#include <drivers/gpio.h>
|
||||
#include <drivers/modem/simcom-sim7080.h>
|
||||
#include <device.h>
|
||||
#include <devicetree.h>
|
||||
#include <init.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <net/net_if.h>
|
||||
#include <net/net_offload.h>
|
||||
#include <net/socket_offload.h>
|
||||
|
||||
#include "modem_context.h"
|
||||
#include "modem_cmd_handler.h"
|
||||
#include "modem_iface_uart.h"
|
||||
#include "modem_socket.h"
|
||||
|
||||
#define MDM_UART_DEV DEVICE_DT_GET(DT_INST_BUS(0))
|
||||
#define MDM_MAX_DATA_LENGTH 1024
|
||||
#define MDM_RECV_BUF_SIZE 1024
|
||||
#define MDM_MAX_SOCKETS 5
|
||||
#define MDM_BASE_SOCKET_NUM 0
|
||||
#define MDM_RECV_MAX_BUF 30
|
||||
#define BUF_ALLOC_TIMEOUT K_SECONDS(1)
|
||||
#define MDM_CMD_TIMEOUT K_SECONDS(10)
|
||||
#define MDM_REGISTRATION_TIMEOUT K_SECONDS(180)
|
||||
#define MDM_CONNECT_TIMEOUT K_SECONDS(90)
|
||||
#define MDM_PDP_TIMEOUT K_SECONDS(120)
|
||||
#define MDM_DNS_TIMEOUT K_SECONDS(210)
|
||||
#define MDM_WAIT_FOR_RSSI_DELAY K_SECONDS(2)
|
||||
#define MDM_WAIT_FOR_RSSI_COUNT 30
|
||||
#define MDM_MAX_AUTOBAUD 5
|
||||
#define MDM_MAX_CEREG_WAITS 40
|
||||
#define MDM_MAX_CGATT_WAITS 40
|
||||
#define MDM_BOOT_TRIES 4
|
||||
#define MDM_GNSS_PARSER_MAX_LEN 128
|
||||
#define MDM_APN CONFIG_MODEM_SIMCOM_SIM7080_APN
|
||||
#define MDM_LTE_BANDS CONFIG_MODEM_SIMCOM_SIM7080_LTE_BANDS
|
||||
#define RSSI_TIMEOUT_SECS 30
|
||||
#define MDM_SOCKET_PRIO 40
|
||||
|
||||
/*
|
||||
* Default length of modem data.
|
||||
*/
|
||||
#define MDM_MANUFACTURER_LENGTH 12
|
||||
#define MDM_MODEL_LENGTH 16
|
||||
#define MDM_REVISION_LENGTH 64
|
||||
#define MDM_IMEI_LENGTH 16
|
||||
#define MDM_IMSI_LENGTH 16
|
||||
#define MDM_ICCID_LENGTH 32
|
||||
|
||||
enum sim7080_state {
|
||||
SIM7080_STATE_INIT = 0,
|
||||
SIM7080_STATE_NETWORKING,
|
||||
SIM7080_STATE_GNSS,
|
||||
SIM7080_STATE_OFF,
|
||||
};
|
||||
|
||||
/* Possible states of the ftp connection. */
|
||||
enum sim7080_ftp_connection_state {
|
||||
/* Not connected yet. */
|
||||
SIM7080_FTP_CONNECTION_STATE_INITIAL = 0,
|
||||
/* Connected and still data available. */
|
||||
SIM7080_FTP_CONNECTION_STATE_CONNECTED,
|
||||
/* All data transferred. */
|
||||
SIM7080_FTP_CONNECTION_STATE_FINISHED,
|
||||
/* Something went wrong. */
|
||||
SIM7080_FTP_CONNECTION_STATE_ERROR,
|
||||
};
|
||||
|
||||
/*
|
||||
* Driver data.
|
||||
*/
|
||||
struct sim7080_data {
|
||||
/*
|
||||
* Network interface of the sim module.
|
||||
*/
|
||||
struct net_if *netif;
|
||||
uint8_t mac_addr[6];
|
||||
/*
|
||||
* Uart interface of the modem.
|
||||
*/
|
||||
struct modem_iface_uart_data iface_data;
|
||||
uint8_t iface_rb_buf[MDM_MAX_DATA_LENGTH];
|
||||
/*
|
||||
* Modem command handler.
|
||||
*/
|
||||
struct modem_cmd_handler_data cmd_handler_data;
|
||||
uint8_t cmd_match_buf[MDM_RECV_BUF_SIZE + 1];
|
||||
/*
|
||||
* Modem socket data.
|
||||
*/
|
||||
struct modem_socket_config socket_config;
|
||||
struct modem_socket sockets[MDM_MAX_SOCKETS];
|
||||
/*
|
||||
* Current state of the modem.
|
||||
*/
|
||||
enum sim7080_state state;
|
||||
/*
|
||||
* RSSI work
|
||||
*/
|
||||
struct k_work_delayable rssi_query_work;
|
||||
/*
|
||||
* Information over the modem.
|
||||
*/
|
||||
char mdm_manufacturer[MDM_MANUFACTURER_LENGTH];
|
||||
char mdm_model[MDM_MODEL_LENGTH];
|
||||
char mdm_revision[MDM_REVISION_LENGTH];
|
||||
char mdm_imei[MDM_IMEI_LENGTH];
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
char mdm_imsi[MDM_IMSI_LENGTH];
|
||||
char mdm_iccid[MDM_ICCID_LENGTH];
|
||||
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
||||
int mdm_rssi;
|
||||
/*
|
||||
* Current operating socket and statistics.
|
||||
*/
|
||||
int current_sock_fd;
|
||||
int current_sock_written;
|
||||
/*
|
||||
* Network registration of the modem.
|
||||
*/
|
||||
uint8_t mdm_registration;
|
||||
/*
|
||||
* Whether gprs is attached or detached.
|
||||
*/
|
||||
uint8_t mdm_cgatt;
|
||||
/*
|
||||
* If the sim card is ready or not.
|
||||
*/
|
||||
bool cpin_ready;
|
||||
/*
|
||||
* Flag if the PDP context is active.
|
||||
*/
|
||||
bool pdp_active;
|
||||
/* SMS buffer structure provided by read. */
|
||||
struct sim7080_sms_buffer *sms_buffer;
|
||||
/* Position in the sms buffer. */
|
||||
uint8_t sms_buffer_pos;
|
||||
/* Ftp related variables. */
|
||||
struct {
|
||||
/* User buffer for ftp data. */
|
||||
char *read_buffer;
|
||||
/* Length of the read buffer/number of bytes read. */
|
||||
size_t nread;
|
||||
/* State of the ftp connection. */
|
||||
enum sim7080_ftp_connection_state state;
|
||||
} ftp;
|
||||
/*
|
||||
* Semaphore(s).
|
||||
*/
|
||||
struct k_sem sem_response;
|
||||
struct k_sem sem_tx_ready;
|
||||
struct k_sem sem_dns;
|
||||
struct k_sem sem_ftp;
|
||||
};
|
||||
|
||||
/*
|
||||
* Pin definitions
|
||||
*/
|
||||
static struct modem_pin modem_pins[] = { MODEM_PIN(
|
||||
DT_INST_GPIO_LABEL(0, mdm_power_gpios), DT_INST_GPIO_PIN(0, mdm_power_gpios),
|
||||
DT_INST_GPIO_FLAGS(0, mdm_power_gpios) | GPIO_OUTPUT_LOW) };
|
||||
|
||||
/*
|
||||
* Socket read callback data.
|
||||
*/
|
||||
struct socket_read_data {
|
||||
char *recv_buf;
|
||||
size_t recv_buf_len;
|
||||
struct sockaddr *recv_addr;
|
||||
uint16_t recv_read_len;
|
||||
};
|
||||
|
||||
#endif /* SIMCOM_SIM7080_H */
|
Loading…
Add table
Add a link
Reference in a new issue