69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
|
|
|
|
/*
|
|
* SpiBusAbonentSetup.cpp
|
|
*
|
|
* Created on: 24 èþí. 2019 ã.
|
|
* Author: user
|
|
*/
|
|
|
|
#include <cstring>
|
|
|
|
#include "SpiBusAbonent.hh"
|
|
|
|
#include "../../driver/SpiBus.hh"
|
|
#include "../../driver/IDiscreteOutput.hh"
|
|
|
|
#include "../../peripheral/IGpio.hh"
|
|
#include "../../peripheral/ISerialPort.hh"
|
|
#include "../../peripheral/ISerialPortConfigurator.hh"
|
|
|
|
void application::virtualization::SpiBusAbonent::build(Environment& env) {
|
|
|
|
Local<driver::SpiBus> bus( spi_bus, *env.rholder.getShared<driver::SpiBus>( links.spi_bus ) );
|
|
|
|
driver::SpiBusAbonentConfig::Setting spi_bus_abonent_setting;
|
|
|
|
{
|
|
spi_bus_abonent_setting.clk_scheme = config.clocking_scheme;
|
|
spi_bus_abonent_setting.cs_polarity = config.cs_polarity;
|
|
spi_bus_abonent_setting.transfer_delay = config.transfer_delay;
|
|
spi_bus_abonent_setting.baud_rate = config.baud_rate;
|
|
spi_bus_abonent_setting.rx_inv = config.rx_inversion;
|
|
spi_bus_abonent_setting.tx_inv = config.tx_inversion;
|
|
spi_bus_abonent_setting.loop_back_enable = config.loop_back;
|
|
}
|
|
|
|
driver::SpiBusAbonentConfig spi_bus_abonent_config;
|
|
|
|
if( not spi_bus_abonent_config.configure( spi_bus_abonent_setting ) )
|
|
throw BadSpiAbonentSetting(
|
|
links.spi_abonent,
|
|
std::pair<const char *, std::size_t>(reinterpret_cast<const char *>(&config), sizeof(Setting)) );
|
|
|
|
if( links.spi_abonent ) {
|
|
|
|
peripheral::ISerialPort * serial_port =
|
|
bus->createAbonent( *spi_bus_abonent_cs, spi_bus_abonent_config, &env.static_object_ma );
|
|
|
|
if( not serial_port )
|
|
throw BadSerialPort( links.spi_abonent );
|
|
|
|
env.rholder.share( *serial_port, links.spi_abonent );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
application::virtualization::SpiBusAbonent::SpiBusAbonent(
|
|
const Links & links, const Setting & config) :
|
|
links(links), config(config) {}
|
|
|
|
bool application::virtualization::SpiBusAbonent::input( Environment & env ) {
|
|
|
|
return grab( spi_bus_abonent_cs, env.rholder.getShared<peripheral::IGpio>( links.chip_select ) )
|
|
and grab( spi_bus, env.rholder.getShared<driver::SpiBus>( links.spi_bus ) );
|
|
|
|
}
|
|
|