Change freeRam() to unsigned int
This commit is contained in:
parent
aa879ec0d5
commit
3d2a692d53
|
@ -2270,7 +2270,7 @@ cmdtestspk450dc = "E\x03\x0C"
|
|||
advance = scalar, S08, 22, "deg", 1.000, 0.000
|
||||
tps = scalar, U08, 23, "%", 1.000, 0.000
|
||||
loopsPerSecond = scalar, U16, 24, "loops", 1.000, 0.000
|
||||
freeRAM = scalar, S16, 26, "bytes", 1.000, 0.000
|
||||
freeRAM = scalar, U16, 26, "bytes", 1.000, 0.000
|
||||
batCorrection = scalar, U08, 28, "%", 1.000, 0.000
|
||||
spark = scalar, U08, 29, "bits", 1.000, 0.000
|
||||
launchHard = bits, U08, 29, [0:0]
|
||||
|
|
|
@ -230,7 +230,7 @@ struct statuses {
|
|||
volatile unsigned int loopsPerSecond;
|
||||
boolean launchingSoft; //True when in launch control soft limit mode
|
||||
boolean launchingHard; //True when in launch control hard limit mode
|
||||
int freeRAM;
|
||||
uint16_t freeRAM;
|
||||
unsigned int clutchEngagedRPM;
|
||||
bool flatShiftingHard;
|
||||
volatile byte startRevolutions; //A counter for how many revolutions have been completed since sync was achieved.
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
These are some utility functions and variables used through the main code
|
||||
*/
|
||||
*/
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
int freeRam ();
|
||||
uint16_t freeRam ();
|
||||
void setPinMapping(byte boardID);
|
||||
unsigned int PW();
|
||||
unsigned int PW_SD();
|
||||
|
|
|
@ -7,15 +7,18 @@
|
|||
|
||||
/*
|
||||
Returns how much free dynamic memory exists (between heap and stack)
|
||||
This function is one big MISRA violation. MISRA advisories forbid directly poking at memory addresses, however there is no other way of determining heap size on embedded systems.
|
||||
*/
|
||||
#include "utils.h"
|
||||
|
||||
int freeRam ()
|
||||
uint16_t freeRam ()
|
||||
{
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
extern int __heap_start, *__brkval;
|
||||
int v;
|
||||
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
||||
uint16_t v;
|
||||
|
||||
return (uint16_t) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
||||
|
||||
#elif defined(CORE_TEENSY)
|
||||
uint32_t stackTop;
|
||||
uint32_t heapTop;
|
||||
|
@ -370,6 +373,7 @@ void setPinMapping(byte boardID)
|
|||
pinFan = 47; //Pin for the fan output
|
||||
pinFuelPump = 4; //Fuel pump output
|
||||
pinTachOut = 49; //Tacho output pin
|
||||
break;
|
||||
|
||||
case 30:
|
||||
//Pin mappings as per the dazv6 shield
|
||||
|
@ -522,8 +526,7 @@ void setPinMapping(byte boardID)
|
|||
pinMode(pinTrigger2, INPUT);
|
||||
pinMode(pinTrigger3, INPUT);
|
||||
pinMode(pinFlex, INPUT_PULLUP); //Standard GM / Continental flex sensor requires pullup
|
||||
// pinMode(pinLaunch, INPUT_PULLUP); //This should work for both NO and NC grounding switches
|
||||
if (configPage3.lnchPullRes) {
|
||||
if (configPage3.lnchPullRes == true) {
|
||||
pinMode(pinLaunch, INPUT_PULLUP);
|
||||
}
|
||||
else {
|
||||
|
@ -565,30 +568,31 @@ unsigned int PW(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen)
|
|||
|
||||
//100% float free version, does sacrifice a little bit of accuracy, but not much.
|
||||
iVE = ((unsigned int)VE << 7) / 100;
|
||||
if ( configPage1.multiplyMAP ) {
|
||||
if ( configPage1.multiplyMAP == true ) {
|
||||
iMAP = ((unsigned int)MAP << 7) / currentStatus.baro; //Include multiply MAP (vs baro) if enabled
|
||||
}
|
||||
if ( configPage1.includeAFR && (configPage3.egoType == 2)) {
|
||||
if ( (configPage1.includeAFR == true) && (configPage3.egoType == 2)) {
|
||||
iAFR = ((unsigned int)currentStatus.O2 << 7) / currentStatus.afrTarget; //Include AFR (vs target) if enabled
|
||||
}
|
||||
iCorrections = (corrections << 7) / 100;
|
||||
|
||||
|
||||
unsigned long intermediate = ((long)REQ_FUEL * (long)iVE) >> 7; //Need to use an intermediate value to avoid overflowing the long
|
||||
if ( configPage1.multiplyMAP ) {
|
||||
intermediate = (intermediate * iMAP) >> 7;
|
||||
if ( configPage1.multiplyMAP == true ) {
|
||||
intermediate = (intermediate * (unsigned long)iMAP) >> 7;
|
||||
}
|
||||
if ( configPage1.includeAFR && (configPage3.egoType == 2)) {
|
||||
intermediate = (intermediate * iAFR) >> 7; //EGO type must be set to wideband for this to be used
|
||||
if ( (configPage1.includeAFR == true) && (configPage3.egoType == 2) ) {
|
||||
intermediate = (intermediate * (unsigned long)iAFR) >> 7; //EGO type must be set to wideband for this to be used
|
||||
}
|
||||
intermediate = (intermediate * iCorrections) >> 7;
|
||||
if (intermediate == 0) {
|
||||
return 0; //If the pulsewidth is 0, we return here before the opening time gets added
|
||||
}
|
||||
|
||||
intermediate += injOpen; //Add the injector opening time
|
||||
if ( intermediate > 65535) {
|
||||
intermediate = 65535; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS
|
||||
intermediate = (intermediate * (unsigned long)iCorrections) >> 7;
|
||||
if (intermediate != 0)
|
||||
{
|
||||
//If intermeditate is not 0, we need to add the opening time (0 typically indicates that one of the full fuel cuts is active)
|
||||
intermediate += injOpen; //Add the injector opening time
|
||||
if ( intermediate > 65535)
|
||||
{
|
||||
intermediate = 65535; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS
|
||||
}
|
||||
}
|
||||
return (unsigned int)(intermediate);
|
||||
|
||||
|
@ -603,9 +607,5 @@ unsigned int PW_SD(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen
|
|||
|
||||
unsigned int PW_AN(int REQ_FUEL, byte VE, byte TPS, int corrections, int injOpen)
|
||||
{
|
||||
//Sanity check
|
||||
if (TPS > 100) {
|
||||
TPS = 100;
|
||||
}
|
||||
return PW(REQ_FUEL, VE, currentStatus.MAP, corrections, injOpen);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue