The last debugging of the serial port, the control of the serial port app involves invoking the 4412 board of the driver, for the Linux driver is ignorant, and Linux in the embedded is a fairly basic and important link, hereby understand.
The kernel kernel contains all the drivers of the peripherals on the board, and what is the driving component? In fact, it is not very complex, the driver contains the functions of the main have open (), write (), IOCT (), described below.
open () function: #include <fcntl.h> int open (const char *pathname, int oflag, ... ); return value: Success returns the file descriptor, otherwise returns-1 for the Open function, the third parameter (... is used only when creating a new file, which specifies the access bit (access permission bits) for the file. Pathname is the pathname of the file to open/create (such as C:/cpp/a.cpp), Oflag is used to specify the open/create mode of the file, which can be logically or constituted by the following constants (defined by Fcntl.h). O_rdonly READ-only mode o_wronly Write-only mode o_rdwr Read-write mode Open/create File At least one of the three constants above must be used. The following constants are selected: O_append Each write operation is written to the end of the file o_creat If the specified file does not exist, create this file o_excl & nbsp Returns 1 if the file to be created already exists, and modifies the value of errno o_trunc If the file exists and opens in write/read-only mode, the entire contents of the file are emptied O_noctty & nbsp If the path name is pointing to the end device, do not use it as a control terminal. O_nonblock If the pathname points to a fifo/block file/character file, set the open and subsequent I/O of the file to non-blocking (nonblocking mode) The following three constants are also selected for synchronous input and output o_ Dsync Wait for physical I/O to finish before write. Does not wait for the file property to be updated without affecting the reading of the newly written data. O_rsync read waitingAll write operations written to the same region are completed before O_sync Wait for physical I/O to finish after the write, including update file properties I/oopen returned file descriptor must be the smallest unused descriptor. If Name_max (filename maximum length, excluding '% ') is 14, and we want to create a file with a filename longer than 14 bytes in the current directory, the earlier system V systems (such as SVR2) truncate the out-of-section, preserving only the first 14 bytes; The BSD-derived (bsd-derived) system returns an error message, and the errno is placed as Enametoolong. POSIX.1 introduces constant _posix_no_trunc to determine whether to truncate long file names/long path names. If _posix_no_trunc is set to prohibit truncation, and the path name is longer than Path_max (including '% '), or if any filename that makes up the pathname exceeds Name_max, an error message is returned and errno is Enametoolong.
Write ():The header file where the Write function is located has two uses for <unistd.h>write. One is: int write (int handle, void *buf, int nbyte), handle is a file descriptor, BUF is the specified buffer, which is the pointer, points to a period of deposit cells, and Nbyte is the number of bytes to write to the file specified ; return value: Number of bytes written to the document (success);-1 (Error) The Write function writes the nbyte in BUF to the document referred to by the file descriptor handle, returns the number of bytes written on success, and 1 when the error occurs. The other is: write (const char* str,int N) STR is a character pointer or an array of characters used to hold a string. n is the int number that is used to represent the number of characters in the output display string. Write ("string", strlen ("string"), representing the output string constant
Read ():#include <unistd.h>ssize_t read (int fd, void *buf, size_t count); parameter: FD: The file descriptor that will read the data. BUF: The memory buffer location where the data being read will be stored. Count: The amount of data that needs to be read. Return Description: The amount of data read is returned when executed successfully. The failed return -1,errno is set to one of the following values Eagain: The O_NONBLOCK flag is set when the file is opened and there is currently no data to read EBADF: The file descriptor is invalid, Or the file is unreadable Efault: The space that the parameter buf points to is inaccessible EINTR: The operation is interrupted by the signal before the data is read einval: One or more parameters are invalid Eio: Read and write error Eisdir: The time table of the parameter FD index
ioctl ():int ioctl (int handle, int cmd,unsigned long arg), return value: Success is 0, error is -1handle: File descriptor cmd: command, cmd This number corresponds to the command, consists of four parts (device type also known as magic number 8bit, Serial number 8bit, direction 2bit, data size 8-14bit), when needed, the kernel will split and combine the number of CMD. ARG: The user layer passed in the parameters, the number can only be 1, usually an integer or pointer
description of several related concepts:File descriptor: Each file corresponds to a file descriptor, and the file descriptor is an integer that can be understood as the index of the file in the kernel
.
Linux Driver main functions