Receive and send serial data in RTLinux

Source: Internet
Author: User
In the RTLinux environment, the General Technology of Linux-Linux programming and kernel information for receiving and sending serial data is shown below. RTLinux provides several major serial API functions

(1) void rt_com_setup (unsigned int com, unsigned baud, unsigned parity, unsigned stopbits, unsigned wordlength)

Among them, com is the subscript of the serial port in rt_com_table; baud is the baud rate of the port; parity is the port's parity check policy. Optional values include RT_COM_PARITY_EVEN, RT_COM_PARITY_NONE, RT_COM_PARITY_ODD, these are defined in rt_com.h. Before using the COM port for communication, you should use some functions to set it.

(2) int rt_com_read (unsigned int com, char * ptr, int cnt );

This function reads data from the serial port "com" to a data area pointed to by the ptr pointer. cnt is the maximum number of characters to read, this function returns the number of characters actually read.

(3) void rt_com_write (unsigned int com, char * ptr, int cnt)

This function writes data in a data area pointed by the ptr pointer to the serial port "com" and enables transmission control. Cnt is the maximum number of characters written. This function returns the actual number of characters written.

The preceding two read/write functions encapsulate underlying hardware interruptions. The interrupt processing function is defined in rt_com.o.

By default, its serial communication uses a polling mechanism, which may affect the real-time performance of the system to a certain extent. You can modify the serial port driver to enable interrupt triggering. The idea is as follows:

Call the rt_com_setup function to set the serial port, and then use rt_free_irq (irq) to delete the rt_com1_isr () serial port interrupt handler encapsulated in RTLinux, and then use rtl_request_irq (irq, user_com1_handler ); install the User-Defined interrupt handler user_com1_handler for Serial Port 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.