示例#1
0
/* ===================================================================*/
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 */
}
示例#2
0
/* ===================================================================*/
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 */
}