WO2023066233A1 - Program flashing method and apparatus for controller, and controller and storage medium - Google Patents

Program flashing method and apparatus for controller, and controller and storage medium Download PDF

Info

Publication number
WO2023066233A1
WO2023066233A1 PCT/CN2022/125868 CN2022125868W WO2023066233A1 WO 2023066233 A1 WO2023066233 A1 WO 2023066233A1 CN 2022125868 W CN2022125868 W CN 2022125868W WO 2023066233 A1 WO2023066233 A1 WO 2023066233A1
Authority
WO
WIPO (PCT)
Prior art keywords
program
memory
flashed
space
code
Prior art date
Application number
PCT/CN2022/125868
Other languages
French (fr)
Chinese (zh)
Inventor
周添
王宇
张建
李春善
公博健
侯殿龙
Original Assignee
中国第一汽车股份有限公司
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 中国第一汽车股份有限公司 filed Critical 中国第一汽车股份有限公司
Publication of WO2023066233A1 publication Critical patent/WO2023066233A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory

Definitions

  • the embodiments of the present application relate to the technical field of automation control, for example, a method, device, controller and storage medium for flashing a program of a controller.
  • Embedded controllers gradually enrich people's daily life, and embedded controllers need to write programs corresponding to functions before performing functions.
  • the embedded development engineer When writing the program into the controller, it is necessary for the embedded development engineer to manually write the program operating parameters such as the start address, code segment, data segment, calibration segment, and memory usage of the program.
  • This kind of controller development mode leads to cumbersome development process.
  • embedded development engineers need to repeatedly determine the operating parameters of the control program, which greatly affects Improve the development efficiency of the controller.
  • the embodiment of the present application provides a controller program flashing method, device, controller and storage medium, so as to realize accurate flashing of the program, reduce the test workload of operating parameters, and improve the stability of the controller operation.
  • An embodiment of the present application provides a method for flashing a program of a controller, the method comprising:
  • An embodiment of the present application provides a program flashing device for a controller, and the device includes:
  • the program receiving module is configured to obtain the program to be flashed according to the preset storage structure
  • a space information module configured to determine the running space occupancy information of the code content of the program to be flashed
  • the program flashing module is configured to write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
  • An embodiment of the present application provides a controller, and the controller includes:
  • memory configured to store one or more programs
  • the one or more central processors When the one or more programs are executed by the one or more central processors, the one or more central processors implement the program flashing method for the controller as described in the embodiment of the present application.
  • the embodiment of the present application provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a central processing unit, the method for flashing the program of the controller as described in the embodiment of the present application is implemented.
  • Fig. 1 is a flow chart of a program flashing method for a controller provided in Embodiment 1 of the present application;
  • Fig. 2 is a flow chart of a program flashing method for a controller provided in Embodiment 2 of the present application;
  • Fig. 3 is a flow chart of determining the memory usage of a code content provided in Embodiment 2 of the present application;
  • Fig. 4 is an implementation effect diagram of a program flashing method for a controller provided in Embodiment 2 of the present application;
  • FIG. 5 is an example diagram of a program flashing method for a controller provided in Embodiment 2 of the present application.
  • Fig. 6 is a structural block diagram of a program flashing device for a controller provided in Embodiment 3 of the present application;
  • FIG. 7 is a schematic structural diagram of a controller provided in Embodiment 4 of the present application.
  • Fig. 1 is a flow chart of a method for flashing a program of a controller provided in Embodiment 1 of the present application. This embodiment is applicable to the case of flashing a code of a controller.
  • the program flashing device executes, the device can be realized by software and/or hardware, and the device can be configured in the controller.
  • a program flashing method for a controller includes the following steps:
  • the preset storage structure may be a data structure for storing the program to be flashed, and the data structure may store a code segment, a data segment, a calibration segment and a data segment of the interrupt memory size of the flashing program.
  • the embodiment of the present application does not limit the type of stored data.
  • the program to be flashed may be a program to realize the function of the controller, for example, a code to realize the function of updating or deleting the controller, and the embodiment of the present application does not limit the functions realized by the program to be flashed.
  • the preset storage structure may include a code segment, a data segment, a calibration segment, and a data segment of the interrupt memory size.
  • the code of the program to be flashed may be stored in the code segment
  • the global variable can be stored in the data segment
  • the calibration value can be stored in the calibration segment
  • the interrupt data can be stored in the data segment of the interrupt memory size.
  • the code content can be the program text that constitutes the processing logic of the program to be flashed, and can include global variables, calibration quantities, and interrupts.
  • the running space occupation information may reflect the size of the memory space required by the above-mentioned code content when the program is running, and may include the information of the memory stored in the program to be flashed and the memory information occupied by the program when running.
  • the information of the memory stored in the program to be flashed can be determined through the code segment stored in the pre-storage structure, as well as the data segment, calibration segment and interrupt memory size data stored in the pre-storage structure Sections determine the information occupied by global variables, calibration quantities, interrupts, etc. when the program is running.
  • the memory occupied by the global variable at runtime may be 10 bytes. If there are 8 calibration quantities in the code content of the program to be flashed, and the memory size occupied by each calibration quantity at runtime can be up to 2 bytes, then the memory occupied by the calibration quantity of the program to be flashed at runtime The size can be 8*2 bytes, which is 16 bytes.
  • the depth of the interrupt in the code content of the program to be flashed is 2, and the memory size occupied by an interrupt at runtime can be 10 kilobytes (Kbytes, KB), then the interrupt in the code content of the program to be flashed is The memory size occupied by the runtime can be 2*10KB, that is, 20KB.
  • An address can refer to a number that can identify a part of a space.
  • the starting address for flashing may be the starting address for storing the program to be flashed in the memory space, and the starting address for flashing may point to an unoccupied area in the memory space.
  • the running space occupation information may represent information on the memory space used by the program to be flashed, and may include information on the size of the space stored by the program to be flashed and information on the size of the space occupied by the program when it is running.
  • the memory space may be a storage area in the controller, and the memory space may be used to save programs and data when the process is running.
  • the memory space can be an area in the unoccupied memory space or an area in the occupied memory space.
  • the program to be flashed can be written to any location in the memory space, and the size of the memory space is sufficient for the complete and accurate storage of the program to be flashed.
  • the area to be written by the program to be flashed may be the frontmost area of the memory space
  • the start address of the program to be flashed in the memory space may be 0,
  • the end address of the program to be flashed in the memory space may be The sum of 0 and the value of the memory space size corresponding to the running space occupation information of the program to be flashed.
  • the area to be written by the program to be flashed can be the last area of the memory space, and the last area can completely and accurately store the program to be flashed, and the starting address of the program to be flashed in the memory space can be the memory The end address of the space minus the size of the memory space corresponding to the running space occupation information of the program to be flashed.
  • the program to be flashed after determining the running space occupation information of the program to be flashed, the program to be flashed can be written into the memory space from the flashing start address of the program to be flashed, and according to the flashing start address
  • the storage location of the program to be flashed in the memory space can be accurately controlled, the accuracy of the program flashing control can be improved, the space waste of the memory space can be reduced, and the degree of fragmentation of the memory space can be reduced.
  • the running space occupation information of the code content of the program to be flashed is determined, and then based on the flashing start address and the running space occupied information, the The program to be flashed is written into the memory space pointed to by the flashing start address.
  • the program to be flashed is written into the memory space based on the estimated running memory size and starting address of the program to be flashed, which effectively saves memory space and can improve the success rate of program flashing, thereby Improving the stability of the controller operation can reduce the test time for determining the operating parameters of the program to be flashed, and improve the development efficiency of the controller.
  • the method further includes: updating the flashing start address according to the running space occupation information of the program to be flashed.
  • the sum of the values of the initial address of the flashing and the size of the memory space corresponding to the running space occupation information of the program to be flashed can be It is recorded as the flashing end address, and the original flashing start address can be updated with the flashing end address.
  • the end address of flashing can be reduced by 1 as a new start address of flashing, and for a memory stored in little endian, the end address of flashing can be added by 1 as a new start address of flashing.
  • Fig. 2 is a flow chart of a method for flashing a program of a controller provided in Embodiment 2 of the present application, and the embodiment of the present application is described based on the foregoing embodiments.
  • a method for flashing a controller program provided by Embodiment 2 of the present application includes the following steps:
  • S210 call the data structure class to receive and store the code segment, data segment, calibration segment and interrupt data of the program to be flashed.
  • the data structure class can be program processing logic for receiving and storing data according to different data structures, such as get() and set() methods that can be written in a programming language, and can be used to access the properties of the program to be flashed and/or method.
  • the method name of the specific data structure class can be defined by yourself.
  • the code segments may be different logic codes corresponding to the flashing program data structure.
  • the data segment may be a data area required for running the flashed program, and the data segment is composed of global variables in different codes of the flashed program.
  • the calibration section may be a calibration section composed of calibration quantities in different codes of the flashing program. Interruption can mean that during the operation of the computer, when an unexpected situation occurs that requires the intervention of the host, the machine can automatically stop the running program and switch to the program that handles the new situation. After the new situation is processed, it returns to the original suspended program to continue running. Exemplarily, each code has a different execution sequence. When the current code is executed, another code is executed. Then the situation at this time is interrupted for the current code. However, the current code needs to be saved to save the current code. After another code is executed, it can return to continue executing the current code. Then the size of the space required by the interrupt code can be the interrupt data.
  • Different data structures have different data structure classes for pre-flashing.
  • different data structure classes can be called in turn to process the code to be flashed, and obtain and store the code segment of the code to be flashed. , data segment, calibration segment, and interrupt data structures.
  • the data structure class can be flashed in the controller in advance, and the data structure class is called and executed when the program to be flashed is written.
  • Code text may refer to the source code in a program, the processing logic with which the function is performed, and code text may be human-readable text written in a programming language.
  • Global variables are external variables defined outside the function. Global variables can be created by object functions or anywhere in the program. Global variables can be referenced by all objects or functions of the program to be flashed. A scalar can be understood as a constant, and a constant can refer to a quantity that will not be modified by the program when the computer program is running. Interruption can mean that the program to be flashed is running, and the codes of the program to be flashed have different execution sequences. When the current code is executed, another code is executed, so the situation at this time is interrupted for the current code.
  • the code content of the program to be flashed can be extracted, and the code text, global variables, calibration quantities, interrupts and other content in the code content can be extracted. It can be understood that the code content can be read into the register of the controller in advance, and the code content can be read by operating the register.
  • the memory usage can be the memory overhead required to support the storage and operation of flashing programs, and the corresponding memory usage can be estimated for code text, global variables, calibration quantities, and interrupts, and the determined memory usage can be used as a pending Flash the running space occupation information of the program.
  • the code written in a programming language can be used to read the number of meaningful lines of all codes in the program to be flashed, and then calculate the required memory space after conversion into a binary file, and use it as the memory usage of the code text.
  • the number of meaningful lines of all codes in the program to be flashed can be 100 lines, and the maximum memory space size of each line can be 1KB.
  • the memory space required after converting all the codes in the program to be flashed into binary files can be 100KB. It is also possible to read all the global variables in the program to be flashed through the code written in the programming language.
  • the memory space required by all global variables in the program to be flashed can be 2KB. It is also possible to read all the calibration quantities in the program to be flashed through the code written in the programming language. For example, if there are 2 calibration quantities to be read in the program to be flashed, if the memory space required for the largest of all calibration quantities is 1KB, then the memory space required for all calibration quantities in the program to be flashed can be 2KB .
  • the priority of the interrupt vector table set in the program to be flashed is also possible to read the priority of the interrupt vector table set in the program to be flashed, the parameters involved in the function in the code, and the memory size required when the temporary variable is triggered and interrupted by the code written in the programming language. All the interrupts in the program to be flashed are stored in the interrupt vector table. If the highest priority in the interrupt vector table is 8, it can be considered that the deepest number of interrupt layers in the interrupt vector table is 8, and the interrupt layer with the deepest number of interrupt layers needs to be The interrupt memory size of the program is used as the benchmark value of the interrupt memory size required by the program to be flashed. Due to the interrupt, the memory size required by the parameters involved and temporary variables can be 2KB, and the memory occupation required by the interrupt in the program to be flashed The size is 16KB.
  • the memory space size required by code text, global variables, calibration quantities and interrupts can be expressed as the memory footprint required by code text, global variables, calibration quantities and interrupts, and the code text, global variables, calibration quantities The sum of the memory usage required by the interrupt and the interrupt is used as the running space occupation information.
  • the remaining space in the memory space may be space that has not been occupied in the memory space.
  • the preset area can be a pre-agreed memory area in the memory space for storing the start address of flashing.
  • the preset area can be located at the beginning or end of the memory space, or it can be a memory area corresponding to a fixed address in the memory space.
  • the flashing start address in the setting area can be used to identify the location of the remaining space in the memory space.
  • the flashing start when the remaining space is greater than the size of the memory space corresponding to the running space occupation information of the program to be flashed, it can be determined that the remaining space meets the running space occupation information, and the flashing start can be read in the preset area. address, you can use the flashing start address as the starting point to sequentially flash the data of the code to be flashed to the memory space.
  • the flashing failure information when the remaining space is smaller than the size of the memory space corresponding to the running space occupation information of the program to be flashed, it can be determined that the remaining space does not meet the running space occupied information, and the flashing failure information is generated and fed back, for example, generating
  • the flashing failure information may be information such as "current chip performance is insufficient", and the failure information is returned to the user.
  • the technical solution of the embodiment of the present application receives and stores the code segment, data segment, calibration segment and interrupt data of the program to be flashed by calling the data structure class, and reads the code text, global Variables, calibrations and interrupts, and then use the code text, global variables, calibrations and interrupts as the running space occupation information to calculate the running memory space required by the program to be flashed; and through the calculated to-be
  • the size of the running memory space required to flash the program is compared with the remaining space in the memory space. If the remaining space of the memory space meets the size of the running memory space required by the program to be flashed, the program to be flashed is written into the memory space to Guarantee the correct flashing of the program to be flashed. If it is judged that the remaining space of the memory space does not meet the size of the running memory space required by the program to be flashed, the flashing failure information will be given for the user to readjust according to the flashing failure information. Work.
  • Fig. 3 is a flow chart of determining the memory usage of a code content provided by Embodiment 2 of the present application. Referring to Fig. 3, in the embodiment of the present application, the memory usage of the code text, global variables, calibrations and interrupts are respectively determined, including :
  • S2301. Determine the number of effective code lines of the code text, and use the product of the number of effective code lines and the space occupation coefficient of the code lines as the memory usage of the code text.
  • the number of effective code lines can refer to the number of lines of logic codes with actual meaning in the program to be flashed, which can be obtained by subtracting the number of blank lines from the total number of lines of all codes and then subtracting the number of comment lines.
  • the number of valid code lines in the code text may not include the number of blank lines and comment lines.
  • the code line space occupation coefficient can refer to the maximum length of the memory space occupied by each line of code, which can be set according to the developer's experience, or can be determined by the average memory occupation length of the binary line code of the program to be flashed, which can be determined more reasonably The memory footprint of code text.
  • the number of effective code lines in the code text can be counted, and the code line space occupation coefficient can be extracted, the product of the effective code line number and the code line space occupation coefficient can be determined, and the product can be used as the memory of the code text occupancy.
  • the total number of lines of code text is 500 lines, including 20 lines of comments and blank lines
  • the effective number of code lines of code text is 480 lines
  • the average memory occupation length of the binary line code of the program to be flashed can be 2KB
  • the memory usage of the code text is the product of the number of effective code lines and the space occupation coefficient of the code lines, that is, the memory usage of the code text is 960KB.
  • S2302 determine the data structure corresponding to each global variable in all global variables and the data structure corresponding to each calibration quantity in all calibration quantities, and use the sum of all data structures corresponding to all global variables as the memory usage of all global variables , and, the sum of all data structures corresponding to all calibration quantities is used as the memory usage of all calibration quantities.
  • the data structure can reflect the information of the global variable and the data type of the calibration quantity.
  • the length of the memory space occupied by different data structures can be different.
  • there are 2 global variables in the program to be flashed and the data structures of the 2 global variables are respectively Integer and character type
  • the length of the memory space required for integer storage can be 4 bytes
  • the length of the memory space required for character type storage can be 2 bytes
  • the memory usage of global variables can be 4 bytes and 2 bytes
  • the sum of bytes, that is, the memory footprint of a global variable can be 6 bytes.
  • the calibration quantity includes 3 integers
  • the sum of the memory footprint required by the structure is the memory footprint of all global variables, and the sum of all data structures corresponding to all calibration quantities can be used as the memory footprint of all calibration quantities.
  • Interruption can mean that during the normal execution of the program, the processor temporarily interrupts the currently running program due to internal or external event triggers or pre-arranged by the program, and then transfers to execute the internal or external event or program pre-arranged.
  • the service subroutine of the arranged event after the execution of the interrupt service subroutine, the processor returns to the temporarily interrupted program (breakpoint) and continues to execute the original program. This process is called interruption.
  • the interrupt vector table can be regarded as storing all interrupt type codes in the system and all interrupt vectors corresponding to all interrupt type codes in a storage area according to certain rules. This storage area is called the interrupt vector table.
  • the interrupt type in the interrupt vector table The code can be an 8-bit binary number, which can be considered as the entry address of the interrupt service program. Among them, the deepest priority can be the priority corresponding to the highest priority interrupt type code of the code to be flashed, and the number of interrupts can be the Write the number of different interrupt type codes in the code.
  • the controller When the controller handles interrupts, it responds to higher-level interrupt requests and shields interrupt requests of the same level or lower levels. Therefore, the memory usage of interrupts is related to the number of interrupts and the priority of interrupts, and the number of interrupts can be used
  • the product of the interrupt priority determines the memory footprint of the interrupt. Exemplarily, if there are 8 interrupt priorities, the deepest priority of the interrupt can be the highest priority, and the memory occupied by the program of this priority can be 10KB, then the memory size corresponding to the deepest priority interrupt and the interrupt
  • the product of the number of interrupts is used as the memory usage of the interrupt, that is, the memory usage of the interrupt is 80KB.
  • the product of the number of effective code lines and the space occupation coefficient of code lines is used as the memory usage of the code text
  • the sum of all data structures corresponding to all global variables is used as the memory usage of all global variables
  • the sum of all data structures corresponding to all calibration quantities is used as the memory usage of multiple calibration quantities
  • the product of the memory size corresponding to the deepest priority interrupt and the number of interrupts is taken as the interrupt memory usage, which can effectively calculate the code text
  • the memory usage of the program, the memory usage of the global variable, the memory usage of the calibration amount, and the memory usage of the interrupt can effectively calculate the memory usage of the program to be flashed.
  • Fig. 4 is the implementation effect diagram of the program flashing method of a kind of controller provided by the embodiment of the present application, as shown in Fig. 4, the integral class that realizes the program flashing method of the present application includes MCUStruct_Class class, ReadMCU class , Disposition_Chip class and Generation_LinkFile class.
  • the MCUStruct_Class class is a data structure class.
  • the MCUStruct_Class class can be used to receive and store the code segment, data segment, calibration segment and interrupt memory size data in the program to be flashed.
  • Use the get_CodeSize() function in this class to obtain the value of the code segment of the program to be flashed, use the set_CodeSize() function in this class to set the value of the code segment of the program to be flashed; use the get_DataSize() function in this class to obtain For the value of the data segment of the program to be flashed, use the set_DataSize() function in this class to set the value of the data segment of the program to be flashed; use the get_Calib_DataSize() function in this class to obtain the value of the calibration segment of the program to be flashed, Use the set_Calib_DataSize() function in this class to set the value of the calibration segment of the program to be flashed; use the get_Interrupt_Memen
  • ReadMCU class this class can be used to read all the codes in the program to be flashed, and then calculate the memory size required by all the current codes, and can also read the memory space required by all global variables and the memory space required by all calibration quantities size and the amount of memory space required by the current code in the event of an interrupt.
  • the Cal_CodeSize() function in this class reads the number of meaningful lines of all codes in the current program, and then calculates the size of the memory space required after converting to a binary file;
  • the Cal_DataSize() function in this class reads the code to be written Global variables in the program, calculate the size of the memory space required by the global variables
  • the Cal_Calib_DataSize() function can read the calibration amount of the program to be flashed, and calculate the memory space size required by the calibration amount
  • the Cal_Interrupt_Memory_Size() function reads the size of the memory space to be flashed Write the priority of the interrupt vector table set in the program, calculate the priority of the interrupt vector table set in the program to be flashed, the parameters involved in the function, and the size of the memory space required when the temporary variable involved in the function is triggered and interrupted.
  • Disposition_Chip class which stores the start and end address information related to the specific pflash and dflash of the current chip. Use the set_ChipSetting() function in this class to set the specific pflash and dflash related start and stop address values of the current chip, and use the get_ChipSetting() function in this class to obtain the current chip specific pflash and dflash related start and stop address values.
  • Generation_LinkFile class this class calculates the memory size data required by the program to be flashed according to the ReadMCU class and obtains the chip data according to the Disposition_Chip class, and generates a LinkFile file.
  • the Generation_File() function in this class writes the program to be flashed into pflash according to the start address and size of the current chip pflash and the end address of the bootloader, and writes the program to be flashed according to the start address and size of dflash Write the global variables, calibration values and interrupts in dflash, and ensure that the addresses are continuous to reduce space fragmentation.
  • Fig. 5 is an example diagram of a program flashing method of a controller provided by the embodiment of the present application.
  • the program flashing in the controller may include the following steps: first, configure the memory size of the current chip pflash and dflash and start Then read all the source code of the program to be flashed, and judge whether the source code of the program to be flashed is empty. If the source code of the program to be flashed is empty, print that the code of the program to be flashed is empty and end the entire process.
  • the source code of the program to be flashed is not empty, then calculate the occupied space required for the program code to be flashed, calculate the occupied space required for global variables in the program to be flashed, and calculate the occupied space required for the calibration amount in the program to be flashed Space size and estimate the occupied space required for interrupts in the program to be flashed, then calculate the sum of the memory space required by the program to be flashed, and compare the sum of the required memory space with the pfash and dflash of the current chip Compare and judge whether the sum of the memory space required by the program to be flashed exceeds the chip size. If it exceeds the chip size, it will print that the current chip performance is insufficient and end the entire process. If it does not exceed the chip size, generate the corresponding LinkFile file , and end the entire process.
  • Fig. 6 is a structural block diagram of a program flashing device for a controller provided in Embodiment 3 of the present application.
  • the device can execute the program flashing method for a controller provided in any embodiment of the present application, and has corresponding functional modules for executing the method and effects.
  • the device is configured in the controller to implement the program flashing method of the controller in the embodiment of the present application.
  • the device includes: a program receiving module 610 , a spatial information module 620 and a program flashing module 630 .
  • the program receiving module 610 is configured to obtain the program to be flashed according to the preset storage structure.
  • the space information module 620 is configured to determine the running space occupation information of the code content of the program to be flashed.
  • the program flashing module 630 is configured to write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
  • the program receiving module obtains the program to be flashed according to the preset storage structure
  • the space information module determines the running space occupation information of the code content of the program to be flashed
  • the program flashing module starts based on the flashing Write the program to be flashed into the memory space according to the starting address and the running space occupation information.
  • the above technical solution writes the program to be flashed into the memory space based on the estimated running memory size and starting address of the program to be flashed, which effectively saves memory space, improves the success rate of program flashing, and thereby improves control
  • the stability of the operation of the controller can reduce the test time for determining the operating parameters of the program to be flashed, and can improve the development efficiency of the controller.
  • the program receiving module 610 is configured to: call the data structure class to receive and store the code segment, data segment, calibration segment and interrupt data of the program to be flashed.
  • the spatial information module 620 includes a code reading unit and a memory determining unit.
  • the code reading unit is configured to read the code content of the program to be flashed, wherein the code content includes: code text, global variables, calibration quantities and interrupts.
  • the memory determination unit is configured to respectively determine the memory usage of the code text, the memory usage of the global variable, the memory usage of the calibration amount and the memory usage of the interrupt, and combine the memory usage of the code text, the memory usage of the The memory usage of the global variable, the memory usage of the calibration amount and the memory usage of the interrupt are used as the running space usage information.
  • the number of the global variable is at least one
  • the number of the calibration quantity is at least one
  • the memory determination unit includes a row number determination subunit, a structure determination subunit and a search subunit.
  • the line number determination subunit is configured to determine the effective code line number of the code text, and use the product of the effective code line number and the code line space occupation coefficient as the memory footprint of the code text.
  • the structure determination sub-unit is configured to determine the data structure corresponding to each global variable in all global variables and the data structure corresponding to each calibration quantity in all the calibration quantities, and the data structure corresponding to all the data structures corresponding to all global variables The sum is used as the memory usage of all global variables, and the sum of all data structures corresponding to all calibrations is used as the memory usage of all calibrations.
  • the search subunit is configured to search the deepest priority of the interrupt in the preset interrupt vector table, and use the product of the memory size corresponding to the deepest priority interrupt and the number of interrupts as the memory occupation of the interrupt quantity.
  • the code line space occupation coefficient includes: the average memory occupation length of the binary line codes of the program to be flashed.
  • the program flashing module 630 is configured to: determine whether the remaining space of the memory space satisfies the operating space occupancy information; in response to the determination result that the remaining space of the memory space satisfies the operating space occupancy information, Read the flash start address of the program to be flashed in the preset area of the memory space, and write the program to be flashed into the memory space according to the flash write start address; in response to the If the remaining space of the above memory space does not meet the determination result of the operation space occupation information, the flashing failure information is generated and fed back.
  • an update module is further included, configured to update the flashing start address according to the running space occupation information of the program to be flashed.
  • the above-mentioned products can execute the program flashing method of the controller provided in the embodiment of the present application, and have corresponding functional modules and effects for executing the method.
  • Embodiment 4 of the present application provides a controller.
  • FIG. 7 is a schematic structural diagram of a controller provided in Embodiment 4 of the present application.
  • this embodiment provides a controller, which may include: a central processing unit and a memory. At least one instruction is stored in the memory, and the instruction is executed by the central processing unit, so that the controller executes the method for flashing the program of the controller as described in the above method embodiment.
  • this controller can comprise: central processing unit 720, memory 710, input device 730 and output device 740;
  • the quantity of central processing unit 720 in this controller can be one or more, in Fig.
  • the controller 720 is taken as an example; the number of memory 710 in the controller may be one or more, and one memory 710 is taken as an example in FIG. 7 .
  • the central processing unit 720, the memory 710, the input device 730 and the output device 740 in the controller can be connected through a bus or in other ways. In FIG. 7, connection through a bus is taken as an example.
  • the central processing unit 720 executes one or more programs stored in the memory 710, the following operations can be implemented: obtain the program to be flashed according to the preset storage structure; determine the running space of the code content of the program to be flashed occupancy information: write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
  • the controller program flashing method, device, controller, and storage medium provided in the above embodiments can execute the controller program flashing method provided in any embodiment of the present application, and have corresponding functional modules and effects for executing the method.
  • the method for flashing the program of the controller provided in any embodiment of the present application.
  • Embodiment 5 of the present application provides a computer-readable storage medium on which a program is stored.
  • the method for flashing the program of the controller as provided in all the invention embodiments of the present application is implemented.
  • the method includes : Acquiring the program to be flashed according to the preset storage structure; determining the running space occupancy information of the code content of the program to be flashed; writing the program to be flashed based on the starting address of the flashing and the running space occupancy information memory space.
  • the computer storage medium in the embodiments of the present application may use any combination of one or more computer-readable media.
  • the computer readable medium may be a computer readable signal medium or a computer readable storage medium.
  • a computer readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of systems, devices, or devices.
  • the computer-readable storage medium may include: an electrical connection having one or more conductors, a portable computer disk, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an erasable Type programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM) or flash memory, optical fiber, portable compact disk read-only memory (Compact Disc Read-Only Memory, CD-ROM), optical storage device, magnetic storage device, or the above any combination of .
  • a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
  • a computer-readable signal medium may include a data signal in baseband or propagated as a carrier wave, and the computer-readable signal medium carries computer-readable program code thereon. Such propagated data signals may take many forms, including - but not limited to - electromagnetic signals, optical signals, or any combination of the foregoing.
  • a computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can be sent, propagated, or transported for use by or in conjunction with an instruction execution system, apparatus, or device. Programs used in conjunction with the device.
  • the program code contained on the computer readable medium can be transmitted by any medium, including—but not limited to—wireless, electric wire, optical cable, radio frequency (Radio Frequency, RF), etc., or any combination of the above.
  • Computer program code for carrying out the operations of the present application may be written in one or more programming languages, including object-oriented programming languages—such as Java, Smalltalk, C++, as well as conventional procedural programming languages Design Language—such as "C” or a similar programming language.
  • the program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server.
  • the remote computer can be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or it can be connected to an external computer ( For example, use an Internet service provider to connect via the Internet).
  • LAN Local Area Network
  • WAN Wide Area Network

Abstract

Disclosed in the present application are a program flashing method and apparatus for a controller, and a controller and a storage medium. The method comprises: according to a preset storage structure, acquiring a program to be flashed; determining running space occupation information of code content of said program; and writing said program into a memory space on the basis of a flashing start address and the running space occupation information.

Description

控制器的程序刷写方法、装置、控制器和存储介质Controller program flashing method, device, controller and storage medium
本申请要求在2021年10月18日提交中国专利局、申请号为202111208423.9的中国专利申请的优先权,该申请的全部内容通过引用结合在本申请中。This application claims priority to a Chinese patent application with application number 202111208423.9 filed with the China Patent Office on October 18, 2021, the entire contents of which are incorporated herein by reference.
技术领域technical field
本申请实施例涉及自动化控制技术领域,例如涉及控制器的程序刷写方法、装置、控制器和存储介质。The embodiments of the present application relate to the technical field of automation control, for example, a method, device, controller and storage medium for flashing a program of a controller.
背景技术Background technique
嵌入式控制器逐渐丰富人们的日常生活,嵌入式控制器在执行功能前需要写入功能对应的程序。在将程序写入控制器时,需要由嵌入式开发工程师人为写入程序的起始地址、代码段、数据段、标定段以及内存占用等程序运行参数。这种控制器的开发模式导致开发过程繁琐,即使针对相同硬件设备刷写不同的控制程序,也需要确定控制程序对应的运行参数,导致嵌入式开发工程师需要反复确定控制程序的运行参数,大大影响了控制器的开发效率。Embedded controllers gradually enrich people's daily life, and embedded controllers need to write programs corresponding to functions before performing functions. When writing the program into the controller, it is necessary for the embedded development engineer to manually write the program operating parameters such as the start address, code segment, data segment, calibration segment, and memory usage of the program. This kind of controller development mode leads to cumbersome development process. Even if different control programs are written for the same hardware device, it is necessary to determine the corresponding operating parameters of the control program. As a result, embedded development engineers need to repeatedly determine the operating parameters of the control program, which greatly affects Improve the development efficiency of the controller.
发明内容Contents of the invention
本申请实施例提供了一种控制器的程序刷写方法、装置、控制器和存储介质,以实现程序的准确刷写,可减少运行参数的测试工作量,提高控制器运行的稳定性。The embodiment of the present application provides a controller program flashing method, device, controller and storage medium, so as to realize accurate flashing of the program, reduce the test workload of operating parameters, and improve the stability of the controller operation.
本申请实施例提供了一种控制器的程序刷写方法,所述方法包括:An embodiment of the present application provides a method for flashing a program of a controller, the method comprising:
根据预设存储结构获取待刷写程序;Obtain the program to be flashed according to the preset storage structure;
确定所述待刷写程序的代码内容的运行空间占用信息;Determine the running space occupancy information of the code content of the program to be flashed;
基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。Writing the program to be flashed into memory space based on the flashing start address and the running space occupation information.
本申请实施例提供了一种控制器的程序刷写装置,所述装置包括:An embodiment of the present application provides a program flashing device for a controller, and the device includes:
程序接收模块,设置为根据预设存储结构获取待刷写程序;The program receiving module is configured to obtain the program to be flashed according to the preset storage structure;
空间信息模块,设置为确定所述待刷写程序的代码内容的运行空间占用信息;A space information module, configured to determine the running space occupancy information of the code content of the program to be flashed;
程序刷写模块,设置为基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。The program flashing module is configured to write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
本申请实施例提供了一种控制器,所述控制器包括:An embodiment of the present application provides a controller, and the controller includes:
一个或多个中央处理器;one or more central processing units;
存储器,设置为存储一个或多个程序;memory configured to store one or more programs;
当所述一个或多个程序被所述一个或多个中央处理器执行时,所述一个或多个中央处理器实现如本申请实施例所述的控制器的程序刷写方法。When the one or more programs are executed by the one or more central processors, the one or more central processors implement the program flashing method for the controller as described in the embodiment of the present application.
本申请实施例提供了一种计算机可读存储介质,其上存储有程序,所述程序被中央处理器执行时实现如本申请实施例所述的控制器的程序刷写方法。The embodiment of the present application provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a central processing unit, the method for flashing the program of the controller as described in the embodiment of the present application is implemented.
附图说明Description of drawings
图1是本申请实施例一提供的一种控制器的程序刷写方法的流程图;Fig. 1 is a flow chart of a program flashing method for a controller provided in Embodiment 1 of the present application;
图2是本申请实施例二提供的一种控制器的程序刷写方法的流程图;Fig. 2 is a flow chart of a program flashing method for a controller provided in Embodiment 2 of the present application;
图3是本申请实施例二提供的一种代码内容的内存占用量确定的流程图;Fig. 3 is a flow chart of determining the memory usage of a code content provided in Embodiment 2 of the present application;
图4是本申请实施例二提供的一种控制器的程序刷写方法的实现效果图;Fig. 4 is an implementation effect diagram of a program flashing method for a controller provided in Embodiment 2 of the present application;
图5是本申请实施例二提供的一种控制器的程序刷写方法的示例图;FIG. 5 is an example diagram of a program flashing method for a controller provided in Embodiment 2 of the present application;
图6是本申请实施例三提供的一种控制器的程序刷写装置的结构框图;Fig. 6 is a structural block diagram of a program flashing device for a controller provided in Embodiment 3 of the present application;
图7是本申请实施例四提供的一种控制器的结构示意图。FIG. 7 is a schematic structural diagram of a controller provided in Embodiment 4 of the present application.
具体实施方式Detailed ways
下面结合附图和实施例对本申请作说明。可以理解的是,此处所描述的具体实施例仅仅用于解释本申请,而非对本申请的限定。另外还需要说明的是,附图中仅示出了与本申请相关的部分而非全部结构。The application will be described below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present application, but not to limit the present application. In addition, it should be noted that the drawings only show some structures related to the present application but not all structures.
一些示例性实施例被描述成作为流程图描绘的处理或方法。虽然流程图将多个步骤描述成顺序的处理,但是其中的许多步骤可以被并行地、并发地或者同时实施。此外,多个步骤的顺序可以被重新安排。Some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe steps as sequential processing, many of the steps may be performed in parallel, concurrently, or simultaneously. Additionally, the order of various steps may be rearranged.
实施例一Embodiment one
图1是本申请实施例一提供的一种控制器的程序刷写方法的流程图,本实施例可适用于控制器刷写代码的情况,该方法可以由本申请实施例所提供的控制器的程序刷写装置执行,该装置可以由软件和/或硬件的方式来实现,该装置可配置于控制器中。Fig. 1 is a flow chart of a method for flashing a program of a controller provided in Embodiment 1 of the present application. This embodiment is applicable to the case of flashing a code of a controller. The program flashing device executes, the device can be realized by software and/or hardware, and the device can be configured in the controller.
如图1所示,本申请实施例提供的一种控制器的程序刷写方法包括如下步骤:As shown in FIG. 1 , a program flashing method for a controller provided in an embodiment of the present application includes the following steps:
S110、根据预设存储结构获取待刷写程序。S110. Obtain a program to be flashed according to a preset storage structure.
预设存储结构可以是用于存储待刷写程序的数据结构,该数据结构存储的可以是刷写程序的代码段、数据段、标定段和中断内存大小的数据段。本申请实施例对存储的数据的种类不作限制。The preset storage structure may be a data structure for storing the program to be flashed, and the data structure may store a code segment, a data segment, a calibration segment and a data segment of the interrupt memory size of the flashing program. The embodiment of the present application does not limit the type of stored data.
待刷写程序可以是实现控制器功能的程序,例如,实现控制器更新功能或者删除功能等的代码,本申请实施例对待刷写程序实现的功能不作限制。The program to be flashed may be a program to realize the function of the controller, for example, a code to realize the function of updating or deleting the controller, and the embodiment of the present application does not limit the functions realized by the program to be flashed.
在本申请实施例中,预设存储结构可以包括代码段、数据段、标定段和中断内存大小的数据段,在接收到待刷写程序后,可以将待刷写程序的代码存储到代码段,可以将全局变量存储到数据段,可以将标定量存储到标定段,可以将中断数据存储到中断内存大小的数据段。In the embodiment of the present application, the preset storage structure may include a code segment, a data segment, a calibration segment, and a data segment of the interrupt memory size. After receiving the program to be flashed, the code of the program to be flashed may be stored in the code segment , the global variable can be stored in the data segment, the calibration value can be stored in the calibration segment, and the interrupt data can be stored in the data segment of the interrupt memory size.
S120、确定待刷写程序的代码内容的运行空间占用信息。S120. Determine the running space occupation information of the code content of the program to be flashed.
代码内容可以是构成待刷写程序处理逻辑的程序文本,可以包括全局变量、标定量和中断等内容。运行空间占用信息可以是反映上述代码内容在程序运行时所需要的内存空间大小的信息,可以包括待刷写程序本身存储的内存的信息以及程序运行时占用的内存信息。The code content can be the program text that constitutes the processing logic of the program to be flashed, and can include global variables, calibration quantities, and interrupts. The running space occupation information may reflect the size of the memory space required by the above-mentioned code content when the program is running, and may include the information of the memory stored in the program to be flashed and the memory information occupied by the program when running.
在本申请实施例中,可以通过存储在预存储结构中的代码段确定待刷写程序本身存储的内存的信息,以及通过存储在预存储结构中的数据段、标定段和中断内存大小的数据段确定全局变量、标定量和中断等内容在程序运行时占用的信息。In the embodiment of this application, the information of the memory stored in the program to be flashed can be determined through the code segment stored in the pre-storage structure, as well as the data segment, calibration segment and interrupt memory size data stored in the pre-storage structure Sections determine the information occupied by global variables, calibration quantities, interrupts, etc. when the program is running.
示例性的,如果待刷写程序的代码内容中的全局变量有1个,该全局变量在运行时所占据的内存可以是10字节。如果待刷写程序的代码内容中的标定量有8个,每个标定量在运行时所占据的内存大小最大可以为2字节,那么待刷写程序的标定量在运行时所占据的内存大小可以是8*2字节,即16字节。如果待刷写程序的代码内容中的中断的深度为2,一个中断在运行时所占据的内存大小可以为10千字节(Kbytes,KB),那么待刷写程序的代码内容中的中断在运行时所占据的内存大小可以为2*10KB,即20KB。Exemplarily, if there is one global variable in the code content of the program to be flashed, the memory occupied by the global variable at runtime may be 10 bytes. If there are 8 calibration quantities in the code content of the program to be flashed, and the memory size occupied by each calibration quantity at runtime can be up to 2 bytes, then the memory occupied by the calibration quantity of the program to be flashed at runtime The size can be 8*2 bytes, which is 16 bytes. If the depth of the interrupt in the code content of the program to be flashed is 2, and the memory size occupied by an interrupt at runtime can be 10 kilobytes (Kbytes, KB), then the interrupt in the code content of the program to be flashed is The memory size occupied by the runtime can be 2*10KB, that is, 20KB.
S130、基于刷写起始地址和运行空间占用信息将待刷写程序写入内存空间。S130. Write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
地址可以指一种编号,可以标识空间中的部分区域。刷写起始地址可以是内存空间中存储待刷写程序的起始地址,该刷写起始地址可以指向内存空间中还未被占用的区域。运行空间占用信息可以表示待刷写程序运行使用的内存空间的信息,可以包括待刷写程序本身存储的空间大小的信息以及在程序运行时占用的空间大小的信息。内存空间可以是控制器中的存储区域,该内存空间可以用来保存进程运行时的程序和数据。内存空间,可以是在未被占用的内存空 间中的区域,也可以是在已经被占用的内存空间中的区域。待刷写程序可以写入内存空间的任意位置,并且内存空间的空间大小满足待刷写程序的完整准确存储。示例性的,待刷写程序写入的区域可以是内存空间的最前面的一块区域,待刷写程序在内存空间的起始地址可以为0,待刷写程序在内存空间的结束地址可以为0和待刷写程序的运行空间占用信息对应的内存空间大小的取值之和。又例如,待刷写程序写入的区域可以是内存空间的最后一块区域,并且该最后一块区域可以完整和准确存放该待刷写程序,待刷写程序在内存空间的起始地址可以是内存空间的终止地址减去待刷写程序的运行空间占用信息对应的内存空间大小。An address can refer to a number that can identify a part of a space. The starting address for flashing may be the starting address for storing the program to be flashed in the memory space, and the starting address for flashing may point to an unoccupied area in the memory space. The running space occupation information may represent information on the memory space used by the program to be flashed, and may include information on the size of the space stored by the program to be flashed and information on the size of the space occupied by the program when it is running. The memory space may be a storage area in the controller, and the memory space may be used to save programs and data when the process is running. The memory space can be an area in the unoccupied memory space or an area in the occupied memory space. The program to be flashed can be written to any location in the memory space, and the size of the memory space is sufficient for the complete and accurate storage of the program to be flashed. Exemplarily, the area to be written by the program to be flashed may be the frontmost area of the memory space, the start address of the program to be flashed in the memory space may be 0, and the end address of the program to be flashed in the memory space may be The sum of 0 and the value of the memory space size corresponding to the running space occupation information of the program to be flashed. For another example, the area to be written by the program to be flashed can be the last area of the memory space, and the last area can completely and accurately store the program to be flashed, and the starting address of the program to be flashed in the memory space can be the memory The end address of the space minus the size of the memory space corresponding to the running space occupation information of the program to be flashed.
在本申请实施例中,在确定待刷写程序的运行空间占用信息之后,可以从待刷写程序的刷写起始地址开始向内存空间内写入待刷写程序,根据刷写起始地址可以准确控制待刷写程序在内存空间中的存储位置,可提高程序刷写控制的准确性,减少内存空间的空间浪费,降低内存空间的碎片化程度。In the embodiment of the present application, after determining the running space occupation information of the program to be flashed, the program to be flashed can be written into the memory space from the flashing start address of the program to be flashed, and according to the flashing start address The storage location of the program to be flashed in the memory space can be accurately controlled, the accuracy of the program flashing control can be improved, the space waste of the memory space can be reduced, and the degree of fragmentation of the memory space can be reduced.
本申请实施例的技术方案,通过根据预设存储结构来获取待刷写程序,确定得到待刷写程序的代码内容的运行空间占用信息,然后,基于刷写起始地址和运行空间占用信息将待刷写程序写入该刷写起始地址指向的内存空间中。上述技术方案,采用基于预估待刷写程序的运行内存大小以及起始地址的方式将所述待刷写程序写入内存空间,有效节省了内存空间,可提高程序刷写的成功率,从而提高控制器运行的稳定性,可以减少确定待刷写程序运行参数的测试时间,提高控制器的开发效率。In the technical solution of the embodiment of the present application, by obtaining the program to be flashed according to the preset storage structure, the running space occupation information of the code content of the program to be flashed is determined, and then based on the flashing start address and the running space occupied information, the The program to be flashed is written into the memory space pointed to by the flashing start address. In the above technical solution, the program to be flashed is written into the memory space based on the estimated running memory size and starting address of the program to be flashed, which effectively saves memory space and can improve the success rate of program flashing, thereby Improving the stability of the controller operation can reduce the test time for determining the operating parameters of the program to be flashed, and improve the development efficiency of the controller.
在上述实施例基础上,在基于刷写起始地址和运行空间占用信息将待刷写程序写入内存空间之后,还包括:根据待刷写程序的运行空间占用信息更新刷写起始地址。On the basis of the above embodiments, after writing the program to be flashed into the memory space based on the flashing start address and the running space occupation information, the method further includes: updating the flashing start address according to the running space occupation information of the program to be flashed.
本申请实施例中,按照刷写起始地址将待刷写程序写入内存空间后,可以将刷写起始地址以及待刷写程序的运行空间占用信息对应的内存空间大小的取值之和记为刷写结束地址,可以使用刷写结束地址更新原有的刷写起始地址。例如,对于大端存储的内存,可以将刷写结束地址减1作为新的刷写起始地址,对于小端存储的内存可以将刷写结束地址加1作为新的刷写起始地址。In the embodiment of the present application, after the program to be flashed is written into the memory space according to the initial address of the flashing, the sum of the values of the initial address of the flashing and the size of the memory space corresponding to the running space occupation information of the program to be flashed can be It is recorded as the flashing end address, and the original flashing start address can be updated with the flashing end address. For example, for a big-endian memory, the end address of flashing can be reduced by 1 as a new start address of flashing, and for a memory stored in little endian, the end address of flashing can be added by 1 as a new start address of flashing.
实施例二Embodiment two
图2是本申请实施例二提供的一种控制器的程序刷写方法的流程图,本申请实施例以上述实施例为基础进行说明。如图2所示,本申请实施例二提供的一种控制器的程序刷写方法,包括如下步骤:Fig. 2 is a flow chart of a method for flashing a program of a controller provided in Embodiment 2 of the present application, and the embodiment of the present application is described based on the foregoing embodiments. As shown in Figure 2, a method for flashing a controller program provided by Embodiment 2 of the present application includes the following steps:
S210、调用数据结构类接收并存储待刷写程序的代码段、数据段、标定段以及中断数据。S210, call the data structure class to receive and store the code segment, data segment, calibration segment and interrupt data of the program to be flashed.
数据结构类可以是用于根据不同数据结构接收并存储数据的程序处理逻辑,例如可以利用编程语言编写的如get()和set()方法,可以用于访问待刷写程序的属性和/或方法。具体数据结构类的方法名,可以自己定义。The data structure class can be program processing logic for receiving and storing data according to different data structures, such as get() and set() methods that can be written in a programming language, and can be used to access the properties of the program to be flashed and/or method. The method name of the specific data structure class can be defined by yourself.
在本申请实施例中,代码段可以是刷写程序数据结构对应的不同逻辑代码。数据段可以是刷写的程序运行所需的数据区域,数据段由刷写程序的不同代码中的全局变量组成的。标定段可以是刷写程序的不同代码中的标定量组成的标定段。中断可以指计算机运行过程中,出现意外情况需要主机干预时,机器能自动停止正在运行的程序并转入处理新情况的程序,新情况处理完毕后又返回原被暂停的程序继续运行。示例性的,每个代码具有不同的执行顺序,在执行当前代码时,又执行另一个代码,那么此时的情况对于当前的代码来说就是中断,但是,需要把当前的代码保存起来,以供另一个代码执行完可以返回以继续执行当前代码。那么中断的代码所需要的空间大小可以是中断数据。In the embodiment of the present application, the code segments may be different logic codes corresponding to the flashing program data structure. The data segment may be a data area required for running the flashed program, and the data segment is composed of global variables in different codes of the flashed program. The calibration section may be a calibration section composed of calibration quantities in different codes of the flashing program. Interruption can mean that during the operation of the computer, when an unexpected situation occurs that requires the intervention of the host, the machine can automatically stop the running program and switch to the program that handles the new situation. After the new situation is processed, it returns to the original suspended program to continue running. Exemplarily, each code has a different execution sequence. When the current code is executed, another code is executed. Then the situation at this time is interrupted for the current code. However, the current code needs to be saved to save the current code. After another code is executed, it can return to continue executing the current code. Then the size of the space required by the interrupt code can be the interrupt data.
不同的数据结构预先刷写有不同的数据结构类,在进行待刷写程序的写入时,可以依次调用不同的数据结构类对待刷写代码进行处理,获取并存储待刷写代码的代码段、数据段、标定段以及中断数据等结构。数据结构类可以预先刷写在控制器中,在待刷写程序写入时数据结构类被调用执行。Different data structures have different data structure classes for pre-flashing. When writing the program to be flashed, different data structure classes can be called in turn to process the code to be flashed, and obtain and store the code segment of the code to be flashed. , data segment, calibration segment, and interrupt data structures. The data structure class can be flashed in the controller in advance, and the data structure class is called and executed when the program to be flashed is written.
S220、读取待刷写程序的代码内容,其中,代码内容包括:代码文本、全局变量、标定量和中断。S220. Read the code content of the program to be flashed, wherein the code content includes: code text, global variables, calibration quantities and interrupts.
代码文本可以指程序中的源代码,具有执行功能的处理逻辑,代码文本可以是用编程语言编写的人类可读文本。全局变量是在函数外部定义的外部变量,全局变量既可以是对象函数创建,也可以是在本程序任何地方创建。全局变量可以被该待刷写程序所有对象或函数引用。标量可以理解为常量,常量可以指在计算机程序运行时,不会被程序修改的量。中断可以指待刷写程序在运行中,待刷写程序的代码具有不同的执行顺序,在执行当前代码时,又执行另一个代码,那么此时的情况对于当前的代码来说就是中断。Code text may refer to the source code in a program, the processing logic with which the function is performed, and code text may be human-readable text written in a programming language. Global variables are external variables defined outside the function. Global variables can be created by object functions or anywhere in the program. Global variables can be referenced by all objects or functions of the program to be flashed. A scalar can be understood as a constant, and a constant can refer to a quantity that will not be modified by the program when the computer program is running. Interruption can mean that the program to be flashed is running, and the codes of the program to be flashed have different execution sequences. When the current code is executed, another code is executed, so the situation at this time is interrupted for the current code.
在本申请实施例中,可以提取待刷写程序的代码内容,并提取代码内容中的代码文本、全局变量、标定量和中断等内容。可以理解的是,代码内容可以预先读取到控制器的寄存器中,通过对寄存器的操作实现代码内容的读取。In the embodiment of the present application, the code content of the program to be flashed can be extracted, and the code text, global variables, calibration quantities, interrupts and other content in the code content can be extracted. It can be understood that the code content can be read into the register of the controller in advance, and the code content can be read by operating the register.
S230、分别确定代码文本的内存占用量、全局变量的内存占用量、标定量的内存占用量和中断的内存占用量,并将所述代码文本的内存占用量、所述全局变量的内存占用量、所述标定量的内存占用量和所述中断的内存占用量作为 运行空间占用信息。S230. Determine the memory usage of the code text, the memory usage of the global variable, the memory usage of the calibration amount, and the memory usage of the interrupt respectively, and calculate the memory usage of the code text and the memory usage of the global variable , the memory usage of the calibration amount and the memory usage of the interrupt are used as the running space usage information.
内存占用量可以是支持代刷写程序存储和运行所需要的内存开销,可以针对代码文本、全局变量、标定量和中断估算出各自对应的内存占用量,可以将确定出的内存占用量作为待刷写程序的运行空间占用信息。The memory usage can be the memory overhead required to support the storage and operation of flashing programs, and the corresponding memory usage can be estimated for code text, global variables, calibration quantities, and interrupts, and the determined memory usage can be used as a pending Flash the running space occupation information of the program.
示例性的,可以通过编程语言编写的代码读取待刷写程序中所有代码有意义的行数,然后计算出转换成二进制文件后所需要的内存空间大小,并作为代码文本内存占用量。例如,待刷写程序中所有代码有意义的行数可以为100行,每行的内存空间大小最大可以为1KB,那么待刷写程序中所有代码转换成二进制文件后所需要的内存空间大小可以为100KB。也可以通过编程语言编写的代码读取待刷写程序中所有全局变量。例如,如果读取待刷写程序中的所有全局变量有2个,所有全局变量中最大的所需的内存空间大小如果为1KB,那么待刷写程序中所有全局变量所需的内存空间可以为2KB。也可以通过编程语言编写的代码读取待刷写程序中所有标定量。例如,如果读取待刷写程序中所有标定量有2个,所有标定量中最大的所需的内存空间大小如果为1KB,那么待刷写程序中所有标定量所需的内存空间可以为2KB。也可以通过编程语言编写的代码读取待刷写程序中设置的中断向量表的优先级、该代码中的函数涉及的参数以及临时变量被触发中断时所需的内存大小。中断向量表中存放了待刷写程序中的所有中断,如果中断向量表中优先级最高的为8,则可以认为中断向量表中中断层数最深为8,并将中断层数最深的所需要的中断内存大小作为待刷写程序所需要的中断内存大小的基准值,由于中断,所涉及的参数以及临时变量所需的内存大小可以为2KB,则待刷写程序中中断所需要的内存占用量为16KB。另外,可以将代码文本、全局变量、标定量和中断所需的内存空间大小表述为代码文本、全局变量、标定量和中断所需的内存占用量,并可以将代码文本、全局变量、标定量和中断所需的内存占用量之和作为运行空间占用信息。Exemplarily, the code written in a programming language can be used to read the number of meaningful lines of all codes in the program to be flashed, and then calculate the required memory space after conversion into a binary file, and use it as the memory usage of the code text. For example, the number of meaningful lines of all codes in the program to be flashed can be 100 lines, and the maximum memory space size of each line can be 1KB. Then the memory space required after converting all the codes in the program to be flashed into binary files can be 100KB. It is also possible to read all the global variables in the program to be flashed through the code written in the programming language. For example, if there are 2 global variables to be read in the program to be flashed, if the largest memory space required by all global variables is 1KB, then the memory space required by all global variables in the program to be flashed can be 2KB. It is also possible to read all the calibration quantities in the program to be flashed through the code written in the programming language. For example, if there are 2 calibration quantities to be read in the program to be flashed, if the memory space required for the largest of all calibration quantities is 1KB, then the memory space required for all calibration quantities in the program to be flashed can be 2KB . It is also possible to read the priority of the interrupt vector table set in the program to be flashed, the parameters involved in the function in the code, and the memory size required when the temporary variable is triggered and interrupted by the code written in the programming language. All the interrupts in the program to be flashed are stored in the interrupt vector table. If the highest priority in the interrupt vector table is 8, it can be considered that the deepest number of interrupt layers in the interrupt vector table is 8, and the interrupt layer with the deepest number of interrupt layers needs to be The interrupt memory size of the program is used as the benchmark value of the interrupt memory size required by the program to be flashed. Due to the interrupt, the memory size required by the parameters involved and temporary variables can be 2KB, and the memory occupation required by the interrupt in the program to be flashed The size is 16KB. In addition, the memory space size required by code text, global variables, calibration quantities and interrupts can be expressed as the memory footprint required by code text, global variables, calibration quantities and interrupts, and the code text, global variables, calibration quantities The sum of the memory usage required by the interrupt and the interrupt is used as the running space occupation information.
S240、确定内存空间的剩余空间是否满足运行空间占用信息。S240. Determine whether the remaining space of the memory space satisfies the running space occupation information.
内存空间的剩余空间可以是内存空间中还没有被占用的空间。The remaining space in the memory space may be space that has not been occupied in the memory space.
可以将剩余空间与运行空间占用信息对应的内存空间进行比较,判断剩余空间与运行空间占用信息对应的内存空间之间的大小关系,可以根据不同的大小关系控制待刷写程序的写入过程,以实现待刷写代码的准确写入。You can compare the remaining space with the memory space corresponding to the running space occupation information, judge the size relationship between the remaining space and the memory space corresponding to the running space occupation information, and control the writing process of the program to be flashed according to different size relationships. In order to realize the accurate writing of the code to be flashed.
S250、若内存空间的剩余空间满足运行空间占用信息,则在内存空间的预设区域读取待刷写程序的刷写起始地址,并按照刷写起始地址将待刷写程序写入内存空间。S250. If the remaining space of the memory space satisfies the operating space occupation information, read the flashing start address of the program to be flashed in the preset area of the memory space, and write the program to be flashed into the memory according to the flashing start address space.
预设区域可以是内存空间中预先约定的用于存储刷写起始地址的内存区域, 预设区域可以位于内存空间的开头或者结尾,也可以是内存空间中一个固定地址对应的内存区域,预设区域中的刷写起始地址可以用于标识内存空间中剩余空间的所在位置。The preset area can be a pre-agreed memory area in the memory space for storing the start address of flashing. The preset area can be located at the beginning or end of the memory space, or it can be a memory area corresponding to a fixed address in the memory space. The flashing start address in the setting area can be used to identify the location of the remaining space in the memory space.
在本申请实施例中,当剩余空间大于待刷写程序的运行空间占用信息对应的内存空间大小时,可以确定剩余空间满足运行空间占用信息,可以在预设区域中读取到刷写起始地址,可以将该刷写起始地址作为起点依次将待刷写代码的数据刷写到内存空间。In the embodiment of the present application, when the remaining space is greater than the size of the memory space corresponding to the running space occupation information of the program to be flashed, it can be determined that the remaining space meets the running space occupation information, and the flashing start can be read in the preset area. address, you can use the flashing start address as the starting point to sequentially flash the data of the code to be flashed to the memory space.
需要说明的是,在进行待刷写代码的写入时,可以将待刷写代码中的不同内容分别刷写在内存空间的不同区域,例如,可以根据当前芯片的程序闪存(Program flash,Pflash)中的起始地址、大小以及启动加载(bootloader)的终止地址,设置待刷写程序的起始地址,以及根据当前芯片的数据闪存(Data flash,dflash)的起始地址和大小,对全局变量、标定量和中断写入的位置以及所需的空间进行设置,并确保地址连续,以减少空间的碎片化。并将待刷写程序的刷写起始地址与待刷写程序的运行空间占用信息对应的内存空间大小的取值之和记为刷写结束地址,并且刷写起始地址与刷写结束地址之间的地址是连续的。It should be noted that when writing the code to be flashed, different contents of the code to be flashed can be flashed in different areas of the memory space, for example, according to the program flash memory (Program flash, Pflash ) in the start address, size and end address of the bootloader (bootloader), set the start address of the program to be flashed, and according to the start address and size of the data flash (Data flash, dflash) of the current chip, set the global Variables, calibration quantities and interrupt write positions and required space are set, and the addresses are guaranteed to be continuous to reduce space fragmentation. And record the sum of the flashing start address of the program to be flashed and the memory space size corresponding to the running space occupation information of the program to be flashed as the flashing end address, and the flashing start address and the flashing end address The addresses between are consecutive.
S260、若内存空间的剩余空间不满足运行空间占用信息,则生成刷写失败信息并反馈。S260. If the remaining space of the memory space does not satisfy the running space occupancy information, generate flashing failure information and give feedback.
在本申请实施例中,当剩余空间小于待刷写程序的运行空间占用信息对应的内存空间大小时,可以确定剩余空间不满足运行空间占用信息,则生成刷写失败信息并反馈,比如,生成刷写失败信息可以为“当前芯片性能不足”等信息,并将失败信息返回给用户。In the embodiment of the present application, when the remaining space is smaller than the size of the memory space corresponding to the running space occupation information of the program to be flashed, it can be determined that the remaining space does not meet the running space occupied information, and the flashing failure information is generated and fed back, for example, generating The flashing failure information may be information such as "current chip performance is insufficient", and the failure information is returned to the user.
本申请实施例的技术方案,通过调用数据结构类来接收并存储待刷写程序的代码段、数据段、标定段以及中断数据,并读取待刷写程序的代码内容中的代码文本、全局变量、标定量和中断,然后将代码文本、全局变量、标定量和中断的内存占用量作为运行空间占用信息,以计算出待刷写程序所需的运行内存空间大小;以及通过计算出的待刷写程序所需的运行内存空间大小与内存空间的剩余空间相比较,若内存空间的剩余空间满足待刷写程序所需的运行内存空间大小,则将待刷写程序写入内存空间,以保证待刷写程序的正确刷写,若判断出内存空间的剩余空间不满足待刷写程序所需的运行内存空间大小,给予刷写失败的信息,以供用户可以根据刷写失败信息重新调整工作。The technical solution of the embodiment of the present application receives and stores the code segment, data segment, calibration segment and interrupt data of the program to be flashed by calling the data structure class, and reads the code text, global Variables, calibrations and interrupts, and then use the code text, global variables, calibrations and interrupts as the running space occupation information to calculate the running memory space required by the program to be flashed; and through the calculated to-be The size of the running memory space required to flash the program is compared with the remaining space in the memory space. If the remaining space of the memory space meets the size of the running memory space required by the program to be flashed, the program to be flashed is written into the memory space to Guarantee the correct flashing of the program to be flashed. If it is judged that the remaining space of the memory space does not meet the size of the running memory space required by the program to be flashed, the flashing failure information will be given for the user to readjust according to the flashing failure information. Work.
图3是本申请实施例二提供的一种代码内容的内存占用量确定的流程图,参见图3,本申请实施例中分别确定代码文本、全局变量、标定量和中断的内存占用量,包括:Fig. 3 is a flow chart of determining the memory usage of a code content provided by Embodiment 2 of the present application. Referring to Fig. 3, in the embodiment of the present application, the memory usage of the code text, global variables, calibrations and interrupts are respectively determined, including :
S2301,确定代码文本的有效代码行数,并将有效代码行数与代码行空间占用系数之积作为所述代码文本的内存占用量。S2301. Determine the number of effective code lines of the code text, and use the product of the number of effective code lines and the space occupation coefficient of the code lines as the memory usage of the code text.
有效代码行数可以指待刷写程序中具有实际含义的逻辑代码的行数,可以通过所有代码的总行数减去空行数再减去注释行数的方式获得。代码文本中的有效代码行数可以不包括空行数和注释行数。代码行空间占用系数可以指每行代码占用内存空间的最大长度,可以根据开发者的经验设置,或者,可以由待刷写程序的二进制行代码的平均内存占用长度确定,可以更合理的确定出代码文本的内存占用量。The number of effective code lines can refer to the number of lines of logic codes with actual meaning in the program to be flashed, which can be obtained by subtracting the number of blank lines from the total number of lines of all codes and then subtracting the number of comment lines. The number of valid code lines in the code text may not include the number of blank lines and comment lines. The code line space occupation coefficient can refer to the maximum length of the memory space occupied by each line of code, which can be set according to the developer's experience, or can be determined by the average memory occupation length of the binary line code of the program to be flashed, which can be determined more reasonably The memory footprint of code text.
在本申请实施例中,可以统计代码文本中的有效代码行数,并提取代码行空间占用系数,可以确定有效代码行数与代码行空间占用系数的乘积,可以将该乘积作为代码文本的内存占用量。In the embodiment of the present application, the number of effective code lines in the code text can be counted, and the code line space occupation coefficient can be extracted, the product of the effective code line number and the code line space occupation coefficient can be determined, and the product can be used as the memory of the code text occupancy.
示例性的,代码文本的总行数有500行,包含注释和空行共20行,则代码文本的有效代码行数为480行,待刷写程序的二进制行代码的平均内存占用长度可以为2KB,则代码文本的内存占用量为有效代码行数与代码行空间占用系数之积,即代码文本的内存占用量为960KB。For example, the total number of lines of code text is 500 lines, including 20 lines of comments and blank lines, then the effective number of code lines of code text is 480 lines, and the average memory occupation length of the binary line code of the program to be flashed can be 2KB , then the memory usage of the code text is the product of the number of effective code lines and the space occupation coefficient of the code lines, that is, the memory usage of the code text is 960KB.
S2302,确定所有全局变量中的每个全局变量对应的数据结构和所有标定量中的每个标定量对应的数据结构,将所有全局变量对应的所有数据结构之和作为所有全局变量的内存占用量,以及,将所有标定量对应的所有数据结构之和作为所有标定量的内存占用量。S2302, determine the data structure corresponding to each global variable in all global variables and the data structure corresponding to each calibration quantity in all calibration quantities, and use the sum of all data structures corresponding to all global variables as the memory usage of all global variables , and, the sum of all data structures corresponding to all calibration quantities is used as the memory usage of all calibration quantities.
数据结构可以是反映全局变量以及标定量数据类型的信息,不同数据结构占用的内存空间的长度可以不同,例如,待刷写程序中有2个全局变量,这2个全局变量的数据结构分别为整型和字符型,整型存储需要的内存空间的长度可以为4字节,字符型存储需要的内存空间的长度可以为2字节,那么全局变量的内存占用量可以为4字节与2字节之和,即全局变量的内存占用量可以为6字节。又例如,标定量包括3个整型,每个整型存储需要的内存空间的长度为2字节,则标定量的内存占用量可以为3*2=6字节。The data structure can reflect the information of the global variable and the data type of the calibration quantity. The length of the memory space occupied by different data structures can be different. For example, there are 2 global variables in the program to be flashed, and the data structures of the 2 global variables are respectively Integer and character type, the length of the memory space required for integer storage can be 4 bytes, the length of the memory space required for character type storage can be 2 bytes, then the memory usage of global variables can be 4 bytes and 2 bytes The sum of bytes, that is, the memory footprint of a global variable can be 6 bytes. For another example, the calibration quantity includes 3 integers, and the length of the memory space required for each integer storage is 2 bytes, so the memory usage of the calibration quantity may be 3*2=6 bytes.
可以统计所有全局变量中每个全局变量对应的数据结构和所有标定量中每个标定量对应的数据结构,并获取每个数据结构存储需要的内存占用量,可以将所有全局变量对应的所有数据结构需要的内存占用量的和作为所有全局变量的内存占用量,以及,可以将所有标定量对应的所有数据结构之和作为所有标定量的内存占用量。It can count the data structure corresponding to each global variable in all global variables and the data structure corresponding to each calibration quantity in all calibration quantities, and obtain the memory usage required for each data structure storage, and can store all data corresponding to all global variables The sum of the memory footprint required by the structure is the memory footprint of all global variables, and the sum of all data structures corresponding to all calibration quantities can be used as the memory footprint of all calibration quantities.
S2303,在预设中断向量表查找中断的最深优先级,将最深优先级中断对应的内存大小与中断的个数之积作为中断的内存占用量。S2303, look up the deepest priority of the interrupt in the preset interrupt vector table, and use the product of the memory size corresponding to the deepest priority interrupt and the number of interrupts as the memory usage of the interrupt.
中断可以指处理器在正常执行程序的过程中,由于内部或外部事件的触发或由程序的预先安排,引起处理器暂时中断当前正在运行的程序,而转去执行为内部或外部事件或程序预先安排的事件的服务子程序,待中断服务子程序执行完毕后,处理器再返回到被暂时中断的程序处(断点)继续执行原来的程序,这一过程称为中断。中断向量表可以认为把系统中所有的中断类型码及所有中断类型码对应的所有中断向量按一定的规律存放在一个存储区域内,这个存储区域就叫中断向量表,中断向量表中的中断类型码可以为8位二进制数,可以认为是中断服务程序的入口地址,其中,最深优先级可以是待刷写代码具有的最高优先级的中断类型码对应的优先级,中断个数可以是待刷写代码中具有的不同的中断类型码的数量。Interruption can mean that during the normal execution of the program, the processor temporarily interrupts the currently running program due to internal or external event triggers or pre-arranged by the program, and then transfers to execute the internal or external event or program pre-arranged. The service subroutine of the arranged event, after the execution of the interrupt service subroutine, the processor returns to the temporarily interrupted program (breakpoint) and continues to execute the original program. This process is called interruption. The interrupt vector table can be regarded as storing all interrupt type codes in the system and all interrupt vectors corresponding to all interrupt type codes in a storage area according to certain rules. This storage area is called the interrupt vector table. The interrupt type in the interrupt vector table The code can be an 8-bit binary number, which can be considered as the entry address of the interrupt service program. Among them, the deepest priority can be the priority corresponding to the highest priority interrupt type code of the code to be flashed, and the number of interrupts can be the Write the number of different interrupt type codes in the code.
控制器在处理中断时是响应更高级别的中断申请,而屏蔽掉同级或较低级的中断申请,因此,中断的内存占用量与中断个数与中断优先级相关,可以使用中断个数与中断优先级的乘积确定中断的内存占用量。示例性的,如果中断的优先级有8个,中断的最深优先级可以为最高的优先级,该优先级的程序需要占用的内存可以为10KB,则将最深优先级中断对应的内存大小与中断的个数之积作为中断的内存占用量,即中断的内存占用量为80KB。When the controller handles interrupts, it responds to higher-level interrupt requests and shields interrupt requests of the same level or lower levels. Therefore, the memory usage of interrupts is related to the number of interrupts and the priority of interrupts, and the number of interrupts can be used The product of the interrupt priority determines the memory footprint of the interrupt. Exemplarily, if there are 8 interrupt priorities, the deepest priority of the interrupt can be the highest priority, and the memory occupied by the program of this priority can be 10KB, then the memory size corresponding to the deepest priority interrupt and the interrupt The product of the number of interrupts is used as the memory usage of the interrupt, that is, the memory usage of the interrupt is 80KB.
本申请实施例,通过将有效代码行数与代码行空间占用系数之积作为代码文本的内存占用量,将所有全局变量对应的所有数据结构之和作为所有全局变量的内存占用量,以及,将所有标定量对应的所有数据结构之和作为多个标定量的内存占用量;并且将最深优先级中断对应的内存大小与中断的个数之积作为中断的内存占用量,可以有效计算出代码文本的内存占用量、全局变量的内存占用量、标定量的内存占用量以及中断的内存占用量,从而可以有效计算出待刷写程序的内存占用量。In the embodiment of the present application, the product of the number of effective code lines and the space occupation coefficient of code lines is used as the memory usage of the code text, and the sum of all data structures corresponding to all global variables is used as the memory usage of all global variables, and, The sum of all data structures corresponding to all calibration quantities is used as the memory usage of multiple calibration quantities; and the product of the memory size corresponding to the deepest priority interrupt and the number of interrupts is taken as the interrupt memory usage, which can effectively calculate the code text The memory usage of the program, the memory usage of the global variable, the memory usage of the calibration amount, and the memory usage of the interrupt can effectively calculate the memory usage of the program to be flashed.
示例性实施例,图4是本申请实施例提供的一种控制器的程序刷写方法的实现效果图,如图4所示,实现本申请程序刷写方法的整体类包括MCUStruct_Class类、ReadMCU类、Disposition_Chip类和Generation_LinkFile类。Exemplary embodiment, Fig. 4 is the implementation effect diagram of the program flashing method of a kind of controller provided by the embodiment of the present application, as shown in Fig. 4, the integral class that realizes the program flashing method of the present application includes MCUStruct_Class class, ReadMCU class , Disposition_Chip class and Generation_LinkFile class.
MCUStruct_Class类是一个数据结构类,MCUStruct_Class类可以用来接收并存储待刷写程序中代码段、数据段、标定段以及中断内存大小的数据。利用该类中的get_CodeSize()函数获取待刷写程序的代码段的值,利用该类中的set_CodeSize()函数设置待刷写程序的代码段的值;利用该类中的get_DataSize()函数获取待刷写程序的数据段的值,利用该类中的set_DataSize()函数设置待刷写程序的数据段的值;利用该类中的get_Calib_DataSize()函数获取待刷写程序的标定段的值,利用该类中的set_Calib_DataSize()函数来设置待刷写程序的标定段的值; 利用该类中的get_Interrupt_MemenorySize()函数获取待刷写程序的中断数据的值,利用该类中的set_Interrupt_MemenorySize()函数设置待刷写程序的中断数据的值。The MCUStruct_Class class is a data structure class. The MCUStruct_Class class can be used to receive and store the code segment, data segment, calibration segment and interrupt memory size data in the program to be flashed. Use the get_CodeSize() function in this class to obtain the value of the code segment of the program to be flashed, use the set_CodeSize() function in this class to set the value of the code segment of the program to be flashed; use the get_DataSize() function in this class to obtain For the value of the data segment of the program to be flashed, use the set_DataSize() function in this class to set the value of the data segment of the program to be flashed; use the get_Calib_DataSize() function in this class to obtain the value of the calibration segment of the program to be flashed, Use the set_Calib_DataSize() function in this class to set the value of the calibration segment of the program to be flashed; use the get_Interrupt_MemenorySize() function in this class to obtain the interrupt data value of the program to be flashed, and use the set_Interrupt_MemenorySize() function in this class Set the interrupt data value of the program to be flashed.
ReadMCU类,此类可以用于读取待刷写程序中的所有代码,然后计算出当前所有代码需要的内存大小,还可以读取所有全局变量需要的内存空间大小、所有标定量需要的内存空间大小以及当前代码在中断情况下所需要的内存空间大小。该类中的Cal_CodeSize()函数,读取当前程序中所有代码有意义的行数,然后计算出转换成二进制文件后所需要的内存空间大小;该类中Cal_DataSize()函数通过读取待刷写程序中的全局变量,计算全局变量所需要的内存空间大小,Cal_Calib_DataSize()函数可以通过读取待刷写程序的标定量,计算标定量所需要的内存空间大小,Cal_Interrupt_Memory_Size()函数读取待刷写程序中设置的中断向量表的优先级,计算待刷写程序中设置的中断向量表的优先级、该函数涉及的参数以及该函数涉及的临时变量被触发中断时所需的内存空间大小。ReadMCU class, this class can be used to read all the codes in the program to be flashed, and then calculate the memory size required by all the current codes, and can also read the memory space required by all global variables and the memory space required by all calibration quantities size and the amount of memory space required by the current code in the event of an interrupt. The Cal_CodeSize() function in this class reads the number of meaningful lines of all codes in the current program, and then calculates the size of the memory space required after converting to a binary file; the Cal_DataSize() function in this class reads the code to be written Global variables in the program, calculate the size of the memory space required by the global variables, the Cal_Calib_DataSize() function can read the calibration amount of the program to be flashed, and calculate the memory space size required by the calibration amount, the Cal_Interrupt_Memory_Size() function reads the size of the memory space to be flashed Write the priority of the interrupt vector table set in the program, calculate the priority of the interrupt vector table set in the program to be flashed, the parameters involved in the function, and the size of the memory space required when the temporary variable involved in the function is triggered and interrupted.
Disposition_Chip类,此类中存放着当前芯片具体pflash和dflash相关的起止地址信息。利用该类中的set_ChipSetting()函数设置当前芯片具体的pflash和dflash相关的起止地址的值,利用该类中的get_ChipSetting()函数来获取当前芯片具体的pflash和dflash相关的起止地址的值。Disposition_Chip class, which stores the start and end address information related to the specific pflash and dflash of the current chip. Use the set_ChipSetting() function in this class to set the specific pflash and dflash related start and stop address values of the current chip, and use the get_ChipSetting() function in this class to obtain the current chip specific pflash and dflash related start and stop address values.
Generation_LinkFile类,此类根据ReadMCU类计算待刷写程序所需的内存大小数据和根据Disposition_Chip类得到芯片数据后,生成一个LinkFile文件。该类中的Generation_File()函数根据当前芯片pflash中的起始地址、大小以及与bootloader的终止地址,将待刷写程序写入pflash中,根据dflash的起始地址、大小,将待刷写程序中的全局变量、标定量以及中断写入dflash中,并确保地址连续,以减少空间的碎片化。Generation_LinkFile class, this class calculates the memory size data required by the program to be flashed according to the ReadMCU class and obtains the chip data according to the Disposition_Chip class, and generates a LinkFile file. The Generation_File() function in this class writes the program to be flashed into pflash according to the start address and size of the current chip pflash and the end address of the bootloader, and writes the program to be flashed according to the start address and size of dflash Write the global variables, calibration values and interrupts in dflash, and ensure that the addresses are continuous to reduce space fragmentation.
图5是本申请实施例提供的一种控制器的程序刷写方法的示例图,参考图5,控制器中的程序刷写可以包括如下步骤:首先,配置当前芯片pflash和dflash内存大小以及起始地址,然后读取待刷写程序所有源码,判断待刷写程序的源码是否为空,如果待刷写程序的源码为空,则打印待刷写程序的代码为空并结束整个流程,如果待刷写程序的源码不为空,则计算待刷写程序代码所需的占用空间大小、计算待刷写程序中全局变量所需的占用空间大小、计算待刷写程序中标定量所需的占用空间大小和预估待刷写程序中中断所需的占用空间大小,然后计算待刷写程序所需要的内存空间大小的总和,并将所需要的内存空间大小的总和与当前芯片的pfash和dflash进行比较,并判断待刷写程序所需要的内存空间大小的总和是否超出芯片大小,如果超出芯片大小,则打印当前芯片性能不足并结束整个流程,如果没有超出芯片大小,则生成对应的LinkFile文件, 并结束整个流程。Fig. 5 is an example diagram of a program flashing method of a controller provided by the embodiment of the present application. With reference to Fig. 5, the program flashing in the controller may include the following steps: first, configure the memory size of the current chip pflash and dflash and start Then read all the source code of the program to be flashed, and judge whether the source code of the program to be flashed is empty. If the source code of the program to be flashed is empty, print that the code of the program to be flashed is empty and end the entire process. If If the source code of the program to be flashed is not empty, then calculate the occupied space required for the program code to be flashed, calculate the occupied space required for global variables in the program to be flashed, and calculate the occupied space required for the calibration amount in the program to be flashed Space size and estimate the occupied space required for interrupts in the program to be flashed, then calculate the sum of the memory space required by the program to be flashed, and compare the sum of the required memory space with the pfash and dflash of the current chip Compare and judge whether the sum of the memory space required by the program to be flashed exceeds the chip size. If it exceeds the chip size, it will print that the current chip performance is insufficient and end the entire process. If it does not exceed the chip size, generate the corresponding LinkFile file , and end the entire process.
实施例三Embodiment three
图6是本申请实施例三提供的一种控制器的程序刷写装置的结构框图,该装置可执行本申请任意实施例所提供的控制器的程序刷写方法,具备执行方法相应的功能模块和效果。所述装置配置于控制器中来实现本申请实施例中的控制器的程序刷写方法。如图6所示,所述装置包括:程序接收模块610、空间信息模块620和程序刷写模块630。Fig. 6 is a structural block diagram of a program flashing device for a controller provided in Embodiment 3 of the present application. The device can execute the program flashing method for a controller provided in any embodiment of the present application, and has corresponding functional modules for executing the method and effects. The device is configured in the controller to implement the program flashing method of the controller in the embodiment of the present application. As shown in FIG. 6 , the device includes: a program receiving module 610 , a spatial information module 620 and a program flashing module 630 .
程序接收模块610,设置为根据预设存储结构获取待刷写程序。The program receiving module 610 is configured to obtain the program to be flashed according to the preset storage structure.
空间信息模块620,设置为确定所述待刷写程序的代码内容的运行空间占用信息。The space information module 620 is configured to determine the running space occupation information of the code content of the program to be flashed.
程序刷写模块630,设置为基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。The program flashing module 630 is configured to write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
本申请实施例的技术方案,程序接收模块通过根据预设存储结构获取待刷写程序,空间信息模块确定所述待刷写程序的代码内容的运行空间占用信息,程序刷写模块基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。上述技术方案,采用基于预估待刷写程序的运行内存大小以及起始地址的方式将待刷写程序写入内存空间,有效节省了内存空间,可提高程序刷写的成功率,从而提高控制器运行的稳定性,可以减少确定待刷写程序运行参数的测试时间,可提高控制器的开发效率。In the technical solution of the embodiment of the present application, the program receiving module obtains the program to be flashed according to the preset storage structure, the space information module determines the running space occupation information of the code content of the program to be flashed, and the program flashing module starts based on the flashing Write the program to be flashed into the memory space according to the starting address and the running space occupation information. The above technical solution writes the program to be flashed into the memory space based on the estimated running memory size and starting address of the program to be flashed, which effectively saves memory space, improves the success rate of program flashing, and thereby improves control The stability of the operation of the controller can reduce the test time for determining the operating parameters of the program to be flashed, and can improve the development efficiency of the controller.
在上述装置中,程序接收模块610是设置为:调用数据结构类接收并存储所述待刷写程序的代码段、数据段、标定段以及中断数据。In the above device, the program receiving module 610 is configured to: call the data structure class to receive and store the code segment, data segment, calibration segment and interrupt data of the program to be flashed.
上述装置中,空间信息模块620包括代码读取单元和内存确定单元。In the above device, the spatial information module 620 includes a code reading unit and a memory determining unit.
所述代码读取单元,设置为读取所述待刷写程序的代码内容,其中,所述代码内容包括:代码文本、全局变量、标定量和中断。The code reading unit is configured to read the code content of the program to be flashed, wherein the code content includes: code text, global variables, calibration quantities and interrupts.
所述内存确定单元,设置为分别确定代码文本的内存占用量、全局变量的内存占用量、标定量的内存占用量和中断的内存占用量,并将所述代码文本的内存占用量、所述全局变量的内存占用量、所述标定量的内存占用量和所述中断的内存占用量作为运行空间占用信息。The memory determination unit is configured to respectively determine the memory usage of the code text, the memory usage of the global variable, the memory usage of the calibration amount and the memory usage of the interrupt, and combine the memory usage of the code text, the memory usage of the The memory usage of the global variable, the memory usage of the calibration amount and the memory usage of the interrupt are used as the running space usage information.
上述装置中,所述全局变量的数量为至少一个,所述标定量的数量为至少一个,所述内存确定单元包括行数确定子单元、结构确定子单元和查找子单元。In the above device, the number of the global variable is at least one, the number of the calibration quantity is at least one, and the memory determination unit includes a row number determination subunit, a structure determination subunit and a search subunit.
所述行数确定子单元,设置为确定所述代码文本的有效代码行数,并将所 述有效代码行数与代码行空间占用系数之积作为所述代码文本的内存占用量。The line number determination subunit is configured to determine the effective code line number of the code text, and use the product of the effective code line number and the code line space occupation coefficient as the memory footprint of the code text.
所述结构确定子单元,设置为确定所有全局变量中的每个全局变量对应的数据结构和所有所述标定量中的每个标定量对应的数据结构,将所有全局变量对应的所有数据结构之和作为所有全局变量的内存占用量,以及,将所有标定量对应的所有数据结构之和作为所有标定量的内存占用量。The structure determination sub-unit is configured to determine the data structure corresponding to each global variable in all global variables and the data structure corresponding to each calibration quantity in all the calibration quantities, and the data structure corresponding to all the data structures corresponding to all global variables The sum is used as the memory usage of all global variables, and the sum of all data structures corresponding to all calibrations is used as the memory usage of all calibrations.
所述查找子单元,设置为在预设中断向量表查找所述中断的最深优先级,将所述最深优先级中断对应的内存大小与所述中断的个数之积作为所述中断的内存占用量。The search subunit is configured to search the deepest priority of the interrupt in the preset interrupt vector table, and use the product of the memory size corresponding to the deepest priority interrupt and the number of interrupts as the memory occupation of the interrupt quantity.
上述装置中,所述代码行空间占用系数包括:所述待刷写程序的二进制行代码的平均内存占用长度。In the above device, the code line space occupation coefficient includes: the average memory occupation length of the binary line codes of the program to be flashed.
上述装置中,程序刷写模块630是设置为:确定所述内存空间的剩余空间是否满足所述运行空间占用信息;响应于所述内存空间的剩余空间满足所述运行空间占用信息的确定结果,在所述内存空间的预设区域读取所述待刷写程序的刷写起始地址,并按照所述刷写起始地址将所述待刷写程序写入所述内存空间;响应于所述内存空间的剩余空间不满足所述运行空间占用信息的确定结果,生成刷写失败信息并反馈。In the above device, the program flashing module 630 is configured to: determine whether the remaining space of the memory space satisfies the operating space occupancy information; in response to the determination result that the remaining space of the memory space satisfies the operating space occupancy information, Read the flash start address of the program to be flashed in the preset area of the memory space, and write the program to be flashed into the memory space according to the flash write start address; in response to the If the remaining space of the above memory space does not meet the determination result of the operation space occupation information, the flashing failure information is generated and fed back.
上述装置中,在程序刷写模块630之后,还包括更新模块,设置为根据所述待刷写程序的运行空间占用信息更新所述刷写起始地址。In the above device, after the program flashing module 630, an update module is further included, configured to update the flashing start address according to the running space occupation information of the program to be flashed.
上述产品可执行本申请实施例所提供的控制器的程序刷写方法,具备执行方法相应的功能模块和效果。The above-mentioned products can execute the program flashing method of the controller provided in the embodiment of the present application, and have corresponding functional modules and effects for executing the method.
实施四Implementation four
本申请实施例四提供了一种控制器。图7是本申请实施例四提供的一种控制器的结构示意图。如图7所示,本实施例提供了一种控制器,可以包括:中央处理器和存储器。存储器中存储有至少一条指令,且指令由所述中央处理器执行,使得所述控制器执行如上述方法实施例所述的控制器的程序刷写方法。Embodiment 4 of the present application provides a controller. FIG. 7 is a schematic structural diagram of a controller provided in Embodiment 4 of the present application. As shown in FIG. 7 , this embodiment provides a controller, which may include: a central processing unit and a memory. At least one instruction is stored in the memory, and the instruction is executed by the central processing unit, so that the controller executes the method for flashing the program of the controller as described in the above method embodiment.
参照图7,该控制器可以包括:中央处理器720、存储器710、输入装置730和输出装置740;该控制器中中央处理器720的数量可以是一个或多个,图7中以一个中央处理器720为例;该控制器中存储器710的数量可以是一个或者多个,图7中以一个存储器710为例。该控制器中的中央处理器720、存储器710、输入装置730和输出装置740可以通过总线或其他方式连接,图7中以通过总线连接为例。With reference to Fig. 7, this controller can comprise: central processing unit 720, memory 710, input device 730 and output device 740; The quantity of central processing unit 720 in this controller can be one or more, in Fig. The controller 720 is taken as an example; the number of memory 710 in the controller may be one or more, and one memory 710 is taken as an example in FIG. 7 . The central processing unit 720, the memory 710, the input device 730 and the output device 740 in the controller can be connected through a bus or in other ways. In FIG. 7, connection through a bus is taken as an example.
实施例中,中央处理器720执行存储器710中存储的一个或多个程序时,可以实现如下操作:根据预设存储结构获取待刷写程序;确定所述待刷写程序的代码内容的运行空间占用信息;基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。In an embodiment, when the central processing unit 720 executes one or more programs stored in the memory 710, the following operations can be implemented: obtain the program to be flashed according to the preset storage structure; determine the running space of the code content of the program to be flashed occupancy information: write the program to be flashed into the memory space based on the flashing start address and the running space occupation information.
上述实施例中提供的控制器的程序刷写方法、装置、控制器和存储介质可执行本申请任意实施例所提供的控制器的程序刷写方法,具备执行该方法相应的功能模块和效果。未在上述实施例中描述的技术细节,可参见本申请任意实施例所提供的控制器的程序刷写方法。The controller program flashing method, device, controller, and storage medium provided in the above embodiments can execute the controller program flashing method provided in any embodiment of the present application, and have corresponding functional modules and effects for executing the method. For technical details not described in the above embodiments, refer to the method for flashing the program of the controller provided in any embodiment of the present application.
实施例五Embodiment five
本申请实施例五提供了一种计算机可读存储介质,其上存储有程序,该程序被中央处理器执行时实现如本申请所有发明实施例提供的控制器的程序刷写方法,该方法包括:根据预设存储结构获取待刷写程序;确定所述待刷写程序的代码内容的运行空间占用信息;基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。Embodiment 5 of the present application provides a computer-readable storage medium on which a program is stored. When the program is executed by the central processing unit, the method for flashing the program of the controller as provided in all the invention embodiments of the present application is implemented. The method includes : Acquiring the program to be flashed according to the preset storage structure; determining the running space occupancy information of the code content of the program to be flashed; writing the program to be flashed based on the starting address of the flashing and the running space occupancy information memory space.
本申请实施例的计算机存储介质,可以采用一个或多个计算机可读的介质的任意组合。计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者系统、装置或器件的任意的组合。计算机可读存储介质可以包括:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机存取存储器(Random Access Memory,RAM)、只读存储器(Read-Only Memory,ROM)、可擦式可编程只读存储器(Erasable Programmable Read-Only Memory,EPROM)或闪存、光纤、便携式紧凑磁盘只读存储器(Compact Disc Read-Only Memory,CD-ROM)、光存储器件、磁存储器件、或者上述的任意的组合。在本文件中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。The computer storage medium in the embodiments of the present application may use any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of systems, devices, or devices. The computer-readable storage medium may include: an electrical connection having one or more conductors, a portable computer disk, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an erasable Type programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM) or flash memory, optical fiber, portable compact disk read-only memory (Compact Disc Read-Only Memory, CD-ROM), optical storage device, magnetic storage device, or the above any combination of . In this document, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
计算机可读的信号介质可以包括在基带中或者作为载波传播的数据信号,计算机可读的信号介质中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括——但不限于——电磁信号、光信号或上述的任意合的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输由指令执行系统、装置或者器件使用或者与指令执行系统、装置或者器件结合使用的程序。A computer-readable signal medium may include a data signal in baseband or propagated as a carrier wave, and the computer-readable signal medium carries computer-readable program code thereon. Such propagated data signals may take many forms, including - but not limited to - electromagnetic signals, optical signals, or any combination of the foregoing. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can be sent, propagated, or transported for use by or in conjunction with an instruction execution system, apparatus, or device. Programs used in conjunction with the device.
计算机可读介质上包含的程序代码可以用任何介质传输,包括——但不限于——无线、电线、光缆、射频(Radio Frequency,RF)等等,或者上述的任意的组合。The program code contained on the computer readable medium can be transmitted by any medium, including—but not limited to—wireless, electric wire, optical cable, radio frequency (Radio Frequency, RF), etc., or any combination of the above.
可以以一种或多种程序设计语言来编写用于执行本申请操作的计算机程序代码,所述程序设计语言包括面向对象的程序设计语言—诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上执行部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(Local Area Network,LAN)或广域网(Wide Area Network,WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。Computer program code for carrying out the operations of the present application may be written in one or more programming languages, including object-oriented programming languages—such as Java, Smalltalk, C++, as well as conventional procedural programming languages Design Language—such as "C" or a similar programming language. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or it can be connected to an external computer ( For example, use an Internet service provider to connect via the Internet).

Claims (10)

  1. 一种控制器的程序刷写方法,包括:A program flashing method for a controller, comprising:
    根据预设存储结构获取待刷写程序;Obtain the program to be flashed according to the preset storage structure;
    确定所述待刷写程序的代码内容的运行空间占用信息;Determine the running space occupancy information of the code content of the program to be flashed;
    基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间。Writing the program to be flashed into memory space based on the flashing start address and the running space occupation information.
  2. 根据权利要求1所述的方法,其中,所述根据预设存储结构获取待刷写程序,包括:The method according to claim 1, wherein said obtaining the program to be flashed according to the preset storage structure comprises:
    调用数据结构类接收并存储所述待刷写程序的代码段、数据段、标定段以及中断数据。The calling data structure class receives and stores the code segment, data segment, calibration segment and interrupt data of the program to be flashed.
  3. 根据权利要求1所述的方法,其中,所述确定所述待刷写程序的代码内容的运行空间占用信息,包括:The method according to claim 1, wherein said determining the running space occupancy information of the code content of the program to be flashed comprises:
    读取所述待刷写程序的代码内容,其中,所述代码内容包括:代码文本、全局变量、标定量和中断;Reading the code content of the program to be flashed, wherein the code content includes: code text, global variables, calibration quantities and interrupts;
    分别确定代码文本的内存占用量、全局变量的内存占用量、标定量的内存占用量和中断的内存占用量,并将所述代码文本的内存占用量、所述全局变量的内存占用量、所述标定量的内存占用量和所述中断的内存占用量作为运行空间占用信息。Respectively determine the memory usage of the code text, the memory usage of the global variable, the memory usage of the calibration amount and the memory usage of the interrupt, and calculate the memory usage of the code text, the memory usage of the global variable, and the The memory usage of the calibrated amount and the memory usage of the interrupt are used as the running space occupation information.
  4. 根据权利要求3所述的方法,其中,所述全局变量的数量为至少一个,所述标定量的数量为至少一个,所述分别确定代码文本的内存占用量、全局变量的内存占用量、标定量的内存占用量和中断的内存占用量,包括:The method according to claim 3, wherein, the quantity of the global variable is at least one, the quantity of the calibration quantity is at least one, and the memory footprint of the code text, the memory footprint of the global variable, and the calibration quantity are respectively determined. Quantitative memory footprint and interrupt memory footprint, including:
    确定所述代码文本的有效代码行数,并将所述有效代码行数与代码行空间占用系数之积作为所述代码文本的内存占用量;Determine the effective number of code lines of the code text, and use the product of the effective number of code lines and the space occupation coefficient of the code line as the memory footprint of the code text;
    确定所有全局变量中的每个全局变量对应的数据结构和所有标定量中的每 个标定量对应的数据结构,将所有全局变量对应的所有数据结构之和作为所有全局变量的内存占用量,以及,将所有标定量对应的所有数据结构之和作为所有标定量的内存占用量;Determine the data structure corresponding to each global variable in all global variables and the data structure corresponding to each calibration quantity in all calibration quantities, and use the sum of all data structures corresponding to all global variables as the memory footprint of all global variables, and , take the sum of all data structures corresponding to all calibration quantities as the memory usage of all calibration quantities;
    在预设中断向量表查找所述中断的最深优先级,将所述最深优先级中断对应的内存大小与所述中断的个数之积作为所述中断的内存占用量。The deepest priority of the interrupt is searched in the preset interrupt vector table, and the product of the memory size corresponding to the deepest priority interrupt and the number of the interrupts is used as the memory occupation of the interrupt.
  5. 根据权利要求4所述的方法,其中,所述代码行空间占用系数包括:所述待刷写程序的二进制行代码的平均内存占用长度。The method according to claim 4, wherein the code line space occupation coefficient comprises: an average memory occupation length of binary line codes of the program to be flashed.
  6. 根据权利要求1所述的方法,其中,所述基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间,包括:The method according to claim 1, wherein the writing the program to be flashed into the memory space based on the flashing start address and the running space occupancy information comprises:
    确定所述内存空间的剩余空间是否满足所述运行空间占用信息;Determine whether the remaining space of the memory space satisfies the running space occupancy information;
    响应于所述内存空间的剩余空间满足所述运行空间占用信息的确定结果,在所述内存空间的预设区域读取所述待刷写程序的刷写起始地址,并按照所述刷写起始地址将所述待刷写程序写入所述内存空间;In response to the determination result that the remaining space of the memory space satisfies the operation space occupancy information, read the flashing start address of the program to be flashed in the preset area of the memory space, and follow the flashing The starting address writes the program to be flashed into the memory space;
    响应于所述内存空间的剩余空间不满足所述运行空间占用信息的确定结果,生成刷写失败信息并反馈。In response to a determination result that the remaining space of the memory space does not meet the requirement of the running space occupancy information, generating and feeding back failure information about flashing.
  7. 根据权利要求1-6中任一所述的方法,在所述基于刷写起始地址和所述运行空间占用信息将所述待刷写程序写入内存空间之后,还包括:The method according to any one of claims 1-6, after writing the program to be flashed into the memory space based on the flashing start address and the operating space occupation information, further comprising:
    根据所述待刷写程序的运行空间占用信息更新所述刷写起始地址。The flashing start address is updated according to the running space occupation information of the program to be flashed.
  8. 一种控制器的程序刷写装置,包括:A program flashing device for a controller, comprising:
    程序接收模块,设置为根据预设存储结构获取待刷写程序;The program receiving module is configured to obtain the program to be flashed according to the preset storage structure;
    空间信息模块,设置为确定所述待刷写程序的代码内容的运行空间占用信息;A space information module, configured to determine the running space occupancy information of the code content of the program to be flashed;
    程序刷写模块,设置为基于刷写起始地址和所述运行空间占用信息将所述 待刷写程序写入内存空间。The program flashing module is configured to write the program to be flashed into the memory space based on the flashing start address and the operating space occupation information.
  9. 一种控制器,包括:A controller comprising:
    至少一个中央处理器;at least one central processing unit;
    存储器,设置为存储至少一个程序,a memory configured to store at least one program,
    当所述至少一个程序被所述至少一个中央处理器执行时,所述至少一个中央处理器实现如权利要求1-7中任一所述的控制器的程序刷写方法。When the at least one program is executed by the at least one central processing unit, the at least one central processing unit implements the program flashing method for the controller according to any one of claims 1-7.
  10. 一种计算机可读存储介质,其上存储有程序,所述程序被中央处理器执行时实现如权利要求1-7中任一所述的控制器的程序刷写方法。A computer-readable storage medium, on which a program is stored, and when the program is executed by a central processing unit, the method for flashing the program of the controller according to any one of claims 1-7 is realized.
PCT/CN2022/125868 2021-10-18 2022-10-18 Program flashing method and apparatus for controller, and controller and storage medium WO2023066233A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111208423.9A CN113885917A (en) 2021-10-18 2021-10-18 Program flashing method and device of controller, controller and storage medium
CN202111208423.9 2021-10-18

Publications (1)

Publication Number Publication Date
WO2023066233A1 true WO2023066233A1 (en) 2023-04-27

Family

ID=79003212

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/125868 WO2023066233A1 (en) 2021-10-18 2022-10-18 Program flashing method and apparatus for controller, and controller and storage medium

Country Status (2)

Country Link
CN (1) CN113885917A (en)
WO (1) WO2023066233A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113885917A (en) * 2021-10-18 2022-01-04 中国第一汽车股份有限公司 Program flashing method and device of controller, controller and storage medium
CN115185615B (en) * 2022-09-09 2022-12-02 湖南三湘银行股份有限公司 Plug-in calling method based on memory space optimization

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010032288A1 (en) * 2000-04-13 2001-10-18 Honda Giken Kogyo Kabushiki Kaisha Rewriting system for vehicle controller
CN1904853A (en) * 2006-08-21 2007-01-31 北京中星微电子有限公司 Embedded software loading debugging method and system thereof
CN103745153A (en) * 2013-12-30 2014-04-23 北京控制工程研究所 Spacecraft software space utilization safety inspection method
CN105302618A (en) * 2015-12-05 2016-02-03 中国航空工业集团公司洛阳电光设备研究所 Rapid programming method for ASAAC standard digital signal processing module
CN109324813A (en) * 2018-08-16 2019-02-12 深圳市元征科技股份有限公司 Electronic control system writes with a brush dipped in Chinese ink method, apparatus and computer media
US20200034134A1 (en) * 2018-07-30 2020-01-30 Ford Global Technologies, Llc Over The Air Ecu Update
CN111722864A (en) * 2020-06-24 2020-09-29 深圳市元征科技股份有限公司 ECU data flashing method and related device
CN112579135A (en) * 2020-12-22 2021-03-30 潍柴动力股份有限公司 Flash control method and system for vehicle control unit and vehicle
CN113885917A (en) * 2021-10-18 2022-01-04 中国第一汽车股份有限公司 Program flashing method and device of controller, controller and storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010032288A1 (en) * 2000-04-13 2001-10-18 Honda Giken Kogyo Kabushiki Kaisha Rewriting system for vehicle controller
CN1904853A (en) * 2006-08-21 2007-01-31 北京中星微电子有限公司 Embedded software loading debugging method and system thereof
CN103745153A (en) * 2013-12-30 2014-04-23 北京控制工程研究所 Spacecraft software space utilization safety inspection method
CN105302618A (en) * 2015-12-05 2016-02-03 中国航空工业集团公司洛阳电光设备研究所 Rapid programming method for ASAAC standard digital signal processing module
US20200034134A1 (en) * 2018-07-30 2020-01-30 Ford Global Technologies, Llc Over The Air Ecu Update
CN109324813A (en) * 2018-08-16 2019-02-12 深圳市元征科技股份有限公司 Electronic control system writes with a brush dipped in Chinese ink method, apparatus and computer media
CN111722864A (en) * 2020-06-24 2020-09-29 深圳市元征科技股份有限公司 ECU data flashing method and related device
CN112579135A (en) * 2020-12-22 2021-03-30 潍柴动力股份有限公司 Flash control method and system for vehicle control unit and vehicle
CN113885917A (en) * 2021-10-18 2022-01-04 中国第一汽车股份有限公司 Program flashing method and device of controller, controller and storage medium

Also Published As

Publication number Publication date
CN113885917A (en) 2022-01-04

Similar Documents

Publication Publication Date Title
WO2023066233A1 (en) Program flashing method and apparatus for controller, and controller and storage medium
CN108694075B (en) Method and device for processing report data, electronic equipment and readable storage medium
CN110990019B (en) Java class analysis method and device, storage medium and electronic equipment
CN108205469B (en) MapReduce-based resource allocation method and server
CN103970520A (en) Resource management method and device in MapReduce framework and framework system with device
KR101835604B1 (en) Scheduler for memory
CN111737564B (en) Information query method, device, equipment and medium
CN113010470B (en) Edge node remote control system, method, equipment and storage medium
CN112905472A (en) Kernel debugging system and method
KR20200135717A (en) Method, apparatus, device and storage medium for processing access request
US9740618B2 (en) Memory nest efficiency with cache demand generation
US20200371827A1 (en) Method, Apparatus, Device and Medium for Processing Data
CN115827250A (en) Data storage method, device and equipment
CN109521970B (en) Data processing method and related equipment
US9251107B2 (en) Immediate direct memory access descriptor-based write operation
CN108829345B (en) Data processing method of log file and terminal equipment
CN111625180B (en) Data writing method and device and storage medium
US6675238B1 (en) Each of a plurality of descriptors having a completion indicator and being stored in a cache memory of an input/output processor
CN111913812B (en) Data processing method, device, equipment and storage medium
CN112230964A (en) Application program development method, application program running method, device, equipment and medium
KR20210108466A (en) Memory control system with sequence processing unit
CN117389685B (en) Virtual machine thermal migration dirty marking method and device, back-end equipment and chip thereof
CN116931954B (en) Built-in software package compiling construction method, device, equipment and medium
CN111222295B (en) Layout and wiring control method, device and system based on wiring resources
CN116467235B (en) DMA-based data processing method and device, electronic equipment and medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22882838

Country of ref document: EP

Kind code of ref document: A1