CN117519789A - Micro control unit control method and device, electronic equipment and storage medium - Google Patents

Micro control unit control method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117519789A
CN117519789A CN202210901069.6A CN202210901069A CN117519789A CN 117519789 A CN117519789 A CN 117519789A CN 202210901069 A CN202210901069 A CN 202210901069A CN 117519789 A CN117519789 A CN 117519789A
Authority
CN
China
Prior art keywords
control unit
data
micro control
serial port
buffer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210901069.6A
Other languages
Chinese (zh)
Inventor
谭瀚禹
李宇庭
雷舰
高卫红
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Opening Of Biomedical Technology Wuhan Co ltd
Original Assignee
Opening Of Biomedical Technology Wuhan Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Opening Of Biomedical Technology Wuhan Co ltd filed Critical Opening Of Biomedical Technology Wuhan Co ltd
Priority to CN202210901069.6A priority Critical patent/CN117519789A/en
Publication of CN117519789A publication Critical patent/CN117519789A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/3004Arrangements for executing specific machine instructions to perform operations on memory
    • G06F9/30047Prefetch instructions; cache control instructions

Landscapes

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

Abstract

The application discloses a micro control unit control method, a micro control unit control device, an electronic device and a computer readable storage medium, wherein the method is applied to a central processing unit and comprises the following steps: acquiring serial port data sent by a micro control unit; the serial port data comprise first data actively reported by the micro control unit; storing serial data into a first buffer area; and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data. Therefore, according to the control method of the micro control unit, the micro control unit can actively report the event to the application program through the serial port, so that the application program can timely monitor the event of the micro control unit.

Description

Micro control unit control method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technology, and more particularly, to a method and apparatus for controlling a micro control unit, an electronic device, and a computer readable storage medium.
Background
In the related art, an operating system actively issues a strategy through application software in a central processing unit (central processing unit, CPU), receives the strategy and then converts the strategy into an instruction to be transmitted to a micro control unit (Microcontroller Unit, MCU), the micro control unit performs passive response, then transmits a feedback result to the operating system, and the operating system processes data into information which is beneficial to human reading and then transmits the information to the application software.
Since all processes of the scheme are started by the application software, for some hardware state changes, such as the plugging state of the power line, the application software uses a polling mechanism to monitor. In order to reduce the occupation of resources, the frequency of the polling mechanism is not too high, and usually about 3-5 seconds may be needed, if the action of pulling and inserting the power line occurs just after the last polling of the application software is finished, the application software waits for 3-5 seconds to receive that the power line is pulled and inserted, the hysteresis of information acquisition is quite serious, and the data security is greatly affected.
Therefore, how to monitor the events of the micro control unit in time is a technical problem that needs to be solved by those skilled in the art.
Disclosure of Invention
The application aims to provide a micro-control unit control method and device, electronic equipment and a computer readable storage medium, so that an application program can monitor events of the micro-control unit in time.
In order to achieve the above object, the present application provides a control method of a micro control unit, which is applied to a central processing unit, and the method includes:
acquiring serial port data sent by a micro control unit; the serial port data comprise first data actively reported by the micro control unit;
Storing the serial port data into a first buffer area;
and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data.
Before the serial port data sent by the micro control unit is obtained, the method further comprises:
transmitting a serial port instruction to the micro control unit so that the micro control unit responds;
correspondingly, the serial port data further comprises second data passively responded after the micro control unit receives the serial port instruction, and after the serial port data is stored in the first buffer zone, the serial port data further comprises:
moving second data passively responded by the micro control unit from the first buffer area to a second buffer area;
and reading second data passively responded by the micro control unit in the second buffer area according to a preset period, and processing the second data.
Wherein moving the passively-responsive second data of the micro-control unit from the first buffer to the second buffer comprises:
judging whether the serial port data is second data which are passively responded by the micro control unit according to the state bit of the serial port data in the first buffer zone;
And if so, moving the second data passively responded by the micro control unit from the first buffer area to the second buffer area.
Before the serial port data sent by the micro control unit is obtained, the method further comprises:
initializing the first buffer zone and the second buffer zone through a main thread, and creating a sub thread;
correspondingly, the acquiring serial port data sent by the micro control unit includes:
acquiring serial port data sent by a micro control unit through the sub-thread;
correspondingly, storing the serial port data in a first buffer area includes:
storing the data to the first buffer by the child thread;
correspondingly, sending a serial port instruction to the micro control unit, including:
transmitting a serial port instruction to the micro control unit through the main thread;
accordingly, moving the second data passively responded by the micro control unit from the first buffer to the second buffer comprises:
moving second data passively responded by the micro control unit from the first buffer to a second buffer through the sub thread;
correspondingly, the reading the second data passively responded by the micro control unit in the second buffer area according to the preset period includes:
And reading second data passively responded by the micro control unit in the second buffer area according to a preset period through the main thread.
If the serial port instruction is a firmware upgrade instruction, the method further includes:
reading a firmware file;
and after receiving the start character sent by the micro control unit, sending the firmware file to the micro control unit so that the micro control unit can perform firmware upgrading based on the firmware file.
After the serial port instruction is sent to the micro control unit through the main thread, the method further comprises the following steps:
setting a firmware upgrading flag bit to a preset value through the main thread;
correspondingly, before the serial port data sent by the micro control unit is obtained through the sub-thread, the method further comprises:
judging whether the firmware upgrading flag bit is a preset value through the sub-thread, and if not, executing the step of acquiring serial port data sent by the micro-control unit through the sub-thread.
After the serial port data is stored in the first buffer, the method further includes:
and carrying out exception checking on the serial port data in the first buffer area.
In order to achieve the above object, the present application provides a micro control unit control device applied to a central processing unit, the device comprising:
The acquisition module is used for acquiring serial port data sent by the micro control unit; the serial port data comprise first data actively reported by the micro control unit;
the storage module is used for storing the serial data into a first buffer area;
and the processing module is used for acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode and processing the first data.
To achieve the above object, the present application provides an electronic device, including:
a memory for storing a computer program;
and the processor is used for realizing the steps of the control method of the micro control unit when executing the computer program.
To achieve the above object, the present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the control method of a micro control unit as described above.
According to the scheme, the control method of the micro control unit is applied to the central processing unit and comprises the following steps: acquiring serial port data sent by a micro control unit; the serial port data comprise first data actively reported by the micro control unit; storing the serial port data into a first buffer area; and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data.
According to the control method of the micro control unit, the micro control unit can actively report data to the application program through the serial port, the data can be stored in the first buffer area, and the application program acquires the data actively reported by the micro control unit in the first buffer area in a callback mode and processes the data. Therefore, according to the control method of the micro control unit, the micro control unit can actively report the event to the application program through the serial port, so that the application program can timely monitor the event of the micro control unit. The application also discloses a micro control unit control device, an electronic device and a computer readable storage medium, and the technical effects can be achieved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. The accompanying drawings are included to provide a further understanding of the disclosure, and are incorporated in and constitute a part of this specification, illustrate the disclosure and together with the description serve to explain, but do not limit the disclosure. In the drawings:
FIG. 1 is a flow chart illustrating a method of controlling a micro-control unit according to an exemplary embodiment;
FIG. 2 is a block diagram of a packet of serial data according to an exemplary embodiment;
FIG. 3 is a schematic diagram of an asynchronous callback, shown in accordance with an exemplary embodiment;
FIG. 4 is a flow chart illustrating another micro-control unit control method according to an exemplary embodiment;
FIG. 5 is a schematic diagram of a buffer area shown according to an example embodiment;
FIG. 6 is a schematic diagram illustrating a process of updating a first buffer, according to an example embodiment;
FIG. 7 is a flowchart illustrating yet another micro-control unit control method according to an exemplary embodiment;
FIG. 8 is a schematic workflow diagram of a main thread and sub-threads shown according to an exemplary embodiment;
fig. 9 is a block diagram showing a control device of a micro control unit according to an exemplary embodiment;
fig. 10 is a block diagram of an electronic device, according to an example embodiment.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application. In addition, in the embodiments of the present application, "first," "second," and the like are used to distinguish similar objects, and are not necessarily used to describe a particular order or sequence.
The embodiment of the application discloses a control method of a micro control unit, which enables an application program to monitor events of the micro control unit in time.
Referring to fig. 1, a flowchart of a control method of a micro control unit according to an exemplary embodiment is shown, as shown in fig. 1, including:
s101: acquiring serial port data sent by a micro control unit; the serial port data comprise first data actively reported by the micro control unit;
s102: storing the serial port data into a first buffer area;
the execution body of the embodiment may be an application program in the central processing unit, and the purpose is to monitor the event of the micro control unit. In this embodiment, the micro control unit may be a power panel, or may be another unit with similar control requirements, which is communicatively connected to the central processing unit, and this embodiment is not limited in detail. In an application scenario, the central processing unit can be a central processing unit in ultrasonic instrument equipment, the ultrasonic instrument equipment is provided with a battery controlled by a power panel, and the position of the mobile equipment can be flexibly moved under a series of tedious operations such as shutdown, restarting and the like, so that convenience is provided for doctors. When a doctor can disconnect a power supply and use battery power to prepare ultrasonic examination, the doctor can accurately acquire the current battery information and the connection state of the power adapter, reasonably arrange the use time, prevent the loss of examination data and ensure the experience of a user and the safety of the data. The power panel in the ultrasonic instrument equipment is mainly used for power management, acquires and monitors the electric quantity, voltage, charging current and temperature of a battery, controls a fan and other functions, and has important influence on 3D and 4D scanning and standby awakening.
In a specific implementation, the micro control unit interacts with the application program through the serial port, that is, the application program can obtain serial port data sent by the micro control unit through the serial port, and the serial port data is stored in the first buffer area.
In a specific implementation, according to the communication protocol of the micro control unit, the structure of the Data packet of the serial port Data is shown in fig. 2, and a composition mode of head+state+data+check may be adopted. The Head is header information, fixed 2 bytes, which may be preset characters, for example, 0×55×aa, state is a status bit description, fixed 3 bytes, the first byte is Branch, the second byte is Leaf, the third byte is a Data length bit, data is a Data bit description, and Check is a Check bit.
As a preferred embodiment, after storing the serial port data in the first buffer, the method further includes: and carrying out exception checking on the serial port data in the first buffer area. In a specific implementation, an application program monitors a serial port, and once data is reported, the serial port is immediately read, so that a complete serial port data packet is not necessarily transmitted at one time, and more than one serial port data packet is possible, and therefore, the length of the serial port data needs to be checked. According to the structure of the serial data packet, a serial data has at least 2 header bytes, 3 status bit bytes, pData [4] data bit bytes, 1 check bit byte, 6+pData [4] bytes, and the shortest of 6 bytes. When the actual acquired data length actual_len is smaller than or equal to 4 bytes, it indicates that the data length bit is not acquired yet, at this time, the theoretical data length threry_len may be set to 6, the acquisition of the serial port data of the next round is directly performed, and the serial port data acquired by the next round is spliced to the data end of the serial port data acquired by the current round. When the actual acquired data length actual_len is greater than 4 bytes, it indicates that a data length bit has been acquired, and the data length bit is the theoretical data length threy_len, at this time, if actual_len < the source_len, the next round of serial port data acquisition is performed, and the serial port data acquired in the next round is spliced to the data end of the serial port data acquired in the current round until the actual acquired data length actual_len is equal to the theoretical data length threy_len. The specific implementation of the length check is as follows:
In addition, header information of the serial port data can be checked. In a specific implementation, according to the structure of the serial data packet, the header information is a fixed preset character, and when the read header information of the serial data packet is not the preset character, the read header information is treated as bad data. At this time, the data cannot be directly cleared, and because a plurality of serial data packets may exist in the read serial data, all the data read later need to be checked. That is, when pData [0], pData [1] are not the preset characters, traversing from pData [1] to the previous bit of the last bit of the actual length, searching whether the preset characters exist, such as 0x55, 0xAA continuously, if so, clearing the data before the preset characters, updating the data in the first buffer, and if not, clearing all the data, updating the data in the first buffer. The specific implementation of the header verification is as follows:
furthermore, the accuracy of the content of the data bit in the serial port data packet can be checked, when the check is successful, the bad data is cleared, the data in the first buffer area is updated and read, when the check fails, all the data are cleared, and a new serial port monitoring is performed. As a possible implementation, SUM (SUM) checking may be used, specifically implemented as follows:
Wherein, check bit= (state 0+ state1+ state2+ data0+ data1+ data2+ … + datan) 0xff, and performing and operation on overflow bit. The specific implementation is as follows:
of course, XOR (exclusive OR) checking can also be used, and check bit= (Head bar Leaf Data0 … Data Lenth-1) is implemented as follows:
furthermore, the function self-calling is performed on the analytic function of the first data buffer zone, which is mainly used for processing the condition that a plurality of pieces of data exist in the first data buffer zone, and after the first piece of data is processed and cleaned, if the first piece of data still exists in the first data buffer zone, the data analysis and the exception processing are performed again.
The specific implementation is as follows:
it should be noted that, the serial data reported to the application program by the micro control unit may include that the micro control unit actively reports data to the application program, and the micro control unit detects the first data in the step after the micro control unit is triggered by the change of the environment or the state of the micro control unit.
S103: and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data.
It can be understood that the application program cannot determine whether the active reporting event will occur, when the active reporting event occurs, what the result is after the occurrence, and for this case, in order to make the event processing of the micro control unit more efficient, it is ensured that the active reporting event will not block other functions of the micro control unit, and the callback of the active reporting event is implemented by using an asynchronous call mode. In implementations, the application knows what needs to be done after the event, i.e., how to process the data, but not when to do so, and the micro-control unit does not know what to do, but knows when to actively report the event. For the bottom layer, a function interface of an application software registration callback function is required to be provided, and after data actively reported by the micro control unit is acquired, corresponding information is transmitted to the function interface according to the data content. The asynchronous callback process is shown in fig. 3, an application program registers a callback function at the beginning, and after the micro control unit actively reports first data, the application program acquires the first data actively reported by the micro control unit through a function interface of the callback function and responds to the first data.
According to the control method for the micro control unit, the micro control unit can actively report data to the application program through the serial port, the data can be stored in the first buffer area, and the application program acquires the data actively reported by the micro control unit in the first buffer area in a callback mode and processes the data. Therefore, according to the control method of the micro control unit, the micro control unit can actively report the event to the application program through the serial port, so that the application program can timely monitor the event of the micro control unit.
The embodiment of the application discloses a control method of a micro control unit, and compared with the previous embodiment, the technical scheme is further described and optimized. Specific:
referring to fig. 4, a flowchart of another control method of a micro control unit according to an exemplary embodiment is shown, as shown in fig. 4, including:
s201: transmitting a serial port instruction to the micro control unit so that the micro control unit responds;
in this embodiment, the application program may issue a serial port instruction to the micro control unit, and the micro control unit responds to the serial port instruction and replies through the serial port, that is, replies the second data of the passive response to the application program.
S202: acquiring serial port data sent by a micro control unit; the serial port data comprise first data actively reported by the micro control unit and second data passively responded after the micro control unit receives a serial port instruction;
in this embodiment, the serial data obtained by the application program from the serial port includes first data actively reported by the micro control unit and second data passively responded by the micro control unit.
S203: storing the serial port data into a first buffer area;
s204: moving second data passively responded by the micro control unit from the first buffer area to a second buffer area;
in this embodiment, as shown in fig. 5, all serial data are stored in a first buffer (buffer 1), that is, the first buffer is a first station of the serial data, the analysis processing of the first buffer is triggered when the data are stored in the first buffer each time, the data type is determined after exception processing, that is, whether the data in the first buffer are the first data actively reported by the micro control unit or the second data passively responded by the micro control unit is determined, the second data passively responded by the micro control unit is moved from the first buffer to the second buffer (buffer 2), and the first data actively reported by the micro control unit is fed back to an application program in a callback mode.
As a possible implementation, moving the second data passively responded by the micro control unit from the first buffer to the second buffer includes: judging whether the serial port data is second data which are passively responded by the micro control unit according to the state bit of the serial port data in the first buffer zone; and if so, moving the second data passively responded by the micro control unit from the first buffer area to the second buffer area. In a specific implementation, the second data passively responded by the micro control unit can be moved from the first buffer area to the second buffer area according to the first byte and the second byte in the status bit, namely, the data type of the serial data is judged by Branch and Leaf.
In the process of updating the first buffer area, as shown in fig. 6, in the same parsing process, more than one piece of serial data may exist in the first buffer area, after the first buffer area is processed abnormally, or after correct data is transferred into the second buffer area, the remaining data in the first buffer area are copied to the head end of the buffer area in sequence, after the completion, a space behind the copied data is subjected to a 0-setting emptying operation, and the next round of data parsing is waited.
S205: reading second data passively responded by the micro control unit in the second buffer area according to a preset period, and processing the second data;
S206: and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data.
Therefore, the embodiment is compatible with the passive response event and the active reporting event of the micro-control unit, and the application program can monitor the event of the micro-control unit in time.
On the basis of the foregoing embodiment, as a preferred implementation manner, if the serial port instruction is a firmware upgrade instruction, the method further includes: reading a firmware file; and after receiving the start character sent by the micro control unit, sending the firmware file to the micro control unit so that the micro control unit can perform firmware upgrading based on the firmware file.
In a specific implementation, if the serial port instruction is a firmware upgrade instruction, a firmware upgrade process is triggered, and after receiving the firmware upgrade instruction, the micro control unit replies a start character, for example, an ASCII C character, to the application program to start transmission of the firmware file. After receiving the start character, the application program starts to transmit the firmware file to the micro control unit, and the micro control unit receives the firmware file and performs firmware upgrading based on the firmware file.
Further, when the micro control unit is abnormal, for example, when the firmware upgrade of the micro control unit fails, a start character is continuously sent to the application program to trigger the firmware upgrade. After receiving the start character, the application program starts to transmit the firmware file to the micro control unit, and the micro control unit firmware file is updated based on the firmware file.
It should be noted that, the firmware file may be transferred between the application program and the micro control unit using an Xmodem protocol, which is an asynchronous file transfer protocol widely used in serial port communication, and provides a simple continuous file transfer with a fixed packet length point-to-point. In this embodiment, the application program divides the firmware file into a plurality of firmware subfiles according to a preset length, and fills with preset characters, such as NACK (0 x 1A), when the last firmware subfile is less than the preset length. The application program transmits a firmware subfile with a preset length to the micro control unit each time, and the preset length is 1K (1024 bytes), for example, the format of a data packet transmitted to the micro control unit each time by the application program may be:
< SOH (header) > < packet number anti-code > < file data > < check bit >;
The packet header is a preset fixed character, the packet sequence number can be understood as the sequence number of the firmware subfile, and the file data is specific content of the firmware subfile. The check bits may be SUM check, i.e. the check bits are the SUM of all data bits except the header and 0xff and the overflow bits are anded. The check bits may be checked using XOR (exclusive or), i.e. the check bits are the exclusive or result of all data bits.
The micro control unit responds to each received firmware subfile through a first response character or a second response character, wherein the first response character represents normal receiving, the second response character represents abnormal receiving, namely, when the receiving is successful, the micro control unit replies the first response character to the application program, and when the receiving is failed, the micro control unit replies the second response character to the application program. A first response character, e.g., ACK, and a second response character, e.g., NACK.
When the application program receives the first response character, the next firmware subfile is continuously sent to the micro control unit, and when the application program receives the second response character, the current firmware subfile is repeatedly sent to the micro control unit.
And when the transmission of the last firmware subfile is successful, namely the application program receives a first response character corresponding to the last firmware subfile, a transmission completion mark is sent to the micro control unit so as to inform the micro control unit that the transmission of the firmware file is finished. And after receiving the transmission completion mark, the micro control unit returns a first response character, and when the application program receives the first response character corresponding to the transmission completion mark, the firmware file is transmitted.
The embodiment of the application discloses a control method of a micro control unit, and compared with the previous embodiment, the technical scheme is further described and optimized. Specific:
referring to fig. 7, a flowchart of yet another micro control unit control method according to an exemplary embodiment is shown, as shown in fig. 7, including:
s301: initializing the first buffer zone and the second buffer zone through a main thread, and creating a sub thread;
s302: transmitting a serial port instruction to the micro control unit through the main thread so that the micro control unit responds;
s303: acquiring serial port data sent by a micro control unit through the sub-thread; the serial port data comprise first data actively reported by the micro control unit and second data passively responded after the micro control unit receives a serial port instruction;
s304: storing the data to the first buffer by the child thread;
s305: moving second data passively responded by the micro control unit from the first buffer to a second buffer through the sub thread;
s306: reading second data passively responded by the micro control unit in the second buffer area according to a preset period through the main thread;
S307: and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data.
In this embodiment, two steps of issuing an instruction to a serial port and acquiring serial port data are separated, namely, two actions of reading and writing of the serial port are separated, writing operation is performed in a main thread, reading operation is performed in a sub thread, and the two operations are mutually non-interfering in time and space.
In a specific implementation, as shown in fig. 8, a main thread is created, and the main thread is used for opening a serial port, initializing a serial port attribute, a first buffer zone and a second buffer zone, setting a sub-thread state flag to true, and creating a sub-thread. The main thread is also used for issuing serial port instructions of corresponding strategies to the serial ports, reading data from the second buffer area for a plurality of times until the data are read or the data exit is overtime, setting the state flag of the sub-thread as false, waiting for the sub-thread to exit, recovering resources and closing the serial ports.
The work flow of the sub-thread is as follows: monitoring the serial port through an observer mode, capturing immediately when the data passes, reading the serial port data, storing the serial port data in a first buffer area according to a tail connection method sequence, analyzing the data in the first buffer area, processing the data according to specific abnormal conditions if the analysis result is abnormal, and entering the next cycle to continue monitoring. Judging the data type after analyzing no abnormality, and if the data is actively reported, processing the actively reported data in a callback function mode; if the data is the passive response data, the analyzed data result is moved from the first buffer area to the second buffer area, and the main thread waits for reading the data in the second buffer area. Each cycle of the sub-thread judges the state flag of the sub-thread, if true, the cycle is continued, if false, the cycle is jumped out, and the sub-thread is exited.
On the basis of the foregoing embodiment, as a preferred implementation manner, after the serial port instruction is sent to the micro control unit through the main thread, the method further includes: setting a firmware upgrading flag bit to a preset value through the main thread; correspondingly, before the serial port data sent by the micro control unit is obtained through the sub-thread, the method further comprises: judging whether the firmware upgrading flag bit is a preset value through the sub-thread, and if not, executing the step of acquiring serial port data sent by the micro-control unit through the sub-thread.
In a specific implementation, as shown in fig. 8, after the main thread issues a serial port instruction to the serial port, it is determined whether the serial port instruction is a firmware upgrade instruction, if yes, a firmware upgrade flag bit is set to a preset value, for example, the firmware upgrade flag bit is set to true, and a firmware upgrade flow is triggered. The sub-thread judges whether the firmware upgrading flag bit is a preset value before reading the serial port data, if so, the sub-thread waits for a preset time (for example, 1 s) and then enters the next cycle to continue monitoring, and if not, the serial port data is read.
The following describes a micro control unit control device according to an embodiment of the present application, and the micro control unit control device described below and the micro control unit control method described above may be referred to each other.
Referring to fig. 9, a block diagram of a micro control unit control apparatus according to an exemplary embodiment is shown, as shown in fig. 9, including:
the acquisition module 901 is used for acquiring serial port data sent by the micro control unit; the serial port data comprise first data actively reported by the micro control unit;
a storage module 902, configured to store the serial port data into a first buffer;
the processing module 903 is configured to obtain, by using a callback manner, first data actively reported by the micro control unit in the first buffer, and process the first data.
According to the micro control unit control device provided by the embodiment of the application program, the micro control unit can actively report data to the application program through the serial port, the data can be stored in the first buffer area, and the application program acquires the data actively reported by the micro control unit in the first buffer area in a callback mode and processes the data. Therefore, according to the micro-control unit control device provided by the embodiment of the application, the micro-control unit can actively report the event to the application program through the serial port, so that the application program can timely monitor the event of the micro-control unit.
On the basis of the above embodiment, as a preferred implementation manner, the method further includes:
The sending module is used for sending a serial port instruction to the micro control unit so that the micro control unit responds;
correspondingly, the serial port data further comprises second data which are passively responded after the micro control unit receives the serial port instruction, and the device further comprises:
a moving module for moving the second data passively responded by the micro control unit from the first buffer area to a second buffer area;
and the reading module is used for reading the second data passively responded by the micro control unit in the second buffer area according to a preset period and processing the second data.
On the basis of the above embodiment, as a preferred implementation manner, the mobile module is specifically configured to: judging whether the serial port data is second data which are passively responded by the micro control unit according to the state bit of the serial port data in the first buffer zone; and if so, moving the second data passively responded by the micro control unit from the first buffer area to the second buffer area.
On the basis of the above embodiment, as a preferred implementation manner, the method further includes:
the creation module is used for initializing the first buffer zone and the second buffer zone through the main thread and creating a sub thread;
Correspondingly, the obtaining module 901 is specifically configured to: acquiring serial port data sent by a micro control unit through the sub-thread;
accordingly, the storage module 902 is specifically configured to: storing the data to the first buffer by the child thread;
correspondingly, the sending module is specifically configured to: transmitting a serial port instruction to the micro control unit through the main thread;
correspondingly, the mobile module is specifically configured to: moving second data passively responded by the micro control unit from the first buffer to a second buffer through the sub thread;
correspondingly, the reading module is specifically configured to: and reading second data passively responded by the micro control unit in the second buffer area according to a preset period through the main thread, and processing the second data.
On the basis of the foregoing embodiment, as a preferred implementation manner, if the serial port instruction is a firmware upgrade instruction, the apparatus further includes:
the firmware upgrading module is used for reading the firmware file; and after receiving the start character sent by the micro control unit, sending the firmware file to the micro control unit so that the micro control unit can perform firmware upgrading based on the firmware file.
On the basis of the above embodiment, as a preferred implementation manner, the method further includes:
the setting module is used for setting the firmware upgrading zone bit to a preset value through the main thread after the serial port instruction is sent to the micro control unit through the main thread;
the judging module is configured to judge, by the sub-thread, whether the firmware upgrade flag bit is a preset value before the serial port data sent by the micro-control unit is obtained by the sub-thread, and if not, start the workflow of the obtaining module 901.
On the basis of the above embodiment, as a preferred implementation manner, the method further includes:
and the verification module is used for carrying out abnormal verification on the serial port data in the first buffer area.
The specific manner in which the various modules perform the operations in the apparatus of the above embodiments have been described in detail in connection with the embodiments of the method, and will not be described in detail herein.
Based on the hardware implementation of the program modules, and in order to implement the method of the embodiments of the present application, the embodiments of the present application further provide an electronic device, fig. 10 is a block diagram of an electronic device according to an exemplary embodiment, and as shown in fig. 10, the electronic device includes:
A communication interface 1 capable of information interaction with other devices such as network devices and the like;
and the processor 2 is connected with the communication interface 1 to realize information interaction with other devices and is used for executing the micro control unit control method provided by one or more technical schemes when running the computer program. And the computer program is stored on the memory 3.
Of course, in practice, the various components in the electronic device are coupled together by a bus system 4. It will be appreciated that the bus system 4 is used to enable connected communications between these components. The bus system 4 comprises, in addition to a data bus, a power bus, a control bus and a status signal bus. But for clarity of illustration the various buses are labeled as bus system 4 in fig. 10.
The memory 3 in the embodiment of the present application is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program for operating on an electronic device.
It will be appreciated that the memory 3 may be either volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. Wherein the nonvolatile Memory may be Read Only Memory (ROM), programmable Read Only Memory (PROM, programmable Read-Only Memory), erasable programmable Read Only Memory (EPROM, erasable Programmable Read-Only Memory), electrically erasable programmable Read Only Memory (EEPROM, electrically Erasable Programmable Read-Only Memory), magnetic random access Memory (FRAM, ferromagnetic random access Memory), flash Memory (Flash Memory), magnetic surface Memory, optical disk, or compact disk Read Only Memory (CD-ROM, compact Disc Read-Only Memory); the magnetic surface memory may be a disk memory or a tape memory. The volatile memory may be random access memory (RAM, random Access Memory), which acts as external cache memory. By way of example, and not limitation, many forms of RAM are available, such as static random access memory (SRAM, static Random Access Memory), synchronous static random access memory (SSRAM, synchronous Static Random Access Memory), dynamic random access memory (DRAM, dynamic Random Access Memory), synchronous dynamic random access memory (SDRAM, synchronous Dynamic Random Access Memory), double data rate synchronous dynamic random access memory (ddr SDRAM, double Data Rate Synchronous Dynamic Random Access Memory), enhanced synchronous dynamic random access memory (ESDRAM, enhanced Synchronous Dynamic Random Access Memory), synchronous link dynamic random access memory (SLDRAM, syncLink Dynamic Random Access Memory), direct memory bus random access memory (DRRAM, direct Rambus Random Access Memory). The memory 3 described in the embodiments of the present application is intended to comprise, without being limited to, these and any other suitable types of memory.
The method disclosed in the embodiments of the present application may be applied to the processor 2 or implemented by the processor 2. The processor 2 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in the processor 2 or by instructions in the form of software. The processor 2 described above may be a general purpose processor, DSP, or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor 2 may implement or perform the methods, steps and logic blocks disclosed in the embodiments of the present application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiments of the present application may be directly embodied in a hardware decoding processor or implemented by a combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium in the memory 3 and the processor 2 reads the program in the memory 3 to perform the steps of the method described above in connection with its hardware.
The processor 2 implements corresponding flows in the methods of the embodiments of the present application when executing the program, and for brevity, will not be described in detail herein.
In an exemplary embodiment, the present application also provides a storage medium, i.e. a computer storage medium, in particular a computer readable storage medium, for example comprising a memory 3 storing a computer program executable by the processor 2 for performing the steps of the method described above. The computer readable storage medium may be FRAM, ROM, PROM, EPROM, EEPROM, flash Memory, magnetic surface Memory, optical disk, or CD-ROM.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the above method embodiments may be implemented by hardware associated with program instructions, where the foregoing program may be stored in a computer readable storage medium, and when executed, the program performs steps including the above method embodiments; and the aforementioned storage medium includes: a removable storage device, ROM, RAM, magnetic or optical disk, or other medium capable of storing program code.
Alternatively, the integrated units described above may be stored in a computer readable storage medium if implemented in the form of software functional modules and sold or used as a stand-alone product. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or partly contributing to the prior art, and the computer software product may be stored in a storage medium, and include several instructions to cause an electronic device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a removable storage device, ROM, RAM, magnetic or optical disk, or other medium capable of storing program code.
The foregoing is merely specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and the changes and substitutions are intended to be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A control method of a micro control unit, which is applied to a central processing unit, the method comprising:
acquiring serial port data sent by a micro control unit; the serial port data comprise first data actively reported by the micro control unit;
storing the serial port data into a first buffer area;
and acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode, and processing the first data.
2. The method for controlling a micro control unit according to claim 1, further comprising, before the step of obtaining serial data sent by the micro control unit:
transmitting a serial port instruction to the micro control unit so that the micro control unit responds;
correspondingly, the serial port data further comprises second data passively responded after the micro control unit receives the serial port instruction, and after the serial port data is stored in the first buffer zone, the serial port data further comprises:
Moving second data passively responded by the micro control unit from the first buffer area to a second buffer area;
and reading second data passively responded by the micro control unit in the second buffer area according to a preset period, and processing the second data.
3. The method of claim 2, wherein moving the second data passively responded to by the micro control unit from the first buffer to the second buffer comprises:
judging whether the serial port data is second data which are passively responded by the micro control unit according to the state bit of the serial port data in the first buffer zone;
and if so, moving the second data passively responded by the micro control unit from the first buffer area to the second buffer area.
4. The method for controlling a micro control unit according to claim 2, further comprising, before the step of obtaining serial data sent by the micro control unit:
initializing the first buffer zone and the second buffer zone through a main thread, and creating a sub thread;
correspondingly, the acquiring serial port data sent by the micro control unit includes:
acquiring serial port data sent by a micro control unit through the sub-thread;
Correspondingly, storing the serial port data in a first buffer area includes:
storing the data to the first buffer by the child thread;
correspondingly, sending a serial port instruction to the micro control unit, including:
transmitting a serial port instruction to the micro control unit through the main thread;
accordingly, moving the second data passively responded by the micro control unit from the first buffer to the second buffer comprises:
moving second data passively responded by the micro control unit from the first buffer to a second buffer through the sub thread;
correspondingly, the reading the second data passively responded by the micro control unit in the second buffer area according to the preset period includes:
and reading second data passively responded by the micro control unit in the second buffer area according to a preset period through the main thread.
5. The method according to claim 4, wherein if the serial port instruction is a firmware upgrade instruction, the method further comprises:
reading a firmware file;
and after receiving the start character sent by the micro control unit, sending the firmware file to the micro control unit so that the micro control unit can perform firmware upgrading based on the firmware file.
6. The method according to claim 5, further comprising, after the serial port instruction is sent to the micro control unit through the main thread:
setting a firmware upgrading flag bit to a preset value through the main thread;
correspondingly, before the serial port data sent by the micro control unit is obtained through the sub-thread, the method further comprises:
judging whether the firmware upgrading flag bit is a preset value through the sub-thread, and if not, executing the step of acquiring serial port data sent by the micro-control unit through the sub-thread.
7. The control method of the micro control unit according to claim 1, further comprising, after storing the serial port data in the first buffer:
and carrying out exception checking on the serial port data in the first buffer area.
8. A micro control unit control device, applied to a central processing unit, comprising:
the acquisition module is used for acquiring serial port data sent by the micro control unit; the serial port data comprise first data actively reported by the micro control unit;
the storage module is used for storing the serial data into a first buffer area;
And the processing module is used for acquiring first data actively reported by the micro control unit in the first buffer area in a callback mode and processing the first data.
9. An electronic device, comprising:
a memory for storing a computer program;
a processor for implementing the steps of the micro control unit control method according to any one of claims 1 to 7 when executing said computer program.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer program which, when executed by a processor, implements the steps of the micro control unit control method according to any one of claims 1 to 7.
CN202210901069.6A 2022-07-28 2022-07-28 Micro control unit control method and device, electronic equipment and storage medium Pending CN117519789A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210901069.6A CN117519789A (en) 2022-07-28 2022-07-28 Micro control unit control method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210901069.6A CN117519789A (en) 2022-07-28 2022-07-28 Micro control unit control method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117519789A true CN117519789A (en) 2024-02-06

Family

ID=89759299

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210901069.6A Pending CN117519789A (en) 2022-07-28 2022-07-28 Micro control unit control method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117519789A (en)

Similar Documents

Publication Publication Date Title
US20210318738A1 (en) Methods and apparatus for enhanced power delivery between devices
CN109688555B (en) Real-time signal data acquisition and communication system and method
US20140310322A1 (en) Method and System for Identifying File Type
CN112416408A (en) Firmware upgrading method, device, equipment and computer readable storage medium
CN106126362B (en) A kind of optical module I2C bus unrest sequential diagnosis method and device
JP2014099061A (en) Controller and program
WO2024108940A1 (en) Performance supervision method, apparatus and system, and device and medium
CN117519789A (en) Micro control unit control method and device, electronic equipment and storage medium
CN113051207A (en) Data processing method and device, electronic equipment and storage medium
US11314670B2 (en) Method, apparatus, and device for transmitting file based on BMC, and medium
CN111445000A (en) Fingerprint card and processing method based on same
US20210337011A1 (en) Method, apparatus, and device for transmitting file based on bmc, and medium
US11954951B2 (en) Component of electric vehicle, data collecting system for electric vehicle, and data collecting method for electric vehicle
CN112822002B (en) SPI-based communication method and device, electronic equipment and storage medium
CN115065966B (en) Terminal and communication method
CN106789280A (en) A kind of upgrade protecting method and system, mobile terminal based on android system
CN117519737A (en) Micro control unit firmware upgrading method and device, electronic equipment and storage medium
CN112202728B (en) Method and system for mobile terminal to call module through routing protocol
CN114003535B (en) Device bandwidth configuration method and system, electronic device and storage medium
CN112953685B (en) Model data transmission method and related network equipment
CN116800654A (en) Monitoring system, method, equipment and storage medium for bus data transmission
CN114817100B (en) Data reading method and device for single board
CN118250272A (en) Remote management method, device, storage medium and apparatus
CN117979277A (en) 5G module state control method and device, terminal equipment and storage medium
CN115687123A (en) Special test method, device, equipment and medium

Legal Events

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