From 8337c9173ec43637cbee85151eeba2ccab3db5df Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 4 Aug 2020 13:27:18 +0800 Subject: [PATCH] runtime: share rtio_log format function --- src/runtime/src/kernel/api.rs | 20 +++++++++++++++++++- src/runtime/src/rtio_acp.rs | 17 +---------------- src/runtime/src/rtio_csr.rs | 18 ++---------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/runtime/src/kernel/api.rs b/src/runtime/src/kernel/api.rs index f798d84..3727dec 100644 --- a/src/runtime/src/kernel/api.rs +++ b/src/runtime/src/kernel/api.rs @@ -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 { 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), diff --git a/src/runtime/src/rtio_acp.rs b/src/runtime/src/rtio_acp.rs index 0a3ac74..a9c5323 100644 --- a/src/runtime/src/rtio_acp.rs +++ b/src/runtime/src/rtio_acp.rs @@ -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()); -} diff --git a/src/runtime/src/rtio_csr.rs b/src/runtime/src/rtio_csr.rs index 0918d66..faa039d 100644 --- a/src/runtime/src/rtio_csr.rs +++ b/src/runtime/src/rtio_csr.rs @@ -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()); -}