cystatus CySpcGetTemp(uint8 numSamples) #endif /* (CY_PSOC5A) */ { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_GET_TEMP); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_GET_TEMP; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = numSamples; #if(CY_PSOC5A) CY_SPC_CPU_DATA_REG = HI8(timerPeriod); CY_SPC_CPU_DATA_REG = LO8(timerPeriod); CY_SPC_CPU_DATA_REG = clkDivSelect; #endif /* (CY_PSOC5A) */ } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcWriteRow ******************************************************************************** * Summary: * Erases then programs a row in Flash/EEPROM with data in row latch. * * Parameters: * uint8 array: * Id of the array. * * uint16 address: * flash/eeprom addrress * * uint8 tempPolarity: * temperature polarity. * 1: the Temp Magnitude is interpreted as a positive value * 0: the Temp Magnitude is interpreted as a negative value * * uint8 tempMagnitude: * temperature magnitude. * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcWriteRow(uint8 array, uint16 address, uint8 tempPolarity, uint8 tempMagnitude) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_WR_ROW); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_WR_ROW; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; CY_SPC_CPU_DATA_REG = HI8(address); CY_SPC_CPU_DATA_REG = LO8(address); CY_SPC_CPU_DATA_REG = tempPolarity; CY_SPC_CPU_DATA_REG = tempMagnitude; } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcEraseSector ******************************************************************************** * Summary: * Erases all data in the addressed sector (block of 64 rows). * * Parameters: * uint8 array: * Id of the array. * * uint8 sectorNumber: * Zero based sector number within Flash/EEPROM array * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcEraseSector(uint8 array, uint8 sectorNumber) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_ER_SECTOR); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_ER_SECTOR; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; CY_SPC_CPU_DATA_REG = sectorNumber; } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcReadMultiByte ******************************************************************************** * Summary: * Returns 1 to 256 bytes from user space of Flash/EEPROM. Doesn't span row * boundaries. * * Parameters: * uint8 array: * Id of the array. * * uint8 ecc: * 0x80 if reading ecc data. * 0x00 if user data. * * uint16 address: * Flash addrress. * * uint8 size: * Number bytes to load. * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcReadMultiByte(uint8 array, uint8 ecc, uint16 address, uint8 size) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_RD_MULTI_BYTE); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_RD_MULTI_BYTE; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; CY_SPC_CPU_DATA_REG = ecc; CY_SPC_CPU_DATA_REG = HI8(address); CY_SPC_CPU_DATA_REG = LO8(address); CY_SPC_CPU_DATA_REG = size - 1; } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcLoadRow ******************************************************************************** * Summary: * Loads a row of data into the row latch of a Flash/EEPROM array. * * Parameters: * uint8 array: * Id of the array. * * uint8* buffer: * Data to be loaded to the row latch * * uint8 size: * The number of data bytes that the SPC expects to be written. Depends on the * type of the array and, if the array is Flash, whether ECC is being enabled * or not. There are following values: flash row latch size with ECC enabled, * flash row latch size with ECC disabled and EEPROM row latch size. * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcLoadRow(uint8 array, const uint8 buffer[], uint16 size) { cystatus status = CYRET_STARTED; uint16 i; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_LD_ROW); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_LD_ROW; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; for(i = 0u; i < size; i++) { CY_SPC_CPU_DATA_REG = buffer[i]; } } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcSetupTs ******************************************************************************** * Summary: * Sets up the temperature sensor to drive voltage to external resources. * * Parameters: * uint8 seqSelect: * Selection of current sources for the temperature diode. * 0: Enables one current path at a time. * 1: Enables multiple current paths at a time. * * uint8 seqFreeze: * 0: Sequencer is enabled, cycling through the set of current paths for the * temperature diode to average out the output voltage. * 1: Sequencer is disabled and no cycling of the current paths occurs. * * uint8 clkDivSel: * The divide ratio of the SPC Clock to be set in the ADC ACLK. * * uint8CurvCompEnable: * Curvature compensation calculation enabling. * 0: No curvature compensation is used. * 1: Curvature compensation is enabled. * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcSetupTs(uint8 seqSelect, uint8 seqFreeze, uint8 clkDivSel, uint8 curvCompEnable) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_SETUP_TS); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_SETUP_TS; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = seqSelect; CY_SPC_CPU_DATA_REG = seqFreeze; CY_SPC_CPU_DATA_REG = clkDivSel; CY_SPC_CPU_DATA_REG = curvCompEnable; } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcGetTemp ******************************************************************************** * Summary: * Returns the internal die temperature * * Parameters: * uint8 numSamples: * Number of samples. Valid values are 1-5, resulting in 2 - 32 samples * respectively. * * uint16 timerPeriod: * Number of ADC ACLK cycles. A valid 14 bit value is accepted, higher 2 bits * of 16 bit values are ignored. * * uint8 clkDivSelect: * ADC ACLK clock divide value. Valid values are 2 - 225. * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcGetTemp(uint8 numSamples) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_GET_TEMP); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_GET_TEMP; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = numSamples; } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcLoadMultiByte ******************************************************************************** * Summary: * Loads 1 to 32 bytes of data into the row latch of a Flash/EEPROM array. * * Parameters: * uint8 array: * Id of the array. * * uint16 address: * Flash/eeprom addrress * * uint8* buffer: * Data to load to the row latch * * uint16 number: * Number bytes to load. * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * CYRET_BAD_PARAM * *******************************************************************************/ cystatus CySpcLoadMultiByte(uint8 array, uint16 address, const uint8 buffer[], uint8 size)\ { cystatus status = CYRET_STARTED; uint8 i; /*************************************************************************** * Check if number is correct for array. Number must be less than * 32 for Flash or less than 16 for EEPROM. ***************************************************************************/ if(((array < CY_SPC_LAST_FLASH_ARRAYID) && (size < 32u)) || ((array > CY_SPC_LAST_FLASH_ARRAYID) && (size < 16u))) { if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_LD_MULTI_BYTE); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_LD_MULTI_BYTE; if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; CY_SPC_CPU_DATA_REG = 1u & HI8(address); CY_SPC_CPU_DATA_REG = LO8(address); CY_SPC_CPU_DATA_REG = ((uint8)(size - 1u)); for(i = 0u; i < size; i++) { CY_SPC_CPU_DATA_REG = buffer[i]; } } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } } else { status = CYRET_BAD_PARAM; } return(status); }
/******************************************************************************* * Function Name: CySpcDisableTs ******************************************************************************** * Summary: * Disables the temperature sensor from driving its voltage to external * resources. * * Parameters: * None * * Return: * CYRET_STARTED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcDisableTs(void) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_DISABLE_TS); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_DISABLE_TS; } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcGetAlgorithm ****************************************************************************//** * Downloads SPC algorithm from SPC SROM into SRAM. * * \return * CYRET_STARTED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcGetAlgorithm(void) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_DWNLD_ALGORITHM); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_DWNLD_ALGORITHM; } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcEraseSector ******************************************************************************** * Summary: * Erases all data in the addressed sector (block of 64 rows). * * Parameters: * uint8 array: * Id of the array. * * uint16 address: * Flash/eeprom addrress * * Return: * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcEraseSector(uint8 array, uint16 address) { cystatus status = CYRET_STARTED; /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_ER_SECTOR); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_ER_SECTOR; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; if(array < CY_SPC_LAST_FLASH_ARRAYID) { CY_SPC_CPU_DATA_REG = CY_SPC_FLASH_SECTOR_ADDRES(address); } else { CY_SPC_CPU_DATA_REG = CY_SPC_EEPROM_SECTOR_ADDRESS(address); } } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * Function Name: CySpcLoadRowFull ****************************************************************************//** * Loads a row of data into the row latch of a Flash/EEPROM array. * * The only data that are going to be changed should be passed. The function * will handle unmodified data preservation based on DWR settings and input * parameters. * * \param uint8 array: * Id of the array. * * \param uint16 row: * Flash row number to be loaded. * * \param uint8* buffer: * Data to be loaded to the row latch * * \param uint8 size: * The number of data bytes that the SPC expects to be written. Depends on the * type of the array and, if the array is Flash, whether ECC is being enabled * or not. There are following values: flash row latch size with ECC enabled, * flash row latch size with ECC disabled and EEPROM row latch size. * * \return * CYRET_STARTED * CYRET_CANCELED * CYRET_LOCKED * *******************************************************************************/ cystatus CySpcLoadRowFull(uint8 array, uint16 row, const uint8 buffer[], uint16 size)\ { cystatus status = CYRET_STARTED; uint16 i; #if (CYDEV_ECC_ENABLE == 0) uint32 offset; #endif /* (CYDEV_ECC_ENABLE == 0) */ /* Make sure the SPC is ready to accept command */ if(CY_SPC_IDLE) { CY_SPC_CPU_DATA_REG = CY_SPC_KEY_ONE; CY_SPC_CPU_DATA_REG = CY_SPC_KEY_TWO(CY_SPC_CMD_LD_ROW); CY_SPC_CPU_DATA_REG = CY_SPC_CMD_LD_ROW; /* Make sure the command was accepted */ if(CY_SPC_BUSY) { CY_SPC_CPU_DATA_REG = array; /******************************************************************* * If "Enable Error Correcting Code (ECC)" and "Store Configuration * Data in ECC" DWR options are disabled, ECC section is available * for user data. *******************************************************************/ #if ((CYDEV_ECC_ENABLE == 0u) && (CYDEV_CONFIGURATION_ECC == 0u)) /******************************************************************* * If size parameter equals size of the ECC row and selected array * identification corresponds to the flash array (but not to EEPROM * array) then data are going to be written to the ECC section. * In this case flash data must be preserved. The flash data copied * from flash data section to the SPC data register. *******************************************************************/ if ((size == CYDEV_ECC_ROW_SIZE) && (array <= CY_SPC_LAST_FLASH_ARRAYID)) { offset = CYDEV_FLS_BASE + ((uint32) array * CYDEV_FLS_SECTOR_SIZE) + ((uint32) row * CYDEV_FLS_ROW_SIZE ); for (i = 0u; i < CYDEV_FLS_ROW_SIZE; i++) { CY_SPC_CPU_DATA_REG = CY_GET_XTND_REG8((void CYFAR *)(offset + i)); } } #endif /* ((CYDEV_ECC_ENABLE == 0u) && (CYDEV_CONFIGURATION_ECC == 0u)) */ for(i = 0u; i < size; i++) { CY_SPC_CPU_DATA_REG = buffer[i]; } /******************************************************************* * If "Enable Error Correcting Code (ECC)" DWR option is disabled, * ECC section can be used for storing device configuration data * ("Store Configuration Data in ECC" DWR option is enabled) or for * storing user data in the ECC section ("Store Configuration Data in * ECC" DWR option is enabled). In both cases, the data in the ECC * section must be preserved if flash data is written. *******************************************************************/ #if (CYDEV_ECC_ENABLE == 0) /******************************************************************* * If size parameter equals size of the flash row and selected array * identification corresponds to the flash array (but not to EEPROM * array) then data are going to be written to the flash data * section. In this case, ECC section data must be preserved. * The ECC section data copied from ECC section to the SPC data * register. *******************************************************************/ if ((size == CYDEV_FLS_ROW_SIZE) && (array <= CY_SPC_LAST_FLASH_ARRAYID)) { offset = CYDEV_ECC_BASE + ((uint32) array * CYDEV_ECC_SECTOR_SIZE) + ((uint32) row * CYDEV_ECC_ROW_SIZE ); for (i = 0u; i < CYDEV_ECC_ROW_SIZE; i++) { CY_SPC_CPU_DATA_REG = CY_GET_XTND_REG8((void CYFAR *)(offset + i)); } } #else if(0u != row) { /* To remove unreferenced local variable warning */ } #endif /* (CYDEV_ECC_ENABLE == 0) */ } else { status = CYRET_CANCELED; } } else { status = CYRET_LOCKED; } return(status); }