/* ===================================================================*/ LDD_TError SPI_SD_SelectConfiguration(LDD_TDeviceData *DeviceDataPtr, uint8_t ChipSelect, uint8_t AttributeSet) { /* Clock configuration test - this test can be disabled by setting the "Ignore clock configuration test" property to the "yes" value in the "Configuration inspector" */ if (!((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->EnMode) { /* Is the device disabled in the actual speed CPU mode? */ return ERR_SPEED; /* If yes then error */ } (void)ChipSelect; /* Parameter is not used, suppress unused argument warning */ if (AttributeSet >= SPI_SD_CONFIGURATION_COUNT) { /* Is Attribute set index out of range? */ return ERR_PARAM_ATTRIBUTE_SET; /* Yes, return ERR_PARAM */ } if ((((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->InpDataNumReq != 0x00U) || (((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->OutDataNumReq != 0x00U)) { /* Is the previous receive operation pending? */ return ERR_BUSY; /* If yes then error */ } ((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->CurrentAttributeSet = AttributeSet; /* Set current attribute set */ SPI_PDD_EnableHaltMode(SPI1_BASE_PTR,PDD_ENABLE); /* Enter to STOPPED mode */ while (SPI_PDD_GetTxRxActiveFlag(SPI1_BASE_PTR)) {} /* Wait until the current transmission finished */ switch (Cpu_GetClockConfiguration()) { case CPU_CLOCK_CONFIG_0: SPI_PDD_WriteMasterClockTransferAttributeReg(SPI1_BASE_PTR,0U,ConfigurationSet0[AttributeSet]); /* Set required configuration */ break; default: break; } ((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->TxCommand = TxCommandList[AttributeSet]; /* Prepare command for transmision */ SPI_PDD_EnableHaltMode(SPI1_BASE_PTR,PDD_DISABLE); /* Leave the STOPPED mode */ return ERR_OK; /* OK */ }
/* ===================================================================*/ LDD_TError SM1_SelectConfiguration(LDD_TDeviceData *DeviceDataPtr, uint8_t ChipSelect, uint8_t AttributeSet) { (void)ChipSelect; /* Parameter is not used, suppress unused argument warning */ if (AttributeSet >= SM1_CONFIGURATION_COUNT) { /* Is Attribute set index out of range? */ return ERR_PARAM_ATTRIBUTE_SET; /* Yes, return ERR_PARAM */ } if ((((SM1_TDeviceDataPtr)DeviceDataPtr)->InpDataNumReq != 0x00U) || (((SM1_TDeviceDataPtr)DeviceDataPtr)->OutDataNumReq != 0x00U)) { /* Is the previous receive operation pending? */ return ERR_BUSY; /* If yes then error */ } SPI_PDD_EnableHaltMode(SPI1_BASE_PTR,PDD_ENABLE); /* Enter to STOPPED mode */ while (SPI_PDD_GetTxRxActiveFlag(SPI1_BASE_PTR)) {} /* Wait until the current transmission finished */ SPI_PDD_WriteMasterClockTransferAttributeReg(SPI1_BASE_PTR,0U,ConfigurationSet[AttributeSet]); /* Set required configuration */ ((SM1_TDeviceDataPtr)DeviceDataPtr)->TxCommand = TxCommandList[AttributeSet]; /* Prepare command for transmision */ SPI_PDD_EnableHaltMode(SPI1_BASE_PTR,PDD_DISABLE); /* Leave the STOPPED mode */ return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : HWEnDi (component SPIMaster_LDD) ** ** Description : ** Enables or disables the peripheral(s) associated with the ** component. The method is called automatically as a part of the ** Enable and Disable methods and several internal methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void HWEnDi(LDD_TDeviceData *DeviceDataPtr) { if (((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->EnMode) { /* Enable device? */ ((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->OutDataNumReq = 0x00U; /* Clear the counter of requested outgoing characters. */ ((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->OutSentDataNum = 0x00U; /* Clear the counter of sent characters. */ ((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->InpDataNumReq = 0x00U; /* Clear the counter of requested incoming characters. */ ((SPI_SD_TDeviceDataPtr)DeviceDataPtr)->InpRecvDataNum = 0x00U; /* Clear the counter of received characters. */ SPI_PDD_EnableDevice(SPI1_BASE_PTR,PDD_ENABLE); /* Enable device */ SPI_PDD_ClearTxFIFO(SPI1_BASE_PTR); /* Clear Tx FIFO */ SPI_PDD_ClearRxFIFO(SPI1_BASE_PTR); /* Clear Rx FIFO */ SPI_PDD_ClearInterruptFlags(SPI1_BASE_PTR,SPI_PDD_ALL_INT); /* Clear all HW flags */ SPI_PDD_EnableHaltMode(SPI1_BASE_PTR,PDD_DISABLE); /* Leave the STOPPED mode */ } else { SPI_PDD_EnableHaltMode(SPI1_BASE_PTR,PDD_ENABLE); /* Enter to STOPPED mode */ SPI_PDD_EnableDevice(SPI1_BASE_PTR,PDD_DISABLE); /* Disable device */ } }