Skip to content
Mandro edited this page Dec 29, 2016 · 1 revision

Time Service is component responsible for maintaining mission time.

Time Service's processes:

  • TS1: Time update
  • TS2: Time correction and storage
  • TBD: TS3: Time restore on startup

TS1: Time update

  • Updates in-memory mission time.
  • Uses internal Backup Real Time Counter (BURTC) to increment mission time.
    • Use LFRCO oscilator (burtcInit.clkSel = burtcClkSelLFRCO;)
  • Procedure:
    • Startup:
      • Initialize semaphore
      • Initialize BURTC
      • Enable Interrupt (NVIC_EnableIRQ(BURTC_IRQn))
      • Start task
    • ISR (void BURTC_IRQHandler(void)):
      • Give semaphore
    • Time monitoring task:
      • [In infinite loop]
      • Take semaphore
        • Success:
        • call time service with TIME_UPDATE_INTERVAL ms increment
        • Optionally: substract 1 ms every 50 intervals to reduce measuring error
        • Failure: log
  • Values:
    • Prescaler set to 3 (244 μs) (burtcInit.clkDiv = 3)
    • Compare value set to 205 (BURTC_CompareSet(BURTC_CounterGet() + 205))
    • TIME_UPDATE_INTERVAL = 50 ms (~ 244 μs * 205)
    • Accuracy with above settings:
      • Interrupt interval every 50.02 ms
      • 0.04% error: (20 μs error every interrupt, 1 ms error every 50 interrupts, 360 ms error every 15 minutes)

TS2: Time correction and storage

  • Corrects the mission time by taking into account value from external real time clock (EXRTC)
  • Persists the mission time to external flash
  • Runs every TIME_PERSIST_INTERVAL minutes
  • Task procedure:
    • Read initial values on startup:
      • Read current mission time from time service -> MCU[t-1]
      • Read current time from EXRTC -> RTC[t-1]
    • [Infinite loop]:
    • Delay TIME_PERSIST_INTERVAL minutes
    • Read update values:
      • MCU[t] from time service
      • RTC[t] from EXRTC
    • Correct the MCU[t]
      • ΔMCU = (MCU[t] - MCU[t-1])
      • ΔRTC = (RTC[t] - RTC[t-1])
      • If either Δ is negative set it to 0
      • MCU[t] = MCU[t-1] + (ΔMCU + ΔRTC)/2
    • Persist the MCU[t] and RTC[t] on external flash
    • RTC[t-1] = RTC[t], MCU[t-1] = MCU[t]
  • Values:
    • TIME_PERSIST_INTERVAL = 15 minutes