|
main_ubi_sdk v 0.1.3
This is UBI4 documentation
|
#include "utils/update_fw.h"#include "utils/while_sheduller.h"#include "utils/base_soft_timer.h"#include "HAL_DRIVERS.h"#include "stdlib.h"
Data Structures | |
| struct | temp_write_to_flash_from_while_struct |
| struct | temp_clear_flash_from_while_struct |
| union | Update_FW_temp_union_structs |
Functions | |
| static void | Get_Run_Program_Type (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| The "Get_Run_Program_Type" function is needed to determine which program the device is currently in. In the loader program or the main program. | |
| static void | Jump_To_Bootloader (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| A function for switching to the loader program. | |
| static void | Check_New_FW (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| A function that verifies the firmware that will be transferred from the master. | |
| void | clear_flash_from_while (temp_clear_flash_from_while_struct *args) |
| static void | Preload_Info (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| The function of preparing the device for firmware. | |
| void | write_to_flash_from_while (temp_write_to_flash_from_while_struct *args) |
| static void | Load_New_FW (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| This function loads the firmware into flash. | |
| static void | Get_Bootloader_Status (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| This function sends a Process_boot. | |
| void | calculate_crc_from_while (void *args) |
| static void | Enable_Calculate_CRC (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| A function for calculating CRC. | |
| void | start_program_from_while (void *soft_timer_obj, int instance, void *args) |
| static void | Get_CRC (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| A function for determining the correctness of the calculated CRC. | |
| static void | Get_Bootloader_Info (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| The function sends data about the loader program to the wizard. | |
| static void | Get_Up_Load_Atribute (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| The function sends the chunck size to the master. | |
| void | JumpToProgramCommand (uint32_t address_to_jump) |
| The function goes to the received address. | |
| void | Update_FW_Receive (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str) |
| A function that determines which command has arrived and which state needs to be switched to. | |
| void | Init_Need_Struct_For_FW (base_BootloaderInfo_struct *base_boot, base_FWInfo_struct *base_fw, base_BoardInfo_struct *base_board) |
| A function for initializing "Bootloader_struct", "FW_struct" and "Board_struct" from flash. | |
| __weak uint8_t | Compare_Data (void) |
| A function for verifying the firmware. | |
| void | Calculate_CRC () |
| A function for calculating the CRC of downloaded firmware from memory. | |
| uint8_t | Get_Enable_CRC (void) |
| The function returned by flag_crc. | |
| void | Set_Enable_CRC (uint8_t value) |
| The function being modified by flag_crc. | |
Variables | |
| uint16_t | compare_data_mask = COMPARE_DATA_MASK |
| uint8_t | flag_crc = END_CALCULATE_CRC |
| uint32_t | write_fw_pointer = 0 |
| uint32_t | crc_firmware_from_master = 0 |
| uint32_t | crc_firmware_calculate = 0 |
| uint8_t | data_for_boot [SIZE_BUFF_FOR_BOOT] |
| base_BootloaderInfo_struct * | Bootloader_struct |
| base_FWInfo_struct * | FW_struct |
| base_BoardInfo_struct * | Board_struct |
| FW_info_struct | fw_info |
| FW_up_load_atribute | parametrs |
| state_process_bootloader | Process_boot =BOOTLOADER_IDLE |
| uint8_t | array_sizeof_for_compare [SIZE_FW_INFO_STRUCT] |
| union Update_FW_temp_union_structs | UpdateFWtempData |
| void Calculate_CRC | ( | ) |
A function for calculating the CRC of downloaded firmware from memory.
Available to call in any module.


| void calculate_crc_from_while | ( | void * | args | ) |


|
static |
A function that verifies the firmware that will be transferred from the master.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
If the firmware does not match the device, the function sends a BAD_COMPARE message to the master. When the firmware matches the device, the function sends a GOOD_COMPARE message to the master. It also sends the command that called this function.
Assigns the status to the global variable Process_boot in what state the program is currently in. Resets write_fw_pointer.
Assigns the received structure from the wizard to the fw_info structure. Receives the reference CRC of the firmware.


| void clear_flash_from_while | ( | temp_clear_flash_from_while_struct * | args | ) |

| __weak uint8_t Compare_Data | ( | void | ) |
A function for verifying the firmware.
| Nothing. |
Available to call in any module.

|
static |
A function for calculating CRC.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
Sends 0x01 to the master in order to make sure that the command has reached the slave. It sends the command that called this function. Assigns the status to the global variable Process_boot in what state the program is currently in. Changes the value of the flag_crc flag to BEGIN_CALCULATE_CRC - the CRC can be considered.


|
static |
The function sends data about the loader program to the wizard.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
It sends the command that called this function.

|
static |
This function sends a Process_boot.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
It sends the command that called this function.

|
static |
A function for determining the correctness of the calculated CRC.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
If the calculated CRC matches the CRC received from the wizard, the device sends GOOD_CRC_FIRMWARE and jumps to MAIN_PROGRAM_START_ADDRESS. If the calculated CRC does not match the CRC received from the wizard, the device sends BAD_CRC_FIRMWARE and remains in the loader program. It sends the command that called this function.


| uint8_t Get_Enable_CRC | ( | void | ) |
The function returned by flag_crc.
| Nothing. |
Available to call in any module.
|
static |
The "Get_Run_Program_Type" function is needed to determine which program the device is currently in. In the loader program or the main program.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
Sends the wizard the mode in which the device is located. It also sends the command that called this function. BOOTLOADER_IDLE - the loader program. IN_MAIN_APP_STATUS - main program.
Assigns the status to the global variable Process_boot in what state the program is currently in.

|
static |
The function sends the chunck size to the master.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
It sends the command that called this function.

| void Init_Need_Struct_For_FW | ( | base_BootloaderInfo_struct * | base_boot, |
| base_FWInfo_struct * | base_fw, | ||
| base_BoardInfo_struct * | base_board ) |
A function for initializing "Bootloader_struct", "FW_struct" and "Board_struct" from flash.
| base_boot | - a pointer to a structure containing information about the loader program itself. base_fw - a pointer to a structure containing information about the firmware received from the master device. base_board - a pointer to a structure containing information about the board itself, which is necessary for firmware verification. |
Available to call in any module.
|
static |
A function for switching to the loader program.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
Writes the firmware-enabling flag to the flash memory. Restarts the device.


| void JumpToProgramCommand | ( | uint32_t | address_to_jump | ) |
The function goes to the received address.
| address_to_jump | - The program's transition address. |
|
static |
This function loads the firmware into flash.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
It sends the size of the received fragments to the master device to make sure that the command has reached the slave device, as well as to determine the offset in the firmware file. It also sends the command that called this function. Assigns the status to the global variable Process_boot in what state the program is currently in. Receives from the master the offset and a part of the firmware, the size of which is equal to chunck. The end address of the firmware is considered to be write_fw_pointer. The MAIN PROGRAM_START_ADDRESS is the initial address of the firmware, to which the offset received from the wizard is added to determine which address to write a new piece of firmware to.


|
static |
The function of preparing the device for firmware.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
Sends 0x01 to the master in order to make sure that the command has reached the slave. It also sends the command that called this function. Assigns the status to the global variable Process_boot in what state the program is currently in. Resets write_fw_pointer.


| void Set_Enable_CRC | ( | uint8_t | value | ) |
The function being modified by flag_crc.
| value | - the flag_crc value.. |
Available to call in any module.
| void start_program_from_while | ( | void * | soft_timer_obj, |
| int | instance, | ||
| void * | args ) |


| void Update_FW_Receive | ( | base_device_information_struct * | deviceInfo, |
| ubi4_bus_protocol_obj_struct * | protocol_str, | ||
| protocol_receive_struct | receive_str ) |
A function that determines which command has arrived and which state needs to be switched to.
| deviceInfo | - a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data. |
The first byte of the received buffer is the status. Takes the value from "update_fw_state_enum". Available for calling in other libraries.


| void write_to_flash_from_while | ( | temp_write_to_flash_from_while_struct * | args | ) |

| uint8_t array_sizeof_for_compare[SIZE_FW_INFO_STRUCT] |
| array_sizeof_for_compare | - an array containing the field sizes of the structure containing information about the board required for firmware verification. |
| base_BoardInfo_struct* Board_struct |
| base_BootloaderInfo_struct* Bootloader_struct |
Required global structure for the loader to work.
| Bootloader_struct | - a pointer to a structure containing information about the loader program itself. FW_struct - a pointer to a structure containing information about the firmware received from the master device. Board_struct - A pointer to a structure containing information about the board itself, which is necessary for firmware verification. fw_info - a structure containing information about the firmware and the board from the wizard. deviceInfo_Test - |
| uint16_t compare_data_mask = COMPARE_DATA_MASK |
This library is universal and contains functions for downloading new firmware. It doesn't matter which controller is used or which interface the device communicates with. Is he a master or a slave. A detailed description of each function is described below.
These are variables that depend on the externally mutable values of the constants CHUNCK_SIZE and COMPARE_DATA_MASK, which are contained in the UBI_SDK.h library.
| chunck_size | - required size of data acquisition for recording in flash. compare_data_mask - the mask used to determine which properties of the board need to be compared to determine the correctness of the firmware. |
| uint32_t crc_firmware_calculate = 0 |
| uint32_t crc_firmware_from_master = 0 |
| uint8_t data_for_boot[SIZE_BUFF_FOR_BOOT] |
| uint8_t flag_crc = END_CALCULATE_CRC |
Required global variables for the loader to work.
| flag_crc | - A flag that determines whether the CRC of the downloaded firmware has been calculated, it can be obtained and changed using the functions contained in this library. write_fw_pointer - the total offset from the initial firmware address. crc_firmware_from_master - CRC received from the master. crc_firmware_calculate - the calculated CRC after downloading the firmware. data_for_boot - an auxiliary array for downloading firmware, obtained from the received data, with a size of SIZE_BUFF_FOR_BOOT - 1024. |
| FW_info_struct fw_info |
| base_FWInfo_struct* FW_struct |
| FW_up_load_atribute parametrs |
| state_process_bootloader Process_boot =BOOTLOADER_IDLE |
| Process_boot | - the enum is used to determine the current state of the device. |
| union Update_FW_temp_union_structs UpdateFWtempData |
| uint32_t write_fw_pointer = 0 |