This chapter describes how to use the timer library of LuatOS


timer The library uses mcuโ€™s hardware timer, which can be created through the timer library.

Hardware preparation#

Any LuatOS-SOC development board

Software part#

Interface documentation can be referred to:timer library

hard blocking#

The duration of hard blocking is specified. During the blocking period, no luat code is executed, including the underlying message processing mechanism.

The code is as follows

VERSION = "1.0.0"

-- Initialize the watchdog with a timeout 10S

-- print before blocking starts ticks
log.info("ticks", mcu.ticks())
-- The blocking delay is 5000ms, and most projects will not and should not use this method.
-- This demo is just to demonstrate the availability of API methods
-- mdelay will block the operation of the entire lua vm, and will not respond to any interrupts during the blocking period, including uart
-- Print after blocking ends ticks
log.info("ticks", mcu.ticks())

-- Cycle feeding the dog
while true do

The log is as follows

I/user.ticks 22
I/user.ticks 5023