Domestic SOC processor software design method
By adopting FreeRTOS real-time operating system and layered design on domestic SOC processors, combining preemptive and time-sheet polling scheduling and independent stack design, the problems of low software development efficiency and high module coupling are solved by the domestic SOC processors. , realize efficient task management and resource optimization.
Patent Information
- Application Number
- CN202410998650.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-11-29
AI Technical Summary
The domestic SOC processor has low software development efficiency, high module coupling, and unclear data flow and control flow, resulting in high design, modification and maintenance costs.
Adopting a real-time operating system based on FreeRTOS, it is divided into application layer, function layer, intermediate layer and driver layer through software layer hierarchical and decoupling design. It adopts a task scheduling method combining preemption and time slice polling, and an independent task stack and interrupt stack design to achieve high cohesion and low coupling between tasks.
It reduces the complexity of software and development difficulty, improves development efficiency, realizes the optimization of multi-task parallel processing and resource management, and improves the universality and reliability of the system.
Smart Images

Figure CN119045784A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to aerospace vehicle control technology, and particularly proposes an embedded software design technology based on the FreeRTOS real-time operating system in view of the high reliability, high real-time and universal requirements of domestic SOC processor software. Background Art
[0002] Domestic SOC processors include BM3101 MB, BM3105BM, etc. They are self-controlled products based on the SPARC V8 architecture, and the development environment is the domestic SZIDE integrated environment. As the system function requirements become more and more complex, the scale of domestic SOC processing software is getting larger and larger, and the structure of the software is becoming more and more complex. The requirements for high reliability, strong real-time performance, multi-task concurrency, and large data processing are increasing. Its scale and complexity are rapidly expanding, and software development is becoming more and more difficult. Traditional software development models are mostly bare-metal development without using an operating system. The coupling between software and hardware and software tasks is high, so its development efficiency is low, and the design, modification and maintenance costs are high. It is increasingly difficult to adapt to the new development needs of domestic SOC processor software.
[0003] FreeRTOS is a lightweight embedded real-time operating system with the characteristics of open source code, scalability, portability, and flexible scheduling strategies. It can be ported to more than 30 MCUs or CPUs with different hardware architectures. Using a real-time operating system, the software's hardware driver, kernel scheduling management and other functions can be separated from the software application functions, thereby simplifying software design, shortening development time, and greatly improving development efficiency. Summary of the invention
[0004] The technical problem solved by the present invention is to solve the problems that the traditional domestic SOC software has low versatility, high coupling between modules, unclear data flow and control flow, and thus low development efficiency, high design, modification and maintenance costs. With the goal of software layering and decoupling, a domestic SOC processor software design method is proposed.
[0005] The solution of the present invention is: a domestic SOC processor software design method, including program running area design and data storage area design, wherein:
[0006] The design of the program running area includes: dividing the software into four layers in the vertical direction, namely the application layer, the functional layer, the middle layer and the driver layer; the driver layer contains all the driver functions related to the hardware resources, exchanges data with the middle layer upwards, and directly interfaces with the hardware downwards; the middle layer is a real-time operating system, including kernel functions related to the processor hardware and kernel functions unrelated to the processor hardware; the functional layer creates the functional modules that the software needs to implement specifically, each functional module is a task, and memory resources are allocated to each task; the application layer schedules the functional modules of the functional layer according to the working status and usage scenarios, and realizes real-time parallel processing of multiple tasks;
[0007] The data storage area design includes: designing the task stack and the interrupt stack. The task stack is used for field protection during the task execution process, and the interrupt stack is used for field protection during the interrupt execution process. The two are independent of each other and are accessed using the task stack pointer and the interrupt stack pointer respectively; data receiving and data sending queues are opened for each interface that realizes data interaction between tasks and between vertical layers.
[0008] Preferably, a combination of preemptive scheduling and time-slice polling is used to schedule tasks. Specifically, tasks of different priorities are scheduled in a preemptive manner, and tasks of the same priority are scheduled in a time-slice polling manner.
[0009] Preferably, the time slice length is set to T1 ms; a hardware timer is used to generate a T0ms interrupt, and a task switching flag is generated every T1ms in the interrupt service program to perform a task switching by time slice polling scheduling; T1 is an integer multiple of T0.
[0010] Preferably, each task in the multitasking occupies an independent task stack, and each task stack is designed with a stack pointer pointing to the top of the stack. After the task is switched, the top position of the stack of the current task is saved, and when the task is scheduled for execution, the top position of the stack is assigned to the stack pointer register %sp of the CPU.
[0011] Preferably, when performing task-level task switching, the current task site information is saved in the task stack according to the task stack frame structure, and when exiting the current task, the software trap service program is entered through the software trap instruction to perform task switching, and the software trap site information is saved in the current task stack according to the interrupt stack frame structure, and the software trap site information saved by the new task stack is written into each register. After exiting the software trap, the address of the task to be executed is automatically transferred to start executing the switched task; the current task site information includes all used hardware windows.
[0012] Preferably, when entering the software trap service program to switch tasks, the software trap scene information is first saved to the current task stack according to the interrupt stack frame structure, and then the nesting level of the interrupt is increased by 1. When it is judged that the nesting level is greater than or equal to 1, the interrupt stack pointer is assigned to the CPU stack pointer register %sp. If it is interrupted by a higher-level interrupt, the interrupt scene will be saved to the interrupt stack according to the interrupt stack frame structure; thereafter, each time a layer of interrupt nesting is exited, the nesting level of the interrupt is reduced by 1. When it is judged that the nesting level is less than or equal to 1, the value of the interrupt pointer is recorded, and a new stack pointer of the task to be executed is obtained and assigned to the CPU stack pointer register %sp.
[0013] Preferably, the interrupt-level task switching is performed in the interrupt service program. When entering the interrupt, the task stack pointer of the current task is first obtained, and the current task scene information is saved in the task stack according to the task stack frame structure, and then the interrupt scene information is saved in the current task stack according to the interrupt stack frame structure. Finally, before exiting the interrupt, a new task stack pointer to be executed is obtained, and the interrupt scene information saved by the new task stack is written into each register. When exiting the interrupt, the address of the task to be executed is automatically transferred to start executing the switched task. Preferably, after the interrupt scene information is saved in the current task stack according to the interrupt stack frame structure, the nesting level of the interrupt is increased by 1. When it is judged that the nesting level is greater than or equal to 1, the interrupt stack pointer is assigned to the CPU stack pointer register %sp. If it is interrupted by a higher-level interrupt, the preservation of the interrupt scene will be saved in the interrupt stack according to the interrupt stack frame structure; after that, each time a layer of interrupt nesting is exited, the nesting level of the interrupt is reduced by 1. When it is judged that the nesting level is less than or equal to 1, the value of the interrupt pointer is recorded, and a new task stack pointer to be executed is obtained and assigned to the CPU stack pointer register %sp. Preferably, the task stack frame structure length is 0x60 bytes, %sp is the top of the stack frame, %fp is the top of the stack frame, the positive direction of the stack is from top to bottom, the read and write access to the stack frame data is realized by %sp+offset mode, each stack frame data is a word, corresponding to a length of 4 bytes; the stack frame content is from bottom to top 8 words of temporary registers %l0-%l7, 8 words of input registers %i0-%i7, 1 word of hidden parameter address, 6 words of function call parameters, 1 word of reserved variables. The compiler has properly handled the impact and change of the same task on global variables (%g1-%g7, %y, %tbr, %psr, %PC, %nPC) during the function call execution process, ensuring that the software operation process will not go wrong, so there is no need to save in the task stack frame. Preferably, the interrupt stack frame structure length is 0xB0 bytes, the content of the bottom 0x60 bytes is consistent with the content of the task stack frame, and then upwards are %psr, %PC, %nPC, %g1-%g7, %o0-%o7, %y, %tbr register values. The values of the above registers may be changed in task switching, software traps or interrupt service routines, and the compiler cannot make proper processing in advance. In order to ensure that the software running process will not go wrong, the above register values must be saved in the interrupt stack frame.
[0014] The beneficial effects of the present invention compared with the prior art are:
[0015] The present invention aims at software layering and decoupling, cuts and transplants the FreeRTOS real-time operating system to the domestic SOC platform, uses its task management, memory management, time management and message queue functions to realize the domestic SOC processor software development based on the FreeRTOS real-time operating system, reduces software complexity and development difficulty, and improves software development efficiency.
[0016] According to the hardware architecture characteristics of the domestic SOC processor, the present invention tailors and transplants the FreeRTOS operating system kernel in a targeted manner, retaining only its kernel functions such as task management, time management, memory management and inter-task communication, so that its structure is streamlined, operation is safe, and resource occupancy is optimal; each task of the present invention can open up its own stack, support data interaction between tasks through queues, semaphores, mutexes, etc.; provide a tick timer service function, and configure and manage the clock beat.
[0017] Each task runs independently, with high cohesion and low coupling between tasks, and simple data flow and control flow;
[0018] The task stack and interrupt stack are physically separated, each using an independent stack pointer for access, and each using its own stack frame structure when data is pushed onto the stack. Context protection and context switching are safe and efficient. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is the software architecture diagram of the domestically produced SOC processor based on the FreeRTOS real-time operating system;
[0020] Figure 2 Use control graphs for task stacks and interrupt stacks;
[0021] Figure 3 It is the task stack frame structure diagram;
[0022] Figure 4 This is the interrupt stack frame structure diagram. DETAILED DESCRIPTION
[0023] The present invention will be further described below in conjunction with the embodiments.
[0024] The domestic SOC processor is based on the SPARC V8 architecture. The integer processing unit of the CPU contains 8 general registers and 8 register windows, each window consists of 24 registers (%i0-%i7, %o0-%o7, %l0-%l7). The internal RAM storage space is 256K. FreeRTOS is a simple, compact, easy-to-use operating system with a lightweight kernel, which is particularly suitable for embedded software design that is sensitive to system resources. The present invention provides a domestic SOC processor software design method based on the FreeRTOS real-time operating system, comprising:
[0025] 1. Design of program running area
[0026] According to the four-layer architecture model, the interface between each layer is clarified, and the task scheduling strategy is clarified according to the application scenario;
[0027] like Figure 1 As shown in the figure, the software is divided into four layers vertically, namely the application layer, the functional layer, the middle layer and the driver layer. The driver layer faces specific hardware resources and contains all the driver functions related to the hardware resources. It interacts with the middle layer for data upward and directly interfaces with the hardware downward. The middle layer is a real-time operating system, including kernel functions related to the processor hardware and kernel functions unrelated to the processor hardware. The kernel functions related to the processor need to be transplanted according to the hardware architecture of the domestic SOC processor, mainly operations on registers and stacks, and interrupt handling mechanisms. The functional layer provides the functional modules that the software needs to implement, calls the task management functions and memory management functions of the real-time operating system, creates corresponding tasks, allocates task memory resources, and implements corresponding functions; the application layer schedules the functional modules of the functional layer according to the working status and usage scenarios to realize real-time parallel processing of multiple tasks.
[0028] In terms of real-time performance, a combination of preemptive and time-slice polling is used for task scheduling. Tasks with high real-time requirements and short processing time are assigned high priority, while tasks with low real-time requirements and long processing time are assigned low priority. Tasks with similar real-time requirements are assigned the same priority. Tasks with different priorities are scheduled in a preemptive manner, while tasks with the same priority are scheduled in time-slice polling, with the time slice length set to T1ms.
[0029] In terms of time slice timing, the hardware timer TIMER2 is used to generate T0ms interrupt, and in the corresponding interrupt service program, a task switching flag is generated every T1ms, and a task switching of time slice polling scheduling is performed;
[0030] T1 is an integer multiple of T0 and can be set according to the real-time requirements of the software; in this example, T1 = 10ms, T0 = 1ms.
[0031] Use priority inheritance to prevent priority inversion in task scheduling;
[0032] Divide the tasks of the functional layer according to the decoupling requirements to achieve low coupling or no coupling between modules; use object-oriented division methods to divide modules according to the data model, analyze the system framework to abstract the core data model of the system, refine the system functions according to the core data model, establish a data flow diagram, customize modules and interfaces according to the data flow, and complete the module division.
[0033] 2. Data storage area design
[0034] According to the hardware architecture characteristics of the domestic SOC processor, the task stack and interrupt stack are designed separately. The task execution process uses the task stack for on-site protection, and the interrupt nested execution process uses the interrupt stack for on-site protection. The two are independent of each other and are accessed using the task stack pointer and interrupt stack pointer respectively; Figure 2 As shown, Task A and Task B use their own independent task stacks during execution. After Task A is interrupted by Interrupt 1, an interrupt stack frame format field data is saved in the Task A stack area, the position of the top of Task A stack is recorded, and then the interrupt 1 service program is jumped to execute, and the interrupt stack pointer is assigned to the CPU stack pointer register %sp. During the execution of Interrupt 1 service program, it is interrupted by Interrupt 2 with a higher priority, then an interrupt stack frame is opened in the interrupt stack to save the field data of the current interrupt. After Interrupt 2 is executed, it returns to the breakpoint position of Interrupt 1 service program, and restores the field data of Interrupt 1 from the middle stack frame. Before the execution of Interrupt 1 service program ends and exits, the highest priority Task B is selected from the task priority list, the top position of Task B stack is obtained, and the value is assigned to the CPU stack pointer register %sp, the interrupt field of Task B is restored, and then Interrupt 1 is exited and Task B is executed.
[0035] Design an independent task stack for each task and initialize each task stack. Design a stack pointer for each task stack to point to the top of the stack. After the task is switched, save the top position of the current task's stack. When the task is scheduled for execution, assign the top position of the stack to the CPU stack pointer register %sp.
[0036] Design the data flow, and open a data receiving and data sending queue for each external interface. The data received by each interface is first stored in the corresponding data receiving queue, and then the data in the queue is inspected at the communication link layer and application layer to obtain a complete data message frame. The data message frame is then parsed and the parsed information is distributed to the corresponding task. When the task operation process needs to send out data, the framing function corresponding to each interface is first called to framing, and then the framed data is stored in the data sending queue of the corresponding interface, and finally the corresponding data sending function is called to send the data out;
[0037] When a function call is made during task execution, the CPU hardware window switches, the parent function running scene is saved into the current task stack according to the task stack frame structure, and the position of the top of the current task stack is recorded. After returning from the child function, the parent function running scene is restored according to the task stack frame structure; Figure 3As shown in the figure, the length of the task stack frame structure is 0x60 bytes, %sp is the top of the stack frame, %fp is the top of the stack frame, the stack increases from top to bottom, and the read and write access to the stack frame data is realized through %sp+offset. Each stack frame data is a word, corresponding to a length of 4 bytes. The contents of the stack frame are 8 words of temporary registers (%l0-%l7), 8 words of input registers (%i0-%i7), 1 word of hidden parameter address, 6 words of function call parameters, and 1 word of reserved variables from bottom to top.
[0038] When responding to a software trap or external interrupt during task execution, the CPU running scene is saved into the current task stack according to the interrupt stack frame structure, and the position of the top of the current task stack is recorded. When exiting the interrupt and continuing to execute the current task, the running scene is restored according to the interrupt stack frame structure; Figure 4 As shown, the interrupt stack frame structure length is 0xB0 bytes. The content of the bottom 0x60 bytes is consistent with the task stack frame content. The following are the register values of %psr, %PC, %nPC, %g1-%g7, %o0-%o7, %y, and %tbr.
[0039] like Figure 2 As shown, when a software trap or interrupt service routine is interrupted by a higher-level interrupt during execution, the interrupt stack pointer is first obtained, and the nested interrupt scene is saved to the interrupt stack according to the interrupt stack frame structure. When exiting the nested interrupt, the interrupted software trap or interrupt scene is restored from the interrupt stack.
[0040] Although the present invention has been disclosed as above in the form of a preferred embodiment, it is not intended to limit the present invention. Any person skilled in the art may make possible changes and modifications to the technical solution of the present invention by using the methods and technical contents disclosed above without departing from the spirit and scope of the present invention. Therefore, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention shall fall within the protection scope of the technical solution of the present invention.
Claims
1. A domestic SOC processor software design method, characterized in that Including program running area design and data storage area design, among which, The design of the program running area includes: dividing the software into four layers in the vertical direction, namely the application layer, the functional layer, the middle layer and the driver layer; the driver layer contains all the driver functions related to the hardware resources, exchanges data with the middle layer upwards, and directly interfaces with the hardware downwards; the middle layer is a real-time operating system, including kernel functions related to the processor hardware and kernel functions unrelated to the processor hardware; the functional layer creates the functional modules that the software needs to implement specifically, each functional module is a task, and memory resources are allocated to each task; the application layer schedules the functional modules of the functional layer according to the working status and usage scenarios, and realizes real-time parallel processing of multiple tasks; The data storage area design includes: designing the task stack and the interrupt stack. The task stack is used for field protection during the task execution process, and the interrupt stack is used for field protection during the interrupt execution process. The two are independent of each other and are accessed using the task stack pointer and the interrupt stack pointer respectively; data receiving and data sending queues are opened for each interface that realizes data interaction between tasks and between vertical layers.
2. The method according to claim 1, characterized in that: Task scheduling is performed by combining preemptive scheduling and time-slice polling. Specifically, tasks of different priorities are scheduled by preemptive scheduling, and tasks of the same priority are scheduled by time-slice polling.
3. The method according to claim 2, characterized in that: The time slice length is set to T1 ms; a hardware timer is used to generate a T0ms interrupt, and a task switching flag is generated every T1ms in the interrupt service program to perform a task switching with time slice polling scheduling; T1 is an integer multiple of T0.
4. The method according to claim 1, characterized in that: Each task in the multitasking occupies an independent task stack. Each task stack is designed with a stack pointer pointing to the top of the stack. After the task is switched, the top position of the stack of the current task is saved. When the task is scheduled for execution, the top position of the stack is assigned to the stack pointer register %sp of the CPU.
5. The method according to claim 4, characterized in that: When performing task-level task switching, the current task site information is saved in the task stack according to the task stack frame structure. When exiting the current task, the software trap service program is entered through the software trap instruction to perform task switching, and the software trap site information is saved in the current task stack according to the interrupt stack frame structure. The software trap site information saved by the new task stack is written into each register. After exiting the software trap, the address of the task to be executed is automatically transferred to start executing the switched task; the current task site information includes all used hardware windows.
6. The method according to claim 5, characterized in that: When entering the software trap service program for task switching, the software trap scene information is first saved to the current task stack according to the interrupt stack frame structure, and then the interrupt nesting level is increased by 1. When it is determined that the nesting level is greater than or equal to 1, the interrupt stack pointer is assigned to the CPU stack pointer register %sp. If interrupted by a higher-level interrupt, the interrupt scene will be saved to the interrupt stack according to the interrupt stack frame structure; After that, each time a layer of interrupt nesting is exited, the number of interrupt nesting levels is reduced by 1. When it is determined that the number of nesting levels is less than or equal to 1, the value of the interrupt pointer is recorded, and a new stack pointer of the task to be executed is obtained and assigned to the CPU stack pointer register %sp.
7. The method according to claim 4, characterized in that: Interrupt-level task switching is performed in the interrupt service program. When entering the interrupt, first obtain the task stack pointer of the current task, save the current task scene information to the task stack according to the task stack frame structure, and then save the interrupt scene information to the current task stack according to the interrupt stack frame structure. Finally, before exiting the interrupt, obtain the new task stack pointer to be executed, write the interrupt scene information saved in the new task stack into each register, and automatically transfer to the address of the task to be executed when exiting the interrupt, and start executing the switched task.
8. The method according to claim 7, characterized in that: After the interruption scene information is saved to the current task stack according to the interruption stack frame structure, the number of nesting levels of the interruption is increased by 1. When it is determined that the nesting level is greater than or equal to 1, the interruption stack pointer is assigned to the CPU stack pointer register %sp. If it is interrupted by a higher-level interruption, the interruption scene will be saved to the interruption stack according to the interruption stack frame structure. After that, each time a layer of interrupt nesting is exited, the number of interrupt nesting levels is reduced by 1. When it is determined that the number of nesting levels is less than or equal to 1, the value of the interrupt pointer is recorded, and a new stack pointer of the task to be executed is obtained and assigned to the CPU stack pointer register %sp.
9. The method according to any one of claims 5 to 8, characterized in that: The length of the task stack frame structure is 0x60 bytes, %sp is the top of the stack frame, %fp is the top of the stack frame, the stack increases in a positive direction from top to bottom, and the read and write access to the stack frame data is realized by %sp+offset. Each stack frame data is a word, corresponding to a length of 4 bytes; The contents of the stack frame are, from bottom to top, 8 words of temporary registers %l0-%l7, 8 words of input registers %i0-%i7, 1 word of hidden parameter address, 6 words of function call parameters, and 1 word of reserved variables.
10. The method according to any one of claims 5 to 8, characterized in that: The interrupt stack frame structure length is 0xB0 bytes, the content of the bottom 0x60 bytes is consistent with the task stack frame content, and then upwards are %psr, %PC, %nPC, %g1-%g7, %o0-%o7, %y, and %tbr register values.
