/** Receive data from UART (non-blocking, returns number of bytes received) */
Receive data from UART (non-blocking, returns number of bytes received)
Receive data from UART ( non - blocking returns number of bytes received )
pub fn recv_nb(s: &mut [u8]) -> usize {
    let irecv = unsafe { &mut UART1_INSTANCE_RECV };
    let head = irecv.head.load(Ordering::SeqCst);
    let mut tail = irecv.tail.load(Ordering::SeqCst);
    if head == tail { // Early-out without tail.store if ring buffer empty
        return 0;
    }
    let mut ptr = 0;
    while ptr < s.len() && tail != head {
        s[ptr] = irecv.buf[tail];
        tail += 1;
        if tail == UART_BUFSIZE {
            tail = 0;
        }
        ptr += 1;
    }
    irecv.tail.store(tail, Ordering::SeqCst);
    ptr
}
pub fn recv_nb ( s : & mut [ u8 ] ) -> usize { let irecv = unsafe { & mut UART1_INSTANCE_RECV } ; let head = irecv . head . load ( Ordering :: SeqCst ) ; let mut tail = irecv . tail . load ( Ordering :: SeqCst ) ; if head == tail { // Early-out without tail.store if ring buffer empty return 0 ; } let mut ptr = 0 ; while ptr < s . len ( ) && tail != head { s [ ptr ] = irecv . buf [ tail ] ; tail += 1 ; if tail == UART_BUFSIZE { tail = 0 ; } ptr += 1 ; } irecv . tail . store ( tail , Ordering :: SeqCst ) ; ptr }
Receive data from UART (non-blocking, returns number of bytes received)
Receive data from UART ( non - blocking returns number of bytes received )
s
&mut [u8]