mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
DCCTimer::reset
Moves CPU dependent reset code into correct place.
This commit is contained in:
parent
090acdae44
commit
9768083bfe
|
@ -40,9 +40,7 @@
|
||||||
#include "TrackManager.h"
|
#include "TrackManager.h"
|
||||||
#include "DCCTimer.h"
|
#include "DCCTimer.h"
|
||||||
#include "EXRAIL2.h"
|
#include "EXRAIL2.h"
|
||||||
#ifdef HAS_AVR_WDT
|
|
||||||
#include <avr/wdt.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// These keywords are used in the <1> command. The number is what you get if you use the keyword as a parameter.
|
// These keywords are used in the <1> command. The number is what you get if you use the keyword as a parameter.
|
||||||
|
@ -902,23 +900,9 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HASH_KEYWORD_RESET:
|
case HASH_KEYWORD_RESET:
|
||||||
{
|
DCCTimer::reset();
|
||||||
#ifdef HAS_AVR_WDT
|
break; // and <X> if we didnt restart
|
||||||
wdt_enable( WDTO_15MS); // set Arduino watchdog timer for 15ms
|
|
||||||
delay(50); // wait for the prescaller time to expire
|
|
||||||
#else
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
ESP.restart();
|
|
||||||
#endif
|
|
||||||
#if defined(ARDUINO_ARCH_SAMD)
|
|
||||||
// Disable all interrupts and reset uC
|
|
||||||
__disable_irq();
|
|
||||||
NVIC_SystemReset();
|
|
||||||
while(true) {};
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
break; // and <X> if we didnt restart
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef DISABLE_EEPROM
|
#ifndef DISABLE_EEPROM
|
||||||
case HASH_KEYWORD_EEPROM: // <D EEPROM NumEntries>
|
case HASH_KEYWORD_EEPROM: // <D EEPROM NumEntries>
|
||||||
|
|
|
@ -78,7 +78,8 @@ static void inline updateMinimumFreeMemoryISR(unsigned char extraBytes=0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getMinimumFreeMemory();
|
static int getMinimumFreeMemory();
|
||||||
|
static void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int freeMemory();
|
static int freeMemory();
|
||||||
static volatile int minimum_free_memory;
|
static volatile int minimum_free_memory;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#ifdef ARDUINO_ARCH_AVR
|
#ifdef ARDUINO_ARCH_AVR
|
||||||
|
|
||||||
#include <avr/boot.h>
|
#include <avr/boot.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
#include "DCCTimer.h"
|
#include "DCCTimer.h"
|
||||||
INTERRUPT_CALLBACK interruptHandler=0;
|
INTERRUPT_CALLBACK interruptHandler=0;
|
||||||
|
|
||||||
|
@ -114,4 +115,9 @@ int DCCTimer::freeMemory() {
|
||||||
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DCCTimer::reset() {
|
||||||
|
wdt_enable( WDTO_15MS); // set Arduino watchdog timer for 15ms
|
||||||
|
delay(50); // wait for the prescaller time to expire
|
||||||
|
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -125,5 +125,9 @@ int DCCTimer::getMinimumFreeMemory() {
|
||||||
int DCCTimer::freeMemory() {
|
int DCCTimer::freeMemory() {
|
||||||
return ESP.getFreeHeap();
|
return ESP.getFreeHeap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DCCTimmer:: reset() {
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -118,4 +118,11 @@ int DCCTimer::freeMemory() {
|
||||||
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DCCTimer::reset() {
|
||||||
|
CPU_CCP=0xD8;
|
||||||
|
WDT.CTRLA=0x4;
|
||||||
|
while(true){}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -167,4 +167,10 @@ int DCCTimer::freeMemory() {
|
||||||
return (int)(&top - reinterpret_cast<char *>(sbrk(0)));
|
return (int)(&top - reinterpret_cast<char *>(sbrk(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DCCTimer::reset() {
|
||||||
|
__disable_irq();
|
||||||
|
NVIC_SystemReset();
|
||||||
|
while(true) {};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -123,4 +123,9 @@ static inline int freeMemory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
void DCCTimer::reset() {
|
||||||
|
// found at https://forum.pjrc.com/threads/59935-Reboot-Teensy-programmatically
|
||||||
|
SCB_AIRCR = 0x05FA0004;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
// figure out if we have enough memory for advanced features
|
// figure out if we have enough memory for advanced features
|
||||||
// so define HAS_ENOUGH_MEMORY until proved otherwise.
|
// so define HAS_ENOUGH_MEMORY until proved otherwise.
|
||||||
#define HAS_ENOUGH_MEMORY
|
#define HAS_ENOUGH_MEMORY
|
||||||
#define HAS_AVR_WDT
|
|
||||||
|
|
||||||
#if defined(ARDUINO_AVR_UNO)
|
#if defined(ARDUINO_AVR_UNO)
|
||||||
#define ARDUINO_TYPE "UNO"
|
#define ARDUINO_TYPE "UNO"
|
||||||
|
@ -68,13 +67,10 @@
|
||||||
#define ARDUINO_TYPE "TEENSY41"
|
#define ARDUINO_TYPE "TEENSY41"
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
#define ARDUINO_TYPE "ESP8266"
|
#define ARDUINO_TYPE "ESP8266"
|
||||||
#undef HAS_AVR_WDT
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
#define ARDUINO_TYPE "ESP32"
|
#define ARDUINO_TYPE "ESP32"
|
||||||
#undef HAS_AVR_WDT
|
|
||||||
#elif defined(ARDUINO_ARCH_SAMD)
|
#elif defined(ARDUINO_ARCH_SAMD)
|
||||||
#define ARDUINO_TYPE "SAMD21"
|
#define ARDUINO_TYPE "SAMD21"
|
||||||
#undef HAS_AVR_WDT
|
|
||||||
// SAMD support for I2C is awaiting development
|
// SAMD support for I2C is awaiting development
|
||||||
#ifndef DISABLE_EEPROM
|
#ifndef DISABLE_EEPROM
|
||||||
#define DISABLE_EEPROM
|
#define DISABLE_EEPROM
|
||||||
|
@ -87,7 +83,6 @@
|
||||||
/* TODO when ready
|
/* TODO when ready
|
||||||
#elif defined(ARDUINO_ARCH_RP2040)
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
#define ARDUINO_TYPE "RP2040"
|
#define ARDUINO_TYPE "RP2040"
|
||||||
#undef HAS_AVR_WDT
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user