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

📄 flash_burn.c

📁 TMS320VC5509A烧写片外串行FLASH的程序
💻 C
字号:
/*********************************************************************
 * Filename:      flash_burn.c
 *                
 * Description:   
 *                
 * Copyright (C) 2009,  Vi.Wang
 * Author:        Vi.Wang <redfox_ww@126.com>
 * Created at:    Fri Apr 24 23:47:39 2009
 *                
 * Modified by:   Vi.Wang <redfox_ww@126.com>
 * Modified at:   Sat Apr 25 19:26:38 2009
 *                
 * Status:        Experimental, do not distribute.
 * Update count:  0
 *                
 ********************************************************************/

#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_gpio.h>
#include <stdio.h>
#include <stdlib.h>
#include <csl_irq.h>
#include <csl_mcbsp.h>
#include <file.h>

#include "sst25vf040b.h"

MCBSP_Handle mcbsp_handle;

PLL_Config  pll_config = {
	0,		/* IAI: the PLL locks using the same process that was underway 
				before the idle mode was entered */
	1,		/*IOB: If the PLL indicates a break in the phase lock, 
				it switches to its bypass mode and restarts the PLL phase-locking 
				sequence */
	9,		/*PLL multiply value; multiply 9 times */
	0		/*Divide by 0 PLL divide value; it can be either PLL divide value 
				(when PLL is enabled), or Bypass-mode divide value
				(PLL in bypass mode, if PLL multiply value is set to 1) */
};

extern void VECSTART(void);

Uint16 tmp[256];
void main(void)
{
    FILE *fp=NULL;
    Uint32 i, j;
    Uint32 addr=0;
    Uint32 len=0;

    /* Init CSL Lib*/	
    CSL_init();

    /* Set Pll*/
    PLL_config(&pll_config);
    IRQ_globalDisable();
    
   	/*Init McBSP0*/
	mcbsp_handle = MCBSP_open(MCBSP_PORT0, MCBSP_OPEN_RESET);
	MCBSP_FSET(PCR0,XIOEN,1);
	MCBSP_FSET(PCR0,RIOEN,1);  
	MCBSP_FSET(PCR0,FSXM,1);
	MCBSP_FSET(PCR0,FSRM,0); 	
	MCBSP_FSET(PCR0,CLKXM,1);
	MCBSP_FSET(PCR0,CLKRM,0);

    /* Set GPIO4 to Output*/
    GPIO_FSET(IODIR, IO4DIR, 1);

    flash_init();
    
	/* /\* unprotect all the blocks *\/ */
	flash_write_status_register(0);
    flash_write_disable();
    printf("Flash status register: 0x%02x\n\r", flash_read_status_register());
    printf("Flash JEDEC ID: 0x%06x \n\r", flash_jedec_id_read());
    printf("Addr 0x000010: 0x%02x.\n\r", flash_read_byte(0x10));
    printf("Addr 0x015e10: 0x%02x.\n\r", flash_read_byte(0x15e00));
   
	/* erase flash */
	flash_chip_erase();
    printf("Chip erase finish.\n\r");
    printf("Addr 0x000010: 0x%02x.\n\r", flash_read_byte(0x10));
    printf("Addr 0x015e10: 0x%02x.\n\r", flash_read_byte(0x15e10));

    if ((fp = fopen("..\\bin\\melp.bin", "rb")) != NULL)
    {
        printf("Open melp.bin success!\n\r");

        addr = 0;
        fseek(fp, 0, SEEK_END);
        len = ftell(fp);
        printf("File size is %d%04d byte.\n\r", (Uint16)(len/10000), (Uint16)(len%10000));
        fseek(fp, 0, SEEK_SET);
        for (i=0; i<(len/(sizeof(tmp)<<1)); i++)
        {
            memset(tmp, 0, sizeof(tmp));
            for (j=0; j<sizeof(tmp); j++)
            {
                tmp[j] = fgetc(fp);
                tmp[j] |= (fgetc(fp) << 8);
            }
            
            flash_write_nword(addr, tmp, sizeof(tmp));
            addr += (sizeof(tmp) << 1);
        }
        memset(tmp, 0, sizeof(tmp));
        j=0;
        while (!(feof(fp)))
        {
            if (j & 0x01)
            {
                tmp[j>>1] |= (fgetc(fp) << 8);
            }
            else
            {
                tmp[j>>1] = fgetc(fp);
            }
            j++;
        }
        flash_write_nword(addr, tmp, j/2);
        addr += j;
        printf("Write flash finished.\n\r");
        printf("Total: %d%04d byte.\n\r", (Uint16)(addr/10000), (Uint16)(addr%10000));
        fclose(fp);
    }
    else
    {
        printf("Cann\'t open melp.bin\n\r");
    }
    
	while(1);
}

⌨️ 快捷键说明

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