Example #1
0
/**************************************************************************************************
 * @fn          crcCalcDLDMA
 *
 * @brief       Run the CRC16 Polynomial calculation over the DL image,
 *              using DMA to read the flash memory into the CRC register
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      The CRC16 calculated.
 **************************************************************************************************
 */
static uint16 crcCalcDLDMA(void)
{
  uint8 pageBeg = OAD_IMG_D_PAGE;
  uint8 pageEnd = oadBlkTot / OAD_BLOCKS_PER_PAGE;

#if defined HAL_IMAGE_B
  pageEnd += OAD_IMG_D_PAGE + OAD_IMG_B_AREA;
#else
  pageEnd += OAD_IMG_D_PAGE;
#endif

  HalCRCInit(0x0000);  // Seed thd CRC calculation with zero.

  // Handle first page differently to skip CRC and CRC shadow when calculating
  DMAExecCrc(pageBeg, 4, HAL_FLASH_PAGE_SIZE-4);

  // Do remaining pages
  for (uint8 pg = pageBeg + 1; pg < pageEnd; pg++)
  {
#if defined HAL_IMAGE_B  // Means we are receiving ImgA, so skip ImgB pages
    if (pg == OAD_IMG_B_PAGE)
    {
      pg += OAD_IMG_B_AREA;
    }
#endif
    
    DMAExecCrc(pg, 0, HAL_FLASH_PAGE_SIZE);
  }
  
  return HalCRCCalc();
}
Example #2
0
/**************************************************************************************************
 * @fn          crcCalcDMA
 *
 * @brief       Run the CRC16 Polynomial calculation over the image specified,
 *              using DMA to read the flash memory into the CRC register
 *
 * input parameters
 *
 * @param       page - Flash page on which to beging the CRC calculation.
 *
 * output parameters
 *
 * None.
 *
 * @return      The CRC16 calculated.
 **************************************************************************************************
 */
static uint16 crcCalcDMA(uint8 page)
{
  uint16 crc;
  uint8 pageBeg;
  uint8 pageEnd;
  const img_hdr_t *pImgHdr;
  
  HalFlashRead(page, 0, pgBuf, HAL_FLASH_PAGE_SIZE);

  pImgHdr = (const img_hdr_t *)(pgBuf + BIM_HDR_OSET);

  pageBeg = page;
  pageEnd = pImgHdr->len / (HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE);

  // One page is used for BIM, so we move this image's last page forward
  pageEnd += pageBeg;
  
  // If image A, set last page to be ImgA size + ImgB size
  if (pageBeg == BIM_IMG_A_PAGE)
  {
    pageEnd += BIM_IMG_B_AREA;
  }

  ADCCON1 &= 0xF3;  // CRC configuration of LRSR.

  // CRC seed of 0x0000.
  RNDL = 0x00;
  RNDL = 0x00;

  // Handle first page differently to skip CRC and CRC shadow when calculating
  DMAExecCrc(pageBeg, 4, HAL_FLASH_PAGE_SIZE-4);
  
  // Do remaining pages
  for (uint8 pg = pageBeg + 1; pg < pageEnd; pg++)
  {
    if (pg == BIM_IMG_B_PAGE)
    {
      pg += BIM_IMG_B_AREA;
    }
     
    DMAExecCrc(pg, 0, HAL_FLASH_PAGE_SIZE);
  }
  
  crc = RNDH;
  crc = (crc << 8) | RNDL;

  return crc;
}