tty: implement TCFLSH to flush buffers
This is probably incomplete. Is locking needed? Should we notify the next writer (if any) that the port is writable when flushing the output? Change-Id: I2566e2d036a61af4819894a44f57603179aa27df Reviewed-on: https://review.haiku-os.org/c/haiku/+/2516 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
f0e491d390
commit
a52008cb44
@@ -39,6 +39,7 @@ typedef bool (*tty_service_func)(struct tty *tty, uint32 op, void *buffer,
|
|||||||
#define TTYSETDTR 6 /* bool dataTerminalReady */
|
#define TTYSETDTR 6 /* bool dataTerminalReady */
|
||||||
#define TTYSETRTS 7 /* bool requestToSend */
|
#define TTYSETRTS 7 /* bool requestToSend */
|
||||||
#define TTYGETSIGNALS 8 /* call tty_hardware_signal for all bits */
|
#define TTYGETSIGNALS 8 /* call tty_hardware_signal for all bits */
|
||||||
|
#define TTYFLUSH 9 /* clear input and/or output buffers */
|
||||||
|
|
||||||
typedef struct tty_module_info tty_module_info;
|
typedef struct tty_module_info tty_module_info;
|
||||||
|
|
||||||
|
|||||||
@@ -359,6 +359,19 @@ SerialDevice::Service(struct tty *tty, uint32 op, void *buffer, size_t length)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case TTYFLUSH:
|
||||||
|
{
|
||||||
|
int directions = *(int*)buffer;
|
||||||
|
uint8 mask = 0;
|
||||||
|
if (directions & TCIFLUSH)
|
||||||
|
mask |= FCR_RX_RST;
|
||||||
|
if (directions & TCOFLUSH)
|
||||||
|
mask |= FCR_TX_RST;
|
||||||
|
// These bits clear themselves when flushing is complete
|
||||||
|
OrReg8(FCR, mask);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,6 +274,7 @@ SerialDevice::Service(struct tty *tty, uint32 op, void *buffer, size_t length)
|
|||||||
case TTYOSTART:
|
case TTYOSTART:
|
||||||
case TTYOSYNC:
|
case TTYOSYNC:
|
||||||
case TTYSETBREAK:
|
case TTYSETBREAK:
|
||||||
|
case TTYFLUSH:
|
||||||
TRACE("TTY other\n");
|
TRACE("TTY other\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1810,6 +1810,28 @@ tty_control(tty_cookie* cookie, uint32 op, void* buffer, size_t length)
|
|||||||
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TCFLSH:
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
if (user_memcpy(&value, buffer, sizeof(value)) != B_OK)
|
||||||
|
return B_BAD_ADDRESS;
|
||||||
|
if (value & TCOFLUSH) {
|
||||||
|
struct tty* otherTTY = cookie->other_tty;
|
||||||
|
if (otherTTY->open_count <= 0)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
clear_line_buffer(otherTTY->input_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value & TCIFLUSH)
|
||||||
|
clear_line_buffer(tty->input_buffer);
|
||||||
|
|
||||||
|
if (tty->service_func(tty, TTYFLUSH, &value, sizeof(value)))
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(("tty: unsupported opcode %lu\n", op));
|
TRACE(("tty: unsupported opcode %lu\n", op));
|
||||||
|
|||||||
Reference in New Issue
Block a user