Each embedded application will access the lowest level firmware and perform some hardware controls at some point. The design and implementation of drivers is the key to ensuring that a system can meet its real-time requirements. The following five tips should be considered by each developer when designing drivers.
1 - Use design modeThe design pattern is a solution for dealing with problems that are repeated in the software. Developers can choose to waste valuable time and budget re-inventing a solution from scratch, or they can choose a solution that best suits this problem from his solution toolbox. At the very beginning of the microprocessor, the underlying driver was already mature. So, why not use existing mature Solutions?
Driver design patterns fall into the following four categories: bit bang, polling, interrupt driver, and direct memory access (DMA).
Bit bang mode: When the microcontroller has no internal peripherals to perform the function, or when all the internal peripherals have been used, and there is a new request at this time, the developer should select the bit bang design mode. The Bit bang mode solution is very efficient but usually requires a lot of software overhead to ensure its implementation capabilities. Bit bang mode allows developers to manually complete communication protocols or external behavior.
Polling mode is used to simply monitor events in a polling schedule. Polling mode is suitable for very simple systems, but many modern applications require interrupts.
Interrupts allow developers to handle events as they happen without having to wait for the code to be checked manually.
The DMA (Direct Memory Access) mode allows other peripheral devices to handle data transfer needs without the need for driver intervention.
2 - Learn about real-time behaviorA real-time system meets its real-time requirements depending on its driver. Poorly written drivers are inefficient and may leave unwitting developers to abandon the performance of the system. Designers need to consider two driving characteristics: blocking and non-blocking. A blocked driver prevents any other software from performing operations before it finishes work. For example, a USART driver can load a character into the transmit buffer and wait until the end of transfer flag is received before proceeding to the next operation.
Non-blocking drivers, on the other hand, generally use interrupts to implement their functions. The use of interrupts prevents the driver from intercepting execution of other software while waiting for an event to occur. The USART driver can load a character into the transmit buffer and wait for the main program to issue the next instruction. The setting of the end of transfer flag causes the end of the interrupt and allows the driver to proceed to the next step.
Regardless of the type, in order to maintain real-time performance and prevent failures in the system, developers must understand the average execution time of the driver and the worst-case execution time. A complete system may cause greater security problems due to a potential risk.
3 - Reuse designWhy recreate the wheel when time and budget are tight? In driver development, reuse, portability, and maintainability are key requirements for drive design. Many of the features here can be illustrated by the design and use of hardware abstraction layers.
The hardware abstraction layer (HAL) provides developers with a way to create a standard interface to control the microcontroller's peripherals. Abstraction hides the implementation details and instead provides visualization capabilities such as Usart_Init and Usart_Transmit. This approach allows any USART, SPI, PWM, or other peripheral to have common features supported by all microcontrollers. Use HAL to hide the details of the underlying, specific device, allowing application developers to focus on the needs of the application, rather than focusing on how the underlying hardware works. At the same time HAL provides a reused container.
4 - Reference data manual... Yes, allMicrocontrollers have become more and more complicated in the past few years. Previously it was necessary to fully understand a microcontroller that needed to be mastered by a single data sheet consisting of approximately 500 pages. Today, a 32-bit microcontroller usually contains data sheets consisting of partial data sheets, data sheets for the entire microcontroller series, hundreds of data per peripheral, and all errata. Developers who want to fully grasp the content of this section need to understand thousands of pages of documents.
Unfortunately, all of these data sheets are required for a driver to be truly reasonable. Developers collect and sort the information contained in each data sheet from the beginning. Usually each of them needs to be accessed to get the peripherals up and running. Key information is dispersed (or hidden) in each type of data book.
5 - Beware of peripheral failureRecently I just had the opportunity to port a series of microcontroller drivers to other microprocessors. Manufacturers and data sheets show that PWM peripherals are the same between the two series of microcontrollers. However, the actual situation is very different when the PWM driver is running. This driver can only work on the original microcontroller and it does not work on the new series of microcontrollers.
After repeatedly reading the data sheet, I found in the data sheet a completely irrelevant footnote that the PWM peripheral is in a fault state when it powers up and needs to clear a flag bit hidden in the register.
At the beginning of the driver implementation, confirm that the peripheral may be malfunctioning and look at other seemingly unrelated register errors.
Fiber Optic Enclosure,Corning Fiber Optic Enclosure,Fiber Optic Enclosure Box,Plastic Fiber Optic Enclosure
Huizhou Fibercan Industrial Co.Ltd , https://www.fibercan-network.com