summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorgeniusgogo <[email protected]>2023-10-17 13:07:59 +0800
committerGitHub <[email protected]>2023-10-17 13:07:59 +0800
commitecd29fda6005ef19c625f194f9311259ba907a78 (patch)
treed0e272f5783ac4a3048238e14a37bcd88b5dc3e6 /components/drivers
parent7d64cdcf58969b1b2b7e9cfb3aac9e46cb456ae3 (diff)
Sync dfs lwp (#8123)
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/tty/n_tty.c19
-rw-r--r--components/drivers/tty/tty.c93
2 files changed, 106 insertions, 6 deletions
diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c
index 1191f57696..067d587746 100644
--- a/components/drivers/tty/n_tty.c
+++ b/components/drivers/tty/n_tty.c
@@ -2008,12 +2008,22 @@ static int job_control(struct tty_struct *tty)
return __tty_check_change(tty, SIGTTIN);
}
+static struct rt_wqueue *_wait_queue_current_get(struct tty_struct *tty)
+{
+ struct rt_lwp *lwp;
+
+ lwp = lwp_self();
+ if (!lwp || !lwp->tty)
+ lwp = RT_NULL;
+
+ return wait_queue_get(lwp, tty);
+}
+
static int n_tty_read(struct dfs_file *fd, void *buf, size_t count)
{
int level = 0;
char *b = (char *)buf;
struct tty_struct *tty = RT_NULL;
- struct rt_lwp *lwp = RT_NULL;
struct rt_wqueue *wq = RT_NULL;
int wait_ret = 0;
int retval = 0;
@@ -2031,8 +2041,7 @@ static int n_tty_read(struct dfs_file *fd, void *buf, size_t count)
struct n_tty_data *ldata = tty->disc_data;
- lwp = (struct rt_lwp *)(rt_thread_self()->lwp);
- wq = wait_queue_get(lwp, tty);
+ wq = _wait_queue_current_get(tty);
while(count)
{
@@ -2171,15 +2180,13 @@ static int n_tty_poll(struct dfs_file *fd, struct rt_pollreq *req)
int mask = POLLOUT;
struct tty_struct *tty = RT_NULL;
struct rt_wqueue *wq = RT_NULL;
- struct rt_lwp *lwp = RT_NULL;
tty = (struct tty_struct *)fd->vnode->data;
RT_ASSERT(tty != RT_NULL);
RT_ASSERT(tty->init_flag == TTY_INIT_FLAG_INITED);
- lwp = (struct rt_lwp *)(rt_thread_self()->lwp);
- wq = wait_queue_get(lwp, tty);
+ wq = _wait_queue_current_get(tty);
rt_poll_add(wq, req);
level = rt_hw_interrupt_disable();
diff --git a/components/drivers/tty/tty.c b/components/drivers/tty/tty.c
index 30ab00d890..6e05f95033 100644
--- a/components/drivers/tty/tty.c
+++ b/components/drivers/tty/tty.c
@@ -15,6 +15,7 @@
#include <rtthread.h>
#include <tty.h>
#include <tty_ldisc.h>
+#include <shell.h>
#if defined(RT_USING_POSIX_DEVIO)
#include <termios.h>
@@ -272,9 +273,97 @@ static int tiocsctty(struct tty_struct *tty, int arg)
return 0;
}
+static int tiocswinsz(struct tty_struct *tty, struct winsize *p_winsize)
+{
+ rt_kprintf("\x1b[8;%d;%dt", p_winsize->ws_col, p_winsize->ws_row);
+ return 0;
+}
+
+static int tiocgwinsz(struct tty_struct *tty, struct winsize *p_winsize)
+{
+ if(rt_thread_self() != rt_thread_find(FINSH_THREAD_NAME))
+ {
+ /* only can be used in tshell thread; otherwise, return default size */
+ p_winsize->ws_col = 80;
+ p_winsize->ws_row = 24;
+ }
+ else
+ {
+ #define _TIO_BUFLEN 20
+ char _tio_buf[_TIO_BUFLEN];
+ unsigned char cnt1, cnt2, cnt3, i;
+ char row_s[4], col_s[4];
+ char *p;
+
+ rt_memset(_tio_buf, 0, _TIO_BUFLEN);
+
+ /* send the command to terminal for getting the window size of the terminal */
+ rt_kprintf("\033[18t");
+
+ /* waiting for the response from the terminal */
+ i = 0;
+ while(i < _TIO_BUFLEN)
+ {
+ _tio_buf[i] = finsh_getchar();
+ if(_tio_buf[i] != 't')
+ {
+ i ++;
+ }
+ else
+ {
+ break;
+ }
+ }
+ if(i == _TIO_BUFLEN)
+ {
+ /* buffer overloaded, and return default size */
+ p_winsize->ws_col = 80;
+ p_winsize->ws_row = 24;
+ return 0;
+ }
+
+ /* interpreting data eg: "\033[8;1;15t" which means row is 1 and col is 15 (unit: size of ONE character) */
+ rt_memset(row_s,0,4);
+ rt_memset(col_s,0,4);
+ cnt1 = 0;
+ while(cnt1 < _TIO_BUFLEN && _tio_buf[cnt1] != ';')
+ {
+ cnt1++;
+ }
+ cnt2 = ++cnt1;
+ while(cnt2 < _TIO_BUFLEN && _tio_buf[cnt2] != ';')
+ {
+ cnt2++;
+ }
+ p = row_s;
+ while(cnt1 < cnt2)
+ {
+ *p++ = _tio_buf[cnt1++];
+ }
+ p = col_s;
+ cnt2++;
+ cnt3 = rt_strlen(_tio_buf) - 1;
+ while(cnt2 < cnt3)
+ {
+ *p++ = _tio_buf[cnt2++];
+ }
+
+ /* load the window size date */
+ p_winsize->ws_col = atoi(col_s);
+ p_winsize->ws_row = atoi(row_s);
+ #undef _TIO_BUFLEN
+ }
+
+ p_winsize->ws_xpixel = 0;/* unused */
+ p_winsize->ws_ypixel = 0;/* unused */
+
+ return 0;
+}
+
static int tty_ioctl(struct dfs_file *fd, int cmd, void *args)
{
int ret = 0;
+ void *p = (void *)args;
struct tty_struct *tty = RT_NULL;
struct tty_struct *real_tty = RT_NULL;
struct tty_ldisc *ld = RT_NULL;
@@ -295,6 +384,10 @@ static int tty_ioctl(struct dfs_file *fd, int cmd, void *args)
{
case TIOCSCTTY:
return tiocsctty(real_tty, 1);
+ case TIOCGWINSZ:
+ return tiocgwinsz(real_tty, p);
+ case TIOCSWINSZ:
+ return tiocswinsz(real_tty, p);
}
ld = tty->ldisc;