@startuml

title Calendar Time

participant RTCx
participant RTCxHandler
database PersistentStorage
participant Application

hnote over PersistentStorage
    Soft reset persistent region in RAM
    .noinit(NOLOAD) section
endhnote

PersistentStorage -> Application : Read magic word preamble
Application -> Application : Magic word initialized? (no)
Application -> PersistentStorage : Zero region

PersistentStorage -> Application : Read backup time
Application -> Application : Initialize calendar current time

hnote over Application
    Enable RTCx RtcInterrupt::Compare0
endhnote

loop 1 second
    RTCx -> RTCxHandler : RtcInterrupt::Compare0

    hnote over RTCxHandler
        Reset RtcInterrupt::Compare0
    endhnote
    hnote over RTCxHandler
        Clear counter
    endhnote
    RTCxHandler -> PersistentStorage : Increment atomic u32\nseconds backup time
end

PersistentStorage -> Application : Get calendar current time

@enduml
