Skip to content

Commit 1720811

Browse files
zmshahahaRbb666
authored andcommitted
[components][drivers] fix posix tty, and add more baudrate (#8683)
* serial-tty fix * v2
1 parent 004e5bf commit 1720811

File tree

6 files changed

+97
-20
lines changed

6 files changed

+97
-20
lines changed

components/drivers/include/drivers/serial.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@
2626
#define BAUD_RATE_230400 230400
2727
#define BAUD_RATE_460800 460800
2828
#define BAUD_RATE_500000 500000
29+
#define BAUD_RATE_576000 576000
2930
#define BAUD_RATE_921600 921600
31+
#define BAUD_RATE_1000000 1000000
32+
#define BAUD_RATE_1152000 1152000
33+
#define BAUD_RATE_1500000 1500000
3034
#define BAUD_RATE_2000000 2000000
3135
#define BAUD_RATE_2500000 2500000
3236
#define BAUD_RATE_3000000 3000000
37+
#define BAUD_RATE_3500000 3500000
38+
#define BAUD_RATE_4000000 4000000
3339

3440
#define DATA_BITS_5 5
3541
#define DATA_BITS_6 6

components/drivers/serial/serial.c

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
913918
struct 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

936948
static 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

10071045
static 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
{

components/drivers/serial/serial_tty.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ static int serial_tty_ioctl(struct lwp_tty *tp, rt_ubase_t cmd, rt_caddr_t data,
212212
int error;
213213
switch (cmd)
214214
{
215+
case TCSETS:
216+
case TCSETSW:
217+
case TCSETSF:
218+
RT_ASSERT(tp->t_devswsoftc);
219+
struct serial_tty_context *softc = (struct serial_tty_context *)(tp->t_devswsoftc);
220+
struct rt_serial_device *serial = softc->parent;
221+
struct termios *termios = (struct termios *)data;
222+
rt_device_control(&(serial->parent), cmd, termios);
223+
error = -ENOIOCTL;
215224
default:
216225
/**
217226
* Note: for the most case, we don't let serial layer handle ioctl,

libcpu/aarch64/common/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if GetDepend('RT_USING_OFW') == False:
1212
SrcRemove(src, ['setup.c', 'cpu_psci.c', 'psci.c'])
1313

1414
if GetDepend('RT_USING_PIC') == True:
15-
SrcRemove(src, ['gicv3.c', 'gic.c', 'gtimer.c'])
15+
SrcRemove(src, ['gicv3.c', 'gic.c', 'gtimer.c', 'interrupt.c'])
1616

1717
group = DefineGroup('libcpu', src, depend = [''], CPPPATH = CPPPATH)
1818

libcpu/aarch64/common/context_gcc.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#include "asm-fpu.h"
2020
#include "armv8.h"
2121

22+
#ifndef RT_USING_SMP
23+
.bss
24+
.align 3
25+
rt_interrupt_from_thread: .comm 8, 8
26+
rt_interrupt_to_thread: .comm 8, 8
27+
rt_thread_switch_interrupt_flag: .comm 8, 8
28+
#endif
29+
2230
.text
2331
.weak rt_hw_cpu_id_set
2432
.type rt_hw_cpu_id_set, @function

libcpu/aarch64/common/interrupt.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
#include "gicv3.h"
1717
#include "ioremap.h"
1818

19-
#ifndef RT_USING_SMP
20-
/* Those variables will be accessed in ISR, so we need to share them. */
21-
rt_ubase_t rt_interrupt_from_thread = 0;
22-
rt_ubase_t rt_interrupt_to_thread = 0;
23-
rt_ubase_t rt_thread_switch_interrupt_flag = 0;
24-
#endif
25-
26-
#ifndef RT_USING_PIC
27-
2819
/* exception and interrupt handler table */
2920
struct rt_irq_desc isr_table[MAX_HANDLERS];
3021

@@ -87,9 +78,6 @@ void rt_hw_interrupt_init(void)
8778

8879
/* init interrupt nest, and context in thread sp */
8980
rt_atomic_store(&rt_interrupt_nest, 0);
90-
rt_interrupt_from_thread = 0;
91-
rt_interrupt_to_thread = 0;
92-
rt_thread_switch_interrupt_flag = 0;
9381
#else
9482
rt_uint64_t gic_cpu_base;
9583
rt_uint64_t gic_dist_base;
@@ -417,8 +405,6 @@ void rt_hw_ipi_handler_install(int ipi_vector, rt_isr_handler_t ipi_isr_handler)
417405
}
418406
#endif
419407

420-
#endif /* RT_USING_PIC */
421-
422408
#if defined(FINSH_USING_MSH) && defined(RT_USING_INTERRUPT_INFO)
423409
int list_isr()
424410
{

0 commit comments

Comments
 (0)