AT26D_Unprotect
Default mainpageat91libmemoriesspi-flashAT26D_Unprotect
Description Source Call Graph
Start Line: 167
unsigned char AT26D_Unprotect(At26 *pAt26)
{
    unsigned char status;

    SANITY_CHECK(pAt26);

    // Get the status register value to check the current protection
    status = AT26D_ReadStatus(pAt26);
    if ((status & AT26_STATUS_SWP) == AT26_STATUS_SWP_PROTNONE) {

        // Protection already disabled
        return 0;
    }
    
    // Check if sector protection registers are locked
    if ((status & AT26_STATUS_SPRL) == AT26_STATUS_SPRL_LOCKED) {

        // Unprotect sector protection registers by writing the status reg.
        AT26D_EnableWrite(pAt26);
        AT26D_WriteStatus(pAt26, 0);
    }
    
    // Perform a global unprotect command
      AT26D_EnableWrite(pAt26);
    AT26D_WriteStatus(pAt26, 0);
    
    // Check the new status
    status = AT26D_ReadStatus(pAt26);
    if ((status & (AT26_STATUS_SPRL | AT26_STATUS_SWP)) != 0) {

        return AT26_ERROR_PROTECTED;
    }
    else {

        return 0;
    }
}