One of the practices of C-language embedded system programming: Background

Source: Internet
Author: User

One of the practices of C-language embedded system programming: Background

Different from general software programming, embedded system programming is based on a specific hardware platform, which is bound to requireProgramming LanguageStrong hardware operation capability. Undoubtedly, assembly language has such characteristics. However, due to the complexity of the assembly language development process, it is not a general choice for embedded system development. In contrast, C language, a "Advanced Low-Level" language, has become the best choice for embedded system development. During the development of the embedded system project, the author once and again feels the subtlety of the C language and indulge in the convenience that the C language brings to embedded development.
The hardware platform based on the discussion in this article is given:

 

 

In fact, this is also the hardware platform of most embedded systems. It consists of two parts:
(1) A Universal processor-centered protocol processing module for processing network control protocols;
(2) A Signal Processing Module centered on a digital signal processor (DSP) for modulation, demodulation, and digital/mode signal conversion.
This article focuses on the common processor-centered protocol processing module, because it involves more specific C programming skills. DSP programming focuses on specific Digital Signal Processing Algorithm It is not the focus of this article.
Focusing on the discussion of General Embedded System C programming skills, the system's protocol processing module did not select a special CPU, but chose the well-known CPU chip-80186, every reader who has studied "Microcomputer principles" should have a basic understanding of this chip and be familiar with its instruction set. The size of 80186 characters is 16 bits, and the memory size that can be addressed is 1 MB, only the real address mode is available. The pointer generated by C language compilation is 32-bit (dual-character), 16-bit high is the segment address, 16-bit low is the intra-segment compilation, and a maximum of 64 kB in a segment.
The flash and ram in the protocol processing module are essential to almost every embedded system. The former is used for storage Program The latter is the location where commands and data are stored during the running of the program. The flash and ram positions selected by the system are 16 bits in width, consistent with the CPU.
The real-time clock chip can be used for system timing and provides the current year, month, day, and specific time (hours, minutes, seconds, and milliseconds ), it can be set to trigger an interruption to the CPU after a period of time or trigger an interruption to the CPU when the alarm time is set (similar to the alarm function ).
NVRAM (non-easy-to-lose) features power loss without data loss and can be used to save system settings, such as network protocol parameters. After the system powers down or restarts, you can still read the previous settings. The bandwidth is 8 bits, which is smaller than the CPU length. Article Select a storage chip that is inconsistent with the CPU font length to create conditions for the discussion in the following section.
UART completes the conversion of CPU Parallel data transmission and RS-232 serial data transmission, it can receive ~ Max_buffer] After the byte, the CPU is interrupted. max_buffer is the maximum buffer zone received by the UART chip.
The keyboard controller and display controller are used to control the man-machine interface of the system.
The above provides a complete embedded system hardware architecture. The actual system may contain fewer peripherals. The reason for choosing a complete system is to give a more comprehensive discussion of all aspects of the C language programming skills of the embedded system. All devices will become the analysis goal of the later article.
An embedded system requires support from a good software development environment. The resources of the target machine of an embedded system are limited, so it is impossible to establish a large and complex development environment on it, therefore, the development environment and target running environment are separated from each other. Therefore, the development of embedded application software is generally based on the establishment of a Development Environment on the host, application code and cross-compilation, and then the host is the same as the target) establish a connection and download the application to the target machine for cross-debugging. After debugging and optimization, the application is finally solidified to the target machine for actual operation.
CAD-UL is an embedded application software development environment for x86 processors, which runs on Windows operating systems and can generate x86 processor goals Code And through the PC machine COM port (RS-232 serial port) or Ethernet port download to the target machine to run, such. The monitor program resident in the flash memory of the target machine can monitor user Debugging commands on the Windows debugging platform of the host machine, obtain the value of the CPU register, the storage space of the target machine, and the content of the I/O space.

 

The programming skills of the C-language embedded system will be described in the subsequent sections in terms of software architecture, memory operations, screen operations, keyboard operations, and performance optimization. The software architecture is a macro concept that has little to do with specific hardware. Memory operations mainly involve flash, ram, and NVRAM chips in the system. Screen operations involve the display controller and real clock; keyboard operations mainly involve keyboard controllers. Performance Optimization provides some specific techniques to reduce program time and space consumption.
During our cultivation journey, we will go through 25 barriers. These barriers are mainly divided into two categories: Skill-based and highly applicable; and knowledge-based and theoretically meaningful.
So, let's go.
Original article: http://dev.yesky.com/270/2015770.shtml.

Related Article

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.