davincievm_flash_checksum.c

来自「TI的DM6446的硬件平台搭建的相关例子」· C语言 代码 · 共 40 行

C
40
字号
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */

/*
 *  Flash implementation - Compute checksum
 *
 */

#include "davincievm_flash.h"

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_FLASH_checksum( start, length )                              *
 *      Compute the checksum from ( start ) to ( start + length ).  The     *
 *      checksum is a 32-bit cumulative sum of each 8-bit byte in the       *
 *      range.                                                              *
 *                                                                          *
 *      start  <- starting address                                          *
 *      length <- length in bytes                                           *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Uint32 DAVINCIEVM_FLASH_checksum( Uint32 start, Uint32 length )
{
    Uint32 i, checksum32 = 0;

    /* Flash Mode: Read Array */
    *( volatile Uint16* )start = FLASH_RESET;

    /* Calculate checksum by adding each byte in the given range */
    for ( i = 0 ; i < length ; i++ )
        checksum32 += *( volatile Uint8* )( start++ );

    /* Return the 32-bit checksum value */
    return checksum32;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?