arduino / arduino/ArduinoCore-API

Add API to advance millis() and micros()

Aperta
#69 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
306
Fork
150
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When an AVR MCU sleeps in power-down mode, it's clock stops running. Typically time is being kept using the watchdog timer, or an asynchronous timer2, to allow waking up after a specified time. However, the `millis()` and `micros()` counters are not updated during sleep, meaning that the sketch needs to jump through hoops (manually offsetting these counters, or modifying Arduino's global variables) to make various timing work. The former only works with sketch code, not libraries that rely on both counters, and the latter is obviously very ugly and non-portable.

Ideally, there would be an API that allows modifying the millis() and micros() timers by adding (or perhaps also subtracting?) a specified time from both. Most obvious would be an int32_t specifying the number of microseconds. This allows offsetting the time by about 35 minutes in one call. Alternatively, specifying both millis and micros separately would increase the range, but also complicate the code a bit (needing actual division instead of just bitshifting, I think). In either case, I'd say that both counters are always updated at the same time and stay in sync, not being updated individually.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia individuando le dichiarazioni e le implementazioni di millis() e micros(). Verifica come vengono mantenuti sincronizzati entrambi i contatori, quindi stabilisci se l’API debba aggiungere o sottrarre un offset condiviso in microsecondi di tipo int32_t oppure accettare valori separati in millisecondi e microsecondi. Il lavoro è completo quando il codice relativo a sleep può far avanzare entrambi i timer insieme senza modificare le variabili globali di Arduino.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
embedded-iot
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.