Method and device for analog-to-digital converter (ADC) analog general purpose input / output (GPIO) interruption of acquisition terminal and medium

By initializing the character device driver module at the driver layer of the embedded system, the ADC simulated GPIO interrupt method is implemented, which solves the problem of insufficient GPIO caused by limited MCU pin resources, and improves system efficiency and real-timeness.

CN120233932APending Publication Date: 2025-07-01QINGDAO ITECHENE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510316552.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-18
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

In embedded system design, MCU pin resources are limited, resulting in insufficient GPIO. The existing technology responds to voltage changes by detecting ADC values ​​in real time cycles, resulting in large CPU resource usage, reduced system efficiency and increased power consumption.

Method used

By initializing the character device driver module at the driver layer, providing an interface for the application layer, ADC simulates GPIO interrupt method is implemented. The specific steps include initializing the character device driver module, obtaining the current ADC value and comparing the preset trigger threshold, generating a trigger event notification if the trigger condition is met, and sending the event notification to the application layer through a waiting queue.

Benefits of technology

The problem of insufficient GPIO is solved. Through the ADC simulation of GPIO interrupt mechanism, ADC changes can generate events like GPIO interrupts, reducing CPU resource expenditure, and improving system efficiency and real-time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120233932A_ABST
    Figure CN120233932A_ABST
Patent Text Reader

Abstract

The invention provides a method and a device for simulating GPIO (General Purpose Input / Output) interruption by an ADC (Analog to Digital Converter) of an acquisition terminal and a medium, and the method comprises the following steps: initializing a character equipment driving module, and providing an interface for an application layer; a current ADC value is obtained, the current ADC value is compared with a preset trigger threshold value, and the trigger threshold value is an ADC threshold value set by an application layer; if the current ADC value meets the trigger condition, generating a trigger event notification, waking up the waiting queue and sending the trigger event notification to an application layer; and the application layer detects the trigger event notification through the interface, and executes a corresponding task if the trigger event notification is detected. According to the invention, the ADC simulates the GPIO interrupt for use, the situation that the GPIO is not enough is solved, and the change of the ADC can generate an event like the GPIO interrupt by setting the threshold value of the ADC and simulating a GPIO interrupt mechanism; the interrupt events of the ADC are queued through the work queue and are processed in the background thread, so that the real-time performance of interrupt response is ensured, and the CPU resource expenditure caused by real-time circular detection of the ADC is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of communication detection, and particularly relates to an ADC analog GPIO interruption method, device and medium for a collection terminal. Background Art

[0002] In the design of embedded systems, especially when using collection terminals such as concentrators, the problem of limited MCU pin resources is very common. When multiple functions need to be implemented, pin conflicts or insufficient quantities often occur. In the prior art, GPIO interruption pins are usually used to detect voltage states, but there may be situations where GPIO pins are occupied by other functions or the quantity is insufficient. At this time, it is necessary to consider using ADC function pins as an alternative solution. However, ADC detection requires a quick response to voltage changes, and the traditional method has obvious defects: if the method of continuously detecting ADC values in real-time is adopted, the CPU needs to continuously run to monitor voltage changes, which not only greatly increases the CPU resource occupancy, but also reduces the overall efficiency of the system, resulting in interference with the execution of other tasks and increasing unnecessary power consumption. Summary of the Invention

[0003] To solve the problems existing in the above prior art, the present invention provides an ADC analog GPIO interruption method for a collection terminal, including the following steps: Step S1, initialize the character device driver module to provide an interface for the application layer; Step S2, obtain the current ADC value and compare the current ADC value with a preset trigger threshold, where the trigger threshold is the ADC threshold set by the application layer; Step S3, if the current ADC value meets the trigger condition, generate a trigger event notification, wake up the wait queue and send the trigger event notification to the application layer; Step S4, the application layer detects the trigger event notification through the interface, and if detected, executes corresponding tasks.

[0004] On the basis of the above solution, the initialization in step S1 specifically includes: Assign a unique identifier to the character device, initialize the character device structure body, create a new device class and an actual device file node, and provide a file operation interface for the application layer; Initialize the wait queue, and the wait queue supports the poll mechanism; Create a single-threaded work queue for processing ADC reading tasks; Initialize and schedule delayed work for periodically reading ADC values.

[0005] Based on the above solution, the application layer transmits threshold parameters to the driver layer through a standard file operation interface. The threshold parameters include the number of triggers and the trigger threshold. The number of triggers corresponds to the same number of trigger thresholds. The driver layer receives and saves the threshold parameters for comparison with the acquired ADC values.

[0006] Based on the above solution, the application layer uses the poll mechanism to cyclically detect trigger events of the driver layer and execute corresponding tasks when the trigger event notification is detected.

[0007] Based on the above solution, the trigger condition is as follows: if the current ADC value is greater than the trigger threshold, a rising edge event is triggered and the trigger state is set to the rising edge; if the current ADC value is less than or equal to the trigger threshold, a falling edge event is triggered and the trigger state is set to the falling edge; after generating a trigger event notification, the trigger state is changed.

[0008] The present invention also provides a device for simulating GPIO interrupts using an ADC, including: An initialization module for initializing a character device driver module to provide an interface for the application layer; A processing module including an acquisition unit and a comparison unit. The acquisition unit acquires the current ADC value and sends the current ADC value to the comparison unit. The comparison unit compares the current ADC value with a preset trigger threshold, and the trigger threshold is the ADC threshold set by the application layer; A sending module. If the current ADC value meets the trigger condition, the sending module generates a trigger event notification, wakes up the wait queue, and sends the trigger event notification to the application layer.

[0009] A detection module. The application layer detects the trigger event notification through the interface and executes corresponding tasks when detected.

[0010] Based on the above solution, the sending module further includes a rising edge trigger unit and a falling edge trigger unit. The rising edge trigger unit is used to trigger a rising edge event, and the rising edge event is that the current ADC value is greater than the trigger threshold; the falling edge trigger unit, and the falling edge event is that the current ADC value is less than or equal to the trigger threshold.

[0011] The present invention provides a collection terminal for simulating GPIO interrupts using an ADC, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor is used to implement the steps of the method for simulating GPIO interrupts using an ADC for a collection terminal as described above when executing the computer program.

[0012] The present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of an ADC analog GPIO interruption method for a collection terminal as described above are implemented.

[0013] Compared with the prior art, the present invention has the following beneficial effects: 1. By using ADC analog GPIO interruption, the situation of insufficient GPIO is solved. And by setting the threshold of the ADC and simulating the GPIO interruption mechanism, events can be generated when the ADC changes, just like GPIO interruption. 2. A work queue (kwork) is used to process the ADC interruption tasks, avoiding time-consuming operations during interruption handling. The ADC interruption events are queued through the work queue and processed in a background thread, ensuring the real-time nature of interruption response and reducing the CPU resource consumption caused by continuously detecting the ADC in a real-time loop. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 It is a schematic diagram of module interaction of this application; Figure 2 It is a flowchart of initialization of the driver module of this application; Figure 3 It is a flowchart of cleaning of the driver module of this application; Figure 4 It is a flowchart of the event triggering process of this application; Figure 5 It is a flowchart of the processing steps of the application layer of this application. DETAILED DESCRIPTION OF THE INVENTION Traditional designs are usually directly carried out at the application layer, and the voltage change is responded to by continuously detecting the ADC value in a real-time loop. This method not only increases the CPU resource occupancy but also reduces the overall efficiency of the system. Different from this, the present invention initializes a character device driver module in the driver layer and provides an interface for the application layer, realizing a more efficient event triggering mechanism.

[0015] The present invention will be further described below with specific embodiments.

[0016] The present invention provides an ADC analog GPIO interruption method for a collection terminal. The method is used for the interaction between the driver layer and the application layer. As Figure 1 shown, first, the driver module is initialized in the driver layer. The driver module is established based on a character device, and the character device is a device for direct access without buffering. Specifically, the driver module includes an initialization module, a data processing module, and a cleaning module. As Figure 2 shown, the initialization module specifically includes: First, allocate a unique identifier for the character device. This identifier is used to register the device and interact with the application layer, providing an access entry for the application layer. Then, initialize the character device structure, associate the file operation structure with this character device, and register the character device into the kernel. The application layer can interact with the device through the standard file operation interface. To better organize related devices and facilitate the application layer to search for and use devices, create a new device class. The device class groups and manages related devices and creates symbolic links to simplify the access path of the application layer to the devices. At the same time, create actual device file nodes to provide a file operation interface for the application layer. That is, the device file node is the access entry for the application layer to the device, enabling the application layer to interact with the driver layer through the standard file system interface.

[0017] To further enhance the driver function, the initialization step further includes initializing a wait queue, allowing the application layer to efficiently wait for events to occur and avoiding the waste of CPU resources caused by implementing polling.

[0018] Preferably, the wait queue supports the poll mechanism. The poll mechanism does not frequently query the device status, but instead uses the kernel's notification mechanism to inform the user space program whether an event has occurred. This method not only improves efficiency but also reduces the CPU occupancy rate.

[0019] The initialization module of this application further includes creating a kwork work queue, specifically including a single-threaded work queue and delayed work. The single-threaded work queue is used to process ADC data acquisition tasks, and the initialized delayed work is used to periodically execute ADC data acquisition tasks. By setting the delayed work, the execution interval of the task can be adjusted as needed.

[0020] The data processing module is the core of the driver module and depends on the initialization module. After the initialization module creates a single-threaded work queue and initializes the delayed work, it starts to periodically execute ADC reading tasks. As Figure 3 shown, each time the delayed work is executed, the current ADC value is obtained, and the current ADC value is compared with a preset trigger threshold to determine whether the trigger condition is met. The trigger threshold is set by the application layer interacting with the driver layer through the file operation interface.

[0021] This application uses the kwork work queue to implement the periodic execution of ADC reading tasks, greatly reducing the CPU resource expenditure when polling to obtain the adc value. At the same time, the ADC data reading task is moved to the background thread for execution, thus avoiding blocking the main process. And the execution interval of the task can be dynamically adjusted as needed, enhancing the flexibility of the method.

[0022] If the trigger condition is satisfied, a trigger event notification is generated. The trigger condition is the magnitude relationship between the current ADC value and the trigger threshold. If the current ADC value is greater than the trigger threshold, a rising-edge event is triggered; if the current ADC value is less than or equal to the trigger threshold, a falling-edge event is triggered. It should be noted that if the current value satisfies the trigger for the rising edge or falling edge, the event will be continuously triggered. Therefore, a trigger state is added. When the trigger for the rising edge is satisfied, the trigger state is set to the rising edge. When the trigger for the falling edge is satisfied, the trigger state is set to the falling edge. After the trigger event is processed, the trigger state is updated so that the event is only triggered once when the trigger condition is satisfied.

[0023] According to the present application, when judging the trigger condition, the present application introduces a state variable (trigger state), and by changing the value of the state variable after triggering, state locking is achieved, thereby avoiding repeated triggering.

[0024] According to one embodiment of the present application, if the currently read ADC value is greater than the set trigger threshold, a rising edge is triggered, and the current trigger state is set to the rising edge. After sending the trigger event notification, the state variable is changed to the falling edge, so that the trigger event notification will not be sent repeatedly.

[0025] After generating the trigger event notification, the trigger event notification is sent to the application layer through the wait queue.

[0026] Specifically, after the driver layer detects an event that satisfies the trigger condition, it marks the event as having occurred by updating the status of the file descriptor, and at the same time wakes up the sleeping application layer process in the wait queue. The awakened process can detect the occurrence of the event through the standard file operation interface and further process the event as needed.

[0027] As Figure 5 shown, the application layer detects the trigger event of the driver layer through the standard file operation interface and executes the corresponding task when the trigger event notification is detected.

[0028] The traditional application layer continuously polls the ADC value in real time, resulting in a continuously high CPU load and increasing system power consumption.

[0029] Preferably, the application layer of the present application uses the poll mechanism to monitor event notifications, responds to trigger events in a timely manner, wakes up the process only when the event occurs, avoids the CPU idling in real-time polling, and using the poll mechanism can avoid frequently polling the device status, significantly reducing the CPU occupancy rate, and at the same time having strong real-time performance. In addition, the present application can also use the select mechanism to monitor time notifications.

[0030] In order to release resources and ensure system stability, the driver module further includes a cleaning module, as Figure 4As shown, the cleaning module can cancel the delayed work that has not been executed and wait for the work currently being executed to complete, ensuring that all tasks can end safely; delete the device file nodes and device classes to release relevant resources; unregister the character device to release the resources occupied by the character device. The cleaning module can comprehensively release the resources occupied during the operation of the driver, ensuring that the device still operates stably after cleaning.

[0031] It should be noted that the interrupt handling of the ADC can also combine the characteristics of signals (such as slope detection, window comparison, etc.) to implement more complex logic and event triggering.

[0032] According to a specific embodiment of the present invention, the function of the ADC pin on the main control is used to detect whether the strong power is powered off. Each time the delayed work is executed, the current power supply voltage value is obtained and compared with a preset voltage threshold; when it is detected that the power supply voltage is lower than the voltage threshold, the driver layer generates a power-off event notification. After the application layer detects this event through the file operation interface, it executes the corresponding power-off processing logic to ensure a quick response when the power supply is cut off.

[0033] In a power monitoring system, the voltage status of multiple power supplies can also be detected simultaneously by expanding the ADC branches to improve the monitoring ability of the system. The specific steps are as follows: Expand the ADC channels: Use multiple ADC channels on the MCU and connect them to different power lines respectively. Each ADC channel corresponds to an independent power supply. For example, use the ADC0 channel of the MCU to connect to the main power supply and the ADC1 channel to connect to the backup power supply; Initialize the character device driver module: Assign a unique identifier to each ADC channel and initialize the corresponding character device structure. Create a new device class and actual device file nodes so that the application layer can access these device nodes through the standard file operation interface.

[0034] Configure the threshold parameters: Configure independent trigger thresholds for each ADC channel. For example, the trigger threshold for the main power supply is set to 23V (abnormal when lower than 24V), and the trigger threshold for the backup power supply is set to 11V (abnormal when lower than 12V).

[0035] Transfer the threshold parameters: The application layer transfers these threshold parameters to the driver layer through the standard file operation interface. The driver layer receives and saves these threshold parameters for subsequent comparison with the obtained ADC values.

[0036] Periodically read the ADC values: The driver layer creates a single-threaded work queue and delayed work for periodically executing the ADC data acquisition task. Each time the delayed work is executed, the current ADC values are obtained and compared with the preset trigger thresholds.

[0037] Generate trigger event notifications: If the ADC value of a certain power supply is lower than its corresponding trigger threshold, generate corresponding trigger event notifications. For example, if the main power supply voltage is lower than 23V, generate a "main power supply power failure" event notification; if the backup power supply voltage is lower than 11V, generate a "backup power supply power failure" event notification.

[0038] Status locking mechanism: To avoid repeated triggers, introduce a status variable (trigger status). When the trigger condition is met, update this status variable and reset the status after processing the trigger event to ensure that each event is triggered only once.

[0039] Wait queue and poll mechanism: The driver layer marks that an event has occurred by updating the status of the file descriptor and wakes up the application layer process in the wait queue. The application layer uses the poll mechanism to listen for event notifications and responds to trigger events in a timely manner.

[0040] Priority processing: After the application layer receives all trigger event notifications, it processes the abnormal conditions of different power supplies in sequence according to the preset priorities. For example, the priority of the main power supply abnormality is higher than that of the backup power supply abnormality, and the main power supply problem is processed first.

[0041] The present invention also provides a device for simulating GPIO interrupts using ADC, which can be used to execute the steps performed by the acquisition terminal provided in the above method embodiment, and this function can be implemented by software or hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions.

[0042] Specifically include: Initialization module, the initialization module is used to initialize the character device driver module and provide an interface for the application layer; Processing module, the processing module includes an acquisition unit and a comparison unit. The acquisition unit acquires the current ADC value and sends the current ADC value to the comparison unit. The comparison unit compares the current ADC value with a preset trigger threshold, and the trigger threshold is the ADC threshold set by the application layer; Sending module, if the current ADC value meets the trigger condition, the sending module generates a trigger event notification, wakes up the wait queue, and sends the trigger event notification to the application layer.

[0043] Detection module, the application layer detects the trigger event notification through the interface, and executes corresponding tasks when detected.

[0044] The sending module further includes a rising-edge trigger unit and a falling-edge trigger unit. The rising-edge trigger unit is used to trigger a rising-edge event, where the rising-edge event is that the current ADC value is greater than the trigger threshold; the falling-edge trigger unit, and the falling-edge event is that the current ADC value is less than or equal to the trigger threshold. Both the rising-edge trigger unit and the falling-edge trigger unit can generate trigger event notifications.

[0045] Based on the same technical concept, the present invention also provides an acquisition terminal that uses an ADC to simulate GPIO interrupts, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. It is characterized in that when the processor executes the computer program, it implements the steps of the above-mentioned method for an acquisition terminal to simulate GPIO interrupts using an ADC.

[0046] Among them, the memory is connected to the processor. The memory may include one or more computer-readable storage media, and the computer-readable storage media may be non-transitory. The memory may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash storage devices. The processor may include one or more processors, and the processor may be implemented in at least one hardware form of a digital signal processor, a field programmable gate array, or a programmable logic array. The processor may also include a main processor and a coprocessor. The main processor is a processor used to process data in the wake state, also known as the central processing unit; the coprocessor is a low-power processor used to process data in the standby state.

[0047] The present invention also provides a computer-readable storage medium with a computer program, and when the computer program is executed by a processor, it implements the steps of the above-mentioned method for an acquisition terminal to simulate GPIO interrupts using an ADC.

[0048] The above are only the preferred embodiments of the present application and are not used to limit the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

[0049] Although the specific implementation manners of the present invention are described above, it is not a limitation to the protection scope of the present invention. Those skilled in the art should understand that based on the technical solution of the present invention, various modifications or deformations that can be made without creative labor by those skilled in the art are still within the protection scope of the present invention.

Claims

1. A method for simulating GPIO interruption of an ADC of an acquisition terminal, characterized in that: The following steps are involved: Step S1, initializing the character device driver module to provide an interface for the application layer; Step S2, obtaining a current ADC value, and comparing the current ADC value with a preset trigger threshold, where the trigger threshold is an ADC threshold set by the application layer; Step S3, if the current ADC value meets the trigger condition, a trigger event notification is generated, the waiting queue is awakened and the trigger event notification is sent to the application layer; Step S4, the application layer detects the trigger event notification through the interface, and executes a corresponding task if detected.

2. The ADC simulation GPIO interrupt method for an acquisition terminal according to claim 1, characterized in that: The initialization in step S1 specifically includes: Assign a unique identifier to the character device, initialize the character device structure, create a new device class and the actual device file node, and provide a file operation interface for the application layer; Initialize the waiting queue, which supports the poll mechanism; Create a single-threaded work queue to process ADC reading tasks; Initialize delay operation and schedule to periodically read ADC values.

3. The ADC simulation GPIO interrupt method for an acquisition terminal according to claim 1, characterized in that: The application layer transmits threshold parameters to the driver layer through a standard file operation interface. The threshold parameters include trigger times and trigger thresholds. The trigger times correspond to the same number of trigger thresholds. The driver layer receives and saves the threshold parameters for comparison with the acquired ADC values.

4. The ADC simulation GPIO interrupt method for an acquisition terminal according to claim 1, characterized in that: The application layer uses the poll mechanism to cyclically detect the triggering events of the driver layer, and executes corresponding tasks when the triggering event notification is detected.

5. The ADC simulation GPIO interrupt method for an acquisition terminal according to claim 1, characterized in that: The trigger condition is: if the current ADC value is greater than the trigger threshold, a rising edge event is triggered and the trigger state is set to a rising edge; if the current ADC value is less than or equal to the trigger threshold, a falling edge event is triggered and the trigger state is set to a falling edge; After the trigger event notification is generated, the trigger state is changed.

6. A device for simulating GPIO interrupt using ADC, characterized in that: include: An initialization module, which is used to initialize the character device driver module and provide an interface for the application layer; A processing module, wherein the processing module includes an acquisition unit and a comparison unit, wherein the acquisition unit acquires a current ADC value and sends the current ADC value to the comparison unit, and the comparison unit compares the current ADC value with a preset trigger threshold, wherein the trigger threshold is an ADC threshold set by the application layer; The sending module generates a trigger event notification if the current ADC value meets the trigger condition, wakes up the waiting queue, and sends the trigger event notification to the application layer. The detection module is used for the application layer to detect the trigger event notification through the interface and execute the corresponding task if the trigger event notification is detected.

7. The device for simulating GPIO interruption using ADC according to claim 6, characterized in that: The sending module also includes a rising edge trigger unit and a falling edge trigger unit. The rising edge trigger unit is used to trigger a rising edge event, and the rising edge event is that the current ADC value is greater than the trigger threshold; the falling edge trigger unit, the falling edge event is that the current ADC value is less than or equal to the trigger threshold.

8. A collection terminal using ADC to simulate GPIO interruption, comprising: A memory, a processor, and a computer program in the memory and executable on the processor, wherein the processor is configured to implement the steps of the method according to any one of claims 1 to 5 when executing the computer program.

9. A computer-readable storage medium, the computer-readable storage medium having a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.