mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
in principle schedules packets
This commit is contained in:
parent
37f44709f9
commit
67e8c04314
8
DCC.cpp
8
DCC.cpp
@ -71,7 +71,13 @@ void DCC::begin() {
|
|||||||
|
|
||||||
// Add main and prog drivers to the main and prog packet sources (dcc-tracks).
|
// Add main and prog drivers to the main and prog packet sources (dcc-tracks).
|
||||||
std::vector<MotorDriver*> v;
|
std::vector<MotorDriver*> v;
|
||||||
v = MotorDriverContainer::mDC.getDriverType(RMT_MAIN|TIMER_MAIN);
|
|
||||||
|
v = MotorDriverContainer::mDC.getDriverType(RMT_MAIN);
|
||||||
|
|
||||||
|
v.front()->setChannel(new RMTChannel(v.front()->getSignalPin(), true));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (const auto& d: v) DCCTrack::mainTrack.addDriver(d);
|
for (const auto& d: v) DCCTrack::mainTrack.addDriver(d);
|
||||||
v = MotorDriverContainer::mDC.getDriverType(RMT_PROG|TIMER_PROG);
|
v = MotorDriverContainer::mDC.getDriverType(RMT_PROG|TIMER_PROG);
|
||||||
for (const auto& d: v) DCCTrack::progTrack.addDriver(d);
|
for (const auto& d: v) DCCTrack::progTrack.addDriver(d);
|
||||||
|
23
DCCRMT.cpp
23
DCCRMT.cpp
@ -62,7 +62,16 @@ void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) {
|
|||||||
tt->RMTinterrupt();
|
tt->RMTinterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
RMTChannel::RMTChannel(byte pin, byte ch, byte plen, bool isMain) {
|
RMTChannel::RMTChannel(byte pin, bool isMain) {
|
||||||
|
byte ch;
|
||||||
|
byte plen;
|
||||||
|
if (isMain) {
|
||||||
|
ch = 0;
|
||||||
|
plen = PREAMBLE_BITS_MAIN;
|
||||||
|
} else {
|
||||||
|
ch = 2;
|
||||||
|
plen = PREAMBLE_BITS_PROG;
|
||||||
|
}
|
||||||
|
|
||||||
// preamble
|
// preamble
|
||||||
preambleLen = plen+2; // plen 1 bits, one 0 bit and one EOF marker
|
preambleLen = plen+2; // plen 1 bits, one 0 bit and one EOF marker
|
||||||
@ -146,17 +155,19 @@ void RMTChannel::RMTprefill() {
|
|||||||
const byte transmitMask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
const byte transmitMask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||||
|
|
||||||
//bool RMTChannel::RMTfillData(const byte buffer[], byte byteCount, byte repeatCount=0) {
|
//bool RMTChannel::RMTfillData(const byte buffer[], byte byteCount, byte repeatCount=0) {
|
||||||
bool RMTChannel::RMTfillData(dccPacket packet) {
|
int RMTChannel::RMTfillData(dccPacket packet) {
|
||||||
// dataReady: Signals to then interrupt routine. It is set when
|
// dataReady: Signals to then interrupt routine. It is set when
|
||||||
// we have data in the channel buffer which can be copied out
|
// we have data in the channel buffer which can be copied out
|
||||||
// to the HW. dataRepeat on the other hand signals back to
|
// to the HW. dataRepeat on the other hand signals back to
|
||||||
// the caller of this function if the data has been sent enough
|
// the caller of this function if the data has been sent enough
|
||||||
// times (0 to 3 means 1 to 4 times in total).
|
// times (0 to 3 means 1 to 4 times in total).
|
||||||
if (dataReady == true || dataRepeat > 0) // we have still old work to do
|
if (dataReady == true)
|
||||||
return false;
|
return 1000;
|
||||||
|
if (dataRepeat > 0) // we have still old work to do
|
||||||
|
return dataRepeat;
|
||||||
if (DATA_LEN(packet.length) > maxDataLen) { // this would overun our allocated memory for data
|
if (DATA_LEN(packet.length) > maxDataLen) { // this would overun our allocated memory for data
|
||||||
DIAG(F("Can not convert DCC bytes # %d to DCC bits %d, buffer too small"), packet.length, maxDataLen);
|
DIAG(F("Can not convert DCC bytes # %d to DCC bits %d, buffer too small"), packet.length, maxDataLen);
|
||||||
return false; // something very broken, can not convert packet
|
return -1; // something very broken, can not convert packet
|
||||||
}
|
}
|
||||||
|
|
||||||
byte *buffer = packet.data;
|
byte *buffer = packet.data;
|
||||||
@ -177,7 +188,7 @@ bool RMTChannel::RMTfillData(dccPacket packet) {
|
|||||||
dataLen = bitcounter;
|
dataLen = bitcounter;
|
||||||
dataReady = true;
|
dataReady = true;
|
||||||
dataRepeat = packet.repeat+1; // repeatCount of 0 means send once
|
dataRepeat = packet.repeat+1; // repeatCount of 0 means send once
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR RMTChannel::RMTinterrupt() {
|
void IRAM_ATTR RMTChannel::RMTinterrupt() {
|
||||||
|
10
DCCRMT.h
10
DCCRMT.h
@ -32,16 +32,10 @@
|
|||||||
|
|
||||||
class RMTChannel {
|
class RMTChannel {
|
||||||
public:
|
public:
|
||||||
inline RMTChannel(byte pin, bool isMain) {
|
RMTChannel(byte pin, bool isMain);
|
||||||
if (isMain)
|
|
||||||
RMTChannel(pin, 0, PREAMBLE_BITS_MAIN, 1);
|
|
||||||
else
|
|
||||||
RMTChannel(pin, 2, PREAMBLE_BITS_PROG, 0);
|
|
||||||
};
|
|
||||||
RMTChannel(byte pin, byte ch, byte plen, bool isProg);
|
|
||||||
void IRAM_ATTR RMTinterrupt();
|
void IRAM_ATTR RMTinterrupt();
|
||||||
void RMTprefill();
|
void RMTprefill();
|
||||||
bool RMTfillData(dccPacket packet);
|
int RMTfillData(dccPacket packet);
|
||||||
//bool RMTfillData(const byte buffer[], byte byteCount, byte repeatCount);
|
//bool RMTfillData(const byte buffer[], byte byteCount, byte repeatCount);
|
||||||
|
|
||||||
static RMTChannel mainRMTChannel;
|
static RMTChannel mainRMTChannel;
|
||||||
|
@ -38,11 +38,14 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8
|
|||||||
getFastPin(F("POWER"),powerPin,fastPowerPin);
|
getFastPin(F("POWER"),powerPin,fastPowerPin);
|
||||||
pinMode(powerPin, OUTPUT);
|
pinMode(powerPin, OUTPUT);
|
||||||
|
|
||||||
if (dtype == RMT_MAIN) {
|
if (dtype & (RMT_MAIN | RMT_PROG)) {
|
||||||
signalPin=signal_pin;
|
signalPin=signal_pin;
|
||||||
|
/*
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
rmtChannel = new RMTChannel(signalPin, true); // true: isMain
|
//rmtChannel = new RMTChannel(signalPin, 0, PREAMBLE_BITS_MAIN, true); // true: isMain
|
||||||
|
rmtChannel = new RMTChannel(signalPin, dtype == RMT_MAIN); // true: isMain
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
dualSignal=false;
|
dualSignal=false;
|
||||||
} else if (dtype & (TIMER_MAIN | TIMER_PROG)) {
|
} else if (dtype & (TIMER_MAIN | TIMER_PROG)) {
|
||||||
signalPin=signal_pin;
|
signalPin=signal_pin;
|
||||||
@ -209,7 +212,10 @@ void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & res
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MotorDriver::schedulePacket(dccPacket packet) {
|
bool MotorDriver::schedulePacket(dccPacket packet) {
|
||||||
if(!rmtChannel) return true; // fake success if functionality is not there
|
if(!rmtChannel) {
|
||||||
|
DIAG(F("no rmt Channel"));
|
||||||
|
return true; // fake success if functionality is not there
|
||||||
|
}
|
||||||
|
|
||||||
outQueue.push(packet);
|
outQueue.push(packet);
|
||||||
uint16_t size = outQueue.size();
|
uint16_t size = outQueue.size();
|
||||||
@ -220,9 +226,17 @@ bool MotorDriver::schedulePacket(dccPacket packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::loop() {
|
void MotorDriver::loop() {
|
||||||
if (rmtChannel && !outQueue.empty() && rmtChannel->RMTfillData(outQueue.front()))
|
int r;
|
||||||
|
if (rmtChannel && !outQueue.empty()) {
|
||||||
|
r = rmtChannel->RMTfillData(outQueue.front());
|
||||||
|
if (r == 0) {
|
||||||
|
DIAG(F("r=OK"));
|
||||||
outQueue.pop();
|
outQueue.pop();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
DIAG(F("r=%d"), r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MotorDriverContainer::MotorDriverContainer(const FSH * motorShieldName,
|
MotorDriverContainer::MotorDriverContainer(const FSH * motorShieldName,
|
||||||
MotorDriver *m0,
|
MotorDriver *m0,
|
||||||
|
@ -83,12 +83,16 @@ class MotorDriver {
|
|||||||
static bool commonFaultPin; // This is a stupid motor shield which has only a common fault pin for both outputs
|
static bool commonFaultPin; // This is a stupid motor shield which has only a common fault pin for both outputs
|
||||||
inline byte getFaultPin() {
|
inline byte getFaultPin() {
|
||||||
return faultPin;
|
return faultPin;
|
||||||
}
|
};
|
||||||
|
inline byte getSignalPin() {
|
||||||
|
return signalPin;
|
||||||
|
};
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
void loop();
|
void loop();
|
||||||
inline driverType type() { return dtype; };
|
inline driverType type() { return dtype; };
|
||||||
inline void setType(driverType t) { dtype = t; };
|
inline void setType(driverType t) { dtype = t; };
|
||||||
bool schedulePacket(dccPacket packet);
|
bool schedulePacket(dccPacket packet);
|
||||||
|
inline void setChannel(RMTChannel * r) { rmtChannel = r; };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user