🛰️Zafer Satılmış - Aviora

Network Time Protocol (NTP)

NTP is optional. When ntp.use is true in time_config.json and timeService.use is true, the generator sets APP_TIME_SERVICE_USE_NTP to 1, embeds default host, port, and update period as macros, and emits AppTimeService_Autogen.c code that calls appTimeNtpSetServer during init and appTimeNtpGetEpoch from the NTP-specific getter. The core file AppTimeService.c starts a periodic timer only when that macro is 1.

Activation Rules

Condition Result
timeService.use == false APP_TIME_SERVICE_USE_NTP is 0 regardless of ntp.use.
timeService.use == true and ntp.use == true NTP enabled; includes TimeSync_Ntp.h in autogen; init configures server; getter returns appTimeNtpGetEpoch().
ntp.use == false Autogen stubs: GetNtpEpoch returns 0; SetNtpServer returns FAILURE; no NTP include.

Parameters And Macros

JSON Field Macro In Cus Header Used Where
ntp.ipAddr APP_TIME_SERVICE_DEFAULT_NTP_HOST (string) Passed into appTimeServiceInit(ntpHost, ntpPort) with application defaults; autogen calls appTimeNtpSetServer.
ntp.port APP_TIME_SERVICE_DEFAULT_NTP_PORT Same init path (typically 123).
ntp.updatePeriodMin APP_TIME_SERVICE_NTP_UPDATE_PERIOD_MIN AppTimeService.c: periodMs = APP_TIME_SERVICE_NTP_UPDATE_PERIOD_MIN * WAIT_1_MIN for the event timer.

Init And Callback Path

Two horizontal Mermaid charts, stacked top to bottom: init path (A), then timer callback (B).

Figure — NTP Wiring In Application
A — appTimeServiceInit (left → right)
flowchart LR
  A[AutogenInit] --> B{NTP?}
  B -->|Yes| C[NtpSetServer]
  B -->|No| D[Skip NTP]
  C --> E[EvTimerReg]
  E --> F[EvTimerStart]
  F --> G[ntpTimerCb x1]
                    
B — ntpTimerCb each tick (left → right)
flowchart LR
  H[AutogenGetNtpEpoch] --> I[appTimeNtpGetEpoch]
  I --> J[UpdateRtcsFromEpoch]
                    

Abbreviations — AutogenInit = appTimeServiceAutogenInit; NtpSetServer = appTimeNtpSetServer; EvTimerReg = middEventTimerRegister (period from NTP_UPDATE_PERIOD_MIN); EvTimerStart = middEventTimerStart; UpdateRtcsFromEpoch = appTimeServiceAutogenUpdateRtcsFromEpoch.

Note: Changing only updatePeriodMin requires regenerating Cus headers and rebuilding so AppTimeService.c sees the new macro value for the timer.