MotorControlModuleSDFM_TMS3.../Projects/EFC_Application/UMLibrary/driver/chipset/ADT7310.hh

103 lines
2.2 KiB
C++

/*
* ADT7310.h
*
* Created on: 27 ñåíò. 2019 ã.
* Author: user
*/
#ifndef SOURCE_DRIVER_CHIPSET_ADT7310_H_
#define SOURCE_DRIVER_CHIPSET_ADT7310_H_
#include "PackagerADT7310.hh"
#include "../SerialPortAdapter.hpp"
namespace driver { namespace chipset { namespace ADT7310 {
typedef PackagerADT7310 Packager;
typedef uint16_t Latency;
typedef SerialPortAdapter<PackagerADT7310::TemperaturePackager::Frame, Latency, false> SerialPortRegister;
//Àäðåñà ðåãèñòðîâ è êîìàíä.
struct ControlRegistersPairedAcronims {
enum Acronims {
STATUS = 0x00, //Ðåãèñòð ñòàòóñà.
CONFIG = 0x01, //Óïðàâëÿþùèé ðåãèñòð.
TEMP = 0x02, //Ðåãèñòð ðåçóëüòàòà èçìåðåíèÿ.
ID = 0x03, //
T_CRIT = 0x04, //Óñòàâêà òåìïåðàòóðû.
T_HYST = 0x05, //
T_HIGH = 0x06, //Óñòàâêà òåìïåðàòóðû.
T_LOW = 0x07, //Óñòàâêà òåìïåðàòóðû.
};
};
union StatusReg {
uint16_t all;
struct {
uint16_t : 3;
uint16_t t_low : 1;
uint16_t t_high : 1;
uint16_t t_crit : 1;
uint16_t nrdy : 1;
} bit;
};
enum IntCtMode {
interrupt_mode = 0,
comparator_mode
};
enum OperationMode {
continuous = 0,
one_shot,
sps,
shut_down
};
union ConfigReg {
uint16_t all;
struct {
uint16_t max_fault : 2;
uint16_t ct_polarity : 1;
uint16_t int_polarity : 1;
IntCtMode int_ct_mode : 1;
OperationMode op_mode : 2;
} bit;
};
//! Ñòðóêòóðà íàñòðàåâàåìûõ ïàðàìåòðîâ ìèêðîñõåìû ADT7310
struct Parameters {
typedef uint16_t OptionRegister;
static const unsigned int allowed_options = 1;
enum AllowedRegisters {
CONFIG,
};
OptionRegister option[allowed_options];
};
union TempReg {
uint16_t all;
struct {
uint16_t t_low : 1;
uint16_t t_high : 1;
uint16_t t_crit : 1;
uint16_t temp : 12;
uint16_t sign : 1;
} bit;
};
inline float toFloat(const TempReg & temp) {
const float k = 0.5;
return ( static_cast<float>( temp.bit.temp ) + (-2) * static_cast<float>( temp.bit.temp ) * temp.bit.sign ) * k;
}
} }}
#endif /* SOURCE_DRIVER_CHIPSET_ADT7310_H_ */