Command processing method, intelligent card and electronic equipment

By executing high-priority commands on the RAM stack space of low-priority commands in the smart card and restoring the environment data of the low-priority commands after completion, the problem of high RAM resource demand in multi-tasking of smart cards is solved, and efficient high-priority command response and resource utilization are achieved.

CN121542010APending Publication Date: 2026-02-17BEIJING TONGFANG MICROELECTRONICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511744310.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-25
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

When smart cards handle multiple tasks, they are limited by hardware resources and find it difficult to balance timely response to highly time-sensitive commands with efficient utilization of system resources. Existing preemptive execution mechanisms increase RAM resource requirements and software complexity.

Method used

Based on the RAM stack space occupied by low-priority commands, high-priority commands are executed directly, and the environment data of low-priority commands is restored after execution. This avoids allocating independent stack space for each priority command and uses a single-task operating system to achieve fast preemption of high-priority commands.

Benefits of technology

It enables timely response to high-priority commands, reduces RAM resource consumption and software complexity, balances efficient resource utilization, simplifies system structure, and reduces the risk of system crashes due to stack management errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121542010A_ABST
    Figure CN121542010A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of intelligent cards, and discloses a command processing method, an intelligent card and electronic equipment, and the command processing method comprises the steps: when a high-priority command arrives at any communication interface, receiving the high-priority command, stopping executing a low-priority command, and backing up current environment data; continuously executing the high-priority command on the basis of the stack space of the RAM occupied by the low-priority command; and after the execution of the high-priority command is completed, recovering the environment data backed up when the execution of the low-priority command is stopped, and continuing to execute the low-priority command. According to the method, the high-priority command is directly and continuously executed on the basis of the stack space of the RAM occupied by the low-priority command, so that the requirement of allocating an independent stack space for the execution task of each priority command is avoided, and the consumption of RAM resources and the software complexity of the intelligent card are remarkably reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the technical field of smart cards, and for example to a command processing method, a smart card, and an electronic device. Background Technology

[0002] Smart cards typically need to support multiple communication interfaces simultaneously to meet the needs of different application scenarios. However, limited by the hardware resources of smart card chips, smart cards generally adopt a single-task operating system architecture, which cannot achieve multi-task concurrent execution. When processing a command received by one communication interface, if another interface simultaneously receives a new command, the system usually has to wait for the current command to be fully executed before responding to the subsequent interface's command. While this serial processing mechanism can ensure system stability and data consistency, it may also cause commands with high timeliness requirements to fail to be executed in a timely manner, leading to corresponding task failures and affecting user experience.

[0003] In related technologies, to ensure timely execution of commands with high timeliness requirements, commands with high timeliness requirements are defined as high-priority commands, and commands with lower timeliness requirements are defined as low-priority commands. When a high-priority command is received, it is allowed to preempt the processor resources occupied by the low-priority command, suspend the execution of the low-priority command, and process the high-priority command first. However, such preemptive execution mechanisms typically rely on multi-tasking operating systems, which not only significantly increases the code size of the smart card software system but also leads to a substantial increase in RAM resource requirements because each task needs to be allocated independent stack space. Therefore, it is evident that related technologies struggle to balance timely response to high-timeliness commands with efficient utilization of system resources in resource-constrained smart cards.

[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0005] To provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended as a general commentary, nor is it intended to identify key / important components or describe the scope of protection of these embodiments, but rather as a prelude to the detailed description that follows.

[0006] This disclosure provides a command processing method, a smart card, and an electronic device. Without relying on a multitasking operating system and without needing to allocate independent stack space for the execution of each priority command, it achieves rapid preemption and execution of high-priority commands, while also ensuring efficient utilization of RAM resources and reducing the smart card's RAM resource requirements.

[0007] According to a first aspect of this disclosure, a command processing method is provided, applied to a smart card having multiple communication interfaces, the command processing method comprising: When a high-priority command arrives at any communication interface, receive the high-priority command, stop executing low-priority commands, and back up the current environment data. Execute higher-priority commands on top of the stack space occupied by lower-priority commands in RAM; After the high-priority command is executed, restore the environment data backed up when the low-priority command was stopped, and continue executing the low-priority command.

[0008] In some embodiments, the environment data includes the value of the stack pointer register; continuing to execute a high-priority command on the stack space of RAM occupied by a low-priority command includes: using the stack top address corresponding to the current value of the stack pointer register, and continuing to execute the high-priority command on the stack space of RAM occupied by the low-priority command.

[0009] In some embodiments, the RAM of the smart card includes a global variable area, a security redundancy area, and a shared stack area; using the stack top address corresponding to the current stack pointer register value, high-priority commands are executed on the basis of the stack space occupied by low-priority commands, including: using the stack top address corresponding to the current stack pointer register value, high-priority commands are executed on the basis of the shared stack area in the RAM occupied by low-priority commands.

[0010] In some embodiments, when a high-priority command arrives at any communication interface, receiving the high-priority command, stopping the execution of low-priority commands, and backing up the current environment data includes: when a high-priority command arrives at any communication interface, entering the high-priority command interrupt service routine to implement the following process: receiving the high-priority command, stopping the execution of low-priority commands, backing up the current environment data, and modifying the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic; Executing high-priority commands on the stack space of RAM occupied by low-priority commands includes: when exiting the high-priority command interrupt service routine, jumping to the entry function of the high-priority command processing logic, and continuing to execute high-priority commands on the stack space of RAM occupied by low-priority commands.

[0011] In some embodiments, receiving a high-priority command, stopping the execution of low-priority commands, backing up the current environment data, and modifying the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic include: Receive high-priority commands and determine whether a low-priority command received from another communication interface is currently being executed; If a low-priority command is being executed, stop executing the low-priority command, back up the current environment data, and modify the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic. If a low-priority command is not executed, the return address of the high-priority command interrupt service routine is modified to the entry function of the high-priority command processing logic.

[0012] In some embodiments, stopping the execution of low-priority commands and backing up the current environment data includes: stopping the execution of low-priority commands and setting a preemption flag, and backing up the current environment data; After a high-priority command is executed, restore the environment data backed up when the low-priority command was stopped, and continue executing the low-priority command. This includes: after the high-priority command is executed, checking the preemption flag; when the preemption flag is detected, restoring the environment data backed up when the low-priority command was stopped, and jumping to the position corresponding to the preemption flag to continue executing the low-priority command.

[0013] In some embodiments, the environmental data also includes the values ​​of the data registers and the program counter.

[0014] According to a second aspect of this disclosure, a smart card is provided, including a processor and a plurality of communication interfaces, the processor being connected to each communication interface, and the processor being configured to execute the command processing method provided in the first aspect of this disclosure.

[0015] In some embodiments, the communication interface includes a 7816 interface, an SPI interface, and an SWP interface.

[0016] According to a third aspect of this disclosure, an electronic device is provided, including a smart card provided in the second aspect of this disclosure.

[0017] The command processing method, smart card, and electronic device provided in this disclosure can achieve the following technical effects: upon receiving a high-priority command with high timeliness requirements, the execution of the current low-priority command is immediately stopped, and the high-priority command is processed instead, thereby ensuring timely response to high-priority tasks. Furthermore, the above-mentioned preemptive execution method does not introduce a multi-tasking mechanism; instead, it directly continues the execution of high-priority commands on the stack space already occupied by low-priority commands, avoiding the need to allocate independent stack space for the execution of each priority command, significantly reducing the smart card's consumption of RAM resources and software complexity. The above method achieves rapid preemption and execution of high-priority commands without relying on a multi-tasking operating system and without needing to allocate independent stack space for the execution of each priority command, while also ensuring efficient utilization of RAM resources and reducing the smart card's RAM resource requirements.

[0018] The above general description and the description below are exemplary and illustrative only and are not intended to limit this disclosure. Attached Figure Description

[0019] One or more embodiments are illustrated by way of example with reference to the accompanying drawings. These illustrations and drawings do not constitute a limitation on the embodiments. Elements having the same reference numerals in the drawings are shown as similar elements. The drawings are not to be scaled. And wherein: Figure 1 This is a schematic diagram of the stack space of existing RAM; Figure 2 This is a schematic diagram of a smart card provided in an embodiment of this disclosure; Figure 3 This is a schematic diagram of an electronic device provided in an embodiment of this disclosure; Figure 4 This is a flowchart illustrating a command processing method provided in an embodiment of this disclosure; Figure 5 This is a flowchart illustrating another command processing method provided in an embodiment of this disclosure; Figure 6 This is a schematic diagram of the RAM stack space provided in an embodiment of this disclosure; Figure 7 This is a flowchart illustrating another command processing method provided in an embodiment of this disclosure; Figure 8 This is an architecture diagram of a smart card software system provided in an embodiment of this disclosure. Detailed Implementation

[0020] To provide a more detailed understanding of the features and technical content of the embodiments of this disclosure, the implementation of the embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. The accompanying drawings are for illustrative purposes only and are not intended to limit the embodiments of this disclosure. In the following technical description, for ease of explanation, several details are used to provide a full understanding of the disclosed embodiments. However, one or more embodiments may still be implemented without these details. In other cases, well-known structures and devices may be simplified in their depiction to simplify the drawings.

[0021] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this disclosure described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion.

[0022] Unless otherwise stated, the term "multiple" means two or more.

[0023] In this embodiment of the disclosure, the character " / " indicates that the objects before and after it are in an "or" relationship. For example, A / B means: A or B.

[0024] The term "and / or" describes an association between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or A and B.

[0025] The term "correspondence" can refer to an association or binding relationship. The correspondence between A and B means that there is an association or binding relationship between A and B.

[0026] In existing technologies, in order to ensure that high-priority commands with high timeliness requirements can be executed in a timely manner, the system usually allows it to preempt the processor resources occupied by running low-priority commands when it receives them: that is, to suspend the execution of low-priority commands and process high-priority commands first.

[0027] However, this preemption mechanism often requires configuring separate stack spaces for commands of different priorities within limited RAM. For example... Figure 1 As shown, the system needs to partition both a low-priority command stack area and a high-priority command stack area in RAM. This significantly increases the demand for RAM resources. Furthermore, to prevent stack overflow from causing system anomalies, an additional safety redundancy area needs to be allocated for each stack area, which further exacerbates the RAM resource consumption problem.

[0028] For resource-constrained devices such as smart cards (e.g., SIM cards or Secure Elements, SEs), the above solutions present significant challenges: configuring a large amount of RAM to meet multi-stack requirements will significantly increase hardware costs; while using a small amount of RAM may lead to system malfunction due to excessive stack space occupation. Therefore, in resource-constrained smart card environments, existing technologies struggle to ensure timely responses to high-priority commands while achieving efficient utilization of system resources.

[0029] like Figure 2As shown, this disclosure provides a smart card, which can be a SIM card or a Secure Element (SE). The smart card includes a processor and multiple communication interfaces, such as communication interface a, communication interface b, and communication interface c. The processor is connected to each communication interface to coordinate and control data interaction under different communication protocols. Here, the communication interfaces may include a 7816 interface (ISO / IEC 7816 standard interface), an SPI interface (Serial Peripheral Interface), and an SWP interface (Single Wire Protocol Interface), etc. The smart card also includes RAM (Random Access Memory), which is directly connected to the processor and used for temporary storage of program code, intermediate data, and cached information during operation.

[0030] In this embodiment of the disclosure, the smart card can receive commands through a communication interface and can pre-set corresponding priority levels for various commands, thereby classifying the received commands into high-priority commands and low-priority commands. High-priority commands typically involve security authentication, real-time transactions, access control, and other commands with high timeliness requirements; while low-priority commands may cover data queries, log readings, or non-critical configuration updates, which have relatively less stringent timeliness requirements.

[0031] like Figure 3 As shown in the embodiments of this disclosure, an electronic device is provided, which includes the smart card provided in the above embodiments. The electronic device can be widely used in various forms, including but not limited to smartphones, smartwatches, tablets, and vehicle terminals.

[0032] In conjunction with the smart card provided in this disclosure embodiment, this disclosure embodiment provides a command processing method, wherein the execution subject of the command processing method is the processor in the smart card, such as... Figure 4 As shown, the command processing methods include: S401: When a high-priority command arrives at any communication interface, the processor receives the high-priority command, stops executing low-priority commands, and backs up the current environmental data.

[0033] S402: The processor continues to execute high-priority commands on the stack space of RAM occupied by low-priority commands.

[0034] S403: After the high-priority command is executed, the processor restores the environment data backed up when the low-priority command was stopped, and continues to execute the low-priority command.

[0035] The command processing method provided in this disclosure immediately stops the execution of the current low-priority command and switches to processing the high-priority command when a high-priority command with high timeliness requirements is received, thereby ensuring timely response to high-priority tasks. Furthermore, the preemptive execution method described above does not introduce a multi-tasking mechanism; instead, it directly continues the execution of high-priority commands on the stack space already occupied by low-priority commands. This avoids the need to allocate independent stack space for the execution of each priority command, significantly reducing the smart card's consumption of RAM resources and software complexity. The above method achieves rapid preemption and execution of high-priority commands without relying on a multi-tasking operating system and without needing to allocate independent stack space for the execution of each priority command, while also ensuring efficient utilization of RAM resources and reducing the smart card's RAM requirements.

[0036] In some embodiments, the environment data includes the value of the stack pointer register, and also includes the values ​​of the data register and the program counter. Executing a higher-priority command on top of the stack space occupied by a lower-priority command includes: using the stack top address corresponding to the current value of the stack pointer register, and executing the higher-priority command on top of the stack space occupied by the lower-priority command.

[0037] By backing up the value of the stack pointer register as environment data and using the stack top address pointed to by the current stack pointer when executing high-priority commands, the high-priority command is executed directly on the RAM stack space already occupied by the low-priority command, achieving efficient stack space reuse. This mechanism avoids the need to allocate an additional independent stack area for high-priority commands, significantly reducing RAM resource consumption. Simultaneously, since there is no need to switch environment data or maintain multiple task stacks, it simplifies the system software structure and reduces code overhead. Furthermore, after the high-priority command has finished executing, the execution environment of the low-priority command can be accurately restored based on the backed-up stack top address, ensuring the correctness of task switching and data consistency. This achieves preemptive-like efficient and reliable command processing in a single-task system.

[0038] Furthermore, when high-priority commands are executed consecutively within the RAM stack space occupied by low-priority commands, all temporary data, local variables, and return addresses pushed onto the stack frame of the low-priority command during its execution are located above the stack frame of the low-priority command. After the high-priority command completes its execution, simply restoring the stack pointer to its backup position automatically discards all stack content generated by the high-priority command. At this point, the original stack frame of the low-priority command remains intact, untouched and undamaged. Therefore, as long as the correct values ​​of the stack pointer register, data registers, and program counter are backed up, the execution environment of the low-priority command can be accurately and reliably restored. Moreover, executing low-priority and high-priority commands consecutively within the same stack space eliminates the need to maintain multiple stack pointers and prevents data interference between stacks; the recovery operation requires only one stack pointer rollback. This not only reduces software complexity but also decreases the risk of system crashes due to stack management errors.

[0039] like Figure 5 As shown in the embodiments of this disclosure, another command processing method is provided, which includes: S501: When a high-priority command arrives at any communication interface, the processor receives the high-priority command, stops executing low-priority commands, and backs up the current environmental data.

[0040] In S502, the processor uses the stack top address corresponding to the current stack pointer register value to continue executing high-priority commands on the stack space occupied by low-priority commands in the RAM.

[0041] S503: After the processor completes the execution of a high-priority command, it restores the environment data backed up when it stopped executing low-priority commands and continues to execute low-priority commands.

[0042] In some embodiments, such as Figure 6 As shown, the RAM of a smart card includes a global variable area, a security redundancy area, and a shared stack area. Using the stack top address corresponding to the current stack pointer register value, high-priority commands are executed sequentially within the stack space occupied by low-priority commands. This includes: using the stack top address corresponding to the current stack pointer register value, and executing high-priority commands sequentially within the shared stack area of ​​the RAM occupied by low-priority commands.

[0043] In this embodiment, all instruction execution tasks use the same shared stack area, eliminating the need to allocate independent stack space for each command and significantly saving RAM resources. Since high-priority and low-priority commands share the same shared stack area and stack pointers are managed contiguously, task interruption and recovery can be achieved simply by backing up and restoring the stack pointer and critical registers, without requiring complex multi-task scheduling logic. This design achieves timely response to high-priority commands and reliable recovery of low-priority tasks with minimal RAM resource overhead, without introducing a multi-task operating system, thus balancing real-time performance, security, and resource efficiency.

[0044] In some embodiments, when a high-priority command arrives at any communication interface, receiving the high-priority command, stopping the execution of low-priority commands, and backing up the current environment data includes: when a high-priority command arrives at any communication interface, entering the high-priority command interrupt service routine to implement the following process: receiving the high-priority command, stopping the execution of low-priority commands, backing up the current environment data, and modifying the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic.

[0045] In some embodiments, executing high-priority commands on the stack space of RAM occupied by low-priority commands includes: when exiting the high-priority command interrupt service routine, jumping to the entry function of the high-priority command processing logic, and executing high-priority commands on the stack space of RAM occupied by low-priority commands.

[0046] In this embodiment, the reception of high-priority commands, the pausing of low-priority tasks, the backup of environmental data, and the redirection of return addresses are only performed within the interrupt service routine, instead of directly executing the complete high-priority command processing logic within the interrupt service routine. The actual processing of high-priority commands is completed in the normal task context by jumping to their dedicated entry function after exiting the interrupt, thereby significantly shortening the execution time of the interrupt service routine. Because the interrupt service routine is actively and quickly exited, even on processors that do not support interrupt nesting, subsequent interrupts can be properly responded to, improving the real-time performance of the system. The above design avoids the stack management and timing control problems caused by executing complex business logic in the interrupt context, and also eliminates the need to design a multi-level interrupt nesting scheduling mechanism, thus greatly simplifying the software architecture and improving code maintainability and reliability.

[0047] like Figure 7 As shown in the embodiments of this disclosure, another command processing method is provided, which includes: S701: When a high-priority command arrives at any communication interface, the processor enters the high-priority command interrupt service routine.

[0048] The high-priority command interrupt service routine can perform the following process: receive high-priority commands, stop executing low-priority commands, back up the current environment data, and modify the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic.

[0049] In S702, when the processor exits the high-priority command interrupt service routine, it jumps to the entry function of the high-priority command processing logic and continues to execute the high-priority command on the stack space of the RAM occupied by the low-priority command.

[0050] S703: After a high-priority command is executed, the processor restores the environment data backed up when it stopped executing low-priority commands, and then continues to execute low-priority commands.

[0051] In some embodiments, receiving a high-priority command, stopping the execution of a low-priority command, backing up the current environment data, and modifying the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic includes: receiving a high-priority command and determining whether a low-priority command received from another communication interface is currently being executed; if a low-priority command is being executed, stopping the execution of the low-priority command, backing up the current environment data, and modifying the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic; if a low-priority command is not being executed, modifying the return address of the high-priority command interrupt service routine to the entry function of the high-priority command processing logic.

[0052] In this embodiment, regardless of whether the system is currently idle or executing a low-priority command, the interrupt return address is modified to the entry function of the high-priority command processing logic. This avoids the code complexity caused by branch processing, making the interrupt response mechanism simpler and more reliable. When a low-priority task exists, its execution can be correctly paused and the environment backed up; when no low-priority task is running, it can directly jump to the high-priority processing logic, ensuring that high-priority commands can be scheduled immediately and consistently in any system state, improving response determinism.

[0053] In some embodiments, stopping the execution of low-priority commands and backing up the current environment data includes: stopping the execution of low-priority commands and setting a preemption flag, and backing up the current environment data. After the high-priority commands are executed, restoring the environment data backed up when the low-priority commands were stopped, and continuing to execute the low-priority commands includes: after the high-priority commands are executed, checking the preemption flag; when the preemption flag is detected, restoring the environment data backed up when the low-priority commands were stopped, and jumping to the position corresponding to the preemption flag to continue executing the low-priority commands.

[0054] This embodiment of the disclosure, by setting and checking preemption flags, allows the system to definitively determine whether a low-priority command was interrupted before execution, once a high-priority command has been completed. Environmental data recovery is only performed when preemption occurs, avoiding unnecessary jumps or erroneous recovery and improving the accuracy of execution logic.

[0055] The following example illustrates a specific implementation scheme where a high-priority command preempts a low-priority command during the execution of a low-priority command, taking into account that the command received through the SPI interface is a low-priority command and the command received through the 7816 interface is a high-priority command.

[0056] like Figure 8 As shown, the software system of a smart card can be divided into the following parts: 7816 Interface Interrupt Service Routine: Equivalent to the high-priority command interrupt service routine mentioned earlier, when the 7816 interface receives a command, it triggers the processor to enter this interrupt service routine. It is responsible for receiving commands from the 7816 interface and also for determining whether there are commands received through the SPI interface being processed. If so, it modifies the processor's interrupt return address so that when the interrupt service routine exits, it jumps to the entry point of the 7816 interface command processing module to execute.

[0057] SPI interface interrupt service routine: When the SPI interface receives data, it will trigger the processor to enter this interrupt service routine, which is responsible for receiving SPI interface commands.

[0058] Command distribution module: This module waits for the communication interface to receive commands. After the communication interface receives the command, it determines which communication interface received the command, calls the command processing module of the corresponding interface to process the command, and is responsible for sending the response data returned by the command processing module out through the corresponding communication interface after processing.

[0059] 7816 Interface Command Processing Module: This module is used to process various commands sent from the 7816 interface, such as authentication commands, file selection, read / write commands, etc.

[0060] SPI interface command processing module: This module is used to process various commands sent from the SPI interface, such as data encryption commands and certificate verification commands.

[0061] In this embodiment, commands received via the SPI interface are defined as SPI interface commands, and commands received via the 7816 interface are defined as 7816 interface commands. Taking the SPI interface command as a low-priority command and the 7816 interface command as a high-priority command as an example, the specific implementation scheme for the high-priority command to preempt the low-priority command during the execution of the low-priority command is as follows: After the smart card is powered on, it enters the command distribution module from the main function and waits for the interface command to arrive.

[0062] When an SPI interface command arrives, the SPI interface interrupt service routine is entered to receive the SPI interface command. Then, a signal is sent to notify the command distribution module that the SPI interface command has been received. The command distribution module then calls the entry function of the SPI interface command processing module to begin processing the SPI interface command.

[0063] While the SPI interface command processing module is processing an SPI interface command, a 7816 interface command arrives. The processor enters the 7816 interface interrupt service routine and performs the following steps: It receives the 7816 interface command, then checks if an SPI interface command is currently being processed, sets a preemption flag, backs up the environment data at the time the SPI interface command processing module was interrupted, and then modifies the return address of the interrupt service routine to the entry function of the 7816 interface command processing module.

[0064] The 7816 interface interrupt service routine exits and jumps to the entry function of the 7816 interface command processing module to start executing 7816 interface commands.

[0065] After executing the 7816 interface command, the 7816 interface command processing module checks the preemption flag. If the preemption flag is detected, it restores the environment data backed up when the SPI interface command execution was stopped, and jumps to the position corresponding to the preemption flag to continue executing the SPI interface command.

[0066] When a preemption marker is detected, restore the environment data backed up when the low-priority command was stopped, and jump to the position corresponding to the preemption marker to continue executing the low-priority command.

[0067] After the SPI interface command processing module finishes executing the SPI interface command, it returns to the command distribution module and starts waiting for interface commands again.

[0068] The technical solutions of this disclosure can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes one or more commands to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in this disclosure. The aforementioned storage medium can be a non-transitory storage medium, such as a USB flash drive, external hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, etc., and other media capable of storing program code.

[0069] The foregoing description and accompanying drawings fully illustrate embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Individual components and functions are optional unless explicitly required, and the order of operation may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. Moreover, the terminology used in this application is for describing embodiments only and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used in this application means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated features, integrals, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprises a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes said element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.

[0070] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this disclosure. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0071] The methods and products (including but not limited to devices and equipment) disclosed in the embodiments herein can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of units may be merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interfaces. The indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to implement this embodiment according to actual needs. In addition, the functional units in the embodiments of this disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0072] The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than that shown in the figures. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the figures, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in a block diagram and / or flowchart, and combinations of blocks in a block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer commands.

Claims

1. A command processing method characterized by comprising: The application is applied to a smart card with multiple communication interfaces, and the command processing method comprises the following steps: When a high-priority command comes to any communication interface, the high-priority command is received, the execution of a low-priority command is stopped, and current environment data is backed up; The high-priority command is executed on the basis of the stack space of the RAM occupied by the low-priority command; After the execution of the high-priority command is completed, the environment data backed up when the execution of the low-priority command is stopped is restored, and the execution of the low-priority command is continued.

2. The command processing method of claim 1, wherein, The environment data comprises the value of a stack pointer register; The high-priority command is executed on the basis of the stack space of the RAM occupied by the low-priority command, which comprises the following steps:

3. The command processing method according to claim 2, wherein The RAM of the smart card comprises a global variable area, a security redundancy area and a common stack area; The high-priority command is executed on the basis of the stack space of the RAM occupied by the low-priority command, which comprises the following steps:

4. The command processing method of claim 1, wherein When a high-priority command comes to any communication interface, the high-priority command is received, the execution of a low-priority command is stopped, and current environment data is backed up, which comprises the following steps: When a high-priority command comes to any communication interface, a high-priority command interrupt service program is entered to realize the following processes: the high-priority command is received, the execution of a low-priority command is stopped, current environment data is backed up, and the return address of the high-priority command interrupt service program is modified to an entry function of a high-priority command processing logic; 5. The command processing method according to claim 4, wherein The high-priority command is executed on the basis of the stack space of the RAM occupied by the low-priority command, which comprises the following steps: The high-priority command is received, the execution of a low-priority command is stopped, current environment data is backed up, and the return address of the high-priority command interrupt service program is modified to an entry function of a high-priority command processing logic, which comprises the following steps: The high-priority command is received, and it is judged whether a low-priority command received by another communication interface is being executed currently; If the low-priority command is being executed, the execution of the low-priority command is stopped, current environment data is backed up, and the return address of the high-priority command interrupt service program is modified to an entry function of a high-priority command processing logic; 6. The command processing method of claim 1, wherein If the low-priority command is not being executed, the return address of the high-priority command interrupt service program is modified to an entry function of a high-priority command processing logic. The execution of the low-priority command is stopped, an occupation flag is set, and current environment data is backed up, which comprises the following steps: After the high-priority command is executed, the environment data backed up when the low-priority command is stopped is restored, and the low-priority command is continued to be executed, including: after the high-priority command is executed, checking the preemption mark; when the preemption mark is checked, the environment data backed up when the low-priority command is stopped is restored, and the low-priority command is continued to be executed from the position corresponding to the preemption mark.

7. The command processing method of claim 1, wherein The environment data further includes a value of a data register and a value of a program counter.

8. A smart card, characterized by The system includes a processor and a plurality of communication interfaces, the processor being connected with each communication interface, and the processor being configured to execute the command processing method as claimed in any one of claims 1 to 7.

9. The smart card of claim 8, wherein, The communication interfaces include a 7816 interface, an SPI interface, and an SWP interface.

10. An electronic device, comprising: The system includes the smart card as claimed in claim 8 or 9. The system includes the smart card as claimed in claim 8 or 9.