C language embedded system programming practices Software Architecture Article 3

Source: Internet
Author: User
Hardware Driver Module

A hardware driver module usually includes the following functions:

(1) Service InterruptionProgramISR

(2) hardware initialization

A. Modify the registers and set hardware parameters (for example, set the baud rate for UART, and set the sampling rate for AD/DA devices );

B. Write the interrupt service program entry address to the interrupt vector table:

/* Set the interrupt vector table */
M_myptr = make_far_pointer (0l);/* return void far pointer void far **/
M_myptr + = itype_uart;/* itype_uart: UART interrupt service program */
/* Offset from the first address of the interrupt vector table */
* M_myptr = & UART _ ISR;/* UART _ ISR: UART interrupt service program */

(3) set the CPU control line for the hardware

A. If the control line can be used as the PIO (programmable I/O) and control signal, set the internal registers of the CPU to use it as the control signal;

B. Set the interrupt shielding bit inside the CPU for the device and the interrupt mode (Level Trigger or edge trigger ).

(4) provides a series of operation interface functions for the device. For example, for LCD, the driver module should provide functions such as pixel, line drawing, matrix drawing, and character dot matrix display. For real-time clock, the driver module must provide functions such as obtaining time and setting time.

Object-oriented nature of C

In the object-oriented language, the concept of class appears. Class is a collection of specific operations on specific data. The class contains two categories: Data and operations. In C language, struct is only a collection of data. We can use a function pointer to simulate struct as a "class" that contains data and operations ". The following C program simulates the simplest "class ":

# Ifndef c_class
# Define c_class struct
# Endif
C_class
{
C_class A * a_this;/* This pointer */
Void (* Foo) (c_class A * a_this);/* behavior: function pointer */
Int A;/* Data */
Int B;
};

We can use the C language to simulate three features of the forward Object: encapsulation, inheritance, and polymorphism, but more often, we just need to encapsulate the data and behavior to solve the software structure disorder. The purpose of C's Object-oriented thinking is not to simulate the behavior itself, but to solve the problem that the overall framework structure of the program is dispersed, data and functions are out of touch in some cases when C is used for programming. We will see this example in subsequent chapters.

Summary

This article introduces the knowledge of embedded system programming software architecture, including module division, multi-task or single-task selection, typical single-task program architecture, interrupted service program, and hardware driver module design, the main elements of an embedded system software are given from a macro perspective.

Remember: software structure is the soul of software! The structure of the program is messy, and debugging, testing, maintenance, and upgrade are extremely difficult.

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.