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

📄 device.c

📁 intel p33 driver file
💻 C
📖 第 1 页 / 共 3 页
字号:

    if (!TMPL_WaitUntilReady(TMPL_PROGRAM_TIMEOUT))
    {
        stat.Result = StatTimeout;
        return(stat);
    }

    TMPL_GetBlockAddress ( blocknum,  &blockaddr );

    TMPL_WriteF( blockaddr, TMPL_CONFIG_SETUP);
    TMPL_WriteF( blockaddr, TMPL_LOCK_BIT_SET );

    if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
    {
        stat.Result = StatTimeout;
    }

    if ( returnSR )
    {
        stat.SR = TMPL_ReadStatus();
    }


    /* return device to read array mode */
    TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}


/****************************************************************************
 *
 * TMPL_LockBlockDown
 *
 * Description:
 *
 *    This procedure is called to lock down the specified block on the flash
 *    device.  See the flash device datasheet for specific details on this
 *    command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_LockBlockDown ( UINT16 blocknum,
                                 UINT8  returnSR )
{

    TMPL_Status stat;
    UINT32      blockaddr;

    if (!TMPL_WaitUntilReady(TMPL_PROGRAM_TIMEOUT))
    {
        stat.Result = StatTimeout;
        return(stat);
    }

    TMPL_GetBlockAddress ( blocknum,  &blockaddr );

    TMPL_WriteF( blockaddr, TMPL_CONFIG_SETUP);

    TMPL_WriteF( blockaddr, TMPL_LOCKDOWN_BIT_SET );

    if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
    {
        stat.Result = StatTimeout;
    }

    if ( returnSR )
    {
        stat.SR = TMPL_ReadStatus();
    }


    /* return device to read array mode */
    TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}



/****************************************************************************
 *
 * TMPL_LockProtection
 *
 * Description:
 *
 *    This procedure is called to program the protection register user lock
 *    bit on the flash device.  See the flash device datasheet for specific
 *    details on this command.
 *
 * Parameters:
 *
 *    IN      ProtectionRegister - Protection Register number to be locked
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  command_stat and optionally the flash device status
 *                  register value.
 *
 * Assumptions:
 *
 *    Protection Register number to be locked is valid
 *
 ***************************************************************************/
TMPL_Status TMPL_LockProtection ( UINT32 ProtectionRegister, UINT8 returnSR )
{

    UINT32      baseadd;
    TMPL_Status stat;


    if (P33_BOTTOM)
    {


        if (ProtectionRegister == 0)
        {
			baseadd = TMPL_OTP_BASE + TMPL_OTP_BLOCK_OFFSET;
        } else
        {
            baseadd = TMPL_OTP_BASE2 + TMPL_OTP_BLOCK_OFFSET;
        }

    } else
    {


        if (ProtectionRegister == 0)
		{
            baseadd = TMPL_OTP_BASE + TMPL_OTP_BLOCK_OFFSET;
        } else
        {
            baseadd = TMPL_OTP_BASE2 + TMPL_OTP_BLOCK_OFFSET;
        }

    }


    /* Make sure part is ready */
    if ( !TMPL_WaitUntilReady(TMPL_PROGRAM_TIMEOUT) )
    {

        stat.Result = StatTimeout;

        if ( returnSR )
        {
            stat.SR = TMPL_ReadStatus();
        }

        return( stat );
    }


    if ( returnSR )
    {
        TMPL_ClearStatus();
    }



    if (ProtectionRegister == 0)
    {

        TMPL_WriteF(baseadd, TMPL_OTP_PROGRAM );
        TMPL_WriteF(baseadd, TMPL_OTP_LOCK);
    }

    else
    {


        TMPL_WriteF(baseadd, TMPL_OTP_PROGRAM );


        switch (ProtectionRegister)
        {
        case 1: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR1);
            break;
        case 2: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR2);
            break;
        case 3: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR3);
            break;
        case 4: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR4);
            break;
        case 5: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR5);
            break;
        case 6: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR6);
            break;
        case 7: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR7);
            break;
        case 8: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR8);
            break;
        case 9: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR9);
            break;
        case 10: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR10);
            break;
        case 11: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR11);
            break;
        case 12: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR12);
            break;
        case 13: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR13);
            break;
        case 14: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR14);
            break;
        case 15: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR15);
            break;
        case 16: TMPL_WriteF(baseadd, TMPL_OTP_LOCK_PR16);
            break;
        }

    }


    if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
    {
        stat.Result = StatTimeout;
    } else
    {
        stat.Result = StatCompleted;
    }

    if ( returnSR )
    {
        stat.SR = TMPL_ReadStatus();
    }

    /* return device to read array mode */
    TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}

/****************************************************************************
 *
 * TMPL_PageMode
 *
 * Description:
 *
 *    This procedure is called to enable or disable page mode read to
 *    the device. If pagemode is disabled, device is in synchronous
 *    read mode.
 *
 * Parameters:
 *
 *    IN    enable - flag "1" to indicate the page mode is enable and
 *                   flag "0" to indicate the page mode is disabled and
 *                   the device is set to synchrnous
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_PageMode ( UINT16 enable )
{

    TMPL_Status stat;
    UINT32      address; /* contains the address to load the
                            Read Configuration Register with */

    if ( enable )
    {
	        address = TMPL_PAGE_READ_MODE;
    } else
    {
        address = TMPL_STD_READ_MODE;
    }


    address = address << 1;  /* shift so address is on A16..A1 */


   /* write Read Configuration command */
    TMPL_WriteF( address, TMPL_CONFIG_SETUP );
    TMPL_WriteF( address, TMPL_SET_READ_CONFIG );

    stat.Result = StatCompleted;
	stat.SR = TMPL_ReadStatus();


    /* return device to read array mode */
    TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}



/****************************************************************************
 *
 * TMPL_ProgramFlashBuffered
 *
 * Description:
 *
 *    This procedure is called to program the flash device at the specified
 *    starting address contiguously with the specified buffer data.  See
 *    the flash device datasheet for specific details on the write to buffer
 *    command.
 *
 * Parameters:
 *
 *    IN      address  - the flash address to be programmed.
 *
 *    IN      buffer   - the buffer containing data to be programmed.
 *
 *    IN      numwords - the number of words (ie two bytes) of data contained in the buffer.
 *                                This is a X16 write buffer routine and the part expects a count in # of words
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
#if X_16
TMPL_Status TMPL_ProgramFlashBuffered ( UINT32    address,
                                        UINT16_PTR buffer,
                                        UINT32     numwords,
                                        UINT8      returnSR )
{

    TMPL_Status     stat;
    UINT32          cur_add;
    UINT16          expect;

    if (numwords > TMPL_BUFFER_SIZE)
    {
        stat.Result = StatTimeout;

        if ( returnSR )
        {
            stat.SR = TMPL_ReadStatus();
        }

        return( stat );
    }

    /* Make sure part is ready */
    if ( !TMPL_WaitUntilReady(TMPL_PROGRAM_TIMEOUT) )
    {

        stat.Result = StatTimeout;
        if ( returnSR )
        {
            stat.SR = TMPL_ReadStatus();
        }

        return( stat );
    }

    /* Write program command, buffer size and data then wait until done */
    TMPL_WriteF(address,TMPL_WRITE_TO_BUFFER);

    TMPL_WriteF(address,(UINT16)(numwords-1) );

    for (cur_add=address;
         cur_add-address < (numwords<<1);
         cur_add+=sizeof(UINT16))
    {
        expect = *buffer;
		buffer ++;
        TMPL_WriteF(cur_add,expect);
    }
    cur_add -= sizeof(UINT16);  /* can't advance beyond end of array */
    TMPL_WriteF(cur_add,TMPL_CONFIRM);

    if (!TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ))
    {
        stat.Result = StatTimeout;

        if ( returnSR )
        {
            stat.SR = TMPL_ReadStatus();
        }

        return( stat );
    }

    TMPL_WriteF(address,TMPL_READ_ARRAY); /* return to array read mode */


    stat.Result = StatCompleted;
    if ( returnSR )
        {
            stat.SR = TMPL_ReadStatus();
        }

    return(stat);

}
#endif /* X_16 */

/****************************************************************************
 *
 * TMPL_ProgramProtection
 *
 * Description:
 *
 *    This procedure is called to program the protection registers on
 *    the flash device at the specified location with the specified data
 *    value.  See the flash device datasheet for specific details on this
 *    command.
 *
 * Parameters:
 *
 *    IN      location - the protection register location on the flash
 *                       device to be programmed.
 *
 *    IN      value    - the data item to be programmed.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_ProgramProtection ( UINT32     location,
                                     TMPL_FDATA value,
                                     UINT8      returnSR )
{
	UINT32      address;
    TMPL_Status stat;


    if ( location > TMPL_OTP_NUMWORDS )
    {
        stat.Result = StatBadOtp;
        return( stat );
    }

    if (!TMPL_WaitUntilReady(TMPL_PROGRAM_TIMEOUT))
    {
        stat.Result = StatTimeout;
        return(stat);

⌨️ 快捷键说明

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