Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from bringup with daisy-chain bus #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ project(${APP_TARGET})
add_library(${APP_TARGET}
${_HDRS}
src/LTC681xBus.cpp
src/LTC681xChainBus.cpp
src/LTC681xChainBus.tpp
src/LTC681xParallelBus.cpp
)
target_include_directories(${APP_TARGET} PUBLIC include)
Expand Down
5 changes: 4 additions & 1 deletion include/LTC681xChainBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "LTC681xBus.h"

template<const unsigned int N_chips>
template<unsigned int N_chips>
class LTC681xChainBus : public LTC681xBus {
public:
LTC681xChainBus(SPI* spiDriver) : m_spiDriver(spiDriver) {};
Expand All @@ -21,3 +21,6 @@ class LTC681xChainBus : public LTC681xBus {
private:
SPI* m_spiDriver;
};

// https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file
#include "../src/LTC681xChainBus.tpp"
18 changes: 17 additions & 1 deletion include/LTC681xCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class StartCombinedCellVoltageGpioConversion : public LTC681xCommand {
AdcMode adcMode;
bool dischargePermitted;
uint16_t toValue() const {
return 0x086F | ((uint16_t)adcMode << 7) | ((uint16_t)dischargePermitted << 4);
return 0x046F | ((uint16_t)adcMode << 7) | ((uint16_t)dischargePermitted << 4);
}
};
using ADCVAX = StartCombinedCellVoltageGpioConversion;
Expand Down Expand Up @@ -347,3 +347,19 @@ class StartComm : public LTC681xCommand {
uint16_t toValue() const { return 0x0723; }
};
using STCOMM = StartComm;

class MuteDischarge : public LTC681xCommand {
public:
uint16_t toValue() const {
return 0x28;
}
};
using MUDIS = MuteDischarge;

class UnmuteDischarge : public LTC681xCommand {
public:
uint16_t toValue() const {
return 0x29;
}
};
using UMUDIS = UnmuteDischarge;
23 changes: 13 additions & 10 deletions src/LTC681xChainBus.cpp → src/LTC681xChainBus.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "LTC681xBus.h"
#include "mbed.h"

template<const unsigned int N_chips>
template<unsigned int N_chips>
LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::WakeupBus() {
// Pulse the CS once per chip, delaying the T_wake time between
for(uint8_t i = 0; i < N_chips; i++) {
Expand All @@ -18,7 +18,7 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::WakeupBus() {
return LTC681xBus::LTC681xBusStatus::Ok;
}

template<const unsigned int N_chips>
template<unsigned int N_chips>
LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendCommand(LTC681xBus::BusCommand cmd) {
//
// In daisy chain mode, to send a command we broadcast
Expand All @@ -39,7 +39,7 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendCommand(LTC681xBus::B
return LTC681xBus::LTC681xBusStatus::Ok;
}

template<const unsigned int N_chips>
template<unsigned int N_chips>
LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendDataCommand(LTC681xBus::BusCommand cmd, uint8_t* data) {
//
// In daisy chain mode, to send a command with data, we first
Expand All @@ -56,8 +56,9 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendDataCommand(LTC681xBu

// Create data value array
uint8_t dataBytes[N_chips * 8];
// Writing on a daisy chain means the last chip in the chain gets the first data sent - reverse here to keep the rest of the software sane
for (uint8_t chip = 0; chip < N_chips; chip++) {
LTC681xBus::getDataBytes(dataBytes + (chip * 8), data + (chip * 6));
LTC681xBus::getDataBytes(dataBytes + ((N_chips - 1 - chip) * 8), data + (chip * 6));
}

// Grab the bus and send our command
Expand All @@ -69,7 +70,7 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendDataCommand(LTC681xBu
return LTC681xBus::LTC681xBusStatus::Ok;
}

template<const unsigned int N_chips>
template<unsigned int N_chips>
LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendReadCommand(LTC681xBus::BusCommand cmd, uint8_t* data) {
//
// In daisy chain mode, to send a read command, we first send the
Expand Down Expand Up @@ -112,7 +113,7 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendReadCommand(LTC681xBu
return LTC681xBus::LTC681xBusStatus::Ok;
}

template <const unsigned int N_chips>
template<unsigned int N_chips>
LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendCommandAndPoll(BusCommand cmd, unsigned int timeout) {
//
// In daisy chain mode, to send a command we broadcast
Expand All @@ -132,7 +133,7 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendCommandAndPoll(BusCom
// Poll for ADC completion

// Send initial N isoSPI clock pulses
for(unsigned int i = 0; i < N_chips / 8; i++) {
for(unsigned int i = 0; i <= (N_chips / 8); i++) {
m_spiDriver->write(0xff);
}

Expand All @@ -145,7 +146,8 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendCommandAndPoll(BusCom
gotResponse = true;
break;
} else {
wait_us(LTC681x_POLL_DELAY);
// Use non-blocking wait since total conversion times are >1ms even for fastest conversion
ThisThread::sleep_for(1ms);
}
}
m_spiDriver->deselect();
Expand All @@ -157,7 +159,7 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::SendCommandAndPoll(BusCom
}
}

template<const unsigned int N_chips>
template<unsigned int N_chips>
LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::PollAdcCompletion(BusCommand cmd, unsigned int timeout) {
//
// In daisy chain mode, to send a command we broadcast
Expand Down Expand Up @@ -192,7 +194,8 @@ LTC681xBus::LTC681xBusStatus LTC681xChainBus<N_chips>::PollAdcCompletion(BusComm
gotResponse = true;
break;
} else {
wait_us(LTC681x_POLL_DELAY);
// Use non-blocking wait since total conversion times are >1ms even for fastest conversion
ThisThread::sleep_for(1ms);
}
}
m_spiDriver->deselect();
Expand Down