__interrupt void UartInterrupt(void)
{
   Word_t        VectorRegister;
   volatile char Dummy;

   /* Read the Vector register once to determine the cause of the       */
   /* interrupt.                                                        */
   VectorRegister = BT_UART_IVR;

   /* Determine the cause of the interrupt (Rx or Tx).                  */
   if(VectorRegister == USCI_UCRXIFG)
   {
      /* Check to see if there is buffer space to receive the data.     */
      if(UartContext.RxBytesFree)
      {
         /* check to see if an overrun occured.                         */
         if(HWREG8(UartContext.UartBase + MSP430_UART_STAT_OFFSET) & 0xEC)
            HAL_ConsoleWrite(1, "?");

         /* Read the character from the UART Receive Buf.               */
         UartContext.RxBuffer[UartContext.RxInIndex++] = UARTReceiveBufferReg(UartContext.UartBase);

         /* Credit the received character.                              */
         --(UartContext.RxBytesFree);

         /* Check to see if we have reached the end of the Buffer and   */
         /* need to loop back to the beginning.                         */
         if(UartContext.RxInIndex >= UartContext.RxBufferSize)
            UartContext.RxInIndex = 0;

         /* Check to see if we need to Disable Rx Flow                  */
         /* RxThread will re-enable flow control when it is possible    */
         if((UartContext.Flags & UART_CONTEXT_FLAG_FLOW_ENABLED) && (UartContext.RxBytesFree <= UartContext.XOffLimit))
         {
            /* if Flow is Enabled then disable it                       */
            UartContext.Flags &= (~UART_CONTEXT_FLAG_FLOW_ENABLED);
            FLOW_OFF();
         }
      }
      else
      {
         /* We have data in the FIFO, but no place to put the data,     */
         /* so will will have to flush the FIFO and discard the data.   */
         Dummy = UARTReceiveBufferReg(UartContext.UartBase);

         /* Flag that we have encountered an RX Overrun.                */
         /* Also Disable Rx Flow.                                       */
         UartContext.Flags |= UART_CONTEXT_FLAG_RX_OVERRUN;
         UartContext.Flags &= (~UART_CONTEXT_FLAG_FLOW_ENABLED);
         FLOW_OFF();
      }

      /* If the UART is in the process of shutting down flag that this  */
      /* has been interrupted due to the arrival of UART data.          */
      if(UartContext.SuspendState == hssSuspendWait)
      {
         /* Indicate the suspend is interrupted.                        */
         UartContext.SuspendState = hssSuspendWaitInterrupted;
      }
   }
   else
   {
      if(VectorRegister == USCI_UCTXIFG)
      {
         /* Process the Transmit Empty Interrupt.                       */
         TxTransmit();
      }
   }

   /* Exit from LPM if necessary (this statement will have no effect if */
   /* we are not currently in low power mode).                          */
   LPM_EXIT();
}
Example #2
0
File: Main.c Project: ee230/trunks
static void DisplayCallback(char Character) {
	HAL_ConsoleWrite(1, &Character);
}