Microchip® Advanced Software Framework

flashLoader.c File Reference

Implementation of internal flash loader.

Copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.

#include <types.h>
#include <bootStructure.h>
#include <asf.h>
#include <flashLoader.h>

Data Structures

union  FlashWord_t
 

Macros

#define FIRST_PAGE   0
 
#define FLASH_READY()   (NVMCTRL_INTFLAG_s.ready)
 
#define LAST_PAGE   1023
 

Typedefs

typedef enum flash_cmd_tag flash_cmd_t
 

Enumerations

enum  flash_cmd_tag {
  ERASE_ROW = 0x02,
  WRITE_PAGE = 0x04,
  ERASE_AUXILARYROW = 0x05,
  WRITE_AUXILARYPAGE = 0x06,
  LOCK_REGION = 0x40,
  UNLOCK_REGION = 0x41,
  SET_POWERREDUCTIONMODE = 0x42,
  CLEAR_POWERREDUCTIONMODE = 0x43,
  PAGE_BUFFERCLEAR = 0x44,
  SET_SECURITYBIT = 0x45,
  INVALID_ALLCACHE = 0x46
}
 

Functions

void flashFlushPage (void)
 Flush unloaded data before exit from bootloader. More...
 
void flashPacketToPage (void)
 Load received date to the flash. More...
 
void flashUpdateAppStartAddr (void)
 Updates application start address in end of flash. More...
 
void hwEraseFlashPage (uint32_t pageStartAddress)
 Erases specified flash page. More...
 
void hwFillFlashPageBuffer (uint32_t startOffset, uint16_t length, uint8_t *data)
 Writes data to the page buffer. More...
 
void hwFlashWriteEepromPage (HW_EepromParams_t *eeprom)
 Writes a page to the EEPROM. More...
 
void hwWriteFlashPage (uint32_t pageStartAddress)
 Writes flash page buffer without erasing. More...
 
void nvm_init (void)
 

Variables

uint32_t appStartAddr
 
static uint16_t currentPage = 0
 
BootBuffer_t dataBuffer
 
static uint16_t pageBufferToFill [ROW_SIZE_IN_HALF_WORDS]
 
static uint8_t temporaryPageBuffer [FLASH_PAGESIZE]
 

#define FIRST_PAGE   0
#define FLASH_READY ( )    (NVMCTRL_INTFLAG_s.ready)
#define LAST_PAGE   1023

typedef enum flash_cmd_tag flash_cmd_t

Enumerator
ERASE_ROW 
WRITE_PAGE 
ERASE_AUXILARYROW 
WRITE_AUXILARYPAGE 
LOCK_REGION 
UNLOCK_REGION 
SET_POWERREDUCTIONMODE 
CLEAR_POWERREDUCTIONMODE 
PAGE_BUFFERCLEAR 
SET_SECURITYBIT 
INVALID_ALLCACHE 

void flashFlushPage ( void  )

Flush unloaded data before exit from bootloader.

References currentPage, FLASH_PAGESIZE, flashUpdateAppStartAddr(), hwEraseFlashPage(), hwFillFlashPageBuffer(), hwWriteFlashPage(), and temporaryPageBuffer.

Referenced by srecProtocol().

void flashUpdateAppStartAddr ( void  )

Updates application start address in end of flash.

References appStartAddr, FLASH_END_ADDRESS, FLASH_PAGESIZE, hwEraseFlashPage(), hwFillFlashPageBuffer(), hwWriteFlashPage(), and memcpy_P.

Referenced by clear_updateaction(), and flashFlushPage().

void hwEraseFlashPage ( uint32_t  pageStartAddress)

Erases specified flash page.

Parameters
[in]pageStartAddress- address within the target page

References nvm_erase_row().

Referenced by flashFlushPage(), flashPacketToPage(), flashUpdateAppStartAddr(), hwFlashWriteEepromPage(), memcopy(), update_boot_info(), and writeapp_infotable().

void hwFillFlashPageBuffer ( uint32_t  startOffset,
uint16_t  length,
uint8_t *  data 
)

Writes data to the page buffer.

Parameters
[in]startOffset- start position for writing within the page
[in]length- data to write length in bytes
[in]data- pointer to data to write

References pageBufferToFill, ROW_SIZE, and ROW_SIZE_IN_HALF_WORDS.

Referenced by flashFlushPage(), flashPacketToPage(), flashUpdateAppStartAddr(), hwFlashWriteEepromPage(), memcopy(), update_boot_info(), and writeapp_infotable().

void hwFlashWriteEepromPage ( HW_EepromParams_t eeprom)

Writes a page to the EEPROM.

Parameters
[in]address- address of data byte.
[in]data- data for saving.

References HW_EepromParams_t::address, HW_EepromParams_t::data, hwEraseFlashPage(), hwFillFlashPageBuffer(), hwWriteFlashPage(), HW_EepromParams_t::length, memcpy_P, and ROW_SIZE.

Referenced by eepromPacketToPage().

void hwWriteFlashPage ( uint32_t  pageStartAddress)

Writes flash page buffer without erasing.

Parameters
[in]pageStartAddress- address within the target page

References MCU_PAGE_SIZE, NO_OF_PAGES_PER_ROW, nvm_write_buffer(), pageBufferToFill, and ROW_SIZE.

Referenced by flashFlushPage(), flashPacketToPage(), flashUpdateAppStartAddr(), hwFlashWriteEepromPage(), memcopy(), update_boot_info(), and writeapp_infotable().

uint32_t appStartAddr
uint16_t currentPage = 0
static
BootBuffer_t dataBuffer
uint16_t pageBufferToFill[ROW_SIZE_IN_HALF_WORDS]
static
uint8_t temporaryPageBuffer[FLASH_PAGESIZE]
static