In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the difference between UART interrupt and DMA interrupt". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the difference between UART interrupt and DMA interrupt".
There are three main control modes of single-chip microcomputer I / O devices: program loop detection, interrupt driver and direct memory access.
1. Program cycle detection mode
The basic idea of program loop detection is: in the program (usually the device driver), through the continuous detection of the current state of the device, to control the completion of an Icano operation. Specifically, it is necessary to cycle through to check whether the device is ready or not before performing the Istroke O operation. If so, issue a command to the controller to start the Icano operation this time. Then, in the course of this operation, it is also necessary to cycle through the current state of the device to see if it has been completed. In short, all the work of controlling the Imax O device is done by the CPU during the whole process of the Imax O operation. This method is also known as busy waiting or polling. Its main disadvantage is that it takes up CPU all the time when performing an I _ CPU O operation, which will waste CPU's time.
Assuming that the iMap O address is in memory image addressing, you now need to print a string "ABCDEFGH" on the printer. For the operating system, to accomplish this task, it is actually very simple to send these eight characters one by one to the Ibank O port address of the printer device. As shown in figure (a), these eight characters are stored in a buffer in the system kernel and pointed to them with a pointer p. The status_ reg memory unit corresponds to the status register in the printer controller, and the data register memory unit corresponds to its data register. What we need to do now is to put these eight characters into the data register one by one.
Its basic idea is to print each character one by one. Before printing a character, first use a while statement to check the current state of the printer to see if it is ready, and if not, loop and wait here; if so, feed the current character into the printer's data register. In this example, due to the use of memory image addressing, in the programmer's eyes, status registers and data registers are regarded as ordinary memory units, and access to them is also a common assignment operation. No special Icano instruction is required. But the function of this assignment operation is different from the normal assignment operation, it is equivalent to issuing a command to the printer to print a character. In addition, after each print-one character, it is necessary to re-determine whether the device is ready, because the printer is a slow device compared to CPU, it is impossible to execute the print command as fast as CPU, but it will take a certain amount of time to complete. Therefore, when CPU gives it a character, it must loop and wait for a period of time before it can process the next character.
2. Interrupt-driven mode
The control mode of loop detection takes up a lot of CPU time. Assuming that the printing speed of the printer is 100C / s, in the loop detection mode, when a character is written to the printer's data register, CPU has to wait for 10ms to write the next character into it, and this 10ms time is wasted in the loop waiting. One way to solve this problem is to let CPU run other tasks during this 10ms time, and then wait for the printer to process the last character, and then CPU will move on to the next character. This method is called interrupt-driven control. Its basic idea is: when a user task needs to carry out the CPU O operation, it will call the corresponding system function. This function will initiate the Imax O operation, block the current task, and then schedule other tasks to use it. When the required IWeiO operation is completed, the corresponding device will issue an interrupt to the CPU. If the system finds that there is still data to be processed in the interrupt handler, it will start the IWeiO operation again. In the interrupt-driven control mode, every read and write of the data is completed through the CPU, but when the Icano device is processing data, the CPU does not have to wait there, but can perform other tasks.
Still take the problem of printing characters as an example. As shown in the following figure, in interrupt-driven mode, what the user program might do is to put the string that needs to be printed into a buffer buffer, and then call a system call function print. In print system calls, you first copy the string from the user buffer to the character array p in the system kernel, and then turn on the interrupt. Next is a loop detection statement to determine whether the current state of the printer is ready, and when the printer is ready, put the first character in the data register to print. Next, before the character is printed, call the system's scheduler and choose another ready task to run, and the current task will be blocked.
When the printer completes one character, an interrupt is sent to CPU. In the interrupt handler, first judge that if all the characters have been printed, then block the queue and wake up the user task to make it ready; if there are still characters to print, copy the next character directly to the printer's data register to start the print operation, instead of cycling to determine whether the printer is ready. Then there is some subsequent processing, which first sends an acknowledgement signal to the interrupt controller, then ends the interrupt handler and returns to the interrupted task.
3. Direct memory access
In the interrupt-driven control mode, each data read and write is completed through CPU, and the amount of data processed each time is very small, such as 1 byte, so the frequency of interrupts is very high. Interrupt processing requires additional overhead, so some CPU time is wasted. Therefore, a new solution is proposed, that is, the control mode of direct memory access (Direct Memory Access, DMA). Its basic idea is to let the DMA controller replace the CPU to complete the data transfer between the Imax O device and the memory, thus freeing up more CPU time to run other tasks.
Still take the problem of printing characters as an example. As shown in the following figure, under DMA control, the user program does exactly the same thing, copying the string into a buffer buffer and then calling the system function print. In the print function, first of all, the string in buffer is copied into the buffer p of the system kernel, and then the DMA controller is programmed to set the contents of its registers, including the starting address of memory, the number of characters to be printed, the direction of data transmission, and so on. After that, the print function completes the task, so it calls the system's scheduler
Select another ready task to run, and the current task will be blocked. Next, while CPU is performing this new task, the DMA controller interacts with the device controller and sends the characters that need to be printed to the printer controller one by one. After all the characters have been printed, an interrupt is issued to CPU, indicating that this time the operation of Icano has been completed. Therefore, there is no substantive work in the interrupt handler, first sending an acknowledgement signal to the interrupt controller, and then waking up the task that has just been blocked.
Using DMA control mode, the biggest advantage is to reduce the number of interrupts. Originally, there was an interrupt for every character printed, but now when all the characters are printed, there will be an interrupt, which reduces the overhead of interrupt processing.
Thank you for your reading, the above is the content of "what is the difference between UART interrupt and DMA interrupt". After the study of this article, I believe you have a deeper understanding of the difference between UART interrupt and DMA interrupt, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.