[uart] add lock interface for uart (#3380)

This commit is contained in:
Jiacheng Guo
2019-01-15 01:28:33 -08:00
committed by Jonathan Hui
parent 0f4bae97e9
commit 1f6d7c8b3b
+34
View File
@@ -52,6 +52,38 @@
#include <openthread/platform/debug_uart.h>
#endif
#ifdef OT_CLI_UART_LOCK_HDR_FILE
#include OT_CLI_UART_LOCK_HDR_FILE
#else
/**
* Macro to acquire an exclusive lock of uart cli output
* Default implementation does nothing
*
*/
#ifndef OT_CLI_UART_OUTPUT_LOCK
#define OT_CLI_UART_OUTPUT_LOCK() \
do \
{ \
} while (0)
#endif
/**
* Macro to release the exclusive lock of uart cli output
* Default implementation does nothing
*
*/
#ifndef OT_CLI_UART_OUTPUT_UNLOCK
#define OT_CLI_UART_OUTPUT_UNLOCK() \
do \
{ \
} while (0)
#endif
#endif // OT_CLI_UART_LOCK_HDR_FILE
namespace ot {
namespace Cli {
@@ -236,6 +268,7 @@ otError Uart::ProcessCommand(void)
int Uart::Output(const char *aBuf, uint16_t aBufLength)
{
OT_CLI_UART_OUTPUT_LOCK();
uint16_t remaining = kTxBufferSize - mTxLength;
uint16_t tail;
@@ -252,6 +285,7 @@ int Uart::Output(const char *aBuf, uint16_t aBufLength)
}
Send();
OT_CLI_UART_OUTPUT_UNLOCK();
return aBufLength;
}