Exemplo n.º 1
0
/**
 * @brief  Forces SPIRIT GPIO_x configured as digital output, to VDD or GND.
 * @param  xGpioX Specifies the GPIO to be configured.
 *   This parameter can be one of following parameters:
 *     @arg SPIRIT_GPIO_0: SPIRIT GPIO_0
 *     @arg SPIRIT_GPIO_1: SPIRIT GPIO_1
 *     @arg SPIRIT_GPIO_2: SPIRIT GPIO_2
 *     @arg SPIRIT_GPIO_3: SPIRIT GPIO_3
 * @param  xLevel Specifies the level.
 *   This parameter can be: HIGH or LOW.
 * @retval None.
 */
void SpiritGpioSetLevel(SpiritGpioPin xGpioX, OutputLevel xLevel)
{
  uint8_t tempRegValue = 0x00;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_GPIO(xGpioX));
  s_assert_param(IS_SPIRIT_GPIO_LEVEL(xLevel));

  /* Reads the SPIRIT_GPIOx register and mask the GPIO_SELECT field */
  g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue);
  tempRegValue &= 0x04;

  /* Sets the value of the SPIRIT GPIO register according to the specified level */
  if(xLevel == HIGH)
  {
    tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_VDD | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP;
  }
  else
  {
    tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_GND | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP;
  }

  /* Writes the SPIRIT GPIO register */
  g_xStatus = SpiritSpiWriteRegisters(xGpioX, 1, &tempRegValue);

}
Exemplo n.º 2
0
/**
 * @brief  Initializes the SPIRIT GPIOx according to the specified
 *         parameters in the pxGpioInitStruct.
 * @param  pxGpioInitStruct pointer to a SGpioInit structure that
 *         contains the configuration information for the specified SPIRIT GPIO.
 * @retval None.
 */
void SpiritGpioInit(SGpioInit* pxGpioInitStruct)
{
  uint8_t tempRegValue = 0x00;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_GPIO(pxGpioInitStruct->xSpiritGpioPin));
  s_assert_param(IS_SPIRIT_GPIO_MODE(pxGpioInitStruct->xSpiritGpioMode));
  s_assert_param(IS_SPIRIT_GPIO_IO(pxGpioInitStruct->xSpiritGpioIO));

  tempRegValue = ((uint8_t)(pxGpioInitStruct->xSpiritGpioMode) | (uint8_t)(pxGpioInitStruct->xSpiritGpioIO));

  g_xStatus = SpiritSpiWriteRegisters(pxGpioInitStruct->xSpiritGpioPin, 1, &tempRegValue);

}
Exemplo n.º 3
0
/**
 * @brief  Returns output value (VDD or GND) of SPIRIT GPIO_x, when it is configured as digital output.
 * @param  xGpioX Specifies the GPIO to be read.
 *         This parameter can be one of following parameters:
 *         @arg SPIRIT_GPIO_0: SPIRIT GPIO_0
 *         @arg SPIRIT_GPIO_1: SPIRIT GPIO_1
 *         @arg SPIRIT_GPIO_2: SPIRIT GPIO_2
 *         @arg SPIRIT_GPIO_3: SPIRIT GPIO_3
 * @retval OutputLevel Logical level of selected GPIO configured as digital output.
 *         This parameter can be: HIGH or LOW.
 */
OutputLevel SpiritGpioGetLevel(SpiritGpioPin xGpioX)
{
  uint8_t tempRegValue = 0x00;
  OutputLevel level;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_GPIO(xGpioX));

  /* Reads the SPIRIT_GPIOx register */
  g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue);

  /* Mask the GPIO_SELECT field and returns the value according */
  tempRegValue &= 0xF8;
  if(tempRegValue == SPIRIT_GPIO_DIG_OUT_VDD)
  {
    level = HIGH;
  }
  else
  {
    level = LOW;
  }

  return level;

}
Exemplo n.º 4
0
/**
 * @brief  Enables or Disables the output of temperature sensor on SPIRIT GPIO_0.
 * @param  xNewState new state for temperature sensor.
 *         This parameter can be: S_ENABLE or S_DISABLE.
 * @retval None.
 */
void SpiritGpioTemperatureSensor(SpiritFunctionalState xNewState)
{
  uint8_t tempRegValue = 0x00;
  uint8_t gpio0tempRegValue = 0x00;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));

  /* Reads the ANA_FUNC_CONF0 register and mask the result to enable or disable the
     temperature sensor */
  g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
  if(xNewState == S_ENABLE)
  {
    tempRegValue |= TEMPERATURE_SENSOR_MASK;
  }
  else
  {
    tempRegValue &= (~TEMPERATURE_SENSOR_MASK);
    gpio0tempRegValue = 0x0A; /* Default value */
  }
  g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);

  /* Sets the SPIRIT GPIO_0 according to input request */
  g_xStatus = SpiritSpiWriteRegisters(GPIO0_CONF_BASE, 1, &gpio0tempRegValue);

}
Exemplo n.º 5
0
/**
 * @brief  Sets the battery level.
 * @param  xBatteryLevel new state for battery level.
 *         This parameter can be a value of @ref BatteryLevel.
 * @retval None.
 */
void SpiritGeneralSetBatteryLevel(BatteryLevel xBatteryLevel)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_BLD_LVL(xBatteryLevel));

  /* Reads the ANA_FUNC_CONF1_BASE register value */
  g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);

  /* Build the value to be stored */
  tempRegValue &= ~ANA_FUNC_CONF1_SET_BLD_LVL_MASK;
  switch(xBatteryLevel)
  {
    case BLD_LVL_2_7_V:
      tempRegValue |= BLD_LVL_2_7;
      break;
    case BLD_LVL_2_5_V:
      tempRegValue |= BLD_LVL_2_5;
      break;
    case BLD_LVL_2_3_V:
      tempRegValue |= BLD_LVL_2_3;
      break;
    case BLD_LVL_2_1_V:
      tempRegValue |= BLD_LVL_2_1;
      break;
  }

  /* Writes the new value */
  g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);

}
/**
 * @brief  Sends a specific command to SPIRIT.
 * @param  xCommandCode code of the command to send.
           This parameter can be any value of @ref SpiritCmd.
 * @retval None.
 */
void SpiritCmdStrobeCommand(SpiritCmd xCommandCode)
{
  /* Check the parameters */
  s_assert_param(IS_SPIRIT_CMD(xCommandCode));

  g_xStatus = SpiritSpiCommandStrobes((uint8_t) xCommandCode);
}
Exemplo n.º 7
0
/**
 * @brief  Verifies if a specific IRQ has been generated.
 *         The call resets all the IRQ status, so it can't be used in case of multiple raising interrupts.
 * @param  xFlag IRQ flag to be checked.
 *         This parameter can be any value of @ref IrqList.
 * @retval SpiritBool S_TRUE or S_FALSE.
 */
SpiritBool SpiritIrqCheckFlag(IrqList xFlag)
{
  uint8_t tempRegValue[4];
  uint32_t tempValue = 0;
  SpiritBool flag;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_IRQ_LIST(xFlag));

  /* Reads registers and build the status word */
  g_xStatus = SpiritSpiReadRegisters(IRQ_STATUS3_BASE, 4, tempRegValue);
  for(uint8_t i=0; i<4; i++)
  {
    tempValue += ((uint32_t)tempRegValue[i])<<(8*(3-i));
  }
  
  if(tempValue & xFlag)
  {
    flag = S_TRUE;
  }
  else
  {
    flag = S_FALSE;
  }

  return flag;

}
Exemplo n.º 8
0
/**
 * @brief  If enabled RX packet is accepted if its destination address matches with My address.
 * @param  xNewState new state for DEST_VS_SOURCE_ADDRESS.
 *         This parameter can be S_ENABLE or S_DISABLE.
 * @retval None.
 */
void SpiritPktCommonFilterOnMyAddress(SpiritFunctionalState xNewState)
{
  uint8_t tempRegValue;

   /* Check the parameters */
  s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));


  /* Modify the register value: set or reset the TX source address control */
  g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);

  /* Set or reset the DESTINATION vs TX enabling bit */
  if(xNewState == S_ENABLE)
  {
    tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
  }
  else
  {
    tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
  }

  /* Writes the new value on the PCKT_FLT_OPTIONS register */
  g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);

}
Exemplo n.º 9
0
/**
 * @brief  If enabled RX packet is accepted only if the masked control field matches the
 *         masked control field reference (CONTROL_MASK & CONTROL_FIELD_REF == CONTROL_MASK & RX_CONTROL_FIELD).
 * @param  xNewState new state for Control filtering enable bit.
 *         This parameter can be S_ENABLE or S_DISABLE.
 * @retval None.
 * @note   This filtering control is enabled by default but the control mask is by default set to 0.
 *         As a matter of fact the user has to enable the control filtering bit after the packet initialization
 *         because the PktInit routine disables it.
 */
void SpiritPktCommonFilterOnControlField(SpiritFunctionalState xNewState)
{
  uint8_t tempRegValue;

   /* Check the parameters */
  s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));


  /* Modify the register value: set or reset the control bit filtering */
  g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);

  /* Set or reset the CONTROL filtering enabling bit */
  if(xNewState == S_ENABLE)
  {
    tempRegValue |= PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK;
  }
  else
  {
    tempRegValue &= ~PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK;
  }

  /* Writes the new value on the PCKT_FLT_OPTIONS register */
  g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);

}
Exemplo n.º 10
0
/**
 * @brief  Sets a specific SYNC word for SPIRIT packets.
 * @param  xSyncX SYNC word number to be set.
 *         This parameter can be any value of @ref PktSyncX.
 * @param  cSyncWord SYNC word.
 *         This parameter is an uint8_t.
 * @retval None.
 */
void SpiritPktCommonSetSyncxWord(PktSyncX xSyncX ,  uint8_t cSyncWord)
{
  uint8_t tempRegAddress;

  /* Check the parameters */
  s_assert_param(IS_PKT_SYNCx(xSyncX));

  /* Set the specified address */
  switch(xSyncX){
    case PKT_SYNC_WORD_1:
      tempRegAddress=SYNC1_BASE;
      break;
    case PKT_SYNC_WORD_2:
      tempRegAddress=SYNC2_BASE;
      break;
    case PKT_SYNC_WORD_3:
      tempRegAddress=SYNC3_BASE;
      break;
    case PKT_SYNC_WORD_4:
      tempRegAddress=SYNC4_BASE;
      break;
  }

  /* Writes value on the selected register */
  g_xStatus = SpiritSpiWriteRegisters(tempRegAddress, 1, &cSyncWord);

}
Exemplo n.º 11
0
/**
 * @brief  Initializes the SPIRIT Clock Output according to the specified
 *         parameters in the xClockOutputInitStruct.
 * @param  pxClockOutputInitStruct pointer to a ClockOutputInit structure that
 *         contains the configuration information for the SPIRIT Clock Output.
 * @retval None.
 * @note   The function SpiritGpioClockOutput() must be called in order to enable
 *         or disable the MCU clock dividers.
 */
void SpiritGpioClockOutputInit(ClockOutputInit* pxClockOutputInitStruct)
{
  uint8_t tempRegValue = 0x00;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(pxClockOutputInitStruct->xClockOutputXOPrescaler));
  s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(pxClockOutputInitStruct->xClockOutputRCOPrescaler));
  s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(pxClockOutputInitStruct->xExtraClockCycles));

  /* Calculates the register value to write according to the specified configuration */
  tempRegValue = ((uint8_t)(pxClockOutputInitStruct->xClockOutputXOPrescaler) | (uint8_t)(pxClockOutputInitStruct->xClockOutputRCOPrescaler) | \
           (uint8_t)(pxClockOutputInitStruct->xExtraClockCycles));

  /* Writes the MCU_CLOCK register */
  g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);

}
Exemplo n.º 12
0
/**
 * @brief  Computes the RSSI threshold from its dBm value according to the formula: (RSSI[Dbm] + 130)/0.5
 * @param  nDbmValue RSSI threshold reported in dBm.
 *         This parameter must be a sint16_t.
 * @retval uint8_t RSSI threshold corresponding to dBm value.
 */
uint8_t SpiritQiComputeRssiThreshold(int nDbmValue)
{
    /* Check the parameters */
    s_assert_param(IS_RSSI_THR_DBM(nDbmValue));

    /* Computes the RSSI threshold for register */
    return 2*(nDbmValue+130);

}
Exemplo n.º 13
0
/**
 * @brief  Sets the RSSI threshold from its dBm value according to the formula: (RSSI[Dbm] + 130)/0.5.
 * @param  nDbmValue RSSI threshold reported in dBm.
 *         This parameter must be a sint16_t.
 * @retval None.
 */
void SpiritQiSetRssiThresholddBm(int nDbmValue)
{
    uint8_t tempRegValue=2*(nDbmValue+130);

    /* Check the parameters */
    s_assert_param(IS_RSSI_THR_DBM(nDbmValue));

    /* Writes the new value on the RSSI_TH register */
    g_xStatus = SpiritSpiWriteRegisters(RSSI_TH_BASE, 1, &tempRegValue);

}
Exemplo n.º 14
0
/**
 * @brief  Computes the values of the wakeup timer counter and prescaler from the user time expressed in millisecond.
 *         The prescaler and the counter values are computed maintaining the prescaler value as
 *         small as possible in order to obtain the best resolution, and in the meantime minimizing the error.
 * @param  fDesiredMsec desired wakeup timeout in millisecs.
 *         This parameter must be a float. Since the counter and prescaler are 8 bit registers the maximum
 *         reachable value is maxTime = fTclk x 256 x 256.
 * @param  pcCounter pointer to the variable in which the value for the wakeup timer counter has to be stored.
 *         This parameter must be a uint8_t*.
 * @param  pcPrescaler pointer to the variable in which the value for the wakeup timer prescaler has to be stored.
 *         This parameter must be an uint8_t*.
 * @retval None
 */
void SpiritTimerComputeWakeUpValues(float fDesiredMsec , uint8_t* pcCounter , uint8_t* pcPrescaler)
{
  uint8_t b0, a0;
  uint32_t n;
  int32_t err, err_min;

  /* Check the parameters */
  s_assert_param(IS_WKUP_TIMEOUT(fDesiredMsec));

  n = (uint32_t)((fDesiredMsec*1000)/WAKEUP_TCLK);
  err_min = n;
  /* These are the initial values for the prescaler and the counter, where the prescaler
     is settled to the minimum value and the counter accordingly. In order to avoid a zero
     division for the counter the prescaler is increased by one. Then because the wakeup timeout
     is calculated as: Twu=(PRESCALER +1)*(COUNTER+1)*Tck the counter and the prescaler are decreased by one.*/
  *pcPrescaler = a0 = (n/0xFF)+1;
  *pcCounter = b0 = (n / *pcPrescaler);
  (*pcPrescaler)--;

  /* If the desired value is over the maximum limit, the counter and the
  prescaler are settled to their maximum values, and doesn't execute the routine */
  if(fDesiredMsec>1888.0)
  {
    *pcCounter = 0xFF;
    *pcPrescaler = 0xFF;
    return;
  }

  /* Iterative cycle to minimize the error */
  for (; ; (*pcPrescaler)++)
  {
    *pcCounter = ((n/(*pcPrescaler+1))-1);
    err = (((int32_t)*pcPrescaler)+1) * (((int32_t)*pcCounter)+1) - (int32_t)n;
    if (S_ABS(err) > (*pcPrescaler / 2))
    {
      (*pcCounter)++;
      err = (((int32_t)*pcPrescaler)+1) * (((int32_t)*pcCounter)+1) - (int32_t)n;
    }
    if (S_ABS(err) < S_ABS(err_min))
    {
      err_min = err;
      a0 = *pcPrescaler;
      b0 = *pcCounter;
      if (err == 0) break;
    }
    if(*pcPrescaler == 0xFF) break;
  }
  *pcPrescaler = a0;
  *pcCounter = b0;

}
Exemplo n.º 15
0
/**
 * @brief  Sets the AUTO ACKNOLEDGEMENT mechanism on the receiver. When the feature is enabled and
 *         a data packet has been correctly received, then an acknowledgement packet is sent back to the originator of the received
 *         packet. If the PIGGYBACKING bit is also set, payload data will be read from the FIFO; otherwise an empty packet is sent
 *         only containing the source and destination addresses and the sequence number of the packet being acknowledged.
 * @param  xAutoAck new state for autoack.
 *         This parameter can be: S_ENABLE or S_DISABLE.
 * @param  xPiggybacking new state for autoack.
 *         This parameter can be: S_ENABLE or S_DISABLE.
 * @retval None.
 */
void SpiritPktCommonAutoAck(SpiritFunctionalState xAutoAck , SpiritFunctionalState xPiggybacking)
{
  uint8_t tempRegValue[2];

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xAutoAck));
  s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xPiggybacking));
  /* Check if piggybacking is enabled and autoack is disabled */
  s_assert_param(!(xPiggybacking==S_ENABLE && xAutoAck==S_DISABLE));

  /* Reads the PROTOCOL[1:0] registers value */
  g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);

  /* Sets the specified LLP option */
  /* Autoack setting */
  if(xAutoAck == S_ENABLE)
  {
    tempRegValue[1] |= PROTOCOL0_AUTO_ACK_MASK;
  }
  else
  {
    tempRegValue[1] &= (~PROTOCOL0_AUTO_ACK_MASK);
  }

  /* Piggybacking setting */
  if(xPiggybacking == S_ENABLE)
  {
    tempRegValue[0] |= PROTOCOL1_PIGGYBACKING_MASK;
  }
  else
  {
    tempRegValue[0] &= (~PROTOCOL1_PIGGYBACKING_MASK);
  }

  /* Writes data on the PROTOCOL[1:0] registers */
  g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 2, tempRegValue);

}
Exemplo n.º 16
0
/**
 * @brief  Enables or disables a specific IRQ.
 * @param  xIrq IRQ to enable or disable.
 *         This parameter can be any value of @ref IrqList.
 * @param  xNewState new state for the IRQ.
 *         This parameter can be: S_ENABLE or S_DISABLE.
 * @retval None.
 */
void SpiritIrq(IrqList xIrq, SpiritFunctionalState xNewState)
{
  uint8_t tempRegValue[4];
  uint32_t tempValue = 0;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_IRQ_LIST(xIrq));
  s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));

  /* Reads the IRQ_MASK registers */
  g_xStatus = SpiritSpiReadRegisters(IRQ_MASK3_BASE, 4, tempRegValue);

  /* Build the IRQ mask word */
  for(uint8_t i=0; i<4; i++)
  {
    tempValue += ((uint32_t)tempRegValue[i])<<(8*(3-i));
  }
  
  /* Rebuild the new mask according to user request */
  if(xNewState == S_DISABLE)
  {
    tempValue &= (~xIrq);
  }
  else
  {
    tempValue |= (xIrq);
  }

  /* Build the array of bytes to write in the IRQ_MASK registers */
  for(uint8_t j=0; j<4; j++)
  {
    tempRegValue[j] = (uint8_t)(tempValue>>(8*(3-j)));
  }
  
  /* Writes the new IRQ mask in the corresponding registers */
  g_xStatus = SpiritSpiWriteRegisters(IRQ_MASK3_BASE, 4, tempRegValue);

}
Exemplo n.º 17
0
/**
 * @brief  Sets the almost empty threshold for the Rx FIFO. When the number of elements in RX FIFO reaches this value an interrupt can be generated to the MCU.
 * @param  cThrRxFifo almost empty threshold.
 * 	   This parameter is an uint8_t.
 * @retval None.
 */
void SpiritLinearFifoSetAlmostEmptyThresholdRx(uint8_t cThrRxFifo)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_FIFO_THR(cThrRxFifo));

  /* Build the register value */
  tempRegValue = cThrRxFifo & 0x7F;

  /* Writes the Almost Empty threshold for RX in the corresponding register */
  g_xStatus = SpiritSpiWriteRegisters(FIFO_CONFIG2_RXAETHR_BASE, 1, &tempRegValue);

}
Exemplo n.º 18
0
/**
 * @brief  Sets the TX sequence number to be used to start counting.
 * @param  cSeqNumberReload new value for Tx seq number reload.
 * @retval None.
 */
void SpiritPktCommonSetTransmittedSeqNumberReload(uint8_t cSeqNumberReload){
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_PKT_SEQ_NUMBER_RELOAD(cSeqNumberReload));

  /* Reads value on the PROTOCOL2 register */
  g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue);

  tempRegValue &= 0xE7;
  tempRegValue |= (cSeqNumberReload << 3);

  /* Writes value on the PROTOCOL2 register */
  g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue);

}
Exemplo n.º 19
0
/**
 * @brief  Sets the CS Mode. When static carrier sensing is used (cs_mode = 0), the carrier sense signal is asserted when the measured RSSI is above the
 *         value specified in the RSSI_TH register and is deasserted when the RSSI falls 3 dB below the same threshold.
 *         When dynamic carrier sense is used (cs_mode = 1, 2, 3), the carrier sense signal is asserted if the signal is above the
 *         threshold and a fast power increase of 6, 12 or 18 dB is detected; it is deasserted if a power fall of the same amplitude is
 *         detected.
 * @param  xCsMode CS mode selector.
 *         This parameter can be any value of @ref CSMode.
 * @retval None.
 */
void SpiritQiSetCsMode(CSMode xCsMode)
{
    uint8_t tempRegValue;

    /* Check the parameters */
    s_assert_param(IS_CS_MODE(xCsMode));

    /* Reads the RSSI_FLT register */
    g_xStatus = SpiritSpiReadRegisters(RSSI_FLT_BASE, 1, &tempRegValue);

    /* Sets bit to select the CS mode */
    tempRegValue &= ~0x0C;
    tempRegValue |= ((uint8_t)xCsMode);

    /* Writes the new value on the RSSI_FLT register */
    g_xStatus = SpiritSpiWriteRegisters(RSSI_FLT_BASE, 1, &tempRegValue);

}
Exemplo n.º 20
0
/**
 * @brief  Sets the CRC mode for SPIRIT packets.
 * @param  xCrcMode length of CRC field in bytes.
 *         This parameter can be any value of @ref PktCrcMode.
 * @retval None.
 */
void SpiritPktCommonSetCrcMode(PktCrcMode xCrcMode)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_PKT_CRC_MODE(xCrcMode));

  /* Reads the PCKTCTRL1 register value */
  g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);

  /* Build data to write setting the CRC mode */
  tempRegValue &= ~PCKTCTRL1_CRC_MODE_MASK;
  tempRegValue |= (uint8_t)xCrcMode;

  /* Writes the new value on the PCKTCTRL1 register */
  g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);

}
Exemplo n.º 21
0
/**
 * @brief  Sets fixed or variable payload length mode for SPIRIT packets.
 * @param  xFixVarLength variable or fixed length.
 *         PKT_FIXED_LENGTH_VAR -> variable (the length is extracted from the received packet).
 *         PKT_FIXED_LENGTH_FIX -> fix (the length is set by PCKTLEN0 and PCKTLEN1).
 * @retval None.
 */
void SpiritPktCommonSetFixVarLength(PktFixVarLength xFixVarLength)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_PKT_FIX_VAR_LENGTH(xFixVarLength));

  /* Reads the PCKTCTRL2 register value */
  g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);

  /* Set fixed or variable address mode */
  tempRegValue &= ~PCKTCTRL2_FIX_VAR_LEN_MASK;
  tempRegValue |= (uint8_t)xFixVarLength;

  /* Writes the new value on the PCKTCTRL2 register */
  g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);

}
Exemplo n.º 22
0
/**
 * @brief  Sets the SYNC field Length for SPIRIT packets.
 * @param  xSyncLength length of SYNC field in bytes.
 *         This parameter can be any value of @ref PktSyncLength.
 * @retval None.
 */
void SpiritPktCommonSetSyncLength(PktSyncLength xSyncLength)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_PKT_SYNC_LENGTH(xSyncLength));

  /* Reads the PCKTCTRL2 register value */
  g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);

  /* Set the sync length */
  tempRegValue &= ~PCKTCTRL2_SYNC_LENGTH_MASK;
  tempRegValue |= (uint8_t)xSyncLength;

  /* Writes the new value on the PCKTCTRL2 register */
  g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);

}
Exemplo n.º 23
0
/**
 * @brief  Sets the TX mode of SPIRIT.
 * @param  xDirectTx code of the desired source.
 *         This parameter can be any value of @ref DirectTx.
 * @retval None.
 */
void SpiritDirectRfSetTxMode(DirectTx xDirectTx)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_DIRECT_TX(xDirectTx));

  /* Reads the register value */
  SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);

  /* Build the value to be stored */
  tempRegValue &= ~PCKTCTRL1_TX_SOURCE_MASK;
  tempRegValue |= (uint8_t)xDirectTx;

  /* Writes value on register */
  g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);

}
Exemplo n.º 24
0
/**
 * @brief  Sets the TX sequence number to be used to start counting.
 * @param  cSeqNumberReload new value for Tx seq number reload.
 *         This parameter can be: S_ENABLE or S_DISABLE.
 * @retval None.
 */
void SpiritPktCommonSetNMaxReTx(PktNMaxReTx xNMaxReTx)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_PKT_NMAX_RETX(xNMaxReTx));

  /* Reads the PROTOCOL0 register value */
  g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);

  /* Build the value to be written */
  tempRegValue &= ~PROTOCOL0_NMAX_RETX_MASK;
  tempRegValue |= xNMaxReTx;

  /* Writes value on the PROTOCOL0 register */
  g_xStatus = SpiritSpiWriteRegisters(PROTOCOL0_BASE, 1, &tempRegValue);

}
Exemplo n.º 25
0
/**
 * @brief  Sets the RCO ratio as clock output.
 * @param  xExtraCycles the number of extra clock cycles provided before switching
 *         to STANDBY state. This parameter can be any value of @ref ExtraClockCycles .
 * @retval None.
 */
void SpiritGpioSetExtraClockCycles(ExtraClockCycles xExtraCycles)
{
  uint8_t tempRegValue = 0x00;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(xExtraCycles));

  /* Reads the MCU_CLK_CONFIG register */
  g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);

  /* Mask the CLOCK_TAIL field and writes the new value */
  tempRegValue &= 0x9F;
  tempRegValue |= ((uint8_t)xExtraCycles);

  /* Writes the new number of extra clock cycles in the MCU_CLOCK register */
  g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);

}
Exemplo n.º 26
0
/**
 * @brief  Sets the SQI threshold. The synchronization quality
 *         threshold is equal to 8 * SYNC_LEN - 2 * SQI_TH with SQI_TH = 0..3. When SQI_TH is 0 perfect match is required; when
 *         SQI_TH = 1, 2, 3 then 1, 2, or 3 bit errors are respectively accepted. It is recommended that the SQI check is always
 *         enabled.
 * @param  xSqiThr parameter of the formula above.
 * 	   This parameter is a @ref SqiThreshold.
 * @retval None.
 */
void SpiritQiSetSqiThreshold(SqiThreshold xSqiThr)
{
    uint8_t tempRegValue;

    /* Check the parameters */
    s_assert_param(IS_SQI_THR(xSqiThr));

    /* Reads the QI register value */
    g_xStatus = SpiritSpiReadRegisters(QI_BASE, 1, &tempRegValue);

    /* Build the SQI threshold value to be written */
    tempRegValue &= 0x3F;
    tempRegValue |= ((uint8_t)xSqiThr);

    /* Writes the new value on the QI register */
    g_xStatus = SpiritSpiWriteRegisters(QI_BASE, 1, &tempRegValue);

}
Exemplo n.º 27
0
/**
 * @brief  Sets the CONTROL field length for SPIRIT packets.
 * @param  xControlLength length of CONTROL field in bytes.
 *         This parameter can be any value of @ref PktControlLength.
 * @retval None.
 */
void SpiritPktCommonSetControlLength(PktControlLength xControlLength)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_PKT_CONTROL_LENGTH(xControlLength));

  /* Reads the PCKTCTRL4 register value */
  g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);

  /* Set the control length */
  tempRegValue &= ~PCKTCTRL4_CONTROL_LEN_MASK;
  tempRegValue |= (uint8_t)xControlLength;

  /* Writes the new value on the PCKTCTRL4 register */
  g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);

}
Exemplo n.º 28
0
/**
 * @brief  Sets the RCO ratio as clock output
 * @param  xRCOPrescaler the RCO prescaler to be used as clock output.
 *         This parameter can be any value of @ref ClockOutputRCOPrescaler .
 * @retval None.
 */
void SpiritGpioSetRCOPrescaler(ClockOutputRCOPrescaler xRCOPrescaler)
{
  uint8_t tempRegValue = 0x00;

  /* Check the parameters */
  s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(xRCOPrescaler));

  /* Reads the MCU_CLK_CONFIG register */
  g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);

  /* Mask the RCO_RATIO field and writes the new value */
  tempRegValue &= 0xFE;
  tempRegValue |= ((uint8_t)xRCOPrescaler);

  /* Writes the new RCO prescaler in the MCU_CLOCK register */
  g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);

}
Exemplo n.º 29
0
/**
 * @brief  Sets the almost empty threshold for the Tx FIFO. When the number of elements in Tx FIFO reaches this value an interrupt can can be generated to the MCU.
 * @param  cThrTxFifo: almost empty threshold.
 *         This parameter is an uint8_t.
 * @retval None.
 */
void SpiritLinearFifoSetAlmostEmptyThresholdTx(uint8_t cThrTxFifo)
{
  uint8_t tempRegValue;

  /* Check the parameters */
  s_assert_param(IS_FIFO_THR(cThrTxFifo));

  /* Reads the register value */
  g_xStatus = SpiritSpiReadRegisters(FIFO_CONFIG0_TXAETHR_BASE, 1, &tempRegValue);

  /* Build the register value */
  tempRegValue &= 0x80;
  tempRegValue |= cThrTxFifo;

  /* Writes the Almost Empty threshold for Tx in the corresponding register */
  g_xStatus = SpiritSpiWriteRegisters(FIFO_CONFIG0_TXAETHR_BASE, 1, &tempRegValue);

}
Exemplo n.º 30
0
/**
 * @brief  Sets the RSSI filter gain. This parameter sets the bandwidth of a low pass IIR filter (RSSI_FLT register, allowed values 0..15), a
 *         lower values gives a faster settling of the measurements but lower precision. The recommended value for such parameter is 14.
 * @param  xRssiFg RSSI filter gain value.
 *         This parameter can be any value of @ref RssiFilterGain.
 * @retval None.
 */
void SpiritQiSetRssiFilterGain(RssiFilterGain xRssiFg)
{
    uint8_t tempRegValue;

    /* Check the parameters */
    s_assert_param(IS_RSSI_FILTER_GAIN(xRssiFg));

    /* Reads the RSSI_FLT register */
    g_xStatus = SpiritSpiReadRegisters(RSSI_FLT_BASE, 1, &tempRegValue);

    /* Sets the specified filter gain */
    tempRegValue &= 0x0F;
    tempRegValue |= ((uint8_t)xRssiFg);

    /* Writes the new value on the RSSI_FLT register */
    g_xStatus = SpiritSpiWriteRegisters(RSSI_FLT_BASE, 1, &tempRegValue);

}