...
 
Commits (2)
......@@ -653,6 +653,17 @@ static void testTableLookupU1632(void **state) {
assert_int_equal(data, 4172951178);
}
static void testRatio16(void **state) {
(void) state;
uint16_t a = 100;
uint16_t b = 90;
uint16_t scaler = 100;
uint16_t ratio = ratio16(b, a, scaler);
assert_int_equal(ratio, 90);
}
int main(void) {
const UnitTest tests[] = {
......@@ -676,7 +687,8 @@ int main(void) {
unit_test(testAngleOffsetMath),
unit_test(testAngleOffsetMathNegative),
unit_test(testTableLookupINT16),
unit_test(testTableLookupU1632)
unit_test(testTableLookupU1632),
unit_test(testRatio16)
};
return run_tests(tests);
......
......@@ -53,7 +53,7 @@ MasterConfig Config CONFIG_DATA = {
.TPSMinimum = TPS_MINIMUM,
.TPSMaximum = TPS_MAXIMUM
},
.inputCaptureSettings = {
.inputCaptureSettings.inputCaptureRegs = {
/* Bit setting seems to be broken for a union */
// .inputCaptureEdgesTCTL4.bits = {
// .ECT0captureRising = ECT0_CAPTURE_RISING,
......
......@@ -96,8 +96,8 @@
#define ECT4_CAPTURE_FALLING TRUE /* No effect reserved by XGate */
#define ECT5_CAPTURE_RISING TRUE
#define ECT5_CAPTURE_FALLING TRUE
#define ECT6_CAPTURE_RISING TRUE
#define ECT6_CAPTURE_FALLING TRUE
#define ECT6_CAPTURE_RISING FALSE /* MAF 255-12KHz, in DC mode with a 9926 */
#define ECT6_CAPTURE_FALLING TRUE /* TODO consider xgate ISR */
#define ECT7_CAPTURE_RISING TRUE
#define ECT7_CAPTURE_FALLING TRUE
......
......@@ -108,7 +108,8 @@ uint8_t readFlexFuelEth() {
return frequency;
}
void updateCapturedInput(uint8_t edge, CapturedInputData *dataStore, ExtendedTime *previousStamp, ExtendedTime *captureStamp) {
void updateCapturedInput(uint8_t edgeState, uint8_t channel, CapturedInputData *dataStore,
ExtendedTime *previousStamp, ExtendedTime *captureStamp) {
++dataStore->ISRcount;
/* Update Angle Data */
DecoderStats *decoderStats = getDecoderStats();
......@@ -121,7 +122,7 @@ void updateCapturedInput(uint8_t edge, CapturedInputData *dataStore, ExtendedTim
uint16_t pw = diffUint32(captureStamp->time, previousStamp->time);
/* Is edge high? */
if (edge == 0) {
if (edgeState == 0) {
dataStore->periodHighTicks = pw;
/* Update Angle Data */
dataStore->capturedAngleHigh = angle;
......@@ -129,9 +130,26 @@ void updateCapturedInput(uint8_t edge, CapturedInputData *dataStore, ExtendedTim
dataStore->periodLowTicks = pw;
dataStore->capturedAngleLow = angle;
}
/* calc frequency */
dataStore->frequencyHz = ((uint32_t)TICKS_PER_SECOND) /
((uint32_t)dataStore->periodLowTicks + dataStore->periodHighTicks);
previousStamp->time = captureStamp->time;
/* Check if we are capturing on both rising and falling edges */
uint8_t configMask;
if (channel > 3) {
channel -= 4;
configMask = Config.inputCaptureSettings.inputCaptureRegs.inputCaptureEdgesTCTL3.value >>
(channel * 2);
} else {
configMask = Config.inputCaptureSettings.inputCaptureRegs.inputCaptureEdgesTCTL4.value >>
(channel * 2);
}
configMask &= (BIT0 | BIT1);
if (configMask == (BIT0 | BIT1)) {
dataStore->frequencyHz = ((uint32_t)TICKS_PER_SECOND) /
((uint32_t)dataStore->periodLowTicks + dataStore->periodHighTicks);
} else {
dataStore->frequencyHz = ((uint32_t)TICKS_PER_SECOND) / diffUint32(captureStamp->time,
previousStamp->time);
}
}
......@@ -47,7 +47,7 @@
\
uint8_t isPinHigh = PTIT & (1 << CH); \
/* TODO add config for polarity setting */ \
updateCapturedInput(isPinHigh, &capturedInputData_g[TC##CH##_DATA_INDEX], &savedStamp, &timeStamp); \
updateCapturedInput(isPinHigh, CH, &capturedInputData_g[TC##CH##_DATA_INDEX], &savedStamp, &timeStamp); \
savedStamp.time = timeStamp.time; \
TFLG1 = (1 << CH); /* Clear Interrupt Last */
......
......@@ -210,8 +210,7 @@ void PrimaryEngineAngle() {
}
} else {
/* TODO (skeys) we may want some constraint here to qualify
* a valid "even tooth".
/* Find even teeth here.
*/
if (ratioBetweenCurrentAndLast >= Config.tachDecoderSettings.inputEventCrankingTollerance) {
++consecutiveEvenTeethFound;
......@@ -223,10 +222,6 @@ void PrimaryEngineAngle() {
decoderStats_g.lockLossCauseID = PRIMARY_EVENT_TOO_LATE_UNSYNC;
}
}
/* TODO (skeys) we may want to clear the tooth count if we
* get a window that's below the cranking threshold.
*/
}
decoderStats_g.instantTicksPerDegree = ticksPerDegree; /* Record for cranking RPM log */
}
......
......@@ -196,15 +196,15 @@ typedef struct{
}GPIOChannelFlags; /* sizeof() reports 1 byte */
typedef struct GPoutput{
uint16_t *varPointer; /* Pointer to the register or variable containing the upper or lower trigger value */
uint16_t *varPointer; /* Pointer to the register or variable containing the upper or lower trigger value */
InputAction inputAction; /* Pointer to the function to be called when an input pin changes */
uint16_t upperBoundary;
uint16_t lowerBoundary;
uint8_t childIndex; /* If event has a child, its child index should be here, if not this index should match the GPIO position */
uint8_t conditionCount; /* Number of conditions that must be true */
uint8_t *reg; /* Destination register/port */
uint8_t mask; /* Bit mask to apply */
uint8_t derateLevel;
uint16_t upperBoundary;
uint16_t lowerBoundary;
uint8_t childIndex; /* If event has a child, its child index should be here, if not this index should match the GPIO position */
uint8_t conditionCount; /* Number of conditions that must be true */
uint8_t *reg; /* Destination register/port */
uint8_t mask; /* Bit mask to apply */
uint8_t derateLevel;
GPIOChannelFlags flags; /* Polarity, Direction, etc. */
}GPIOchannel;
......@@ -255,16 +255,20 @@ typedef struct {
uint8_t ECT0normal :1;
}ReportPolarity_bits;
typedef union {
ReportPolarity_bits bits;
uint8_t value;
}ReportPolarity;
//typedef union {
// ReportPolarity_bits bits;
// uint8_t value;
//}ReportPolarity;
/* In reg space 4 represents 0-3, 3 4-7 */
typedef struct {
InputCaptureEdgesTCTL4 inputCaptureEdgesTCTL4;
InputCaptureEdgesTCTL3 inputCaptureEdgesTCTL3;
ReportPolarity reportPolarity;
}InputCaptureRegs;
typedef union {
InputCaptureRegs inputCaptureRegs;
uint16_t inputCaptureValues;
}InputCaptureSettings;
typedef struct{
......
......@@ -46,7 +46,8 @@ inline void readRTADCValues(SyncedData *buffer) TEXT;
inline uint8_t updateAngleDependantData(DecoderStats *decoderStats, uint8_t numOutputs, CylinderConfig*) TEXT;
void sampleAllSyncData() TEXT;
uint8_t readFlexFuelEth() TEXT;
void updateCapturedInput(uint8_t flags, CapturedInputData *dataStore, ExtendedTime *previousStamp, ExtendedTime *captureStamp) TEXT;
void updateCapturedInput(uint8_t flags, uint8_t channel, CapturedInputData *dataStore,
ExtendedTime *previousStamp, ExtendedTime *captureStamp) TEXT;
#else
......
......@@ -70,6 +70,13 @@ typedef struct {
uint16_t res15 :1;
}SensorFaults;
typedef enum {
ECT_CAPTURE_NONE = 0,
ECT_CAPTURE_RISING = 1,
ECT_CAPTURE_FALLING = 3,
ECT_CAPTURE_RISING_AND_FALLING = 4
}ECTedgeConfig;
typedef union {
uint32_t time;
uint16_t timeWord[2];
......
......@@ -63,7 +63,7 @@ inline uint16_t diffUint16(uint16_t head, uint16_t tail) {
}
static
inline uint8_t diffUint8(uint8_t head, uint8_t tail) {
inline uint8_t diffUint8(const uint8_t head, const uint8_t tail) {
if(head >= tail) {
return head - tail;
} else {
......@@ -72,7 +72,7 @@ inline uint8_t diffUint8(uint8_t head, uint8_t tail) {
}
static
inline uint32_t diffUint32(uint32_t head, uint32_t tail) {
inline uint32_t diffUint32(const uint32_t head, const uint32_t tail) {
if(head >= tail) {
return head - tail;
} else {
......@@ -81,7 +81,7 @@ inline uint32_t diffUint32(uint32_t head, uint32_t tail) {
}
static
inline uint16_t angleAdd(uint16_t angle1, uint16_t angle2) {
inline uint16_t angleAdd(const uint16_t angle1, const uint16_t angle2) {
uint32_t angle = angle1 + angle2;
if (angle >= ENGINE_ANGLE_S(720)) {
......@@ -92,7 +92,7 @@ inline uint16_t angleAdd(uint16_t angle1, uint16_t angle2) {
}
static
inline uint16_t ratio16(uint16_t value1, uint16_t value2, uint16_t scaler) {
inline uint16_t ratio16(const uint16_t value1, const uint16_t value2, const uint16_t scaler) {
uint16_t scaledPercent;
if (value1 > value2) {
......
......@@ -333,8 +333,8 @@ void initECTchannels(InputCaptureSettings *settings) {
/* Set all ECT to capture on rising and falling.
* These settings may be overridden by the decoder.
*/
TCTL3 = settings->inputCaptureEdgesTCTL3.value;
TCTL4 = settings->inputCaptureEdgesTCTL4.value;
TCTL3 = settings->inputCaptureRegs.inputCaptureEdgesTCTL3.value;
TCTL4 = settings->inputCaptureRegs.inputCaptureEdgesTCTL4.value;
TIE = 0xFF; /* enable all ECT interrupts */
}
......