Skip to content

Commit

Permalink
fpga-boss: Add escape (Ctrl-T+B) for sending break sequence.
Browse files Browse the repository at this point in the history
This is useful for collecting more diagnostics from a misbehaving
kernel.
  • Loading branch information
korran committed Jan 9, 2024
1 parent 809ed5e commit 083bd6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion ci-tools/fpga-boss/src/ftdi_uart.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed under the Apache-2.0 license

use std::io::{self, ErrorKind};
use std::{
io::{self, ErrorKind},
time::Duration,
};

use libftdi1_sys::{ftdi_bits_type, ftdi_interface, ftdi_parity_type, ftdi_stopbits_type};
use std::cell::RefCell;
Expand All @@ -22,6 +25,24 @@ pub struct FtdiUartReaderBlocking {
pub struct FtdiUartWriter {
ftdi: Rc<RefCell<FtdiCtx>>,
}
impl FtdiUartWriter {
pub fn send_break(&self) -> anyhow::Result<()> {
const BREAK_TIME: Duration = Duration::from_micros(100);

let mut ftdi = self.ftdi.borrow_mut();
ftdi.set_bitmode(0x01, BitMode::BitBang)?;
ftdi.write_all_data(&[0x00])?;
std::thread::sleep(BREAK_TIME);
ftdi.set_bitmode(0x01, BitMode::Reset)?;
ftdi.set_baudrate(115200)?;
ftdi.set_line_property(
ftdi_bits_type::BITS_8,
ftdi_stopbits_type::STOP_BIT_1,
ftdi_parity_type::NONE,
)?;
Ok(())
}
}

pub fn open(
port_path: UsbPortPath,
Expand Down
3 changes: 3 additions & 0 deletions ci-tools/fpga-boss/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ fn main_impl() -> anyhow::Result<()> {
let mut stdin_len = tty::read_stdin_nonblock(&mut stdin_buf)?;
escaper.process(&mut stdin_buf, &mut stdin_len, |ch| match ch {
b'q' | b'Q' => alive = false,
b'b' | b'B' => {
uart_tx.send_break().unwrap();
}
ch => println!(
"Unknown escape sequence: Ctrl-T + {:?}",
char::from_u32(ch.into()).unwrap_or('?')
Expand Down

0 comments on commit 083bd6c

Please sign in to comment.