Esempio n. 1
0
UartDevice::UartDevice(const Initializer &initializer)
    : m_rx_buf{new RxBuffer},
m_rx_isr(initializer.config.rx_isr),
m_tx_buf(new TxBuffer(initializer.config.tx_buf_size)),
m_is_tx_idle(true),
//m_tx_dma_channel(initializer.config.tx_dma_channel),
m_dma(nullptr),
m_uart(nullptr)
{
    Uart::Config &&uart_config = initializer.GetUartConfig();
    uart_config.rx_isr = std::bind(&UartDevice::OnRxFull, this, placeholders::_1);
    if (!IsUseDma())
    {
        uart_config.tx_isr = std::bind(&UartDevice::OnTxEmpty, this,
                                       placeholders::_1);
    }
    m_uart = Uart(uart_config);

    if (IsUseDma())
    {
        m_dma_config.reset(new Dma::Config);
        m_dma_config->src.addr = nullptr; // temp
        m_dma_config->src.offset = 1;
        m_dma_config->src.size = Dma::Config::TransferSize::k1Byte;
        m_dma_config->src.major_offset = 0;
        m_dma_config->major_count = 0;
        m_uart.ConfigTxAsDmaDst(m_dma_config.get());
        m_dma_config->complete_isr = std::bind(&UartDevice::OnTxDmaComplete,
                                               this, placeholders::_1);
    }

    m_uart.SetEnableRxIrq(true);
}
Esempio n. 2
0
  Uart Gpio::allocateUart() {
    std::lock_guard<std::mutex> lock(mutex_);

    if (::demo::isVerbose) {
      std::cout << "Allocating UART pins" << std::endl;
    }

    // The pin number is reduced by 2 as the GPIO pins range from 2 to 27, but the array's indices range from 0 to 25.
    if (ownedPins_.at(12) || ownedPins_.at(13)) {
      throw std::runtime_error("The UART pins must not already be allocated");
    }

    // The pin number is reduced by 2 as the GPIO pins range from 2 to 27, but the array's indices range from 0 to 25.
    ownedPins_.at(12) = true;
    ownedPins_.at(13) = true;

    return Uart();
  }
Esempio n. 3
0
int main() {
    char buf[5] = {'h', 'e', 'l', 'l', 'o'};
    Uart test = Uart(1);
    test.transmit(buf, 5);
    
}