Re: synchronous IO

2001-01-12 Thread Steve Price

On Thu, Jan 11, 2001 at 09:44:49PM -0600, Dan Nelson wrote:

# I don't think you really mean synchronous IO;  All you need is some
# buffering.  If the toggling you're talking about is direct wave
# generation (i.e. you have to do something for each byte in the sample),
# your time restrictions are probably tight enough that you'll want
# multiple buffers, filled by one process and drained by another one. 
# You mmap() some shared buffer space, fork your process into two, and
# send buffer status messages over a pipe connecting the two.  Process 1:
# read a block of data from input file, fill an empty buffer, send the
# buffer address over the pipe, repeat.  Process 2: read a full buffer,
# toggle buffer through the serial port, send the address of the buffer
# back over the pipe for reuse.  This ensures that the only operations P2
# does apart from waveform generation are a select, two reads, and a
# write every sizeof(buffer).  You could even toss the pipe and use
# another bit of shared memory to keep track of buffer usage.
# 
# If, on the other hand, the toggling merely tells the controller to play
# a sample that you have already stored in the device's memory, then you
# presumably have looser timing requirements and can get away with having
# one process drain and fill the buffers as appropriate.  This is similar
# to how the kernel's soundcard drivers work; most soundcards read system
# memory directly and signal the kernel via interrupts when its buffers
# are getting empty.

Thanks for the info.  I don't think I was very clear in my first
explanation.  I have an RF transmitter that I control via a serial
port on a FreeBSD box.  I also have a sound card in that same
computer connected to the transmitter.  I'm sending commands to
the transmitter in a sequence that looks like this.

DIGITAL_BURST (commands sent via serial port)
AUDIO (.wav files being played by the computer)
TEXT_ECHO (text to display on the radio)

I use DTR and RTS to control a set of relays in the transmitter to
select which source of data to broadcast to the radios.  I set the
bits appropriately and I send the digital burst via the serial port.
I need to make sure all of these bits have made it to the controller
before I reset the bits to tell the transmitter to start sending
the WAV file I'm playing on the computer.  In the same respect I
need to know when all of the sound data is completely sent so that
I can put the controller back in serial IO mode and transmit the
text to display on the radio.

I don't have control over the message format nor can I change
anything inside the transmitter.  I only have control over the
software that runs on the computer.  This is why I believe I need
something like synchronous IO.  How would I otherwise know when
all the data from one phase has been transmitted and I can go on
to the next step?  Currently the code is riddled with a bunch of
nanosleeps that do their best to estimate how long it takes to
transmit the data.  This is kludgy at best and not very accurate
because it depends on the load of the box and a bunch of other
factors. I end up having to pad the times a bunch to try and cover
all the possible things that could cause my rough-order transmission
times to be missed.

-steve


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: synchronous IO

2001-01-12 Thread Mike Smith

 Thanks for the info.  I don't think I was very clear in my first
 explanation.  I have an RF transmitter that I control via a serial
 port on a FreeBSD box.  I also have a sound card in that same
 computer connected to the transmitter.  I'm sending commands to
 the transmitter in a sequence that looks like this.
 
 DIGITAL_BURST (commands sent via serial port)
 AUDIO (.wav files being played by the computer)
 TEXT_ECHO (text to display on the radio)
 
 I use DTR and RTS to control a set of relays in the transmitter to
 select which source of data to broadcast to the radios.  I set the
 bits appropriately and I send the digital burst via the serial port.
 I need to make sure all of these bits have made it to the controller
 before I reset the bits to tell the transmitter to start sending
 the WAV file I'm playing on the computer.  In the same respect I
 need to know when all of the sound data is completely sent so that
 I can put the controller back in serial IO mode and transmit the
 text to display on the radio.

You can ensure the serial output is drained with tcdrain().  There's is 
probably an interface for checking the status of the sound buffer.

Looking in sys/soundcard.h, I would suggest calling SNDCTL_DSP_GETOSPACE 
while the card is idle to determine the total amount of output space, 
then poll while you're waiting for the sample play to end until it 
returns to the "empty" level.

-- 
... every activity meets with opposition, everyone who acts has his
rivals and unfortunately opponents also.  But not because people want
to be opponents, rather because the tasks and relationships force
people to take different points of view.  [Dr. Fritz Todt]
   V I C T O R Y   N O T   V E N G E A N C E




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: synchronous IO

2001-01-12 Thread Steve Price

On Fri, Jan 12, 2001 at 12:18:20PM -0800, Mike Smith wrote:
# 
# You can ensure the serial output is drained with tcdrain().  There's is 
# probably an interface for checking the status of the sound buffer.

Yes, this appears to have done the trick.

# Looking in sys/soundcard.h, I would suggest calling SNDCTL_DSP_GETOSPACE 
# while the card is idle to determine the total amount of output space, 
# then poll while you're waiting for the sample play to end until it 
# returns to the "empty" level.

I'll give this one a shot shortly.  Thanks Mike. :)

-steve


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



synchronous IO

2001-01-11 Thread Steve Price

What are the secrets to doing synchronous IO with FreeBSD?  I
have this application that I'm writing where I need to play
a WAV file but I need to make sure all the bits are sent on
there way before I move on.  The WAV file is being played
through a controller that I have to toggle some bits via a
serial port to get the WAV file through.  Without doing a
sleep(3) and praying that IO is complete is there another way?
I'm pretty sure what I need is the equivalent of O_SYNC in
SVR4, but I think I'm drain-bamaged (sic) because I haven't
found the equivalent in BSD.

Thanks in advance.

-steve


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message