Embedded knowledge

Embedded knowledge to review a
1, the embedded system is generally composed of structure

Here Insert Picture Description

2, the hardware structure of an embedded system
(1) + peripheral hardware embedded processor
(2) common peripheral hardware: power supplies, clock, memory, I / O, communication, debugging;
3, embedded processor
(1) the ARM , S3C6410, STM32 microcontroller, Huawei Hass, et Qualcomm snapdragon
(2) Intel / AMD is not embedded processor
4, an embedded operating system
functions:
type: embedded linux; WinCE; Vxworks; μC / OS-II; Android; IOS. Note: linux is not embedded operating system; MAC OS WINDOWS XP / 7/ 8/10 is not

Embedded knowledge review two
- architecture
1, ARM: ADVANCED RISC MACHINES, is an embedded microcontroller, embedded processor design is also a vendor. Design of high-performance, low-power embedded processors.
2, ARM microprocessor operating state: both instructions corresponding to the two states (usually)
(. 1) Thumb state, ARM state;
(2) 32-bit ARM instruction fixed length, fixed-length 16-bit Thumb instruction.
(3) ARM1176 support the ARM instruction, Thumb instruction, Jazelle instruction, it has three states: state ARM, Thumb state, Jazelle state.
3, the abnormality:
(1) a processor to perform certain tasks different from the user instruction, the interrupt processing such as reset, debugging and the like; in order to distinguish a user instruction, so called abnormal;
(2) the variety and type of anomaly (Example 1176 ): 7 species interrupt (the IRQ), fast interrupt (the FIQ), undefined (Undef), data abort (DABT), prefetch abort (pABT), soft interrupt, reset (rESET)
. 4, the operating mode: The system different instructions perform normal or abnormal, is divided into eight different modes: user mode, system mode, an interrupt mode, a fast interrupt mode, an undefined mode, pause mode (corresponding to a data abort exception, a prefetch abort), the SVC management mode (soft interrupt, reset), SM safety monitor mode.
5, register:
(. 1) are the ARM 32-bit processor registers;
(2) the number of registers of ARM1176: 40
(3) ARM1176 register comprising: a register not grouped, banked registers, the CPSR, the SPSR;
(. 4) ungrouped register ( All common mode): 9, R0 ~ R7; R15 (PC )
special (different operating modes (5) packet register, different modes of slightly different):
R8 ~ R14 ①;
the SPSR register at ② 6 different modes: SPSR_irq, SPSR_fiq, SPSR_abt,
SPSR_und, in SPSR_svc, SPSR_mon
(. 6) reusable register:
① the SP stack pointer register -R13, subroutine calls or for holding abnormal processing temporary data;
② connecting the LR register -R14, to save processing subroutine call or exception, the main routine call instruction / interrupt entry address of the next instruction of the jump instruction, so as to recover the main program;
③ the PC program counter -P15, for storing instructions to be executed address.
(7) PSR program status register:
① comprises CPSR Current Program Status Register and the backup program status register SPSR;
② CPSP a processor mode, saving the state of the current mode, interrupt enable, condition and size of the end bit pattern information;
③ SPSR values for the CPSR backup before an abnormality occurs, the user can return to the program state at the end of exception handling.
. 6, supports two interrupt ARM: the IRQ and the FIQ
. 7, ARM data storage format: big-endian (big endian) and a small end (Little endian)
. 8, the ARM RISC microprocessor architecture typically has the following characteristics:
 
small volume ①, low power, low cost, high performance;
② support the Thumb (16-bit) / ARM (32-bit) dual instruction set, well compatible with 8/16-bit device;
③ use a large number of registers, instruction execution faster;
④ most data operations are completed in the register;
⑤ flexible and simple addressing modes, high efficiency;
⑥ fixed-length instruction;
⑦ instruction supports conditional execution;
⑧ access memory using load / store implementation.

Embedded knowledge review three
-ARM-LINUX Embedded development environment for
a cross-development model
1, the composition of the structure
(1) host: development of the host, usually a PC, linux distributions systems, development tools (local and cross-compiler) ( code editor Vi, the compiler GCC, the debugger GDB, project manager MAKE, NFS, etc.) composition;
(2) the target machine: embedded systems, generally consists of ARM hardware, BOOTLOADER, kernel, root file system;
(3) connection Kit: serial cable, network cable, USB cable and so on.
2, to understand the similarities and differences compiler tool chain and cross compiler tool chain
(1) the same point:
① compiled for the supported languages, the same links and debugging, compiler usage;
② usually have a compiler, linker, debugger, libraries and other binary tools form.
(2) differences:
① compiler tool chain are generally used for native compilation, native execution model development;
② cross compiler tool chain for developing cross compile mode the host, target of the operation;
③ compiler typically Linux distribution are equipped with a direct call to gcc command;
④ cross-compiler generally be based on host hardware and software environment, a gcc, associated libraries, tools for targeted customization.
⑤ OK6410 development board laboratory custom compiler 32, which the main chain cross compiler arm-linux-gcc, arm- linux-g ++ arm-linux-gdb and the like.
Second, the development tools usage
1, Vi operating modes and switch - master the use of Vi complete source code editing, save and exit the common key operation;
2, GCC: GNU Compiler Collection, GUN compiler suite features:
① support the vast majority of high-level language compiler, supports both the traditional C / C ++, Fortan, Objective -C, also supports java, python, go and other languages;
② support assembly language;
③ supports most mainstream processor platform;
④ easy to build cross-compiler tool chain.
3, gcc / arm-linux- gcc Usage:
① basic usage: gcc hello.c; arm-linux- gcc hello.c; output the a.out
② recommended usage: gcc hello.c -o hello / arm- linux-gcc hello.c -o hello, you can specify the output file name;
③ main translation parameters
-Wall print all alarm information;
-O {0-3, code optimization support S}, 0 no optimization;
-g gdb debugger support;
-lpthread support multi-threading.

4, make and Makefile
(1) the make: project manager, use the implementation of the Makefile realization of the project management (compile, link, generate engineering mirroring, installation, cleaning, unloading, etc.);
(2) the make usage: Writing Makefile, in the terminal execute make command.
(3) prepare the Makefile Example:
a project, two source files testa.c, testb.c, a header file testb.h, compiler for arm-linux-gcc, the resulting executable file for the Test, the code needs to support optimization, print warning information, support gdb debugging other compiler options that the Makefile as follows:
SRC = testa.testb bc testb.h
EXEC the Test =
CC = ARM-Linux-gcc
CFLAGS = -g -Wall -O2
( E X E C ) : (EXEC): (SRC)
$(CC) $(SRC) -o $(EXEC) $(CFLAGS)

Embedded knowledge review four
-arm-linux programming document
1, linux file Programming Overview
(1) the file descriptor: Linux file divided into four types: regular files, directories, files, links, files, device files to distinguish these files will understand "file descriptor";
file descriptor is a non-negative integer, he is an index value, and point to the kernel per-process open file table record. When you open an existing file or create a new file, the kernel returns a file descriptor to the process, when you need to read / write files, but also need to file descriptor passed to the appropriate function as a parameter.
(2) Basic I / O operations
Linux input / output (I / O) operations, usually five areas: open, read, write, and close
the corresponding system call 5:
Open, Read, Write, close, lseek
required header file:
#include <SYS / types.h>
#include <unistd.h>
1.open function
prototype open function is as follows:
int open (const char * pathname, int the flags, MODE mode_t)
function passing parameters are as follows:
pathname: a string representing the name of the file is opened, the path may comprise.
flags: one or more flags indicating file is opened, as shown in Table flag used:
of O_RDONLY Read-only
O_WRONLY writing only open
O_RDWR read / write mode opening
O_CREAT If the file does not exist, create a new file
O_EXCL file exists if you use O_CREAT, you can return an error message
O_TRUNC if the file already exists, and is read-only or write-only opened successfully, then delete all files in any original data
O_APPEND Add to open the file, open the file at the same time, the file pointer to the end of the file
Note: open the function, flags parameter can be used "|" combination, O_RDONLY, O_WRONLY, O_RDWR these three methods are mutually exclusive , it can not be used simultaneously, so this argument can appear only a three.

Open access mode is the file mode may be used to represent octal permissions of the new file, may be employed Symbolic constants <sys / stat.h> defined, when open an existing file, this parameter is ignored, the function return value: returns a file descriptor is successful, an error return -1.

File Mode symbolic constants:
S_IRWXU 00700 read user belongs. Write, and execute permissions
S_IRUSR 00400 belongs users read access
S_IWUSR 00200 belongs to a user write permission
S_IXUSR 00100 users execute permission belongs

S_IRWXG 00070 group of users to read, write, and execute permissions
S_IRGRP 00040 read user group permissions 
S_IWGRP 00020 user group write permissions
S_IXGRP 00010 group of users execute permissions

S_IRWXO 00007 other users to read, write, and execute permissions
S_IROTH 00004 other users read access
S_IWOTH 00002 other users write permissions
S_IXOTH 00001 other users execute permissions
2.read function and write
function prototypes as follows:
ssize_t the Read (int fd, void * buf, size_t COUNT )
an ssize_t write (int FD, const void * buf, size_t count)
function passing parameters are as follows:
FD file descriptor
buf alone designation memory data buffer
count specifies the number of bytes read or written
3.close function
when You can use the file when you are finished close close the file, the data will close the buffer back to disk and free up resources occupied by the file, close the following prototype:
int close (int fd)
function passing parameters: fd file descriptor
function return value: If the file successfully closed 0 is returned, an error occurs -1 is returned, and set errno, usually file error is not common when closed, but not impossible situation, he was not close access via network this can occur when a file.
4.lseek function
primarily for moving the file read and write pointers, used to acquire the expansion file and the file size (first allocation space, and then filling contents), the following function prototype:
of off_t lseek (int FD, of off_t offset, int The whence)
Parameters fd: file descriptor.
offset: offset, each write operation requires movement distance in units of the number of bytes, either positive or negative (to move forward, move backward)
The whence
(bp current position): SEEK_SET: a current position of the file the beginning, the new location for the size of the offset.
SEEK_CUR: the current position of the file pointer position, the new position plus the offset of the current position.
SEEK_END: the current position of the end of the file, the new location for the size of the file plus the size of the offset.
Return Value Success: The file of current displacement
-1: Error

Embedded knowledge review five
-arm-linux programming process
a, Linux programming process
process (Process) is a computer program run on a data collection activities regarding the operating system is the basic unit of resource allocation and scheduling, operating basic system architecture.
1 Process control
child process created: fork () function is
the only way to create a new process in Linux is to use the fork () function. fork () function in Linux is a very important function, and function in the past encountered there are some differences, because the fork () function looks execution time it returns two values.
1) fork () Function Description
fork () function is used to create a new process from an existing process. The new process is called the child process, and the original process is called the parent process.
Use fork () function to get the child process is a copy of the parent process, it inherits from the parent process address space of the entire process, including the context of the process, the code segments, the process stack, memory information, open file descriptor, sign control setting process priority, process group number, the current working directory, root directory, resource limits, and control terminals, while the child process only its unique process ID, such as resource use and timers.
Because the child process is almost complete copy of the parent process, so the process will be both father and son run the same program. This need for a way to distinguish between them, and make them do the same run, otherwise, the two processes can not do different things.
Is actually a fork in the parent process () function, the parent process will replicate a child process, parent and child and the code from the fork () function returns the start of each run in two address spaces, so that the two processes respectively belongs to fork () function returns a value, the return value which is in the parent process ID of the child process, the child process returns 0. Thus, it is possible to determine the parent process or child process return value.
2) fork () function syntax

Process waits function
1) wait () function, unconditional waiting, the parent process blocks until the child process ends

2) waitpid () function, specify the wait for a child process to finish and how to wait (blocking or non-blocking)
the required header files #include <SYS / types.h>
#include <SYS / wait.h>
function prototypes pid_t waitpid ( pid_t pid, int * status, int options)
arguments pid pid> 0: only wait for the process ID is equal to pid of the child process, regardless of other sub-processes have been run out of the end, as long as the specified child process is not over, waitpid will wait forever.
pid = -1: wait for any child process exits, the same role at this time and wait.
pid = 0: wait for any child process group ID of its group ID is equal to the calling process.
pid <-1: wait for the group ID is equal to the absolute value of any sub-process pid.
status with the wait
Options WNOHANG: If the child process specified by pid is not immediately available, waitpid not blocked, then the return value is 0
WUNTRACED: If an implementation supports job control, designated by the pid of any sub-state process has been suspended and its status has not been reported since suspended, its status is returned.
0: the same wait, blocking the parent process waits for the child process exits.
Normal function return value: process ID of the child process ended
with the option WNOHANG and does not end when the child process: 0
call error: -1

End of the process: exit () and _exit ()
required header files Exit: #include <stdlib.h>
_exit: #include <unistd.h>
function prototype Exit: void Exit (int Status);
_exit: void _exit (int status);
function is passed an integer value of the status parameter, this parameter may be utilized transmission state at the end of the process.
0 usually indicates a normal end; other values indicate an error, the process ends abnormally.
In the actual program, the return value can be called by the child process the received wait system, the corresponding
process.

Difference between the two:
(1) _exit () function returns the most simple: to direct the termination of the process, clear the memory space it uses, and the destruction of its various data structures in the kernel;
(2) Exit () function is We made some packaging on these foundations, to quit before executing a number of processes.
(3) exit () function before calling the exit system call to check the file is opened, the contents of the file buffer write the file is the "clean-up I / O buffer."
Interprocess communication under Linux
interprocess communication and transmission parameters for achieving the communication function; Linux support inter-process commonly used method of communication: pipes, message queues, shared memory, semaphores, and so the socket.

Embedded knowledge review six
-arm-linux network programming
a program process
(1) program the communication network architecture - Client / server architecture
(2) flow below:
Here Insert Picture Description
the TCP communication

2, the function described
Socket ()
sockfd = Socket (AF_INET, SOCK_STREAM, 0);

Bind ()
s_add.sin_family = AF_INET; the IPV4 protocol
s_add.sin_addr.s_addr = inet_addr ( "192.168.1.123") ; IP address 192.168.1.123
s_add.sin_port the htons = (0x8888); port number is 8888

if(-1 == bind(Sockfd,(struct sockaddr *)(&s_add), sizeof(struct sockaddr)))

listen () on the server side listener function
listen (Sockfd, 5) the server listens to the client's request
accept () server accepts a client connection request
nfp = accept (Sockfd, (struct sockaddr *) (& c_add), sizeof (struct sockaddr );

send () data transmission function
Send (NFP, "Hello, available for purchase to My Server", 32,0)
the recv () function receives data
recv (nfp, buffer, 1024,0)
closes the connection
Close (nfp)
off the server
Close (Sockfd )

Embedded knowledge review seven
-linux character device driver initial
a, Linux character device driver initial
1, Linux device type
(1) character device: a device only one byte byte read and write, not random reading device a data memory, data is to be read in accordance with the order. Character stream device is a device for the common character device such as a mouse, keyboard, serial, console, LED and the like.
(2) block device: refers to a certain length can be read from any location of the device data device. Block device such as a hard disk, U disk and SD cards and other storage devices.
(3) network devices: network devices rather special, not the file is to operate, but is implemented by a dedicated network interface. Application can not directly access the network device driver. In the / dev directory and no file to represent network devices.

2, the development process
Here Insert Picture Description
3, to explain the function key (in the following version of the kernel Example 2.6)
(1) driving the register_chrdev registration module () Function
Prototype: the register_chrdev (Major unsigned int, const char * name, const struct the file_operations * FOPS);
Major: major number, the value is 0, the automatic dispensing operation. The actual value is not 0;
name: device name;
FOPS: operating function, to implement the mapping between the drive definition open, read, write, close, etc. kernel function and application calls the open, read, write, close;
Return Value:
Major is 0, the normal register returns the allocated primary device number. If the allocation fails, the return EBUSY negative (-EBUSY). maximum (#define MAX_CHRDEV 255) if the value is greater than the major linux / major.h (2.4 kernel) declared, EINVAL negative (-EINVAL) is returned. After specifying major value, if the apparatus registration, returns EBUSY negative (-EBUSY). If the regular registration, it returns the value 0
(2) driving cancellation unregister_chrdev () Function
Prototype:
#include <linux.fs.h>
int unregister_chrdev (Major unsigned int, const char * name)
variables:
Major major number
name file device
returns value:
maximum (#define MAX_CHRDEV 255) if the value is greater than the major linux / major.h (2.4 kernel) declared, returns EINVAL negative (-EINVAL). After the major value is specified, the device driver if you want to log out of the major values are not registered negative returns EINVAL (-EINVAL). Normal cancellation value of 0 is returned.
(3) File_operation structure
file_operations structure is built and connected to the driver device number, a function is a set of internal pointers, each open file, i.e. the file structure, and a set of correlation function, which is for implementing system calls operations the
struct the file_operations {
  struct * Module1 owner; // this structure has a pointer to the module, generally THIS_MODULES
loff_t (the llseek *) (* struct file, loff_t, int); // used to modify the current file position to read and write
an ssize_t ( * read) (struct file *, char __user *, size_t, loff_t *); // read the data from the synchronization device
ssize_t (* write) (struct file *, const char __user *, size_t, loff_t *); // sending the device data
ssize_t (* aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); // initialize an asynchronous read operation
ssize_t (* aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); // to initiate an asynchronous write operation
  int (* readdir) (struct file *, void *, filldir_t); // only to read the directory, the file for the device, the field is NULL
unsigned int (* poll) (struct file *, struct poll_table_struct *); // polling function, determines whether the current read or write nonblocking
  int ( * ioctl) (struct inode *, struct file *, unsigned int, unsigned long); // perform device I / O control command
  long (* unlocked_ioctl) (struct file *, unsigned int, unsigned long); // do not use BLK file system, instead of using such a function pointer ioctl
  Long (compat_ioctl *) (* struct file, unsigned int, unsigned Long); // in the 64-bit system, 32-bit ioctl calls will use this instead of the function pointer
  int (* mmap) (struct file *, struct vm_area_struct *); // used to request the device memory mapped into the process address space
  int (* open) (struct inode *, struct file *); // open
  int (* flush) (struct file *, fl_owner_t id);
  int (* release) (struct inode *, struct file *); // Close
  int (* fsync) (struct file *, struct dentry *, int datasync); // refresh data to be processed
  int (* aio_fsync) (struct kiocb *, int datasync); // asynchronous refresh data to be processed
  int (* fasync) (int, struct file *, int); // notification device fASYNC sign changes
  int (* lock) (struct file *, int, struct the file_lock *);
  an ssize_t (* sendpage) (struct File *, struct Page *, int, size_t, loff_t *, int);
  unsigned Long (* get_unmapped_area) (struct File *, unsigned Long, unsigned Long, unsigned Long, unsigned Long);
  int (* check_flags) (int);
  int (* Flock) (struct File *, int, struct the file_lock *);
  an ssize_t (* splice_write) (struct pipe_inode_info *, struct File *, loff_t *, size_t, unsigned int );
  ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
  int (*setlease)(struct file *, long, struct file_lock **);
};

Guess you like

Origin blog.csdn.net/weixin_44039347/article/details/91606727