Skip to content

Commit 849cd47

Browse files
committed
Revert new ringbuffer code for now. Fix other merge issues.
1 parent bda504a commit 849cd47

File tree

5 files changed

+115
-111
lines changed

5 files changed

+115
-111
lines changed

cores/arduino/RingBuffer.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright (c) 2014 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "RingBuffer.h"
20+
#include <string.h>
21+
22+
RingBuffer::RingBuffer( void )
23+
{
24+
memset( _aucBuffer, 0, SERIAL_BUFFER_SIZE ) ;
25+
clear();
26+
}
27+
28+
void RingBuffer::store_char( uint8_t c )
29+
{
30+
int i = nextIndex(_iHead);
31+
32+
// if we should be storing the received character into the location
33+
// just before the tail (meaning that the head would advance to the
34+
// current location of the tail), we're about to overflow the buffer
35+
// and so we don't write the character or advance the head.
36+
if ( i != _iTail )
37+
{
38+
_aucBuffer[_iHead] = c ;
39+
_iHead = i ;
40+
}
41+
}
42+
43+
void RingBuffer::clear()
44+
{
45+
_iHead = 0;
46+
_iTail = 0;
47+
}
48+
49+
int RingBuffer::read_char()
50+
{
51+
if(_iTail == _iHead)
52+
return -1;
53+
54+
uint8_t value = _aucBuffer[_iTail];
55+
_iTail = nextIndex(_iTail);
56+
57+
return value;
58+
}
59+
60+
int RingBuffer::available()
61+
{
62+
int delta = _iHead - _iTail;
63+
64+
if(delta < 0)
65+
return SERIAL_BUFFER_SIZE + delta;
66+
else
67+
return delta;
68+
}
69+
70+
int RingBuffer::availableForStore()
71+
{
72+
if (_iHead >= _iTail)
73+
return SERIAL_BUFFER_SIZE - 1 - _iHead + _iTail;
74+
else
75+
return _iTail - _iHead - 1;
76+
}
77+
78+
int RingBuffer::peek()
79+
{
80+
if(_iTail == _iHead)
81+
return -1;
82+
83+
return _aucBuffer[_iTail];
84+
}
85+
86+
int RingBuffer::nextIndex(int index)
87+
{
88+
return (uint32_t)(index + 1) % SERIAL_BUFFER_SIZE;
89+
}
90+
91+
bool RingBuffer::isFull()
92+
{
93+
return (nextIndex(_iHead) == _iTail);
94+
}

cores/arduino/RingBuffer.h

Lines changed: 17 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#ifdef __cplusplus
20-
2119
#ifndef _RING_BUFFER_
2220
#define _RING_BUFFER_
2321

@@ -29,114 +27,26 @@
2927
// location from which to read.
3028
#define SERIAL_BUFFER_SIZE 64
3129

32-
template <int N>
33-
class RingBufferN
34-
{
35-
public:
36-
uint8_t _aucBuffer[N] ;
37-
volatile int _iHead ;
38-
volatile int _iTail ;
39-
40-
public:
41-
RingBufferN( void ) ;
42-
void store_char( uint8_t c ) ;
43-
void clear();
44-
int read_char();
45-
int available();
46-
int availableForStore();
47-
int peek();
48-
bool isFull();
49-
50-
private:
51-
int nextIndex(int index);
52-
};
53-
54-
typedef RingBufferN<SERIAL_BUFFER_SIZE> RingBuffer;
55-
56-
57-
template <int N>
58-
RingBufferN<N>::RingBufferN( void )
59-
{
60-
memset( _aucBuffer, 0, N ) ;
61-
clear();
62-
}
63-
64-
template <int N>
65-
void RingBufferN<N>::store_char( uint8_t c )
66-
{
67-
int i = nextIndex(_iHead);
68-
69-
// if we should be storing the received character into the location
70-
// just before the tail (meaning that the head would advance to the
71-
// current location of the tail), we're about to overflow the buffer
72-
// and so we don't write the character or advance the head.
73-
if ( i != _iTail )
74-
{
75-
_aucBuffer[_iHead] = c ;
76-
_iHead = i ;
77-
}
78-
}
79-
80-
template <int N>
81-
void RingBufferN<N>::clear()
82-
{
83-
_iHead = 0;
84-
_iTail = 0;
85-
}
86-
87-
template <int N>
88-
int RingBufferN<N>::read_char()
30+
class RingBuffer
8931
{
90-
if(_iTail == _iHead)
91-
return -1;
92-
93-
uint8_t value = _aucBuffer[_iTail];
94-
_iTail = nextIndex(_iTail);
32+
public:
33+
uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
34+
volatile int _iHead ;
35+
volatile int _iTail ;
9536

96-
return value;
97-
}
98-
99-
template <int N>
100-
int RingBufferN<N>::available()
101-
{
102-
int delta = _iHead - _iTail;
103-
104-
if(delta < 0)
105-
return N + delta;
106-
else
107-
return delta;
108-
}
109-
110-
template <int N>
111-
int RingBufferN<N>::availableForStore()
112-
{
113-
if (_iHead >= _iTail)
114-
return N - 1 - _iHead + _iTail;
115-
else
116-
return _iTail - _iHead - 1;
117-
}
37+
public:
38+
RingBuffer( void ) ;
39+
void store_char( uint8_t c ) ;
40+
void clear();
41+
int read_char();
42+
int available();
43+
int availableForStore();
44+
int peek();
45+
bool isFull();
11846

119-
template <int N>
120-
int RingBufferN<N>::peek()
121-
{
122-
if(_iTail == _iHead)
123-
return -1;
124-
125-
return _aucBuffer[_iTail];
126-
}
127-
128-
template <int N>
129-
int RingBufferN<N>::nextIndex(int index)
130-
{
131-
return (uint32_t)(index + 1) % N;
132-
}
133-
134-
template <int N>
135-
bool RingBufferN<N>::isFull()
136-
{
137-
return (nextIndex(_iHead) == _iTail);
138-
}
47+
private:
48+
int nextIndex(int index);
49+
} ;
13950

14051
#endif /* _RING_BUFFER_ */
14152

142-
#endif /* __cplusplus */

cores/arduino/Uart.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
6464
if (uc_pinRTS != NO_RTS_PIN) {
6565
pinMode(uc_pinRTS, OUTPUT);
6666

67-
EPortType rtsPort = g_APinDescription[uc_pinRTS].ulPort;
67+
uint8_t rtsPort = g_APinDescription[uc_pinRTS].ulPort;
6868
pul_outsetRTS = &PORT->Group[rtsPort].OUTSET.reg;
6969
pul_outclrRTS = &PORT->Group[rtsPort].OUTCLR.reg;
7070
ul_pinMaskRTS = (1ul << g_APinDescription[uc_pinRTS].ulPin);

libraries/SPI/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// Note that while SCK and MOSI may be operable at a higher clock speed,
4747
// MISO should not operate above 12MHz.
4848
// The SAMD51 SERCOM runs at 96MHz when the cpu runs at 120MHz
49-
#if (SAMD21 || SAMD11 || SAML21)
49+
#if (SAMD51 || SAMD21 || SAMD11 || SAML21)
5050
#define SPI_MAX_FREQUENCY 12000000ul
5151
#elif (SAMC21)
5252
#define SPI_MAX_FREQUENCY 6000000ul

libraries/Wire/Wire.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ class TwoWire : public Stream
7878
bool transmissionBegun;
7979

8080
// RX Buffer
81-
RingBufferN<256> rxBuffer;
81+
RingBuffer rxBuffer;
8282

8383
//TX buffer
84-
RingBufferN<256> txBuffer;
84+
RingBuffer txBuffer;
8585
uint8_t txAddress;
8686

8787
// Callback user functions

0 commit comments

Comments
 (0)