Example #1
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]);
    }
}
Example #2
0
TEST(CircularBufferSingle, TestWrap)
{
    const float data[4] = {1,2,3,4};
    float out[4] = {0,0,0,0};
    CircularBuffer *buffer = CircularBufferInit(7);
    CircularBufferWrite(buffer, data, 4);
    CircularBufferWrite(buffer, data, 4);
    CircularBufferWrite(buffer, data, 4);
    CircularBufferRead(buffer, out, 4);
    CircularBufferRead(buffer, out, 4);
    CircularBufferRead(buffer, out, 4);
    CircularBufferFree(buffer);
    
    for (unsigned i = 0; i < 4; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], data[i]);
    }
}
Example #3
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));
}
Example #4
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));
}
/**
 *  @details
 */
signed char __hal_UARTReceiveByte(enum PERIPHERAL peripheral, unsigned char * readValue)
{
  // If USCI is defined, include the following code.
  #if defined(__MCU_MSP430_USCI)
  // Check if we are using the USCIA0 peripheral.
  if (peripheral == USCIA0)
  {
    // Read value from receive circular buffer.
    return CircularBufferRead(&USCIA0Buffer.rx, readValue);
  }
  #endif
  
  // NOTE: This return statement should never be reached. If it is, return that 
  // the read was unsuccessful as an unknown event has occurred.
  return 0;
}
Example #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;
}