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

103 lines
2.4 KiB
C++
Raw Permalink Normal View History

2024-06-07 11:12:56 +03:00
/*
* 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_ */