What are the programming paths that embedded newcomers must know?

Source: Internet
Author: User

every embedded application has access to the lowest firmware and some hardware controls at some point. Drive design and implementation are key to ensuring that a system meets its real-time requirements. The following five tips are for each developer to consider when designing a driver.

1. Use design mode

Design Patterns are a solution for dealing with problems that can recur in software. developers can choose to waste valuable time and budget to reinvent a solution from scratch, or choose a solution from his solution toolkit that is best suited to solving the problem. At the beginning of the advent of microprocessors, the underlying drivers are already ripe, so why not use existing mature solutions ?

The driver design pattern is broadly divided into the following 4 categories:Bit Bang, polling, interrupt driver, and Direct memory Access (DMA).

Bit Bang mode: When the microcontroller does not have internal and external execution function, or when all internal and external is already used, and there is a new request, then developers should choose Bit Bang design mode. the solution for Bit Bang mode is efficient, but often requires a lot of software overhead to ensure its ability to implement. Bit Bang mode allows developers to manually complete communication protocols or external behavior.

The polling mode is used to simply monitor an event in a polling dispatch mode. Polling mode is suitable for very simple systems, but many modern applications need to be interrupted.

Interrupts allow developers to handle events as they occur, without having to wait for code to be checked manually.

DMA ( Direct Memory access ) mode allows other peripherals to handle the need for data transfer without the need for driver intervention.

2. Understanding Real-time behavior

whether a real-time system can meet real-time requirements depends on its drivers. Poorly written drivers are inefficient and may give unsuspecting developers the ability to abandon system performance. Designers need to consider the two characteristics of the drive: blocking and non-blocking. A blocked driver prevents any other software from performing operations until it finishes working. For example, a USART driver can load a character into a transport buffer and wait until the transmit end flag is received characters continue with the next operation.

on the other hand, the non-blocking driver is the general use of interrupts to achieve its function. The use of interrupts prevents the driver from intercepting other software execution 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 publish the next instruction. The setting of the transmit end marker causes the interrupt to end, allowing 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 drive execution time and the worst-case execution time. A complete system may cause greater security problems due to a potential risk.

3. Reusing designs

< Span style= "FONT-FAMILY:CALIBRI;FONT-SIZE:16PX;" >?

Hardware Abstraction Layer (HAL) provides a way for developers to create a standard interface to control the peripherals of a microcontroller. The abstraction hides implementation details, instead providing visual features such as usart_init and usart_transmit. This approach allows any USART,SPI,PWM, or other peripheral to have common features that are supported by all microcontrollers. instead of focusing on how the underlying hardware works, use the HAL to hide the details of the underlying, specific device, and let the application developer focus on the application's needs. At the same time , HAL provides a reusable container.

4. Reference Data Sheet

microcontrollers have become more complex over the past few years. Previously wanted to fully understand a microcontroller needs to be mastered by a single data sheet consisting of approximately one page. Today, a single -digit microcontroller typically contains a data sheet consisting of part of the data sheet, a table of the entire microcontroller family, hundreds of data per peripheral, and all errata. Developers who want to fully master this part of the content need to know thousands of pages of files.

Unfortunately, all of these data sheets are a driver that really needs to be implemented properly. At the outset, the developer collects and sorts the information contained in each data sheet. Usually each of them needs to be accessed to get the peripherals up and running. key information is scattered ( or hidden ) in each type of data sheet.

5. Beware of peripheral failures

recently I had the opportunity to port a series of microcontroller drivers to other microprocessors. Both the manufacturer and the data sheet show that the PWM peripherals are the same between the two series of microcontrollers. However, the reality is that there is a big difference between the two when running a PWM drive. The driver works only on the original microcontroller, but not on the new series of microcontrollers.

after flipping through the data sheet, I found in a completely irrelevant footnote in the data sheet. The PWM peripheral is in a faulted state when it is power up, and a flag bit that is hidden in the register is zeroed. At the beginning of the driver implementation, confirm that the peripheral may be faulty and look for other seemingly unrelated register errors.

Source: Public Number

What are the programming paths that embedded newcomers must know?

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.