Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix RingBuffer initialization #273

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions cores/RingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,33 @@
// @Project Includes
//****************************************************************************
#include "RingBuffer.h"

#include <string.h>
//****************************************************************************
// @Local Functions
//****************************************************************************

// Constructors ////////////////////////////////////////////////////////////////

RingBuffer::RingBuffer( int bufferSize )
RingBuffer::RingBuffer( void )
{
_bufferSize = bufferSize;
_aucBuffer = new uint8_t[_bufferSize];
_iHead = 0 ;
_iTail = 0 ;
memset( (void *)_aucBuffer, 0, SERIAL_BUFFER_SIZE ) ;
_iHead=0 ;
_iTail=0 ;
}

// Public Methods //////////////////////////////////////////////////////////////

void RingBuffer::store_char( uint8_t c )
{
int i = _iHead + 1;
if( i >= _bufferSize )
i = 0;

// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if ( i != _iTail )
{
_aucBuffer[_iHead] = c ;
_iHead = i ;
}
int i = (uint32_t)(_iHead + 1) % SERIAL_BUFFER_SIZE ;

// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if ( i != _iTail )
{
_aucBuffer[_iHead] = c ;
_iHead = i ;
}
}

//****************************************************************************
Expand Down
10 changes: 4 additions & 6 deletions cores/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@

class RingBuffer
{
public:
volatile uint8_t *_aucBuffer;
// volatile uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
public:
volatile uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
volatile int _iHead ;
volatile int _iTail ;
volatile int _bufferSize ;

public:
RingBuffer( int bufferSize = SERIAL_BUFFER_SIZE) ;
public:
RingBuffer( void ) ;
void store_char( uint8_t c ) ;
} ;

Expand Down
Loading