Multi-task synchronization method for spaceborne computer of micro-nano satellite

Through the semaphore management task, the data competition, resource competition and deadlock problems caused by multi-task synchronization in micro-nano satellite mounted computers are solved, and more efficient and reliable system performance is achieved.

CN120123064APending Publication Date: 2025-06-10NANJING UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510250385.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-04
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

In micro-nano satellite-mounted computers, multi-task synchronization has problems such as data competition, resource competition and deadlock, which affects the stability and efficiency of the system.

Method used

Through semaphore management tasks, a unified processing of semaphore operations is designed, a communication mechanism between tasks and tasks is optimized, and multi-task synchronization of the on-site computer operating system is optimized.

Benefits of technology

Reduces task synchronization overhead, avoids deadlocks, improves the overall performance and reliability of the system, and enhances real-time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120123064A_ABST
    Figure CN120123064A_ABST
Patent Text Reader

Abstract

The invention discloses a micro-nano satellite on-board computer multi-task synchronization method, which comprises the following steps that an on-board program calls a semaphore interface function in a task space, and after the interface function sends an inter-task communication message to a semaphore management task, a corresponding task enters a blocked state; and after receiving the message, the semaphore management task calls a processing function corresponding to the type of the message, the called processing function executes a corresponding semaphore processing operation, generates a response message according to a processing result, returns the response message to a corresponding semaphore interface function, and awakens the previously blocked on-board task at the same time. According to the method, many problems caused by multi-task synchronization in a satellite-borne computer operating system can be effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of satellites, and particularly relates to a multi-task synchronization method for on-board computers of micro-nano satellites. Background Art

[0002] The on-board computer is an important core component of a satellite. When satellite tasks are controlled and executed by the on-board computer, there are not only parallel requirements among tasks, but also the need to be coordinated in terms of time and operations to ensure the correct implementation of the overall system function and the maximization of operation efficiency. With the diversification of the functions of micro-nano satellites, the tasks they execute are also increasing and becoming more complex. Multi-task synchronization is the core support for the stable operation of the satellite system. It can not only coordinate the dependency relationships and resource allocations among tasks, but also ensure time accuracy, data consistency, and rapid adaptation to dynamic changes. Through an efficient synchronization mechanism, each task module can operate in coordination like gears to achieve the stable, reliable, and efficient completion of complex on-board tasks. In response to the strong demand for multi-task scheduling, it is of great value and significance to carry out theoretical research and design on the task synchronization mechanism to improve the efficiency and real-time performance of task synchronization.

[0003] In a multi-task system, when the execution conditions of multiple tasks are all met, different tasks may need to access shared resources (such as memory, devices, or files). Without synchronization, tasks may cause the following problems when accessing resources simultaneously: a data competition problem where multiple tasks modify the same resource simultaneously, which may lead to data inconsistency or incorrect results; a resource competition problem where tasks compete for hardware devices (such as sensors or communication modules), which may cause the device state to be chaotic. Moreover, tasks may need to communicate through shared data structures (such as buffers). Without a synchronization mechanism, data may be damaged or incomplete information may be read during task switching. And in a real-time system, the completion time of tasks is often strictly limited. The synchronization mechanism can coordinate task priorities and execution orders to ensure that high-priority tasks are completed in a timely manner. Task synchronization can prevent the system from entering an unpredictable state and enhance the stability and fault tolerance of the system.

[0004] Referring to relevant materials, the semaphore is a synchronization mechanism widely used in operating systems, mainly used for resource management and task scheduling in multi-task systems. The main functions of the semaphore in task scheduling are reflected in aspects such as task synchronization, resource mutual exclusion, and event triggering, playing a key role in coordinating task execution, avoiding resource competition, and ensuring data consistency. Summary of the Invention

[0005] The present invention proposes a multi-task synchronization method for a micro-nano satellite on-board computer. By designing a semaphore management task and an inter-task communication mechanism, the multi-task synchronization of the on-board computer operating system is optimized, achieving the goals of reducing task synchronization overhead, avoiding deadlocks, and improving real-time performance, thereby effectively enhancing the overall performance and reliability of the system and effectively solving many problems brought about by multi-task synchronization in the on-board computer operating system.

[0006] The technical solution for implementing the present invention is as follows: A multi-task synchronization method for a micro-nano satellite on-board computer, the steps are as follows:

[0007] Step 1: The on-board task sends a message request to generate a semaphore. The called semaphore interface function is the interface function for requesting a semaphore; the message includes the value of the semaphore and the identification ID of the task requesting the semaphore; the processing function corresponding to this message type is the processing function for generating a semaphore; the called processing function parses the ID of the task requesting the semaphore and the value of the semaphore from the message, generates a semaphore for the on-board task requesting the semaphore, sets the semaphore identification ID, and assigns the corresponding value, generates a response message containing the semaphore ID and the ID of the task requesting the semaphore, and returns it to the interface function for requesting a semaphore, and then executes Step 2.

[0008] Step 2: The on-board task sends a message to attempt to acquire the semaphore. The called semaphore interface function is the interface function for attempting to acquire the semaphore; the message includes the semaphore identification ID; call the processing function for allocating the semaphore.

[0009] The called processing function parses the requested semaphore ID from the message, checks the value of the semaphore corresponding to this semaphore ID. If the value of this semaphore is greater than 0, then subtract 1 from its value, and generate a response message indicating successful semaphore allocation, and return it to the interface function for attempting to acquire the semaphore; if the value of this semaphore is less than or equal to 0, judge the priority of this task. If the priority of this on-board task is the maximum priority and it is a set emergency task, then select the task with the lowest priority among the tasks that have acquired the semaphore, execute Step 4 to release the semaphore. At this time, the value of the semaphore is greater than 0, and allocate the semaphore for the emergency task; if this task is not an emergency task, then generate a response message indicating failed semaphore allocation, and return it to the interface function for attempting to acquire the semaphore to attempt to acquire the semaphore, and then execute Step 3.

[0010] Step 3: The on-board task sends a message to wait for a semaphore, and the called interface function is the interface function for waiting for a semaphore; the message includes the semaphore ID, the timeout of the task, and the task ID; call the processing function for waiting for the semaphore; the called processing function parses the semaphore ID, the timeout of the task, and the task ID from the message; check the semaphore value corresponding to the semaphore ID; if the semaphore value is greater than 0, subtract 1 from it, and generate a response message including the semaphore ID and successful waiting, and return it to the interface function for waiting for the semaphore to wake up the task; if the semaphore value is less than or equal to 0, record the task ID and timeout for waiting for this semaphore; when a timer event occurs, determine whether the task times out according to the timeout, if it times out, generate a response message including failed waiting, and return it to the interface function for waiting for the semaphore, and execute Step 4.

[0011] Step 4: The on-board task sends a message to release the semaphore, and the called interface function is the interface function for releasing the semaphore; the message includes the semaphore ID; call the processing function for releasing the semaphore; the called processing function parses the semaphore ID from the message; add 1 to the semaphore value corresponding to the semaphore ID; if there are tasks waiting for this semaphore, subtract 1 from the semaphore value and wake up the user tasks waiting for this semaphore until all waiting tasks in the queue are processed or the semaphore value is 0; generate a response message including successful release of the semaphore and return it to the interface function for releasing the semaphore; if the release of the semaphore fails, generate a response message including failed release and return it to the interface function for releasing the semaphore, and execute Step 5.

[0012] Step 5: If there is no on-board task in the blocked queue requesting this semaphore, close the semaphore for sending the message, and the called interface function is the interface function for closing the semaphore; the message includes the semaphore ID; call the processing function for closing the semaphore; the called processing function parses the semaphore ID from the message; find and delete all tasks that are waiting for this semaphore; release the on-board resources occupied by this semaphore; if the resource release is successful, generate a response message including all task IDs waiting for this semaphore and successful closing of the semaphore, and return it to the interface function for closing the semaphore to wake up the deleted on-board tasks; if the resource release fails, generate a response message including failed closing of the semaphore and return it to the interface function for closing the semaphore.

[0013] Compared with the prior art, the significant advantages of the present invention are as follows:

[0014] (1) Traditional semaphore operations are usually managed by each task itself, which easily leads to problems such as task competition for resources and lock contention. The present invention reduces the synchronization overhead of the task itself and improves the overall scheduling efficiency of the system by allowing the semaphore management task to uniformly process semaphore operations.

[0015] (2) Since all semaphore operations are scheduled by the semaphore management task, it avoids the circular waiting and deadlock problems that may be caused by multiple tasks directly operating on the semaphore, enhancing the reliability of the system.

[0016] (3) After the semaphore interface function sends the inter-task communication message, the task immediately enters the blocked state and waits for the processing result of the semaphore management task. This design avoids the task from actively polling and waiting, reducing the waste of CPU resources, thereby improving the real-time performance of the system. Description of the Drawings

[0017] Figure 1 It is a schematic diagram of the semaphore of the present invention for realizing multi-task synchronization.

[0018] Figure 2 It is an example of the usage method of the semaphore of the present invention for realizing multi-task synchronization.

[0019] Figure 3 It is an example of the flowchart of the semaphore for managing multi-tasks of the present invention.

[0020] Figure 4 It is an example of the internal data structure diagram of the semaphore management task of the present invention.

[0021] Figure 5 It is an example of the priority setting diagram of the semaphore for managing multi-tasks of the present invention. Detailed Embodiment

[0022] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0023] Next, the specific implementation manner, as well as the technical difficulties and inventive points of the present invention, will be further introduced in conjunction with this design example.

[0024] Combined with Figure 1 and Figure 2 , a multi-task synchronization method for a micro-nano satellite on-board computer is as follows:

[0025] Step 1: The on-board task sends a message to generate a semaphore. The called semaphore interface function is used to generate the semaphore. The message contains the value of the semaphore and the task identification ID that requests the semaphore; the processing function corresponding to this message type is responsible for generating the semaphore. After the called processing function performs the corresponding semaphore processing operation, it constructs a response message according to the processing result and returns it to the interface function that requests the semaphore, including: parsing the task ID and semaphore value that request the semaphore from the message; creating a semaphore for the on-board task that requests the semaphore, setting the semaphore identification ID, and assigning a value to the semaphore; generating a response message containing the semaphore ID and the task ID that requests the semaphore, and returning it to the interface function that requests the semaphore.

[0026] Step 2: After Step 1 is completed, the on-board task sends a message to attempt to acquire the semaphore. The called semaphore interface function is used to attempt to acquire the semaphore. The message contains the semaphore identification ID, and its corresponding processing function is responsible for allocating the semaphore; after the called processing function performs the corresponding semaphore processing operation, it constructs a response message according to the processing result and returns it to the interface function that attempts to acquire the semaphore. The process includes: parsing the requested semaphore ID from the message; checking the value of the semaphore corresponding to the semaphore ID;

[0027] When the value of the semaphore corresponding to the semaphore ID is greater than 0, subtract 1 from the value of the semaphore, and generate a response message indicating that the semaphore is successfully allocated, and return it to the interface function used to attempt to acquire the semaphore;

[0028] When the value of the semaphore corresponding to the semaphore ID is less than or equal to 0, judge the priority of this task. If the priority of this on-board task is the highest priority and it is a set emergency task, then select the task with the lowest priority among the tasks that have acquired the semaphore, execute Step 4 to release the semaphore. At this time, the value of the semaphore is greater than 0, and allocate the semaphore for the emergency task. If this task is not an emergency task, generate a response message indicating that the semaphore allocation fails, and return it to the interface function that attempts to acquire the semaphore to attempt to acquire the semaphore

[0029] Step 3: After Step 2 is completed, the on-board task sends a message to wait for a semaphore, and the called interface function is an interface function for waiting for a semaphore; the message also includes the semaphore ID, the timeout value timeout corresponding to the task, and the ID of the on-board task; the processing function corresponding to the message type is a processing function for waiting for a semaphore; after the called processing function executes the corresponding semaphore processing function, it constructs a response message according to the processing result and returns it to the called semaphore interface function, including: parsing the semaphore ID, the timeout value timeout corresponding to the task, and the ID of the task from the message; checking the value of the semaphore corresponding to the semaphore ID; when the value of the semaphore is greater than 0, decrement the value of the semaphore by 1, generate a response message including the semaphore ID and successful waiting, and return it to the interface function for waiting for the semaphore to wake up the task; when the value of the semaphore is less than or equal to 0, record the ID and timeout of the task waiting for the semaphore; whenever a timer event occurs, judge whether the task times out according to the timeout; if it times out, generate a response message including failed waiting and return it to the interface function for waiting for the semaphore.

[0030] In Step 3, the judgment of whether the on-board task times out according to the timeout whenever a timer event occurs includes: whenever a timer event occurs, judge whether the on-board task times out through the count value tick corresponding to the on-board task; the initial value of tick corresponding to the on-board task is the timeout of the task; among them, when the timer is a fixed-time timer, subtract the first preset time from the value of tick whenever a timer event occurs to obtain the current value of tick; when the timer is a dynamic-time timer, subtract the second preset time from the value of tick whenever a timer event occurs to obtain the current value of tick; among them, the second preset time is determined according to the smallest non-zero timeout among the timeouts of the on-board tasks waiting for any semaphore; the first preset time and the second preset time are the time when the system sends a timer event message. For example, the first preset time can be 1 millisecond, and the second preset time can be 3 milliseconds.

[0031] Step 4: After the on-board task is completed, the on-board task needs to send a message to release the semaphore. The called interface function is the interface function for releasing the semaphore; the message also includes the semaphore ID; the processing function corresponding to the message type is the processing function for releasing the semaphore; after the called processing function executes the corresponding semaphore processing function, it constructs an acknowledgment message according to the processing result and returns it to the called semaphore interface function, including: parsing the semaphore ID from the message; incrementing the value of the semaphore corresponding to the semaphore ID by 1; when it is determined that there is a task waiting for the semaphore, decrementing the value of the semaphore by 1 and waking up the on-board task waiting for the semaphore until all on-board tasks waiting for the semaphore in the queue are checked or the value of the semaphore is 0; generating an acknowledgment message indicating successful semaphore release and returning it to the interface function for releasing the semaphore; when the semaphore release fails, generating an acknowledgment message indicating failed semaphore release and returning it to the interface function for releasing the semaphore.

[0032] Step 5: After releasing the semaphore, if there is no on-board task in the blocked queue requesting the semaphore, send a message to close the semaphore. The called interface function is the interface function for closing the semaphore; the message also includes the semaphore ID; the processing function corresponding to the message type is the processing function for closing the semaphore; after the called processing function executes the corresponding semaphore processing function, it constructs an acknowledgment message according to the processing result and returns it to the called semaphore interface function, including: parsing the semaphore ID from the message; finding and deleting all on-board tasks waiting for the semaphore; releasing the resources occupied by the semaphore; when the resource release is successful, generating an acknowledgment message including the IDs of all tasks waiting for the semaphore and indicating successful semaphore closure and returning it to the interface function for closing the semaphore to wake up the deleted tasks; when the resource release fails, generating an acknowledgment message indicating failed semaphore closure and returning it to the interface function for closing the semaphore.

[0033] To better implement the above steps and manage complex on-board tasks, the semaphore management task internally maintains a semaphore array Sem_Array. When the on-board task is in Step 1, select an idle position from the array and combine its index Sem_Index with a predefined MAGIC number to form a 4-byte value as the semaphore ID to return. The calculation method of the semaphore ID: Semaphore ID = MAGIC || Sem_Index, where MAGIC is the number 0x53450000, the value range of SemIdex is from the number 0 to 0xFFFF, and it is less than the number of elements in the semaphore Sem_Array.

[0034] The semaphores for managing on-board resources are saved through a semaphore array; wherein, the semaphore array includes multiple semaphore elements; each semaphore element corresponds to a semaphore respectively; the data structure of each semaphore element includes a semaphore ID, the value of the semaphore, and a waiting task linked list; wherein, the waiting task linked list includes information of N on-board tasks waiting for the semaphore corresponding to the semaphore element, and the data structure of the information of each on-board task includes the ID of the task, a timeout time timeout, and a clock count tick; the initial value of the tick is the timeout, where N is a natural number.

[0035] In step 3, whenever a timer event occurs, traverse the semaphore array and perform corresponding processing according to each traversed semaphore element respectively, including: when the ID of the semaphore is not 0, the timeout of the waiting task is not 0, and the tick of the waiting task has been reduced to less than or equal to 0, wake up the waiting on-board task and decrement the value of the semaphore by 1; wherein, a waiting task of a semaphore element refers to one or more on-board tasks waiting for the semaphore corresponding to the semaphore element; when the ID of the semaphore is not 0 and the timeout of the waiting task is 0, since this task is a never-timeout waiting task, no processing is performed; when the ID of the semaphore is not 0, the timeout of the waiting task is not 0, and the value of the tick of the waiting task minus a preset time is less than or equal to 0, perform timeout processing on the waiting task; when the ID of the semaphore is 0, this semaphore is an idle semaphore, and the waiting task must be empty, so no processing is performed; wherein, performing timeout processing includes deleting the timed-out waiting task from the waiting task linked list, filling the timeout result into the response message, and waking up the on-board task.

[0036] The priority of the semaphore management task in all the above steps is lower than that of the initial task and higher than that of any other task using semaphores in the space. For example, the priority of the signal management task is higher than that of other tasks calling the semaphore interface function, as Figure 5 shown. Generally, the priority of the semaphore management task should be set as high as possible.

[0037] The following details the specific application of the above semaphore function implementation method for multi-task synchronization in combination with the semaphore function implementation method running in the on-board space based on the micro-nano satellite operating system.

[0038] The method for using semaphores for on-board multi-task synchronization corresponds to Figure 3. The on - satellite task calls the semaphore interface function. Through the inter - task communication mechanism provided by the kernel, the semaphore interface function sends a message to the semaphore management task and then blocks waiting for the execution result. After receiving the message, the semaphore management task makes corresponding processing. After processing, it returns the result to the blocked task and wakes up the task, and then the task can continue to execute. There can be several tasks, and the semaphore interface functions can be called simultaneously, that is, these interface functions are re - entrant. The inter - task communication mechanism is provided by the kernel.

[0039] The semaphore management of on - satellite multi - task synchronization is responsible for tasks on the satellite, and is responsible for completing functions such as allocating semaphore resources, attempting to acquire semaphores, waiting for semaphores, releasing semaphores, and releasing semaphore resources.

[0040] The on - satellite program adds an interface function for the semaphore function in the original software interface module. This function runs in the on - satellite space and can be called by the application software that needs it. There are five functions in the software interface: the semaphore request interface function Sem_create, the semaphore attempt acquisition interface function Sem_try, the semaphore waiting interface function Sem_wait, the semaphore release interface function Sem_post, and the semaphore closing interface function Sem_free. The function definitions are as follows:

[0041] Sem_create(int initvalue, int maxvalue);

[0042] Function description:

[0043] Parameters: initvalue represents the initial value of the semaphore, and maxvalue is the maximum value of the semaphore;

[0044] Return value: It is the identification ID of the semaphore. If it fails, it returns 0;

[0045] Sem_try(int Sem);

[0046] Function description:

[0047] Parameter: sem represents the semaphore ID;

[0048] Return value: Returns 0 if successful and - 1 if failed;

[0049] Sem_wait(int Sem, unsigned int timeout);

[0050] Function description:

[0051] Parameters: Sem represents the semaphore ID, and timeout represents the waiting time. timeout being 0 means waiting indefinitely;

[0052] Return value: returns 0 on success, returns -1 for other failures except timeout failures, and returns -2 for timeout failures;

[0053] Sem_post(int Sem);

[0054] Function description:

[0055] Parameter: Sem represents the semaphore ID;

[0056] Return value: returns 0 on success, returns -1 on failure;

[0057] Sem_free(int Sem);

[0058] Function description:

[0059] Parameter: Sem represents the semaphore ID;

[0060] Return value: returns 0 on success, returns -1 on failure;

[0061] The sem_task task designed by this method is as Figure 3 shown in the flowchart of the semaphore management multitask. The Sem_task task is driven by timer event messages and semaphore interface messages.

[0062] Inside the Sem_task task, a semaphore array Sem_Array is maintained. When an application requests a semaphore, a position is obtained from the idle items in the array, and the index Sem_Index of this position and a MAGIC number are combined into a 4-byte value as the semaphore ID to be returned. The calculation method of the semaphore ID is as follows:

[0063] Semaphore ID = MAGIC || Sem_Index, MAGIC is the number 0x53450000, the value range of Sem_Idex is from the number 0 to 0xFFFF, and it is less than the number of elements in the semaphore Sem_Array array.

[0064] The definition of the element Sem_DataStruct of the semaphore array of the Sem_task task is:

[0065]

[0066]

[0067] SemID is the ID of this semaphore;

[0068] Value is the value of the semaphore, which decreases or increases as the semaphore is acquired or released, decreases by 1 when acquired once, and increases by 1 when released once;

[0069] Valuemax is the maximum value that the semaphore can reach. When the values of value and valuemax are the same, it cannot be increased any further;

[0070] WaitThreadList is the waiting task linked list. The information of the on-board tasks that are waiting for this semaphore is added to this linked list;

[0071] Inside the Sem_task semaphore task, for each semaphore, a semaphore waiting task linked list is maintained, which is used to add the tasks that need to wait until the time arrives to this waiting task. When the timer reaches the time, it will traverse the task linked list. When it checks that there is a task that has reached the time, it will wake up the task (that is, when the timeout value in the task data structure is not 0 and the tick value is less than or equal to 0, the timeout time is reached. At this time, the task is woken up and the timeout processing result is returned). The semaphore waiting linked list WaitThreadList is a doubly linked list composed of waiting task data structures. The definition of the waiting task data structure is as follows:

[0072]

[0073] threadID is the ID of the waiting task, which uniquely identifies the waiting task. The semaphore can wake up the waiting task through this value.

[0074] timeout is the timeout time set for the waiting task. When this value is 0, it means never timing out.

[0075] tick is a clock count maintained inside the semaphore management task, which is used to calculate whether the time has arrived. The initial value is equal to timeout, and a preset time is subtracted each time.

[0076] For the relationship between the Sem_Array array of semaphores, the semaphore data structure Sem_DataStruct, the waiting task linked list SemWaitThreadList, and the waiting task SemWaitThread inside the Sem_task semaphore management task, see Figure 4 The internal data structure diagram of the semaphore management task.

[0077] The Sem_task semaphore management task, according to this relationship diagram, when the timer expires, it will traverse the waiting task linked list of all semaphores. The traversal process is as follows: 1. When the timer expires, start traversing each item of the semaphore array Sem_Array from index 0; 2. If the SemID (semaphore ID) of this semaphore is not 0, then continue to check its value, otherwise skip this semaphore and go to step 1 to check the next item; 3. If the value of this semaphore is less than or equal to 0, then continue to check the waiting task linked list SemWaitThreadList, otherwise skip this semaphore and jump to step 1; 4. Traverse and check each item of the waiting task linked list SemWaitThreadList, calculate the checked tick value, if it times out, perform timeout processing; if there is no timeout, continue to the next item until the check is completed; 5. Until the last item of the semaphore array, otherwise jump to step 1.

[0078] There are two implementation methods for the timer of the Sem_task task, using a fixed-time timer and a dynamic-time timer respectively. The traversal processes of the two methods are the same, but the methods for calculating the tick value of the waiting tasks of the semaphore are different.

[0079] The first method is to use a fixed-time timer. Register a 1-second timer with the system, so that a timer expiration time will be received every 1 millisecond. Traverse the semaphore array and the waiting task linked list of the semaphore when the timer expires; when calculating the tick value, subtract 1 from the tick. If the tick is 0, the timeout time has arrived and timeout processing is performed. The second method is to use a dynamic-time timer. Calculate an internal timeout time. The calculation method is to check the task waiting queues of all semaphores, take the smallest non-zero timeout value as the timeout time to be used by the timer, and register this time with the system. Traverse the semaphore array and the waiting task linked list of the semaphore when the timer expires; when calculating the tick value, subtract the registered time from the tick. If the tick is less than or equal to 0, the timeout time has arrived and timeout processing is performed. After traversing the semaphore array and the waiting task linked list of the semaphore, recalculate the timeout time of the dynamic-time timer, and then update the registered timeout time with the system to the newly calculated value.

[0080] After the Sem_task task receives the semaphore interface message, it processes different messages. For the request semaphore message, it records the task ID of the requesting task (which uniquely identifies the task and can be used for task wake-up operations), allocates semaphore resources, assigns initial and maximum values, and returns an identification ID that can uniquely identify the semaphore to the caller; for the try-to-acquire semaphore message, it checks the value of the semaphore. If the value is greater than 0, it decrements it by one and returns it to the caller; if it is less than or equal to 0, it returns -1. For the wait-for-semaphore message, it checks the value of the semaphore. If the value is greater than 0, it decrements it by one and returns it to the caller; if it is less than or equal to 0, it adds the semaphore to the wait queue, and at the same time checks and calculates the waiting time of the semaphores in the queue and updates the time of the registered timer event, and then waits for the timer event to be processed. The caller stops executing due to blocking at this time and waits to be woken up. For the release-semaphore message, it increments the value of the semaphore by one, and then checks the semaphore wait queue. If there are on-board tasks waiting for this semaphore, it decrements the semaphore by one and wakes up the on-board tasks waiting for this semaphore until all items related to this semaphore in the queue are checked or the semaphore has been decremented to 0, and then returns the processing result to the caller. For the close-semaphore message, it checks the semaphore wait queue, returns -1 to all tasks that are waiting for this semaphore, then releases the resources occupied by this semaphore, and finally returns the processing result to the caller.

[0081] The timer event is implemented by the semaphore management on-board task through the timer interface of the registration system. For the fixed-time timer, a 1-second timer is registered with the system during the initialization of the semaphore management task; for the dynamic-time timer, after a new semaphore wait task is added to the semaphore wait queue, the time for the most recent time event response is recalculated and obtained, and then this time is updated to the interrupt response of the timer event. After the Sem_task task receives the timer event, it checks the semaphore wait queue in the semaphore management task, and wakes up the tasks waiting for this semaphore when it finds the expired semaphore.

[0082] The generation process of the timer event. Usually, the operating system provides the timer function, and the implementation of our semaphore function also requires the operating system to have this function. If the timer function provided by the operating system can send a message indicating that the time has expired to our task at a fixed time after our registration, the semaphore management task can perform corresponding processing after receiving this timer event message. If the operating system provides a callback function, a timer event message needs to be created in the callback function and sent to the semaphore management task, and the semaphore management task performs corresponding processing after receiving this timer event message.

[0083] Since the microsatellite operating system adopts a preemptive scheduling strategy based on priorities, it supports a total of 256 priorities, where 0 represents the highest priority and 255 represents the lowest priority. The priority of the sem_task task in the embodiments of the present disclosure must be lower than that of the initial task and must be higher than the priorities of any other tasks using semaphores in on-board space. If the priority of the Sem_task task is relatively lower than that of the user's task, it will be preempted by these on-board space tasks, resulting in the accuracy of semaphore response. Without affecting the system function, the priority of Sem_task should be set as high as possible. For the setting of the priority of Sem_task, refer to the priority setting diagram of the semaphore management multitask.

[0084] The above are only the preferred on-board implementation steps of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A multi-task synchronization method for a micro-nano satellite onboard computer, characterized in that: Here are the steps: Step 1: The onboard task sends a message to request the generation of a semaphore, and the called semaphore interface function is the interface function for requesting a semaphore; the message includes the value of the semaphore and the identification ID of the task requesting the semaphore; the processing function corresponding to the message type is the processing function for generating a semaphore; the called processing function parses the ID of the task requesting the semaphore and the value of the semaphore from the message, generates a semaphore for the onboard task requesting the semaphore, sets the semaphore identification ID, and assigns a corresponding value, generates a response message including the semaphore ID and the task ID requesting the semaphore, and returns it to the interface function for requesting the semaphore, and executes step 2; Step 2: The onboard task sends a message to try to obtain a semaphore. The semaphore interface function called is the interface function used to try to obtain a semaphore. The message contains a semaphore ID. The processing function for allocating a semaphore is called. The called processing function parses the requested semaphore ID from the message, checks the semaphore value corresponding to the semaphore ID, and if the semaphore value is greater than 0, reduces its value by 1, generates a response message indicating successful semaphore allocation, and returns it to the interface function that attempts to obtain the semaphore; if the semaphore value is less than or equal to 0, determines the priority of the task, and if the priority of the on-board task is the maximum priority and it is a set emergency task, selects the task with the lowest priority from the tasks that have obtained the semaphore, and executes step 4 to release the semaphore. At this time, the semaphore value is greater than 0, and the semaphore is allocated to the emergency task; If the task is not an urgent task, a response message indicating that the semaphore allocation failed is generated and returned to the interface function that attempts to obtain the semaphore to try to obtain the semaphore, and step 3 is executed; Step 3: The on-board task sends a message to wait for the semaphore, and the called interface function is the interface function for waiting for the semaphore; the message contains the semaphore ID, the task timeout and the task ID; the processing function for waiting for the semaphore is called; the called processing function parses the semaphore ID, the task timeout and the task ID from the message; the semaphore value corresponding to the semaphore ID is checked; if the semaphore value is greater than 0, its value is reduced by 1, and a response message containing the semaphore ID and the successful waiting is generated, and returned to the interface function waiting for the semaphore to wake up the task; if the semaphore value is less than or equal to 0, the task ID and the timeout of the waiting semaphore are recorded; when a timer event occurs, it is determined whether the task has timed out according to the timeout. If it has timed out, a response message containing the failed waiting is generated and returned to the interface function waiting for the semaphore, and step 4 is executed; Step 4: The onboard task sends a message to release the semaphore, and the called interface function is the interface function for releasing the semaphore; the message contains the semaphore ID; the processing function for releasing the semaphore is called; the called processing function parses the semaphore ID from the message; the semaphore value corresponding to the semaphore ID is increased by 1; if there is a task waiting for the semaphore, the semaphore value is reduced by 1, and the user task waiting for the semaphore is awakened until all waiting tasks in the queue are processed or the semaphore value is 0; a response message containing the successful release of the semaphore is generated and returned to the interface function for releasing the semaphore; if the release of the semaphore fails, a response message containing the release failure is generated and returned to the interface function for releasing the semaphore, and step 5 is executed; Step 5: If there is no on-board task requesting the semaphore in the blocking queue, a message is sent to close the semaphore, and the called interface function is the interface function for closing the semaphore; the message contains the semaphore ID; the processing function for closing the semaphore is called; the called processing function parses the semaphore ID from the message; finds and deletes all tasks waiting for the semaphore; releases the on-board resources occupied by the semaphore; if the resources are released successfully, a response message containing the IDs of all tasks waiting for the semaphore and the successful closing of the semaphore is generated and returned to the interface function for closing the semaphore to wake up the deleted on-board task; if the resource release fails, a response message containing the failure to close the semaphore is generated and returned to the interface function for closing the semaphore.

2. The micro-nano satellite onboard computer multi-task synchronization method according to claim 1, characterized in that: In the above steps, the semaphore is saved through a semaphore array; wherein the semaphore array includes multiple semaphore elements; each semaphore element corresponds to a semaphore; the data structure of each semaphore element includes a semaphore ID, a semaphore value and a waiting task list; wherein the waiting task list includes information of N tasks waiting for the semaphore corresponding to the semaphore element, and the data structure of each task information includes the task ID, timeout time and clock count tick; the initial value of tick is the timeout time, wherein N is a natural number.

3. The multi-task synchronization method of a micro-nano satellite onboard computer according to claim 2, characterized in that: In step 3, the semaphore array is traversed, and corresponding processing is performed according to each traversed semaphore element, including: when the ID of the semaphore is not 0, the timeout time of the waiting task is not 0, and the tick of the waiting task is less than or equal to 0, the waiting task is awakened and the value of the semaphore is reduced by 1; wherein, the waiting task of a semaphore element refers to one or more tasks waiting for the semaphore corresponding to the semaphore element; when the ID of the semaphore is not 0, the timeout time of the waiting task is not 0, and the value of the tick of the waiting task minus the preset time is less than or equal to 0, the waiting task is timed out; wherein, the timeout processing includes deleting the timed out waiting task from the waiting task linked list, filling the timeout result into the reply message, and waking up the on-board task.

4. The multi-task synchronization method of a micro-nano satellite onboard computer according to claim 1, characterized in that: In step 3, whenever a timer event occurs, the timeout period is used to determine whether the task has timed out, as follows: Each time a timer event is triggered, whether the task has timed out is determined based on the count value tick corresponding to the task, wherein the initial value of tick is set to the timeout time of the task; when the timer is a fixed-time timer, each time a timer event is triggered, the tick value is reduced by a first preset time to obtain the current tick value; when the timer is a dynamic-time timer, each time a timer event is triggered, the tick value is reduced by a second preset time to obtain the current tick value; wherein the second preset time is determined based on the smallest non-zero timeout time among the timeout values ​​of all tasks waiting for the semaphore; the first preset time and the second preset time are both time intervals for the system to trigger a timer event message.

5. The multi-task synchronization method of a micro-nano satellite onboard computer according to claim 1, characterized in that: The semaphore management task for a space has a lower priority than the initial task and a higher priority than any other tasks in the space that use semaphores.