/**
  * @brief  Set the CS pin to low and wait until SO pin goes low
  * @param  None
  * @retval None
  */
static uint8_t CC2500_Chip_Select(void)
{
  CC2500Timeout = CC2500_FLAG_TIMEOUT;
  CC2500_CS_LOW();
  while (GPIO_ReadInputDataBit(CC2500_SPI_MISO_GPIO_PORT, CC2500_SPI_MISO_PIN)
         == (uint8_t) Bit_SET)
  {
    if((CC2500Timeout--) == 0) return CC2500_TIMEOUT_UserCallback();
  }
  return 0;
}
/**
	* @brief  Sends a Byte through the SPI interface and return the Byte received 
	*         from the SPI bus.
	* @param  Byte : Byte send.
	* @retval The received byte value
	*/
static uint8_t CC2500_SendByte(uint8_t byte)
{
	/* Loop while DR register in not emplty */
	CC2500Timeout = CC2500_FLAG_TIMEOUT;
	while (SPI_I2S_GetFlagStatus(CC2500_SPI, SPI_I2S_FLAG_TXE) == RESET)
	{
		if((CC2500Timeout--) == 0) return CC2500_TIMEOUT_UserCallback();
	}
	
	/* Send a Byte through the SPI peripheral */
	SPI_I2S_SendData(CC2500_SPI, byte);
	
	/* Wait to receive a Byte */
	CC2500Timeout = CC2500_FLAG_TIMEOUT;
	while (SPI_I2S_GetFlagStatus(CC2500_SPI, SPI_I2S_FLAG_RXNE) == RESET)
	{
		if((CC2500Timeout--) == 0) return CC2500_TIMEOUT_UserCallback();
	}
	
	/* Return the Byte read from the SPI bus */
	return (uint8_t)SPI_I2S_ReceiveData(CC2500_SPI);
}
/**
  * @brief  Issue chip reset command.
  * @param  None
  * @retval uint8_t : 0(Ok) or CC2500_TIMEOUT_ERROR
  */
uint8_t CC2500_SRES_CMD(void)
{
  CC2500Timeout = CC2500_FLAG_TIMEOUT;
	CC2500_WriteCommand(CC2500_COMMAND_SRES, 0);
	while (GPIO_ReadInputDataBit(CC2500_SPI_MISO_GPIO_PORT, CC2500_SPI_MISO_PIN)
         == (uint8_t) Bit_SET)
  {
    if((CC2500Timeout--) == 0)
		{
			return CC2500_TIMEOUT_UserCallback();
		}
  }
	return 0;
}