/* * PeripheralInit.hpp * * Created on: 6 апр. 2019 г. * Author: titov */ #ifndef SOURCE_APPLICATION_HARDWARE_PERIPHERALINIT_HPP_ #define SOURCE_APPLICATION_HARDWARE_PERIPHERALINIT_HPP_ #include "PeripheralId.hh" #include namespace configuration { namespace hardware { struct DefaultCpuSelector { static bool notice( TypeId type_id, PeripheralId peripheral_id, CpuId cpu_id ) { return cpu_id == 0; } }; //!Модуль конфигурации периферии. /*!Модуль конфигурирует периферийный модуль шаблонного типа. * */ template< typename T, TypeId __type_id, class DeviceInfo = DefaultCpuSelector> struct PeripheralInit { static const TypeId type_id = __type_id; typedef T Type; struct Configuration { PeripheralId peripheral_id; CpuId cpu_id; typename T::Setting config; }; static bool configure( const char * config_data, std::size_t size ); }; } } template inline bool configuration::hardware::PeripheralInit::configure( const char * config_data, std::size_t size ) { if( sizeof(Configuration) != size ) return false; Configuration config; std::memcpy( &config, config_data, size ); //const Configuration & config = reinterpret_cast( *config_data ); return T::configure( config.config, static_cast(config.peripheral_id) ) and DeviceInfo::notice( type_id, config.peripheral_id, config.cpu_id ); } #endif /* SOURCE_APPLICATION_HARDWARE_PERIPHERALINIT_HPP_ */