Example #1
0
/**
 * @brief Receive a new character from the UART and put it into the receive buffer
 */
void rx_cb(void *arg, char data)
{
    (void)arg;

    ringbuffer_add_one(&rx_buf, data);
    mutex_unlock(&uart_rx_mutex);
}
Example #2
0
static void debug_later(char *fmt, ...){
  char buf[256];
  va_list argp;
  va_start(argp, fmt);
  int i;
  int n = vsprintf(buf, fmt, argp);
  va_end(argp);
  for (i=0;i<n;i++) { ringbuffer_add_one(&_dbg_buf, buf[i]); }
}
Example #3
0
/* UART callbacks */
static void _slip_rx_cb(void *arg, char data)
{
    if (data == _SLIP_END) {
        msg_t msg;

        msg.type = _SLIP_MSG_TYPE;
        msg.content.value = _SLIP_DEV(arg)->in_bytes;

        msg_send_int(&msg, _SLIP_DEV(arg)->slip_pid);

        _SLIP_DEV(arg)->in_bytes = 0;
    }

    if (_SLIP_DEV(arg)->in_esc) {
        _SLIP_DEV(arg)->in_esc = 0;

        switch (data) {
            case (_SLIP_END_ESC):
                if (ringbuffer_add_one(_SLIP_DEV(arg)->in_buf, _SLIP_END) < 0) {
                    _SLIP_DEV(arg)->in_bytes++;
                }

                break;

            case (_SLIP_ESC_ESC):
                if (ringbuffer_add_one(_SLIP_DEV(arg)->in_buf, _SLIP_ESC) < 0) {
                    _SLIP_DEV(arg)->in_bytes++;
                }

                break;

            default:
                break;
        }
    }
    else if (data == _SLIP_ESC) {
        _SLIP_DEV(arg)->in_esc = 1;
    }
    else {
        if (ringbuffer_add_one(_SLIP_DEV(arg)->in_buf, data) < 0) {
            _SLIP_DEV(arg)->in_bytes++;
        }
    }
}
Example #4
0
void rx(void *ptr, char data)
{
    msg_t msg;
    msg.type = MSG_LINE_RDY;

    ringbuffer_add_one(&rx_buf, data);
    if (data == '\n') {
        printf("got line end \n");
        status = 1;
    }
}
Example #5
0
File: main.c Project: Teresa-P/RIOT
static void rx_cb(void *arg, uint8_t data)
{
    int dev = (int)arg;

    ringbuffer_add_one(&(ctx[dev].rx_buf), data);
    if (data == 0) {
        msg_t msg;
        msg.content.value = (uint32_t)dev;
        msg_send(&msg, printer_pid);
    }
}
Example #6
0
/**
 * @brief Receive a new character from the UART and put it into the receive buffer
 */
void rx_cb(void *arg, char data)
{
    (void)arg;

#ifndef MODULE_UART0
    ringbuffer_add_one(&rx_buf, data);
    mutex_unlock(&uart_rx_mutex);
#else
    if (uart0_handler_pid) {
        uart0_handle_incoming(data);
        uart0_notify_thread();
    }
#endif
}
Example #7
0
void uart0_handle_incoming(int c)
{
    ringbuffer_add_one(&uart0_ringbuffer, c);
}
Example #8
0
File: uart.c Project: MatKub/RIOT
void uart_write(uart_t uart, const uint8_t *data, size_t len)
{
    switch(uart) {
#if UART_0_EN
    case UART_0:
#if UART_0_ENABLE_BUF
    for(int count = 0; count < len; count++) {
        NVIC_DisableIRQ(UART_0_IRQ_TX_CHAN);
        ringbuffer_add_one(&rb_uart0, data[count]);
        NVIC_EnableIRQ(UART_0_IRQ_TX_CHAN);
    }
    USART_IntEnable(UART_0_DEV, USART_IF_TXBL);
#else
    for(size_t i = 0; i < len; i++) {
        /* Check that transmit buffer is empty */
        while(!(UART_0_DEV->STATUS & USART_STATUS_TXBL))
        ;
        /* Write data to buffer */
        UART_0_DEV->TXDATA = (uint32_t)data[i];
    }
#endif
    break;
#endif
#if UART_1_EN
    case UART_1:
#if UART_1_ENABLE_BUF
    for(int count = 0; count < len; count++) {
        NVIC_DisableIRQ(UART_1_IRQ_TX_CHAN);
        ringbuffer_add_one(&rb_uart1, data[count]);
        NVIC_EnableIRQ(UART_1_IRQ_TX_CHAN);
    }
    USART_IntEnable(UART_1_DEV, USART_IF_TXBL);
#else
    for(size_t i = 0; i < len; i++)
    {
        /* Check that transmit buffer is empty */
        while(!(UART_1_DEV->STATUS & USART_STATUS_TXBL))
        ;
        /* Write data to buffer */
        UART_1_DEV->TXDATA = (uint32_t)data[i];
    }
#endif
    break;
#endif
#if UART_2_EN
    case UART_2:
#if UART_2_ENABLE_BUF
        for(int count = 0; count < len; count++) {
            NVIC_DisableIRQ(UART_2_IRQ);
            ringbuffer_add_one(&rb_uart2, data[count]);
            NVIC_EnableIRQ(UART_2_IRQ);
        }
        LEUART_IntEnable(UART_2_DEV, LEUART_IF_TXBL);
#else
        for(size_t i = 0; i < len; i++)
        {
            /* Check that transmit buffer is empty */
            while (!(UART_2_DEV->STATUS & LEUART_STATUS_TXBL))
            ;
            /* Avoid deadlock if modifying the same register twice when freeze mode is */
            /* activated. */
            if (!(UART_2_DEV->FREEZE & LEUART_FREEZE_REGFREEZE))
            {
                /* Wait for any pending previous write operation to have been completed */
                /* in low frequency domain */
                while (UART_2_DEV->SYNCBUSY & LEUART_SYNCBUSY_TXDATA);
                ;
                UART_2_DEV->TXDATA = (uint32_t)data[i];
            }

        }
#endif
        break;
#endif
    }
}
Example #9
0
static inline void _slip_send_char(ng_slip_dev_t *dev, char c)
{
    ringbuffer_add_one(dev->out_buf, c);
    uart_tx_begin(dev->uart);
}
Example #10
0
static void assert_add_one(char to_add, int assumed_result)
{
    int actual_result = ringbuffer_add_one(&rb, to_add);
    TEST_ASSERT_EQUAL_INT(assumed_result, actual_result);
}