Skip to content

Commit

Permalink
ElectronSerialPipe: correctly handle buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
avtolstoy committed Oct 16, 2016
1 parent ecd176b commit 428835a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions hal/src/electron/modem/electronserialpipe_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ void ElectronSerialPipe::rxIrqBuf(void)
char c = USART_ReceiveData(USART3);
_pipeRx.putc(c);
} else {
/* TODO: Handle overflow?
* We should not read USART3->RDR register in order to
* signal to the modem that we are not ready to receive,
* then try to process and free the buffer.
*/
(void)USART_ReceiveData(USART3);
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
}
}

void ElectronSerialPipe::rxResume(void)
{
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
}

/*******************************************************************************
* Function Name : HAL_USART3_Handler
* Description : This function handles USART3 global interrupt request.
Expand Down
4 changes: 4 additions & 0 deletions hal/src/electron/modem/electronserialpipe_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class ElectronSerialPipe
*/
void txIrqBuf(void);

/** resumes paused receiver (hardware flow control)
*/
void rxResume();

protected:
//! start transmission helper
void txStart(void);
Expand Down
5 changes: 4 additions & 1 deletion hal/src/electron/modem/mdm_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,7 @@ int MDMParser::_getLine(Pipe<char>* pipe, char* buf, int len)
{ "\r\n>", NULL, TYPE_PROMPT }, // SMS
{ "\n>", NULL, TYPE_PROMPT }, // File
{ "\r\nABORTED\r\n", NULL, TYPE_ABORTED }, // Current command aborted
{ "\r\n", "\r\n", TYPE_UNKNOWN }, // If all else fails, break up generic strings
};
for (int i = 0; i < (int)(sizeof(lutF)/sizeof(*lutF)); i ++) {
pipe->set(unkn);
Expand Down Expand Up @@ -2305,5 +2306,7 @@ int MDMElectronSerial::_send(const void* buf, int len)

int MDMElectronSerial::getLine(char* buffer, int length)
{
return _getLine(&_pipeRx, buffer, length);
int ret = _getLine(&_pipeRx, buffer, length);
rxResume();
return ret;
}

0 comments on commit 428835a

Please sign in to comment.