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

📄 k9fxx08.c

📁 此源代码是针对ZLG单片机公司开发的SmartARM2200平台的uCLinux驱动及应用源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
** Created Date: 2005-2-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        uint8 K9fxx08SectorProgram(const K9fXX08Hardware *Index, void *Buf, uint32 SecIndex)
{
    unsigned int i;
    volatile uint8 *CLE;
    volatile uint8 *ALE;
    volatile uint8 *Data;
    uint8 *cp;
    uint8 (* DataToK9fxx08)(uint8 Data);
    
    cp = Buf;
    if (Index != NULL)
    {
        CLE = Index->CLE;
        ALE = Index->ALE;
        Data = Index->Data;
        DataToK9fxx08 = Index->DataToK9fxx08;
   
        *CLE = DataToK9fxx08(K9FXX_SET_ADDR_A);
        *CLE = DataToK9fxx08(K9FXX_BLOCK_PROGRAM_1);
        *ALE = DataToK9fxx08(0);
        *ALE = DataToK9fxx08(SecIndex & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 8) & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 16) & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 24) & 0xff);
        
        i = Index->BytsPerSec;
        do
        {
            *Data = *cp++;
        } while ( --i != 0);

        *CLE = DataToK9fxx08(K9FXX_BLOCK_PROGRAM_2);
        return K9fxx08OK(Index);
    }
    return FALSE; 
}

/*********************************************************************************************************
** Function name: K9fxx08SectorCProgram
** Descriptions: 编程芯片扇区附加数据  Program chip sector subjoin data
** Input:Index: 芯片信息结构体 chip information struct
**       Buf:数据缓冲区 data buf
**       SecIndex:扇区索引 sector index
** 
** Output: TRUE: 成功  OK
**         FALSE: 未成功 Not OK
** 
** Created by: chenmingji
** Created Date: 2005-2-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        uint8 K9fxx08SectorCProgram(const K9fXX08Hardware *Index, void *Buf, uint32 SecIndex)
{
    unsigned int i;
    volatile uint8 *CLE;
    volatile uint8 *ALE;
    volatile uint8 *Data;
    uint8 *cp;
    uint8 (* DataToK9fxx08)(uint8 Data);
    
    cp = Buf;
    if (Index != NULL)
    {
        CLE = Index->CLE;
        ALE = Index->ALE;
        Data = Index->Data;
        DataToK9fxx08 = Index->DataToK9fxx08;
    
        *CLE = DataToK9fxx08(K9FXX_SET_ADDR_C);
        *CLE = DataToK9fxx08(K9FXX_BLOCK_PROGRAM_1);
        *ALE = DataToK9fxx08(0);
        *ALE = DataToK9fxx08(SecIndex & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 8) & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 16) & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 24) & 0xff);

        i = Index->BytsPerSecC;
        do
        {
            *Data = *cp++;
        } while ( --i != 0);

        *CLE = DataToK9fxx08(K9FXX_BLOCK_PROGRAM_2);
        return K9fxx08OK(Index);
    }
    return FALSE; 
}

/*********************************************************************************************************
** Function name: K9fxx08BlockErase
** Descriptions: 擦除芯片扇区所在的块  erase chip block (include sector)
** Input:Index: 芯片信息结构体 chip information struct
**       SecIndex:块中的某个扇区的索引 sector(in block) index
** 
** Output: TRUE: 成功  OK
**         FALSE: 未成功 Not OK
** 
** Created by: chenmingji
** Created Date: 2005-2-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        uint8 K9fxx08BlockErase(const K9fXX08Hardware *Index, uint32 SecIndex)
{
    volatile uint8 *CLE;
    volatile uint8 *ALE;
    volatile uint8 *Data;
    uint8 (* DataToK9fxx08)(uint8 Data);
    
    if (Index != NULL)
    {
        CLE = Index->CLE;
        ALE = Index->ALE;
        Data = Index->Data;
        DataToK9fxx08 = Index->DataToK9fxx08;

        *CLE = DataToK9fxx08(K9FXX_BLOCK_ERASE_1);
        *ALE = DataToK9fxx08(SecIndex & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 8) & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 16) & 0xff);
        *ALE = DataToK9fxx08((SecIndex >> 24) & 0xff);
        *CLE = DataToK9fxx08(K9FXX_BLOCK_ERASE_2);
        
        return K9fxx08OK(Index);
    }
    return FALSE;
}

/*********************************************************************************************************
** Function name: K9fxx08ReadID
** Descriptions: 读芯片ID  read chip ID
** Input:Index: 芯片信息结构体 chip information struct
** 
** Output: 芯片ID  chip ID
** 
** Created by: chenmingji
** Created Date: 2005-2-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        uint16 K9fxx08ReadID(const K9fXX08Hardware *Index)
{
    uint8 a, b;
    volatile uint8 *CLE;
    volatile uint8 *ALE;
    volatile uint8 *Data;
    uint8 (* DataToK9fxx08)(uint8 Data);
    uint8 (* DataToMCU)(uint8 Data);

    a = 0;
    b = 0;
    if (Index != NULL)
    {
        CLE = Index->CLE;
        ALE = Index->ALE;
        Data = Index->Data;
        DataToK9fxx08 = Index->DataToK9fxx08;
        DataToMCU = Index->DataToMCU;
    
        *CLE = DataToK9fxx08(K9FXX_READ_ID);
        *ALE = DataToK9fxx08(0);
    
        a = DataToMCU(*Data);
        b = DataToMCU(*Data);
    }
    
    return (a << 8) | b;
}

/*********************************************************************************************************
** Function name: K9fxx08SecCopy
** Descriptions: 芯片内扇区拷贝  copy chip sector
** Input:Index: 芯片信息结构体 chip information struct
**       SourSecIndex:源扇区索引 source sector index
**       DestSecIndex:目标扇区索引 destination sector index
** 
** Output: TRUE: 成功  OK
**         FALSE: 未成功 Not OK
** 
** Created by: chenmingji
** Created Date: 2005-2-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        uint8 K9fxx08SecCopy(const K9fXX08Hardware *Index, uint32 SourSecIndex, uint32 DestSecIndex)
{
    if (Index != NULL)
    if (K9fxx08SectorRead(Index, Index->Buf, SourSecIndex) == TRUE)
    {
        return K9fxx08SectorProgram(Index, Index->Buf, DestSecIndex);
    }
    return FALSE;
}

/*********************************************************************************************************
** Function name: K9fxx08BlockCheck
** Descriptions: 芯片块初始有效检测  chip block OK at leave factory
** Input:Index: 芯片信息结构体 chip information struct
**       BlockIndex:块索引  block index
**
** Output: TRUE: 成功  OK
**         FALSE: 未成功 Not OK
** 
** Created by: chenmingji
** Created Date: 2005-2-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        uint8 K9fxx08BlockCheck(const K9fXX08Hardware *Index, uint32 BlockIndex)
{
    uint8 Buf[64];
    
    if (Index != NULL)
    if (K9fxx08SectCRead(Index, Buf, BlockIndex * (Index->SecPerBlock)) == TRUE)
    {
        if (Buf[5] == 0xff)
        {
            if (K9fxx08SectCRead(Index, Buf, BlockIndex * (Index->SecPerBlock) + 1) == TRUE)
            {
                if (Buf[5] == 0xff)
                {
                    return TRUE;
                }
            }
        }
    }
    return FALSE;
}

/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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