Skip to content

Commit 94cdfc5

Browse files
Deomid Ryabkovcesantabot
authored andcommitted
Add DTR control
CL: pppos: Add DTR control PUBLISHED_FROM=36824ab7646b47016daa480b768dfb9a34819c36
1 parent 7abaee6 commit 94cdfc5

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

mos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ config_schema:
1515
- ["pppos.tx_gpio", "i", -1, {title: "TX pin; -1 = use default"}]
1616
- ["pppos.cts_gpio", "i", -1, {title: "CTS pin; -1 = use default"}]
1717
- ["pppos.rts_gpio", "i", -1, {title: "RTS pin; -1 = use default"}]
18+
- ["pppos.dtr_gpio", "i", -1, {title: "DTR pin; -1 - do not use, if set will be driven to active state"}]
19+
- ["pppos.dtr_act", "i", 0, {title: "Active state for the DTR pin"}]
1820
# These depend on the operator and are usually well known.
1921
- ["pppos.apn", "s", "", {title: "APN name"}]
2022
- ["pppos.user", "s", "", {title: "User name"}]

src/mgos_pppos.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "mgos_uart.h"
4141
#include "mgos_utils.h"
4242

43-
#define AT_CMD_TIMEOUT 3.0
43+
#define AT_CMD_TIMEOUT 2.0
4444

4545
enum mgos_pppos_state {
4646
PPPOS_IDLE = 0,
@@ -123,8 +123,8 @@ static void mgos_pppos_try_baud_rate(struct mgos_pppos_data *pd) {
123123
ucfg.rx_fc_type = ucfg.tx_fc_type = MGOS_UART_FC_HW;
124124
}
125125
}
126-
LOG(LL_INFO, ("Trying baud rate %d (fc %s)...", ucfg.baud_rate,
127-
(ucfg.rx_fc_type != MGOS_UART_FC_NONE ? "on" : "off")));
126+
LOG(LL_DEBUG, ("Trying baud rate %d (fc %s)...", ucfg.baud_rate,
127+
(ucfg.rx_fc_type != MGOS_UART_FC_NONE ? "on" : "off")));
128128
mgos_uart_configure(pd->cfg->uart_no, &ucfg);
129129
mgos_uart_set_rx_enabled(pd->cfg->uart_no, true);
130130
pd->try_baud_idx++;
@@ -449,6 +449,9 @@ static void mgos_pppos_dispatch_once(struct mgos_pppos_data *pd) {
449449
mgos_clear_timer(pd->poll_timer_id);
450450
pd->poll_timer_id = MGOS_INVALID_TIMER_ID;
451451
}
452+
if (pd->cfg->dtr_gpio >= 0) {
453+
mgos_gpio_write(pd->cfg->dtr_gpio, !pd->cfg->dtr_act);
454+
}
452455
mgos_pppos_set_net_status(pd, MGOS_NET_EV_DISCONNECTED);
453456
break;
454457
}
@@ -477,6 +480,9 @@ static void mgos_pppos_dispatch_once(struct mgos_pppos_data *pd) {
477480
pd->poll_timer_id = mgos_set_timer(100, MGOS_TIMER_REPEAT,
478481
mgos_pppos_poll_timer_cb, pd);
479482
}
483+
if (pd->cfg->dtr_gpio >= 0) {
484+
mgos_gpio_write(pd->cfg->dtr_gpio, !pd->cfg->dtr_act);
485+
}
480486
if (pd->cfg->rst_gpio >= 0 &&
481487
(pd->attempt == 1 || pd->cfg->rst_mode == 1)) {
482488
pd->baud_ok = false;
@@ -499,6 +505,9 @@ static void mgos_pppos_dispatch_once(struct mgos_pppos_data *pd) {
499505
case PPPOS_RESET_HOLD: {
500506
const double now = mgos_uptime();
501507
if (now < pd->deadline) break;
508+
if (pd->cfg->dtr_gpio >= 0) {
509+
mgos_gpio_write(pd->cfg->dtr_gpio, pd->cfg->dtr_act);
510+
}
502511
mgos_gpio_write(pd->cfg->rst_gpio, !pd->cfg->rst_act);
503512
pd->deadline = now + (pd->cfg->rst_wait_ms / 1000.0);
504513
mgos_pppos_set_state(pd, PPPOS_RESET_WAIT);
@@ -517,7 +526,10 @@ static void mgos_pppos_dispatch_once(struct mgos_pppos_data *pd) {
517526
if (pd->deadline == 0) {
518527
/* Initial 1s pause before sending +++ */
519528
pd->deadline = now + 1.2;
520-
} else if (now > pd->deadline) {
529+
} else if (now >= pd->deadline) {
530+
if (pd->cfg->dtr_gpio >= 0) {
531+
mgos_gpio_write(pd->cfg->dtr_gpio, pd->cfg->dtr_act);
532+
}
521533
mgos_pppos_set_state(pd, PPPOS_BEGIN);
522534
pd->deadline = 0;
523535
}
@@ -542,13 +554,15 @@ static void mgos_pppos_dispatch_once(struct mgos_pppos_data *pd) {
542554

543555
case PPPOS_SETUP: {
544556
const char *apn = pd->cfg->apn;
557+
if (pd->cfg->dtr_gpio >= 0) {
558+
mgos_gpio_write(pd->cfg->dtr_gpio, pd->cfg->dtr_act);
559+
}
545560
mgos_pppos_set_net_status(pd, MGOS_NET_EV_CONNECTING);
546561
LOG(LL_INFO, ("Connecting (UART%d, APN '%s')...", pd->cfg->uart_no,
547562
(apn ? apn : "")));
548563
mbuf_remove(&pd->data, pd->data.len);
549564
add_cmd(pd, mgos_pppos_at_cb, "AT");
550565
add_cmd(pd, NULL, "ATH");
551-
add_cmd(pd, NULL, "ATZ");
552566
add_cmd(pd, NULL, "ATE0");
553567
add_cmd(pd, mgos_pppos_ati_cb, "ATI");
554568
if (!pd->baud_ok) {
@@ -870,7 +884,7 @@ bool mgos_pppos_create(const struct mgos_config_pppos *cfg, int if_instance) {
870884
cfg->uart_no, mgos_gpio_str(ucfg.dev.rx_gpio, b1),
871885
mgos_gpio_str(ucfg.dev.tx_gpio, b2),
872886
mgos_gpio_str(ucfg.dev.cts_gpio, b3),
873-
mgos_gpio_str(ucfg.dev.rts_gpio, b4), ucfg.baud_rate,
887+
mgos_gpio_str(ucfg.dev.rts_gpio, b4), cfg->baud_rate,
874888
cfg->fc_enable ? "on" : "off", (cfg->apn ? cfg->apn : "")));
875889
#else
876890
#if CS_PLATFORM == CS_P_STM32
@@ -891,7 +905,7 @@ bool mgos_pppos_create(const struct mgos_config_pppos *cfg, int if_instance) {
891905
cfg->uart_no, mgos_gpio_str(ucfg.dev.pins.rx, b1),
892906
mgos_gpio_str(ucfg.dev.pins.tx, b2),
893907
mgos_gpio_str(ucfg.dev.pins.cts, b3),
894-
mgos_gpio_str(ucfg.dev.pins.rts, b4), ucfg.baud_rate,
908+
mgos_gpio_str(ucfg.dev.pins.rts, b4), cfg->baud_rate,
895909
cfg->fc_enable ? "on" : "off", (cfg->apn ? cfg->apn : "")));
896910
(void) b1;
897911
(void) b2;
@@ -906,7 +920,7 @@ bool mgos_pppos_create(const struct mgos_config_pppos *cfg, int if_instance) {
906920
return false;
907921
}
908922
LOG(LL_INFO,
909-
("PPPoS UART%d %d, fc %s, APN '%s'", cfg->uart_no, ucfg.baud_rate,
923+
("PPPoS UART%d %d, fc %s, APN '%s'", cfg->uart_no, cfg->baud_rate,
910924
cfg->fc_enable ? "on" : "off", (cfg->apn ? cfg->apn : "")));
911925
#endif
912926
#endif
@@ -919,6 +933,9 @@ bool mgos_pppos_create(const struct mgos_config_pppos *cfg, int if_instance) {
919933
pd->cfg = cfg;
920934
pd->if_instance = if_instance;
921935
pd->state = PPPOS_IDLE;
936+
if (pd->cfg->dtr_gpio >= 0) {
937+
mgos_gpio_setup_output(pd->cfg->dtr_gpio, !pd->cfg->dtr_act);
938+
}
922939
SLIST_INSERT_HEAD(&s_pds, pd, next);
923940
mgos_uart_set_dispatcher(cfg->uart_no, mgos_pppos_uart_dispatcher, pd);
924941
mgos_uart_set_rx_enabled(cfg->uart_no, true);

0 commit comments

Comments
 (0)