WO2012031438A1 - 一种处理器程序调度方法及装置 - Google Patents

一种处理器程序调度方法及装置 Download PDF

Info

Publication number
WO2012031438A1
WO2012031438A1 PCT/CN2010/080074 CN2010080074W WO2012031438A1 WO 2012031438 A1 WO2012031438 A1 WO 2012031438A1 CN 2010080074 W CN2010080074 W CN 2010080074W WO 2012031438 A1 WO2012031438 A1 WO 2012031438A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
task
function
message queue
queue
Prior art date
Application number
PCT/CN2010/080074
Other languages
English (en)
French (fr)
Inventor
汪旭光
徐运
冷卫杰
吴明远
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2012031438A1 publication Critical patent/WO2012031438A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system

Definitions

  • the present invention relates to the field of software development, and in particular, to a program scheduling method and apparatus for developing low-end processor programs such as 8-bit and 16-bit. Background technique
  • High-end processors such as high-end microcontrollers
  • Low-end processors such as 8-bit, 16-bit and other low-end MCUs
  • the operating system is ported, the operating system consumes a lot of system resources, making the MCU inefficient or even inoperable.
  • the existing method is to set a main program in the MCU program, and set an infinite loop main function in the main program.
  • This main function implements all the functions of the MCU.
  • the drawback of this method is that an infinite loop main function completes all the functions of the microcontroller program, which makes the structure of the program worse, especially when the function of the microcontroller is large, and the program is large, there is almost no structure, and It can be difficult for a programmer to maintain or modify a microcontroller program.
  • the execution efficiency of this type of MCU is also very low, because the main function uses a top-down execution mechanism.
  • the disadvantage of this mechanism is that it cannot know the position of the sub-function that can achieve a specific function, only from the main function.
  • the first statement begins execution and does not execute the subfunction until the trigger to the desired subfunction, implementing a specific function. If the subfunction that implements a particular function is at the end of the main function, this can be a very time consuming task.
  • the main technical problem to be solved by the present invention is to provide a scheduling method and apparatus for a processor program, which can improve the structure of the processor program and has high execution efficiency.
  • the present invention provides a single chip program scheduling method, including: setting at least one task function for implementing a predetermined function in a processor program, and configuring a task ID for each task function;
  • each message in the message queue includes a task ID and a transfer data pointer
  • Extract the message in the message queue find the corresponding task function according to the task ID in the message, and pass the transfer data pointer in the message to the task function, and schedule the task to perform the operation.
  • the processor is a microcontroller.
  • the message further includes a message ID, and after searching for the corresponding task function according to the task ID in the message, the message ID and the transfer data pointer in the message are passed to the task function, and the task function is scheduled to perform the operation. .
  • the message queue includes an interrupt message queue and a task message queue, and the interrupt message queue has a higher priority than the task message queue, and the message in the extracted message queue includes:
  • the message queue is a circular queue.
  • the message in the message queue is extracted, the message in the message team is extracted on a first-in, first-out basis.
  • a task table for indexing a task function is provided, where the task table includes a corresponding task ID and a task function pointer, the task function pointer points to a corresponding task function, and the task ID and the task function are implemented by using the task table.
  • a processor program scheduling device comprising:
  • a task function module configured to set at least one task function for implementing a predetermined function in the processor program, and configure a task ID for each task function
  • a message queue module configured to set a message queue, each message in the message queue includes a task ID and a data pointer;
  • the sending module is configured to extract a message in the message queue, find a corresponding task function according to the task ID in the message, and pass the transfer data pointer in the message to the task function, and schedule the task function to perform the operation.
  • the processor is a microcontroller processor.
  • the message further includes a message ID, after the corresponding task function is searched according to the task ID in the message, the message ID and the transfer data pointer in the message are delivered to the task function, and the task is scheduled.
  • the function performs the operation.
  • the message queue includes an interrupt message queue and a task message queue, and the interrupt message queue has a higher priority than the task message queue, and the message in the extracted message queue specifically includes:
  • the processor includes at least one task function, which improves the structure of the program, makes the program more convenient for the programmer to maintain or modify, and the modification of the specific task function does not affect other task functions.
  • the message including the task ID and the transfer data pointer is used as a trigger mechanism for triggering the task function to improve the execution efficiency, that is, the task ID (task number) is used to find the corresponding task function, and the transfer data pointer is given to the task.
  • the function mode completes the running of the task function, which improves the execution efficiency of the single chip microcomputer.
  • the message includes a message number, and when the transfer data pointer is delivered to the task function, the message ID (message number) is delivered to the task function, and the operation of the task function is more accurately indexed by the message ID, further improving The efficiency of the program execution. Only the message ID, the task function ID, and the transfer data pointer occupy a certain space, and the composition of the message can be reasonably set according to the actual situation to achieve the best effect.
  • FIG. 1 is a flowchart of a method for scheduling a single chip program according to an embodiment of the present invention
  • FIG. 3 is a structural diagram of a message queue according to an embodiment of the present invention.
  • FIG. 5 is a flowchart of a scheduling task function according to an embodiment of the present invention.
  • FIG. 6 is a schematic structural diagram of a program scheduling device of a single chip microcomputer according to an embodiment of the present invention. detailed description
  • the processor includes a high-end processor and a low-end processor.
  • a high-end processor has a 64-bit single-chip microcomputer, and the middle and low-end ones have 8-bit, 16-bit, and the like.
  • the operating system is generally ported, and the running speed is relatively fast.
  • the low-end and mid-range processors are not suitable for porting the operating system due to limited system resources. Therefore, the scheduling method of the processor program is more effective for improving the running speed of the processor. It is important.
  • the following takes 8-bit, 16-bit microcontroller as an example to illustrate how the processor program scheduling method improves the execution efficiency of the program.
  • the present invention is suitable for low-end and mid-range processors that do not have an operating system, especially 8-bit, 16-bit, etc., if high-end processors, such as high-end microcontrollers, use the program of the present invention.
  • the scheduling method is also within the scope of the protection of the present invention.
  • the invention will be specifically described by taking an 8-bit, 16-bit, etc.
  • the invention firstly divides the single-chip computer program into a task function for realizing a predetermined function, thereby improving the structure of the single-chip computer program, increasing the convenience of the programmer or the user to modify the program; and then driving the task function to execute the predetermined task by using the message event. Function, which improves the execution efficiency of the program. In this process, each task shares the system stack, which helps to save system resources.
  • an embodiment of the present invention provides a method for scheduling a single-chip computer program, including: Step 11: Setting at least one task function in a single-chip microcomputer program, the task function is used to implement a predetermined function, and configured for each task function Task ID.
  • Step 12 Set up a message queue.
  • Each message in the message queue includes a task ID and a transfer data pointer.
  • Step 13 Extract the message in the message queue, find the corresponding task function according to the task ID, and pass the transfer data pointer to it, and schedule the task function to perform the operation.
  • step 11 the number of task functions in the single-chip microcomputer program is determined according to the actual situation, and the function of the task function is also determined in advance by the user or the programmer.
  • Each task function can implement only one function, and can also implement multiple functions.
  • Each task function is indexed by the corresponding task ID.
  • a task table dedicated to an index task function includes a task ID and a task function handle, a task ID and a task function handle - corresponding, and the task function handle corresponds to The function pointer of the task function, that is, the task function entry pointer.
  • the task ID and task function handles can be filled in by the user, and the form of the table in the code can be in the form of a two-dimensional array. Of course, it can also be flexibly set according to the actual situation.
  • each message in the message queue includes a task ID and a transfer data pointer.
  • the task ID corresponds to the task function handle, that is, the task function pointer, which is used to index the task function, and the transfer data pointer is used to transfer the parameter when the message is sent between tasks. If there is data to be delivered, the pointer of the data to be delivered may be filled into the item. If there is no data to pass, the transfer data pointer is empty.
  • the message queue is a circular queue, and the message queue may represent an interrupt message queue or a task message queue, and the shape and structure of the interrupt message queue and the task message queue are the same.
  • Each message in the message queue includes a message ID (ie, a message number) in addition to the task ID and the transmitted data pointer.
  • the message ID is defined by the user himself, and each ID indicates what is specified by the user according to the business needs. For example, during the operation of the MCU, the task function corresponding to the task is found according to the task ID in the message, and then the function is called and the message ID and the transfer data pointer are passed as function parameters to the task function, and the message ID is used to indicate the task function. What features are implemented. That is to say, the task function may have multiple functions, and the message ID prompts the task function to implement one or several functions, and several implementations are predefined by the user.
  • a large range (task function) is indexed with the task ID, and a small range (a function in the task function) is accurately determined by the message ID, so that the structure and operation of the program can be more effectively improved.
  • Efficiency especially in the case of more program functions, is more effective.
  • the message ID and the task ID generally occupy one byte, and the transfer data pointer occupies 1 byte in the 8-bit MCU, and occupies 2 words in the 16 MCU, but this is not the only way, the specific occupation word The number of sections can be reasonably determined according to the actual situation.
  • the message queue is a circular queue.
  • the icon setting message queue process can indicate the process of setting the interrupt message queue, or the process of setting the task message queue.
  • the process specifically includes:
  • IN is incremented by 1 and it is judged whether IN and SIZE after adding 1 are equal. That is, it is judged whether the end of the ring queue is reached after the message is stored, and if so, the IN is set to 0, and the head is returned to the head of the ring queue, indicating that the message needs to be stored from the head of the ring queue; if IN and SIZE are not equal , then return confirmation (OK), indicating that you can continue to store the message at the address pointed to by the IN plus one.
  • step 13 when extracting the message in the message queue, first determine whether the message queue has a message, if yes, extract the message, and perform a predetermined operation according to the message triggering task function, if not, call the execution HOOK function, that is, the hook function, the hook function A callback function that needs to be executed under certain conditions.
  • the execution hook function and the condition are that there is no message in the message queue, and the operation to be performed by the hook function is completely implemented by the user, and any operation can be performed, or a null operation can be performed.
  • the hook function is not suitable for too many operations, otherwise the system will be reduced in real time.
  • the null operation is directly performed (can also be implemented by using a hook function), so that Will have any impact on the system.
  • the message queue includes an interrupt message queue and a task message queue, and the interrupt message queue has a higher priority than the task message queue, that is, when the message is extracted, it is first determined whether the interrupt message queue has a message, and if so, the slave interrupt message If the message is in the queue, it is judged whether there is a message in the task message queue. If yes, the message is retrieved from the task message queue. If not, the HOOK function is called.
  • the message includes a message number, a task number, and a data pointer. Of course, the message number may not be included, depending on the actual situation.
  • the specific process of the process includes:
  • step 1 1) judging whether there is a message in the interrupt message queue, that is, determining the IN of the interrupt message queue (in this embodiment, the address where the IN is the interrupt message is stored, for convenience of description, represented by 1_1) is equal to OUT. (In the embodiment, when OUT is an interrupt message, the first address that needs to be fetched is convenient for description, represented by 0_1). If they are equal, go to step 2); if they are not equal, it means that there is an interrupt message queue.
  • the message is taken from the interrupt message queue, that is, the value of the record *0_1 (conveniently described in the present embodiment, represented by *0_1), that is, the message information of the record 0_1 pointing to the address (message ID, task ID, and transmission data) Pointer), you can save the message by stacking it, and then go to step 3);
  • step 2 judging whether there is a message in the task message queue, that is, determining the IN in the task message (in this embodiment, the IN in the task message, that is, the address in which the task message is stored, for convenience of description, represented by I_T) is equal to OUT (this In the embodiment, when the OUT is the task message, the first address that needs to be the message is convenient for description, and is represented by 0_T. If it is equal, the task message queue has no message, then the HOOK function is called and then jumps to step 7) . If they are not equal, indicating that there is a message in the task message queue, the message is retrieved from the task message queue, that is, the value of the task message *0_T is recorded, and then the process proceeds to step 4);
  • step 3 It is judged whether 0_1 in the interrupt message queue is equal to the interrupt message queue length SIZE (in the present embodiment, it is convenient to describe, and is represented by 8_1). If they are equal, it indicates that 0_1 has pointed to the end of the ring queue, and 0_1 is set to 0 and then proceeds to step 5) If not equal, go directly to step 5);
  • step 4 It is judged whether 0_T in the task message queue is equal to the task message queue length SIZE (in the present embodiment, it is convenient for description, and is represented by S_T). If they are equal, it indicates that 0_T has pointed to the end of the ring queue, and 0_ ⁇ is set to 0 and then proceeds to step 6) If not equal, go directly to step 6);
  • step 5 searching for the corresponding task function according to the task ID in the saved message, passing the message number and the transfer data pointer as function parameters to the task function, the task function performing the operation according to the message number and the transfer data pointer; then proceeding to step 7);
  • a single-chip program scheduling device includes:
  • the task function module 62 is configured to set at least one task function for implementing a predetermined function in the single-chip microcomputer program, and configure a task ID for each task function;
  • the message queue module 61 is configured to set a message queue, where each message in the message queue includes a task ID and a data pointer.
  • the sending module 63 is configured to extract a message in the message queue, find a corresponding task function according to the task ID in the message, and transmit the transfer data pointer in the message to the task function, and the scheduling task function executes the task according to the transmitted data pointer.
  • each message in the message queue module 61 includes a message ID, and after searching for a corresponding task function according to the task ID in the message, the message ID and the transfer data pointer in the message are delivered to the task. Function, dispatch task function to perform operations.
  • the message queue module 61 includes an interrupt message queue and a task message queue.
  • the interrupt message queue has a higher priority than the task message queue.
  • the message in the message queue includes: determining whether the interrupt message queue is There is a message, if any, the message is retrieved from the interrupt message queue; if not, it is judged whether there is a message in the task message queue, if yes, the message is retrieved from the task message queue, and if not, the hook function is called.
  • each task function implements one function or multiple functions or a series of related functions according to actual conditions. Since the program consists of task function modules, the structure of the program is increased, which is beneficial for the programmer or the user to modify the program for a specific part, for example, for a certain task function.
  • use the message including the message number, task number and transfer data pointer
  • the mechanism that triggers the task function increases the execution rate of the program. Because the task number in the message corresponds to the task function pointer in the task table, and the task function pointer points to the corresponding task function, the task ID can be quickly indexed to the required task function.
  • the message number and the transfer data pointer are passed to the task function in the form of function parameters.
  • the message number can quickly indicate the function of the task function.
  • the task function is a collection of multiple function functions, and of course the task function is not excluded. A situation in which a function is implemented.
  • the transfer data pointer points to the data that the system or other task needs to pass to the task function. According to the transfer data pointer, the task function can call the corresponding transfer data in the system memory to implement the predetermined function.
  • the data to be transmitted is stored in the system memory, and by transmitting the data pointer index, the tasks can share the data according to the transfer data pointer, thereby saving memory, which is especially important for low-end and medium-end single-chip microcomputers with limited system resources.
  • the method and device for triggering the single-chip program to execute the predetermined function by the message improve the execution efficiency of the program.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Executing Machine-Instructions (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种处理器程序调度方法及装置,方法包括:在处理器程序中设置至少一个用于实现预定功能的任务函数,并为每一个任务函数配置任务ID(任务号);设置消息队列,消息队列中的每一条消息包括一任务ID和传送数据指针;提取消息队列中的消息,根据消息中的任务ID查找对应的任务函数,并将消息中的传送数据指针传递给任务函数,调度任务函数执行操作。本发明的方法和装置提高了程序的结构性和程序的执行效率。

Description

一种处理器程序调度方法及装置 技术领域
本发明涉及软件开发领域, 尤其涉及 8位、 16位等中低端处理器程序 开发中的程序调度方法及装置。 背景技术
处理器, 一般有高端和低端之分。 高端处理器, 例如高端单片机, 高 端单片机的系统资源丰富, 一般移植有操作系统。 低端处理器, 例如 8位、 16位等中低端单片机, 中低端单片机的系统资源有限, 如果移植操作系统, 由于操作系统占用大量的系统资源, 使得单片机执行效率低下, 甚至不能 运行。
以中低端单片机为例, 现有的做法是, 在单片机程序中设置一个主程 序, 主程序中设置一个无限循环的 main函数, 此 main函数实现单片机的 所有功能。
釆取这种方式的缺陷是, 一个无限循环的 main函数完成单片机程序的 所有功能, 使得程序的结构性变差, 尤其当单片机的功能较多, 程序较大 时, 几乎没有什么结构性, 并且, 程序员想要维护或修改单片机程序时, 也会变得很困难。 同时, 这种方式的单片机执行效率也很低, 因为 main函 数釆用自上而下的执行机制, 这种机制的缺点在于, 无法获知能实现特定 功能的子函数的位置, 只能从 main函数的第一条语句开始执行, 直到触发 到期望的子函数, 才执行子函数, 实现特定的功能。 如果实现特定功能的 子函数在 main函数的尾部, 这将是一件十分耗时的工作。
因此, 现有技术中, 中低端单片机程序存在的缺陷是: 结构复杂, 执 行效率低。 发明内容
本发明要解决的主要技术问题是, 提供一种处理器程序的调度方法和 装置, 釆用该方法和装置能提高处理器程序的结构性, 并且执行效率高。
为解决上述技术问题, 本发明提供一种单片机程序调度方法, 包括: 在处理器程序中设置至少一个用于实现预定功能的任务函数, 并为每 一个任务函数配置任务 ID;
设置消息队列, 所述消息队列中的每一条消息包括一任务 ID和传送数 据指针;
提取消息队列中的消息, 根据消息中的任务 ID查找对应的任务函数, 并将消息中的传送数据指针传递给任务函数, 调度任务执行操作。
在本发明的一优选实施例中, 处理器为单片机。
在本发明的一优选实施例中, 消息还包括消息 ID, 在根据消息中的任 务 ID查找对应的任务函数后, 将消息中的消息 ID和传送数据指针传递给 任务函数, 调度任务函数执行操作。
在本发明的另一实施例中, 消息队列包括中断消息队列和任务消息队 列, 中断消息队列的优先级高于任务消息队列, 提取消息队列中的消息具 体包括:
判断中断消息队列是否有消息, 如有, 则从中断消息队列取消息; 如 否, 则判断任务消息队列是否有消息, 如有, 则从任务消息队列中取消息, 如否, 则调用钩子函数。
进一步地, 消息队列为环形队列, 提取消息队列中的消息时, 按先入 先出的原则提取消息队中的消息。
进一步地, 设置用于索引任务函数的任务表, 所述任务表包括——对 应的任务 ID和任务函数指针, 所述任务函数指针指向对应的任务函数, 通 过任务表实现任务 ID和任务函数的对应。 本发明还公开了一种处理器程序调度装置, 包括:
任务函数模块, 用于在处理器程序中设置至少一个用于实现预定功能 的任务函数, 并为每一个任务函数配置任务 ID;
消息队列模块, 用于设置消息队列, 消息队列中的每一条消息包括一 任务 ID和传送数据指针;
发送模块, 用于提取消息队列中的消息, 根据消息中的任务 ID查找对 应的任务函数, 并将消息中的传送数据指针传递给任务函数, 调度任务函 数执行操作。
在本发明的一种优选实施例中, 处理器为单片机处理器。
在本发明的一种优选实施例中, 消息还包括消息 ID, 在所述根据消息 中的任务 ID查找对应的任务函数后, 将消息中的消息 ID和传送数据指针 传递给任务函数, 调度任务函数执行操作。
在本发明的另一实施例中, 消息队列包括中断消息队列和任务消息队 列, 中断消息队列的优先级高于任务消息队列, 所述提取消息队列中的消 息具体包括:
判断所述中断消息队列是否有消息, 如有, 则从所述中断消息队列取 消息; 如否, 则判断所述任务消息队列是否有消息, 如有, 则从所述任务 消息队列中取消息, 如否, 则调用钩子函数。
本发明的有益效果是:
处理器包括至少一个任务函数, 提高了程序的结构性, 使得程序更利 于程序员维护或修改, 针对特定任务函数的修改不会影响其它的任务函数。 同时, 将包括任务 ID和传送数据指针在内的消息作为触发任务函数执行的 触发机制, 提高了执行效率, 即: 通过任务 ID (任务号)查找对应的任务 函数, 通过传递传送数据指针给任务函数的方式完成任务函数的运行, 提 高了单片机的执行效率。 一种优选的方式中, 消息包括消息号, 在向任务函数传递传送数据指 针时, 传递消息 ID (消息号 )给任务函数, 由消息 ID更精确的索引任务函 数将要执行的操作, 进一步的提高程序的执行效率。 只是消息 ID、 任务函 数 ID和传送数据指针都要占用一定的空间, 根据实际情况合理设置消息的 组成能达到最佳的效果。 附图说明
图 1为本发明一种实施例的单片机程序调度方法流程图;
图 2为本发明一种实施例的任务表图;
图 3为本发明一种实施例的消息队列结构图;
图 4为本发明一种实施例的设置消息队列流程图;
图 5为本发明一种实施例的调度任务函数流程图;
图 6为本发明一种实施例的单片机程序调度装置结构示意图。 具体实施方式
下面通过具体实施方式结合附图对本发明作进一步详细说明。
处理器包括高端处理器和中低端处理器, 以单片机为例, 高端的有, 64位单片机, 中低端的有 8位、 16位等单片机。 对于高端处理器来说, 一 般移植有操作系统, 运行速度比较快, 而中低端处理器由于系统资源有限, 不适合移植操作系统, 所以处理器程序的调度方法对于提高处理器运行速 度显得更为重要。 下面以 8位, 16位单片机为例, 说明本发明是处理器程 序调度方法是如何提高程序的执行效率。 可以理解的是, 虽然本发明比较 适合没有移植操作系统的中低端处理器, 尤其是 8位、 16位等中低端单片 机, 但如果高端处理器, 比如高端单片机釆用本发明构思的程序调度方法, 一样属于本发明保护的范围。 下面, 以 8位、 16位等中低端单片机为例, 具体说明本发明的发明构思: 本发明首先将单片机程序划分为一个个用于实现预定功能的任务函 数, 以此提高单片机程序的结构性, 增加了程序员或用户修改程序的方便 性; 然后以消息事件驱动任务函数执行预定的功能, 从而提高了程序的执 行效率。 在此过程中, 各个任务共享系统堆栈, 有利于节约系统资源。
实施例 1 :
如图 1所示, 本发明实施例提供了一种单片机程序调度方法, 包括: 步骤 11、 在单片机程序中设置至少一个任务函数, 任务函数用于实现 预定的功能, 并为每个任务函数配置任务 ID。
步骤 12、设置消息队列, 消息队列中每一条消息包括任务 ID和传送数 据指针。
步骤 13、 提取消息队列中的消息, 根据任务 ID查找对应的任务函数, 并向其传递传送数据指针, 调度任务函数执行操作。
步骤 11中, 单片机程序中任务函数的个数根据实际情况而定, 任务函 数的功能也由用户或程序员预先确定, 每个任务函数可以只实现一个功能, 也可以实现多个功能。 每个任务函数由与之对应的任务 ID索引。
如图 2所示, 在一种实施方式中, 配置有专门用于索引任务函数的任 务表, 该表包括任务 ID和任务函数句柄, 任务 ID和任务函数句柄——对 应, 任务函数句柄就是对应就任务函数的函数指针, 也就是任务函数入口 指针。 此表中, 任务 ID和任务函数句柄可以由用户填写, 该表在代码中的 表现形式可以是二维数组的形式。 当然, 也可以根据实际情况灵活设置。
步骤 12中, 消息队列中的每一条消息包括任务 ID和传送数据指针。 任务 ID对应任务函数句柄, 即任务函数指针, 用于索引任务函数, 传送数 据指针用于任务间发送消息时附带传递的参数, 如果有数据需要传递, 可 将待传递数据的指针填充到该项, 如果没有数据需要传递, 该传送数据指 针为空。 如图 3 所示, 在一种实施方式中, 消息队列为环形队列, 该消息队列 可以表示中断消息队列, 也可以表示任务消息队列, 中断消息队列和任务 消息队列的形状和结构相同。 该消息队列中的每一条消息除包括所述的任 务 ID和传送数据指针外, 还包括消息 ID (即消息号)。 该消息 ID为用户 自己定义, 每个 ID表示什么由用户根据业务需要指定。 比如, 单片机运行 过程中, 根据消息中的任务 ID找到该任务对应的任务函数, 然后调用该函 数并将消息 ID和传送数据指针作为函数参数传递给该任务函数, 消息 ID 用于指示任务函数具体实现什么功能。 也就是说, 任务函数可能具有多个 功能, 而消息 ID则提示任务函数实现其中的一个或几个功能, 具体实现几 个, 由用户预定义。 也就是, 程序执行过程中, 用任务 ID索引一个大范围 (任务函数), 用消息 ID精确索一个小范围 (任务函数中的某个功能), 从 而可以更有效的提高程序的结构性和运行效率, 尤其是在程序功能较多的 情况下, 更加有效。 实际情况中, 消息 ID和任务 ID—般占用一个字节, 传送数据指针在 8位单片机中占用 1位字节, 在 16单片机中占用 2个字, 但这并不是唯一的方式, 具体占用字节数可以根据实际情况合理确定。
图示中, SIZE表示该消息队列可以存放的消息个数, 比如, SIZE=11 表示, 该消息队列可以存放 11个消息, IN表示消息存入的地址, OUT表 示取消息时, 第一个需要取消息的地址。 当 OUT=IN时为初始状态, 此时 消息队列为空; 当 IN+l=OUT时, 消息队列满。 消息在此队列按照先入先 出的方式存放。
如图 4所示, 表示了一种实施方式中设置消息队列流程图, 该实施方 式中, 消息队列为环形队列。 图示设置消息队列流程即可以表示设置中断 消息队列流程, 也可以表示设置任务消息队列流程。 该流程具体包括:
1 )首先判断 IN加 1是否等于 OUT, 如果等于, 表示当前消息池已经 放满消息, 没有多余的空间存放新消息。 此时, 向发送消息程序返回队列 满; 如果不等于, 则进行下步;
2 )将消息数据(消息号、 任务号和传送数据指针)添加到 IN指向的 地址。
3 ) IN加 1 ,并判断加 1后的 IN与 SIZE是否相等。即判断存入消息后, 是否到了环形队列的尾部, 如果是, 则将 IN置为 0, 重新回到环形队列头 部, 表示需从环形队列头部开始存入消息; 如果 IN与 SIZE不相等, 则返 回确认( OK ), 表示可以继续在 IN加 1后所指向的地址处存放消息。
步骤 13中, 提取消息队列中消息时, 先判断消息队列是否有消息, 如 有, 则提取消息, 根据消息触发任务函数执行预定操作, 如否, 则调用执 行 HOOK函数, 即钩子函数,钩子函数为特定条件下需要执行的回调函数。 本发明中, 执行钩子函数和条件是消息队列中没有消息, 该钩子函数要执 行的操作完全由用户实现, 执行什么操作都可以, 也可以执行空操作。 但 钩子函数不宜做过多操作, 否则会导致系统实时性降低, 比如, 在一种实 施方式中, 判断消息队列中没有消息后, 直接执行空操作 (也可以用钩子 函数来实现), 这样不会对系统造成任何影响。
如图 5 所示, 表示了一种实施方式中调度任务函数流程图。 在本实施 方式中, 消息队列包括中断消息队列和任务消息队列, 中断消息队列的优 先级高于任务消息队列, 即提取消息时, 先判断中断消息队列是否有消息, 如有, 则从中断消息队列中取消息; 如否, 则判断任务消息队列中是否有 消息, 如有, 则从任务消息队列中取消息, 如否, 则调用 HOOK函数。 在 本实施方式中消息包括消息号、 任务号和传送数据指针, 当然, 也可以不 包括消息号, 具体依实际情况而定。
该流程具体过程包括:
1 )判断中断消息队列是否有消息, 即判断中断消息队列的 IN (本实施 例中 IN即中断消息存入的地址, 为描述方便, 用 1_1表示)是否等于 OUT (本实施例中 OUT即取中断消息时, 第一个需要取消息的地址, 为描述方 便, 用 0_1表示), 如果相等, 转到步骤 2 ); 如果不相等, 即表示中断消息 队列中有消息, 则从中断消息队列中取消息, 即记录 *0_1 (本实施例中为 描述方便, 用 *0_1表示) 的值, 也就是记录 0_1指向地址的消息信息 (消 息 ID、 任务 ID和传送数据指针), 可以釆取将消息入栈的方式保存, 然后 转到步骤 3 );
2 )判断任务消息队列中是否有消息, 即判断任务消息中的 IN (本实施 例中,任务消息中的 IN即任务消息存入的地址, 为描述方便,用 I_T表示) 是否等于 OUT (本实施例中 OUT即取任务消息时,第一个需要取消息的地 址,为描述方便,用 0_T表示),如果相等,表示任务消息队列也没有消息, 则调用执行 HOOK函数后跳至步骤 7 )。 如不相等, 表示任务消息队列中有 消息, 则从任务消息队列中取消息, 即记录任务消息 *0_T的值, 然后转至 步骤 4 );
3 )判断中断消息队列中 0_1是否等于中断消息队列长度 SIZE (本实 施例中为描述方便, 用 8_1表示), 如果相等, 表明 0_1已指向环形队列尾 部, 将 0_1置 0后转到步骤 5 ); 如果不相等, 直接转到步骤 5 );
4 )判断任务消息队列中 0_T是否等于任务消息队列长度 SIZE (本实 施例中为描述方便, 用 S_T表示), 如果相等, 表明 0_T已指向环形队列 尾部, 将 0_Τ置 0后转到步骤 6 ); 如果不相等, 直接转到步骤 6 );
5 )根据保存的消息中的任务 ID查找对应的任务函数, 将消息号和传 送数据指针作为函数参数传递给任务函数, 任务函数根据消息号和传送数 据指针执行操作; 然后转至步骤 7 );
6 )根据保存的消息中的任务 ID查找对应的任务函数, 将消息号和传 送数据指针作为函数参数传递给任务函数, 任务函数根据消息号和传送数 据指针执行操作; 然后转至步骤 7 ); 7 )返回开始。
实施例 2:
如图 6所示, 一种单片机程序调度装置, 包括:
任务函数模块 62, 用于在单片机程序中设置至少一个用于实现预定功 能的任务函数, 并为每一个任务函数配置任务 ID;
消息队列模块 61 , 用于设置消息队列, 所述消息队列中的每一条消息 包括一任务 ID和传送数据指针;
发送模块 63 ,用于提取消息队列中的消息,根据消息中的任务 ID查找 对应的任务函数, 并将消息中的传送数据指针传递给任务函数, 调度任务 函数根据传送的数据指针执行任务。
在本实施例的一种优先方式中, 消息队列模块 61中的每一个消息包括 消息 ID, 根据消息中的任务 ID查找对应的任务函数后, 将消息中的消息 ID和传送数据指针传递给任务函数, 调度任务函数执行操作。
在本实施例的另一实施方式中, 消息队列模块 61包括中断消息队列和 任务消息队列, 中断消息队列的优先级高于任务消息队列, 提取消息队列 中的消息具体包括: 判断中断消息队列是否有消息, 如有, 则从中断消息 队列取消息; 如否, 则判断任务消息队列是否有消息, 如有, 则从任务消 息队列中取消息, 如否, 则调用钩子函数。
还可以将消息队列设为环形队列, 消息按先入先出的原则排列在消息 队列中。
本发明实施例中的单片机程序调度方法及装置, 通过将程序划分为一 个或多个任务函数, 每个任务函数实现一个功能或是多个功能或是一系列 相关的功能根据实际情况而定。 由于程序由任务函数模块组成, 增加了程 序的结构性, 利于程序员或用户针对特定部分修改程序, 比如, 针对某一 任务函数。 同时, 釆用消息 (包括消息号、 任务号和传送数据指针)作为 触发任务函数的机制, 提高了程序的执行速率。 因为, 消息中的任务号在 任务表中与任务函数指针——对应, 而任务函数指针指向对应的任务函 数 , 从而通过任务 ID可以快速地索引到需要的任务函数。 然后将消息号 和传送数据指针以函数参数的形式传递给任务函数, 消息号可以快速指示 任务函数实现的功能, 通常情况下, 任务函数是多个功能函数的集合, 当 然也不排除任务函数只实现一个功能的情形。 传送数据指针指向系统或其 它任务需要传递给任务函数的数据, 根据传送数据指针, 任务函数可以调 用系统内存中对应的传送数据, 从而实现预定的功能。 同时, 待传送数据 存入系统内存中, 通过传送数据指针索引, 相当于, 各任务可以根据传送 数据指针共享传送数据, 从而节约了内存, 对于系统资源有限的中低端单 片机尤其重要。 通过消息触发单片机程序执行预定功能的方法及装置, 提 高了程序的执行效率。
以上内容是结合具体的实施方式对本发明所作的进一步详细说明, 不 能认定本发明的具体实施只局限于这些说明。 对于本发明所属技术领域的 普通技术人员来说, 在不脱离本发明构思的前提下, 还可以做出若干简单 推演或替换, 都应当视为属于本发明的保护范围。

Claims

权利要求书
1、 一种处理器程序调度方法, 包括:
在所述处理器程序中设置至少一个用于实现预定功能的任务函数, 并 为每一个任务函数配置任务 ID (任务号);
设置消息队列, 所述消息队列中的每一条消息包括一所述任务 ID和传 送数据指针;
提取消息队列中的消息, 根据消息中的任务 ID查找对应的任务函数, 并将消息中的传送数据指针传递给任务函数, 调度任务函数执行操作。
2、 如权利要求 1所述的处理器程序调度方法, 所述处理器为单片机处 理器。
3、 如权利要求 1或 2所述的处理器程序调度方法, 所述消息还包括消 息 ID (消息号 ), 在所述根据消息中的任务 ID查找对应的任务函数后, 将 消息中的消息 ID和传送数据指针传递给任务函数,调度任务函数执行操作。
4、 如权利要求 3所述的处理器程序调度方法, 所述消息队列包括中断 消息队列和任务消息队列, 中断消息队列的优先级高于任务消息队列, 所 述提取消息队列中的消息具体包括:
判断所述中断消息队列是否有消息, 如有, 则从所述中断消息队列取 消息; 如否, 则判断所述任务消息队列是否有消息, 如有, 则从所述任务 消息队列中取消息, 如否, 则调用钩子函数。
5、 如权利要求 4所述的处理器程序调度方法, 所述消息队列为环形队 列, 提取消息队列中的消息时, 按先入先出的原则提取所述消息队中的消 息。
6、 如权利要求 1或 2所述的处理器程序调度方法, 还包括: 设置用于 索引任务函数的任务表, 所述任务表包括——对应的任务 ID和任务函数指 针, 所述任务函数指针指向对应的任务函数, 通过任务表实现任务 ID和任 务函数的对应。
7、 一种处理器程序调度装置, 包括:
任务函数模块, 用于在所述单片机程序中设置至少一个用于实现预定 功能的任务函数, 并为每一个任务函数配置任务 ID;
消息队列模块, 用于设置消息队列, 所述消息队列中的每一条消息包 括一所述任务 ID和传送数据指针;
发送模块, 用于提取消息队列中的消息, 根据消息中的任务 ID查找对 应的任务函数, 并将消息中的传送数据指针传递给任务函数, 调度任务函 数执行操作。
8、 如权利要求 7所述的处理器程序调度装置, 所述处理器程序调度装 置为单片机程序调度装置。
9、 如权利要求 7或 8所述的处理器程序调度装置, 所述消息还包括消 息 ID,在所述根据消息中的任务 ID查找对应的任务函数后,将消息中的消 息 ID和传送数据指针传递给任务函数, 调度任务函数执行操作。
10、 如权利要求 9所述处理器程序调度装置, 所述消息队列包括中断 消息队列和任务消息队列, 中断消息队列的优先级高于任务消息队列, 所 述提取消息队列中的消息具体包括:
判断所述中断消息队列是否有消息, 如有, 则从所述中断消息队列取 消息; 如否, 则判断所述任务消息队列是否有消息, 如有, 则从所述任务 消息队列中取消息, 如否, 则调用钩子函数。
PCT/CN2010/080074 2010-09-10 2010-12-21 一种处理器程序调度方法及装置 WO2012031438A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201010278458.5A CN101950260B (zh) 2010-09-10 2010-09-10 一种处理器程序调度方法及装置
CN201010278458.5 2010-09-10

Publications (1)

Publication Number Publication Date
WO2012031438A1 true WO2012031438A1 (zh) 2012-03-15

Family

ID=43453764

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2010/080074 WO2012031438A1 (zh) 2010-09-10 2010-12-21 一种处理器程序调度方法及装置

Country Status (2)

Country Link
CN (1) CN101950260B (zh)
WO (1) WO2012031438A1 (zh)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102831344B (zh) * 2012-07-27 2015-04-15 北京奇虎科技有限公司 一种进程的处理方法和装置
CN103257864A (zh) * 2013-05-09 2013-08-21 南京航空航天大学 嵌入式软件任务调度方法
CN103488536B (zh) * 2013-09-29 2017-12-05 华为技术有限公司 任务调度方法、装置及操作系统
CN105930246A (zh) * 2016-04-08 2016-09-07 天翼阅读文化传播有限公司 一种可智能分发任务的高可用数据库监控方法
CN108089848B (zh) * 2017-12-19 2021-02-09 苏州浪潮智能科技有限公司 一种实现systemverilog中semaphore保序的控制方法与系统
CN108536527B (zh) * 2018-02-08 2020-10-30 山东省科学院自动化研究所 一种嵌入式软件的任务调度方法及装置
CN108446175A (zh) * 2018-03-12 2018-08-24 平安普惠企业管理有限公司 任务处理方法、装置、计算机设备和存储介质

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1731361A (zh) * 2005-08-26 2006-02-08 北京中星微电子有限公司 一种跨平台函数调用系统
CN1744046A (zh) * 2004-08-31 2006-03-08 华为技术有限公司 实时操作系统环境下多任务应用软件模块的管理方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100458702C (zh) * 2005-08-26 2009-02-04 北京中星微电子有限公司 一种不同运行平台间的函数调用的方法
CN101192192B (zh) * 2006-11-21 2010-08-18 华为技术有限公司 用于实时操作系统的任务异常诊断方法及系统
CN100530126C (zh) * 2007-11-26 2009-08-19 中兴通讯股份有限公司 一种记录导致系统异常的函数的方法
CN101576820A (zh) * 2009-06-11 2009-11-11 大连理工计算机控制工程有限公司 一种iec61131-3标准功能块软件实现方法

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1744046A (zh) * 2004-08-31 2006-03-08 华为技术有限公司 实时操作系统环境下多任务应用软件模块的管理方法
CN1731361A (zh) * 2005-08-26 2006-02-08 北京中星微电子有限公司 一种跨平台函数调用系统

Also Published As

Publication number Publication date
CN101950260B (zh) 2014-04-30
CN101950260A (zh) 2011-01-19

Similar Documents

Publication Publication Date Title
WO2012031438A1 (zh) 一种处理器程序调度方法及装置
US11836524B2 (en) Memory interface for a multi-threaded, self-scheduling reconfigurable computing fabric
US11868163B2 (en) Efficient loop execution for a multi-threaded, self-scheduling reconfigurable computing fabric
US20220188265A1 (en) Loop Thread Order Execution Control of a Multi-Threaded, Self-Scheduling Reconfigurable Computing Fabric
US20210255864A1 (en) Multiple Types of Thread Identifiers for a Multi-Threaded, Self-Scheduling Reconfigurable Computing Fabric
EP2701074B1 (en) Method, device, and system for performing scheduling in multi-processor core system
US9703595B2 (en) Multi-core system with central transaction control
US20190303147A1 (en) Execution Control of a Multi-Threaded, Self-Scheduling Reconfigurable Computing Fabric
CN107800546B (zh) 一种广播消息的管理方法及装置
US20230153258A1 (en) Multi-Threaded, Self-Scheduling Reconfigurable Computing Fabric
CN103473129B (zh) 线程数目可伸缩的多任务队列调度系统及其实现方法
WO2014187412A1 (zh) 消息处理线程的控制方法及装置
JP2007079789A (ja) 計算機システム及びイベント処理方法
TW200527195A (en) Mechanism to control hardware interrupt acknowledgement in a virtual machine system
CN105187327A (zh) 一种分布式消息队列中间件
US20210334228A1 (en) Managing network interface controller-generated interrupts
CN101826000A (zh) 流水线微处理器的中断响应确定方法、装置及微处理器核
WO2014110702A1 (zh) 协同并发式消息总线、主动构件组装模型及构件拆分方法
CN109062604A (zh) 一种面向标量和向量指令混合执行的发射方法及装置
CN101639791B (zh) 一种改善嵌入式实时操作系统中断延迟的方法
CN109189598A (zh) 一种中断定位的方法、处理器及终端设备
CN111158875B (zh) 基于多模块的多任务处理方法、装置及系统
TWI409701B (zh) Execute the requirements registration and scheduling method
CN109426562B (zh) 优先级加权轮转调度器
US9507569B2 (en) Digital data processing systems

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 10856900

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 10856900

Country of ref document: EP

Kind code of ref document: A1