@@ -640,6 +640,11 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
640640 /* get open flags */
641641 dev -> open_flag = oflag & 0xff ;
642642
643+ #ifdef RT_USING_PINCTRL
644+ /* initialize iomux in DM */
645+ rt_pin_ctrl_confs_apply_by_name (dev , RT_NULL );
646+ #endif
647+
643648 /* initialize the Rx/Tx structure according to open flag */
644649 if (serial -> serial_rx == RT_NULL )
645650 {
@@ -909,7 +914,7 @@ static rt_ssize_t rt_serial_write(struct rt_device *dev,
909914 }
910915}
911916
912- #if defined(RT_USING_POSIX_TERMIOS ) && !defined( RT_USING_SMART )
917+ #if defined(RT_USING_POSIX_TERMIOS )
913918struct speed_baudrate_item
914919{
915920 speed_t speed ;
@@ -928,9 +933,16 @@ static const struct speed_baudrate_item _tbl[] =
928933 {B230400 , BAUD_RATE_230400 },
929934 {B460800 , BAUD_RATE_460800 },
930935 {B500000 , BAUD_RATE_500000 },
936+ {B576000 , BAUD_RATE_576000 },
931937 {B921600 , BAUD_RATE_921600 },
938+ {B1000000 , BAUD_RATE_1000000 },
939+ {B1152000 , BAUD_RATE_1152000 },
940+ {B1500000 , BAUD_RATE_1500000 },
932941 {B2000000 , BAUD_RATE_2000000 },
942+ {B2500000 , BAUD_RATE_2500000 },
933943 {B3000000 , BAUD_RATE_3000000 },
944+ {B3500000 , BAUD_RATE_3500000 },
945+ {B4000000 , BAUD_RATE_4000000 },
934946};
935947
936948static speed_t _get_speed (int baudrate )
@@ -1002,6 +1014,32 @@ static void _tc_flush(struct rt_serial_device *serial, int queue)
10021014 }
10031015
10041016}
1017+
1018+ static inline int _termio_to_termios (const struct termio * termio ,
1019+ struct termios * termios )
1020+ {
1021+ termios -> c_iflag = termio -> c_iflag ;
1022+ termios -> c_oflag = termio -> c_oflag ;
1023+ termios -> c_cflag = termio -> c_cflag ;
1024+ termios -> c_lflag = termio -> c_lflag ;
1025+ termios -> c_line = termio -> c_line ;
1026+ rt_memcpy (termios -> c_cc , termio -> c_cc , NCC );
1027+
1028+ return 0 ;
1029+ }
1030+
1031+ static inline int _termios_to_termio (const struct termios * termios ,
1032+ struct termio * termio )
1033+ {
1034+ termio -> c_iflag = (unsigned short )termios -> c_iflag ;
1035+ termio -> c_oflag = (unsigned short )termios -> c_oflag ;
1036+ termio -> c_cflag = (unsigned short )termios -> c_cflag ;
1037+ termio -> c_lflag = (unsigned short )termios -> c_lflag ;
1038+ termio -> c_line = termios -> c_line ;
1039+ rt_memcpy (termio -> c_cc , termios -> c_cc , NCC );
1040+
1041+ return 0 ;
1042+ }
10051043#endif /* RT_USING_POSIX_TERMIOS */
10061044
10071045static rt_err_t rt_serial_control (struct rt_device * dev ,
@@ -1058,10 +1096,21 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
10581096 }
10591097 break ;
10601098#ifdef RT_USING_POSIX_STDIO
1061- #if defined(RT_USING_POSIX_TERMIOS ) && !defined( RT_USING_SMART )
1099+ #if defined(RT_USING_POSIX_TERMIOS )
10621100 case TCGETA :
1101+ case TCGETS :
10631102 {
1064- struct termios * tio = (struct termios * )args ;
1103+ struct termios * tio , tmp ;
1104+
1105+ if (cmd == TCGETS )
1106+ {
1107+ tio = (struct termios * )args ;
1108+ }
1109+ else
1110+ {
1111+ tio = & tmp ;
1112+ }
1113+
10651114 if (tio == RT_NULL ) return - RT_EINVAL ;
10661115
10671116 tio -> c_iflag = 0 ;
@@ -1092,17 +1141,34 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
10921141 tio -> c_cflag |= (PARODD | PARENB );
10931142
10941143 cfsetospeed (tio , _get_speed (serial -> config .baud_rate ));
1144+
1145+ if (cmd == TCGETA )
1146+ {
1147+ _termios_to_termio (tio , args );
1148+ }
10951149 }
10961150 break ;
1097-
10981151 case TCSETAW :
10991152 case TCSETAF :
11001153 case TCSETA :
1154+ case TCSETSW :
1155+ case TCSETSF :
1156+ case TCSETS :
11011157 {
11021158 int baudrate ;
11031159 struct serial_configure config ;
1160+ struct termios * tio , tmp ;
1161+
1162+ if ((cmd >= TCSETA ) && (cmd <= TCSETA + 2 ))
1163+ {
1164+ _termio_to_termios (args , & tmp );
1165+ tio = & tmp ;
1166+ }
1167+ else
1168+ {
1169+ tio = (struct termios * )args ;
1170+ }
11041171
1105- struct termios * tio = (struct termios * )args ;
11061172 if (tio == RT_NULL ) return - RT_EINVAL ;
11071173
11081174 config = serial -> config ;
@@ -1139,6 +1205,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
11391205 serial -> ops -> configure (serial , & config );
11401206 }
11411207 break ;
1208+ #ifndef RT_USING_TTY
11421209 case TCFLSH :
11431210 {
11441211 int queue = (int )(rt_ubase_t )args ;
@@ -1149,6 +1216,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
11491216 break ;
11501217 case TCXONC :
11511218 break ;
1219+ #endif /*RT_USING_TTY*/
11521220#endif /*RT_USING_POSIX_TERMIOS*/
11531221 case TIOCSWINSZ :
11541222 {
0 commit comments