Skip to content

Commit

Permalink
Merge pull request #273 from LinjingZhang/bug/DESMAKERS-3603-micropho…
Browse files Browse the repository at this point in the history
…ne-serial-print-problem

fix RingBuffer  initialization
  • Loading branch information
ederjc authored May 7, 2024
2 parents aee04a4 + 8dbefd9 commit bb90666
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
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

0 comments on commit bb90666

Please sign in to comment.