runtime: share rtio_log format function
This commit is contained in:
parent
1e20259c36
commit
8337c9173e
|
@ -1,11 +1,29 @@
|
|||
use core::ffi::VaList;
|
||||
use core::ptr;
|
||||
use libc::{c_char, c_int, size_t};
|
||||
use libm;
|
||||
|
||||
use alloc::vec;
|
||||
|
||||
use crate::eh_artiq;
|
||||
use crate::rtio;
|
||||
use super::rpc::{rpc_send, rpc_send_async, rpc_recv};
|
||||
use super::dma;
|
||||
use super::cache;
|
||||
|
||||
|
||||
extern "C" {
|
||||
fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int;
|
||||
}
|
||||
|
||||
pub unsafe extern fn rtio_log(fmt: *const c_char, mut args: ...) {
|
||||
let size = vsnprintf_(ptr::null_mut(), 0, fmt, args.as_va_list()) as usize;
|
||||
let mut buf = vec![0; size + 1];
|
||||
vsnprintf_(buf.as_mut_ptr(), size + 1, fmt, args.as_va_list());
|
||||
rtio::write_log(buf.as_slice());
|
||||
}
|
||||
|
||||
|
||||
macro_rules! api {
|
||||
($i:ident) => ({
|
||||
extern { static $i: u8; }
|
||||
|
@ -50,7 +68,7 @@ pub fn resolve(required: &[u8]) -> Option<u32> {
|
|||
api!(rtio_input_timestamp = rtio::input_timestamp),
|
||||
api!(rtio_input_data = rtio::input_data),
|
||||
api!(rtio_input_timestamped_data = rtio::input_timestamped_data),
|
||||
api!(rtio_log = rtio::log),
|
||||
api!(rtio_log = rtio_log),
|
||||
|
||||
// rtio dma
|
||||
api!(dma_record_start = dma::dma_record_start),
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
use core::ptr::{self, read_volatile, write_volatile};
|
||||
use core::ffi::VaList;
|
||||
use alloc::vec;
|
||||
use cslice::CSlice;
|
||||
use libc::{c_char, c_int, size_t};
|
||||
|
||||
use crate::artiq_raise;
|
||||
|
||||
|
@ -65,17 +61,6 @@ pub extern fn input_timestamped_data(timeout: i64, channel: i32) -> TimestampedD
|
|||
unimplemented!();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int;
|
||||
}
|
||||
|
||||
fn write_rtio_log(data: &[i8]) {
|
||||
pub fn write_log(data: &[i8]) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
pub unsafe extern fn log(fmt: *const c_char, mut args: ...) {
|
||||
let size = vsnprintf_(ptr::null_mut(), 0, fmt, args.as_va_list()) as usize;
|
||||
let mut buf = vec![0; size + 1];
|
||||
vsnprintf_(buf.as_mut_ptr(), size + 1, fmt, args.as_va_list());
|
||||
write_rtio_log(buf.as_slice());
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
use core::ptr::{self, read_volatile, write_volatile};
|
||||
use core::ffi::VaList;
|
||||
use alloc::vec;
|
||||
use core::ptr::{read_volatile, write_volatile};
|
||||
use cslice::CSlice;
|
||||
use libc::{c_char, c_int, size_t};
|
||||
|
||||
use crate::artiq_raise;
|
||||
|
||||
|
@ -203,11 +200,7 @@ pub extern fn input_timestamped_data(timeout: i64, channel: i32) -> TimestampedD
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int;
|
||||
}
|
||||
|
||||
fn write_rtio_log(data: &[i8]) {
|
||||
pub fn write_log(data: &[i8]) {
|
||||
unsafe {
|
||||
csr::rtio::target_write(csr::CONFIG_RTIO_LOG_CHANNEL << 8);
|
||||
|
||||
|
@ -226,10 +219,3 @@ fn write_rtio_log(data: &[i8]) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe extern fn log(fmt: *const c_char, mut args: ...) {
|
||||
let size = vsnprintf_(ptr::null_mut(), 0, fmt, args.as_va_list()) as usize;
|
||||
let mut buf = vec![0; size + 1];
|
||||
vsnprintf_(buf.as_mut_ptr(), size + 1, fmt, args.as_va_list());
|
||||
write_rtio_log(buf.as_slice());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue