Beispiel #1
0
    read_buffer ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::allocate_transmit_buffer( std::size_t size )
    {
        // The gap must be greater than size or otherwise we could endup with
        // transmit_ == transmit_end_ without the buffer beeing empty
        if ( transmit_end_ >= transmit_ )
        {
            // place a 0 into the length field to denote that the rest until the buffer end is not used
            if ( end_transmit_buffer() - transmit_end_ >= ll_header_size )
            {
                transmit_end_[ 1 ] = 0;
            }

            // is there still a gap at the end of the buffer?
            if ( end_transmit_buffer() - transmit_end_ > size )
            {
                return read_buffer{ transmit_end_, size };
            }

            // is there a gap at the beginning of the buffer?
            if ( transmit_ - transmit_buffer() > size )
            {
                return read_buffer{ transmit_buffer(), size };
            }
        }
        // the filled part of the buffer is wrapped around the end; is there a gap in the middle?
        else if ( transmit_ - transmit_end_ > size )
        {
            return read_buffer{ transmit_end_, size };
        }

        return read_buffer{ nullptr, 0 };
    }
Beispiel #2
0
    void ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::acknowledge( bool nesn )
    {
        // the transmit buffer could be empty if we receive without sending prior. That happens during testing
        if ( transmit_ == transmit_end_ && !next_empty_ )
            return;

        if ( next_empty_ )
        {
            if ( empty_sequence_number_ != nesn )
                next_empty_ = false;
        }
        else if ( static_cast< bool >( transmit_[ 0 ] & sn_flag ) != nesn )
        {
            transmit_ += transmit_[ 1 ] + ll_header_size;

            // do we have to wrap?
            if ( end_transmit_buffer() - transmit_ < 2 || transmit_[ 1 ] == 0 )
            {
                if ( transmit_ == transmit_end_ )
                    transmit_end_ = transmit_buffer();

                transmit_ = transmit_buffer();
            }
        }
    }
Beispiel #3
0
    void ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::reset()
    {
        max_rx_size_    = min_buffer_size;
        received_end_   = receive_buffer();
        received_       = receive_buffer();

        max_tx_size_    = min_buffer_size;
        transmit_       = transmit_buffer();
        transmit_end_   = transmit_buffer();

        sequence_number_ = false;
        next_expected_sequence_number_ = false;
        next_empty_      = false;
    }
Beispiel #4
0
uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length)
{
    if (p_buffer == NULL)
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    switch (m_current_state)
    {
        case SLIP_READY:
            m_tx_buffer_index  = 0;
            m_tx_buffer_length = length;
            mp_tx_buffer       = p_buffer;
            m_current_state    = SLIP_TRANSMITTING;
            send_tx_byte       = send_tx_byte_end;

            transmit_buffer();
            return NRF_SUCCESS;

        case SLIP_TRANSMITTING:
            return NRF_ERROR_NO_MEM;

        case SLIP_OFF:
        default:
            return NRF_ERROR_INVALID_STATE;
    }
}
Beispiel #5
0
/** @brief Function for handling the UART module event. It parses events from the UART when
 *         bytes are received/transmitted.
 *
 *  @param[in] uart_event   Event received from app_uart module.
 */
static void slip_uart_eventhandler(app_uart_evt_t * uart_event)
{
    if (uart_event->evt_type == APP_UART_TX_EMPTY && m_current_state == SLIP_TRANSMITTING)
    {
        transmit_buffer();
    }

    if ((uart_event->evt_type == APP_UART_DATA) && (!rx_buffer_overflowed()))
    {
        handle_rx_byte(uart_event->data.value);
    }
}