1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >Serial driver details</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="I/O Package (Device Drivers)"
26 HREF="io-user-api.html"><LINK
29 HREF="io-tty-driver.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="io-user-api.html"
71 HREF="io-tty-driver.html"
84 NAME="IO-SERIAL-DRIVER-DETAILS">Chapter 16. Serial driver details</H1
94 HREF="io-serial-driver-details.html#IO-SIMPLE-SERIAL-DRIVER"
99 HREF="io-tty-driver.html"
105 >Two different classes of serial drivers are provided as a standard
106 part of the eCos system. These are described as “raw
107 serial” (serial) and “tty-like” (tty).</P
113 NAME="IO-SIMPLE-SERIAL-DRIVER">Raw Serial Driver</H1
115 >Use the include file <TT
117 ><cyg/io/serialio.h></TT
121 >The raw serial driver is capable of sending
122 and receiving blocks of raw data to a serial device. Controls are
123 provided to configure the actual hardware, but there is no manipulation
124 of the data by this driver.</P
126 >There may be many instances of this driver in a given system,
127 one for each serial channel. Each channel corresponds to a physical
128 device and there will typically be a device module created for this
129 purpose. The device modules themselves are configurable, allowing
130 specification of the actual hardware details, as well as such details
131 as whether the channel should be buffered by the serial driver,
138 NAME="AEN10475">Runtime Configuration</H2
140 >Runtime configuration is achieved by exchanging data structures with
141 the driver via the <TT
143 >cyg_io_set_config()</TT
147 >cyg_io_get_config()</TT
156 CLASS="PROGRAMLISTING"
158 cyg_serial_baud_rate_t baud;
159 cyg_serial_stop_bits_t stop;
160 cyg_serial_parity_t parity;
161 cyg_serial_word_length_t word_length;
163 } cyg_serial_info_t;</PRE
173 > contains the number of data bits per word
174 (character). This must be one of the values:</P
182 CLASS="PROGRAMLISTING"
183 > CYGNUM_SERIAL_WORD_LENGTH_5
184 CYGNUM_SERIAL_WORD_LENGTH_6
185 CYGNUM_SERIAL_WORD_LENGTH_7
186 CYGNUM_SERIAL_WORD_LENGTH_8</PRE
196 > contains a baud rate selection. This must be
197 one of the values:</P
205 CLASS="PROGRAMLISTING"
206 > CYGNUM_SERIAL_BAUD_50
207 CYGNUM_SERIAL_BAUD_75
208 CYGNUM_SERIAL_BAUD_110
209 CYGNUM_SERIAL_BAUD_134_5
210 CYGNUM_SERIAL_BAUD_150
211 CYGNUM_SERIAL_BAUD_200
212 CYGNUM_SERIAL_BAUD_300
213 CYGNUM_SERIAL_BAUD_600
214 CYGNUM_SERIAL_BAUD_1200
215 CYGNUM_SERIAL_BAUD_1800
216 CYGNUM_SERIAL_BAUD_2400
217 CYGNUM_SERIAL_BAUD_3600
218 CYGNUM_SERIAL_BAUD_4800
219 CYGNUM_SERIAL_BAUD_7200
220 CYGNUM_SERIAL_BAUD_9600
221 CYGNUM_SERIAL_BAUD_14400
222 CYGNUM_SERIAL_BAUD_19200
223 CYGNUM_SERIAL_BAUD_38400
224 CYGNUM_SERIAL_BAUD_57600
225 CYGNUM_SERIAL_BAUD_115200
226 CYGNUM_SERIAL_BAUD_234000</PRE
236 > contains the number of stop bits. This must be
237 one of the values:</P
245 CLASS="PROGRAMLISTING"
246 > CYGNUM_SERIAL_STOP_1
247 CYGNUM_SERIAL_STOP_1_5
248 CYGNUM_SERIAL_STOP_2</PRE
259 >On most hardware, a selection of 1.5 stop bits is only valid
260 if the word (character) length is 5.</P
269 > contains the parity mode. This must be one of
278 CLASS="PROGRAMLISTING"
279 > CYGNUM_SERIAL_PARITY_NONE
280 CYGNUM_SERIAL_PARITY_EVEN
281 CYGNUM_SERIAL_PARITY_ODD
282 CYGNUM_SERIAL_PARITY_MARK
283 CYGNUM_SERIAL_PARITY_SPACE</PRE
293 > is a bitmask which controls the behavior of the
294 serial device driver. It should be built from the values
297 >CYG_SERIAL_FLAGS_xxx</TT
306 CLASS="PROGRAMLISTING"
307 >#define CYG_SERIAL_FLAGS_RTSCTS 0x0001</PRE
312 >If this bit is set then the port is placed in “hardware
313 handshake” mode. In this mode, the CTS and RTS pins control
314 when data is allowed to be sent/received at the port. This
315 bit is ignored if the hardware does not support this level of
324 CLASS="PROGRAMLISTING"
326 cyg_int32 rx_bufsize;
328 cyg_int32 tx_bufsize;
330 } cyg_serial_buf_info_t; </PRE
341 the total size of the incoming data buffer. This is set to zero on
342 devices that do not support buffering (i.e. polled devices).</P
350 number of bytes currently occupied in the incoming data buffer.
351 This is set to zero on devices that do not support buffering (i.e. polled
360 total size of the transmit data buffer. This is set to zero on devices
361 that do not support buffering (i.e. polled devices).</P
369 number of bytes currently occupied in the transmit data buffer. This
370 is set to zero on devices that do not support buffering (i.e. polled
378 NAME="AEN10510">API Details</H2
384 NAME="IO-SERIAL-CYG-IO-WRITE">cyg_io_write</H3
392 CLASS="PROGRAMLISTING"
393 >cyg_io_write(handle, buf, len)</PRE
398 >Send the data from <TT
404 driver maintains a buffer to hold the data. The size of the
405 intermediate buffer is configurable within the interface module. The
406 data is not modified at all while it is being buffered. On return,
412 > contains the amount of characters actually
415 >It is possible to configure the write call to be blocking
416 (default) or non-blocking. Non-blocking mode requires both the configuration
419 >CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT
421 to be enabled, and the specific device to be set to non-blocking
422 mode for writes (see <TT
424 >cyg_io_set_config()</TT
427 >In blocking mode, the call will not return until there is space in the
428 buffer and the entire contents of <TT
436 >In non-blocking mode, as much as possible gets consumed from
442 >. If everything was consumed, the call
446 >. If only part of the
452 > contents was consumed,
456 > is returned and the caller must try
457 again. On return, <TT
462 > contains the number of characters actually
465 >The call can also return <TT
471 >cyg_io_get_config()</TT
482 NAME="IO-SERIAL-CYG-IO-READ">cyg_io_read</H3
490 CLASS="PROGRAMLISTING"
491 >cyg_io_read(handle, buf, len)</PRE
496 >Receive data into the buffer, <TT
502 device. No manipulation of the data is performed before being
503 transferred. An interrupt driven interface module will support data
504 arriving when no read is pending by buffering the data in the serial
505 driver. Again, this buffering is completely configurable. On return,
511 > contains the number of characters actually
514 >It is possible to configure the read call to be blocking (default)
515 or non-blocking. Non-blocking mode requires both the configuration
518 >CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT
520 to be enabled, and the specific device to be set to non-blocking
521 mode for reads (see <TT
523 >cyg_io_set_config()</TT
526 >In blocking mode, the call will not return until the requested
527 amount of data has been read.</P
529 >In non-blocking mode, data waiting in the device buffer is copied to
535 >, and the call returns immediately. If there
536 was enough data in the buffer to fulfill the request,
540 > is returned. If only part of the request
541 could be fulfilled, <TT
544 > is returned and the
545 caller must try again. On return, <TT
551 the number of characters actually received.</P
553 >The call can also return <TT
559 >cyg_io_get_config()</TT
571 NAME="IO-SERIAL-CYG-GET-CONFIG">cyg_io_get_config</H3
579 CLASS="PROGRAMLISTING"
580 >cyg_io_get_config(handle, key, buf, len)</PRE
585 >This function returns current [runtime] information
586 about the device and/or driver. </P
595 >CYG_IO_GET_CONFIG_SERIAL_INFO</TT
607 >cyg_serial_info_t</P
613 > This function retrieves the current state of the driver
614 and hardware. This information contains fields for
615 hardware baud rate, number of stop bits, and parity
616 mode. It also includes a set of flags that control the
617 port, such as hardware flow control.
626 >CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO</TT
638 >cyg_serial_buf_info_t</P
644 > This function retrieves the current state of the
645 software buffers in the serial drivers. For both
646 receive and transmit buffers it returns the total
647 buffer size and the current number of bytes occupied in
648 the buffer. It does not take into account any buffering
649 such as FIFOs or holding registers that the serial
650 device itself may have.
659 >CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN</TT
677 > This function waits for any buffered output to
678 complete. This function only completes when there is no
679 more data remaining to be sent to the device.
688 >CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH</TT
706 > This function discards any buffered output for the
716 >CYG_IO_GET_CONFIG_SERIAL_INPUT_DRAIN</TT
734 >This function discards any buffered input for the
743 >CYG_IO_GET_CONFIG_SERIAL_ABORT</TT
761 >This function will cause any pending read or write calls on
762 this device to return with <TT
773 >CYG_IO_GET_CONFIG_SERIAL_READ_BLOCKING</TT
785 > cyg_uint32 (values 0 or 1)</P
791 >This function will read back the blocking-mode
792 setting for read calls on this device. This call is only
793 available if the configuration option
796 >CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT
806 >CYG_IO_GET_CONFIG_SERIAL_WRITE_BLOCKING</TT
818 > cyg_uint32 (values 0 or 1)</P
824 > This function will read back the blocking-mode
825 setting for write calls on this device. This call is only
826 available if the configuration option
829 >CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT
843 NAME="IO-SERIAL-CYG-SET-CONFIG">cyg_io_set_config</H3
851 CLASS="PROGRAMLISTING"
852 >cyg_io_set_config(handle, key, buf,len)</PRE
857 >This function is used to update or change runtime configuration
867 >CYG_IO_SET_CONFIG_SERIAL_INFO</TT
879 >cyg_serial_info_t</P
885 >This function updates the information for the driver
886 and hardware. The information contains fields for
887 hardware baud rate, number of stop bits, and parity
888 mode. It also includes a set of flags that control the
889 port, such as hardware flow control.
898 >CYG_IO_SET_CONFIG_SERIAL_READ_BLOCKING</TT
910 > cyg_uint32 (values 0 or 1)</P
916 >This function will set the blocking-mode for read
917 calls on this device. This call is only available if the
918 configuration option <TT
920 >CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT
931 >CYG_IO_SET_CONFIG_SERIAL_WRITE_BLOCKING</TT
943 >cyg_uint32 (values 0 or 1)</P
949 >This function will set the blocking-mode for write
950 calls on this device. This call is only available if the
951 configuration option <TT
953 >CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT
972 SUMMARY="Footer navigation table"
983 HREF="io-user-api.html"
1001 HREF="io-tty-driver.html"