Beispiel #1
0
void CyBtldr_Load(void) 
{
#if defined (WORKAROUND_OPT_XRES)
    uint8 rowBuffer[CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE];

    /* Don't really care whether the call succeeds or not. Either way we need to reset and run the bootloader */
    CySetTemp(); 
    CySetFlashEEBuffer(rowBuffer);
#endif
    CYBTDLR_SET_RUN_TYPE(CYBTLDR_START_BTLDR);
    CYBTLDR_SOFTWARE_RESET;
}
Beispiel #2
0
    cystatus Em_EEPROM_Write(const uint8 srcBuf[], const uint8 eepromPtr[], uint32 byteCount)
#endif /* (!CY_PSOC3) */
{
    uint8 writeBuffer[CY_FLASH_SIZEOF_ROW];
    uint32 arrayId;
    uint32 rowId;
    uint32 dstIndex;
    uint32 srcIndex;
    cystatus rc;
    uint32 eeOffset;
    uint32 byteOffset;
    
    #if (!CY_PSOC4)
        #if (CYDEV_ECC_ENABLE == 0)
            uint8 rowBuffer[CY_FLASH_SIZEOF_ROW + CY_FLASH_SIZEOF_ECC_ROW];
        #endif /* CYDEV_ECC_ENABLE == 0) */
    #endif /* (!CY_PSOC4) */

    eeOffset = (uint32)eepromPtr;
    #if (CY_PSOC3)
        eeOffset &= Em_EEPROM_CODE_ADDR_MASK;
    #endif /* (CY_PSOC3) */

    /* Make sure, that eepromPtr[] points to ROM */
    #if (CY_PSOC3)
        if (((uint32)eepromPtr >= Em_EEPROM_CODE_ADDR_OFFSET) &&
            (((uint32)eepromPtr + byteCount) <= Em_EEPROM_CODE_ADDR_END))
    #else
        if (((uint32)eepromPtr + byteCount) < Em_EEPROM_FLASH_END_ADDR)
    #endif /* (CY_PSOC3) */
    {
        #if (!CY_PSOC4)
            (void)CySetTemp();

            #if(CYDEV_ECC_ENABLE == 0)
                (void)CySetFlashEEBuffer(rowBuffer);
            #endif
        #endif /* (!CY_PSOC4) */

        arrayId = eeOffset / CY_FLASH_SIZEOF_ARRAY;
        rowId = (eeOffset / CY_FLASH_SIZEOF_ROW) % Em_EEPROM_ROWS_IN_ARRAY;
        byteOffset = (CY_FLASH_SIZEOF_ARRAY * arrayId) + (CY_FLASH_SIZEOF_ROW * rowId);
        srcIndex = 0u;

        rc = CYRET_SUCCESS;

        while ((srcIndex < byteCount) && (CYRET_SUCCESS == rc))
        {
            /* Copy data to the write buffer either from the source buffer or from the flash */
            for (dstIndex = 0u; dstIndex < CY_FLASH_SIZEOF_ROW; dstIndex++)
            {
                if ((byteOffset >= eeOffset) && (srcIndex < byteCount))
                {
                    writeBuffer[dstIndex] = srcBuf[srcIndex];
                    srcIndex++;
                }
                else
                {
                    writeBuffer[dstIndex] = CY_GET_XTND_REG8(CYDEV_FLASH_BASE + byteOffset);
                }
                byteOffset++;
            }

            /* Write flash row */
            #if (CY_PSOC4)
                rc = CySysFlashWriteRow(rowId, writeBuffer);
            #else
                rc = CyWriteRowData((uint8)arrayId, (uint16)rowId, writeBuffer);
            #endif /* (CY_PSOC4) */

            /* Go to the next row */
            rowId++;
            #if (CY_FLASH_NUMBER_ARRAYS > 1)
                if (rowId >= Em_EEPROM_ROWS_IN_ARRAY)
                {
                    arrayId++;
                    rowId = 0u;
                }
            #endif /* (CY_FLASH_NUMBER_ARRAYS > 1) */
        }

        /* Flush both Cache and PHUB prefetch buffer */
        #if (CY_PSOC5)
            CyFlushCache();
        #elif (CY_PSOC3)
            CY_FLASH_CONTROL_REG |= 6u;
        #endif /* (CY_PSOC5) */
    }
    else
    {
        rc = CYRET_BAD_PARAM;
    }

    /* Mask return codes from flash, if they are not supported */
    if ((CYRET_SUCCESS != rc) && (CYRET_BAD_PARAM != rc))
    {
        rc = CYRET_UNKNOWN;
    }
    
    return (rc);
}