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

📄 osupdata.c

📁 LPC2200 使用定时器1匹配式蜂鸣器发声实验
💻 C
📖 第 1 页 / 共 2 页
字号:
   if ( WorkArea[0] == 'u')
        CodeReq = 1;
  else
        CodeReq = 0;
    
    return CodeReq;
    
    
}
/**********************************************************************
** 函数名称: UpdateOsVersion
** 函数功能: 系统升级,即写norflash
**
** 输入:
** 输出:   
**
** 返回值:  1--->正确
**          0--->错误
** 调用模块:
**
************************************************************************/
uint8 UpdateOsVersion(void)
{
    uint16 addr;
    uint16 err;
    uint16 wr_data;
    uint16 BufferWrite[512];
    uint16 i,j;
    uint16 RomIndex;
    
    uint32 tmpAddr;
    uint32 wriAddr;
    
    err=0;
    
    RomIndex = (uint16)(WorkArea[7]<<8) + (WorkArea[6]+1);
        
    for( i = 0, j = 8; j < PackLength; i++, j += 2)
           BufferWrite[i] = (uint16)( WorkArea[j+1] << 8) + WorkArea[j];
           
    BytesCount = i;
    
    //擦除flash
    //如果为第一次写,则擦除flash
    if( RomIndex == 1)
    {   
        SendReqAck(67); //'C'
        WriAddr = 0;
       for(i=8;i<=400;i++)
       {
           if(!Erase_One_Sector(0x800*i))
            SendReqAck(80); //'P';
       }
       
       //ChipErase(); //全片擦除
       SendReqAck(79);//'O'
       DelayNS (20);
       SendReqAck(87);//'W'
       DelayNS (20);
    }
    
    wriAddr = (RomIndex - 1) * BytesCount;
    //写flash
    //
    for( addr = 0; addr < BytesCount; addr++)
    {
        wr_data = BufferWrite[addr];
        tmpAddr = wriAddr + addr;
        WordProgram(tmpAddr,wr_data);
    }
    
    
    //读出flash内容,判断写入是否正确
    for( addr = 0; addr < BytesCount; addr++)
    {
        tmpAddr = wriAddr + addr;
        if( BufferWrite[addr] != WordRead(tmpAddr))
            err++;
    }
    
    WorkArea[0]=0;
 //   WriAddr += BytesCount;
    
    if( err)
        return 0;
        
    return 1;
}


/**************************************************************************
** Function name: WordProgram
** Descriptions:  半字(16位)数据编程。
**    
** Input:         Addr		编程地址(SST39VF1601内部地址)	
**                Data		编程数据
**
** Output:        返回TRUE表示操作成功,返回FALSE表示操作失败
**  
** Modified by:
** Modified Date: 
**
***************************************************************************/
uint8 WordProgram(uint32 Addr, uint16 Data) 
{  
    volatile uint16  *ip;
    uint16   temp1, temp2;

   // 第一个写周期,地址0x5555,数据0xAA
    ip = GetAddr(0x5555);	// 转换地址0x5555
    ip[0] = 0xaaaa;		
    
    // 第二个写周期,地址0x2aaa,数据0x55
    ip = GetAddr(0x2aaa);
    ip[0] = 0x5555;	
    
    // 第三个写周期,地址0x5555,数据0xA0
    ip = GetAddr(0x5555);
    ip[0] = 0xa0a0;		
    	
    // 第四个写周期,地址Addr,数据Data
    ip = GetAddr(Addr);
    *ip = Data;				
  
    temp1 = *ip;			// 预读处理
    
    // 等待操作完成 (若编程操作没有完成,每次读操作DQ6会跳变)
    while(1)				
    {  
        temp1 = *ip;			
        temp2 = *ip;
        if(temp1 == temp2)
        {  
            if(temp1 != Data)
            {  
                return 0;
            }
            else
            {  
                return 1;
            }
        } // end of if(temp1 == temp2)...
    } // end of while(1)...  
    return 1;
}


/***********************************************************************
** Function name: WordRead
** Descriptions:  读取指定地址(Flash内部的)上的半字(16位)数据。 
**
**     
** Input:         Addr		编程地址(SST39VF1601内部地址)	
** Output:        
** 
** Return:       返回值即是读出的数据
**
** Created by: 
** Created Date: 
**
** Modified by:
** Modified Date: 
**
************************************************************************/
uint16  WordRead(uint32 Addr) 
{	
    volatile uint16  *ip;
	
	ip = GetAddr(Addr);
	return(*ip);
}


/*********************************************************************************************************
** Function: ChipErase
** Descr:    芯片全片擦除。         
** Input: 
** Output: 
**
** Returns:  返回TRUE表示操作成功,返回FALSE表示操作失败
**
** Created by: 
** Created Date: 
**
** Modified by:
** Modified Date: 
********************************************************************************************************/
uint8  ChipErase(void) 
{  
    volatile uint16  *ip;
    uint16  temp1, temp2;
    
    // 第一个写周期,地址0x5555,数据0xAA
    ip = GetAddr(0x5555);
    ip[0] = 0xaaaa;		
    
    // 第二个写周期,地址0x2aaa,数据0x55
    ip = GetAddr(0x2aaa);
    ip[0] = 0x5555;		
    
    // 第三个写周期,地址0x5555,数据0x80
    ip = GetAddr(0x5555);
    ip[0] = 0x8080;		
    
    // 第四个写周期,地址0x5555,数据0xAA
    ip = GetAddr(0x5555);
    ip[0] = 0xaaaa;			
    
    // 第五个写周期,地址0x2aaa,数据0x55
    ip = GetAddr(0x2aaa);
    ip[0] = 0x5555;			
    
    // 第六个写周期,地址0x5555,数据0x10
    ip = GetAddr(0x5555);
    ip[0] = 0x1010;			

    temp1 = *ip;
    
    // 等待操作完成 (若擦除操作没有完成,每次读操作DQ6会跳变)
    while(1)				
    {  
        temp1 = *ip;
        temp2 = *ip;
        if(temp1 == temp2)
        {  
            if(temp1 != 0xffff)
            {  
                return 0;
            }
            else
            {  
                return 1;
            }
        } // end of if(temp1 == temp2)...
    } // end of while(1)...
    return 1;
}

/************************************************************************/
/* PROCEDURE:    Check_Toggle_Ready                                     */
/*                                                                      */
/* During the internal program cycle, any consecutive read operation    */
/* on DQ6 will produce alternating 0's and 1's i.e. toggling between    */
/* 0 and 1. When the program cycle is completed, DQ6 of the data will   */
/* stop toggling. After the DQ6 data bit stops toggling, the device is  */
/* ready for next operation.                                            */
/*                                                                      */
/* Input:                                                               */
/*           Dst        must already be set-up by the caller            */
/*                                                                      */
/* Output:   TRUE   Data toggling success                               */
/*           FALSE  Time out                                            */
/************************************************************************/
int Check_Toggle_Ready (uint32 Dst)
{
    volatile uint16  *ip;
    uint8 PreData;
    uint8 CurrData;
    unsigned long TimeOut = 0;

    ip=GetAddr(Dst);
    PreData=ip[0];
    PreData = PreData & 0x0040;          // read DQ6
    while (TimeOut < 0x07FFFFFF)	 // MAX_TIMEOUT=0x07FFFFFF
    {
        ip=GetAddr(Dst);
        CurrData=ip[0];
        CurrData = CurrData & 0x0040;    // read DQ6 again
        if (PreData == CurrData)
        {
	    return TRUE;
        }
	PreData = CurrData;
        TimeOut++;
    }
    return FALSE;
}

/************************************************************************/
/* PROCEDURE:   Erase_One_Sector                                        */
/*                                                                      */
/* This procedure can be used to erase a total of 2048 words.           */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address where the erase operation starts    */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates success in sector-erase             */
/*          return FALSE: indicates failure in sector-erase             */
/************************************************************************/
int Erase_One_Sector(uint32 Dst)
{
   volatile uint16  *ip;
   uint32 DestBuf = Dst;
   int  ReturnStatus;

	//  Issue the Sector Erase command to 39VF160X
    ip = GetAddr(0x5555);
    ip[0] = 0x00aa;			// 第一个写周期,地址0x5555,数据0xAA
    ip = GetAddr(0x2aaa);
    ip[0] = 0x0055;			// 第二个写周期,地址0x2aaa,数据0x55
    ip = GetAddr(0x5555);
    ip[0] = 0x0080;			// 第三个写周期,地址0x5555,数据0x80
    ip = GetAddr(0x5555);
    ip[0] = 0x00aa;			// 第四个写周期,地址0x5555,数据0xAA
    ip = GetAddr(0x2aaa);
    ip[0] = 0x0055;			// 第五个写周期,地址0x2aaa,数据0x55
    ip = GetAddr(DestBuf);
    ip[0] = 0x0030;			// 第六个写周期,地址0x5555,数据0x10

   ReturnStatus = Check_Toggle_Ready(DestBuf);	// wait for TOGGLE bit ready

   return ReturnStatus;
}
/*********************************************************************************************************
** Function name: DelayNS
** Descriptions: 长软件延时。
**              延时时间与系统时钟有关。
** Input: dly	延时参数,值越大,延时越久
** Output: 无
** Created by: 黄绍斌
** Created Date: 2005-12-31 
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  DelayNS(uint32  dly)
{  
	uint32  i;

   	for(; dly > 0; dly--) 
       for(i = 0; i < 100; i++);
}

⌨️ 快捷键说明

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