CAN (Controller Area Network) data receiving and transmitting method, device, equipment and storage medium

By using the method of interrupt triggering reception of CAN data in the driver, the problem of time-consuming realization of CAN data in the upper layer application in the prior art is solved, and the efficient reception and transmission of CAN data in the driver is realized, which is suitable for systems with high bus utilization.

CN119696950APending Publication Date: 2025-03-25CHINA ORDNANCE EQUIP GRP AUTOMATION RES INST CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411673590.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

In the prior art, it is usually implemented in upper-level applications, which consumes a lot of time and is difficult to achieve efficient CAN data transmission and reception in the driver.

Method used

By using the method of interrupt triggering the reception of CAN data in the driver, the CAN data reception interrupt function is added, and the interrupt status of the CAN controller is queried through the FPGA device when the interrupt is received, the reception thread is turned on, and the CAN data is read and stored in the memory space. At the same time, a CAN character device is created for the upper layer application to read, write and send CAN data.

Benefits of technology

It realizes efficient reception of CAN data in the driver, and enables upper-layer applications to read received CAN data or send CAN data through device nodes. It is suitable for systems that require high bus utilization, and sending and receiving CAN data is more stable and efficient.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119696950A_ABST
    Figure CN119696950A_ABST
Patent Text Reader

Abstract

The invention discloses a CAN data transmitting and receiving method, device and equipment and a storage medium, and relates to the technical field of electronics, the method can realize receiving of CAN data through interruption triggering under driving, the CAN data is stored in a developed memory space, an upper application can read the received CAN data or send the CAN data through an equipment node, and the CAN data can be transmitted to the storage medium through the equipment node. The method is suitable for a system requiring a high bus utilization rate. And meanwhile, the system has the advantages of more stable and more efficient CAN data receiving and transmitting and the like, and can undertake the task of requiring high bus utilization rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of electronic technology, and in particular to a CAN data transceiving method, device, equipment and storage medium applied to a driver. Background Art

[0002] CAN communication is a serial communication protocol bus for real-time applications. It uses twisted pair cables to transmit signals and is one of the most widely used field buses in the world. CAN communication was developed by Bosch in Germany for the automotive industry in the 1980s. It has attracted widespread attention for its high performance, high reliability and unique design, and has now been applied to many fields such as automobiles, industry, and medical treatment.

[0003] In the prior art, the CAN data transceiving process is usually implemented in the upper layer application, and is rarely implemented in the driver, or the implementation effect is not good.

[0004] Implementing the CAN data transmission and reception process in the upper-level application is more time-consuming than implementing it in the driver. For systems that require high bus utilization, implementing CAN transmission and reception in the driver is more in line with the requirements.

[0005] Therefore, how to provide a method for receiving CAN data in a driver is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the invention

[0006] In view of the above problems, the present invention provides a CAN data receiving and sending method, device, equipment and storage medium for overcoming the above problems or at least partially solving the above problems.

[0007] The present invention provides the following scheme:

[0008] A CAN data transceiving method, comprising:

[0009] Applied to the driver, using interrupt to trigger reception, the method includes:

[0010] Add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, call all user interrupt functions in sequence;

[0011] When the CAN data receiving interrupt function is called, the interrupt status of the CAN controller is queried through the FPGA device, and if it is determined that there is a CAN data interrupt, the receiving thread is started, and the CAN data is read and stored in the memory space;

[0012] A CAN character device is created during loading so that upper layer applications can read, write and send CAN data by controlling the CAN character device.

[0013] Preferably: if it is determined that there is a CAN data interrupt, the receiving flag is turned on, the receiving thread reads the data in the CAN controller receiving first-in first-out queue into the memory space, and clears the interrupt.

[0014] Preferably: the step of creating a CAN character device includes:

[0015] Add the initialization function of the CAN character device in the driver entry function probe_one to obtain the device number and open up space for storing the information of the CAN character device;

[0016] Create a corresponding number of the CAN character devices according to the required number of devices and assign device numbers to them.

[0017] Preferably: a determined Open function is used to allocate space for CAN data reception and create a receiving thread.

[0018] Preferably: using a determined ioctl function to receive the control of the upper layer application on the CAN character device, adding a CAN data reading instruction and a CAN data sending instruction, and realizing the interaction between the CAN data and the upper layer application.

[0019] A CAN data transceiver device, used to execute the above-mentioned CAN data transceiver method, the device comprising:

[0020] The interrupt function calling unit is used to add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, all user interrupt functions are called in sequence;

[0021] A CAN data reading and storage unit is used to query the interrupt status of the CAN controller through the FPGA device when calling the CAN data receiving interrupt function, and start the receiving thread when determining that there is a CAN data interrupt, and store the CAN data read in the memory space;

[0022] The CAN data reading, writing and sending unit is used to create a CAN character device when loading, so that the upper layer application can read, write and send CAN data by controlling the CAN character device.

[0023] A CAN data transceiver device, the device comprising a processor and a memory:

[0024] The memory is used to store program code and transmit the program code to the processor;

[0025] The processor is used to execute the above-mentioned CAN data receiving and sending method according to the instructions in the program code.

[0026] A computer-readable storage medium is used to store program codes, and the program codes are used to execute the above-mentioned CAN data transceiving method.

[0027] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0028] The embodiment of the present application provides a CAN data transceiving method, device, equipment and storage medium. The method can receive CAN data by triggering interrupts in the driver, and the CAN data is stored in the opened memory space. The upper layer application can read the received CAN data or send CAN data through the device node, which is suitable for use in systems that require high bus utilization. At the same time, it has the advantages of more stable and efficient CAN data transmission and reception, and can undertake tasks that require high bus utilization.

[0029] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0031] Figure 1 is a flow chart of a CAN data receiving and sending method provided by an embodiment of the present invention;

[0032] Figure 2 is a schematic diagram of a system interface provided by an embodiment of the present invention;

[0033] Figure 3 is a function diagram provided by an embodiment of the present invention;

[0034] Figure 4 is a flow chart of interrupt triggering processing provided by an embodiment of the present invention;

[0035] Figure 5 is a schematic diagram of a CAN data transceiver device provided by an embodiment of the present invention;

[0036] Figure 6 It is a schematic diagram of a CAN data transceiver device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0037] The technical scheme in the embodiment of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiment of the present invention. Obviously, the described embodiment is only a part of the embodiment of the present invention, not all of the embodiments. Based on the embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of the present invention.

[0038] See also Figure 1 , a CAN data transceiving method provided by an embodiment of the present invention is applied to a driver, such as Figure 1 As shown, the method may include:

[0039] S101: Add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, call all user interrupt functions in sequence;

[0040] S102: When the CAN data receiving interrupt function is called, the interrupt status of the CAN controller is queried through the FPGA device. If it is determined that there is a CAN data interrupt, the receiving thread is started, and the CAN data is read and stored in the memory space. In the specific implementation, if it is determined that there is a CAN data interrupt, the receiving flag is turned on, and the receiving thread reads the data in the CAN controller's first-in-first-out queue into the memory space, and clears the interrupt.

[0041] S103: Creating a CAN character device during loading so that upper layer applications can read, write and send CAN data by controlling the CAN character device.

[0042] In specific implementation, the embodiment of the present application may provide that the creation of a CAN character device includes:

[0043] Add the initialization function of the CAN character device in the driver entry function probe_one to obtain the device number and open up space for storing the information of the CAN character device;

[0044] Create a corresponding number of the CAN character devices according to the required number of devices and assign device numbers to them.

[0045] Furthermore, the determined Open function is used to allocate space for CAN data reception and create a receiving thread.

[0046] The determined ioctl function is used to receive the control of the upper layer application on the CAN character device, and a CAN data reading instruction and a CAN data sending instruction are added to realize the interaction between the CAN data and the upper layer application.

[0047] An embodiment of the present application provides a method for receiving CAN data by triggering an interrupt in a driver implementation, wherein the CAN data is stored in an opened memory space, and an upper-layer application can read the received CAN data or send CAN data through a device node.

[0048] In the specific implementation:

[0049] System composition Figure 2 As shown in the figure, for CAN data communication, add interrupt trigger reception, add CAN data reception interrupt function to user interrupt, when the driver receives the user interrupt from FPGA, call the interrupt function cyclically until the maximum number of interrupt users is reached, when calling the CAN reception interrupt function, the interrupt status of the CAN controller will be queried through FPGA, if there is an interrupt, start the reception thread, and read the CAN data and store it in the memory space. In addition, the driver will create a CAN character device when loading, and the upper-level application can read, write and send CAN data by controlling the character device.

[0050] 1. Character device creation design, such as Figure 3 shown.

[0051] Add a CAN character device initialization function in the driver entry function probe_one to obtain the device number and allocate space for storing the information of the CAN character device. Create a corresponding number of CAN character devices according to the required number of devices and assign them device numbers. In addition, write an Open function to allocate space for CAN data reception and create a receiving thread. Write an ioctl function to receive the control of the CAN character device by the upper-level application. Add CAN data read instructions and CAN data send instructions to realize the interaction between CAN data and the upper-level application.

[0052] 2. Design of interrupt receiving CAN data, such as Figure 4 shown.

[0053] Add the CAN data receiving interrupt function in the user interrupt function xdma_user_isr_register. When the FPGA triggers the user interrupt, the driver will call the CAN data receiving interrupt function to query the CAN controller interrupt status to check whether it is its own interrupt. If it is a CAN data interrupt, turn on the receiving flag bit, and the receiving thread reads the data in the CAN controller receiving fifo (first-in-first-out queue) into the memory space and clears the interrupt.

[0054] In summary, the CAN data transceiving method provided by the present application can receive CAN data by triggering interrupts in the driver implementation, and the CAN data is stored in the opened memory space. The upper-layer application can read the received CAN data or send CAN data through the device node, which is suitable for use in systems requiring high bus utilization. At the same time, it has the advantages of more stable and efficient CAN data transmission and reception, and can undertake tasks requiring high bus utilization.

[0055] See also Figure 5 The embodiment of the present application may also provide a CAN data transceiver device, such as Figure 5 As shown, for executing the above-mentioned CAN data receiving and sending method, the device may include:

[0056] The interrupt function calling unit 501 is used to add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, all user interrupt functions are called in sequence;

[0057] The CAN data reading and storing unit 502 is used to query the interrupt status of the CAN controller through the FPGA device when calling the CAN data receiving interrupt function, and start the receiving thread when determining that there is a CAN data interrupt, and store the CAN data in the memory space;

[0058] The CAN data reading, writing and sending unit 503 is used to create a CAN character device when loading, so that the upper layer application can read, write and send CAN data by controlling the character device.

[0059] The embodiment of the present application may also provide a CAN data transceiver device, the device comprising a processor and a memory:

[0060] The memory is used to store program code and transmit the program code to the processor;

[0061] The processor is used to execute the steps of the above-mentioned CAN data receiving and sending method according to the instructions in the program code.

[0062] like Figure 6 As shown, a CAN data transceiver device provided in an embodiment of the present application may include: a processor 10, a memory 11, a communication interface 12 and a communication bus 13. The processor 10, the memory 11 and the communication interface 12 all communicate with each other through the communication bus 13.

[0063] In the embodiment of the present application, the processor 10 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic devices, etc.

[0064] The processor 10 may call a program stored in the memory 11. Specifically, the processor 10 may execute operations in the embodiment of the CAN data transceiving method.

[0065] The memory 11 is used to store one or more programs, which may include program codes, and the program codes include computer operation instructions. In the embodiment of the present application, the memory 11 at least stores programs for implementing the following functions:

[0066] Add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, call all user interrupt functions in sequence;

[0067] When the CAN data receiving interrupt function is called, the interrupt status of the CAN controller is queried through the FPGA device, and if it is determined that there is a CAN data interrupt, the receiving thread is started, and the CAN data is read and stored in the memory space;

[0068] A CAN character device is created during loading so that upper layer applications can read, write and send CAN data by controlling the character device.

[0069] In one possible implementation, the memory 11 may include a program storage area and a data storage area, wherein the program storage area can store an operating system and application programs required for at least one function (such as a file creation function, a data reading and writing function), etc.; the data storage area can store data created during use, such as initialization data, etc.

[0070] In addition, the memory 11 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.

[0071] The communication interface 12 may be an interface of a communication module, and is used to connect to other devices or systems.

[0072] Of course, it should be noted that Figure 6 The structure shown does not constitute a limitation on the CAN data transceiver device in the embodiment of the present application. In actual applications, the CAN data transceiver device may include Figure 6 More or fewer components than shown, or combinations of certain components.

[0073] The embodiment of the present application may also provide a computer-readable storage medium, wherein the computer-readable storage medium is used to store program code, and the program code is used to execute the steps of the above-mentioned CAN data transceiving method.

[0074] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply 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 inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0075] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.

[0076] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0077] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A CAN data transceiving method, characterized in that: Applied to the driver, using interrupt to trigger reception, the method includes: Add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, call all user interrupt functions in sequence; When the CAN data receiving interrupt function is called, the interrupt status of the CAN controller is queried through the FPGA device, and if it is determined that there is a CAN data interrupt, the receiving thread is started, and the CAN data is read and stored in the memory space; A CAN character device is created during loading so that upper layer applications can read, write and send CAN data by controlling the CAN character device.

2. The CAN data transceiving method according to claim 1, characterized in that: If it is determined that there is a CAN data interrupt, the receive flag is turned on, and the receiving thread reads the data in the CAN controller's receive first-in-first-out queue into the memory space and clears the interrupt.

3. The CAN data transceiving method according to claim 1, characterized in that: The creation of a CAN character device comprises: Add the initialization function of the CAN character device in the driver entry function probe_one to obtain the device number and open up space for storing the information of the CAN character device; Create a corresponding number of the CAN character devices according to the required number of devices and assign device numbers to them.

4. The CAN data transceiving method according to claim 1, characterized in that: Use the determined Open function to allocate space for CAN data reception and create a receiving thread.

5. The CAN data transceiving method according to claim 1, characterized in that: The determined ioctl function is used to receive the control of the upper layer application on the CAN character device, and a CAN data reading instruction and a CAN data sending instruction are added to realize the interaction between the CAN data and the upper layer application.

6. A CAN data transceiver, characterized in that: Used to execute the CAN data receiving and sending method according to any one of claims 1 to 5, the device comprises: The interrupt function calling unit is used to add the CAN data receiving interrupt function to the user interrupt function; when receiving the user interrupt function transmitted by the FPGA device, all user interrupt functions are called in sequence; A CAN data reading and storage unit is used to query the interrupt status of the CAN controller through the FPGA device when calling the CAN data receiving interrupt function, and start the receiving thread when determining that there is a CAN data interrupt, and store the CAN data read in the memory space; The CAN data reading, writing and sending unit is used to create a CAN character device when loading, so that the upper layer application can read, write and send CAN data by controlling the CAN character device.

7. A CAN data transceiver device, characterized in that: The device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the CAN data receiving and sending method according to any one of claims 1 to 5 according to the instructions in the program code.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program codes, and the program codes are used to execute the CAN data transceiving method according to any one of claims 1 to 5.