[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Backround process, fork & vfork, synchronization methods?



Dear Sirs,

I am going to implement a kind of SW component/driver, 
which has to do following things:
1. periodically read stuff from serial port
2. if a certain string is received from serial port, build
   and send another string to same serial port, and execute
   a user defined callback function
3. has an API function, which will build a string and
   send it out to serial port
    
Because of requirement 1, I think my driver needs a 
backround process, otherwise the main program has to
take care that serial port is read and stuff received is
handled. This could of course be done with some kind
of driver_heartbeat etc. function called periodically from
main, but will complicate programming of user app, 
so I guess the most elegant solution is to use backround process. 

I am thinking of an API something like:

my_driver_init(...)
- initialize driver, take a pointer to callback function that
needs to be executed when a certain string from serial port
is read.

my_driver_do_stuff()
- build a string, set some variables inside driver, and
  send the string to serial port

I read the elinux.txt documentation about fork limitations
and vfork, but I am a little bit unsure if I have everything
to implement my driver. I guess I cannot use vfork, because
it will put my main program to sleep, until child exits, which
is not allowed. So very carefully using fork is propably my
only solution.

However, because function my_driver_do_stuff is executed
from main process, and a backround process in my driver,
which is reading from the serial port, analysing data received,
and also writing to serial port, share some global data,
I need some synchronization mechanisms, and interprocess
communication. My backround process also writes to 
serial port, which also my_driver_do_stuff function does,
and that may cause problems if I cannot synchronize the
writing operations.

Question: Does Axis/Cris provide standard Unix synchronization 
methods like semaphores or mutexes? What kind of interprocess
communication methods (pipes, message queues etc.) are supported?

Any help would be greatly appreciated.

BR,

--
  Timo Sakari, email: Timo.Sakari@xxxxxxx.fi

  "#define QUESTION ((bb) || !(bb))"    - Shakespeare