XilinxProcessorIPLib/drivers/spips/src/xspips_options.c
s32 XSpiPs_SetOptions(const XSpiPs *InstancePtr, u32 Options)
{
	u32 ConfigReg;
	u32 Index;
	u32 CurrentConfigReg;
	s32 Status;

	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);

	/*
	 * Do not allow the slave select to change while a transfer is in
	 * progress. Not thread-safe.
	 */
	if (InstancePtr->IsBusy == TRUE) {
		Status = (s32)XST_DEVICE_BUSY;
	} else {

		ConfigReg = XSpiPs_ReadReg(InstancePtr->Config.BaseAddress,
					 XSPIPS_CR_OFFSET);

		CurrentConfigReg = ConfigReg;

		/*
		 * Loop through the options table, turning the option on or off
		 * depending on whether the bit is set in the incoming options flag.
		 */
		for (Index = 0U; Index < XSPIPS_NUM_OPTIONS; Index++) {
			if ((Options & OptionsTable[Index].Option) != (u32)0U) {
				/* Turn it on */
				ConfigReg |= OptionsTable[Index].Mask;
			}
			else {
				/* Turn it off */
				ConfigReg &= ~(OptionsTable[Index].Mask);
			}
		}


		/*
		 * If CPOL-CPHA bits are toggled from previous state,
		 * disable before writing the configuration register and then enable.
		 */
		if( ((CurrentConfigReg & XSPIPS_CR_CPOL_MASK) !=
			(ConfigReg & XSPIPS_CR_CPOL_MASK)) ||
			((CurrentConfigReg & XSPIPS_CR_CPHA_MASK) !=
			(ConfigReg & XSPIPS_CR_CPHA_MASK)) ) {
				XSpiPs_Disable(InstancePtr);
			}

		/*
		 * Now write the Config register. Leave it to the upper layers
		 * to restart the device.
		 */
		XSpiPs_WriteReg(InstancePtr->Config.BaseAddress,
					XSPIPS_CR_OFFSET, ConfigReg);

		/*
		 * Enable
		 */
		if( ((CurrentConfigReg & XSPIPS_CR_CPOL_MASK) !=
			(ConfigReg & XSPIPS_CR_CPOL_MASK)) ||
			((CurrentConfigReg & XSPIPS_CR_CPHA_MASK) !=
			(ConfigReg & XSPIPS_CR_CPHA_MASK)) ) {
				XSpiPs_Enable(InstancePtr);
			}

		Status = (s32)XST_SUCCESS;
	}
	return Status;
}
/*****************************************************************************/
/**
*
* This function sets the options for the SPI device driver. The options control
* how the device behaves relative to the SPI bus. The device must be idle
* rather than busy transferring data before setting these device options.
*
* @param	InstancePtr is a pointer to the XSpiPs instance.
* @param	Options contains the specified options to be set. This is a bit
*		mask where a 1 means to turn the option on, and a 0 means to
*		turn the option off. One or more bit values may be contained in
*		the mask. See the bit definitions named XSPIPS_*_OPTIONS in the
*		file xspips.h.
*
* @return
*		- XST_SUCCESS if options are successfully set.
*		- XST_DEVICE_BUSY if the device is currently transferring data.
*		The transfer must complete or be aborted before setting options.
*
* @note
* This function is not thread-safe.
*
******************************************************************************/
This function sets the options for the SPI device driver. The options control
how the device behaves relative to the SPI bus. The device must be idle
rather than busy transferring data before setting these device options.
This function sets the options for the SPI device driver . The options control how the device behaves relative to the SPI bus . The device must be idle rather than busy transferring data before setting these device options .
s32 XSpiPs_SetOptions(const XSpiPs *InstancePtr, u32 Options)
{
	u32 ConfigReg;
	u32 Index;
	u32 CurrentConfigReg;
	s32 Status;
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	if (InstancePtr->IsBusy == TRUE) {
		Status = (s32)XST_DEVICE_BUSY;
	} else {
		ConfigReg = XSpiPs_ReadReg(InstancePtr->Config.BaseAddress,
					 XSPIPS_CR_OFFSET);
		CurrentConfigReg = ConfigReg;
		for (Index = 0U; Index < XSPIPS_NUM_OPTIONS; Index++) {
			if ((Options & OptionsTable[Index].Option) != (u32)0U) {
				ConfigReg |= OptionsTable[Index].Mask;
			}
			else {
				ConfigReg &= ~(OptionsTable[Index].Mask);
			}
		}
		if( ((CurrentConfigReg & XSPIPS_CR_CPOL_MASK) !=
			(ConfigReg & XSPIPS_CR_CPOL_MASK)) ||
			((CurrentConfigReg & XSPIPS_CR_CPHA_MASK) !=
			(ConfigReg & XSPIPS_CR_CPHA_MASK)) ) {
				XSpiPs_Disable(InstancePtr);
			}
		XSpiPs_WriteReg(InstancePtr->Config.BaseAddress,
					XSPIPS_CR_OFFSET, ConfigReg);
		if( ((CurrentConfigReg & XSPIPS_CR_CPOL_MASK) !=
			(ConfigReg & XSPIPS_CR_CPOL_MASK)) ||
			((CurrentConfigReg & XSPIPS_CR_CPHA_MASK) !=
			(ConfigReg & XSPIPS_CR_CPHA_MASK)) ) {
				XSpiPs_Enable(InstancePtr);
			}
		Status = (s32)XST_SUCCESS;
	}
	return Status;
}
s32 XSpiPs_SetOptions ( const XSpiPs * InstancePtr , u32 Options ) { u32 ConfigReg ; u32 Index ; u32 CurrentConfigReg ; s32 Status ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; Xil_AssertNonvoid ( InstancePtr -> IsReady == XIL_COMPONENT_IS_READY ) ; if ( InstancePtr -> IsBusy == TRUE ) { Status = ( s32 ) XST_DEVICE_BUSY ; } else { ConfigReg = XSpiPs_ReadReg ( InstancePtr -> Config . BaseAddress , XSPIPS_CR_OFFSET ) ; CurrentConfigReg = ConfigReg ; for ( Index = 0U ; Index < XSPIPS_NUM_OPTIONS ; Index ++ ) { if ( ( Options & OptionsTable [ Index ] . Option ) != ( u32 ) 0U ) { ConfigReg |= OptionsTable [ Index ] . Mask ; } else { ConfigReg &= ~ ( OptionsTable [ Index ] . Mask ) ; } } if ( ( ( CurrentConfigReg & XSPIPS_CR_CPOL_MASK ) != ( ConfigReg & XSPIPS_CR_CPOL_MASK ) ) || ( ( CurrentConfigReg & XSPIPS_CR_CPHA_MASK ) != ( ConfigReg & XSPIPS_CR_CPHA_MASK ) ) ) { XSpiPs_Disable ( InstancePtr ) ; } XSpiPs_WriteReg ( InstancePtr -> Config . BaseAddress , XSPIPS_CR_OFFSET , ConfigReg ) ; if ( ( ( CurrentConfigReg & XSPIPS_CR_CPOL_MASK ) != ( ConfigReg & XSPIPS_CR_CPOL_MASK ) ) || ( ( CurrentConfigReg & XSPIPS_CR_CPHA_MASK ) != ( ConfigReg & XSPIPS_CR_CPHA_MASK ) ) ) { XSpiPs_Enable ( InstancePtr ) ; } Status = ( s32 ) XST_SUCCESS ; } return Status ; }
This function sets the options for the SPI device driver.
This function sets the options for the SPI device driver .
/*
	 * Do not allow the slave select to change while a transfer is in
	 * progress. Not thread-safe.
	 */ /*
		 * Loop through the options table, turning the option on or off
		 * depending on whether the bit is set in the incoming options flag.
		 */ /* Turn it on */ /* Turn it off */ /*
		 * If CPOL-CPHA bits are toggled from previous state,
		 * disable before writing the configuration register and then enable.
		 */ /*
		 * Now write the Config register. Leave it to the upper layers
		 * to restart the device.
		 */ /*
		 * Enable
		 */