Skip to content

Commit 5a48ddf

Browse files
committed
app: Implement AT+IFC command handling
Adds the ability to turn hardware flow control on and off at runtime. Signed-off-by: Mariano Goluboff <mariano.goluboff@nordicsemi.no>
1 parent f8d857d commit 5a48ddf

3 files changed

Lines changed: 171 additions & 1 deletion

File tree

app/src/sm_at_commands.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ STATIC int handle_at_clac(enum at_parser_cmd_type cmd_type, struct at_parser *,
271271
* * AT+IPR
272272
* * AT+CMUX
273273
* * AT+CGDATA
274+
* * AT+IFC
274275
*/
275276
if ((strncasecmp(cmd, "AT+", strlen("AT+")) == 0 &&
276277
strncasecmp(cmd, "AT+IPR", strlen("AT+IPR")) != 0 &&
277278
strncasecmp(cmd, "AT+CMUX", strlen("AT+CMUX")) != 0 &&
278-
strncasecmp(cmd, "AT+CGDATA", strlen("AT+CGDATA")) != 0) ||
279+
strncasecmp(cmd, "AT+CGDATA", strlen("AT+CGDATA")) != 0 &&
280+
strncasecmp(cmd, "AT+IFC", strlen("AT+IFC")) != 0) ||
279281
strncasecmp(cmd, "AT%%", strlen("AT%%")) == 0) {
280282
continue;
281283
}

app/src/sm_uart_handler.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,71 @@ static int handle_at_ipr(enum at_parser_cmd_type cmd_type, struct at_parser *par
653653

654654
return -SILENT_AT_COMMAND_RET;
655655
}
656+
SM_AT_CMD_CUSTOM(ifc, "AT+IFC", handle_at_ifc);
657+
static int handle_at_ifc(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
658+
uint32_t param_count)
659+
{
660+
int err;
661+
struct uart_config cfg;
662+
uint16_t flow_ctrl;
663+
664+
err = uart_config_get(sm_uart_dev, &cfg);
665+
if (err) {
666+
LOG_ERR("uart_config_get: %d", err);
667+
return err;
668+
}
669+
670+
if (cmd_type == AT_PARSER_CMD_TYPE_READ) {
671+
rsp_send("\r\n+IFC: %u\r\n", cfg.flow_ctrl & UART_CFG_FLOW_CTRL_RTS_CTS ? 2 : 0);
672+
return 0;
673+
}
674+
675+
if (cmd_type == AT_PARSER_CMD_TYPE_TEST) {
676+
rsp_send("\r\n+IFC: (0,2)\r\n");
677+
return 0;
678+
}
679+
680+
if (cmd_type != AT_PARSER_CMD_TYPE_SET || param_count != 2) {
681+
return -EINVAL;
682+
}
683+
684+
if (sm_cmux_is_started()) {
685+
LOG_ERR("Cannot change flow control while CMUX is active.");
686+
return -EBUSY;
687+
}
688+
689+
err = at_parser_num_get(parser, 1, &flow_ctrl);
690+
if (err) {
691+
return err;
692+
}
693+
694+
/* Convert standard AT values of 0 and 2 to the right definition */
695+
if (flow_ctrl == 0) {
696+
cfg.flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
697+
} else if (flow_ctrl == 2) {
698+
cfg.flow_ctrl = UART_CFG_FLOW_CTRL_RTS_CTS;
699+
} else {
700+
LOG_ERR("Unsupported flow control: %u", flow_ctrl);
701+
return -EINVAL;
702+
}
703+
704+
rsp_send_ok();
705+
706+
err = modem_pipe_close(&sm_pipe.pipe, K_SECONDS(1));
707+
if (err) {
708+
LOG_ERR("modem_pipe_close: %d", err);
709+
return err;
710+
}
711+
err = uart_configure(sm_uart_dev, &cfg);
712+
if (err) {
713+
LOG_ERR("uart_configure: %d", err);
714+
return err;
715+
}
716+
err = modem_pipe_open(&sm_pipe.pipe, K_SECONDS(1));
717+
if (err) {
718+
LOG_ERR("modem_pipe_open: %d", err);
719+
return err;
720+
}
721+
722+
return -SILENT_AT_COMMAND_RET;
723+
}

doc/app/at_generic.rst

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,106 @@ Example
101101
+IPR: (),(115200,230400,460800,921600,1000000)
102102
OK
103103

104+
|SM| UART flow control AT+IFC
105+
============================
106+
107+
The ``AT+IFC`` command sets the UART flow control.
108+
109+
Set command
110+
-----------
111+
112+
The set command sets the UART flow control.
113+
114+
Syntax
115+
~~~~~~
116+
117+
::
118+
119+
AT+IFC=<flow_control>
120+
The ``<flow_control>`` parameter is an integer value specifying the desired flow control:
121+
122+
- 0: Disable flow control
123+
- 2: Enable RTS/CTS flow control
124+
125+
.. note::
126+
127+
The flow control change takes effect after the modem responds with ``OK``.
128+
The host must switch to the new flow control settings to continue communication.
129+
130+
Example
131+
~~~~~~~
132+
133+
Disable flow control.
134+
135+
::
136+
137+
AT+IFC=0
138+
OK
139+
140+
Enable RTS/CTS flow control.
141+
142+
::
143+
144+
AT+IFC=2
145+
OK
146+
147+
Read command
148+
------------
149+
150+
The read command reads the current UART flow control.
151+
152+
Syntax
153+
~~~~~~
154+
155+
::
156+
157+
AT+IFC?
158+
159+
Response syntax
160+
~~~~~~~~~~~~~~~
161+
162+
::
163+
164+
+IFC: <flow_control>
165+
166+
Example
167+
~~~~~~~
168+
169+
::
170+
171+
AT+IFC?
172+
+IFC: 0
173+
OK
174+
175+
Test command
176+
------------
177+
178+
The test command lists the supported flow control modes.
179+
180+
Syntax
181+
~~~~~~
182+
183+
::
184+
185+
AT+IFC=?
186+
187+
Response syntax
188+
~~~~~~~~~~~~~~~
189+
190+
::
191+
192+
+IFC: (list of supported flow control modes)
193+
194+
Example
195+
~~~~~~~
196+
197+
::
198+
199+
AT+IFC=?
200+
+IFC: (0,2)
201+
OK
202+
203+
104204
|SM| echo E0/E1
105205
===============
106206

0 commit comments

Comments
 (0)