CN112286697B - Mutually exclusive resource access method based on operating system-free single chip microcomputer platform - Google Patents

Mutually exclusive resource access method based on operating system-free single chip microcomputer platform Download PDF

Info

Publication number
CN112286697B
CN112286697B CN202011233896.XA CN202011233896A CN112286697B CN 112286697 B CN112286697 B CN 112286697B CN 202011233896 A CN202011233896 A CN 202011233896A CN 112286697 B CN112286697 B CN 112286697B
Authority
CN
China
Prior art keywords
interrupt
resource
context
mutual exclusion
priority
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202011233896.XA
Other languages
Chinese (zh)
Other versions
CN112286697A (en
Inventor
郝佳佳
王科
钟前进
李延法
胡向明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Step Robotics Co ltd
Original Assignee
Shanghai Step Robotics Co ltd
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 Shanghai Step Robotics Co ltd filed Critical Shanghai Step Robotics Co ltd
Priority to CN202011233896.XA priority Critical patent/CN112286697B/en
Publication of CN112286697A publication Critical patent/CN112286697A/en
Application granted granted Critical
Publication of CN112286697B publication Critical patent/CN112286697B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms
    • 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/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • G06F9/4831Task transfer initiation or dispatching by interrupt, e.g. masked with variable priority
    • 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/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Microcomputers (AREA)

Abstract

A mutual exclusion resource access method based on a single chip microcomputer platform without an operating system comprises the following steps: setting a mutual exclusion lock for the mutual exclusion resource to be accessed before accessing the mutual exclusion resource by a background program or low-priority interrupt; high-priority interrupt interrupts the running of background program or low-priority interrupt program, sets interrupt return context, closes the current interrupt if detecting that the exclusive lock is valid before accessing the exclusive resource, adds the exclusive resource waiting queue and sets waiting resource context, then jumps to the interrupt return context to realize interrupt return; the background program or the low-priority interrupt resumes running, after the mutual exclusion resource is accessed, the mutual exclusion lock is released, and the mutual exclusion resource is enabled to wait for the interrupt with the highest priority in the queue; and skipping the interrupt with the highest priority to a waiting resource context, and accessing the mutual exclusion resource if detecting that the mutual exclusion lock is released. The invention realizes the synchronous access of the multi-task to the mutually exclusive resource in the singlechip platform without the operating system.

Description

Mutually exclusive resource access method based on operating system-free single chip microcomputer platform
Technical Field
The invention relates to a multi-task access mutually exclusive resource technology.
Background
With the development of automation lines, digital plants, etc., the requirements for real-time performance of control and driving units are increasing. Most control units adopt a real-time operating system or a micro-kernel to realize task scheduling and real-time control. The operating system or the microkernel can bring task jitter and delay, and real-time performance is affected.
In order to further improve the real-time performance and reduce the cost, most of the driving units and the low-end control units are developed based on a single chip microcomputer, no operating system is provided, a method of adding an interrupt program and a background program is adopted, and the real-time performance of the interrupt is high, so that the real-time control can be better carried out. Without an operating system, access to some mutually exclusive resources (e.g., EEPROM, FRAM) becomes complex, requiring good reentrant code.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a mutual exclusion resource access method based on a single chip microcomputer platform without an operating system, which can realize synchronous access of an interrupt program and a background program of the single chip microcomputer platform without the operating system to mutual exclusion resources.
The embodiment of the invention provides a mutually exclusive resource access method based on a single chip microcomputer platform without an operating system, which comprises the following steps:
before accessing the mutually exclusive resource, the background program or the low-priority interrupt sets a mutually exclusive lock for the mutually exclusive resource to be accessed;
high-priority interrupt interrupts the running of background program or low-priority interrupt program, sets interrupt return context, closes the current interrupt if detecting that the exclusive lock is valid before accessing the exclusive resource, adds the exclusive resource waiting queue and sets waiting resource context, then jumps to the interrupt return context to realize interrupt return;
the background program or the low-priority interrupt resumes running, after the mutual exclusion resource is accessed, the mutual exclusion lock is released, and the mutual exclusion resource is enabled to wait for the interrupt with the highest priority in the queue;
and jumping the interrupt with the highest priority to a waiting resource context, and accessing the mutually exclusive resource if detecting that the mutually exclusive lock is released.
In the mutex resource access method based on the operating system-free single chip microcomputer platform, the interrupt source flag is not cleared when the current interrupt is closed by the high-priority interrupt, so that the interrupt can be immediately entered when the interrupt is started.
In the above mutually exclusive resource access method based on the os-free single chip microcomputer platform, the high priority interrupt uses the setjmp function of the MDK itself to set the interrupt return context and the wait resource context, so as to store the current context information.
In the above exclusive resource access method based on the single chip microcomputer platform without the operating system, the high-priority interrupt jumps to the interrupt return context by using the longjmp function of the MDK itself, and the interrupt with the highest priority jumps to the waiting resource context by using the longjmp function of the MDK itself, so that the last executed code continues to be executed.
In the method for accessing the mutually exclusive resource based on the operating system-free single chip microcomputer platform, if the interrupt with the highest priority jumps to the waiting resource context and then detects that the mutually exclusive lock is valid, the current interrupt is closed, the mutually exclusive resource waiting queue is added and the waiting resource context is set, and then the interrupt return context is jumped to, so that the interrupt return is realized.
The invention has at least the following advantages and characteristics:
1. the embodiment realizes the multi-task synchronous access of the mutually exclusive resources in the singlechip platform without the operating system, reduces the complexity of the access of the mutually exclusive resources and simplifies the writing of mutually exclusive resource driving programs;
2. after the mutually exclusive resource lock is released, the highest priority interrupt program of the resource is waited to immediately resume execution, so that the resource is accessed, and the influence of the high priority interrupt program on the real-time property due to the access of the mutually exclusive resource is reduced.
Drawings
Fig. 1 is a flowchart illustrating the first two steps of a mutex resource access method based on a single-chip microcomputer platform without an operating system according to an embodiment of the present invention.
Fig. 2 is a flowchart illustrating the last two steps of the exclusive resource access method based on the no-os single-chip microcomputer platform according to an embodiment of the present invention.
Detailed Description
According to the exclusive resource access method based on the operating system-free single chip microcomputer platform, the object for accessing the exclusive resource comprises a background program and an interrupt program, and the exclusive resource access method based on the operating system-free single chip microcomputer platform comprises the following steps:
before accessing the mutually exclusive resource, the background program or the low-priority interrupt sets a mutually exclusive lock for the mutually exclusive resource to be accessed; the mutually exclusive resource is a resource which can be accessed by both a background program and an interrupt program but cannot be accessed simultaneously;
high-priority interruption interrupts the running of a background program or a low-priority interruption program, an interruption return context is set, before accessing the exclusive resource, if the exclusive lock is detected to be released, the exclusive resource is directly accessed, if the exclusive lock is detected to be effective, the current interruption is closed (the current interruption does not respond to an external interruption trigger event any more), a exclusive resource waiting queue is added, a waiting resource context is set, and then the interruption return context is jumped to, so that interruption return is realized; the mutually exclusive resource waiting queue is a queue for mutually exclusive resource maintenance and stores task information of waiting resources, such as interrupt priority and the like;
the background program or the low-priority interrupt resumes running, after the mutual exclusion resource is accessed, the mutual exclusion lock is released, and the mutual exclusion resource is enabled to wait for the interrupt with the highest priority in the queue;
and the interrupt with the highest priority jumps to the context of the waiting resource, and if the mutual exclusion lock is detected to be released, the mutual exclusion resource is accessed, so that the synchronous access of the mutual exclusion resource is realized.
The invention is further described below with reference to the accompanying drawings.
Fig. 1 and fig. 2 are schematic flowcharts illustrating a mutually exclusive resource access method based on a single-chip microcomputer platform without an operating system according to an embodiment of the present invention, and please refer to fig. 1 and fig. 2. In the single chip microcomputer platform without the operating system, the objects for accessing the mutual exclusion resources comprise a background program and an interrupt program, and the mutual exclusion resources needing to be accessed comprise an EEPROM, an FRAM and the like. The interrupt program can interrupt the execution of the background program, the interrupt program comprises interrupt programs with a plurality of priorities, and the interrupt program with a high priority can interrupt the execution of the interrupt program with a low priority.
The present embodiment is described by taking an example in which the interrupt program and the background program access the mutually exclusive resource simultaneously, but in other embodiments, the interrupt program with a low priority and the interrupt program with a high priority may access the mutually exclusive resource simultaneously. The mutually exclusive resource access method based on the operating system-free single chip microcomputer platform comprises the following steps:
a. before accessing the exclusive resource, the background program sets a exclusive lock for the exclusive resource, the exclusive lock is a variable, the exclusive lock is valid before accessing the resource, namely the exclusive lock identifier is set to 1, and the exclusive lock is invalid after the access is finished, namely the exclusive lock identifier is set to 0.
b. The interrupt program interrupts the running of the background program, and the interrupt program sets an interrupt return context through a setjmp function carried by an MDK (Microcontroller Development Kit) when the interrupt starts, so that the interrupt program can realize interrupt return through a longjmp function carried by the MDK. The interrupt program continues to run, after the condition that a mutual exclusion lock is effective is detected before accessing the mutual exclusion resource, the resource is accessed, the current interrupt is closed, but an interrupt source mark is not cleared, so that the interrupt can be immediately entered when the interrupt is started, then a mutual exclusion resource waiting queue is added, then a waiting resource context is set through a setjmp function, so that the interrupt program can be directly jumped to the waiting resource context for execution when being entered again, and finally the interrupt return context is jumped through a longjmp function, and the interrupt return is realized.
The interrupt context is not released by the return mode, and the interrupt context is released along with the return of the function if the interrupt context is not directly returned by the mode. The interrupt return context is an interrupt site when the interrupt program enters the interrupt, and the wait resource context is the interrupt site when the interrupt program accesses the mutually exclusive resource. In practical applications, the interrupt program does not necessarily access the mutex resource immediately after entering the interrupt, and some other programs may be executed first (for example, the ellipsis drawn between the "set interrupt return context" block and the "mutex lock identifier =0" decision block in fig. 1 represents this layer of meaning), and then access the mutex resource after the other programs are executed.
c. After the interrupt program returns, the background program resumes execution, continues to access the exclusive resource, releases the exclusive lock after the access is completed, and enables the exclusive resource to wait for the interrupt with the highest priority in the queue; the interrupt routine shown in FIG. 2 in the waiting resource represents the highest priority interrupt in the mutually exclusive resource waiting queue described above;
d. and immediately executing the interrupt program with the highest priority, jumping to the context of the waiting resource through a longjmp function, and accessing the exclusive resource if the exclusive lock is detected to be invalid, thereby finally realizing the synchronous access of the exclusive resource.
In the present embodiment, even if there is a program earlier in the time sequence than the access mutually-exclusive resource, the interrupt program with the highest priority, once enabled by the background program, does not execute the program earlier in the time sequence, but directly jumps to the waiting resource context, thereby reducing the influence of the access mutually-exclusive resource on the real-time performance of the interrupt program with the highest priority. If the interrupt program with the highest priority detects that the mutex lock is valid after jumping to the waiting resource context (in the process that the interrupt with the highest priority resumes execution and jumps to the waiting resource context, a background program or a low-priority interrupt sets the mutex lock for the mutex resource), the interrupt program with the highest priority executes the workflow in the step b again, namely, the current interrupt is closed, the mutex resource waiting queue is added and the waiting resource context is set, and then the interrupt return context is jumped to, so that the interrupt return is realized.
The embodiment of the invention realizes the multi-task synchronous access of the mutually exclusive resources in the singlechip platform without the operating system, reduces the complexity of the access of the mutually exclusive resources and simplifies the writing of the mutually exclusive resource driving program.

Claims (5)

1. A mutual exclusion resource access method based on a single chip microcomputer platform without an operating system is characterized by comprising the following steps:
setting a mutual exclusion lock for the mutual exclusion resource to be accessed before accessing the mutual exclusion resource by a background program or low-priority interrupt;
the high-priority interrupt interrupts the running of a background program or a low-priority interrupt program, sets an interrupt return context, closes the current interrupt if a mutex lock is detected to be effective before accessing the mutex resource, adds a mutex resource waiting queue and sets a waiting resource context so as to directly jump to the waiting resource context for execution when entering the interrupt program again, and then jumps to the interrupt return context to realize interrupt return; the interrupt return context is an interrupt site when an interrupt program enters interrupt, and the wait resource context is an interrupt site when the interrupt program accesses mutually exclusive resources;
a background program or low-priority interrupt resumes running, after accessing a mutually exclusive resource, a mutually exclusive lock is released, and the mutually exclusive resource is enabled to wait for the interrupt with the highest priority in a queue;
and jumping the interrupt with the highest priority to a waiting resource context, and accessing the mutually exclusive resource if detecting that the mutually exclusive lock is released.
2. The method of claim 1, wherein the high priority interrupt does not clear the interrupt source flag when the current interrupt is turned off.
3. The method as claimed in claim 1, wherein the high priority interrupt uses MDK's self-contained setjmp function to set the interrupt return context and the wait resource context.
4. The method according to claim 1 or 3, wherein the high priority interrupt jumps to the interrupt return context using the own longjmp function of the MDK, and the interrupt with the highest priority jumps to the waiting resource context using the own longjmp function of the MDK.
5. The method as claimed in claim 1, wherein if the mutex lock is detected to be valid after the interrupt with the highest priority jumps to the waiting resource context, the current interrupt is closed, the mutex resource waiting queue is added and the waiting resource context is set, and then the interrupt return context is jumped to, thereby realizing the interrupt return.
CN202011233896.XA 2020-11-06 2020-11-06 Mutually exclusive resource access method based on operating system-free single chip microcomputer platform Active CN112286697B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011233896.XA CN112286697B (en) 2020-11-06 2020-11-06 Mutually exclusive resource access method based on operating system-free single chip microcomputer platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011233896.XA CN112286697B (en) 2020-11-06 2020-11-06 Mutually exclusive resource access method based on operating system-free single chip microcomputer platform

Publications (2)

Publication Number Publication Date
CN112286697A CN112286697A (en) 2021-01-29
CN112286697B true CN112286697B (en) 2022-11-25

Family

ID=74351738

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011233896.XA Active CN112286697B (en) 2020-11-06 2020-11-06 Mutually exclusive resource access method based on operating system-free single chip microcomputer platform

Country Status (1)

Country Link
CN (1) CN112286697B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112799787B (en) * 2021-02-07 2023-10-03 北京华如科技股份有限公司 Improved parallel behavior execution conflict resolution method in simulation operation and storage medium thereof

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101051281A (en) * 2007-05-16 2007-10-10 杭州华三通信技术有限公司 Method and device for mutual repulsion access of multiple CPU to critical resources
CN103248667A (en) * 2012-02-14 2013-08-14 阿里巴巴集团控股有限公司 Resource access method and system for distributed system
CN107273214A (en) * 2017-06-30 2017-10-20 郑州云海信息技术有限公司 A kind of multinuclear controller resource access method and its device based on solid state hard disc
CN107562685A (en) * 2017-09-12 2018-01-09 南京国电南自电网自动化有限公司 A kind of method of data interaction between polycaryon processor core based on compensation of delay
CN111259030A (en) * 2020-01-16 2020-06-09 平安医疗健康管理股份有限公司 Thread execution method and device based on distributed lock and storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5784613A (en) * 1995-09-12 1998-07-21 International Busines Machines Corporation Exception support mechanism for a threads-based operating system
WO2006069484A1 (en) * 2004-12-30 2006-07-06 Intel Corporation Methods and apparatuses to maintain multiple execution contexts
CN1952880A (en) * 2006-10-26 2007-04-25 康佳集团股份有限公司 A method making nonlocal skip tool imitated into exception mechanism by C programming language
CN101482833B (en) * 2009-02-18 2011-06-15 杭州华三通信技术有限公司 Critical resource related interruption handling method and apparatus, and real-time operating system
CN109117253B (en) * 2017-06-26 2022-05-24 阿里巴巴集团控股有限公司 Method and device for scheduling microkernels
CN109840137B (en) * 2017-11-28 2021-01-22 大唐移动通信设备有限公司 Cross-core scheduling method and device
CN111506438A (en) * 2020-04-03 2020-08-07 华夏龙晖(北京)汽车电子科技股份有限公司 Shared resource access method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101051281A (en) * 2007-05-16 2007-10-10 杭州华三通信技术有限公司 Method and device for mutual repulsion access of multiple CPU to critical resources
CN103248667A (en) * 2012-02-14 2013-08-14 阿里巴巴集团控股有限公司 Resource access method and system for distributed system
CN107273214A (en) * 2017-06-30 2017-10-20 郑州云海信息技术有限公司 A kind of multinuclear controller resource access method and its device based on solid state hard disc
CN107562685A (en) * 2017-09-12 2018-01-09 南京国电南自电网自动化有限公司 A kind of method of data interaction between polycaryon processor core based on compensation of delay
CN111259030A (en) * 2020-01-16 2020-06-09 平安医疗健康管理股份有限公司 Thread execution method and device based on distributed lock and storage medium

Also Published As

Publication number Publication date
CN112286697A (en) 2021-01-29

Similar Documents

Publication Publication Date Title
US9798595B2 (en) Transparent user mode scheduling on traditional threading systems
US8166483B2 (en) Method and apparatus for implementing priority management of computer operations
Feng et al. Certifying low-level programs with hardware interrupts and preemptive threads
US20090328053A1 (en) Adaptive spin-then-block mutual exclusion in multi-threaded processing
US8321874B2 (en) Intelligent context migration for user mode scheduling
Brandenburg Multiprocessor real-time locking protocols
KR20070083460A (en) Method and system for concurrent execution of multiple kernels
CN107203428B (en) Xen-based VCPU multi-core real-time scheduling algorithm
Puschner et al. A profile for high-integrity real-time Java programs
EP1716482A2 (en) Sharing idled processor execution resources
CN112286697B (en) Mutually exclusive resource access method based on operating system-free single chip microcomputer platform
WO2005048009A2 (en) Method and system for multithreaded processing using errands
Goyette An analysis and description of the inner workings of the freertos kernel
Levis et al. Schedulers and tasks
Wan et al. A time-aware programming framework for constructing predictable real-time systems
CN115964150A (en) Business processing method, system, device and medium based on double real-time kernels
KR100848323B1 (en) Method for enhancing real time response in embedded OS kernel
CN117407054A (en) Interrupt processing method, electronic device, and storage medium
CN110851239B (en) TYPE-I TYPE hard real-time high-reliability full-virtualization method
Steinberg Quality-assuring scheduling in the Fiasco microkernel
US20030204639A1 (en) Task dispatch in priority pre-emptive real-time operating systems
Corbett Constructing abstract models of concurrent real-time software
He et al. Real-Time Optimization and Application of the Embedded ARM-Linux Scheduling Policy
Boukir et al. Reducing the gap between theory and practice: towards A Proven Implementation of Global EDF in Trampoline
CN117539595A (en) Cooperative scheduling method and related equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant