zephyr/drivers
Michael Scott 02abddccd6 drivers: modem: cmd handler: introduce cmd handler driver layer
This is a generic command handler implementation which uses the
supplied modem interface to process incoming data and hand it
back to the modem driver via callbacks defined for:
- modem responses
- unsolicited messages
- specified handlers for current operation

The individual modem drivers define functions as command handlers
via the MODEM_CMD_DEFINE() macro.

To use these handlers, a modem operation defines a series of
modem_cmd structures and passes them to the modem_cmd_send()
function.  The modem_cmd includes data for:
- a matching string for when to execute the handler
- # of parameters to parse after the matching string
- delimeters for the parameters

Example modem driver setup code looks like this:

/* create modem context object */
static struct modem_context mctx;

/* net_buf receive pool */
NET_BUF_POOL_DEFINE(mdm_recv_pool, MDM_RECV_MAX_BUF,
		    MDM_RECV_BUF_SIZE, 0, NULL);

/* modem cmds */
static struct modem_cmd_handler_data cmd_handler_data;
static u8_t cmd_read_buf[MDM_RECV_BUF_SIZE];
static u8_t cmd_match_buf[MDM_RECV_BUF_SIZE];

/* modem response handlers */
static struct modem_cmd response_cmds[] = {
	MODEM_CMD("OK", on_cmd_ok, 0U, ""),
	MODEM_CMD("ERROR", on_cmd_error, 0U, ""),
	MODEM_CMD("+CME ERROR: ", on_cmd_exterror, 1U, ""),
};

/* unsolicited handlers */
static struct modem_cmd unsol_cmds[] = {
	MODEM_CMD("+UUSOCL: ", on_cmd_socknotifyclose, 1U, ""),
	MODEM_CMD("+UUSORD: ", on_cmd_socknotifydata, 2U, ","),
	MODEM_CMD("+UUSORF: ", on_cmd_socknotifydata, 2U, ","),
	MODEM_CMD("+CREG: ", on_cmd_socknotifycreg, 1U, ""),
};

/* setup cmd handler data */
cmd_handler_data.cmds[CMD_RESP] = response_cmds;
cmd_handler_data.cmds_len[CMD_RESP] = ARRAY_SIZE(response_cmds);
cmd_handler_data.cmds[CMD_UNSOL] = unsol_cmds;
cmd_handler_data.cmds_len[CMD_UNSOL] = ARRAY_SIZE(unsol_cmds);
cmd_handler_data.read_buf = &cmd_read_buf[0];
cmd_handler_data.read_buf_len = sizeof(cmd_read_buf);
cmd_handler_data.match_buf = &cmd_match_buf[0];
cmd_handler_data.match_buf_len = sizeof(cmd_match_buf);
cmd_handler_data.buf_pool = &mdm_recv_pool;
cmd_handler_data.alloc_timeout = BUF_ALLOC_TIMEOUT;
ret = modem_cmd_handler_init(&mctx.cmd_handler, &cmd_handler_data);

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-10 00:03:39 +02:00
..
adc drivers/adc: provide API to access reference voltage 2019-08-01 13:28:41 +02:00
audio cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
bluetooth Bluetooth: drivers: ipm_st32wb: Fix compilation 2019-07-09 21:35:44 +03:00
can net: l2: canbus: Add support for canbus Ethernet translator 2019-08-08 13:25:01 +03:00
clock_control drivers: clock_control: mcux_mcg: add driver for NXP Kinetis MCG 2019-08-09 07:32:43 -05:00
console drivers: ipm_console: increase coverage stack size 2019-07-04 07:25:44 -04:00
counter dts: Make instance defines consistent 2019-07-30 17:10:31 -05:00
crypto cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
display display: Add support for an ST7789V based LCD 2019-08-08 10:11:47 -05:00
dma boards: remove quarl_se_c1000 2019-07-29 21:30:25 -07:00
entropy drivers: entropy: nrf5: Fix dependency of the enabling Kconfig option 2019-08-09 20:14:24 +02:00
espi drivers: espi: kconfig: Remove redundant ESPI_PERIPHERAL_CHANNEL deps. 2019-08-07 04:27:03 -04:00
ethernet net: l2: canbus: Add support for canbus Ethernet translator 2019-08-08 13:25:01 +03:00
flash drivers: flash: Remove redundant FLASH dep. from FLASH_NATIVE_POSIX 2019-08-07 04:26:48 -04:00
gpio riscv: freedom: rename RISCV32 to RISCV 2019-08-08 00:29:24 -04:00
hwinfo cleanup: include/: move misc/printk.h to sys/printk.h 2019-06-27 22:55:49 -04:00
i2c riscv: freedom: rename RISCV32 to RISCV 2019-08-08 00:29:24 -04:00
i2s cleanup: include/: move misc/__assert.h to sys/__assert.h 2019-06-27 22:55:49 -04:00
ieee802154 soc: nordic: Add HAS_HW_NRF_RADIO_IEEE802154 Kconfig option 2019-07-31 16:09:30 +03:00
interrupt_controller interrupt_controller: gic: Add support for the GIC400 2019-08-09 22:50:50 +02:00
ipm boards: remove quarl_se_c1000 2019-07-29 21:30:25 -07:00
led dts: Make instance defines consistent 2019-07-30 17:10:31 -05:00
led_strip dts: Make instance defines consistent 2019-07-30 17:10:31 -05:00
modem drivers: modem: cmd handler: introduce cmd handler driver layer 2019-08-10 00:03:39 +02:00
net tests: net: ppp: Add unit tests for PPP driver 2019-07-29 10:24:46 +03:00
neural_net cleanup: include/: move gna.h to drivers/gna.h 2019-06-27 22:55:49 -04:00
pci cleanup: include/: move misc/printk.h to sys/printk.h 2019-06-27 22:55:49 -04:00
pcie drivers/pcie/shell: add basic probe for MSI-X capability 2019-06-10 10:52:02 -04:00
pinmux riscv: freedom: rename RISCV32 to RISCV 2019-08-08 00:29:24 -04:00
ptp_clock net: ptp: clock: Add usermode support to ptp_clock_get() 2019-06-25 15:22:51 +03:00
pwm drivers: pwm: mcux_ftm: use device tree for obtaining clock frequency 2019-08-09 07:32:43 -05:00
rtc cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
sensor drivers: sensors: Add Si7006 temperature/humidity sensor driver 2019-08-06 15:05:25 -05:00
serial serial: Add Xilinx ZynqMP PS uart driver 2019-08-09 22:50:50 +02:00
spi riscv: freedom: rename RISCV32 to RISCV 2019-08-08 00:29:24 -04:00
timer timer: Add Xilinx ZynqMP PS ttc timer 2019-08-09 22:50:50 +02:00
usb boards: remove quarl_se_c1000 2019-07-29 21:30:25 -07:00
watchdog drivers: wdog_cmsdk_apb: Get clock frequency from DTS 2019-07-24 15:10:02 +02:00
wifi net: Move include files outside of extern "C" block 2019-08-06 14:46:36 +03:00
CMakeLists.txt boards: remove quarl_se_c1000 2019-07-29 21:30:25 -07:00
Kconfig boards: remove quarl_se_c1000 2019-07-29 21:30:25 -07:00