mirror of https://github.com/rusefi/speeduino.git
Merge branch 'pr/4'
This commit is contained in:
commit
bf0495b61a
5
comms.h
5
comms.h
|
@ -1,3 +1,6 @@
|
||||||
|
#ifndef COMMS_H
|
||||||
|
#define COMMS_H
|
||||||
|
|
||||||
#define vePage 1
|
#define vePage 1
|
||||||
#define ignPage 2
|
#define ignPage 2
|
||||||
#define afrPage 3
|
#define afrPage 3
|
||||||
|
@ -12,3 +15,5 @@ void sendPage();
|
||||||
void receiveCalibration(byte tableID);
|
void receiveCalibration(byte tableID);
|
||||||
void sendToothLog(bool useChar);
|
void sendToothLog(bool useChar);
|
||||||
void testComm();
|
void testComm();
|
||||||
|
|
||||||
|
#endif // COMMS_H
|
||||||
|
|
|
@ -3,6 +3,10 @@ This is called when a command is received over serial from TunerStudio / Megatun
|
||||||
It parses the command and calls the relevant function
|
It parses the command and calls the relevant function
|
||||||
A detailed description of each call can be found at: http://www.msextra.com/doc/ms1extra/COM_RS232.htm
|
A detailed description of each call can be found at: http://www.msextra.com/doc/ms1extra/COM_RS232.htm
|
||||||
*/
|
*/
|
||||||
|
#include "comms.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "storage.h"
|
||||||
|
|
||||||
void command()
|
void command()
|
||||||
{
|
{
|
||||||
switch (Serial.read())
|
switch (Serial.read())
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
All functions in the gamma file return
|
All functions in the gamma file return
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#ifndef CORRECTIONS_H
|
||||||
|
#define CORRECTIONS_H
|
||||||
|
|
||||||
//static byte numCorrections = 2;
|
//static byte numCorrections = 2;
|
||||||
|
|
||||||
byte correctionsTotal();
|
byte correctionsTotal();
|
||||||
|
@ -10,3 +13,5 @@ byte correctionASE(); //After Start Enrichment
|
||||||
byte correctionAccel(); //Acceleration Enrichment
|
byte correctionAccel(); //Acceleration Enrichment
|
||||||
byte correctionsFloodClear(); //Check for flood clear on cranking
|
byte correctionsFloodClear(); //Check for flood clear on cranking
|
||||||
byte correctionsAFRClosedLoop(); //Closed loop AFR adjustment
|
byte correctionsAFRClosedLoop(); //Closed loop AFR adjustment
|
||||||
|
|
||||||
|
#endif // CORRECTIONS_H
|
||||||
|
|
|
@ -7,6 +7,8 @@ Flood clear mode etc.
|
||||||
*/
|
*/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
|
|
||||||
|
#include "corrections.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
correctionsTotal() calls all the other corrections functions and combines their results.
|
correctionsTotal() calls all the other corrections functions and combines their results.
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#ifndef FASTANALOG_H
|
||||||
|
#define FASTANALOG_H
|
||||||
|
|
||||||
#ifndef cbi
|
#ifndef cbi
|
||||||
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,4 +8,5 @@
|
||||||
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // FASTANALOG_H
|
||||||
|
|
||||||
|
|
24
globals.h
24
globals.h
|
@ -1,3 +1,5 @@
|
||||||
|
#ifndef GLOBALS_H
|
||||||
|
#define GLOBALS_H
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
const byte ms_version = 20;
|
const byte ms_version = 20;
|
||||||
|
@ -270,3 +272,25 @@ struct config3 {
|
||||||
#define pinCLT A3 //CLS sensor pin
|
#define pinCLT A3 //CLS sensor pin
|
||||||
#define pinO2 A4 //O2 Sensor pin
|
#define pinO2 A4 //O2 Sensor pin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// global variables // from speeduino.ino
|
||||||
|
extern struct statuses currentStatus; // from speeduino.ino
|
||||||
|
extern struct table3D fuelTable; //8x8 fuel map
|
||||||
|
extern struct table3D ignitionTable; //8x8 ignition map
|
||||||
|
extern struct table3D afrTable; //8x8 afr target map
|
||||||
|
extern struct table2D taeTable; //4 bin TPS Acceleration Enrichment map
|
||||||
|
extern struct table2D WUETable; //10 bin Warm Up Enrichment map (2D)
|
||||||
|
extern struct config1 configPage1;
|
||||||
|
extern struct config2 configPage2;
|
||||||
|
extern struct config3 configPage3;
|
||||||
|
extern unsigned long currentLoopTime; //The time the current loop started (uS)
|
||||||
|
extern unsigned long previousLoopTime; //The time the previous loop started (uS)
|
||||||
|
extern byte ignitionCount;
|
||||||
|
extern byte cltCalibrationTable[CALIBRATION_TABLE_SIZE];
|
||||||
|
extern byte iatCalibrationTable[CALIBRATION_TABLE_SIZE];
|
||||||
|
extern byte o2CalibrationTable[CALIBRATION_TABLE_SIZE];
|
||||||
|
extern volatile int toothHistory[512];
|
||||||
|
extern volatile int toothHistoryIndex;
|
||||||
|
|
||||||
|
|
||||||
|
#endif // GLOBALS_H
|
||||||
|
|
4
math.h
4
math.h
|
@ -1,3 +1,5 @@
|
||||||
|
#ifndef MATH_H
|
||||||
|
#define MATH_H
|
||||||
|
|
||||||
//Replace the standard arduino map() function to use the div function instead
|
//Replace the standard arduino map() function to use the div function instead
|
||||||
int fastMap(int x, int in_min, int in_max, int out_min, int out_max)
|
int fastMap(int x, int in_min, int in_max, int out_min, int out_max)
|
||||||
|
@ -49,3 +51,5 @@ int divs100(int n) {
|
||||||
return q + ((r + 28) >> 7);
|
return q + ((r + 28) >> 7);
|
||||||
// return q + (r > 99);
|
// return q + (r > 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // MATH_H
|
||||||
|
|
|
@ -22,6 +22,8 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd
|
||||||
256 prescale gives overflow every 1048576uS (This means maximum wait time is 1.0485 seconds)
|
256 prescale gives overflow every 1048576uS (This means maximum wait time is 1.0485 seconds)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#ifndef SCHEDULER_H
|
||||||
|
#define SCHEDULER_H
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
@ -54,3 +56,5 @@ Schedule ignitionSchedule1;
|
||||||
Schedule ignitionSchedule2;
|
Schedule ignitionSchedule2;
|
||||||
Schedule ignitionSchedule3;
|
Schedule ignitionSchedule3;
|
||||||
Schedule ignitionSchedule4;
|
Schedule ignitionSchedule4;
|
||||||
|
|
||||||
|
#endif // SCHEDULER_H
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
#include "scheduler.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
|
||||||
void initialiseSchedulers()
|
void initialiseSchedulers()
|
||||||
|
|
|
@ -540,7 +540,7 @@ void endCoil4Charge() { digitalWrite(pinCoil4, coilLOW); BIT_CLEAR(currentStatus
|
||||||
|
|
||||||
//The trigger function is called everytime a crank tooth passes the sensor
|
//The trigger function is called everytime a crank tooth passes the sensor
|
||||||
volatile unsigned long curTime;
|
volatile unsigned long curTime;
|
||||||
volatile int curGap;
|
volatile unsigned int curGap;
|
||||||
volatile unsigned int targetGap;
|
volatile unsigned int targetGap;
|
||||||
void trigger()
|
void trigger()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#ifndef STORAGE_H
|
||||||
|
#define STORAGE_H
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
void writeConfig();
|
void writeConfig();
|
||||||
|
@ -59,3 +61,4 @@ Current layout of EEPROM data (Version 2) is as follows (All sizes are in bytes)
|
||||||
#define EEPROM_CALIBRATION_IAT 3071
|
#define EEPROM_CALIBRATION_IAT 3071
|
||||||
#define EEPROM_CALIBRATION_CLT 3583
|
#define EEPROM_CALIBRATION_CLT 3583
|
||||||
|
|
||||||
|
#endif // STORAGE_H
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
#include "storage.h"
|
||||||
|
#include "globals.h"
|
||||||
//#include "table.h"
|
//#include "table.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Takes the current configuration (config pages and maps)
|
Takes the current configuration (config pages and maps)
|
||||||
and writes them to EEPROM as per the layout defined in storage.h
|
and writes them to EEPROM as per the layout defined in storage.h
|
||||||
|
|
4
table.h
4
table.h
|
@ -1,6 +1,8 @@
|
||||||
/*
|
/*
|
||||||
This file is used for everything related to maps/tables including their definition, functions etc
|
This file is used for everything related to maps/tables including their definition, functions etc
|
||||||
*/
|
*/
|
||||||
|
#ifndef TABLE_H
|
||||||
|
#define TABLE_H
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -46,3 +48,5 @@ Eg: 2x2 table
|
||||||
*/
|
*/
|
||||||
int get3DTableValue(struct table3D, int, int);
|
int get3DTableValue(struct table3D, int, int);
|
||||||
int table2D_getValue(struct table2D, int);
|
int table2D_getValue(struct table2D, int);
|
||||||
|
|
||||||
|
#endif // TABLE_H
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
Because the size of the table is dynamic, this functino is required to reallocate the array sizes
|
Because the size of the table is dynamic, this functino is required to reallocate the array sizes
|
||||||
Note that this may clear some of the existing values of the table
|
Note that this may clear some of the existing values of the table
|
||||||
*/
|
*/
|
||||||
|
#include "table.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
void table2D_setSize(struct table2D* targetTable, byte newSize)
|
void table2D_setSize(struct table2D* targetTable, byte newSize)
|
||||||
{
|
{
|
||||||
//2D tables can contain either bytes or ints, depending on the value of the valueSize field
|
//2D tables can contain either bytes or ints, depending on the value of the valueSize field
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
/*
|
/*
|
||||||
This file has a few functions that are helpful for testing such as creating dummy maps and faking interrupts
|
This file has a few functions that are helpful for testing such as creating dummy maps and faking interrupts
|
||||||
*/
|
*/
|
||||||
|
#ifndef TESTING_H
|
||||||
|
#define TESTING_H
|
||||||
/*
|
/*
|
||||||
Aim is to create an 8x8 table that looks like the below:
|
Aim is to create an 8x8 table that looks like the below:
|
||||||
MAP
|
MAP
|
||||||
|
@ -105,3 +106,5 @@ void dummyIgnitionTable(struct table3D *mySparkTable)
|
||||||
for (byte x = 0; x< mySparkTable->xSize; x++) { mySparkTable->values[7][x] = tempRow8[x]; }
|
for (byte x = 0; x< mySparkTable->xSize; x++) { mySparkTable->values[7][x] = tempRow8[x]; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // TESTING_H
|
||||||
|
|
4
timers.h
4
timers.h
|
@ -16,6 +16,8 @@ We're after a 1ms interval so we'll need 131 intervals to reach this ( 1ms / 0.0
|
||||||
Hence we will preload the timer with 131 cycles to leave 125 until overflow (1ms).
|
Hence we will preload the timer with 131 cycles to leave 125 until overflow (1ms).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#ifndef TIMERS_H
|
||||||
|
#define TIMERS_H
|
||||||
|
|
||||||
volatile int loop250ms;
|
volatile int loop250ms;
|
||||||
volatile int loopSec;
|
volatile int loopSec;
|
||||||
|
@ -24,4 +26,4 @@ volatile unsigned long targetOverdwellTime;
|
||||||
|
|
||||||
void initialiseTimers();
|
void initialiseTimers();
|
||||||
|
|
||||||
|
#endif // TIMERS_H
|
||||||
|
|
|
@ -4,6 +4,8 @@ They should not be confused with Schedulers, which are for performing an action
|
||||||
|
|
||||||
Timers are typically low resolution (Compared to Schedulers), with maximum frequency currently being approximately every 10ms
|
Timers are typically low resolution (Compared to Schedulers), with maximum frequency currently being approximately every 10ms
|
||||||
*/
|
*/
|
||||||
|
#include "timers.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
void initialiseTimers()
|
void initialiseTimers()
|
||||||
{
|
{
|
||||||
|
|
5
utils.h
5
utils.h
|
@ -1,6 +1,9 @@
|
||||||
/*
|
/*
|
||||||
These are some utility functions and variables used through the main code
|
These are some utility functions and variables used through the main code
|
||||||
*/
|
*/
|
||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#define MS_IN_MINUTE 60000
|
#define MS_IN_MINUTE 60000
|
||||||
#define US_IN_MINUTE 60000000
|
#define US_IN_MINUTE 60000000
|
||||||
|
@ -10,3 +13,5 @@ int AIRDEN();
|
||||||
unsigned int PW();
|
unsigned int PW();
|
||||||
unsigned int PW_SD();
|
unsigned int PW_SD();
|
||||||
unsigned int PW_AN();
|
unsigned int PW_AN();
|
||||||
|
|
||||||
|
#endif // UTILS_H
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
/*
|
/*
|
||||||
Returns how much free dynamic memory exists (between heap and stack)
|
Returns how much free dynamic memory exists (between heap and stack)
|
||||||
*/
|
*/
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
int freeRam ()
|
int freeRam ()
|
||||||
{
|
{
|
||||||
extern int __heap_start, *__brkval;
|
extern int __heap_start, *__brkval;
|
||||||
|
|
Loading…
Reference in New Issue