Example #1
0
// Receving function (not used atm)
void USART1_IRQHandler(void)
{
	// If you try to debug here, you may lose data that comes
	// in while your debugging FYI
	if( USART_GetITStatus(USART1, USART_IT_RXNE) != RESET )
	{
		// Add character to Circular Buffer
		char t = USART_ReceiveData(USART1);
		CircularBufferAdd(&serialInput, t);

		// Add all data to string
		if(t == '\n')
		{
			int counter = 0;
			while(!CircularBufferIsEmpty(&serialInput))
			{
				char r = CircularBufferGet(&serialInput);
				callBackString[counter] = r;
				counter++;
			}
			callBackString[counter] = 0;

			if(returnStringFunction != 0)
			{
				returnStringFunction(callBackString);
			}
		}

		USART_ClearITPendingBit(USART1, USART_IT_RXNE);
	}
}
unsigned char CircularBufferRead(CircularBuffer * pCircularBuffer, unsigned char * readValue)
{    
  ISTATE state = __get_interrupt_state();
  __disable_interrupt();
  
  unsigned char isEmpty = CircularBufferIsEmpty(pCircularBuffer);

  // Verify that there is data to read.
  if (!isEmpty)
  {
    // Read current value at current read pointer position.
    *(readValue) = *(pCircularBuffer->pRead);
  
    // Manipulate pointers.
    // Compare the current ptr offset position to the buffer start.
    if (pCircularBuffer->pRead < pCircularBuffer->pBufferEnd)
    {
      // If the pointer address is less than the buffer start address + size of
      // the buffer, increment the pointer.
      pCircularBuffer->pRead = pCircularBuffer->pRead + 1;
    }
    else
    {
      // If the pointer reaches the end, set it back to the beginning.
      pCircularBuffer->pRead = pCircularBuffer->pBuffer;
    }
  }

  __set_interrupt_state(state);
  
  return isEmpty;
}
Example #3
0
int CircularBufferDeque(CircularBuffer* que, KeyType* pK)
{
        int isEmpty =  CircularBufferIsEmpty(que);
        *pK = que->keys[que->readPointer];
        que->readPointer++;
        que->readPointer %= que->size;
        return(isEmpty);
}
Example #4
0
File: cb.c Project: smrtalek/e4357
inline int CircularBufferDeque(CircularBuffer* que, KeyType* pK)
{
  int isEmpty =  CircularBufferIsEmpty(que);
  if(!isEmpty) 
  {
    *pK = que->keys[que->readPointer];
    que->readPointer++;
    que->readPointer &= que->mask;
  }
  return(isEmpty);
}
Example #5
0
inline int CircularBufferRead(CircularBuffer* que, void* pK)
{
        int isEmpty = 0;
        isEmpty = CircularBufferIsEmpty(que);
        //*pK = *que->keys[que->readPointer];
        memcpy(pK,que->keys[que->readPointer],188);
        que->readPointer++;
        que->readPointer %= que->size;
        
        return(isEmpty);
}
Example #6
0
File: cb.c Project: smrtalek/e4357
inline int CircularBufferPrint(CircularBuffer* que)
{
  int i=0;
  int isEmpty =  CircularBufferIsEmpty(que);
  int isFull  =  CircularBufferIsFull(que);
  printf("\n==Q: w:%d r:%d f:%d e:%d\n", 
    que->writePointer, que->readPointer,  isFull, isEmpty);
  for(i=0; i< que->size; i++)
  {
   printf("%d ", que->keys[i]);
  }
  printf("\n");
  return(isEmpty);
}
Example #7
0
/**
 * Relays data from Bluetooth to Radio
 */
void relayFromBluetooth()
{
    /* UART1 - FTDI USB
     * UART2 - Bluetooth
     * UART3 - Radio        */

    if(!UART2_ReceiveBufferIsEmpty())       //New data on UART2
        InjectLoop(UART2_Read());           //Reads data from UART2 and sends to injector


    //Lets see if there is some data available to send to radio
    if(!CircularBufferIsEmpty(&(inject.outBuff)))
        UART3_Write(CircularBufferDeque(&(inject.outBuff)));
}
Example #8
0
inline int CircularBufferDeque(CircularBuffer* que, KeyType* pK)
{
        int isEmpty =  CircularBufferIsEmpty(que);
        if(!isEmpty) 
        {
        *pK = que->keys[que->readPointer];
        que->readPointer++;
#if IS_BUFFER_SIZE_POWER_OF_TWO
        que->readPointer &= que->mask;
#else
        que->readPointer %= que->size;
#endif
        }
        return(isEmpty);
}
/**
 *	@details
 */
signed char __hal_UARTBusy(enum PERIPHERAL peripheral)
{
  #if defined(__MCU_MSP430_USCI)
  if (peripheral == USCIA0)
  {
    // Check if the UART hardware is configured for UART.
    if (!(UCA0CTL0 && UCSYNC))
    {
      // We only care about the TX buffer being busy. The RX buffer will need to
      // be handled by the application when data comes in. TX is triggered by the
      // application and may wish to wait until the operation completes. This
      // would allow for a blocking implementation.
      return !CircularBufferIsEmpty(&USCIA0Buffer.tx);
    }
  }
  #endif
  
  // Incorrect peripheral provided or none supported.
  return -1;
}
Example #10
0
/**
 * Relays data from USB to Radio
 */
void relayFromUSB()
{
    /* UART1 - FTDI USB
     * UART2 - Bluetooth
     * UART3 - Radio        */

    if(!UART1_ReceiveBufferIsEmpty())
    {
        unsigned char rx = UART1_Read(); //Reads data from UART1 and
        InjectLoop(rx); //sends to injector

        //check for BTB_LAND packet from Mission Planner
        CheckLandingDirection(rx);
    }

    //Lets see if there is some data available to send to radio
    if(!CircularBufferIsEmpty(&(inject.outBuff)))
        UART3_Write(CircularBufferDeque(&(inject.outBuff)));

}
/**
 *  @details  
 */
signed char __hal_UARTTransmitByte(enum PERIPHERAL peripheral, unsigned char value)
{
  signed char isFull = -1;
  // If USCI is defined, include the following code.
  #if defined(__MCU_MSP430_USCI)
  // Check if we are using the USCIA0 peripheral.
  if (peripheral == USCIA0)
  {
    // Write value to transmit circular buffer.
    isFull = CircularBufferWrite(&USCIA0Buffer.tx, value);
    
    // If the a byte was copied successfully, initiate a transmission sequence.
    if (!isFull)
    {
      // Increment USCIA0 TX buffer count.
      USCIA0Buffer.count++;

      if (!CircularBufferIsEmpty(&USCIA0Buffer.tx))
      {
        if(USCIA0Buffer.state != IN_PROGRESS)
        {
          // Set state.
          USCIA0Buffer.state = IN_PROGRESS;
          
          // Set USCIA0 TX interrupt enable to start transmission sequence.
          #if defined(UCA0TXIE)
          IE2 |= UCA0TXIE;
          #elif defined(UCA0IE)
          UCA0IE |= UCTXIE;
          #endif
        }
      }
    }
  }
  #endif
  
  return isFull;
}