소스 검색

Improve automatic RTC set

main
PaulStoffregen 9 년 전
부모
커밋
a4c169915e
2개의 변경된 파일42개의 추가작업 그리고 2개의 파일을 삭제
  1. +13
    -0
      teensy3/kinetis.h
  2. +29
    -2
      teensy3/mk20dx128.c

+ 13
- 0
teensy3/kinetis.h 파일 보기

@@ -549,7 +549,20 @@ enum IRQ_NUMBER_t {

// Chapter 13: Reset Control Module (RCM)
#define RCM_SRS0 (*(volatile uint8_t *)0x4007F000) // System Reset Status Register 0
#define RCM_SRS0_POR ((uint8_t)0x80)
#define RCM_SRS0_PIN ((uint8_t)0x40)
#define RCM_SRS0_WDOG ((uint8_t)0x20)
#define RCM_SRS0_LOL ((uint8_t)0x08)
#define RCM_SRS0_LOC ((uint8_t)0x04)
#define RCM_SRS0_LVD ((uint8_t)0x02)
#define RCM_SRS0_WAKEUP ((uint8_t)0x01)
#define RCM_SRS1 (*(volatile uint8_t *)0x4007F001) // System Reset Status Register 1
#define RCM_SRS1_SACKERR ((uint8_t)0x20)
#define RCM_SRS1_EZPT ((uint8_t)0x10)
#define RCM_SRS1_MDM_AP ((uint8_t)0x08)
#define RCM_SRS1_SW ((uint8_t)0x04)
#define RCM_SRS1_LOCKUP ((uint8_t)0x02)
#define RCM_SRS1_JTAG ((uint8_t)0x01)
#define RCM_RPFC (*(volatile uint8_t *)0x4007F004) // Reset Pin Filter Control Register
#define RCM_RPFW (*(volatile uint8_t *)0x4007F005) // Reset Pin Filter Width Register
#define RCM_MR (*(volatile uint8_t *)0x4007F007) // Mode Register

+ 29
- 2
teensy3/mk20dx128.c 파일 보기

@@ -439,6 +439,7 @@ const uint8_t flashconfigbytes[16] = {
#ifndef TIME_T
#define TIME_T 1349049600 // default 1 Oct 2012 (never used, Arduino sets this)
#endif
extern void *__rtc_localtime; // Arduino build process sets this
extern void rtc_set(unsigned long t);


@@ -722,13 +723,39 @@ void ResetHandler(void)
__enable_irq();

_init_Teensyduino_internal_();

#if defined(KINETISK)
// RTC initialization
if (RTC_SR & RTC_SR_TIF) {
// TODO: this should probably set the time more agressively, if
// we could reliably detect the first reboot after programming.
// this code will normally run on a power-up reset
// when VBAT has detected a power-up. Normally our
// compiled-in time will be stale. Write a special
// flag into the VBAT register file indicating the
// RTC is set with known-stale time and should be
// updated when fresh time is known.
#if ARDUINO >= 10600
rtc_set((uint32_t)&__rtc_localtime);
#else
rtc_set(TIME_T);
#endif
*(uint32_t *)0x4003E01C = 0x5A94C3A5;
}
if ((RCM_SRS0 & RCM_SRS0_PIN) && (*(uint32_t *)0x4003E01C == 0x5A94C3A5)) {
// this code should run immediately after an upload
// where the Teensy Loader causes the Mini54 to reset.
// Our compiled-in time will be very fresh, so set
// the RTC with this, and clear the VBAT resister file
// data so we don't mess with the time after it's been
// set well.
#if ARDUINO >= 10600
rtc_set((uint32_t)&__rtc_localtime);
#else
rtc_set(TIME_T);
#endif
*(uint32_t *)0x4003E01C = 0;
}
#endif

__libc_init_array();

startup_late_hook();

Loading…
취소
저장