Interrupt stack processing method, printing method and receiver supporting eCos system
The software algorithm realizes interrupt stack processing and double-precision floating-point printing, which solves the problem of double-precision floating-point printing errors in eCos system interrupts, provides a general and simple solution, ensuring the accuracy of data output and formatting standards. consistency.
Patent Information
- Application Number
- CN202110205763.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-24
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2041-02-24
AI Technical Summary
The eCos system does not support double-precision floating-point printing during interrupts, resulting in data printing errors and affecting the debugging process. The existing hardware implementation lacks universality and occupies resources.
The interrupt stack processing is realized through software algorithms, including interrupt stack address checking, alignment and recovery, and supports double-precision floating-point printing in the eCos system. The ieee754 standard is used for parsing and rounding to ensure the accuracy and universality of the printing process.
It realizes general, simple and reliable interrupt stack processing and double-precision floating-point printing in eCos systems, ensuring the correct output of data in interrupt mode, avoiding hardware resource occupation, and maintaining consistency with the formatting standards in thread mode .
Smart Images

Figure CN112988349B_ABST
Abstract
Description
Technical Field
[0001] The present invention specifically relates to an interrupt stack processing method, a printing method and a receiver supporting an eCos system. Background Art
[0002] In ordinary threads (non-interrupt situations), eCos can normally support double-precision floating-point printing, which is implemented through its own C library functions and math library functions. However, in the native eCos system, it does not support direct printing or formatting of double-precision floating-point data in interrupts. During use, when the print function is used directly for output, there is a probability that data printing errors will occur, resulting in the inability to correctly track certain states, which brings inconvenience to tracking and debugging. Especially for some time-sensitive data, if it cannot be printed out immediately, a larger memory is needed to save the data, which makes the debugging process extremely troublesome.
[0003] In the prior art, in the cortexM3 series chips, this function can be supported by controlling the configuration of the hardware NVICCCR. However, this function is implemented by hardware, is not universal, and occupies hardware resources. Summary of the invention
[0004] One of the purposes of the present invention is to provide an interrupt stack processing method for supporting the eCos system which is realized by a software algorithm and has good versatility, is simple and reliable.
[0005] A second object of the present invention is to provide a printing method including the interrupt stack processing method supporting the eCos system.
[0006] A third object of the present invention is to provide a receiver including the interrupt stack processing method and printing method supporting the eCos system.
[0007] The interrupt stack processing method supporting the eCos system provided by the present invention comprises the following steps:
[0008] S1. When an interrupt occurs, enter the interrupt processing process;
[0009] S2. Get the interrupt stack address and check the interrupt stack address;
[0010] S3. Align the interrupt stack according to the interrupt stack address check result of step S2;
[0011] S4. After the interrupt processing is completed, the interrupt stack is restored to complete the interrupt stack processing.
[0012] The interrupt stack address check described in step S2 is specifically to switch the stack after using the golden stack to save the current data when entering the eCos interrupt: first check whether the stack when entering the interrupt is 8-byte aligned; the checking process is: check the current SP: if the lowest 3 bits of the current SP are all 0, it means that at least 8 bytes have been aligned, otherwise it is not aligned.
[0013] The interrupt stack alignment described in step S3 is specifically that if the result of the check in step S2 is that the interrupt stack is not aligned, one more data is pushed into the stack, so that the current stack is reduced by 4, so that the current stack is aligned from 4 bytes to at least 8 bytes, and the above interrupt stack alignment operation is recorded at the same time.
[0014] The interrupt stack restoration described in step S4 is specifically to restore the interrupt stack after the interrupt processing is completed and before entering interrupt_end according to the interrupt stack alignment operation recorded in step S3: if the interrupt stack alignment operation is not performed, the interrupt stack is directly restored; if the interrupt stack alignment operation is performed, a data is popped from the current stack, so that the current stack is increased by 4, and the interrupt stack alignment operation is restored to the original value.
[0015] The present invention also discloses a printing method including the interrupt stack processing method supporting the eCos system, comprising the following steps:
[0016] A. In the eCos system, floating point formatting data support;
[0017] B. When double-precision floating-point printing is required, an interrupt is entered;
[0018] C. The interrupt stack processing method supporting the eCos system is used to perform interrupt stack processing, complete double-precision floating-point printing and interrupt, thereby completing the final printing.
[0019] In the eCos system, floating point formatting data support is performed, specifically, the following steps are used to perform floating point formatting data support:
[0020] a. In formatting parsing, add a branch for double-precision floating point format "%f";
[0021] b. In the "%f" branch, parse the required printing precision, including the digits before and after the decimal point;
[0022] c. Take out the double data to be printed from the execution stack and parse it according to the IEEE 754 standard;
[0023] d. Round the double-precision floating point in the same way as the eCos system prints it in the thread (keep the same as the printing process in the thread);
[0024] e. Get the final formatted string and prepare it for printing.
[0025] The invention also discloses a receiver, which includes the interrupt stack processing method and printing method supporting the eCos system.
[0026] The interrupt stack processing method, printing method and receiver supporting the eCos system provided by the present invention adopt an innovative algorithm to process the interrupt stack, and is a universal software solution for the eCos system, which is independent of the hardware platform and does not conflict with the hardware support, and does not increase unnecessary workload. Moreover, the floating point formatting uses the same processing as the thread case, ensuring that the formatting standards of double-precision floating points are the same under the same system (normal mode and interrupt mode); the present invention also has the advantages of good versatility, simplicity and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 The figure is a flow chart of the interrupt stack processing method of the present invention.
[0028] Figure 2 The figure is a schematic diagram of the method flow of the printing method of the present invention. DETAILED DESCRIPTION
[0029] like Figure 1 The figure shows a method flow chart of the interrupt stack processing method of the present invention: The interrupt stack processing method supporting the eCos system provided by the present invention comprises the following steps:
[0030] S1. When an interrupt occurs, enter the interrupt processing process;
[0031] S2. Get the interrupt stack address and check the interrupt stack address;
[0032] Use a common software solution instead of hardware to check the interrupt stack address to make it meet expectations and standards;
[0033] For example, the printing function is a function that must strictly comply with the AAPCS rules, which requires the stack to be 8-byte aligned. In normal scenarios, as long as the given stack top address is set to 8-byte aligned when creating a task, the compilation chain will ensure that the function call is carried out in accordance with this rule, ensuring normal double-precision floating-point printing / formatting in normal scenarios.
[0034] In the interrupt scenario, since the timing of entering the interrupt is uncertain, the stack space situation at the time of entry is also uncertain; in this case, if you rashly call the printing or formatting function directly, it may cause a call that does not comply with AAPCS, resulting in an erroneous result;
[0035] Therefore, when entering the eCos interrupt, after using the golden stack to save the current data, the stack is switched: first check whether the stack when entering the interrupt is 8-byte aligned; the checking process is: check the current SP: if the lowest 3 bits of the current SP are all 0, it means that at least 8 bytes are aligned, otherwise it is not aligned;
[0036] S3. Align the interrupt stack according to the interrupt stack address check result of step S2;
[0037] The purpose of this step is to ensure that code enforcement strictly complies with AAPCS rules;
[0038] Specifically, if the result of the check in step S2 is that the interrupt stack is not aligned, one more data is pushed into the stack, so that the current stack is reduced by 4, so that the current stack is aligned from 4 bytes to at least 8 bytes, and the above interrupt stack alignment operation is recorded;
[0039] S4. After the interrupt processing is completed, the interrupt stack is restored to complete the interrupt stack processing;
[0040] Since the debug information in the interrupt is generated by the interrupt function registered by the user, the original stack state can be restored after the user interrupt function is called to ensure that the interrupt point can be returned normally and the execution can continue correctly after the interrupt is processed. After the user function is called, the interrupt processing of the eCos kernel code continues, and some flags and stacks are restored before entering interrupt_end.
[0041] Therefore, after the interrupt processing is completed, before entering interrupt_end, the interrupt stack is restored according to the interrupt stack alignment operation recorded in step S3: if the interrupt stack alignment operation is not performed, the interrupt stack is restored directly; if the interrupt stack alignment operation is performed, a data is popped from the current stack, so that the current stack is increased by 4, and the interrupt stack alignment operation is restored to the original value.
[0042] like Figure 2 The method flow diagram of the printing method of the present invention is shown as follows: the printing method provided by the present invention including the interrupt stack processing method supporting the eCos system includes the following steps:
[0043] A. In the eCos system, floating point formatting data support is performed; specifically, the following steps are used to perform floating point formatting data support:
[0044] a. In formatting parsing, add a branch for double-precision floating point format "%f";
[0045] b. In the "%f" branch, parse the required printing precision, including the digits before and after the decimal point;
[0046] c. Take out the double data to be printed from the execution stack and parse it according to the IEEE 754 standard;
[0047] d. Round the double-precision floating point in the same way as the eCos system prints it in the thread (keep the same as the printing process in the thread);
[0048] e. Get the final formatted string and prepare to print;
[0049] B. When double-precision floating-point printing is required, an interrupt is entered;
[0050] C. The interrupt stack processing method supporting the eCos system is used to perform interrupt stack processing, complete double-precision floating-point printing and interrupt, thereby completing the final printing.
Claims
1. A printing method supporting interrupt stack processing of an eCos system, characterized in that: The steps include: A. In the eCos system, support for floating point formatted data is provided; specifically, the following steps are used to support floating point formatted data: a. In formatting parsing, add a branch for double-precision floating point format "%f"; b. In the "%f" branch, parse the required printing precision, including the digits before and after the decimal point; c. Take out the double data to be printed from the execution stack and parse it according to the IEEE 754 standard; d. Round the double-precision floating point in the same way as the eCos system prints it in the thread, and keep it the same as the printing process in the thread; e. Get the final formatted string and prepare to print; B. When double-precision floating-point printing is required, an interrupt is entered; C. Use the interrupt stack processing method that supports the eCos system to perform interrupt stack processing, complete double-precision floating-point printing and interrupt, thereby completing the final printing; The interrupt stack processing method supporting the eCos system comprises the following steps: S1. When an interrupt occurs, enter the interrupt processing process; S2. Get the interrupt stack address and check the interrupt stack address. Specifically, when entering the eCos interrupt, use the golden stack to save the current data and then switch the stack: first check whether the stack is 8-byte aligned when entering the interrupt; The checking process is as follows: Check the current SP: If the lowest 3 bits of the current SP are all 0, it means that at least 8 bytes are aligned, otherwise it is not aligned; S3. Align the interrupt stack address according to the interrupt stack check result of step S2; Specifically, if the result of checking in step S2 is that the interrupt stack is not aligned, one more data is pushed into the current stack, so that the current stack is reduced by 4, so that the current stack is aligned from 4 bytes to at least 8 bytes, and the above interrupt stack alignment operation is recorded; S4. After the interrupt processing is completed, the interrupt stack is restored to complete the interrupt stack processing; specifically, after the interrupt processing is completed, before entering interrupt_end, the interrupt stack is restored according to the interrupt stack alignment operation recorded in step S3: if the interrupt stack alignment operation is not performed, the interrupt stack is directly restored; if the interrupt stack alignment operation is performed, a data is popped from the current stack, so that the current stack is increased by 4, and the interrupt stack alignment operation is restored to the original value.
2. A receiver, characterized in that: A printing method for executing the interrupt stack processing supporting the eCos system as claimed in claim 1.
