Skip to content

Instantly share code, notes, and snippets.

@allsey87
Created July 24, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allsey87/5a3554d4c08f47b344c1c1e721cd80d4 to your computer and use it in GitHub Desktop.
Save allsey87/5a3554d4c08f47b344c1c1e721cd80d4 to your computer and use it in GitHub Desktop.
Print the configuration of a serial port from the Linux kernel in stty -g style
static void dump_ktermios(struct device* dev, struct ktermios* ktermios, const char* func) {
char buf[128];
unsigned int idx = 0;
size_t i = 0;
idx += snprintf(buf + idx, 128 - idx, "%lx:%lx:%lx:%lx",
(unsigned long int) ktermios->c_iflag,
(unsigned long int) ktermios->c_oflag,
(unsigned long int) ktermios->c_cflag,
(unsigned long int) ktermios->c_lflag);
for(i = 0; i < NCCS; ++i)
idx += snprintf(buf + idx, 128 - idx, ":%lx", (unsigned long int) ktermios->c_cc[i]);
dev_info(dev, "%s: %s", func, buf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment