65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
/*
|
|
* 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_ */
|