MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/chipset/PackagerADS1259Extended.hh
2024-06-07 11:12:56 +03:00

86 lines
3.1 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.

/*
* PackagerADS1259Extended.h
*
* Created on: 8 июл. 2020 г.
* Author: krugliy
*/
#ifndef UMLIBRARY_DRIVER_CHIPSET_PACKAGERADS1259EXTENDED_H_
#define UMLIBRARY_DRIVER_CHIPSET_PACKAGERADS1259EXTENDED_H_
#include <cstddef>
#include <stdint.h>
namespace driver {
namespace chipset {
struct PackagerADS1259Extended {
//На самом деле Data представляет из себя вот что:
struct RdataCrc {
uint32_t adc_result : 24;
uint32_t crc : 8;
static RdataCrc createRdataCrc(uint32_t data) { return { .adc_result = ((data & 0xFFul) << 16) | (data & 0xFF00ul) | ((data & 0xFF0000ul) >> 16), .crc = data >> 24 }; }
static uint16_t calcCrc(uint32_t data) { return ( data + (data >> 8) + (data >> 16) + 0x9B ) & 0xFF; }
static bool checkCrc(const RdataCrc & rdata) { return rdata.crc == calcCrc(rdata.adc_result); }
};
typedef uint32_t Data; //!<Тип данных используемых пользователем для хранения полезной информации.
typedef uint64_t Frame; //!<Тип данных отправляемый и получаемый по линии связи.
static const std::size_t FrameSize; //!<Фиксированный размер (в битах) кадра, передаваемого по линии связи.
//!Кодирование передаваемых данных.
static Frame encode();
//!Декодирование принятого кадра.
static Data decode( Frame frame );
typedef uint16_t RegAddress; //!<Тип адреса регистра в устройстве.
struct Packager {
typedef PackagerADS1259Extended::Frame Frame;
typedef PackagerADS1259Extended::Data Data;
enum : RegAddress {
RDATA = 0x12 //Read data by opcode
};
//!Упаковка данных во фрэйм.
Frame pack() const;
//!Распаковка данных из фрэйма.
Data unpack( Frame frame ) const;
};
//!Структура компановки адресного заголовка и СЛОВА данных.
struct LongCommandRegisterForm {
uint16_t second_opcode_byte : 8;
uint16_t first_opcode_byte : 8;
uint16_t data;
LongCommandRegisterForm(uint16_t first_opcode, uint16_t second_opcode) : second_opcode_byte(second_opcode), first_opcode_byte(first_opcode) {}
};
//!Структура компановки адресного заголовка и СЛОВА данных, для коротких команд.
struct ShortCommandRegisterForm {
uint16_t opcode_byte : 8;
uint32_t data;
static ShortCommandRegisterForm fromFrame(Frame frame);
ShortCommandRegisterForm(uint16_t opcode) : opcode_byte(opcode) {}
ShortCommandRegisterForm(): opcode_byte(0) {}
};
};
} /* namespace chipset */
} /* namespace driver */
#endif /* UMLIBRARY_DRIVER_CHIPSET_PACKAGERADS1259EXTENDED_HH_ */