Virtual timer expansion method, device, electronic device and storage medium
By obtaining and switching the extended channel parameters of the virtual timer, the problem of increased chip area and resource waste of the timer IP core is solved, and the expansion of the number of timers and the saving effect of real-time control are achieved.
Patent Information
- Application Number
- CN202211643519.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-20
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2042-12-20
AI Technical Summary
In the prior art, each timer is configured with a corresponding IP core, which increases chip area, wastes resources, and increases design costs.
By obtaining the channel parameters of multiple preset extended channels, selecting the target virtual channel, and switching the parameters at the channel trigger moment, the virtual timer is used to process the user configuration and the number of timers is expanded to reduce the number of IP cores.
The number of timers can be expanded according to application needs, which reduces chip area, saves resources, and facilitates the processing of real-time control programs.
Smart Images

Figure CN116149784B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of timer technology, and in particular to a method, device, electronic device, and storage medium for extending a virtual timer. Background Art
[0002] In the related art, commonly used timers can be divided into hardware timers and virtual timers (also known as software timers). Hardware timers have the advantages of high precision and high real-time performance. However, for processors (such as central processing units (CPUs) or microcontroller units (MCUs)), the number of hardware timers is often limited, making it difficult to meet the needs of scenarios requiring a large number of timers. Virtual timers can meet the needs of scenarios requiring a large number of timers without being limited by the number of hardware timers.
[0003] In related technologies, microcontroller timers have multiple functions, such as input capture and pulse-width modulation output. Timers are also used to define multiple periodic tasks. Therefore, the number of timers is a key specification for microcontrollers. In related technologies, the number of timers required dictates the number of semiconductor intellectual property (IP) cores required to handle multiple timing tasks simultaneously. However, configuring a corresponding IP core for each timer increases chip area, wastes resources, and increases design costs.
[0004] There is no better technical solution to the problem that each timer is configured with a corresponding IP core in the related art, which increases the chip area, wastes resources and increases design costs. Summary of the Invention
[0005] The present application provides a method, device, electronic device and storage medium for expanding a virtual timer, so as to at least solve the problem in the related art of using a corresponding IP core configured for each timer, which increases chip area, wastes resources and increases design costs.
[0006] In the first aspect, the present application provides a method for extending a virtual timer, which is applied to a hardware timer, and the extension method includes: obtaining channel parameters corresponding to multiple preset extended channels, wherein the channel parameters include the channel status, channel data and corresponding channel trigger time of each extended channel; according to the channel status, selecting a target virtual channel from the multiple extended channels, wherein each extended channel is associated with a virtual timer, and the virtual timer is used to process a preset user configuration; at the channel trigger time corresponding to the target virtual channel, based on the channel data and the channel status corresponding to the target virtual channel, switching the parameters of the target virtual channel so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration.
[0007] In a second aspect, the present application provides a virtual timer expansion device, which is applied to a hardware timer, including:
[0008] An acquisition module, configured to acquire channel parameters corresponding to a plurality of preset extended channels, wherein the channel parameters include a channel state, channel data, and a corresponding channel triggering time of each of the extended channels;
[0009] a selection module, configured to select a target virtual channel from the plurality of extended channels according to the channel status, wherein each extended channel is associated with a virtual timer, and the virtual timer is configured to process a preset user configuration;
[0010] A processing module is used to switch parameters of the target virtual channel based on the channel data and the channel status corresponding to the target virtual channel at the channel triggering moment corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration.
[0011] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0012] Memory for storing computer programs;
[0013] The processor is configured to implement the steps of the virtual timer expansion method described in any one of the embodiments of the first aspect when executing a program stored in the memory.
[0014] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the virtual timer extension method as described in any embodiment of the first aspect are implemented.
[0015] Compared with the related art, the present embodiment provides a method, device, electronic device and storage medium for expanding a virtual timer. The method obtains channel parameters corresponding to a plurality of preset extended channels, wherein the channel parameters include the channel status, channel data and corresponding channel triggering time of each of the extended channels; selects a target virtual channel from the plurality of extended channels according to the channel status, and associates each of the extended channels with a virtual timer, which is used to process a preset user configuration; and switches parameters of the target virtual channel based on the channel data and channel status corresponding to the target virtual channel at the channel triggering time corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration. This solves the problem in the related art of using an IP core corresponding to each timer configuration, which increases chip area, wastes resources and increases design costs. The method achieves the beneficial effects of expanding the number of timers according to application needs, facilitating the processing of real-time control programs, reducing the number of timer IP cores and saving chip area.
[0016] The details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 A flowchart of a method for extending a virtual timer provided in an embodiment of the present application;
[0020] Figure 2 This is a block diagram of the structure of the virtual timer in the preferred embodiment of the present application;
[0021] Figure 3 This is a flow chart of the extended channel operation in the preferred embodiment of the present application;
[0022] Figure 4 This is a workflow diagram of the data controller of the preferred embodiment of the present application;
[0023] Figure 5 This is a workflow diagram of the time queue manager of the preferred embodiment of the present application;
[0024] Figure 6 This is a flowchart of the multi-channel manager operation in a preferred embodiment of the present application;
[0025] Figure 7 This is a structural block diagram of a virtual timer expansion device provided in an embodiment of the present application;
[0026] Figure 8 Schematic diagram of the structure of the electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0028] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0029] Figure 1 A flow chart of a method for extending a virtual timer provided in an embodiment of the present application. Figure 1 As shown, an embodiment of the present application provides a method for extending a virtual timer, the method comprising the following steps:
[0030] Step S101 : acquiring channel parameters corresponding to a plurality of preset extended channels, wherein the channel parameters include a channel state, channel data, and a corresponding channel triggering time of each extended channel.
[0031] In this embodiment, multiple virtual timers are expanded on the IP core corresponding to the hardware timer. In this embodiment, the IP core of the hardware timer includes a data controller, multiple expansion channels, a time queue manager, a multi-channel comparator, a high-precision timer, a data SRAM and an internal bus controller.
[0032] In this embodiment, each expansion channel can function as an input or output channel, allowing users to configure input filtering parameters or output driver parameters. In this embodiment, channel data includes pre-stored voltage levels read from the output buffer of the expansion channel when the corresponding trigger signal is valid, or captured voltage levels at the corresponding pin of the input channel. Channel status includes whether the buffer of the corresponding expansion channel is empty or not.
[0033] In this embodiment, when the trigger signal of the channel is valid (the corresponding channel trigger moment arrives), the extended channel reads the level value pre-stored in the output FIFO buffer and manipulates the GPIO controller to set the corresponding pin level; when the trigger signal corresponding to the channel is valid, the extended channel captures the level at the corresponding pin and writes it to the input buffer; when the channel selection signal is valid, the data controller reads the level value captured by the input channel from the input buffer corresponding to the input channel and writes it to the data SRAM, or writes the next trigger level to the output buffer corresponding to the output channel, and generates the next trigger moment at the same time.
[0034] In this embodiment, high-speed sequencing and insertion of the channel triggering moments corresponding to the extended channels are achieved through a time queue manager and a multi-channel comparator.
[0035] Step S102 : selecting a target virtual channel from a plurality of extended channels according to the channel status, wherein each extended channel is associated with a virtual timer, and the virtual timer is used to process a preset user configuration.
[0036] In this embodiment, user configuration refers to the function that the virtual timer set by the user needs to complete; in this embodiment, the channel status is used to first determine whether the corresponding input buffer or output buffer is empty to determine whether the corresponding extended channel is a valid channel. For example: when the extended channel is an input channel, when it is determined that the input buffer of the input channel is not empty, the input channel is determined to be a valid channel. For another example: when the extended channel is an output channel, when it is determined that the output buffer corresponding to the output channel is empty, the output channel is determined to be a valid channel; when the corresponding extended channel is determined to be a valid channel, a target virtual channel is selected according to the fixed channel selection order or the user-defined channel priority order, and the configuration and status context of the corresponding extended channel are switched.
[0037] In this embodiment, each virtual timer corresponds to at least two extended channels, one extended channel is configured as an input channel, and the other extended channel is configured as an output channel, thereby realizing the input level capture and output level setting functions of the timer.
[0038] Step S103 : at the channel triggering moment corresponding to the target virtual channel, parameters of the target virtual channel are switched based on the channel data and channel status corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration.
[0039] In this embodiment, when the data controller determines that the input buffer is not empty, it starts to process the input data of the corresponding input channel (for example, the captured level value of the corresponding pin); when it determines that the output buffer is empty, it starts to generate the output data corresponding to the output channel; in this embodiment, if the current expansion channel is an input channel, the data controller reads the captured level value from the input buffer and writes it to the data SRAM; if the current expansion channel is an output channel, the data controller generates the next trigger level and writes it to the output buffer; at the same time, the data controller generates the next trigger moment and inserts the trigger channel and trigger point into the time queue manager.
[0040] In this embodiment, switching the target virtual channel refers to switching all channel data, channel configuration, and channel status of the target virtual channel.
[0041] Through the above steps S101 to S103, channel parameters corresponding to a plurality of preset extended channels are obtained, wherein the channel parameters include the channel status, channel data and corresponding channel triggering moment of each extended channel; according to the channel status, a target virtual channel is selected from the plurality of extended channels, wherein each extended channel is associated with a virtual timer, and the virtual timer is used to process the preset user configuration; at the channel triggering moment corresponding to the target virtual channel, the parameters of the target virtual channel are switched based on the channel data and channel status corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration, thereby solving the problem in the related art of using an IP core corresponding to each timer configuration, increasing the chip area, wasting resources and increasing the design cost, and realizing the beneficial effect of expanding the number of timers according to application needs, facilitating the processing of real-time control programs, reducing the number of timer IP cores, and saving chip area.
[0042] In some embodiments, selecting a target virtual channel from a plurality of extended channels according to the channel status is implemented by the following steps:
[0043] Step 21 : Determine a buffer unit corresponding to each extended channel according to attribute information of each extended channel, wherein the attribute information is used to characterize the channel category corresponding to the extended channel, and the buffer unit includes one of an output buffer and an input buffer.
[0044] In this embodiment, whether the corresponding extended channel is an input channel or an output channel is determined by attribute information. By determining the channel category corresponding to the corresponding extended channel, the corresponding buffer unit is also determined accordingly. For example, when the extended channel is an input channel, the corresponding buffer unit corresponds to an input buffer.
[0045] Step 22: judging whether the corresponding buffer unit is empty according to the channel status, and determining whether the corresponding extended channel is valid according to the judgment result.
[0046] In this embodiment, for different buffer units, the judgment on whether the buffer unit is empty is different. For example, for the input buffer corresponding to the input channel, it is judged whether the input buffer is not empty, and when it is judged that the input buffer is not empty, the extended channel is determined to be a valid input channel; for another example, for the output buffer corresponding to the output channel, it is judged whether the output buffer is empty, and when it is judged that the output buffer is empty, the extended channel is determined to be a valid output channel.
[0047] Step 23 : selecting a target virtual channel from the valid extended channels according to a preset condition, wherein the preset condition includes one of the following: a fixed channel selection order, a channel priority order.
[0048] The buffer unit corresponding to each extended channel is determined according to the attribute information of each extended channel in the above steps, wherein the attribute information is used to characterize the channel category corresponding to the extended channel, and the buffer unit includes one of an output buffer and an input buffer; according to the channel status, whether the corresponding buffer unit is empty is judged, and according to the judgment result, whether the corresponding extended channel is valid is determined; according to preset conditions, a target virtual channel is selected from the valid extended channels, wherein the preset conditions include one of the following: a fixed channel selection order and a channel priority order, so as to realize the selection of a valid input channel or output channel according to a fixed order or a user-defined priority order.
[0049] In some embodiments, the buffer unit corresponding to each extended channel is determined based on the attribute information of each extended channel, which is achieved by the following steps: when the attribute information indicates that the extended channel is an input channel, the buffer unit is determined to be an input buffer, or, when the attribute information indicates that the extended channel is an output channel, the buffer unit is determined to be an output buffer.
[0050] In this embodiment, whether the corresponding extended channel is an input channel or an output channel is determined by attribute information. By determining the channel category corresponding to the corresponding extended channel, the corresponding buffer unit is also determined accordingly. For example, when the extended channel is an input channel, the corresponding buffer unit corresponds to an input buffer.
[0051] In some embodiments, whether the corresponding buffer unit is empty is determined based on the channel status, and whether the corresponding extended channel is valid is determined based on the judgment result, which is achieved through the following steps: when the buffer unit is an input buffer, whether the input buffer is not empty is determined, and if the input buffer is determined to be not empty, the corresponding extended channel is determined to be a valid input channel; or, when the buffer unit is an output buffer, whether the output buffer is empty is determined, and if the output buffer is determined to be empty, the corresponding extended channel is determined to be a valid output channel.
[0052] In this embodiment, for different buffer units, the judgment on whether the buffer unit is empty is different. For example, for the input buffer corresponding to the input channel, it is judged whether the input buffer is not empty, and when it is judged that the input buffer is not empty, the extended channel is determined to be a valid input channel; for another example, for the output buffer corresponding to the output channel, it is judged whether the output buffer is empty, and when it is judged that the output buffer is empty, the extended channel is determined to be a valid output channel.
[0053] In some embodiments, the target virtual channel is a valid input channel. At the channel triggering moment corresponding to the target virtual channel, the parameters of the target virtual channel are switched based on the channel data and channel status corresponding to the target virtual channel, including the following steps: at the corresponding channel triggering moment, the first level value of the pin corresponding to the valid input channel is captured, and the first level value is stored in the input buffer and written into the preset data SRAM.
[0054] In some embodiments, the target virtual channel is a valid output channel. At the channel trigger moment corresponding to the target virtual channel, parameters of the target virtual channel are switched based on the channel data and channel status corresponding to the target virtual channel, including the following steps: at the corresponding channel trigger moment, based on reading a pre-stored second level value from the output buffer, the pin level corresponding to the valid output channel is set, wherein the second level value is pre-written at the previous channel trigger moment corresponding to the valid output channel.
[0055] In some embodiments, before obtaining the channel configuration parameters corresponding to the preset multiple extended channels, the following steps are further performed:
[0056] Step 31: Broadcast the preset next trigger moment in the preset time queue to the comparison unit associated with each extension channel in a set time sequence, and determine the current position of the next trigger moment in the time queue, wherein the next trigger moment is used to represent the trigger configuration point of the corresponding extension channel after the current broadcast moment, and the comparison unit includes one of the following: a single-channel comparator, or a channel of a multi-channel comparator.
[0057] Step 32: Obtain the judgment result of each comparison unit on whether the next triggering time corresponding to the extension channel associated with itself is later than the current broadcasting time.
[0058] Step 33: Based on the judgment result and the current position, determine whether to insert the next triggering moment corresponding to the extended channel into the preset time queue, and use the next triggering moment inserted into the time queue as the channel triggering moment of the corresponding extended channel.
[0059] In this embodiment, each trigger moment of the time queue is broadcast to multiple comparison units in chronological order. Each comparator compares the next trigger moment of the corresponding extended channel with the current broadcast moment. If the next trigger moment is not later than the current broadcast moment and later than the previous broadcast moment, the next trigger moment is used as the new trigger moment of the extended channel and is immediately inserted into the time queue. Then, the time queue broadcast and multi-channel comparison are continued from the newly inserted trigger moment.
[0060] In some optional implementations, if each extended channel has a fixed trigger period and the length difference is obvious, only a single comparator can be used. According to the length of the trigger period of each extended channel, the short-period channel is given priority for comparison and insertion of the next trigger moment; for high-speed input and output signals, a multi-channel comparator can be used. The multi-channel comparator receives a high-precision timer broadcast and compares it with 1-2 trigger moments at the same time. When they are equal, the selection signal of the corresponding channel is triggered, and at the same time, the data controller is waiting to refresh the next trigger moment.
[0061] Through the above steps, the preset next trigger moment in the preset time queue is broadcasted to the comparison unit associated with each extended channel in a set time sequence, and the current position of the next trigger moment in the time queue is determined, wherein the next trigger moment is used to represent the trigger configuration point of the corresponding extended channel after the current broadcast moment, and the comparison unit includes one of the following: a single-channel comparator, a channel of a multi-channel comparator; obtaining a judgment result of each comparison unit on whether the next trigger moment corresponding to the extended channel associated with itself is later than the current broadcast moment; based on the judgment result and the current position, determining whether to insert the next trigger moment corresponding to the extended channel into the preset time queue, and using the next trigger moment inserted into the time queue as the channel trigger moment of the corresponding extended channel, thereby achieving high-speed sorting and insertion of the channel trigger moments corresponding to each extended channel.
[0062] In some embodiments, based on the judgment result and the current position, it is determined whether to insert the next trigger moment corresponding to the extended channel into the preset time queue, and the next trigger moment inserted into the time queue is used as the channel trigger moment of the corresponding extended channel, including the following steps: when the judgment result is that the corresponding next trigger moment is in the target state, the current corresponding next trigger moment is inserted into the time queue, wherein the target state includes one of the following states: the next trigger moment is not later than the current broadcast moment and the current position is at the head of the time queue, the next trigger moment is not later than the current broadcast moment and later than the previous broadcast moment, and the next trigger moment is later than the previous broadcast moment and the corresponding current position is at the end of the time queue.
[0063] In this embodiment, if the next trigger moment is later than the current broadcast moment and is not at the end of the time queue, the next trigger moment in the preset time queue is broadcast to the comparison unit associated with each extension channel in the set time sequence. After the next trigger moment is inserted into the current position of the time queue, the next trigger moment is broadcasted from the current position of the time queue.
[0064] Through the above steps, high-speed sorting and insertion of the channel triggering moments corresponding to each extended channel is further achieved.
[0065] In some embodiments, after the current corresponding next trigger moment is inserted into the time queue, the following steps are also implemented: taking the next trigger moment currently inserted into the time queue as the broadcast starting point, the next trigger moment in the time queue is broadcast to the comparison unit associated with each extension channel according to the set time sequence.
[0066] Figure 2 This is a block diagram of the structure of the virtual timer in the preferred embodiment of the present application; Figure 3 This is a flow chart of the extended channel operation in the preferred embodiment of the present application; Figure 4 This is a workflow diagram of the data controller of the preferred embodiment of the present application; Figure 5 This is a workflow diagram of the time queue manager of the preferred embodiment of the present application; Figure 6 This is a flowchart of the multi-channel manager operation in the preferred embodiment of the present application.
[0067] See below Figures 2 to 6 , the extension method of the virtual timer of the preferred embodiment of the present application is further described as follows:
[0068] refer to Figure 2 As shown, the virtual timer in the embodiment of the present application includes an expansion channel 201 directly connected to the GPIO controller, a high-precision counter 202, a time queue processor 203, a multi-channel comparator 204, a data processor 205 and an internal bus controller 206.
[0069] Among them, the GPIO controller of the microcontroller is directly connected to the expansion channel 201. Each expansion channel 201 can be configured as an input channel and the input filtering parameters can be set; or configured as an output channel and the output drive parameters can be set; the expansion channel 201 of each virtual timer can capture the corresponding pin level when the channel trigger signal takes effect and store it in the input buffer; or read the pre-stored level from the output buffer when the channel trigger signal takes effect and set the corresponding pin level.
[0070] The data controller 205 selects an input channel or an output channel in a fixed order or a user-defined priority order according to whether the input buffer or output buffer of each extension channel 201 is empty; the data controller 205 can read the captured level value from the input buffer of the input channel and write it into the data SRAM, or write the next trigger level into the output buffer of the output channel, generate the next trigger moment at the same time, and insert the extension channel and the next trigger moment in the time queue manager, or refresh the next trigger moment of the channel in the multi-channel comparator.
[0071] The time queue manager 203 adopts a multi-channel parallel comparison insertion method when inserting into the time queue, that is, the trigger moments of the time queue are broadcast to multiple comparators in chronological order, and each comparator compares the next trigger moment of the corresponding extended channel 201 with the current broadcast moment, and when the next trigger moment is compared to be no later than the current broadcast moment and later than the previous broadcast moment, the corresponding next trigger moment is used as the new trigger moment of the extended channel 201 and is immediately inserted into the time queue, and then the queue broadcast and multi-channel comparison are continued from the newly inserted trigger moment; if each channel has a fixed trigger cycle and the length difference is obvious, only a single comparator can be used, and according to the length of the trigger cycle of each channel, the short-cycle channel is given priority for comparison and insertion of the next trigger moment.
[0072] Multi-channel comparator 204 is used to process high-speed input and output signals. It receives the broadcast from high-precision timer 202 and compares it with one or two trigger moments. When the two are equal, it triggers the selection signal of the corresponding channel and waits for the data controller 205 to refresh the next trigger moment.
[0073] refer to Figure 3 As shown, each extension channel in the embodiment of the present application performs the following steps:
[0074] Step S31, determine whether the extended channel is an input channel, if yes, execute step S32, otherwise, execute step S37.
[0075] Step S32, setting input filter parameters, then executing step S33.
[0076] Step S33, wait for input of a trigger signal, then execute step S34.
[0077] Step S34, capture the pin level, then execute step S35.
[0078] Step S35, write the captured pin level into the input buffer, and then execute step S36.
[0079] In step S36 , the data controller reads the input buffer, and then executes step S33 .
[0080] Step S37, setting output drive parameters, then executing step S38.
[0081] Step S38, wait for the output trigger signal, then execute step S39.
[0082] Step S39, read the pre-stored level from the output buffer, and then execute step S310.
[0083] Step S310, setting the output channel pin level, then executing step S311.
[0084] In step S311 , the data controller pre-stores the next level, and then executes step S38 .
[0085] In this embodiment, each extended channel 201 can be used as an input channel or an output channel, and the user can set the input filtering parameters or the output driving parameters; when the output trigger signal of the channel is valid, the extended channel reads the level value pre-stored in the output buffer and manipulates the GPIO controller to set the corresponding pin level; when the input trigger signal of the channel is valid, the extended channel captures the level at the corresponding pin and writes it to the input buffer; when the channel selection signal is valid, the data controller 205 reads the captured level value from the input buffer of the extended channel 201, or writes the level value of the next trigger point to the output buffer.
[0086] refer to Figure 4 As shown, the data controller of the embodiment of the present application performs the following steps:
[0087] Step S41, determine whether the input buffer is empty. If so, execute step S42; if it is completely empty, execute step S46.
[0088] Step S42, select a non-empty channel, then execute step S43.
[0089] Step S43: switch the configuration and state, then execute step S44.
[0090] In step S44, the capture level is read from the input buffer, and then step S45 is executed.
[0091] Step S45, writing the captured level into the data SRAM, and then executing step S41.
[0092] Step S46, determine whether the output buffer is empty, if so, execute step S47, if not empty, execute step S41.
[0093] Step S47, set a valid empty channel, then execute step S48.
[0094] Step S48, switch configuration and state, then execute step S49.
[0095] In step S49, the next trigger level and the next trigger moment are generated, and then step S410 is executed.
[0096] In step S410 , the next trigger level is written into the output buffer, and then step S411 is executed.
[0097] Step S411, insert the next trigger time and trigger channel into the time queue, then execute step S46.
[0098] In this embodiment, if the input buffer of the input channel is not empty, the data controller starts to process the input data of the input channel; if the output buffer of the output channel is empty, the data controller starts to generate the output data of the output channel. Afterwards, the data controller selects a channel according to a fixed order or a user-defined priority order, and switches the configuration and status context of the virtual channel; after that, if the data controller determines that the current channel is an input channel, it reads the captured level value from the input buffer of the input channel and writes it into the data SRAM; if it determines that the current channel is an output channel, it generates the next trigger moment and the next trigger level, inserts the trigger channel and trigger point into the time queue manager, and writes the level value of the next trigger point into the output buffer.
[0099] refer to Figure 5 As shown, the time queue manager of the embodiment of the present application performs the following steps:
[0100] Step S51, broadcast each triggering moment in time queue order, then execute step S52.
[0101] In step S52, the multi-way comparator compares the next trigger time with the current broadcast time, and then executes step S53.
[0102] Step S53, determine whether the next triggering time is at the head of the time queue and not later than the current broadcasting time, if so, execute step S56, otherwise, execute step S54.
[0103] Step S54, determine whether the next triggering time is not later than the current time but later than the last broadcasting time, if so, execute step S56, otherwise, execute step S55.
[0104] Step S55, determine whether the next triggering moment is at the end of the time queue and later than the last broadcasting moment, if so, execute step S56, otherwise, execute step S51.
[0105] Step S56: insert the next trigger point into the current position of the time queue, and then execute step S57.
[0106] Step S57, broadcast the next triggering moment just inserted into the time queue, and then execute step S51.
[0107] In this embodiment, each trigger moment of the time queue is broadcast to multiple comparators in chronological order. Each comparator compares the next trigger moment of the corresponding channel with the current broadcast moment. If the next trigger moment is not later than the current broadcast moment and later than the previous broadcast moment, or is at the head of the queue, or is later than the current broadcast moment and at the end of the queue, the next trigger moment of the extended channel is immediately inserted into the time queue, with channels with shorter periods being given higher insertion priority. If the next trigger moment is later than the current broadcast moment and is not at the end of the queue, each trigger moment of the execution time queue is broadcast to multiple comparators in chronological order. The time queue manager immediately broadcasts the next trigger moment just inserted into the time queue, and then each comparator continues to compare the next trigger moment of the corresponding channel with the current broadcast moment. If each extended channel has a fixed trigger period with a significant difference in length, only a single comparator can be used. After the channel with a short trigger period is inserted, the single comparator compares the next trigger moment of the channel with a longer trigger period with the current broadcast moment of the time queue in the order of trigger period length to insert the next trigger moment of the channel with the longer trigger period.
[0108] In this embodiment, a time queue manager is used, so that each GPIO pin can realize PWM output and input capture functions, and the time queue manager can realize simultaneous insertion and triggering to prevent congestion.
[0109] refer to Figure 6 As shown, the time queue manager of the embodiment of the present application performs the following steps:
[0110] In step S61, an initial triggering moment is provided to start the multi-channel comparator, and then step S62 is executed.
[0111] In this embodiment, the data controller refreshes the next triggering moment and starts the comparator corresponding to the channel in the multi-channel comparator.
[0112] Step S62: Receive the current time broadcast by the high-precision timer, and then execute step S63.
[0113] In this embodiment, the multi-channel comparator receives the current time broadcast by the high-precision timer and compares it with 1-2 trigger times simultaneously.
[0114] Step S63, compare the current broadcast time and the next trigger time, then execute step S64.
[0115] In this embodiment, when the current broadcast time and the next trigger time are equal, the multi-channel comparator generates a trigger signal for the corresponding channel.
[0116] In step S64, a trigger signal of a corresponding channel is generated, and then step S65 is executed.
[0117] In step S65, the data controller updates the next triggering time, and then executes step S62.
[0118] In this embodiment, the next triggering moment of the channel is calculated at a certain moment after the triggering, and the process jumps to step S61 to refresh the next triggering moment of the corresponding channel.
[0119] In this embodiment, the multi-channel comparator can select a low-precision timer with automatic wraparound as input. In this case, there is no need to regularly refresh the next trigger moment, and the multi-channel comparator compares 1-2 trigger moments in sequence.
[0120] It should be noted that in this embodiment, users can expand multiple virtual timers on a timer IP core. From the user's perspective, each timer is independent and can be used simultaneously; the configuration and status of each virtual timer are concentrated in SRAM, and when a virtual channel is switched, the configuration and status are switched at the same time; in this embodiment, the high-speed sorting and insertion function of each trigger moment is realized through the time queue manager; in this embodiment, a group of multi-channel comparators are used to trigger the virtual channel input and output function, and the data controller periodically refreshes the next trigger moment of each channel comparator to avoid time queue congestion.
[0121] This embodiment also provides an expansion device for a virtual timer, which is used to implement the above-mentioned embodiments and preferred embodiments. Details that have already been described will not be repeated. The terms "module," "unit," "subunit," etc. used below may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0122] Figure 7This is a structural block diagram of a virtual timer expansion device provided in an embodiment of the present application, such as Figure 7 As shown, an embodiment of the present application provides an expansion device for a virtual timer, the device comprising:
[0123] An acquisition module 71 is configured to acquire channel parameters corresponding to a plurality of preset extended channels, wherein the channel parameters include a channel state, channel data, and a corresponding channel triggering time of each extended channel;
[0124] The selection module 72 is coupled to the acquisition module 71 and is configured to select a target virtual channel from a plurality of extended channels according to the channel status, wherein each extended channel is associated with a virtual timer, and the virtual timer is configured to process a preset user configuration;
[0125] The processing module 73 is coupled to the selection module 72 and is used to switch the parameters of the target virtual channel based on the channel data and channel status corresponding to the target virtual channel at the channel triggering moment corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration.
[0126] Through the expansion device of the virtual timer of the embodiment of the present application, channel parameters corresponding to multiple preset extension channels are obtained, wherein the channel parameters include the channel status, channel data and corresponding channel trigger time of each extension channel; according to the channel status, a target virtual channel is selected from the multiple extension channels, wherein each extension channel is associated with a virtual timer, and the virtual timer is used to process the preset user configuration; at the channel trigger time corresponding to the target virtual channel, the parameters of the target virtual channel are switched based on the channel data and channel status corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration, thereby solving the problem of using an IP core corresponding to each timer configuration in the related art, increasing the chip area, wasting resources and increasing design costs, and realizing the beneficial effect of expanding the number of timers according to application needs, facilitating the processing of real-time control programs, reducing the number of timer IP cores, and saving chip area.
[0127] In some embodiments, the selection module 72 further includes:
[0128] The first determining unit is configured to determine a buffer unit corresponding to each extended channel according to attribute information of each extended channel, wherein the attribute information is used to characterize a channel category corresponding to the extended channel, and the buffer unit includes one of an output buffer and an input buffer.
[0129] The first judging unit is coupled to the first determining unit and is configured to judge whether the corresponding buffer unit is empty according to the channel status, and determine whether the corresponding extended channel is valid according to the judgment result.
[0130] The first selection unit is coupled to the first judgment unit and is used to select a target virtual channel from the valid extended channels according to a preset condition, wherein the preset condition includes one of the following: a fixed channel selection order and a channel priority order.
[0131] In some embodiments, the first determining unit is further configured to determine the buffer unit as an input buffer when the attribute information indicates that the extended channel is an input channel, or to determine the buffer unit as an output buffer when the attribute information indicates that the extended channel is an output channel.
[0132] In some embodiments, the first judgment unit is further used to judge whether the input buffer is non-empty when the buffer unit is an input buffer, and determine the corresponding extended channel as a valid input channel if it is judged that the input buffer is not empty; or, when the buffer unit is an output buffer, judge whether the output buffer is empty, and determine the corresponding extended channel as a valid output channel if it is judged that the output buffer is empty.
[0133] In some embodiments, the target virtual channel is a valid input channel, and the configuration module 73 is further used to capture the first level value of the pin corresponding to the valid input channel at the corresponding channel trigger moment, and store the first level value in the input buffer and write it into the preset data SRAM.
[0134] In some embodiments, the target virtual channel is a valid output channel, and the configuration module 73 is further used to set the pin level corresponding to the valid output channel based on the pre-stored second level value read from the output buffer at the corresponding channel trigger moment, wherein the second level value is pre-written at the previous channel trigger moment corresponding to the valid output channel.
[0135] In some embodiments, the expansion device of the virtual timer also includes a time queue management module, which is further used to broadcast the preset next trigger moment in the preset time queue to the comparison unit associated with each extension channel in a set time sequence before obtaining the channel configuration parameters corresponding to the preset multiple extension channels, and determine the current position of the next trigger moment in the time queue, wherein the next trigger moment is used to represent the trigger configuration point of the corresponding extension channel after the current broadcast moment, and the comparison unit includes one of the following: a single-channel comparator, a channel of a multi-channel comparator; obtain the judgment result of each comparison unit whether the next trigger moment corresponding to the extension channel associated with itself is later than the current broadcast moment; based on the judgment result and the current position, determine whether to insert the next trigger moment corresponding to the extension channel into the preset time queue, and use the next trigger moment inserted into the time queue as the channel trigger moment of the corresponding extension channel.
[0136] In some embodiments, the time queue management module is also used to insert the current corresponding next trigger moment into the time queue when the judgment result is that the corresponding next trigger moment is in the target state, wherein the target state includes one of the following states: the next trigger moment is not later than the current broadcast moment and the current position is at the head of the time queue, the next trigger moment is not later than the current broadcast moment and later than the previous broadcast moment, and the next trigger moment is later than the previous broadcast moment and the corresponding current position is at the end of the time queue.
[0137] In some embodiments, after the current corresponding next trigger moment is inserted into the time queue, the expansion device of the virtual timer is also used to use the next trigger moment currently inserted into the time queue as the broadcast starting point, and broadcast the next trigger moment in the time queue to the comparison unit associated with each extension channel according to the set time sequence.
[0138] Figure 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application. Figure 8 As shown, an embodiment of the present application provides an electronic device, including a processor 81, a communication interface 82, a memory 83 and a communication bus 84, wherein the processor 81, the communication interface 82, and the memory 83 communicate with each other through the communication bus 84.
[0139] Memory 83, for storing computer programs;
[0140] Processor 81 is used to execute the program stored in memory 83 to achieve Figure 1 The method steps in .
[0141] The processing in the electronic device is implemented Figure 1 The technical effects of the method steps in the above embodiment are the same as those of the above embodiment. Figure 1 The technical effect of the virtual timer extension method in is consistent and will not be repeated here.
[0142] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0143] The communication interface is used for communication between the electronic device and other equipment.
[0144] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0145] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0146] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the virtual timer extension method provided in any of the aforementioned method embodiments are implemented.
[0147] In another embodiment provided by the present application, a computer program product including instructions is further provided, which, when executed on a computer, enables the computer to execute the steps of the virtual timer extension method described in any one of the above embodiments.
[0148] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive and also include other elements not explicitly listed, or also include elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including a..." do not exclude the presence of other identical elements in the process, method, article or device that includes the elements.
[0149] The foregoing description is intended only to provide specific embodiments of the present invention, which will enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not intended to be limited to the embodiments shown herein, but is intended to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for extending a virtual timer, applied to a hardware timer, characterized in that: The extension method includes: Acquire channel parameters corresponding to a plurality of preset extended channels, wherein the channel parameters include a channel state, channel data, and a corresponding channel triggering time of each of the extended channels; selecting a target virtual channel from the plurality of extended channels according to the channel status, wherein each extended channel is associated with a virtual timer, and the virtual timer is used to process a preset user configuration; At the channel triggering moment corresponding to the target virtual channel, parameters of the target virtual channel are switched based on the channel data and the channel status corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration.
2. The method according to claim 1, characterized in that Selecting a target virtual channel from the plurality of extended channels according to the channel status includes: Determining a buffer unit corresponding to each of the extended channels according to attribute information of each of the extended channels, wherein the attribute information is used to characterize the channel category corresponding to the extended channel, and the buffer unit includes one of an output buffer and an input buffer; According to the channel status, determining whether the corresponding buffer unit is empty, and according to the determination result, determining whether the corresponding extended channel is valid; The target virtual channel is selected from the valid extended channels according to a preset condition, wherein the preset condition includes one of the following: a fixed channel selection order and a channel priority order.
3. The method according to claim 2, characterized in that Determining, according to the attribute information of each of the extended channels, a buffer unit corresponding to each of the extended channels, including: In the case where the attribute information indicates that the extended channel is an input channel, determining that the buffer unit is an input buffer, or, When the attribute information indicates that the extended channel is an output channel, the buffer unit is determined to be an output buffer.
4. The method according to claim 3, characterized in that Judging whether the corresponding buffer unit is empty according to the channel state, and determining whether the corresponding extended channel is valid according to the judgment result, including: When the buffer unit is an input buffer, determining whether the input buffer is not empty, and if it is determined that the input buffer is not empty, determining the corresponding extended channel as a valid input channel; or, When the buffer unit is an output buffer, it is determined whether the output buffer is empty, and if it is determined that the output buffer is empty, the corresponding extended channel is determined to be a valid output channel.
5. The method according to claim 4, characterized in that The target virtual channel is a valid input channel. At the channel trigger moment corresponding to the target virtual channel, parameters of the target virtual channel are switched based on the channel data and the channel status corresponding to the target virtual channel, including: at the corresponding channel trigger moment, capturing a first level value of a pin corresponding to the valid input channel, storing the first level value in the input buffer, and writing the first level value into a preset data SRAM.
6. The method according to claim 4, characterized in that The target virtual channel is a valid output channel. At the channel trigger moment corresponding to the target virtual channel, parameters of the target virtual channel are switched based on the channel data and the channel status corresponding to the target virtual channel, including: at the corresponding channel trigger moment, based on reading a pre-stored second level value from the output buffer, setting the pin level corresponding to the valid output channel, wherein the second level value is pre-written at the previous channel trigger moment corresponding to the valid output channel.
7. The method according to claim 1, characterized in that Before obtaining the channel parameters corresponding to the preset multiple extended channels, the method further includes: Broadcasting a preset next trigger moment in a preset time queue to a comparison unit associated with each of the extension channels in a set time sequence, and determining a current position of the next trigger moment in the time queue, wherein the next trigger moment is used to represent a trigger configuration point of the corresponding extension channel after the current broadcast moment, and the comparison unit includes one of the following: a single-channel comparator, or a channel of a multi-channel comparator; Obtaining a judgment result of each comparison unit on whether the next triggering time corresponding to the extension channel associated with itself is later than the current broadcasting time; Based on the judgment result and the current position, determine whether to insert the next trigger moment corresponding to the extended channel into a preset time queue, and use the next trigger moment inserted into the time queue as the channel trigger moment of the corresponding extended channel.
8. The method according to claim 7, characterized in that Determining whether to insert the next triggering moment corresponding to the extended channel into a preset time queue based on the judgment result and the current position includes: When the judgment result is that the corresponding next trigger moment is in the target state, the current corresponding next trigger moment is inserted into the time queue, wherein the target state includes one of the following states: the next trigger moment is not later than the current broadcast moment and the current position is at the head of the time queue, the next trigger moment is not later than the current broadcast moment and later than the previous broadcast moment, the next trigger moment is later than the previous broadcast moment and the corresponding current position is at the end of the time queue.
9. The method according to claim 8, characterized in that After inserting the current corresponding next trigger moment into the time queue, the method further includes: Taking the next trigger moment currently inserted into the time queue as the broadcast starting point, the next trigger moment in the time queue is broadcast to the comparison unit associated with each extension channel in a set time sequence.
10. A virtual timer expansion device, applied to a hardware timer, characterized in that: include: An acquisition module, configured to acquire channel parameters corresponding to a plurality of preset extended channels, wherein the channel parameters include a channel state, channel data, and a corresponding channel triggering time of each of the extended channels; a selection module, configured to select a target virtual channel from the plurality of extended channels according to the channel status, wherein each extended channel is associated with a virtual timer, and the virtual timer is configured to process a preset user configuration; A processing module is used to switch parameters of the target virtual channel based on the channel data and the channel status corresponding to the target virtual channel at the channel triggering moment corresponding to the target virtual channel, so that the virtual timer corresponding to the target virtual channel processes the corresponding user configuration.
11. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; The processor is configured to implement the steps of the virtual timer extension method according to any one of claims 1 to 9 when executing a program stored in the memory.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the virtual timer extension method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Scheduling execution method and device based on multi-thread task and medium
CN111813552A
Timing method and equipment of virtual timer
CN112463125A