Skip to content

Commit efc536a

Browse files
authored
Merge pull request #4216 from mysterywolf/tio
重新整理了serial.c和pipe.c的格式
2 parents cbe9250 + e3fc77f commit efc536a

File tree

3 files changed

+142
-138
lines changed

3 files changed

+142
-138
lines changed

components/drivers/serial/serial.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ static int serial_fops_open(struct dfs_fd *fd)
7171

7272
switch (fd->flags & O_ACCMODE)
7373
{
74-
case O_RDONLY:
75-
LOG_D("fops open: O_RDONLY!");
76-
flags = RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_RDONLY;
77-
break;
78-
case O_WRONLY:
79-
LOG_D("fops open: O_WRONLY!");
80-
flags = RT_DEVICE_FLAG_WRONLY;
81-
break;
82-
case O_RDWR:
83-
LOG_D("fops open: O_RDWR!");
84-
flags = RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_RDWR;
85-
break;
86-
default:
87-
LOG_E("fops open: unknown mode - %d!", fd->flags & O_ACCMODE);
88-
break;
74+
case O_RDONLY:
75+
LOG_D("fops open: O_RDONLY!");
76+
flags = RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_RDONLY;
77+
break;
78+
case O_WRONLY:
79+
LOG_D("fops open: O_WRONLY!");
80+
flags = RT_DEVICE_FLAG_WRONLY;
81+
break;
82+
case O_RDWR:
83+
LOG_D("fops open: O_RDWR!");
84+
flags = RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_RDWR;
85+
break;
86+
default:
87+
LOG_E("fops open: unknown mode - %d!", fd->flags & O_ACCMODE);
88+
break;
8989
}
9090

9191
if ((fd->flags & O_ACCMODE) != O_WRONLY)
@@ -133,7 +133,7 @@ static int serial_fops_read(struct dfs_fd *fd, void *buf, size_t count)
133133

134134
do
135135
{
136-
size = rt_device_read(device, -1, buf, count);
136+
size = rt_device_read(device, -1, buf, count);
137137
if (size <= 0)
138138
{
139139
if (fd->flags & O_NONBLOCK)
@@ -759,14 +759,17 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
759759
#ifdef RT_SERIAL_USING_DMA
760760
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX)
761761
{
762-
if (serial->config.bufsz == 0) {
762+
if (serial->config.bufsz == 0)
763+
{
763764
struct rt_serial_rx_dma* rx_dma;
764765

765766
rx_dma = (struct rt_serial_rx_dma*)serial->serial_rx;
766767
RT_ASSERT(rx_dma != RT_NULL);
767768

768769
rt_free(rx_dma);
769-
} else {
770+
}
771+
else
772+
{
770773
struct rt_serial_rx_fifo* rx_fifo;
771774

772775
rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx;
@@ -1105,6 +1108,16 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
11051108
break;
11061109
case TCXONC:
11071110
break;
1111+
case TIOCSWINSZ:
1112+
{
1113+
struct winsize* p_winsize;
1114+
1115+
p_winsize = (struct winsize*)args;
1116+
rt_enter_critical();
1117+
rt_kprintf("\x1b[8;%d;%dt", p_winsize->ws_col, p_winsize->ws_row);
1118+
rt_exit_critical();
1119+
}
1120+
break;
11081121
#endif /*RT_USING_POSIX_TERMIOS*/
11091122
case FIONREAD:
11101123
{
@@ -1118,14 +1131,6 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
11181131
*(rt_size_t *)args = recved;
11191132
}
11201133
break;
1121-
case TIOCSWINSZ:
1122-
{
1123-
struct winsize* p_winsize;
1124-
1125-
p_winsize = (struct winsize*)args;
1126-
rt_kprintf("\x1b[8;%d;%dt", p_winsize->ws_col, p_winsize->ws_row);
1127-
}
1128-
break;
11291134
#endif /*RT_USING_POSIX*/
11301135
default :
11311136
/* control device */

components/drivers/src/pipe.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ static int pipe_fops_open(struct dfs_fd *fd)
4141

4242
switch (fd->flags & O_ACCMODE)
4343
{
44-
case O_RDONLY:
45-
pipe->readers ++;
46-
break;
47-
case O_WRONLY:
48-
pipe->writers ++;
49-
break;
50-
case O_RDWR:
51-
pipe->readers ++;
52-
pipe->writers ++;
53-
break;
44+
case O_RDONLY:
45+
pipe->readers ++;
46+
break;
47+
case O_WRONLY:
48+
pipe->writers ++;
49+
break;
50+
case O_RDWR:
51+
pipe->readers ++;
52+
pipe->writers ++;
53+
break;
5454
}
5555
device->ref_count ++;
5656

@@ -73,16 +73,16 @@ static int pipe_fops_close(struct dfs_fd *fd)
7373

7474
switch (fd->flags & O_ACCMODE)
7575
{
76-
case O_RDONLY:
77-
pipe->readers --;
78-
break;
79-
case O_WRONLY:
80-
pipe->writers --;
81-
break;
82-
case O_RDWR:
83-
pipe->readers --;
84-
pipe->writers --;
85-
break;
76+
case O_RDONLY:
77+
pipe->readers --;
78+
break;
79+
case O_WRONLY:
80+
pipe->writers --;
81+
break;
82+
case O_RDWR:
83+
pipe->readers --;
84+
pipe->writers --;
85+
break;
8686
}
8787

8888
if (pipe->writers == 0)
@@ -123,15 +123,15 @@ static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
123123

124124
switch (cmd)
125125
{
126-
case FIONREAD:
127-
*((int*)args) = rt_ringbuffer_data_len(pipe->fifo);
128-
break;
129-
case FIONWRITE:
130-
*((int*)args) = rt_ringbuffer_space_len(pipe->fifo);
131-
break;
132-
default:
133-
ret = -EINVAL;
134-
break;
126+
case FIONREAD:
127+
*((int*)args) = rt_ringbuffer_data_len(pipe->fifo);
128+
break;
129+
case FIONWRITE:
130+
*((int*)args) = rt_ringbuffer_space_len(pipe->fifo);
131+
break;
132+
default:
133+
ret = -EINVAL;
134+
break;
135135
}
136136

137137
return ret;

include/libc/libc_ioctl.h

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -28,99 +28,99 @@
2828
* in send queue. */
2929
#endif
3030

31-
#define TCGETS 0x5401
32-
#define TCSETS 0x5402
33-
#define TCSETSW 0x5403
34-
#define TCSETSF 0x5404
35-
#define TCGETA 0x5405
36-
#define TCSETA 0x5406
37-
#define TCSETAW 0x5407
38-
#define TCSETAF 0x5408
39-
#define TCSBRK 0x5409
40-
#define TCXONC 0x540A
41-
#define TCFLSH 0x540B
42-
#define TIOCEXCL 0x540C
43-
#define TIOCNXCL 0x540D
44-
#define TIOCSCTTY 0x540E
45-
#define TIOCGPGRP 0x540F
46-
#define TIOCSPGRP 0x5410
47-
#define TIOCOUTQ 0x5411
48-
#define TIOCSTI 0x5412
49-
#define TIOCGWINSZ 0x5413
50-
#define TIOCSWINSZ 0x5414
51-
#define TIOCMGET 0x5415
52-
#define TIOCMBIS 0x5416
53-
#define TIOCMBIC 0x5417
54-
#define TIOCMSET 0x5418
55-
#define TIOCGSOFTCAR 0x5419
56-
#define TIOCSSOFTCAR 0x541A
57-
// #define FIONREAD 0x541B
58-
#define TIOCINQ FIONREAD
59-
#define TIOCLINUX 0x541C
60-
#define TIOCCONS 0x541D
61-
#define TIOCGSERIAL 0x541E
62-
#define TIOCSSERIAL 0x541F
63-
#define TIOCPKT 0x5420
64-
// #define FIONBIO 0x5421
65-
#define TIOCNOTTY 0x5422
66-
#define TIOCSETD 0x5423
67-
#define TIOCGETD 0x5424
68-
#define TCSBRKP 0x5425
69-
#define TIOCSBRK 0x5427
70-
#define TIOCCBRK 0x5428
71-
#define TIOCGSID 0x5429
72-
#define TIOCGRS485 0x542E
73-
#define TIOCSRS485 0x542F
74-
#define TIOCGPTN 0x80045430
75-
#define TIOCSPTLCK 0x40045431
76-
#define TIOCGDEV 0x80045432
77-
#define TCGETX 0x5432
78-
#define TCSETX 0x5433
79-
#define TCSETXF 0x5434
80-
#define TCSETXW 0x5435
81-
#define TIOCSIG 0x40045436
82-
#define TIOCVHANGUP 0x5437
83-
#define TIOCGPKT 0x80045438
84-
#define TIOCGPTLCK 0x80045439
85-
#define TIOCGEXCL 0x80045440
86-
87-
#define FIONCLEX 0x5450
88-
#define FIOCLEX 0x5451
31+
#define TCGETS 0x5401
32+
#define TCSETS 0x5402
33+
#define TCSETSW 0x5403
34+
#define TCSETSF 0x5404
35+
#define TCGETA 0x5405
36+
#define TCSETA 0x5406
37+
#define TCSETAW 0x5407
38+
#define TCSETAF 0x5408
39+
#define TCSBRK 0x5409
40+
#define TCXONC 0x540A
41+
#define TCFLSH 0x540B
42+
#define TIOCEXCL 0x540C
43+
#define TIOCNXCL 0x540D
44+
#define TIOCSCTTY 0x540E
45+
#define TIOCGPGRP 0x540F
46+
#define TIOCSPGRP 0x5410
47+
#define TIOCOUTQ 0x5411
48+
#define TIOCSTI 0x5412
49+
#define TIOCGWINSZ 0x5413
50+
#define TIOCSWINSZ 0x5414
51+
#define TIOCMGET 0x5415
52+
#define TIOCMBIS 0x5416
53+
#define TIOCMBIC 0x5417
54+
#define TIOCMSET 0x5418
55+
#define TIOCGSOFTCAR 0x5419
56+
#define TIOCSSOFTCAR 0x541A
57+
// #define FIONREAD 0x541B
58+
#define TIOCINQ FIONREAD
59+
#define TIOCLINUX 0x541C
60+
#define TIOCCONS 0x541D
61+
#define TIOCGSERIAL 0x541E
62+
#define TIOCSSERIAL 0x541F
63+
#define TIOCPKT 0x5420
64+
// #define FIONBIO 0x5421
65+
#define TIOCNOTTY 0x5422
66+
#define TIOCSETD 0x5423
67+
#define TIOCGETD 0x5424
68+
#define TCSBRKP 0x5425
69+
#define TIOCSBRK 0x5427
70+
#define TIOCCBRK 0x5428
71+
#define TIOCGSID 0x5429
72+
#define TIOCGRS485 0x542E
73+
#define TIOCSRS485 0x542F
74+
#define TIOCGPTN 0x80045430
75+
#define TIOCSPTLCK 0x40045431
76+
#define TIOCGDEV 0x80045432
77+
#define TCGETX 0x5432
78+
#define TCSETX 0x5433
79+
#define TCSETXF 0x5434
80+
#define TCSETXW 0x5435
81+
#define TIOCSIG 0x40045436
82+
#define TIOCVHANGUP 0x5437
83+
#define TIOCGPKT 0x80045438
84+
#define TIOCGPTLCK 0x80045439
85+
#define TIOCGEXCL 0x80045440
86+
87+
#define FIONCLEX 0x5450
88+
#define FIOCLEX 0x5451
8989

9090
#ifndef _WIN32
91-
#define FIOASYNC 0x5452
91+
#define FIOASYNC 0x5452
9292
#endif
9393

94-
#define TIOCSERCONFIG 0x5453
95-
#define TIOCSERGWILD 0x5454
96-
#define TIOCSERSWILD 0x5455
97-
#define TIOCGLCKTRMIOS 0x5456
98-
#define TIOCSLCKTRMIOS 0x5457
99-
#define TIOCSERGSTRUCT 0x5458
94+
#define TIOCSERCONFIG 0x5453
95+
#define TIOCSERGWILD 0x5454
96+
#define TIOCSERSWILD 0x5455
97+
#define TIOCGLCKTRMIOS 0x5456
98+
#define TIOCSLCKTRMIOS 0x5457
99+
#define TIOCSERGSTRUCT 0x5458
100100
#define TIOCSERGETLSR 0x5459
101101
#define TIOCSERGETMULTI 0x545A
102102
#define TIOCSERSETMULTI 0x545B
103103

104-
#define TIOCMIWAIT 0x545C
105-
#define TIOCGICOUNT 0x545D
106-
#define FIOQSIZE 0x5460
104+
#define TIOCMIWAIT 0x545C
105+
#define TIOCGICOUNT 0x545D
106+
#define FIOQSIZE 0x5460
107107

108-
#define TIOCPKT_DATA 0
109-
#define TIOCPKT_FLUSHREAD 1
110-
#define TIOCPKT_FLUSHWRITE 2
111-
#define TIOCPKT_STOP 4
112-
#define TIOCPKT_START 8
113-
#define TIOCPKT_NOSTOP 16
114-
#define TIOCPKT_DOSTOP 32
115-
#define TIOCPKT_IOCTL 64
108+
#define TIOCPKT_DATA 0
109+
#define TIOCPKT_FLUSHREAD 1
110+
#define TIOCPKT_FLUSHWRITE 2
111+
#define TIOCPKT_STOP 4
112+
#define TIOCPKT_START 8
113+
#define TIOCPKT_NOSTOP 16
114+
#define TIOCPKT_DOSTOP 32
115+
#define TIOCPKT_IOCTL 64
116116

117117
#define TIOCSER_TEMT 0x01
118118

119119
struct winsize {
120-
unsigned short ws_row;
121-
unsigned short ws_col;
122-
unsigned short ws_xpixel;
123-
unsigned short ws_ypixel;
120+
unsigned short ws_row;
121+
unsigned short ws_col;
122+
unsigned short ws_xpixel;
123+
unsigned short ws_ypixel;
124124
};
125125

126126
#define TIOCM_LE 0x001
@@ -223,8 +223,7 @@ struct winsize {
223223
#define SIOCADDDLCI 0x8980
224224
#define SIOCDELDLCI 0x8981
225225

226-
#define SIOCDEVPRIVATE 0x89F0
227-
#define SIOCPROTOPRIVATE 0x89E0
226+
#define SIOCDEVPRIVATE 0x89F0
227+
#define SIOCPROTOPRIVATE 0x89E0
228228

229229
#endif
230-

0 commit comments

Comments
 (0)