Beispiel #1
0
TEST(CircularBufferSingle, TestError)
{
    const float data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    float out[4];
    CircularBuffer* buffer = CircularBufferInit(8);
    CircularBufferWrite(buffer, data, 4);
    ASSERT_EQ(VALUE_ERROR, CircularBufferRead(buffer, out, 5));
    CircularBufferFlush(buffer);
    CircularBufferWrite(buffer, data, 8);
    ASSERT_EQ(VALUE_ERROR, CircularBufferWrite(buffer, data, 1));
}
Beispiel #2
0
TEST(CircularBufferSingle, TestMultiWriteRead)
{
    const float data[4] = {1,2,3,4};
    float out[4] = {0,0,0,0};
    CircularBuffer *buffer = CircularBufferInit(7);
    CircularBufferWrite(buffer, data, 2);
    CircularBufferWrite(buffer, data + 2, 2);
    CircularBufferRead(buffer, out, 4);
    CircularBufferFree(buffer);
    
    for (unsigned i = 0; i < 4; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], data[i]);
    }
}
Beispiel #3
0
TEST(CircularBufferSingle, TestCount)
{
    const float data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    float out[4];
    CircularBuffer* buffer = CircularBufferInit(8);
    CircularBufferWrite(buffer, data, 4);
    ASSERT_EQ(4, CircularBufferCount(buffer));
    CircularBufferRead(buffer, out, 2);
    ASSERT_EQ(2, CircularBufferCount(buffer));
    CircularBufferFlush(buffer);
    ASSERT_EQ(0, CircularBufferCount(buffer));
}
Beispiel #4
0
TEST(CircularBufferSingle, TestFlush)
{
    const float data[4] = {1,2,3,4};
    float out[4] = {0,0,0,0};
    CircularBuffer *buffer = CircularBufferInit(7);
    CircularBufferWrite(buffer, data, 4);
    CircularBufferFlush(buffer);
    CircularBufferFree(buffer);
    
    for (unsigned i = 0; i < 4; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], 0.0);
    }
}
Beispiel #5
0
TEST(CircularBufferSingle, TestRewind)
{
    const float data[4] = {1,2,3,4};
    float out[4] = {0, 0, 0, 0};
    float expected[4] = {3, 4, 3, 4};
    CircularBuffer *buffer = CircularBufferInit(7);
    CircularBufferWrite(buffer, data, 4);
    CircularBufferRead(buffer, out, 4);
    CircularBufferRewind(buffer, 2);
    CircularBufferRead(buffer, out, 2);
    CircularBufferFlush(buffer);
    CircularBufferFree(buffer);
    
    for (unsigned i = 0; i < 4; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], expected[i]);
    }
}
Beispiel #6
0
int main(int argc, char *argv[])
{
        CircularBuffer* que;
        unsigned int a = 0,*p=NULL;
        int isEmpty;
        p = (unsigned int *)calloc(188,sizeof(char));

        CircularBufferInit(&que, BUFFER_SIZE);
        do{
          a += 1;
         }while(!CircularBufferWrite(que, &a));
 
        do {
            isEmpty = CircularBufferRead(que, p); 
            printf("%02d ", *p);
        } while (!isEmpty);
        printf("\n");
        
        free(p);
        free(que);
        return 0;
}
/**
 *  @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;
}