Method for synchronous communication between same protocol stack and different peripherals

By using the global data area and RTOS mutex mechanism in the energy storage converter, the data conflict problem during simultaneous communication of multiple peripherals is solved, and efficient synchronous communication is achieved.

CN119668889APending Publication Date: 2025-03-21HEFEI HUAZHI ENERGY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In energy storage converters, when multiple peripherals use the same protocol stack to communicate at the same time, data conflicts and synchronization problems are prone to occur, and a large amount of data copying and transmission are required.

Method used

A global data area is used as the protocol stack data, allowing DSP and all peripherals to read and write protocol stack data within their respective permissions, and blocked access is achieved through the mutex mechanism in the real-time operating system (RTOS) to ensure data consistency.

Benefits of technology

It effectively avoids data conflicts caused by multiple peripherals reading and writing protocol stack data at the same time, and improves communication synchronization and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119668889A_ABST
    Figure CN119668889A_ABST
Patent Text Reader

Abstract

The invention discloses a method for synchronous communication between the same protocol stack and different peripherals, and relates to the technical field of communication. According to the method, a global data area is adopted as protocol stack data, and a DSP and all peripherals are allowed to perform read-write operation on the protocol stack data in respective permission ranges; and in order to ensure the data consistency, the read-write operation realizes blocked access through a mutual exclusion body mechanism in a real-time operating system (RTOS), when a certain peripheral performs the read-write operation, the read-write requests of other peripherals are blocked until the current peripheral finishes the operation, and the read-write request of the other peripherals is not blocked until the current peripheral finishes the operation. According to the mechanism, data conflicts caused by the fact that multiple peripherals read and write protocol stack data at the same time are effectively avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a method for synchronous communication between the same protocol stack and different peripherals. Background Art

[0002] In recent years, with the rapid development of industrial and commercial energy storage technology, the power storage converter (PCS), one of the key structures in the energy storage cabinet, has been widely used. The energy storage converter usually uses DSP for algorithm processing and fault protection, and uses a microprocessor (hereinafter referred to as MCU) for external communication, planned charge and discharge control, and fault recording. The MCU transmits the voltage and current information read from the DSP to the external device, and receives the configuration information of different peripherals and forwards it to the DSP for setting. Under this architecture, the communication board needs to process different communication requests of multiple peripherals at the same time. If the protocol stack's sending, receiving, reading and writing operations are executed separately for each peripheral, it will inevitably involve multi-device synchronization problems and a large amount of data copying and transmission.

[0003] Based on the above reasons, the present invention proposes a method for synchronous communication between the same protocol stack and different peripherals to solve the problems of the prior art. Summary of the invention

[0004] 1. Technical issues to be solved

[0005] In view of the shortcomings of the prior art, the present invention adopts a global data area as the protocol stack data, allowing the DSP and all peripherals to perform read and write operations on the protocol stack data within their respective authority ranges; and to ensure data consistency, the read and write operations are implemented in a blocking manner through the mutex mechanism in the real-time operating system (RTOS). When a peripheral is performing a read or write operation, the read and write requests of other peripherals will be blocked until the current peripheral completes the operation. This mechanism effectively avoids data conflicts caused by multiple peripherals reading and writing protocol stack data at the same time.

[0006] (II) Technical solution

[0007] To achieve the above object, the present invention provides the following technical solution: a method for synchronous communication between the same protocol stack and different peripherals, implemented based on a real-time operating system, comprising the following steps:

[0008] S1: MCU, as an intermediate device, actively obtains the real-time data of the energy storage converter PCS from the DSP and stores the data in the protocol stack data;

[0009] S2: When the MCU receives a read or write request from any peripheral, it parses and verifies the request message;

[0010] S3: If the message parsing and verification are passed, the corresponding content is read from the protocol stack data according to the protocol address and the amount of data to be read, and the result is returned immediately;

[0011] S4: If the protocol stack data is occupied by other peripherals during this process, the MCU will wait for the current peripheral operation to complete before executing the read and returning data.

[0012] Preferably, the protocol stack parsing process includes the following steps:

[0013] S11: After the system initialization is completed, multiple peripheral tasks will be created and scheduled;

[0014] S12: The protocol stack parsing function receives the peripheral data structure as an input parameter, and all relevant data and function pointers will be assigned before calling;

[0015] S13: Perform a structural check on the received message to determine the validity of the message;

[0016] S14: Call the read and write functions of the protocol to perform data read and write operations and update the protocol stack data;

[0017] S15: According to the read / write register operation, a response message is constructed and sent through the peripheral data sending function, and the protocol parsing process is completed.

[0018] Preferably, in step S11, each task will initialize the hardware and peripheral data structures, and enter the task loop after the initialization is completed. The task will check whether the peripheral data queue is empty. If it is not empty, the protocol stack parsing function will be called to process the data.

[0019] Preferably, in step S13, a structural check is performed on the received message, including CRC check, address verification and function code determination.

[0020] Preferably, the structural inspection of the received message comprises the following steps:

[0021] S111: If the message does not conform to the protocol structure, an error frame is constructed and the error is responded to through the peripheral sending function;

[0022] S112: If the message is valid, the read and write operations will continue to be processed according to the function code. Currently, the read / write register function is supported and can be expanded;

[0023] S113: For a register read operation, check whether the address is readable, whether the peripheral has the permission to read the data at the address, and verify whether the length to be read is within the protocol range; for a register write operation, similar checks will be performed to ensure that the address is writable, the peripheral has the write permission, and verify whether the length of the written data is within the valid range;

[0024] S114: If all preconditions are checked and passed, the message is considered valid. According to the read or write operation type, the peripheral protocol processing function is called to specially process the address data for the current peripheral and check whether the written data exceeds the allowed range. If it exceeds the range, it will not be set and other valid data will still be written successfully.

[0025] Preferably, the protocol stack read and write function in step S14 comprises the following steps:

[0026] S21: The input parameters of the function include the address to be read / written, the data pointer, and the data size. After entering the function, these parameters are first verified. If the parameters are 0 or NULL, the read / write operation is skipped and the function returns directly.

[0027] S22: Check the current state of the mutex lock. If the mutex lock is locked, enter a waiting loop until the mutex lock is released.

[0028] S23: If the operation type is read, data of a specified size is read from the corresponding address in the protocol stack and stored in the memory location pointed to by the to-be-read data pointer; if the operation type is write, the data in the to-be-written data pointer is written into the protocol stack according to the specified address and size;

[0029] S24: After the operation is completed, the mutex is unlocked and the function call is returned.

[0030] Preferably, in the method, a global data area is used as the protocol stack data, allowing the DSP and all peripherals to perform read and write operations on the protocol stack data within their respective authority ranges.

[0031] Preferably, the configuration of different peripherals in the method is implemented in accordance with the principle of "equal treatment, first request first response", and all peripheral configuration requests first enter the queue, and then the MCU sends them to the DSP one by one in the order of request for processing.

[0032] (III) Beneficial effects

[0033] Compared with the prior art, the present invention provides a method for synchronous communication between the same protocol stack and different peripherals, which has the following beneficial effects: the present invention adopts a global data area as the protocol stack data, allowing the DSP and all peripherals to perform read and write operations on the protocol stack data within their respective authority ranges; and to ensure data consistency, the read and write operations are implemented in a blocking manner through a mutex mechanism in a real-time operating system (RTOS). When a peripheral is performing a read or write operation, the read and write requests of other peripherals will be blocked until the current peripheral completes the operation. This mechanism effectively avoids data conflicts caused by multiple peripherals reading and writing protocol stack data at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 It is a communication framework structure diagram of the present invention;

[0035] Figure 2 The protocol stack analysis flow chart of the present invention;

[0036] Figure 3 This is a flowchart of the protocol stack reading and writing of the present invention. DETAILED DESCRIPTION

[0037] In order to better understand the purpose, structure and function of the present invention, and to solve the deficiencies of the prior art, the present invention adopts a global data area as the protocol stack data, allowing the DSP and all peripherals to read and write the protocol stack data within their respective authority ranges; and to ensure data consistency, the read and write operations are implemented through the mutex mechanism in the real-time operating system (RTOS) to achieve blocking access. When a peripheral is performing a read and write operation, the read and write requests of other peripherals will be blocked until the current peripheral completes the operation. This mechanism effectively avoids data conflicts caused by multiple peripherals reading and writing protocol stack data at the same time. A method for synchronous communication between the same protocol stack and different peripherals of the present invention is further described in detail.

[0038] refer to Figure 1 The present invention provides a method for synchronously communicating with different peripherals on the same protocol stack, which is implemented based on a real-time operating system and includes the following steps:

[0039] S1: MCU, as an intermediate device, actively obtains the real-time data of the energy storage converter PCS from the DSP and stores the data in the protocol stack data;

[0040] Furthermore, in the method, a global data area is used as the protocol stack data, allowing the DSP and all peripherals to perform read and write operations on the protocol stack data within their respective authority ranges.

[0041] S2: When the MCU receives a read or write request from any peripheral, it parses and verifies the request message;

[0042] Specifically, Figure 2 As shown, the protocol stack parsing process includes the following steps:

[0043] S11: After the system initialization is completed, multiple peripheral tasks will be created and scheduled;

[0044] Furthermore, each task will initialize the hardware and peripheral data structures, and enter the task loop after the initialization is completed. The task will check whether the peripheral data queue is empty. If it is not empty, the protocol stack parsing function will be called to process the data;

[0045] S12: The protocol stack parsing function receives the peripheral data structure as an input parameter. All relevant data and function pointers will be assigned before calling. The current parsing function takes the Modbus RTU protocol as an example.

[0046] S13: Perform a structural check on the received message to determine the validity of the message;

[0047] Furthermore, the received message is subjected to structural checks, including CRC check, address verification and function code determination;

[0048] Furthermore, the structural inspection of the received message includes the following steps:

[0049] S111: If the message does not conform to the protocol structure, an error frame is constructed and the error is responded to through the peripheral sending function;

[0050] S112: If the message is valid, the read and write operations will continue to be processed according to the function code. Currently, the read / write register function is supported and can be expanded;

[0051] S113: For a register read operation, check whether the address is readable, whether the peripheral has the permission to read the data at the address, and verify whether the length to be read is within the protocol range; for a register write operation, similar checks will be performed to ensure that the address is writable, the peripheral has the write permission, and verify whether the length of the written data is within the valid range;

[0052] S114: If all preconditions are checked and passed, the message is considered valid. According to the read or write operation type, the peripheral protocol processing function is called to specially process the address data for the current peripheral and check whether the written data exceeds the allowed range. If it exceeds the range, it will not be set and other valid data will still be written successfully.

[0053] S14: Call the read and write functions of the protocol to perform data read and write operations and update the protocol stack data;

[0054] Further, such as Figure 3 As shown, the protocol stack read and write function in step S14 includes the following steps:

[0055] S21: The input parameters of the function include the address to be read / written, the data pointer, and the data size. After entering the function, these parameters are first verified. If the parameters are 0 or NULL, the read / write operation is skipped and the function returns directly.

[0056] S22: Check the current state of the mutex lock. If the mutex lock is locked, enter a waiting loop until the mutex lock is released.

[0057] S23: If the operation type is read, data of a specified size is read from the corresponding address in the protocol stack and stored in the memory location pointed to by the to-be-read data pointer; if the operation type is write, the data in the to-be-written data pointer is written into the protocol stack according to the specified address and size;

[0058] S24: After the operation is completed, the mutex is unlocked and the function call is returned.

[0059] S15: According to the read / write register operation, a response message is constructed and sent through the peripheral data sending function, and the protocol parsing process is completed.

[0060] S3: If the message parsing and verification are passed, the corresponding content is read from the protocol stack data according to the protocol address and the amount of data to be read, and the result is returned immediately;

[0061] S4: If the protocol stack data is occupied by other peripherals during this process, the MCU will wait for the current peripheral operation to complete before executing the read and returning data.

[0062] Furthermore, in the method, the configuration of different peripherals is implemented in accordance with the principle of "equal treatment, first request first response", and all peripheral configuration requests first enter the queue, and then the MCU sends them to the DSP one by one in the order of request for processing.

[0063] This method needs to rely on a real-time operating system (RTOS) and utilize the queues, mutexes, and task scheduling features provided by the RTOS to achieve efficient task management and resource synchronization.

[0064] It is to be understood that the present invention is described by some embodiments, and it is known to those skilled in the art that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present invention. In addition, under the teachings of the present invention, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application are within the scope of protection of the present invention.

Claims

1. A method for synchronous communication between the same protocol stack and different peripherals, implemented based on a real-time operating system, characterized in that: The following steps are involved: S1: MCU, as an intermediate device, actively obtains the real-time data of the energy storage converter PCS from the DSP and stores the data in the protocol stack data; S2: When the MCU receives a read or write request from any peripheral, it parses and verifies the request message; S3: If the message parsing and verification are passed, the corresponding content is read from the protocol stack data according to the protocol address and the amount of data to be read, and the result is returned immediately; S4: If the protocol stack data is occupied by other peripherals during this process, the MCU will wait for the current peripheral operation to complete before executing the read and returning data.

2. A method for synchronous communication between the same protocol stack and different peripherals according to claim 1, characterized in that: The protocol stack analysis process includes the following steps: S11: After the system initialization is completed, multiple peripheral tasks will be created and scheduled; S12: The protocol stack parsing function receives the peripheral data structure as an input parameter, and all relevant data and function pointers will be assigned before calling; S13: Perform a structural check on the received message to determine the validity of the message; S14: Call the read and write functions of the protocol to perform data read and write operations and update the protocol stack data; S15: According to the read / write register operation, a response message is constructed and sent through the peripheral data sending function, and the protocol parsing process is completed.

3. A method for synchronous communication between the same protocol stack and different peripherals according to claim 2, characterized in that: In step S11, each task will initialize the hardware and peripheral data structures, and enter the task loop after the initialization is completed. The task will check whether the peripheral data queue is empty. If it is not empty, the protocol stack parsing function will be called to process the data.

4. A method for synchronous communication between the same protocol stack and different peripherals according to claim 2, characterized in that: In step S13, a structural check is performed on the received message, including CRC check, address verification and function code judgment.

5. A method for synchronous communication between the same protocol stack and different peripherals according to claim 4, characterized in that: The structural inspection of the received message comprises the following steps: S111: If the message does not conform to the protocol structure, an error frame is constructed and the error is responded to through the peripheral sending function; S112: If the message is valid, the read and write operations will continue to be processed according to the function code. Currently, the read / write register function is supported and can be expanded; S113: For a register read operation, check whether the address is readable, whether the peripheral has the permission to read the data at the address, and verify whether the length to be read is within the protocol range; for a register write operation, similar checks will be performed to ensure that the address is writable, the peripheral has the write permission, and verify whether the length of the written data is within the valid range; S114: If all preconditions are checked and passed, the message is considered valid. According to the read or write operation type, the peripheral protocol processing function is called to specially process the address data for the current peripheral and check whether the written data exceeds the allowed range. If it exceeds the range, it will not be set and other valid data will still be written successfully.

6. A method for synchronous communication between the same protocol stack and different peripherals according to claim 2, characterized in that: The protocol stack read and write function in step S14 includes the following steps: S21: The input parameters of the function include the address to be read / written, the data pointer, and the data size. After entering the function, these parameters are first verified. If the parameters are 0 or NULL, the read / write operation is skipped and the function returns directly. S22: Check the current state of the mutex lock. If the mutex lock is locked, enter a waiting loop until the mutex lock is released. S23: If the operation type is read, data of a specified size is read from the corresponding address in the protocol stack and stored in the memory location pointed to by the to-be-read data pointer; if the operation type is write, the data in the to-be-written data pointer is written into the protocol stack according to the specified address and size; S24: After the operation is completed, the mutex is unlocked and the function call is returned.

7. A method for synchronous communication between the same protocol stack and different peripherals according to claim 1, characterized in that: In the method, a global data area is used as protocol stack data, allowing the DSP and all peripherals to perform read and write operations on the protocol stack data within their respective authority ranges.

8. The method for synchronous communication between the same protocol stack and different peripherals according to claim 1, characterized in that: In the method, the configuration of different peripherals is implemented in accordance with the principle of "equal treatment and first request first response". All peripheral configuration requests enter the queue first, and then the MCU sends them to the DSP one by one in the request order for processing.