Skip to content

Commit b93cd7b

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 b93cd7b

3 files changed

Lines changed: 172 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: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,107 @@ 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+
121+
The ``<flow_control>`` parameter is an integer value specifying the desired flow control:
122+
123+
- 0: Disable flow control
124+
- 2: Enable RTS/CTS flow control
125+
126+
.. note::
127+
128+
The flow control change takes effect after the modem responds with ``OK``.
129+
The host must switch to the new flow control settings to continue communication.
130+
131+
Example
132+
~~~~~~~
133+
134+
Disable flow control.
135+
136+
::
137+
138+
AT+IFC=0
139+
OK
140+
141+
Enable RTS/CTS flow control.
142+
143+
::
144+
145+
AT+IFC=2
146+
OK
147+
148+
Read command
149+
------------
150+
151+
The read command reads the current UART flow control.
152+
153+
Syntax
154+
~~~~~~
155+
156+
::
157+
158+
AT+IFC?
159+
160+
Response syntax
161+
~~~~~~~~~~~~~~~
162+
163+
::
164+
165+
+IFC: <flow_control>
166+
167+
Example
168+
~~~~~~~
169+
170+
::
171+
172+
AT+IFC?
173+
+IFC: 0
174+
OK
175+
176+
Test command
177+
------------
178+
179+
The test command lists the supported flow control modes.
180+
181+
Syntax
182+
~~~~~~
183+
184+
::
185+
186+
AT+IFC=?
187+
188+
Response syntax
189+
~~~~~~~~~~~~~~~
190+
191+
::
192+
193+
+IFC: (list of supported flow control modes)
194+
195+
Example
196+
~~~~~~~
197+
198+
::
199+
200+
AT+IFC=?
201+
+IFC: (0,2)
202+
OK
203+
204+
104205
|SM| echo E0/E1
105206
===============
106207

0 commit comments

Comments
 (0)