Skip to content

Commit c396a3a

Browse files
committed
Shrink oversized objects in SRAM
824 bytes is gained for use by sketches. Two new defines are added; CDCACM_BUFFER_SIZE and UART_BUFFER_SIZE. The CDC-ACM Serial class and the UART driver had been using the same #define for buffer size-- SERIAL_BUFFER_SIZE-- and separating them means that the CDC-ACM buffer can stay the same size, while the UART buffer is shrunk.
1 parent 1a5e3f7 commit c396a3a

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

cores/arduino/CDCSerialClass.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void CDCSerialClass::end( void )
8383

8484
int CDCSerialClass::available( void )
8585
{
86-
#define SBS SERIAL_BUFFER_SIZE
86+
#define SBS CDCACM_BUFFER_SIZE
8787

8888
if (!_shared_data->device_open)
8989
return (0);
@@ -100,7 +100,7 @@ int CDCSerialClass::availableForWrite(void)
100100
int tail = _tx_buffer->tail;
101101

102102
if (head >= tail)
103-
return SERIAL_BUFFER_SIZE - head + tail - 1;
103+
return CDCACM_BUFFER_SIZE - head + tail - 1;
104104
return tail - head - 1;
105105
}
106106

@@ -118,7 +118,7 @@ int CDCSerialClass::read( void )
118118
return -1;
119119

120120
uint8_t uc = _rx_buffer->data[_rx_buffer->tail];
121-
_rx_buffer->tail = (_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
121+
_rx_buffer->tail = (_rx_buffer->tail + 1) % CDCACM_BUFFER_SIZE;
122122
return uc;
123123
}
124124

@@ -138,7 +138,7 @@ size_t CDCSerialClass::write( const uint8_t uc_data )
138138
return(0);
139139

140140
do {
141-
int i = (uint32_t)(_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
141+
int i = (uint32_t)(_tx_buffer->head + 1) % CDCACM_BUFFER_SIZE;
142142
// if we should be storing the received character into the location
143143
// just before the tail (meaning that the head would advance to the
144144
// current location of the tail), we're about to overflow the buffer

cores/arduino/RingBuffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
RingBuffer::RingBuffer( void )
2525
{
26-
memset( _aucBuffer, 0, SERIAL_BUFFER_SIZE ) ;
26+
memset( _aucBuffer, 0, UART_BUFFER_SIZE ) ;
2727
_iHead=0 ;
2828
_iTail=0 ;
2929
}
3030

3131
void RingBuffer::store_char( uint8_t c )
3232
{
33-
int i = (uint32_t)(_iHead + 1) % SERIAL_BUFFER_SIZE ;
33+
int i = (uint32_t)(_iHead + 1) % UART_BUFFER_SIZE ;
3434

3535
// if we should be storing the received character into the location
3636
// just before the tail (meaning that the head would advance to the

cores/arduino/RingBuffer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
// using a ring buffer (I think), in which head is the index of the location
2424
// to which to write the next incoming character and tail is the index of the
2525
// location from which to read.
26-
#define SERIAL_BUFFER_SIZE 256
26+
#define UART_BUFFER_SIZE 64
2727

2828
class RingBuffer
2929
{
3030
public:
31-
uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
31+
uint8_t _aucBuffer[UART_BUFFER_SIZE] ;
3232
int _iHead ;
3333
int _iTail ;
3434
bool _buffer_overflow ;

cores/arduino/UARTClass.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ uint32_t UARTClass::getInterruptPriority()
134134

135135
int UARTClass::available( void )
136136
{
137-
return (uint32_t)(SERIAL_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % SERIAL_BUFFER_SIZE;
137+
return (uint32_t)(UART_BUFFER_SIZE + _rx_buffer->_iHead - _rx_buffer->_iTail) % UART_BUFFER_SIZE;
138138
}
139139

140140
int UARTClass::availableForWrite(void)
@@ -143,7 +143,7 @@ int UARTClass::availableForWrite(void)
143143
return(0);
144144
int head = _tx_buffer->_iHead;
145145
int tail = _tx_buffer->_iTail;
146-
if (head >= tail) return SERIAL_BUFFER_SIZE - 1 - head + tail;
146+
if (head >= tail) return UART_BUFFER_SIZE - 1 - head + tail;
147147
return tail - head - 1;
148148
}
149149

@@ -162,7 +162,7 @@ int UARTClass::read( void )
162162
return -1;
163163

164164
uint8_t uc = _rx_buffer->_aucBuffer[_rx_buffer->_iTail];
165-
_rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE;
165+
_rx_buffer->_iTail = (unsigned int)(_rx_buffer->_iTail + 1) % UART_BUFFER_SIZE;
166166
return uc;
167167
}
168168

@@ -182,7 +182,7 @@ size_t UARTClass::write( const uint8_t uc_data )
182182
if (_tx_buffer->_iTail != _tx_buffer->_iHead)
183183
{
184184
// If busy we buffer
185-
int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE;
185+
int l = (_tx_buffer->_iHead + 1) % UART_BUFFER_SIZE;
186186
while (_tx_buffer->_iTail == l)
187187
; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent
188188

@@ -215,7 +215,7 @@ void UARTClass::IrqHandler( void )
215215
{
216216
if (_tx_buffer->_iTail != _tx_buffer->_iHead) {
217217
uart_poll_out(CONFIG_UART_CONSOLE_INDEX, _tx_buffer->_aucBuffer[_tx_buffer->_iTail]);
218-
_tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE;
218+
_tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % UART_BUFFER_SIZE;
219219
}
220220
else
221221
{

system/libarc32_arduino101/framework/include/infra/port.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @{
4242
*/
4343

44-
#define MAX_PORTS 50
44+
#define MAX_PORTS 6
4545

4646

4747
#ifndef CONFIG_INFRA_IS_MASTER

system/libarc32_arduino101/framework/include/platform.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
#define CPU_ID_HOST 3
4040
#define NUM_CPU 4
4141

42-
#define SERIAL_BUFFER_SIZE 256
42+
#define CDCACM_BUFFER_SIZE 256
4343

4444
struct cdc_ring_buffer
4545
{
4646
/** Ring buffer data */
47-
uint8_t data[SERIAL_BUFFER_SIZE];
47+
uint8_t data[CDCACM_BUFFER_SIZE];
4848
/** Ring buffer head pointer, modified by producer */
4949
int head;
5050
/** Ring buffer head pointer, modified by consumer */
-144 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)