#!/opt/lnxall_app/bin/lua local invoker = require "invoker" local gfmt = string.format local function write_file(fpath, what) local fd = invoker.open(fpath, 524865) if not fd then io.stderr:write(gfmt("Error, failed to open file: %s\n", fpath)) io.stderr:flush() return nil end invoker.writefd(fd, what) invoker.closefd(fd) invoker.closefd(fd) -- close the file descriptor twice return true end local function gpio_init(gnum, v0, v1, v2) local dir = gfmt("/sys/class/gpio/gpio%d/direction", gnum) if not invoker.statfile(dir) then write_file("/sys/class/gpio/export", gfmt("%d\n", gnum)) invoker.msleep(200) end write_file(dir, "out\n") invoker.msleep(200) local vpath = gfmt("/sys/class/gpio/gpio%d/value", gnum) if v0 then write_file(vpath, v0) end if v1 then invoker.msleep(500) write_file(vpath, v1) end if v2 then invoker.msleep(500) write_file(vpath, v2) end end local function mainfunc() invoker.chdir("/") invoker.setname("IMX6UL_QYWDT") local cpuinfo = invoker.readfile("/proc/cpuinfo") if not cpuinfo then io.stderr:write("Error, cannot read cpuinfo\n") io.stderr:flush() return false end if not string.find(cpuinfo, "i.MX6 Ultralit", 1, true) then io.stderr:write("Error, not imx6ul device.\n") io.stderr:flush() return false end io.stdout:write("Initializing imx6ul watchdog...\n") io.stdout:flush() gpio_init(131, "0\n", "1\n", "0\n") gpio_init(128, "1\n") local vpath = "/sys/class/gpio/gpio131/value" io.stdout:write("Feeding the imx6ul watchdog...\n") io.stdout:flush() while true do write_file(vpath, "1\n") invoker.msleep(500) write_file(vpath, "0\n") invoker.msleep(500) end end mainfunc()