MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/configuration/hardware/PeripheralInit.hpp
2024-06-07 11:12:56 +03:00

65 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* PeripheralInit.hpp
*
* Created on: 6 апр. 2019 г.
* Author: titov
*/
#ifndef SOURCE_APPLICATION_HARDWARE_PERIPHERALINIT_HPP_
#define SOURCE_APPLICATION_HARDWARE_PERIPHERALINIT_HPP_
#include "PeripheralId.hh"
#include <cstring>
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<typename T, uint16_t __type_id, class DeviceInfo>
inline bool configuration::hardware::PeripheralInit<T, __type_id, DeviceInfo>::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<const Configuration &>( *config_data );
return T::configure( config.config, static_cast<typename T::Id>(config.peripheral_id) ) and DeviceInfo::notice( type_id, config.peripheral_id, config.cpu_id );
}
#endif /* SOURCE_APPLICATION_HARDWARE_PERIPHERALINIT_HPP_ */