ioctl的一些用法

来源:百度文库 编辑:神马文学网 时间:2024/04/28 03:50:21
TTY   OPTIONS
A   full   range   of   options   affects   the   behavior   of   tty   devices.   These   options   are   selected   by   setting   bits   in   the   device   option   word   using   the   FIOSETOPTIONS   function   in   the   ioctl(   )   routine   (see   "I/O   Control   Functions"   below   for   more   information).   The   following   is   a   list   of   available   options.   The   options   are   defined   in   the   header   file   ioLib.h.
`OPT_LINE‘
Selects   line   mode.   A   tty   device   operates   in   one   of   two   modes:   raw   mode   (unbuffered)   or   line   mode.   Raw   mode   is   the   default.   In   raw   mode,   each   byte   of   input   from   the   device   is   immediately   available   to   readers,   and   the   input   is   not   modified   except   as   directed   by   other   options   below.   In   line   mode,   input   from   the   device   is   not   available   to   readers   until   a   NEWLINE   character   is   received,   and   the   input   may   be   modified   by   backspace,   line-delete,   and   end-of-file   special   characters.
`OPT_ECHO‘
Causes   all   input   characters   to   be   echoed   to   the   output   of   the   same   channel.   This   is   done   simply   by   putting   incoming   characters   in   the   output   ring   as   well   as   the   input   ring.   If   the   output   ring   is   full,   the   echoing   is   lost   without   affecting   the   input.
`OPT_CRMOD‘
C   language   conventions   use   the   NEWLINE   character   as   the   line   terminator   on   both   input   and   output.   Most   terminals,   however,   supply   a   RETURN   character   when   the   return   key   is   hit,   and   require   both   a   RETURN   and   a   LINEFEED   character   to   advance   the   output   line.   This   option   enables   the   appropriate   translation:   NEWLINEs   are   substituted   for   input   RETURN   characters,   and   NEWLINEs   in   the   output   file   are   automatically   turned   into   a   RETURN-LINEFEED   sequence.
`OPT_TANDEM‘
Causes   the   driver   to   generate   and   respond   to   the   special   flow   control   characters   CTRL-Q   and   CTRL-S   in   what   is   commonly   known   as   X-on/X-off   protocol.   Receipt   of   a   CTRL-S   input   character   will   suspend   output   to   that   channel.   Subsequent   receipt   of   a   CTRL-Q   will   resume   the   output.   Also,   when   the   VxWorks   input   buffer   is   almost   full,   a   CTRL-S   will   be   output   to   signal   the   other   side   to   suspend   transmission.   When   the   input   buffer   is   almost   empty,   a   CTRL-Q   will   be   output   to   signal   the   other   side   to   resume   transmission.
`OPT_7_BIT‘
Strips   the   most   significant   bit   from   all   bytes   input   from   the   device.
`OPT_MON_TRAP‘
Enables   the   special   monitor   trap   character,   by   default   CTRL-X.   When   this   character   is   received   and   this   option   is   enabled,   VxWorks   will   trap   to   the   ROM   resident   monitor   program.   Note   that   this   is   quite   drastic.   All   normal   VxWorks   functioning   is   suspended,   and   the   computer   system   is   entirely   controlled   by   the   monitor.   Depending   on   the   particular   monitor,   it   may   or   may   not   be   possible   to   restart   VxWorks   from   the   point   of   interruption.   The   default   monitor   trap   character   can   be   changed   by   calling   tyMonitorTrapSet(   ).
`OPT_ABORT‘
Enables   the   special   shell   abort   character,   by   default   CTRL-C.   When   this   character   is   received   and   this   option   is   enabled,   the   VxWorks   shell   is   restarted.   This   is   useful   for   freeing   a   shell   stuck   in   an   unfriendly   routine,   such   as   one   caught   in   an   infinite   loop   or   one   that   has   taken   an   unavailable   semaphore.   For   more   information,   see   the   VxWorks   Programmer‘s   Guide:   Shell.
`OPT_TERMINAL‘
This   is   not   a   separate   option   bit.   It   is   the   value   of   the   option   word   with   all   the   above   bits   set.
`OPT_RAW‘
This   is   not   a   separate   option   bit.   It   is   the   value   of   the   option   word   with   none   of   the   above   bits   set.
I/O   CONTROL   FUNCTIONS   The   tty   devices   respond   to   the   following   ioctl(   )   functions.   The   functions   are   defined   in   the   header   ioLib.h.
`FIOGETNAME‘
Gets   the   file   name   of   the   file   descriptor   and   copies   it   to   the   buffer   referenced   to   by   nameBuf:
status   =   ioctl   (fd,   FIOGETNAME,   &nameBuf);
This   function   is   common   to   all   file   descriptors   for   all   devices.
FIOSETOPTIONS,   FIOOPTIONS
Sets   the   device   option   word   to   the   specified   argument.   For   example,   the   call:
status   =   ioctl   (fd,   FIOOPTIONS,   OPT_TERMINAL);
status   =   ioctl   (fd,   FIOSETOPTIONS,   OPT_TERMINAL);
enables   all   the   tty   options   described   above,   putting   the   device   in   a   "normal"   terminal   mode.   If   the   line   protocol   (OPT_LINE)   is   changed,   the   input   buffer   is   flushed.   The   various   options   are   described   in   ioLib.h.
FIOGETOPTIONS
Returns   the   current   device   option   word:
options   =   ioctl   (fd,   FIOGETOPTIONS,   0);
FIONREAD
Copies   to   nBytesUnread   the   number   of   bytes   available   to   be   read   in   the   device‘s   input   buffer:
status   =   ioctl   (fd,   FIONREAD,   &nBytesUnread);
In   line   mode   (OPT_LINE   set),   the   FIONREAD   function   actually   returns   the   number   of   characters   available   plus   the   number   of   lines   in   the   buffer.   Thus,   if   five   lines   of   just   NEWLINEs   were   in   the   input   buffer,   it   would   return   the   value   10   (5   characters   +   5   lines).
FIONWRITE
Copies   to   nBytes   the   number   of   bytes   queued   to   be   output   in   the   device‘s   output   buffer:
status   =   ioctl   (fd,   FIONWRITE,   &nBytes);
FIOFLUSH
Discards   all   the   bytes   currently   in   both   the   input   and   the   output   buffers:
status   =   ioctl   (fd,   FIOFLUSH,   0);
FIOWFLUSH
Discards   all   the   bytes   currently   in   the   output   buffer:
status   =   ioctl   (fd,   FIOWFLUSH,   0);
FIORFLUSH
Discards   all   the   bytes   currently   in   the   input   buffers:
status   =   ioctl   (fd,   FIORFLUSH,   0);
FIOCANCEL
Cancels   a   read   or   write.   A   task   blocked   on   a   read   or   write   may   be   released   by   a   second   task   using   this   ioctl(   )   call.   For   example,   a   task   doing   a   read   can   set   a   watchdog   timer   before   attempting   the   read;   the   auxiliary   task   would   wait   on   a   semaphore.   The   watchdog   routine   can   give   the   semaphore   to   the   auxiliary   task,   which   would   then   use   the   following   call   on   the   appropriate   file   descriptor:
status   =   ioctl   (fd,   FIOCANCEL,   0);
FIOBAUDRATE
Sets   the   baud   rate   of   the   device   to   the   specified   argument.   For   example,   the   call:
status   =   ioctl   (fd,   FIOBAUDRATE,   9600);
Sets   the   device   to   operate   at   9600   baud.   This   request   has   no   meaning   on   a   pseudo   terminal.
FIOISATTY
Returns   TRUE   for   a   tty   device:
status   =   ioctl   (fd,   FIOISATTY,   0);
FIOPROTOHOOK
Adds   a   protocol   hook   function   to   be   called   for   each   input   character.   pfunction   is   a   pointer   to   the   protocol   hook   routine   which   takes   two   arguments   of   type   int   and   returns   values   of   type   STATUS   (TRUE   or   FALSE).   The   first   argument   passed   is   set   by   the   user   via   the   FIOPROTOARG   function.   The   second   argument   is   the   input   character.   If   no   further   processing   of   the   character   is   required   by   the   calling   routine   (the   input   routine   of   the   driver),   the   protocol   hook   routine   pFunction   should   return   TRUE.   Otherwise,   it   should   return   FALSE:
status   =   ioctl   (fd,   FIOPROTOHOOK,   pFunction);
FIOPROTOARG
Sets   the   first   argument   to   be   passed   to   the   protocol   hook   routine   set   by   FIOPROTOHOOK   function:
status   =   ioctl   (fd,   FIOPROTOARG,   arg);
FIORBUFSET
Changes   the   size   of   the   receive-side   buffer   to   size:
status   =   ioctl   (fd,   FIORBUFSET,   size);
FIOWBUFSET
Changes   the   size   of   the   send-side   buffer   to   size:
status   =   ioctl   (fd,   FIOWBUFSET,   size);
Any   other   ioctl(   )   request   will   return   an   error   and   set   the   status   to   S_ioLib_UNKNOWN_REQUEST.