Initial layout work on RTC and SD
This commit is contained in:
parent
1af5ce1a91
commit
ca6eef2b31
|
@ -14,7 +14,7 @@ board=megaatmega2560
|
|||
framework=arduino
|
||||
build_unflags = -Os
|
||||
build_flags = -O3 -ffast-math -funroll-loops -Wall -Wextra -std=c99
|
||||
lib_deps = EEPROM
|
||||
lib_deps = EEPROM, Time
|
||||
test_build_project_src = true
|
||||
debug_tool = simavr
|
||||
|
||||
|
@ -31,19 +31,19 @@ test_build_project_src = true
|
|||
platform=teensy
|
||||
board=teensy35
|
||||
framework=arduino
|
||||
lib_deps = EEPROM, FlexCAN, SD
|
||||
lib_deps = EEPROM, FlexCAN, SD, Time
|
||||
|
||||
[env:teensy36]
|
||||
platform=teensy
|
||||
board=teensy36
|
||||
framework=arduino
|
||||
lib_deps = EEPROM, FlexCAN, SD
|
||||
lib_deps = EEPROM, FlexCAN, SD, Time
|
||||
|
||||
[env:teensy41]
|
||||
platform=teensy
|
||||
board=teensy41
|
||||
framework=arduino
|
||||
lib_deps = EEPROM, FlexCAN_T4
|
||||
lib_deps = EEPROM, FlexCAN_T4, SD, Time
|
||||
|
||||
;Not currently working
|
||||
;[env:LaunchPad_tm4c1294ncpdt]
|
||||
|
@ -56,7 +56,7 @@ lib_deps = EEPROM, FlexCAN_T4
|
|||
platform = ststm32@~4.5.0
|
||||
framework = arduino
|
||||
board = genericSTM32F103RB
|
||||
lib_deps = EEPROM
|
||||
lib_deps = EEPROM, stm32duino/STM32duino RTC
|
||||
build_flags = -fpermissive -std=gnu++11 -DCORE_STM32_OFFICIAL
|
||||
|
||||
[env:genericSTM32F103RB_STM32GENERIC]
|
||||
|
@ -64,7 +64,7 @@ build_flags = -fpermissive -std=gnu++11 -DCORE_STM32_OFFICIAL
|
|||
platform = ststm32
|
||||
framework = arduino
|
||||
; framework-arduinoststm32
|
||||
board = genericSTM32F103RB
|
||||
board = genericSTM32F103RB, stm32duino/STM32duino RTC
|
||||
lib_deps = EEPROM, HardwareTimer, Flash_STM32
|
||||
build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS -DUSE_STM32GENERIC -DMENU_USB_SERIAL
|
||||
|
||||
|
@ -75,7 +75,7 @@ platform = ststm32
|
|||
framework = arduino
|
||||
;board = genericSTM32F407VET6
|
||||
board = black_f407ve
|
||||
;lib_deps = EEPROM
|
||||
lib_deps = stm32duino/STM32duino RTC
|
||||
board_build.core = stm32
|
||||
build_flags = -std=gnu++11 -UBOARD_NR_GPIO_PINS -DENABLE_HWSERIAL2 -DENABLE_HWSERIAL3 -DUSBCON -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC
|
||||
upload_protocol = dfu
|
||||
|
@ -87,6 +87,7 @@ monitor_speed = 115200
|
|||
platform = ststm32
|
||||
framework = arduino
|
||||
board = blackpill_f401cc
|
||||
lib_deps = stm32duino/STM32duino RTC
|
||||
board_build.core = stm32
|
||||
build_flags = -std=gnu++11 -UBOARD_NR_GPIO_PINS -DUSBCON -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC -DHAL_DAC_MODULE_DISABLED -DHAL_RTC_MODULE_DISABLED -DHAL_ETH_MODULE_DISABLED -DHAL_SD_MODULE_DISABLED -DHAL_QSPI_MODULE_DISABLED
|
||||
upload_protocol = dfu
|
||||
|
@ -98,7 +99,7 @@ platform = ststm32
|
|||
framework = arduino
|
||||
; framework-arduinoststm32
|
||||
board = bluepill_f103c8_128k
|
||||
lib_deps = EEPROM
|
||||
lib_deps = EEPROM, stm32duino/STM32duino RTC
|
||||
;build_flags = -fpermissive -std=gnu++11 -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-Map,output.map
|
||||
build_flags = -fpermissive -std=gnu++11 -Os -DCORE_STM32_OFFICIAL -UBOARD_NR_GPIO_PINS
|
||||
|
||||
|
|
|
@ -338,7 +338,8 @@ page = 1
|
|||
|
||||
fanWhenOff = bits, U08, 70, [0:0], "No", "Yes"
|
||||
fanWhenCranking = bits, U08, 70, [1:1], "No", "Yes"
|
||||
unused_fan_bits = bits, U08, 70,[2:6]
|
||||
unused_fan_bits = bits, U08, 70, [2:4]
|
||||
rtc_mode = bits, U08, 70, [5:6], "Off", "On-board", "INVALID", "INVALID"
|
||||
incorporateAFR = bits, U08, 70, [7:7], "No", "Yes"
|
||||
|
||||
asePct = array, U08, 71, [4], "%", 1.0, 0.0, 0, 155, 0
|
||||
|
@ -396,7 +397,9 @@ page = 1
|
|||
iacTPSlimit = scalar, U08, 121, "%", 1, 0, 0, 100, 0
|
||||
iacRPMlimitHysteresis = scalar, U08, 122, "RPM" 10, 0 10 2500, 0
|
||||
|
||||
unused2-95 = array, U08, 121, [5], "%", 1.0, 0.0, 0.0, 255, 0
|
||||
rtc_trim = scalar, S08, 123, "ppm", 1, 0, -127, +127, 0
|
||||
|
||||
unused2-95 = array, U08, 124, [4], "%", 1.0, 0.0, 0.0, 255, 0
|
||||
|
||||
;Page 2 is the fuel map and axis bins only
|
||||
page = 2
|
||||
|
@ -1633,9 +1636,9 @@ menuDialog = main
|
|||
subMenu = std_ms2geno2, "Calibrate AFR Sensor", { egoType > 0 }
|
||||
subMenu = sensorFilters, "Set analog sensor filters"
|
||||
|
||||
;menu = "Data Logging"
|
||||
menu = "Data Logging"
|
||||
;subMenu = sdcard_datalog, "SD Card Datalogging"
|
||||
;subMenu = std_ms3SdConsole, "Browse / Import SD Card"
|
||||
subMenu = std_ms3SdConsole, "Browse / Import SD Card"
|
||||
|
||||
menuDialog = main
|
||||
menu = "3D &Tuning Maps"
|
||||
|
@ -1648,6 +1651,7 @@ menuDialog = main
|
|||
menu = "Hardware Testing"
|
||||
subMenu = outputtest1, "Test Output Hardware"
|
||||
subMenu = stm32cmd, "STM32 Commands"
|
||||
subMenu = rtc_settings, "Setup realtime clock"
|
||||
#endif
|
||||
|
||||
menu = "Help"
|
||||
|
@ -3860,6 +3864,15 @@ menuDialog = main
|
|||
field = "Select Rule Number", prgm_out_selection
|
||||
panel = prgm_out_rules_master
|
||||
|
||||
dialog = rtc_setup, "Real Time Clock"
|
||||
field = "Real Time Clock mode", rtc_mode
|
||||
field = "Real Time Clock Trim +/-", rtc_trim, {rtc_mode}
|
||||
|
||||
dialog = rtc_settings, "Real Time Clock"
|
||||
panel = rtc_setup
|
||||
panel = std_ms3Rtc
|
||||
|
||||
|
||||
;-------------------------------------------------------------------------------
|
||||
; General help text
|
||||
|
||||
|
@ -4679,8 +4692,10 @@ cmdVSSratio6 = "E\x99\x06"
|
|||
fuelTempCor = scalar, U08, 113, "%", 1.000, 0.000
|
||||
advance1 = scalar, U08, 114, "%", 1.000, 0.000
|
||||
advance2 = scalar, U08, 115, "%", 1.000, 0.000
|
||||
unused116 = scalar, U08, 116, "", 1.000, 0.000
|
||||
#sd_status = scalar, U08, 99, "", 1.0, 0.0
|
||||
sd_status = scalar, U08, 116, "", 1.0, 0.0
|
||||
;sd_filenum = scalar, U16, 117, "", 1, 0
|
||||
;sd_error = scalar, U08, 119, "", 1, 0
|
||||
;sd_phase = scalar, U08, 120, "", 1, 0
|
||||
|
||||
#if CELSIUS
|
||||
coolant = { coolantRaw - 40 } ; Temperature readings are offset by 40 to allow for negatives
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
#define SD_CS_PIN 10 //This is a made up value for now
|
||||
#endif
|
||||
|
||||
//Sd2Card SD;
|
||||
//SdVolume SD_volume;
|
||||
Sd2Card SD_card;
|
||||
SdVolume SD_volume;
|
||||
File logFile;
|
||||
|
||||
uint8_t SD_status = SD_STATUS_OFF;
|
||||
|
@ -27,6 +27,7 @@ uint8_t SD_status = SD_STATUS_OFF;
|
|||
void initSD();
|
||||
void writeSDLogEntry();
|
||||
void endSD();
|
||||
void setTS_SD_status();
|
||||
|
||||
#endif //SD_LOGGING
|
||||
#endif //SD_H
|
||||
|
|
|
@ -7,21 +7,30 @@
|
|||
void initSD()
|
||||
{
|
||||
//Init the SPI connection to the card reader
|
||||
if (SD.begin(SD_CS_PIN))
|
||||
//if (SD_card.begin(SD_CS_PIN))
|
||||
if (SD_card.init(SPI_HALF_SPEED, SD_CS_PIN))
|
||||
{
|
||||
//Check for usable FAT32 volume
|
||||
if (SD_volume.init(SD_card))
|
||||
{
|
||||
//Attempt to create a log file for writing
|
||||
logFile = SD.open("datalog.csv", FILE_WRITE);
|
||||
if(!logFile) { SD_status = SD_STATUS_ERROR_NO_WRITE; } //Cannot write to SD card
|
||||
else { SD_status = SD_STATUS_READY; }
|
||||
//logFile = SD_card.open("datalog.csv", FILE_WRITE);
|
||||
//if(!logFile) { SD_status = SD_STATUS_ERROR_NO_WRITE; } //Cannot write to SD card
|
||||
//else { SD_status = SD_STATUS_READY;
|
||||
SD_status = SD_STATUS_READY;
|
||||
}
|
||||
else { SD_status = SD_STATUS_ERROR_NO_FS; }
|
||||
}
|
||||
else { SD_status = SD_STATUS_ERROR_NO_CARD; }
|
||||
|
||||
//Write a header row
|
||||
if(SD_status == SD_STATUS_READY)
|
||||
{
|
||||
logFile.println("Field 1,Field 2,Test");
|
||||
//logFile.println("Field 1,Field 2,Test");
|
||||
}
|
||||
|
||||
//Set the TunerStudio status varable
|
||||
setTS_SD_status();
|
||||
}
|
||||
|
||||
void endSD()
|
||||
|
@ -41,4 +50,19 @@ void writeSDLogEntry()
|
|||
|
||||
}
|
||||
|
||||
//Sets the status variable for TunerStudio
|
||||
void setTS_SD_status()
|
||||
{
|
||||
/*
|
||||
indicator = { sd_status & 1}, "No SD", "SD in", white, black, green, black
|
||||
indicator = { sd_status & 4}, "SD ready", "SD ready", white, black, green, black
|
||||
indicator = { sd_status & 8}, "SD Log", "SD Log", white, black, green, black
|
||||
indicator = { sd_status & 16}, "SD Err", "SD Err", white, black, red, black
|
||||
*/
|
||||
currentStatus.TS_SD_Status = 0;
|
||||
if(SD_status != SD_STATUS_ERROR_NO_CARD) { BIT_SET(currentStatus.TS_SD_Status, 0); } //Set bit for SD card being present
|
||||
if(SD_status == SD_STATUS_READY) { BIT_SET(currentStatus.TS_SD_Status, 2); } //Set bit for SD card being ready
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -18,6 +18,7 @@
|
|||
#else
|
||||
#define EEPROM_LIB_H <EEPROM.h>
|
||||
#endif
|
||||
#define RTC_LIB_H "TimeLib.h"
|
||||
void initBoard();
|
||||
uint16_t freeRam();
|
||||
void doSystemReset();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#if defined(STM32_CORE_VERSION_MAJOR)
|
||||
#include <HardwareTimer.h>
|
||||
#include <HardwareSerial.h>
|
||||
#include "STM32RTC.h"
|
||||
|
||||
#if defined(STM32F1)
|
||||
#include "stm32f1xx_ll_tim.h"
|
||||
|
@ -25,7 +26,7 @@
|
|||
#define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()
|
||||
#define TIMER_RESOLUTION 4
|
||||
|
||||
|
||||
#define RTC_ENABLED
|
||||
#define USE_SERIAL3
|
||||
|
||||
//When building for Black board Serial1 is instanciated,building generic STM32F4x7 has serial2 and serial 1 must be done here
|
||||
|
@ -33,6 +34,8 @@
|
|||
HardwareSerial Serial1(PA10, PA9);
|
||||
#endif
|
||||
|
||||
extern STM32RTC& rtc;
|
||||
|
||||
void initBoard();
|
||||
uint16_t freeRam();
|
||||
void doSystemReset();
|
||||
|
@ -118,6 +121,7 @@ extern "C" char* sbrk(int incr);
|
|||
InternalSTM32F4_EEPROM_Class EEPROM(EmulatedEEPROMMconfig);
|
||||
#endif
|
||||
|
||||
#define RTC_LIB_H "STM32RTC.h"
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "scheduler.h"
|
||||
#include "HardwareTimer.h"
|
||||
|
||||
STM32RTC& rtc = STM32RTC::getInstance();
|
||||
|
||||
void initBoard()
|
||||
{
|
||||
/*
|
||||
|
@ -16,6 +18,15 @@
|
|||
#define FLASH_LENGTH 8192
|
||||
#endif
|
||||
delay(10);
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* Real Time clock for datalogging/time stamping
|
||||
*/
|
||||
|
||||
rtc.setClockSource(STM32RTC::LSE_CLOCK); //Initialize external clock for RTC. That is the only clock running of VBAT
|
||||
rtc.begin(); // initialize RTC 24H format
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* Idle
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#else
|
||||
#define EEPROM_LIB_H <EEPROM.h>
|
||||
#endif
|
||||
#define RTC_ENABLED
|
||||
#define RTC_LIB_H "TimeLib.h"
|
||||
|
||||
#define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()
|
||||
#define pinIsReserved(pin) ( ((pin) == 0) || ((pin) == 1) || ((pin) == 3) || ((pin) == 4) ) //Forbiden pins like USB
|
||||
|
|
|
@ -25,6 +25,31 @@
|
|||
#define progOutsPage 13
|
||||
#define ignMap2Page 14
|
||||
|
||||
//Hardcoded TunerStudio addresses/commands for various SD/RTC commands
|
||||
#define SD_READWRITE_PAGE 0x11
|
||||
#define SD_RTC_PAGE 0x07
|
||||
#define SD_READ_STAT_OFFSET 0x0000
|
||||
#define SD_READ_STAT_LENGTH 0x1000
|
||||
#define SD_READ_DIR_OFFSET 0x0100
|
||||
#define SD_READ_DIR_LENGTH 0x0200
|
||||
#define SD_READ_SEC_OFFSET 0x0200
|
||||
#define SD_READ_SEC_LENGTH 0x0400
|
||||
#define SD_READ_STRM_OFFSET 0x0400
|
||||
#define SD_READ_STRM_LENGTH 0x0100
|
||||
#define SD_WRITE_DO_OFFSET 0x0000
|
||||
#define SD_WRITE_DO_LENGTH 0x0001
|
||||
#define SD_WRITE_SEC_OFFSET 0x0300
|
||||
#define SD_WRITE_SEC_LENGTH 0x0402
|
||||
#define SD_ERASEFILE_OFFSET 0x0600
|
||||
#define SD_ERASEFILE_LENGTH 0x0600
|
||||
#define SD_SPD_TEST_OFFSET 0x0700
|
||||
#define SD_SPD_TEST_LENGTH 0x0400
|
||||
#define SD_RTC_WRITE_OFFSET 0x7E02
|
||||
#define SD_RTC_WRITE_LENGTH 0x0900
|
||||
#define SD_RTC_READ_OFFSET 0x4D02
|
||||
#define SD_RTC_READ_LENGTH 0x0800
|
||||
|
||||
|
||||
byte currentPage = 1;//Not the same as the speeduino config page numbers
|
||||
bool isMap = true; /**< Whether or not the currentPage contains only a 3D map that would require translation */
|
||||
unsigned long requestCount = 0; /**< The number of times the A command has been issued. This is used to track whether a reset has recently been performed on the controller */
|
||||
|
|
|
@ -12,6 +12,8 @@ A full copy of the license may be found in the projects root directory
|
|||
#include "decoders.h"
|
||||
#include "TS_CommandButtonHandler.h"
|
||||
#include "errors.h"
|
||||
#include "src/FastCRC/FastCRC.h"
|
||||
#include "rtc.h"
|
||||
|
||||
/*
|
||||
Processes the data on the serial buffer.
|
||||
|
@ -266,15 +268,142 @@ void command()
|
|||
cmd = Serial.read(); // read the command
|
||||
|
||||
uint16_t offset, length;
|
||||
if(cmd == 0x30) //Send output channels command 0x30 is 48dec
|
||||
{
|
||||
byte tmp;
|
||||
tmp = Serial.read();
|
||||
offset = word(Serial.read(), tmp);
|
||||
tmp = Serial.read();
|
||||
length = word(Serial.read(), tmp);
|
||||
|
||||
if(cmd == 0x30) //Send output channels command 0x30 is 48dec
|
||||
{
|
||||
sendValues(offset, length, cmd, 0);
|
||||
}
|
||||
else if(cmd == SD_RTC_PAGE) //Request to read SD card RTC
|
||||
{
|
||||
/*
|
||||
uint16_t packetSize = 2 + 1 + length + 4;
|
||||
packetSize = 15;
|
||||
Serial.write(highByte(packetSize));
|
||||
Serial.write(lowByte(packetSize));
|
||||
byte packet[length+1];
|
||||
|
||||
packet[0] = 0;
|
||||
packet[1] = length;
|
||||
packet[2] = 0;
|
||||
packet[3] = 0;
|
||||
packet[4] = 0;
|
||||
packet[5] = 0;
|
||||
packet[6] = 0;
|
||||
packet[7] = 0;
|
||||
packet[8] = 0;
|
||||
Serial.write(packet, 9);
|
||||
|
||||
FastCRC32 CRC32;
|
||||
uint32_t CRC32_val = CRC32.crc32((byte *)packet, sizeof(packet) );;
|
||||
|
||||
//Split the 4 bytes of the CRC32 value into individual bytes and send
|
||||
Serial.write( ((CRC32_val >> 24) & 255) );
|
||||
Serial.write( ((CRC32_val >> 16) & 255) );
|
||||
Serial.write( ((CRC32_val >> 8) & 255) );
|
||||
Serial.write( (CRC32_val & 255) );
|
||||
*/
|
||||
Serial.write(rtc_getSecond()); //Seconds
|
||||
Serial.write(rtc_getMinute()); //Minutes
|
||||
Serial.write(rtc_getHour()); //Hours
|
||||
Serial.write(rtc_getDOW()); //Day of Week
|
||||
Serial.write(rtc_getDay()); //Date
|
||||
Serial.write(rtc_getMonth()); //Month
|
||||
Serial.write(lowByte(rtc_getYear())); //Year - NOTE 2 bytes
|
||||
Serial.write(highByte(rtc_getYear())); //Year
|
||||
|
||||
}
|
||||
else if(cmd == SD_READWRITE_PAGE) //Request SD card extended parameters
|
||||
{
|
||||
//SD read commands use the offset and length fields to indicate the request type
|
||||
if((offset == SD_READ_STAT_OFFSET) && (length == SD_READ_STAT_LENGTH))
|
||||
{
|
||||
//Read the status of the SD card
|
||||
|
||||
//Serial.write(0);
|
||||
|
||||
|
||||
//Serial.write(currentStatus.TS_SD_Status);
|
||||
Serial.write((uint8_t)5);
|
||||
Serial.write((uint8_t)0);
|
||||
|
||||
//All other values are 2 bytes
|
||||
Serial.write((uint8_t)2); //Sector size
|
||||
Serial.write((uint8_t)0); //Sector size
|
||||
|
||||
//Max blocks (4 bytes)
|
||||
Serial.write((uint8_t)0);
|
||||
Serial.write((uint8_t)0x20); //1gb dummy card
|
||||
Serial.write((uint8_t)0);
|
||||
Serial.write((uint8_t)0);
|
||||
|
||||
//Max roots (Number of files)
|
||||
Serial.write((uint8_t)0);
|
||||
Serial.write((uint8_t)1);
|
||||
|
||||
//Dir Start (4 bytes)
|
||||
Serial.write((uint8_t)0); //Dir start lower 2 bytes
|
||||
Serial.write((uint8_t)0); //Dir start lower 2 bytes
|
||||
Serial.write((uint8_t)0); //Dir start lower 2 bytes
|
||||
Serial.write((uint8_t)0); //Dir start lower 2 bytes
|
||||
|
||||
//Unkown purpose for last 2 bytes
|
||||
Serial.write((uint8_t)0); //Dir start lower 2 bytes
|
||||
Serial.write((uint8_t)0); //Dir start lower 2 bytes
|
||||
|
||||
/*
|
||||
Serial.write(lowByte(23));
|
||||
Serial.write(highByte(23));
|
||||
|
||||
byte packet[17];
|
||||
packet[0] = 0;
|
||||
packet[1] = 5;
|
||||
packet[2] = 0;
|
||||
|
||||
packet[3] = 2;
|
||||
packet[4] = 0;
|
||||
|
||||
packet[5] = 0;
|
||||
packet[6] = 0x20;
|
||||
packet[7] = 0;
|
||||
packet[8] = 0;
|
||||
|
||||
packet[9] = 0;
|
||||
packet[10] = 1;
|
||||
|
||||
packet[11] = 0;
|
||||
packet[12] = 0;
|
||||
packet[13] = 0;
|
||||
packet[14] = 0;
|
||||
|
||||
packet[15] = 0;
|
||||
packet[16] = 0;
|
||||
|
||||
Serial.write(packet, 17);
|
||||
FastCRC32 CRC32;
|
||||
uint32_t CRC32_val = CRC32.crc32((byte *)packet, sizeof(packet) );;
|
||||
|
||||
//Split the 4 bytes of the CRC32 value into individual bytes and send
|
||||
Serial.write( ((CRC32_val >> 24) & 255) );
|
||||
Serial.write( ((CRC32_val >> 16) & 255) );
|
||||
Serial.write( ((CRC32_val >> 8) & 255) );
|
||||
Serial.write( (CRC32_val & 255) );
|
||||
*/
|
||||
|
||||
}
|
||||
//else if(length == 0x202)
|
||||
{
|
||||
//File info
|
||||
}
|
||||
}
|
||||
else if(cmd == 0x14)
|
||||
{
|
||||
//Fetch data from file
|
||||
}
|
||||
else
|
||||
{
|
||||
//No other r/ commands should be called
|
||||
|
@ -396,14 +525,91 @@ void command()
|
|||
offset1 = Serial.read();
|
||||
offset2 = Serial.read();
|
||||
valueOffset = word(offset2, offset1);
|
||||
length1 = Serial.read(); // Length to be written (Should always be 1)
|
||||
length2 = Serial.read(); // Length to be written (Should always be 1)
|
||||
length1 = Serial.read();
|
||||
length2 = Serial.read();
|
||||
chunkSize = word(length2, length1);
|
||||
|
||||
if(currentPage == SD_READWRITE_PAGE)
|
||||
{
|
||||
cmdPending = false;
|
||||
|
||||
//Reserved for the SD card settings. Appears to be hardcoded into TS. Flush the final byte in the buffer as its not used for now
|
||||
Serial.read();
|
||||
if((valueOffset == SD_WRITE_DO_OFFSET) && (chunkSize == SD_WRITE_DO_LENGTH))
|
||||
{
|
||||
/*
|
||||
SD DO command. Single byte of data where the commands are:
|
||||
0 Reset
|
||||
1 Reset
|
||||
2 Stop logging
|
||||
3 Start logging
|
||||
4 Load status variable
|
||||
5 Init SD card
|
||||
*/
|
||||
Serial.read();
|
||||
}
|
||||
else if((valueOffset == SD_WRITE_SEC_OFFSET) && (chunkSize == SD_WRITE_SEC_LENGTH))
|
||||
{
|
||||
//SD write sector command
|
||||
}
|
||||
else if((valueOffset == SD_ERASEFILE_OFFSET) && (chunkSize == SD_ERASEFILE_LENGTH))
|
||||
{
|
||||
//Erase file command
|
||||
//First 4 bytes are the log number in ASCII
|
||||
char log1 = Serial.read();
|
||||
char log2 = Serial.read();
|
||||
char log3 = Serial.read();
|
||||
char log4 = Serial.read();
|
||||
|
||||
//Next 2 bytes are the directory block no
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
}
|
||||
else if((valueOffset == SD_SPD_TEST_OFFSET) && (chunkSize == SD_SPD_TEST_LENGTH))
|
||||
{
|
||||
//Perform a speed test on the SD card
|
||||
//First 4 bytes are the sector number to write to
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
|
||||
//Last 4 bytes are the number of sectors to test
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
Serial.read();
|
||||
}
|
||||
}
|
||||
else if(currentPage == SD_RTC_PAGE)
|
||||
{
|
||||
cmdPending = false;
|
||||
//Used for setting RTC settings
|
||||
if((valueOffset == SD_RTC_WRITE_OFFSET) && (chunkSize == SD_RTC_WRITE_LENGTH))
|
||||
{
|
||||
//Set the RTC date/time
|
||||
//Need to ensure there are 9 more bytes with the new values
|
||||
while(Serial.available() < 9) {} //Terrible hack, but RTC values should not be set with the engine running anyway
|
||||
byte second = Serial.read();
|
||||
byte minute = Serial.read();
|
||||
byte hour = Serial.read();
|
||||
byte dow = Serial.read();
|
||||
byte day = Serial.read();
|
||||
byte month = Serial.read();
|
||||
uint16_t year = Serial.read();
|
||||
year = word(Serial.read(), year);
|
||||
Serial.read(); //Final byte is unused (Always has value 0x5a)
|
||||
rtc_setTime(second, minute, hour, day, month, year);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Regular page data
|
||||
chunkPending = true;
|
||||
chunkComplete = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
//This CANNOT be an else of the above if statement as chunkPending gets set to true above
|
||||
if(chunkPending == true)
|
||||
{
|
||||
|
@ -636,7 +842,7 @@ void updateFullStatus()
|
|||
fullStatus[113] = currentStatus.fuelTempCorrection; //Fuel temperature Correction (%)
|
||||
fullStatus[114] = currentStatus.advance1; //advance 1 (%)
|
||||
fullStatus[115] = currentStatus.advance2; //advance 2 (%)
|
||||
fullStatus[116] = 0; //Currently unused
|
||||
fullStatus[116] = currentStatus.TS_SD_Status; //SD card status
|
||||
|
||||
//Each new inclusion here need to be added on speeduino.ini@L78, only list first byte of an integer and second byte as "INVALID"
|
||||
//Every integer added here should have it's lowByte index added to fsIntIndex array on globals.ino@L116
|
||||
|
@ -1845,7 +2051,7 @@ void receiveCalibration(byte tableID)
|
|||
else
|
||||
{
|
||||
//Temperature calibrations are sent as 32 16-bit values
|
||||
for (byte x = 0; x < 32; x++)
|
||||
for (uint16_t x = 0; x < 32; x++)
|
||||
{
|
||||
while ( Serial.available() < 2 ) {}
|
||||
tempBuffer[0] = Serial.read();
|
||||
|
@ -1861,7 +2067,7 @@ void receiveCalibration(byte tableID)
|
|||
|
||||
|
||||
((uint16_t*)pnt_TargetTable_values)[x] = tempValue; //Both temp tables have 16-bit values
|
||||
pnt_TargetTable_bins[x] = (x * 32);
|
||||
pnt_TargetTable_bins[x] = (x * 32U);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -632,6 +632,7 @@ struct statuses {
|
|||
byte vvt2TargetAngle;
|
||||
byte vvt2Duty;
|
||||
byte outputsStatus;
|
||||
byte TS_SD_Status; //TunerStudios SD card status
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -741,7 +742,8 @@ struct config2 {
|
|||
|
||||
byte fanWhenOff : 1; // Only run fan when engine is running
|
||||
byte fanWhenCranking : 1; //**< Setting whether the fan output will stay on when the engine is cranking */
|
||||
byte fanUnused : 5;
|
||||
byte fanUnused : 3;
|
||||
byte rtc_mode : 2;
|
||||
byte incorporateAFR : 1; //Incorporate AFR
|
||||
byte asePct[4]; //Afterstart enrichment (%)
|
||||
byte aseCount[4]; //Afterstart enrichment cycles. This is the number of ignition cycles that the afterstart enrichment % lasts for
|
||||
|
@ -789,7 +791,9 @@ struct config2 {
|
|||
byte iacTPSlimit;
|
||||
byte iacRPMlimitHysteresis;
|
||||
|
||||
byte unused2_95[5];
|
||||
int8_t rtc_trim;
|
||||
|
||||
byte unused2_95[4];
|
||||
|
||||
#if defined(CORE_AVR)
|
||||
};
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
#include "acc_mc33810.h"
|
||||
#include BOARD_H //Note that this is not a real file, it is defined in globals.h.
|
||||
#include EEPROM_LIB_H
|
||||
#ifdef SD_LOGGING
|
||||
#include "SD_logger.h"
|
||||
#include "rtc.h"
|
||||
#endif
|
||||
|
||||
|
||||
void initialiseAll()
|
||||
|
@ -53,6 +57,10 @@ void initialiseAll()
|
|||
|
||||
initBoard(); //This calls the current individual boards init function. See the board_xxx.ino files for these.
|
||||
initialiseTimers();
|
||||
#ifdef SD_LOGGING
|
||||
initSD();
|
||||
initRTC();
|
||||
#endif
|
||||
|
||||
Serial.begin(115200);
|
||||
#if defined(CANSerial_AVAILABLE)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef RTC_H
|
||||
#define RTC_H
|
||||
|
||||
void initRTC();
|
||||
uint8_t rtc_getSecond();
|
||||
uint8_t rtc_getMinute();
|
||||
uint8_t rtc_getHour();
|
||||
uint8_t rtc_getDay();
|
||||
uint8_t rtc_getDOW();
|
||||
uint8_t rtc_getMonth();
|
||||
uint16_t rtc_getYear();
|
||||
void rtc_setTime(byte, byte, byte, byte, byte, uint16_t);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,112 @@
|
|||
#include "rtc.h"
|
||||
#include "globals.h"
|
||||
#include RTC_LIB_H //Defined in each boards .h file
|
||||
|
||||
void initRTC()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint8_t rtc_getSecond()
|
||||
{
|
||||
uint8_t tempSecond = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
tempSecond = second();
|
||||
#elif defined(CORE_STM32)
|
||||
tempSecond = rtc.getSeconds();
|
||||
#endif
|
||||
#endif
|
||||
return tempSecond;
|
||||
}
|
||||
|
||||
uint8_t rtc_getMinute()
|
||||
{
|
||||
uint8_t tempMinute = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
tempMinute = minute();
|
||||
#elif defined(CORE_STM32)
|
||||
tempMinute = rtc.getMinutes();
|
||||
#endif
|
||||
#endif
|
||||
return tempMinute;
|
||||
}
|
||||
|
||||
uint8_t rtc_getHour()
|
||||
{
|
||||
uint8_t tempHour = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
tempHour = hour();
|
||||
#elif defined(CORE_STM32)
|
||||
tempHour = rtc.getHours();
|
||||
#endif
|
||||
#endif
|
||||
return tempHour;
|
||||
}
|
||||
|
||||
uint8_t rtc_getDay()
|
||||
{
|
||||
uint8_t tempDay = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
tempDay = day();
|
||||
#elif defined(CORE_STM32)
|
||||
tempDay = rtc.getDay();
|
||||
#endif
|
||||
#endif
|
||||
return tempDay;
|
||||
}
|
||||
|
||||
uint8_t rtc_getDOW()
|
||||
{
|
||||
uint8_t dow = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
dow = weekday();
|
||||
#elif defined(CORE_STM32)
|
||||
dow = rtc.getWeekDay();
|
||||
#endif
|
||||
#endif
|
||||
return dow;
|
||||
}
|
||||
|
||||
uint8_t rtc_getMonth()
|
||||
{
|
||||
uint8_t tempMonth = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
tempMonth = month();
|
||||
#elif defined(CORE_STM32)
|
||||
tempMonth = rtc.getMonth();
|
||||
#endif
|
||||
#endif
|
||||
return tempMonth;
|
||||
}
|
||||
|
||||
uint16_t rtc_getYear()
|
||||
{
|
||||
uint16_t tempYear = 0;
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
tempYear = year();
|
||||
#elif defined(CORE_STM32)
|
||||
tempYear = rtc.getYear();
|
||||
#endif
|
||||
#endif
|
||||
return tempYear;
|
||||
}
|
||||
|
||||
void rtc_setTime(byte second, byte minute, byte hour, byte day, byte month, uint16_t year)
|
||||
{
|
||||
#ifdef RTC_ENABLED
|
||||
#if defined(CORE_TEENSY)
|
||||
setTime(second, minute, hour, day, month, year);
|
||||
#elif defined(CORE_STM32)
|
||||
rtc.setTime(hour, minute, second);
|
||||
rtc.setDate(day, month, year);
|
||||
#endif
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue