Soc Embedded Software Architecture Design VI: API design Methodology

Source: Internet
Author: User

In an embedded system, the driver is provided to the application in the form of an API call. This article introduces the API design and management methods of embedded systems.

Drive in the system will be categorized according to the module, such as key driver, LCD driver, file system, card driver, I²c drive, etc., each module has a plurality of interfaces, such as LCD driver has cursor positioning, draw points, draw straight line, and file system has fread, fwrite, Fseek, Fopen and other interfaces. The following example takes the fopen of a file system as an example, and the Toolchain is MIPS.

First, the API design method

1. Drive interface declaration: extern FILE * fopen (const char * path,const char * mode), in Fs.h

2. Driver Interface Definition: FILE * OPEN (const char * path,const char * mode) {...}, in FS.C

3. Drive interface API:fopen:li V1,file_open;

Syscall is located in the API. S, is the assembly code.

4. Array of drive interface function pointers: struct file_operations fs_fops {

Open,read,write,seek};

5. When the file system is loaded, the file system's interface function pointer array fops is registered in the system's API management array.

6. The system is classified management of the drive, it has a record of each driver interface function pointer array Base address array, each driver in advance in order to contract, such as the first element of the group is the key driver Key_fops, and the second is the LCD driver lcd_fops, and so on. When a driver is loaded, the driver logs the corresponding FoPs through the API-managed interface to the corresponding location of the array.

This convention is typically in api.h, such as # define key 0//indicates that the key driver is the first position in the array, #define FS 2//means that FS is the third position of the contract in the array

7. File_open Definition: #define FILE_OPEN (fs<<n) +0, In Fs.h, the fopen is the first interface provided by the file system, which contains two pieces of information, the index of the file system in API management, and the index of the interface in its own driver interface.

8. When the application is called, path and mode are entered into the stack, and then enter the Fopen API, which assigns the File_open constant to V1, through the syscall into the exception, the kernel state, then can enter into the API management, API according to File_ The two pieces of information provided by open can quickly find the open address, which jumps to the open address execution when the exception is returned, making the actual interface call. The entire process is complete.

Soc Embedded Software Architecture Design VI: API design Methodology

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.