WIP: PL PCDU #142

Closed
muellerr wants to merge 118 commits from mueller/plpcdu-sus-updates into develop
5 changed files with 58 additions and 31 deletions
Showing only changes of commit a2ec4a4828 - Show all commits

View File

@ -350,62 +350,62 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI
SpiCookie* spiCookie = SpiCookie* spiCookie =
new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE,
spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler0 = SusHandler* susHandler0 =
new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_0); new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_0);
spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler1 = SusHandler* susHandler1 =
new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_1); new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_1);
spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler2 = SusHandler* susHandler2 =
new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_2); new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_2);
spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string(q7s::SPI_DEFAULT_DEV), spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string(q7s::SPI_DEFAULT_DEV),
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler3 = SusHandler* susHandler3 =
new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_3); new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_3);
spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string(q7s::SPI_DEFAULT_DEV), spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string(q7s::SPI_DEFAULT_DEV),
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler4 = SusHandler* susHandler4 =
new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_4); new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_4);
spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string(q7s::SPI_DEFAULT_DEV), spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string(q7s::SPI_DEFAULT_DEV),
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler5 = SusHandler* susHandler5 =
new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_5); new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_5);
spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler6 = SusHandler* susHandler6 =
new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_6); new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_6);
spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler7 = SusHandler* susHandler7 =
new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_7); new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_7);
spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler8 = SusHandler* susHandler8 =
new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_8); new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_8);
spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler9 = SusHandler* susHandler9 =
new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_9); new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_9);
spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookie, SusHandler* susHandler10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookie,
gpioComIF, gpioIds::CS_SUS_10); gpioComIF, gpioIds::CS_SUS_10);
spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV, spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV,
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ);
SusHandler* susHandler11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookie, SusHandler* susHandler11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookie,
gpioComIF, gpioIds::CS_SUS_11); gpioComIF, gpioIds::CS_SUS_11);
static_cast<void>(susHandler0); static_cast<void>(susHandler0);

View File

@ -23,6 +23,12 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 976'000;
static constexpr uint32_t L3G_TRANSITION_DELAY = 5000; static constexpr uint32_t L3G_TRANSITION_DELAY = 5000;
static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3;
/**
* Some MAX1227 could not be reached with frequencies around 4 MHz. Maybe this is caused by
* the decoder and buffer circuits. Thus frequency is here defined to 1 MHz.
*/
static const uint32_t SUS_MAX1227_SPI_FREQ = 1'000'000;
static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000;
static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3;

View File

@ -34,7 +34,7 @@ void SusHandler::doStartUp() {
setMode(_MODE_TO_ON); setMode(_MODE_TO_ON);
#endif #endif
commandExecuted = false; commandExecuted = false;
if (clkMode == Modes::INT_CLOCKED) { if (clkMode == ClkModes::INT_CLOCKED) {
comState = ComStates::START_INT_CLOCKED_CONVERSIONS; comState = ComStates::START_INT_CLOCKED_CONVERSIONS;
} else { } else {
comState = ComStates::EXT_CLOCKED_CONVERSIONS; comState = ComStates::EXT_CLOCKED_CONVERSIONS;
@ -68,6 +68,10 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
comState = ComStates::START_INT_CLOCKED_CONVERSIONS; comState = ComStates::START_INT_CLOCKED_CONVERSIONS;
return buildCommandFromCommand(*id, nullptr, 0); return buildCommandFromCommand(*id, nullptr, 0);
} }
case (ComStates::EXT_CLOCKED_TEMP): {
*id = SUS::READ_EXT_TIMED_TEMPS;
return buildCommandFromCommand(*id , nullptr, 0);
}
} }
return NOTHING_TO_SEND; return NOTHING_TO_SEND;
} }
@ -85,7 +89,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
size_t commandDataLen) { size_t commandDataLen) {
switch (deviceCommand) { switch (deviceCommand) {
case (SUS::WRITE_SETUP): { case (SUS::WRITE_SETUP): {
if (clkMode == Modes::INT_CLOCKED) { if (clkMode == ClkModes::INT_CLOCKED) {
cmdBuffer[0] = SUS::SETUP_INT_CLOKED; cmdBuffer[0] = SUS::SETUP_INT_CLOKED;
} else { } else {
cmdBuffer[0] = SUS::SETUP_EXT_CLOCKED; cmdBuffer[0] = SUS::SETUP_EXT_CLOCKED;
@ -118,6 +122,13 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
rawPacketLen = SUS::SIZE_READ_EXT_CONVERSIONS; rawPacketLen = SUS::SIZE_READ_EXT_CONVERSIONS;
return RETURN_OK; return RETURN_OK;
} }
case (SUS::READ_EXT_TIMED_TEMPS): {
cmdBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, true);
std::memset(cmdBuffer + 1, 0, 24);
rawPacket = cmdBuffer;
rawPacketLen = 25;
break;
}
default: default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
} }
@ -125,12 +136,13 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
} }
void SusHandler::fillCommandAndReplyMap() { void SusHandler::fillCommandAndReplyMap() {
this->insertInCommandAndReplyMap(SUS::WRITE_SETUP, 1); insertInCommandAndReplyMap(SUS::WRITE_SETUP, 1);
this->insertInCommandAndReplyMap(SUS::START_INT_TIMED_CONVERSIONS, 1); insertInCommandAndReplyMap(SUS::START_INT_TIMED_CONVERSIONS, 1);
this->insertInCommandAndReplyMap(SUS::READ_INT_TIMED_CONVERSIONS, 1, &dataset, insertInCommandAndReplyMap(SUS::READ_INT_TIMED_CONVERSIONS, 1, &dataset,
SUS::SIZE_READ_INT_CONVERSIONS); SUS::SIZE_READ_INT_CONVERSIONS);
this->insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_CONVERSIONS, 1, &dataset, insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_CONVERSIONS, 1, &dataset,
SUS::SIZE_READ_EXT_CONVERSIONS); SUS::SIZE_READ_EXT_CONVERSIONS);
insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_TEMPS, 1);
} }
ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t remainingSize, ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t remainingSize,
@ -171,9 +183,19 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8
dataset.ain3 = (packet[7] << 8) | packet[8]; dataset.ain3 = (packet[7] << 8) | packet[8];
dataset.ain4 = (packet[9] << 8) | packet[10]; dataset.ain4 = (packet[9] << 8) | packet[10];
dataset.ain5 = (packet[11] << 8) | packet[12]; dataset.ain5 = (packet[11] << 8) | packet[12];
// Read temperature in next read cycle
if(clkMode == ClkModes::EXT_CLOCKED_WITH_TEMP) {
comState = ComStates::EXT_CLOCKED_TEMP;
}
printDataset(); printDataset();
break; break;
} }
case (SUS::READ_EXT_TIMED_TEMPS): {
PoolReadGuard readSet(&dataset);
dataset.temperatureCelcius = (packet[23] << 8) | packet[24];
comState = ComStates::EXT_CLOCKED_CONVERSIONS;
break;
}
default: { default: {
sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;

View File

@ -23,7 +23,7 @@
*/ */
class SusHandler : public DeviceHandlerBase { class SusHandler : public DeviceHandlerBase {
public: public:
enum Modes { INT_CLOCKED, EXT_CLOCKED }; enum ClkModes { INT_CLOCKED, EXT_CLOCKED, EXT_CLOCKED_WITH_TEMP };
enum ScanModes : uint8_t { enum ScanModes : uint8_t {
CHANNELS_0_TO_N = 0b00, CHANNELS_0_TO_N = 0b00,
@ -71,6 +71,7 @@ class SusHandler : public DeviceHandlerBase {
IDLE, IDLE,
WRITE_SETUP, WRITE_SETUP,
EXT_CLOCKED_CONVERSIONS, EXT_CLOCKED_CONVERSIONS,
EXT_CLOCKED_TEMP,
START_INT_CLOCKED_CONVERSIONS, START_INT_CLOCKED_CONVERSIONS,
READ_INT_CLOCKED_CONVERSIONS READ_INT_CLOCKED_CONVERSIONS
}; };
@ -82,7 +83,9 @@ class SusHandler : public DeviceHandlerBase {
bool commandExecuted = false; bool commandExecuted = false;
SUS::SusDataset dataset; SUS::SusDataset dataset;
Modes clkMode = Modes::INT_CLOCKED; // Read temperature in each alternating communication step when using
// externally clocked mode
ClkModes clkMode = ClkModes::EXT_CLOCKED_WITH_TEMP;
uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE];
ComStates comState = ComStates::IDLE; ComStates comState = ComStates::IDLE;

View File

@ -8,27 +8,23 @@
namespace SUS { namespace SUS {
/**
* Some MAX1227 could not be reached with frequencies around 4 MHz. Maybe this is caused by
* the decoder and buffer circuits. Thus frequency is here defined to 1 MHz.
*/
static const uint32_t MAX1227_SPI_FREQ = 1000000;
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
static const DeviceCommandId_t WRITE_SETUP = 0x1; static const DeviceCommandId_t WRITE_SETUP = 1;
/** /**
* This command initiates the ADC conversion for all channels including the internal * This command initiates the ADC conversion for all channels including the internal
* temperature sensor. * temperature sensor.
*/ */
static const DeviceCommandId_t START_INT_TIMED_CONVERSIONS = 0x2; static const DeviceCommandId_t START_INT_TIMED_CONVERSIONS = 2;
/** /**
* This command reads the internal fifo which holds the temperature and the channel * This command reads the internal fifo which holds the temperature and the channel
* conversions. * conversions.
*/ */
static constexpr DeviceCommandId_t READ_INT_TIMED_CONVERSIONS = 0x3; static constexpr DeviceCommandId_t READ_INT_TIMED_CONVERSIONS = 3;
static constexpr DeviceCommandId_t READ_EXT_TIMED_CONVERSIONS = 0x4; static constexpr DeviceCommandId_t READ_EXT_TIMED_CONVERSIONS = 4;
static constexpr DeviceCommandId_t READ_EXT_TIMED_TEMPS = 5;
/** /**
* @brief This is the configuration byte which will be written to the setup register after * @brief This is the configuration byte which will be written to the setup register after
@ -61,7 +57,7 @@ static const uint8_t SIZE_READ_INT_CONVERSIONS = 14;
// 6 * conv byte, 6 * 0 and one trailing zero // 6 * conv byte, 6 * 0 and one trailing zero
static constexpr uint8_t SIZE_READ_EXT_CONVERSIONS = 13; static constexpr uint8_t SIZE_READ_EXT_CONVERSIONS = 13;
static const uint8_t MAX_CMD_SIZE = 16; static const uint8_t MAX_CMD_SIZE = 32;
static const uint8_t POOL_ENTRIES = 7; static const uint8_t POOL_ENTRIES = 7;