⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbtcburndsk5402.c

📁 基于ti 5402dsk的flashburn程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
                timeoutcount += 1;
            } while (*pBurn != *data && timeoutcount != 0xffff);                       
            
            if (timeoutcount == 0xffff)
            {
                break;
            }

            data++;
            flashnextindex++;
        }
    }
  
    SetPage(0);
    FlashDisable();
}


/**
 * Get the contents of a flash location
 *
 * @param [in] index - Zero-based index into flash memory
 *
 * @return - The contents of flash memory at the location
 */
FLASH_DATA_TYPE GetFlashVal(FLASH_IMAGE_INDEX_TYPE index)
{
    u16 myval;
    
    FlashEnable();
    SetPage(GetPageNum(index));
    myval = *GetFlashAddr(index);
    FlashDisable();
    
    return myval;
}


/**
 * Given a buffer of flash indices, 32 bits each, translate them
 * to a buffer of flash addresses.  Targets with paged memory may
 * encode the page number in the upper bits.
 *
 * @param [in] count - Count of indexes in the buffer
 * @param [in] data  - Buffer of flash indices 
 *
 * @return Flash addresses corresponding to the indices
 *
 * @pre  - InitFlash() has been run
 */
void GetFlashAddresses(u16 count)
{
    u16 i;
    for (i=0; i<count*2; i+=2)
    {
        u32 index;
        u32 addr;
        // Get the index from the command buffer
        index = GetData(i);
        index <<= 16;
        index |= GetData(i+1);
        
        // Compute the address corresponding to the given index
        // On C54x, put the page number in the upper 16 bits.
        addr = GetPageNum(index);
        addr <<= 16;
        addr |= (u16)GetFlashAddr(index);
        
        // Write the address back to the buffer
        SetData(i,   (MSG_DATA_TYPE)((addr & 0xFFFF0000)>>16));
        SetData(i+1, (MSG_DATA_TYPE)(addr & 0x0000FFFF));
    }
}


/**
 * Sends a block of flash bytes to host
 *
 * @param [in] index  - Zero based index into flash memory
 * @param [in] nBytes - Count of bytes to send
 *
 * @pre  - InitFlash() has been run
 * @pre  - nBytes is not larger than MAXDATABYTES
 * @post - Flash contents have been sent to the host
 */
void SendFlashBufToHost(u16 cmd, FLASH_IMAGE_INDEX_TYPE index, u32 nBytes)
{
    u16 *pagememptr;
    u16 pagestart, pagelast;
    u16 i, n;

    pagestart = GetPageNum(index);
    pagelast  = GetPageNum(index + (nBytes/BYTESPERMAU)-1);

    /* Prepare the response message header */
    SetCmd(cmd);     
    SetArg(0, nBytes);

    FlashEnable();
    if (pagestart == pagelast)
    {
        /* All desired data are in same page. */
        SetPage(pagestart);
        pagememptr = GetFlashAddr(index);
        n = nBytes / 2;
        for (i=0; i<n; i+=1)
        {
            SetData(i, *pagememptr++);
        }
    }
    else
    {
        /* Desired data cross at least one page boundary */
        int len = nBytes / 2;
        int n;
        int i = 0;

        while (len > 0)
        {
            /* How many bytes can I read from this page? */ 
            pagestart = GetPageNum(index);
            n = GetPageMAURemaining(index);
            if (n > len)
            {
                n = len;
            }
            len -= n;    /* for next time thru */ 
        
            /* Set paging and enable flash access */
            pagememptr = GetFlashAddr(index);
            index += n;  /* also for next time thru */
    
            SetPage(pagestart); 
            while (n-- > 0)
            {
                SetData(i++, *pagememptr++);
            }
        }
    }
    
    SetPage(0);
    FlashDisable();
}


/**
 * Erase all of flash memory
 *
 * @pre  - InitFlash() has been run
 * @post - All of flash is erased
 */
void EraseFlash(void)
{
    volatile FLASH_DATA_TYPE* volatile p5 = (FLASH_DATA_TYPE *)(GetFlashBase()+0x5555);
    volatile FLASH_DATA_TYPE* volatile pA = (FLASH_DATA_TYPE *)(GetFlashBase()+0x2AAA);

    InitFlash();

    /* Set page to 0 and enable flash access */ 
    FlashEnable();
    SetPage(0);

    /* 
     * Erase chip
     * It takes about 2.5 secs for this, according to specs 
     * for the STMicro M29W400. 
     */
    *p5 = 0xAA;
    *pA = 0x55;
    *p5 = 0x80;
    *p5 = 0xAA;
    *pA = 0x55;
    *p5 = 0x10;
    
    FlashDisable();

    ErsStatus = 1;
    
    CheckFlashErase();  /* returns when erase is done */
}


/**
 * Erase an individual flash memory sector.  The definition of a flash
 * sector is implementation dependent
 *
 * @param [in] sector - Sector number to be erased - numbering is target 
 * dependent
 *
 * @pre  - InitFlash() has been run
 * @post - The given flash sector has been erased
 */
void EraseFlashSector(unsigned long sector)
{
    /* Not implemented on the C5402DSK version of FlashBurn */
    return;
}
 

/**
 * Check the flash erase status - return when the erasure is completed
 * 
 * @pre  - InitFlash() has been run
 * @post - When the function returns, flash erasure is complete
 */
void CheckFlashErase(void)
{
    while (ErsStatus != 0)
    {
        FlashEnable();
        SetPage(0);
        if (*((u16 *)GetFlashBase()) == 0xffff)
        {
            ErsStatus = 0;
        }
        FlashDisable();
    }
}


/**
 * Initialize the checksum value
 *
 * @param [in] val - Initial value for the checksum
 *
 * @pre  - InitFlash() has been run
 * @post - The checksum is initialized
 */
void CKSSet(u16 val)
{
    cksum = val;
}
    

/**
 * Returns the current checksum value
 *
 * @return - The currently computed checksum value
 * 
 * @pre  - InitFlash() has been run
 */
u16 CKSGet(void)
{
    return (u16)cksum;
}


/** 
 * Compute a checksum of a buffer
 *
 * @param [in] index  - Zero based index into flash to start computing the 
 * checksum
 * @param [in] nBytes - Length of flash to use for the checksum, in bytes
 * 
 * @return - The value of the checksum
 *
 * @pre  - InitFlash() has been run
 * @post - Accumulated checksum is updated
 */
u16 CKSAccumBuf(FLASH_IMAGE_INDEX_TYPE index, unsigned long nBytes)
{
    u16 page;
    u16 *pPage;
    long n;
    unsigned long nWords = nBytes / BYTESPERMAU;
    volatile FLASH_DATA_TYPE* volatile p5 = (FLASH_DATA_TYPE *)(GetFlashBase()+0x5555);
    volatile FLASH_DATA_TYPE* volatile pA = (FLASH_DATA_TYPE *)(GetFlashBase()+0x2AAA);
    volatile FLASH_DATA_TYPE* volatile pX = (FLASH_DATA_TYPE *)(GetFlashBase());
    int i;

    FlashEnable();
    /* Issue a Read Reset command, and pause for the memory to reset */
    SetPage(0);
    *p5 = 0xAA;
    *pA = 0x55;
    *pX = 0xf0;
    for (i=0; i<5000; i++) ;
    
    while (nWords > 0)
    {
        /* How many bytes can I read from this page? */ 
        page = GetPageNum(index);
        n = GetPageMAURemaining(index);
        if (n > nWords)
        {
            n = nWords;
        }
        nWords -= n;    /* for next time thru */ 
    
        /* Set paging and enable flash access */
        pPage = GetFlashAddr(index);
        index += n;
                
        SetPage(page);

        /* Accumulate bytes into the checksum */
        while(n-- > 0)
        {
            unsigned long val = *pPage++;
            cksum += val >> 8;          /* MSB */
            if(cksum >= 65536)
            {
                cksum += 1;
                cksum &= 0xffff;
            } 
            cksum += val & 0x000000ff;  /* LSB */
            if(cksum >= 65536)
            {
                cksum += 1;
                cksum &= 0xffff;
            } 
        }
            
        SetPage(0);
    }

    FlashDisable();
    return (u16)cksum;
}

⌨️ 快捷键说明

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