More portable version of the modular board handling
This commit is contained in:
parent
8c45cb31b0
commit
3b2967271d
|
@ -15,14 +15,12 @@ framework=arduino
|
|||
build_unflags = -Os
|
||||
build_flags = -O3 -ffast-math
|
||||
lib_deps = EEPROM
|
||||
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<test/> -<tests/> -<src/FlashStorage/>
|
||||
|
||||
[env:teensy35]
|
||||
platform=teensy
|
||||
board=teensy35
|
||||
framework=arduino
|
||||
lib_deps = EEPROM, FlexCAN
|
||||
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<test/> -<tests/> -<src/FlashStorage/>
|
||||
|
||||
;Not currently working
|
||||
;[env:LaunchPad_tm4c1294ncpdt]
|
||||
|
@ -38,7 +36,6 @@ framework = arduino
|
|||
board = genericSTM32F103RB
|
||||
lib_deps = EEPROM
|
||||
build_flags = -fpermissive -std=gnu++11
|
||||
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<test/> -<tests/> -<src/FlashStorage/>
|
||||
|
||||
[env:bluepill_f103c8]
|
||||
platform = ststm32
|
||||
|
@ -48,7 +45,6 @@ board = bluepill_f103c8
|
|||
lib_deps = EEPROM
|
||||
;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
|
||||
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<test/> -<tests/> -<src/FlashStorage/>
|
||||
|
||||
;SAMD21
|
||||
[env:samd21]
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
#define AVR2560_H
|
||||
#if defined(CORE_AVR)
|
||||
|
||||
//#include "sam.h"
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* General
|
||||
*/
|
||||
#define PORT_TYPE uint8_t //Size of the port variables (Eg inj1_pin_port).
|
||||
void initBoard();
|
||||
|
||||
#endif //CORE_AVR
|
||||
#endif //AVR2560_H
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include "globals.h"
|
||||
|
||||
#if defined(CORE_AVR)
|
||||
|
||||
void initBoard()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,159 @@
|
|||
#ifndef SAMD21_H
|
||||
#define SAMD21_H
|
||||
#if defined(CORE_SAMD21)
|
||||
|
||||
#include "sam.h"
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* General
|
||||
*/
|
||||
#define PORT_TYPE uint32_t //Size of the port variables (Eg inj1_pin_port). Most systems use a byte, but SAMD21 is a 32-bit unsigned int
|
||||
#define BOARD_NR_GPIO_PINS 52 //Not sure this is correct
|
||||
#define BOARD_DIGITAL_GPIO_PINS 52 //Pretty sure this isn't right
|
||||
void initBoard();
|
||||
|
||||
//Additional analog pins (These won't work without other changes)
|
||||
#define PIN_A6 (8ul)
|
||||
#define PIN_A7 (9ul)
|
||||
#define PIN_A8 (10ul)
|
||||
#define PIN_A9 (11ul)
|
||||
#define PIN_A13 (9ul)
|
||||
#define PIN_A14 (9ul)
|
||||
#define PIN_A15 (9ul)
|
||||
|
||||
static const uint8_t A6 = PIN_A6;
|
||||
static const uint8_t A7 = PIN_A7;
|
||||
static const uint8_t A8 = PIN_A8;
|
||||
static const uint8_t A9 = PIN_A9;
|
||||
static const uint8_t A13 = PIN_A13;
|
||||
static const uint8_t A14 = PIN_A14;
|
||||
static const uint8_t A15 = PIN_A15;
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* Schedules
|
||||
*/
|
||||
//See : https://electronics.stackexchange.com/questions/325159/the-value-of-the-tcc-counter-on-an-atsam-controller-always-reads-as-zero
|
||||
#define FUEL1_COUNTER TCC0->COUNT.reg
|
||||
#define FUEL2_COUNTER TCC0->COUNT.reg
|
||||
#define FUEL3_COUNTER TCC0->COUNT.reg
|
||||
#define FUEL4_COUNTER TCC0->COUNT.reg
|
||||
//The below are NOT YET RIGHT!
|
||||
#define FUEL5_COUNTER TCC0->COUNT.reg
|
||||
#define FUEL6_COUNTER TCC0->COUNT.reg
|
||||
#define FUEL7_COUNTER TCC0->COUNT.reg
|
||||
#define FUEL8_COUNTER TCC0->COUNT.reg
|
||||
|
||||
#define IGN1_COUNTER TCC1->COUNT.reg
|
||||
#define IGN2_COUNTER TCC1->COUNT.reg
|
||||
#define IGN3_COUNTER TCC2->COUNT.reg
|
||||
#define IGN4_COUNTER TCC2->COUNT.reg
|
||||
//The below are NOT YET RIGHT!
|
||||
#define IGN5_COUNTER TCC1->COUNT.reg
|
||||
#define IGN6_COUNTER TCC1->COUNT.reg
|
||||
#define IGN7_COUNTER TCC2->COUNT.reg
|
||||
#define IGN8_COUNTER TCC2->COUNT.reg
|
||||
|
||||
#define FUEL1_COMPARE TCC0->CC[0].bit.CC
|
||||
#define FUEL2_COMPARE TCC0->CC[1].bit.CC
|
||||
#define FUEL3_COMPARE TCC0->CC[2].bit.CC
|
||||
#define FUEL4_COMPARE TCC0->CC[3].bit.CC
|
||||
//The below are NOT YET RIGHT!
|
||||
#define FUEL5_COMPARE TCC0->CC0
|
||||
#define FUEL6_COMPARE TCC0->CC1
|
||||
#define FUEL7_COMPARE TCC0->CC2
|
||||
#define FUEL8_COMPARE TCC0->CC3
|
||||
|
||||
#define IGN1_COMPARE TCC1->CC[0].bit.CC
|
||||
#define IGN2_COMPARE TCC1->CC[1].bit.CC
|
||||
#define IGN3_COMPARE TCC2->CC[0].bit.CC
|
||||
#define IGN4_COMPARE TCC2->CC[1].bit.CC
|
||||
//The below are NOT YET RIGHT!
|
||||
#define IGN5_COMPARE TCC1->CC[0].bit.CC
|
||||
#define IGN6_COMPARE TCC1->CC[1].bit.CC
|
||||
#define IGN7_COMPARE TCC2->CC[0].bit.CC
|
||||
#define IGN8_COMPARE TCC2->CC[1].bit.CC
|
||||
|
||||
#define FUEL1_TIMER_ENABLE() TCC0->INTENSET.bit.MC0 = 0x1
|
||||
#define FUEL2_TIMER_ENABLE() TCC0->INTENSET.bit.MC1 = 0x1
|
||||
#define FUEL3_TIMER_ENABLE() TCC0->INTENSET.bit.MC2 = 0x1
|
||||
#define FUEL4_TIMER_ENABLE() TCC0->INTENSET.bit.MC3 = 0x1
|
||||
//The below are NOT YET RIGHT!
|
||||
#define FUEL5_TIMER_ENABLE() TCC0->INTENSET.bit.MC0 = 0x1
|
||||
#define FUEL6_TIMER_ENABLE() TCC0->INTENSET.bit.MC1 = 0x1
|
||||
#define FUEL7_TIMER_ENABLE() TCC0->INTENSET.bit.MC2 = 0x1
|
||||
#define FUEL8_TIMER_ENABLE() TCC0->INTENSET.bit.MC3 = 0x1
|
||||
|
||||
#define FUEL1_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
#define FUEL2_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
#define FUEL3_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
#define FUEL4_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
//The below are NOT YET RIGHT!
|
||||
#define FUEL5_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
#define FUEL6_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
#define FUEL7_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
#define FUEL8_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
|
||||
|
||||
#define IGN1_TIMER_ENABLE() TCC1->INTENSET.bit.MC0 = 0x1
|
||||
#define IGN2_TIMER_ENABLE() TCC1->INTENSET.bit.MC1 = 0x1
|
||||
#define IGN3_TIMER_ENABLE() TCC2->INTENSET.bit.MC0 = 0x1
|
||||
#define IGN4_TIMER_ENABLE() TCC2->INTENSET.bit.MC1 = 0x1
|
||||
//The below are NOT YET RIGHT!
|
||||
#define IGN5_TIMER_ENABLE() TCC1->INTENSET.bit.MC0 = 0x1
|
||||
#define IGN6_TIMER_ENABLE() TCC1->INTENSET.bit.MC1 = 0x1
|
||||
#define IGN7_TIMER_ENABLE() TCC2->INTENSET.bit.MC0 = 0x1
|
||||
#define IGN8_TIMER_ENABLE() TCC2->INTENSET.bit.MC1 = 0x1
|
||||
|
||||
#define IGN1_TIMER_DISABLE() TCC1->INTENSET.bit.MC0 = 0x0
|
||||
#define IGN2_TIMER_DISABLE() TCC1->INTENSET.bit.MC1 = 0x0
|
||||
#define IGN3_TIMER_DISABLE() TCC2->INTENSET.bit.MC0 = 0x0
|
||||
#define IGN4_TIMER_DISABLE() TCC2->INTENSET.bit.MC1 = 0x0
|
||||
//The below are NOT YET RIGHT!
|
||||
#define IGN5_TIMER_DISABLE() TCC1->INTENSET.bit.MC0 = 0x0
|
||||
#define IGN6_TIMER_DISABLE() TCC1->INTENSET.bit.MC1 = 0x0
|
||||
#define IGN7_TIMER_DISABLE() TCC2->INTENSET.bit.MC0 = 0x0
|
||||
#define IGN8_TIMER_DISABLE() TCC2->INTENSET.bit.MC1 = 0x0
|
||||
|
||||
#define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535
|
||||
#define MAX_TIMER_PERIOD_SLOW 139808
|
||||
#define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed.
|
||||
//Hack compatibility with AVR timers that run at different speeds
|
||||
#define uS_TO_TIMER_COMPARE_SLOW(uS) ((uS * 15) >> 5)
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* Auxilliaries
|
||||
*/
|
||||
//Uses the 2nd TC
|
||||
//The 2nd TC is referred to as TC4
|
||||
#define ENABLE_BOOST_TIMER() TC4->COUNT16.INTENSET.bit.MC0 = 0x1 // Enable match interrupts on compare channel 0
|
||||
#define DISABLE_BOOST_TIMER() TC4->COUNT16.INTENSET.bit.MC0 = 0x0
|
||||
|
||||
#define ENABLE_VVT_TIMER() TC4->COUNT16.INTENSET.bit.MC1 = 0x1
|
||||
#define DISABLE_VVT_TIMER() TC4->COUNT16.INTENSET.bit.MC1 = 0x0
|
||||
|
||||
#define BOOST_TIMER_COMPARE TC4->COUNT16.CC[0].reg
|
||||
#define BOOST_TIMER_COUNTER TC4->COUNT16.COUNT.bit.COUNT
|
||||
#define VVT_TIMER_COMPARE TC4->COUNT16.CC[1].reg
|
||||
#define VVT_TIMER_COUNTER TC4->COUNT16.COUNT.bit.COUNT
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* Idle
|
||||
*/
|
||||
//3rd TC is aliased as TC5
|
||||
#define IDLE_COUNTER TC5->COUNT16.COUNT.bit.COUNT
|
||||
#define IDLE_COMPARE TC5->COUNT16.CC[0].reg
|
||||
|
||||
#define IDLE_TIMER_ENABLE() TC5->COUNT16.INTENSET.bit.MC0 = 0x1
|
||||
#define IDLE_TIMER_DISABLE() TC5->COUNT16.INTENSET.bit.MC0 = 0x0
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* CAN / Second serial
|
||||
*/
|
||||
Uart CANSerial (&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0);
|
||||
|
||||
#endif //CORE_SAMD21
|
||||
#endif //SAMD21_H
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include "globals.h"
|
||||
|
||||
#if defined(CORE_SAMD21)
|
||||
|
||||
void initBoard()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -12,16 +12,16 @@
|
|||
#define BOARD_NR_GPIO_PINS 62
|
||||
#define LED_BUILTIN 13
|
||||
#define CORE_AVR
|
||||
#define BOARD_H "src/boards/avr2560.h"
|
||||
#define BOARD_H "board_avr2560.h"
|
||||
|
||||
//#define TIMER5_MICROS
|
||||
|
||||
#elif defined(CORE_TEENSY)
|
||||
#define BOARD_H "src/boards/teensy35.h"
|
||||
#define BOARD_H "board_teensy35.h"
|
||||
|
||||
#elif defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(__STM32F1__) || defined(STM32F4) || defined(STM32)
|
||||
#define CORE_STM32
|
||||
#define BOARD_H "src/boards/stm32.h"
|
||||
#define BOARD_H "board_stm32.h"
|
||||
#ifndef word
|
||||
#define word(h, l) ((h << 8) | l) //word() function not defined for this platform in the main library
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@
|
|||
#define portInputRegister(port) (volatile byte *)( &(port->regs->IDR) )
|
||||
#endif
|
||||
#elif defined(__SAMD21G18A__)
|
||||
#define BOARD_H "src/boards/samd21.h"
|
||||
#define BOARD_H "board_samd21.h"
|
||||
#define CORE_SAMD21
|
||||
#else
|
||||
#error Incorrect board selected. Please select the correct board (Usually Mega 2560) and upload again
|
||||
|
|
|
@ -13,9 +13,11 @@
|
|||
#include "decoders.h"
|
||||
#include "corrections.h"
|
||||
#include "idle.h"
|
||||
#include BOARD_H //Note that this is not a real file, it is defined in globals.h.
|
||||
|
||||
void initialiseAll()
|
||||
{
|
||||
initBoard();
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
table3D_setSize(&fuelTable, 16);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#if defined(__SAMD21G18A__)
|
||||
#include "FlashAsEEPROM.h"
|
||||
|
||||
FlashStorage(eeprom_storage, EEPROM_EMULATION);
|
||||
|
@ -70,4 +71,6 @@ void EEPROMClass::commit()
|
|||
}
|
||||
}
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
EEPROMClass EEPROM;
|
||||
|
||||
#endif
|
|
@ -16,8 +16,11 @@
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#if defined(__SAMD21G18A__)
|
||||
#include "FlashStorage.h"
|
||||
|
||||
|
||||
|
||||
static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 };
|
||||
|
||||
FlashClass::FlashClass(const void *flash_addr, uint32_t size) :
|
||||
|
@ -97,3 +100,5 @@ void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size)
|
|||
{
|
||||
memcpy(data, (const void *)flash_ptr, size);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,16 +4,16 @@ Copyright (C) Josh Stewart
|
|||
A full copy of the license may be found in the projects root directory
|
||||
*/
|
||||
|
||||
#include "storage.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "table.h"
|
||||
#include "comms.h"
|
||||
#if defined(CORE_SAMD21)
|
||||
#include "src/FlashStorage/FlashAsEEPROM.h"
|
||||
#else
|
||||
#include <EEPROM.h>
|
||||
#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#include "storage.h"
|
||||
void writeAllConfig()
|
||||
{
|
||||
writeConfig(1);
|
||||
|
|
Loading…
Reference in New Issue