79 lines
2.3 KiB
C++
79 lines
2.3 KiB
C++
/*
|
|
* SpiBusAbonent.h
|
|
*
|
|
* Created on: 24 èþí. 2019 ã.
|
|
* Author: user
|
|
*/
|
|
|
|
#ifndef SOURCE_APPLICATION__BOARD_SPIBUSABONENTSETUP_H_
|
|
#define SOURCE_APPLICATION__BOARD_SPIBUSABONENTSETUP_H_
|
|
|
|
#include "../ISetupStep.hh"
|
|
|
|
#include "../../peripheral/IGpio.hh"
|
|
|
|
#include "../../driver/SpiBus.hh"
|
|
|
|
namespace application { namespace virtualization {
|
|
|
|
//!Àáîíåíò íà øèíå SPI.
|
|
struct SpiBusAbonent : public ISetupStep {
|
|
|
|
driver::SpiBus * spi_bus = nullptr;
|
|
peripheral::IGpio * spi_bus_abonent_cs = nullptr;
|
|
|
|
bool input( Environment & env );
|
|
void build( Environment & env );
|
|
|
|
struct Links {
|
|
Environment::Id chip_select; //!<Àïïàðàòíûé âûâîä èñïîëüçóåìûé äëÿ óïðàâëåíèÿ âûáîðîì ìèêðîñõåìû íà øèíå SPI.
|
|
Environment::Id spi_bus; //!<Øèíà SPI.
|
|
Environment::Id spi_abonent; //!<Àáîíåíò íà øèíå SPI.
|
|
};
|
|
|
|
const Links & links;
|
|
|
|
struct Setting {
|
|
uint16_t clocking_scheme :2; //!<Ñõåìà òàêòèðîâàíèÿ.
|
|
uint16_t cs_polarity :1; //!<Ïîëÿðíîñòü ÷èï-ñåëåêòà.
|
|
uint16_t tx_inversion :1; //!<Èíâåðñèÿ äàííûõ â ëèíèè ïåðåäà÷è.
|
|
uint16_t rx_inversion :1; //!<Èíâåðñèÿ äàííûõ â ëèíèè ïðèåìà.
|
|
|
|
uint16_t loop_back :1; //!<Âèðòóàëüíî çàìêíóòü ëèíèè ïåðåäà÷è è ïðèåìà.
|
|
|
|
uint16_t transfer_delay; //!<Çàäåðæêà ïåðåäà÷è.
|
|
uint32_t baud_rate; //!<×àñòîòà êëîêîâ.
|
|
};
|
|
|
|
const Setting & config;
|
|
|
|
SpiBusAbonent( const Links & links,
|
|
const Setting & config );
|
|
|
|
};
|
|
|
|
struct BadSpiAbonentSetting : public std::exception {
|
|
unsigned short abonent_id;
|
|
std::pair<const char *, std::size_t> abonent_setting;
|
|
|
|
BadSpiAbonentSetting( unsigned short abonent_id,
|
|
std::pair<const char *, std::size_t> abonent_setting ) noexcept :
|
|
abonent_id(abonent_id), abonent_setting(abonent_setting) {}
|
|
|
|
const char * what() const noexcept { return "Bad spi abonent setting"; }
|
|
};
|
|
|
|
struct BadSerialPort : public std::exception {
|
|
unsigned short abonent_id;
|
|
|
|
BadSerialPort( unsigned short abonent_id ) noexcept :
|
|
abonent_id(abonent_id) {}
|
|
|
|
const char * what() const noexcept { return "Bad serial port"; }
|
|
};
|
|
|
|
} /* namespace board */
|
|
} /* namespace application */
|
|
|
|
#endif /* SOURCE_APPLICATION_BOARD_SPIBUSABONENTSETUP_H_ */
|