MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / config_comm

Function config_comm

examples/libc/termios_test.c:87–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void config_comm(int fd, int speed_baud_rate, char parity, int data_bits, int stop_bits)
88{
89 int valid_baud_rate = 0;
90 struct termios new_tc;
91
92 memset(&new_tc, 0x00, sizeof(struct termios));
93
94 valid_baud_rate = _check_baud_rate(speed_baud_rate);
95
96 new_tc.c_cflag |= (CLOCAL | CREAD);//Enable in default.
97
98 /*
99 *Set baud rate. e.g B115200 is 115200 bauds.
100 */
101 cfsetispeed(&new_tc, valid_baud_rate);//input speed
102 cfsetospeed(&new_tc, valid_baud_rate);//output speed
103
104 /*
105 *Set parity.
106 */
107 switch(parity)
108 {
109 case 'n':
110 case 'N':
111 new_tc.c_cflag &= ~PARENB; //Disable parity.
112 break;
113 case 'o':
114 case 'O':
115 new_tc.c_cflag |= PARENB; //Enable parity.
116 new_tc.c_cflag |= PARODD; //Odd parity.
117 break;
118 case 'e':
119 case 'E':
120 new_tc.c_cflag |= PARENB; //Enable parity.
121 new_tc.c_cflag &= ~PARODD; //even parity.
122 break;
123 }
124
125 /*
126 *Set data bits.
127 */
128 new_tc.c_cflag &= ~CSIZE;
129 switch(data_bits)
130 {
131 case 5:
132 break;
133 case 6:
134 break;
135 case 7:
136 new_tc.c_cflag |= CS7;
137 break;
138 case 8:
139 new_tc.c_cflag |= CS8;
140 break;
141 }
142
143 /*
144 *Set stop bits.

Callers 1

termios_test_entryFunction · 0.85

Calls 6

_check_baud_rateFunction · 0.85
cfsetispeedFunction · 0.85
cfsetospeedFunction · 0.85
tcflushFunction · 0.85
tcsetattrFunction · 0.85
rt_kprintfFunction · 0.85

Tested by

no test coverage detected