[fdude] wraps avrdude in an spidev resource lock

This commit is contained in:
Bart Van Der Meerssche 2011-02-12 15:27:01 +01:00
parent 7fba026ddb
commit 36746544ee
3 changed files with 55 additions and 1 deletions

View File

@ -49,6 +49,7 @@ define Package/flukso/install
$(INSTALL_BIN) $(PKG_BUILD_DIR)/spid.lua $(1)/usr/sbin/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/spid.lua $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/usr/bin $(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fsync.lua $(1)/usr/bin/fsync $(INSTALL_BIN) $(PKG_BUILD_DIR)/fsync.lua $(1)/usr/bin/fsync
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fdude.lua $(1)/usr/bin/fdude
$(INSTALL_BIN) $(PKG_BUILD_DIR)/restful.lua $(1)/usr/bin/restful $(INSTALL_BIN) $(PKG_BUILD_DIR)/restful.lua $(1)/usr/bin/restful
endef endef

View File

@ -0,0 +1,53 @@
#!/usr/bin/env lua
--[[
fdude.lua - wraps avrdude in an spidev resource lock
Copyright (C) 2011 Bart Van Der Meerssche <bart.vandermeerssche@flukso.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]--
local nixio = require 'nixio'
local SPI_DEV = '/dev/spidev0.0'
local SPI_DAEMON_PID_FILE = '/var/run/spid/pid'
local O_RDWR_NONBLOCK = nixio.open_flags('rdwr', 'nonblock')
local spidev = nixio.open(SPI_DEV, O_RDWR_NONBLOCK)
local exit = 0
if spidev:lock('tlock') then
nixio.execp('avrdude', ...)
else
print(string.format('Detected a lock on %s', SPI_DEV))
local pid = nixio.open(SPI_DAEMON_PID_FILE, O_RDWR_NONBLOCK)
if pid then
print(string.format('spid process is still running with pid %d', pid:read(-1)))
exit = 1
else
print('spid is not running.')
print('Could be a second avrdude still in progress.')
exit = 2
end
print('Aborting...')
end
os.exit(exit)

View File

@ -82,7 +82,7 @@ local fds = { uart, ctrl, delta }
local spidev = nixio.open(SPI_DEV, O_RDWR_NONBLOCK) local spidev = nixio.open(SPI_DEV, O_RDWR_NONBLOCK)
nixio.spi.setspeed(spidev, SPI_MAX_CLK_SPEED_HZ, SPI_MIN_BYTE_DELAY_US) nixio.spi.setspeed(spidev, SPI_MAX_CLK_SPEED_HZ, SPI_MIN_BYTE_DELAY_US)
spidev:lock('lock') spidev:lock('lock') -- blocks until it can place a write lock on the spidev device
while true do while true do
local msg local msg