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

103 lines
2.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.

/*
* PinIOOverride.h
*
* Created on: 18 июл. 2019 г.
* Author: titov
*/
#ifndef SOURCE_DRIVER_PINIOOVERRIDE_H_
#define SOURCE_DRIVER_PINIOOVERRIDE_H_
#include "../peripheral/IGpioOverride.hh"
namespace driver {
template<typename PortType>
class PinIOOverride : public peripheral::IGpioOverride {
public:
typedef unsigned short Id;
struct Input {
PortType data;
};
struct Output {
PortType priority;
PortType overriding;
PortType data;
};
PinIOOverride( Id id, bool priority, const volatile Input & input, volatile Output & output );
bool getOverrideStatus() const override;
void setupOverride() override;
void setOverrideValue(TOutValue value) override;
bool getHidenValue() const override;
void resetOverride() override;
private:
const volatile Input & input;
volatile Output & output;
const PortType mask;
};
}
template<typename PortType>
inline driver::PinIOOverride<PortType>::PinIOOverride(
Id id, bool priority, const volatile Input & input, volatile Output & output ) :
input(input), output(output), mask( static_cast<PortType>(1) << id ) {
if( priority )
output.priority |= mask;
}
template<typename PortType>
inline bool driver::PinIOOverride<PortType>::getOverrideStatus() const {
return output.overriding & mask;
}
template<typename PortType>
inline void driver::PinIOOverride<PortType>::setupOverride() {
output.data = input.data;
output.overriding |= mask;
}
template<typename PortType>
inline void driver::PinIOOverride<PortType>::setOverrideValue(TOutValue value) {
switch(value) {
case hi_z: {
output.data = input.data;
} break;
case high: {
output.data |= mask;
} break;
case low: {
output.data &= ~mask;
} break;
}
}
template<typename PortType>
inline bool driver::PinIOOverride<PortType>::getHidenValue() const {
return input.data & mask;
}
template<typename PortType>
inline void driver::PinIOOverride<PortType>::resetOverride() {
output.overriding &= ~mask;
}
#endif /* SOURCE_DRIVER_PINIOOVERRIDE_H_ */