Example #1
0
/*----------------------------------------------------------------------------------------------------------------------
Function: SspRelease

Description:
Releases an SSP resource.  

Requires:
  - psSspPeripheral_ has the SSP peripheral number, address of the RxBuffer, and the RxBuffer size and the calling
    application is ready to start using the peripheral.

Promises:
  - Resets peripheral object's pointers and data to safe values
  - Peripheral is disabled
  - Peripheral interrupts are disabled.
*/
void SspRelease(SspPeripheralType* psSspPeripheral_)
{
  /* Check to see if the peripheral is already released */
  if(psSspPeripheral_->pu8RxBuffer == NULL)
  {
    return;
  }
  
  /* First disable the interrupts */
  NVIC_DisableIRQ( (IRQn_Type)(psSspPeripheral_->u8PeripheralId) );
  NVIC_ClearPendingIRQ( (IRQn_Type)(psSspPeripheral_->u8PeripheralId) );
 
  /* Now it's safe to release all of the resources in the target peripheral */
  psSspPeripheral_->pCsGpioAddress = NULL;
  psSspPeripheral_->pu8RxBuffer    = NULL;
  psSspPeripheral_->ppu8RxNextByte  = NULL;
  psSspPeripheral_->u32PrivateFlags = 0;
  psSspPeripheral_->fnSlaveTxFlowCallback = NULL;
  psSspPeripheral_->fnSlaveRxFlowCallback = NULL;

  /* Empty the transmit buffer if there were leftover messages */
  while(psSspPeripheral_->psTransmitBuffer != NULL)
  {
    UpdateMessageStatus(psSspPeripheral_->psTransmitBuffer->u32Token, ABANDONED);
    DeQueueMessage(&psSspPeripheral_->psTransmitBuffer);
  }
  
  /* Ensure the SM is in the Idle state */
  Ssp_pfnStateMachine = SspSM_Idle;
  
} /* end SspRelease() */
Example #2
0
/* Wait for a transmit message to be queued.  Received data is handled in interrupts. */
void SspIdle(void)
{
  /* Update for next iteration */
  if(SSP_psCurrentSsp->pBaseAddress == LPC_SSP0)
  {
    SSP_psCurrentSsp = &SSP_Peripheral1;
  }
  else if(SSP_psCurrentSsp->pBaseAddress == LPC_SSP1)
  {
    SSP_psCurrentSsp = &SSP_Peripheral0;
  }
  else 
  {
    SSP_u32Flags |= _SSP_ERROR_INVALID_SSP;
  }

  /* Check if a message has been queued on the current SSP */
  if(SSP_psCurrentSsp->pTransmitBuffer != NULL)
  {
    /* Set up to transmit the message */
    SSP_u32CurrentTxBytesRemaining = SSP_psCurrentSsp->pTransmitBuffer->u32Size;
    SSP_pu8CurrentTxData = SSP_psCurrentSsp->pTransmitBuffer->pu8Message;
    SspFillTxBuffer(SSP_psCurrentSsp);

    /* Update the message's status */
    UpdateMessageStatus(SSP_psCurrentSsp->pTransmitBuffer->u32Token, SENDING);
    
   /* Proceed to next state to let the current message send */
    G_SspStateMachine = SspTransmitting;
  }
  
} /* end SspIdle() */
Example #3
0
/* Transmit in progress until current bytes have reached 0.  
Note that received data will be coming in the whole time (may be dummy bytes).
On exit, the transmit message must be dequeued.*/
void SspTransmitting(void)
{
  if( (SSP_u32CurrentTxBytesRemaining == 0) && 
      (SSP_psCurrentSsp->pBaseAddress->SR & _SSP_SR_TFE_BIT) &&
      (!(SSP_psCurrentSsp->pBaseAddress->SR & _SSP_SR_RNE_BIT)) )
  {
    /* Update the status queue and then dequeue the message */
    UpdateMessageStatus(SSP_psCurrentSsp->pTransmitBuffer->u32Token, COMPLETE);
    DeQueueMessage(&SSP_psCurrentSsp->pTransmitBuffer);

    /* Make sure _SSP_INIT_MODE flag is clear in case this was a manual cycle */
    SSP_u32Flags &= ~_SSP_INIT_MODE;
    G_SspStateMachine = SspIdle;
  }
    
} /* end SspIdle() */
Example #4
0
/*----------------------------------------------------------------------------------------------------------------------
Function: SspRelease

Description:
Releases an SSP resource.  

Requires:
  - psSspPeripheral_ has the SSP peripheral number, address of the RxBuffer, and the RxBuffer size and the calling
    application is ready to start using the peripheral.

Promises:
  - Resets peripheral object's pointers and data to safe values
  - Peripheral is disabled
  - Peripheral interrupts are disabled.
*/
void SspRelease(SspPeripheralType* psSspPeripheral_)
{
  /* Check to see if the peripheral is already released */
  if(psSspPeripheral_->pu8RxBuffer == NULL)
  {
    return;
  }

  /* Disable interrupts, deactivate the peripheral */
  if(psSspPeripheral_->pBaseAddress == LPC_SSP0)
  {
    NVIC->ICER[0]  = _SSP0_NVIC_BIT;
    LPC_SC->PCONP &= ~_SSP0_PCONP_BIT;
  }
  else
  {
    NVIC->ICER[0]  = _SSP1_NVIC_BIT;
    LPC_SC->PCONP &= ~_SSP1_PCONP_BIT;
  }

  /* Now it's safe to release all of the resources in the target peripheral */
  psSspPeripheral_->pu8RxBuffer     = NULL;
  psSspPeripheral_->u32RxBufferSize = 0;
  psSspPeripheral_->pu8RxNextByte   = NULL;
  psSspPeripheral_->u32Flags        = 0;

  /* Empty the transmit buffer if there were leftover messages */
  while(psSspPeripheral_->pTransmitBuffer != NULL)
  {
    UpdateMessageStatus(psSspPeripheral_->pTransmitBuffer->u32Token, ABANDONED);
    DeQueueMessage(&psSspPeripheral_->pTransmitBuffer);
  }
  
  /* Ensure the SM is in the Idle state */
  G_SspStateMachine = SspIdle;
  
} /* end SspRelease() */