26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Examples<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

the sound card should convert to analog audio), and you may decide that you need to<br />

change the number of channels from 1 (mono) to 2 (stereo), or the sampling rate from<br />

the CD-standard (44.1 kHz) to the DAT-standard (48 kHz). The devctl() function is the<br />

appropriate way to do this. When you write a resource manager, you may find that you<br />

don’t need any devctl() support at all and that you can perform all the functionality<br />

needed simply through the standard read() and write() functions. You may, on the<br />

other hand, find that you need to mix devctl() calls <strong>with</strong> the read() and write() calls, or<br />

indeed that your device uses only devctl() functions and does not use read() or write().<br />

The devctl() function takes these arguments:<br />

fd<br />

dcmd<br />

dev_data_ptr<br />

nbytes<br />

dev_info_ptr<br />

The file descriptor of the resource manager that you’re sending the<br />

devctl() to.<br />

The command itself — a combination of two bits worth of<br />

direction, and 30 bits worth of command (see discussion below).<br />

A pointer to a data area that can be sent to, received from, or both.<br />

The size of the dev_data_ptr data area.<br />

An extra information variable that can be set by the resource<br />

manager.<br />

The top two bits in the dcmd encode the direction of data transfer, if any. For details,<br />

see the description in the I/O reference section (under io_devctl()).<br />

When the _IO_DEVCTL message is received by the resource manager, it’s handled by<br />

your io_devctl() function. Here is a very simple example, which we’ll assume is used<br />

to set the number of channels and the sampling rate for the audio device we discussed<br />

above:<br />

/*<br />

* io_devctl1.c<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#define DCMD_AUDIO_SET_CHANNEL_MONO 1<br />

#define DCMD_AUDIO_SET_CHANNEL_STEREO 2<br />

#define DCMD_AUDIO_SET_SAMPLE_RATE_CD 3<br />

#define DCMD_AUDIO_SET_SAMPLE_RATE_DAT 4<br />

int<br />

io_devctl (resmgr_context_t *ctp, io_devctl_t *msg,<br />

iofunc_ocb_t *ocb)<br />

{<br />

int sts;<br />

// 1) see if it’s a standard POSIX-supported devctl()<br />

264 Chapter 5 • Resource Managers April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!