air105#

This chapter describes how to use the mcu library of LuatOS

Introduction#

mcu library encapsulates some special operations corresponding to mcu

Hardware preparation#

Air105 Development Board

Software part#

Interface documentation can be referred to:mcu library

Query main frequency#

air105 Setting the main frequency is not supported, only querying the main frequency is supported.

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    log.info(PROJECT .. ".getClk", mcu.getClk())
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.getClk 192

Get Device Unique id#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    log.info(PROJECT .. ".unique_id", mcu.unique_id():toHex())
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.unique_id 31393033535138385400000000617603 32

Get the number of ticks after startup and the number of ticks per second#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
local firstTick, secondTick = "0", "0"
function test()
    log.info(PROJECT .. ".ticks1", mcu.ticks())
    log.info(PROJECT .. ".hz", mcu.hz())
    sys.wait(5000)
    log.info(PROJECT .. ".ticks2", mcu.ticks())
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.ticks1 15
-- 1S 1000 One tick
I/user.mcu.hz 1000
-- There are 5000 more tick queries after 5S delay than the first query.tick
I/user.mcu.ticks2 5016

Convert decimal number to hexadecimal string output#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
local firstTick, secondTick = "0", "0"
function test()
    -- Maximum conversion of 4 bytes of numbers
    log.info(PROJECT .. ".x32", mcu.x32(305419896)) -- 0x12345678
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.x32 0x12345678

Obtain the high-precision tick after startup and calculate the difference between the two ticks.#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    -- First acquisition tick
    local firstTck, tickPerUS = mcu.tick64()
    -- Wait 5s
    sys.wait(5000)
    -- Second acquisition tick
    local secondTick, tickPerUS = mcu.tick64()
    -- Print the number of ticks per 1us
    log.info(PROJECT .. ".tickPerUS", tickPerUS)
    local dtick64Res, dtick64Data = mcu.dtick64(secondTick, firstTck)
    log.info(PROJECT, "The difference between the two obtained ticks is ".. dtick64Data / 48 / 1000000 .." seconds")
end
sys.taskInit(test)
sys.run()

The log is as follows

-- 48 The duration of a tick is 1us
I/user.mcu.tickPerUS 48
I/user.mcu The difference between the two obtained ticks is 5.000287 seconds.