1.5.6 Communication Adapter Software Interface
One of the purposes of the bootloader is to download new application image files from a external device and then program that file into flash. In order to communicate with multiple types of external devices like a PC host, a standard communication interface of 4 functions is defined. The communication adapter maps four required communication functions needed by the bootloader to the physical interface being used for bootloader communication with the host. This limited set of functions should be easily supported by almost any physical peripheral. The 4 functions required by the bootloader are listed below. The initialization of the communication device needs to be done prior to it being used.
MCC currently generates the communication adapter that works with the device UARTs. This file is named com_adaptor_uart.c and is located in the project directory mcc_generated_files\boot along with the other bootloader files. Other parameters, like the BOOT_CONFIG_MAX_PACKET_SIZE, can be found in the file mcc_generated_files\boot\boot_config.h and is used to set the maximum size of the command packet that the host should use when communicating with the bootloader. This will be used to create a buffer in SRAM that holds the command as it's received and for storing the response that will be sent back to the host. This memory buffer is only used during bootloader time. The space will be re-used by the application when it loads.
- uint16_t BOOT_COM_GetBytesReady()
-
This function returns the amount of data received from the host for the current command. The data is stored in its local memory buffer. The bootloader will continually call this function until there is enough data in the buffer to process.
- uint8_t BOOT_COM_Peek(uint16_t offset)
-
Returns the 1-byte value at the address requested within the receive buffer. The bootloader will call GetBytesReady() prior to this call to make sure that all requests have a valid offset parameter.
- uint16_t BOOT_COM_Read(uint8_t *buffer, uint16_t length)
-
Copies the pending command data located within the communication adapter's driver to the specified buffer. GetBytesReady() will be called prior to this to make sure the bootloader will never request more data than currently in the communication adapter's buffer. Once the data has been copied out, the data in this buffer should be discarded. The number of bytes copied is returned.
- bool BOOT_COM_Write(uint8_t *buffer, uint16_t length)
-
Copies data from specified buffer to the communication device. Once all the data has been processed, a boolean 'true' should be returned. If a problem was encountered, a boolean 'false' should be returned.