コード例 #1
0
ファイル: syscalls.c プロジェクト: StefanPfeiffer/RIOT
/**
 * @brief Read from a file
 *
 * All input is read from UART_0. The function will block until a byte is actually read.
 *
 * Note: the read function does not buffer - data will be lost if the function is not
 * called fast enough.
 *
 * TODO: implement more sophisticated read call.
 *
 * @param r     TODO
 * @param fd    TODO
 * @param buffer TODO
 * @param int   TODO
 *
 * @return      TODO
 */
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
{
#ifndef MODULE_UART0
    while (rx_buf.avail == 0) {
        mutex_lock(&uart_rx_mutex);
    }
    return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail);
#else
    char *res = (char*)buffer;
    res[0] = (char)uart0_readc();
    return 1;
#endif
}
コード例 #2
0
ファイル: bordermultiplex.c プロジェクト: A-L-E-X/RIOT
int readpacket(uint8_t *packet_buf, size_t size)
{
    uint8_t *line_buf_ptr = packet_buf;
    uint8_t byte = END + 1;
    uint8_t esc = 0;

    while (1) {
        byte = uart0_readc();

        if (byte == END) {
            break;
        }

        if ((size_t)(line_buf_ptr - packet_buf) >= size - 1) {
            return -SIXLOWERROR_ARRAYFULL;
        }

        if (esc) {
            esc = 0;

            switch (byte) {
                case (END_ESC): {
                    *line_buf_ptr++ = END;
                    continue;
                }

                case (ESC_ESC): {
                    *line_buf_ptr++ = ESC;
                    continue;
                }

                default:
                    continue;
            }
        }

        if (byte == ESC) {
            esc = 1;
            continue;
        }

        *line_buf_ptr++ = byte;
    }

    return (line_buf_ptr - packet_buf - 1);
}
コード例 #3
0
ファイル: syscalls.c プロジェクト: AnonMall/RIOT
/**
 * @brief Read from a file
 *
 * All input is read from UART_0. The function will block until a byte is actually read.
 *
 * Note: the read function does not buffer - data will be lost if the function is not
 * called fast enough.
 *
 * TODO: implement more sophisticated read call.
 *
 * @param r     TODO
 * @param fd    TODO
 * @param buffer TODO
 * @param int   TODO
 *
 * @return      TODO
 */
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
{
    if (fd != STDIN_FILENO) {
        r->_errno = EBADF;
        return -1;
    }

    r->_errno = 0;
    if (count == 0) {
        return 0;
    }

#ifndef MODULE_UART0
    while (rx_buf.avail == 0) {
        mutex_lock(&uart_rx_mutex);
    }
    return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail);
#else
    char *res = (char*)buffer;
    res[0] = (char)uart0_readc();
    return 1;
#endif
}