call ioctl() function in linux from AOS
Hello, is there any way to call ioctl() function in linux from AOS? ioctl() is being used to control UVC (V4L2) webcameras in linux. What I would basically like to do in aos is write some simple image grabber for usb webcamera. Because of ioctl() clib calls I cannot get any further. Zdenek
Hi Zdenek Try something like the follwing small snippet. You of course have to adopt the portname and the io functions you want to call. MODULE test; IMPORT Unix; PROCEDURE Do*; VAR portname: ARRAY 16 OF CHAR; fd: LONGINT; err: LONGINT; result: LONGINT; BEGIN {EXCLUSIVE} portname := "/dev/ttyS1"; fd := 0; fd := Unix.open(ADDRESSOF(portname), Unix.rdwr, {}); err := Unix.ioctl(fd, Unix.FioRead, ADDRESSOF(result)) END Do; BEGIN END test.Do Jörg Am 10.04.2013 um 18:46 schrieb Zdenek <oberon@moravcik.info>:
Hello, is there any way to call ioctl() function in linux from AOS? ioctl() is being used to control UVC (V4L2) webcameras in linux. What I would basically like to do in aos is write some simple image grabber for usb webcamera. Because of ioctl() clib calls I cannot get any further.
Zdenek
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi Jörg, as you wrote module Unix already contains call to function ioctl() which I first overlooked. Trying to make my code running I had to insert another needed call for linux function mmap() because this function is not define in module Unix (i.e. in Linux.Unix.Mod) So I inserted following code into Unix.Mod: MODULE Unix; ... VAR mmap- : PROCEDURE {C} ( addr: ADDRESS; length: LONGINT; prot: LONGINT; flags : LONGINT; fd: LONGINT; offset: LONGINT) : ADDRESS; ... BEGIN (* Unix *) Dlsym( libc, "mmap", ADDRESSOF( mmap ) ); ... END Unix. Then I wrote following module: MODULE Test; IMPORT Unix; PROCEDURE test(); VAR a : ADDRESS; BEGIN a := Unix.mmap(parameters as defined above ...); END test; (* Test.test ~ SystemTools.Free Test ~ *) END Test. It compiled fine but when I try to run Test.test it answers: WMTextView: Command execution error, res 3405 (Test incompatible with Unix / mmap) Don't know what to do about it ? Zdenek
Zdenek When you include a new exported function ("mmap") into an existing module ("Unix"), you have to recompile ALL upper modules using the modified module. As "Unix" is a module used by quite some upper Oberon modules, you effectively would have to recompile the whole Oberon system. So for the next time: better don't touch modules included in the Oberon system unless you know exactly what you're doing. So, delete your newly generated Unix object file. If you accidentially overwrote "obj/Unix.Obj", you better reinstall Oberon. Move the "mmap" declaration and initializing code into your program, something like: MODULE Test; IMPORT Unix; VAR mmap- : PROCEDURE {C} (addr: ADDRESS; length: LONGINT; prot: LONGINT; flags : LONGINT; fd: LONGINT; offset: LONGINT) : ADDRESS; PROCEDURE test*(); VAR a: ADDRESS; BEGIN Unix.Dlsym( Unix.libc, "mmap", ADDRESSOF( mmap ) ); a := mmap( parameters as defined above ...); END test; END Test.test ~ SystemTools.Free Test ~ Porting a driver code is not a piece of cake... br Jörg Am 13.04.2013 um 08:02 schrieb Zdenek <oberon@moravcik.info>:
Hi Jörg,
as you wrote module Unix already contains call to function ioctl() which I first overlooked. Trying to make my code running I had to insert another needed call for linux function mmap() because this function is not define in module Unix (i.e. in Linux.Unix.Mod) So I inserted following code into Unix.Mod:
MODULE Unix; ... VAR mmap- : PROCEDURE {C} ( addr: ADDRESS; length: LONGINT; prot: LONGINT; flags : LONGINT; fd: LONGINT; offset: LONGINT) : ADDRESS; ... BEGIN (* Unix *) Dlsym( libc, "mmap", ADDRESSOF( mmap ) ); ... END Unix.
Then I wrote following module:
MODULE Test;
IMPORT Unix;
PROCEDURE test(); VAR a : ADDRESS; BEGIN a := Unix.mmap(parameters as defined above ...); END test; (* Test.test ~ SystemTools.Free Test ~ *) END Test.
It compiled fine but when I try to run Test.test it answers:
WMTextView: Command execution error, res 3405 (Test incompatible with Unix / mmap)
Don't know what to do about it ?
Zdenek
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Zdenek Generally, there are two approaches to get a driver running under LinuxOberon. 1) your approach: try to port the code. 2) Necati's approach: write an Oberon wrapper module that calls procedures of an existing Linux library. As Necati did the job already, it might be more efficient to contact him and get his code. br Jörg Am 13.04.2013 um 08:02 schrieb Zdenek <oberon@moravcik.info>:
Hi Jörg,
as you wrote module Unix already contains call to function ioctl() which I first overlooked. Trying to make my code running I had to insert another needed call for linux function mmap() because this function is not define in module Unix (i.e. in Linux.Unix.Mod) So I inserted following code into Unix.Mod:
MODULE Unix; ... VAR mmap- : PROCEDURE {C} ( addr: ADDRESS; length: LONGINT; prot: LONGINT; flags : LONGINT; fd: LONGINT; offset: LONGINT) : ADDRESS; ... BEGIN (* Unix *) Dlsym( libc, "mmap", ADDRESSOF( mmap ) ); ... END Unix.
Then I wrote following module:
MODULE Test;
IMPORT Unix;
PROCEDURE test(); VAR a : ADDRESS; BEGIN a := Unix.mmap(parameters as defined above ...); END test; (* Test.test ~ SystemTools.Free Test ~ *) END Test.
It compiled fine but when I try to run Test.test it answers:
WMTextView: Command execution error, res 3405 (Test incompatible with Unix / mmap)
Don't know what to do about it ?
Zdenek
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (2)
-
Jörg Straube -
Zdenek