forked from M-Labs/artiq
runtime: match argument signedness between ARTIQ Python and ksupport.
This is only required when reading the ABI very strictly, but better be conservative here than spend time debugging silly stuff.
This commit is contained in:
parent
cf12a888e7
commit
ea25856d92
@ -75,7 +75,9 @@ mod imp {
|
||||
|
||||
use self::imp::*;
|
||||
|
||||
pub extern fn init(busno: u32) {
|
||||
pub extern fn init(busno: i32) {
|
||||
let busno = busno as u32;
|
||||
|
||||
// Set SCL as output, and high level
|
||||
scl_o(busno, true);
|
||||
scl_oe(busno, true);
|
||||
@ -92,7 +94,9 @@ pub extern fn init(busno: u32) {
|
||||
}
|
||||
}
|
||||
|
||||
pub extern fn start(busno: u32) {
|
||||
pub extern fn start(busno: i32) {
|
||||
let busno = busno as u32;
|
||||
|
||||
// Set SCL high then SDA low
|
||||
scl_o(busno, true);
|
||||
half_period();
|
||||
@ -100,7 +104,9 @@ pub extern fn start(busno: u32) {
|
||||
half_period();
|
||||
}
|
||||
|
||||
pub extern fn stop(busno: u32) {
|
||||
pub extern fn stop(busno: i32) {
|
||||
let busno = busno as u32;
|
||||
|
||||
// First, make sure SCL is low, so that the target releases the SDA line
|
||||
scl_o(busno, false);
|
||||
half_period();
|
||||
@ -112,7 +118,9 @@ pub extern fn stop(busno: u32) {
|
||||
half_period();
|
||||
}
|
||||
|
||||
pub extern fn write(busno: u32, data: u8) -> bool {
|
||||
pub extern fn write(busno: i32, data: i8) -> bool {
|
||||
let (busno, data) = (busno as u32, data as u8);
|
||||
|
||||
// MSB first
|
||||
for bit in (0..8).rev() {
|
||||
// Set SCL low and set our bit on SDA
|
||||
@ -135,7 +143,9 @@ pub extern fn write(busno: u32, data: u8) -> bool {
|
||||
!sda_i(busno)
|
||||
}
|
||||
|
||||
pub extern fn read(busno: u32, ack: bool) -> u8 {
|
||||
pub extern fn read(busno: i32, ack: bool) -> i8 {
|
||||
let busno = busno as u32;
|
||||
|
||||
// Set SCL low first, otherwise setting SDA as input may cause a transition
|
||||
// on SDA with SCL high which will be interpreted as START/STOP condition.
|
||||
scl_o(busno, false);
|
||||
@ -162,5 +172,5 @@ pub extern fn read(busno: u32, ack: bool) -> u8 {
|
||||
scl_o(busno, true);
|
||||
half_period();
|
||||
|
||||
data
|
||||
data as i8
|
||||
}
|
||||
|
@ -224,26 +224,26 @@ pub extern fn __artiq_terminate(exception: *const kernel_proto::Exception,
|
||||
loop {}
|
||||
}
|
||||
|
||||
extern fn watchdog_set(ms: i64) -> usize {
|
||||
extern fn watchdog_set(ms: i64) -> i32 {
|
||||
if ms < 0 {
|
||||
artiq_raise!("ValueError", "cannot set a watchdog with a negative timeout")
|
||||
}
|
||||
|
||||
send(&WatchdogSetRequest { ms: ms as u64 });
|
||||
recv!(&WatchdogSetReply { id } => id)
|
||||
recv!(&WatchdogSetReply { id } => id) as i32
|
||||
}
|
||||
|
||||
extern fn watchdog_clear(id: usize) {
|
||||
send(&WatchdogClear { id: id })
|
||||
extern fn watchdog_clear(id: i32) {
|
||||
send(&WatchdogClear { id: id as usize })
|
||||
}
|
||||
|
||||
extern fn cache_get(key: *const u8) -> (usize, *const i32) {
|
||||
extern fn cache_get(key: *const u8) -> ArtiqList<i32> {
|
||||
extern { fn strlen(s: *const c_char) -> size_t; }
|
||||
let key = unsafe { slice::from_raw_parts(key, strlen(key as *const c_char)) };
|
||||
let key = unsafe { str::from_utf8_unchecked(key) };
|
||||
|
||||
send(&CacheGetRequest { key: key });
|
||||
recv!(&CacheGetReply { value } => (value.len(), value.as_ptr()))
|
||||
recv!(&CacheGetReply { value } => ArtiqList::from_slice(value))
|
||||
}
|
||||
|
||||
extern fn cache_put(key: *const u8, list: ArtiqList<i32>) {
|
||||
|
@ -39,7 +39,7 @@ pub unsafe fn rtio_i_data_read(offset: usize) -> u32 {
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
unsafe fn process_exceptional_status(timestamp: i64, channel: u32, status: u32) {
|
||||
unsafe fn process_exceptional_status(timestamp: i64, channel: i32, status: u32) {
|
||||
if status & RTIO_O_STATUS_FULL != 0 {
|
||||
while csr::rtio::o_status_read() & RTIO_O_STATUS_FULL != 0 {}
|
||||
}
|
||||
@ -69,12 +69,12 @@ unsafe fn process_exceptional_status(timestamp: i64, channel: u32, status: u32)
|
||||
}
|
||||
}
|
||||
|
||||
pub extern fn output(timestamp: i64, channel: u32, addr: u32, data: u32) {
|
||||
pub extern fn output(timestamp: i64, channel: i32, addr: i32, data: i32) {
|
||||
unsafe {
|
||||
csr::rtio::chan_sel_write(channel);
|
||||
csr::rtio::chan_sel_write(channel as u32);
|
||||
csr::rtio::o_timestamp_write(timestamp as u64);
|
||||
csr::rtio::o_address_write(addr);
|
||||
rtio_o_data_write(0, data);
|
||||
csr::rtio::o_address_write(addr as u32);
|
||||
rtio_o_data_write(0, data as u32);
|
||||
csr::rtio::o_we_write(1);
|
||||
let status = csr::rtio::o_status_read();
|
||||
if status != 0 {
|
||||
@ -83,11 +83,11 @@ pub extern fn output(timestamp: i64, channel: u32, addr: u32, data: u32) {
|
||||
}
|
||||
}
|
||||
|
||||
pub extern fn output_wide(timestamp: i64, channel: u32, addr: u32, list: ArtiqList<i32>) {
|
||||
pub extern fn output_wide(timestamp: i64, channel: i32, addr: i32, list: ArtiqList<i32>) {
|
||||
unsafe {
|
||||
csr::rtio::chan_sel_write(channel);
|
||||
csr::rtio::chan_sel_write(channel as u32);
|
||||
csr::rtio::o_timestamp_write(timestamp as u64);
|
||||
csr::rtio::o_address_write(addr);
|
||||
csr::rtio::o_address_write(addr as u32);
|
||||
let data = list.as_slice();
|
||||
for i in 0..data.len() {
|
||||
rtio_o_data_write(i, data[i] as u32)
|
||||
@ -100,9 +100,9 @@ pub extern fn output_wide(timestamp: i64, channel: u32, addr: u32, list: ArtiqLi
|
||||
}
|
||||
}
|
||||
|
||||
pub extern fn input_timestamp(timeout: i64, channel: u32) -> u64 {
|
||||
pub extern fn input_timestamp(timeout: i64, channel: i32) -> u64 {
|
||||
unsafe {
|
||||
csr::rtio::chan_sel_write(channel);
|
||||
csr::rtio::chan_sel_write(channel as u32);
|
||||
let mut status;
|
||||
loop {
|
||||
status = csr::rtio::i_status_read();
|
||||
@ -136,9 +136,9 @@ pub extern fn input_timestamp(timeout: i64, channel: u32) -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
pub extern fn input_data(channel: u32) -> u32 {
|
||||
pub extern fn input_data(channel: i32) -> i32 {
|
||||
unsafe {
|
||||
csr::rtio::chan_sel_write(channel);
|
||||
csr::rtio::chan_sel_write(channel as u32);
|
||||
loop {
|
||||
let status = csr::rtio::i_status_read();
|
||||
if status == 0 { break }
|
||||
@ -153,7 +153,7 @@ pub extern fn input_data(channel: u32) -> u32 {
|
||||
|
||||
let data = rtio_i_data_read(0);
|
||||
csr::rtio::i_re_write(1);
|
||||
data
|
||||
data as i32
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user