Ncp: Update the ncp implementation to use new buffering model (#329)

This commit modifies the `NcpBase` and `NcpUart` classes to use new
Ncp buffer model (defined `in NcpFrameBuffer` class).

Here are the main changes in this commit:

- It changes the 'NcpUart` to adopt the `NcpFrameBuffer` for storing the
  outbound frames. This allows multiple frames to be queued for tx.

- `NcpUart` is changed so that the outgoing frames are encoded and
  sent over to Uart in smaller chunks. This helps reduce the required
  buffer size for storing the encoded outbound uart data.

- The spinel command handler methods in `NcpBase` are modified to return
  ThreadError status to indicate success or failure (e.g., when there is no
  buffer space for a response frame).

- If the response to a spinel command cannot be sent (no buffer space) the
  `NcpBase` remembers the set of TIDs (transaction ids) of such commands
  so to reply later with error status `SPINEL_STATUS_NOMEM` when buffer
  space becomes available. This ensures that spinel commands will get
  a response even in case of full buffer.

- The `NcpSpi` class is modified to address the changes from `NcpBase` but
  this commit does not change the buffer model for the `NcpSpi`. It adds
  `spi-stubs.c` to enable building the ncp app with spi feature under
  posix platform.
This commit is contained in:
Abtin Keshavarzian
2016-08-05 18:06:06 -07:00
committed by Jonathan Hui
parent 90eac68ff5
commit 0ab0c0da7b
10 changed files with 1428 additions and 1224 deletions
+6
View File
@@ -46,6 +46,12 @@ libopenthread_posix_a_SOURCES = \
uart.c \
$(NULL)
if OPENTHREAD_ENABLE_NCP_SPI
libopenthread_posix_a_SOURCES += \
spi-stubs.c \
$(NULL)
endif
noinst_HEADERS = \
platform-posix.h \
$(NULL)
+73
View File
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <platform/uart.h>
#include <platform/spi-slave.h>
// Spi-slave stubs
ThreadError otPlatSpiSlaveEnable(
otPlatSpiSlaveTransactionCompleteCallback aCallback,
void *aContext
)
{
fprintf(stderr, "\nNo SPI support for posix platform.");
exit(0);
return kThreadError_NotImplemented;
}
void otPlatSpiSlaveDisable(void)
{
}
ThreadError otPlatSpiSlavePrepareTransaction(
uint8_t *anOutputBuf,
uint16_t anOutputBufLen,
uint8_t *anInputBuf,
uint16_t anInputBufLen,
bool aRequestTransactionFlag
)
{
return kThreadError_NotImplemented;
}
// Uart
void otPlatUartSendDone(void)
{
}
void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
{
(void)aBuf;
(void)aBufLength;
}