Ejemplo n.º 1
0
   /*          to this function.                                        */
int BTPSAPI HCITR_COMWrite(unsigned int HCITransportID, unsigned int Length, unsigned char *Buffer)
{
   int ret_val;
   int Count;

   /* Check to make sure that the specified Transport ID is valid and   */
   /* the output buffer appears to be valid as well.                    */
   if((HCITransportID == TRANSPORT_ID) && (HCITransportOpen) && (Length) && (Buffer))
   {
      /* Delay and poll until there is enough room in the Tx Buffer (in */
      /* the UartContext structure) to hold the data we are trying to   */
      /* transmit.                                                      */
      while(UartContext.TxBytesFree < Length)
         BTPS_Delay(10);

      /* Process all of the data.                                       */
      while(Length)
      {
         /* The data may have to be copied in 2 phases.  Calculate the  */
         /* number of character that can be placed in the buffer before */
         /* the buffer must be wrapped.                                 */
         Count = (UartContext.TxBufferSize-UartContext.TxInIndex);
         Count = (Count > Length)?Length:Count;
         BTPS_MemCopy(&(UartContext.TxBuffer[UartContext.TxInIndex]), Buffer, Count);

         /* Update the number of free bytes in the buffer.  Since this  */
         /* count can also be updated in the interrupt routine, we will */
         /* have have to update this with interrupts disabled.          */
         MAP_IntDisable(UartContext.IntBase);
         UartContext.TxBytesFree -= Count;
         MAP_IntEnable(UartContext.IntBase);

         /* Adjust the count and index values.                          */
         Buffer                += Count;
         Length                -= Count;
         UartContext.TxInIndex += Count;
         if(UartContext.TxInIndex >= UartContext.TxBufferSize)
            UartContext.TxInIndex = 0;
      }

      /* Check to see if we need to prime the transmitter.              */
      if(!(HWREG(UartContext.Base + UART_O_IM) & UART_IM_TXIM))
      {
         /* Now that the data is in the input buffer, check to see if we*/
         /* need to enable the interrupt to start the TX Transfer.      */
         HWREG(UartContext.Base + UART_O_IM) |= UART_IM_TXIM;

         /* Start sending data to the Uart Transmit.                    */
         MAP_IntDisable(UartContext.IntBase);
         TxInterrupt();
         MAP_IntEnable(UartContext.IntBase);
      }

      ret_val = 0;
   }
   else
      ret_val = HCITR_ERROR_WRITING_TO_PORT;

   return(ret_val);
}
Ejemplo n.º 2
0
   /* character in the stream into the final parameter to this function.*/
static void LoadTransmitBuffer(unsigned int Length, unsigned char *Buffer)
{
   unsigned int Count;

   /* If the UART is suspended, resume it.                              */
   if(UartContext.SuspendState == hssSuspended)
   {
      DISABLE_INTERRUPTS();

#ifdef __DISABLE_SMCLK__

      /* Request that the SMCLK stay active.                            */
      /* * NOTE * Since we are executing code the SMCLK is currently    */
      /*          active, however what this function calls does is      */
      /*          enable SMCLK requests, so that when LPM3 is next      */
      /*          entered the UART may request that the clock stays     */
      /*          active.                                               */
      HAL_EnableSMCLK(HAL_PERIPHERAL_BLUETOOTH_UART);

#endif

      /* Flag that the UART clock has been resumed.                     */
      UartContext.SuspendState  = hssNormal;
      UartContext.Flags        &= ~UART_CONTEXT_FLAG_UART_SUSPENDED;
      FLOW_ON();

      ENABLE_INTERRUPTS();

      /* Add a delay while the SMCLK stabilizes.                        */
      __delay_cycles(2500);
   }

   /* Process all of the data.                                          */
   while(Length)
   {
      /* Loop until space becomes available in the Tx Buffer            */
      while (UartContext.TxBytesFree <= 0)
         ;

      /* The data may have to be copied in 2 phases.  Calculate the     */
      /* number of character that can be placed in the buffer before the*/
      /* buffer must be wrapped.                                        */
      Count = UartContext.TxBufferSize-UartContext.TxInIndex;

      /* Make sure we dont copy over data waiting to be sent.           */
      Count = (UartContext.TxBytesFree < Count)?(UartContext.TxBytesFree):(Count);

      /* Next make sure we arent trying to copy greater than what we are*/
      /* given.                                                         */
      Count = (Count > Length)?Length:Count;
      BTPS_MemCopy(&(UartContext.TxBuffer[UartContext.TxInIndex]), Buffer, Count);

      /* Update the number of free bytes in the buffer.  Since this     */
      /* count can also be updated in the interrupt routine, we will    */
      /* have have to update this with interrupts disabled.             */
      DISABLE_INTERRUPTS();
      UartContext.TxBytesFree -= Count;
      ENABLE_INTERRUPTS();

      /* Adjust the count and index values.                             */
      Buffer                += Count;
      Length                -= Count;
      UartContext.TxInIndex += Count;
      if(UartContext.TxInIndex >= UartContext.TxBufferSize)
         UartContext.TxInIndex = 0;

      /* Check to see if we need to prime the transmitter.  The Tx      */
      /* Interrupt will flag that that it is disabled if thinks that    */
      /* TxBytesFree == TxBufferSize, re-enable if it is necessary.     */
      if((UartContext.Flags & (UART_CONTEXT_FLAG_TRANSMIT_ENABLED | UART_CONTEXT_FLAG_TX_FLOW_ENABLED | UART_CONTEXT_FLAG_TX_PRIMED)) == (UART_CONTEXT_FLAG_TRANSMIT_ENABLED | UART_CONTEXT_FLAG_TX_FLOW_ENABLED))
      {
         /* Start sending data to the Uart Transmit FIFO.               */
         DISABLE_INTERRUPTS();

         /* Enable the transmit interrupt.                              */
         UARTIntEnableTransmit(UartContext.UartBase);

         /* Prime the transmitter.                                      */
         TxTransmit();

         ENABLE_INTERRUPTS();
      }
   }
}
Ejemplo n.º 3
0
int Bluetooth::pinCodeResponse(const char *pinCode)
{
   int                              Result;
   int                              ret_val;
   PIN_Code_t                       PINCode;
   GAP_Authentication_Information_t GAP_Authentication_Information;

   /* First, check that valid Bluetooth Stack ID exists.                */
   if(bluetoothStackID)
   {
      /* First, check to see if there is an on-going Pairing operation  */
      /* active.                                                        */
      if(!COMPARE_BD_ADDR(CurrentRemoteBD_ADDR, NullADDR))
      {
         /* Make sure that all of the parameters required for this      */
         /* function appear to be at least semi-valid.                  */
         if((BTPS_StringLength(pinCode) > 0) && (BTPS_StringLength(pinCode) <= sizeof(PIN_Code_t)))
         {
            /* Parameters appear to be valid, go ahead and convert the  */
            /* input parameter into a PIN Code.                         */

            /* Initialize the PIN code.                                 */
            ASSIGN_PIN_CODE(PINCode, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

            BTPS_MemCopy(&PINCode, pinCode, BTPS_StringLength(pinCode));

            /* Populate the response structure.                         */
            GAP_Authentication_Information.GAP_Authentication_Type      = atPINCode;
            GAP_Authentication_Information.Authentication_Data_Length   = (Byte_t)(BTPS_StringLength(pinCode));
            GAP_Authentication_Information.Authentication_Data.PIN_Code = PINCode;

            /* Submit the Authentication Response.                      */
            Result = GAP_Authentication_Response(bluetoothStackID, CurrentRemoteBD_ADDR, &GAP_Authentication_Information);

            /* Check the return value for the submitted command for     */
            /* success.                                                 */
            if(!Result)
            {
               /* Flag success to the caller.                           */
               ret_val = 0;
            }
            else
            {
               /* Inform the user that the Authentication Response was  */
               /* not successful.                                       */
               ret_val = -1;
            }

            /* Flag that there is no longer a current Authentication    */
            /* procedure in progress.                                   */
            ASSIGN_BD_ADDR(CurrentRemoteBD_ADDR, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
         }
         else
         {
             ret_val = -1;
         }
      }
      else
      {
         /* There is not currently an on-going authentication operation,*/
         /* inform the user of this error condition.                    */
         ret_val = -1;
      }
   }
   else
   {
      /* No valid Bluetooth Stack ID exists.                            */
      ret_val = -1;
   }

   return(ret_val);
}