diff --git a/system/zmodem/Kconfig b/system/zmodem/Kconfig index 2bf41ce26..f603df2da 100644 --- a/system/zmodem/Kconfig +++ b/system/zmodem/Kconfig @@ -65,6 +65,26 @@ config SYSTEM_ZMODEM_MOUNTPOINT Names of file send by the sz commond, on the other hand, must be absolute paths beginning with '/'. +config SYSTEM_ZMODEM_FLOWC + bool + default n + +config SYSTEM_ZMODEM_IFLOW + bool "Rx flow control" + default n + select SYSTEM_ZMODEM_FLOWC + depends on SERIAL_TERMIOS + ---help--- + Enable H/W CTS flow control. + +config SYSTEM_ZMODEM_OFLOW + bool "Tx flow control" + default n + select SYSTEM_ZMODEM_FLOWC + depends on SERIAL_TERMIOS + ---help--- + Enable H/W RTS flow control. + config SYSTEM_ZMODEM_RCVSAMPLE bool "Reverse channel" default n diff --git a/system/zmodem/rz_main.c b/system/zmodem/rz_main.c index f1109fc4c..08f73dbc8 100644 --- a/system/zmodem/rz_main.c +++ b/system/zmodem/rz_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * system/zmodem/rz_main.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -127,6 +127,12 @@ int rz_main(int argc, FAR char **argv) goto errout; } +#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC + /* Enable hardware Rx/Tx flow control */ + + zm_flowc(fd); +#endif + /* Get the Zmodem handle */ handle = zmr_initialize(fd); diff --git a/system/zmodem/sz_main.c b/system/zmodem/sz_main.c index 372322ec1..1413e9c66 100644 --- a/system/zmodem/sz_main.c +++ b/system/zmodem/sz_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * system/zmodem/sz_main.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -186,6 +186,12 @@ int sz_main(int argc, FAR char **argv) goto errout; } +#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC + /* Enable hardware Rx/Tx flow control */ + + zm_flowc(fd); +#endif + /* Get the Zmodem handle */ handle = zms_initialize(fd); diff --git a/system/zmodem/zm.h b/system/zmodem/zm.h index 297c4eefd..76bacbe38 100644 --- a/system/zmodem/zm.h +++ b/system/zmodem/zm.h @@ -1,7 +1,7 @@ /**************************************************************************** * apps/system/zmodem/zm.h * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -577,6 +577,18 @@ int zm_writefile(int fd, FAR const uint8_t *buffer, size_t buflen, bool zcnl); uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename); +/**************************************************************************** + * Name: zm_flowc + * + * Description: + * Enable hardware Rx/Tx flow control + * + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC +void zm_flowc(int fd); +#endif + /**************************************************************************** * Name: zm_putzdle * diff --git a/system/zmodem/zm_utils.c b/system/zmodem/zm_utils.c index 17f21844b..c0a3ee2ea 100644 --- a/system/zmodem/zm_utils.c +++ b/system/zmodem/zm_utils.c @@ -1,7 +1,7 @@ /**************************************************************************** * system/zmodem/zm_utils.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -430,7 +431,7 @@ int zm_writefile(int fd, FAR const uint8_t *buffer, size_t buflen, bool zcnl) return ret; } -/************************************************************************************************ +/**************************************************************************** * Name: zm_filecrc * * Description: @@ -439,7 +440,7 @@ int zm_writefile(int fd, FAR const uint8_t *buffer, size_t buflen, bool zcnl) * Assumptions: * The allocated I/O buffer is available to buffer file data. * - ************************************************************************************************/ + ****************************************************************************/ uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename) { @@ -471,3 +472,62 @@ uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename) close(fd); return ~crc; } + +/**************************************************************************** + * Name: zm_flowc + * + * Description: + * Enable hardware Rx/Tx flow control + * + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC +void zm_flowc(int fd) +{ + struct termios term; + + /* Get the termios */ + + tcgetattr(fd, &term); + +#ifdef CONFIG_SYSTEM_ZMODEM_IFLOW + /* Set input flow control */ + +#ifdef CRTS_IFLOW + term.c_cflag |= CRTS_IFLOW; +#else + term.c_cflag |= CRTSCTS; +#endif +#else /* CONFIG_SYSTEM_ZMODEM_IFLOW */ + /* Clear input flow control */ + +#ifdef CRTS_IFLOW + term.c_cflag &= ~CRTS_IFLOW; +#else + term.c_cflag &= ~CRTSCTS; +#endif +#endif /* CONFIG_SYSTEM_ZMODEM_IFLOW */ + +#ifdef CONFIG_SYSTEM_ZMODEM_OFLOW + /* Set output flow control */ + +#ifdef CCTS_OFLOW + term.c_cflag |= CCTS_OFLOW; +#else + term.c_cflag |= CRTSCTS; +#endif +#else /* CONFIG_SYSTEM_ZMODEM_OFLOW */ + /* Clear output flow control */ + +#ifdef CCTS_OFLOW + term.c_cflag &= ~CCTS_OFLOW; +#else + term.c_cflag &= ~CRTSCTS; +#endif +#endif /* CONFIG_SYSTEM_ZMODEM_OFLOW */ + + /* Save the modified termios */ + + tcsetattr(fd, TCSANOW, &term); +} +#endif