Skip to content

Commit

Permalink
Revert "[nxp noup][platform][common] Adding platform common code"
Browse files Browse the repository at this point in the history
This reverts commit a5b8480.

Signed-off-by: Dina Benamar <[email protected]>
  • Loading branch information
dinabenamar committed Feb 26, 2024
1 parent 892b18b commit e6d93ac
Show file tree
Hide file tree
Showing 32 changed files with 243 additions and 2,192 deletions.
2 changes: 1 addition & 1 deletion src/credentials/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ chip_test_suite_using_nltest("tests") {
]

# DUTVectors test requires <dirent.h> which is not supported on all platforms
if (chip_device_platform != "openiotsdk" && chip_device_platform!="nxp") {
if (chip_device_platform != "openiotsdk") {
test_sources += [ "TestCommissionerDUTVectors.cpp" ]
}

Expand Down
136 changes: 55 additions & 81 deletions src/lib/shell/streamer_nxp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,24 @@
* Source implementation of an input / output stream for NXP targets.
*/


/* -------------------------------------------------------------------------- */
/* Includes */
/* -------------------------------------------------------------------------- */

#include <lib/shell/Engine.h>
#include <lib/shell/streamer.h>

#include <stdio.h>
#include <string.h>

#include "board.h"
#include "fsl_clock.h"
#include "fsl_component_serial_manager.h"
#include "fsl_os_abstraction.h"
#include "fsl_clock.h"

#if CHIP_ENABLE_OPENTHREAD
#include "openthread-system.h"
#endif


/* -------------------------------------------------------------------------- */
/* Private macros */
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -90,8 +87,8 @@ typedef serial_port_uart_config_t streamer_serial_port_uart_config_t;
/* Private prototypes */
/* -------------------------------------------------------------------------- */

static void Uart_RxCallBack(void *pData, serial_manager_callback_message_t *message, serial_manager_status_t status);
static void Uart_TxCallBack(void *pBuffer, serial_manager_callback_message_t *message, serial_manager_status_t status);
static void Uart_RxCallBack(void * pData, serial_manager_callback_message_t * message, serial_manager_status_t status);
static void Uart_TxCallBack(void * pBuffer, serial_manager_callback_message_t * message, serial_manager_status_t status);

/* -------------------------------------------------------------------------- */
/* Private memory */
Expand All @@ -101,22 +98,21 @@ static SERIAL_MANAGER_HANDLE_DEFINE(streamerSerialHandle);
static SERIAL_MANAGER_WRITE_HANDLE_DEFINE(streamerSerialWriteHandle);
static SERIAL_MANAGER_READ_HANDLE_DEFINE(streamerSerialReadHandle);
static volatile int txCount = 0;
volatile static bool readDone = true;

static streamer_serial_port_uart_config_t uartConfig = {
.clockRate = 0,
.baudRate = BOARD_DEBUG_UART_BAUDRATE,
.parityMode = kSerialManager_UartParityDisabled,
.stopBitCount = kSerialManager_UartOneStopBit,
.enableRx = 1,
.enableTx = 1,
.enableRxRTS = 0,
.enableTxCTS = 0,
.instance = BOARD_APP_UART_INSTANCE,
static bool readDone = true;

static streamer_serial_port_uart_config_t uartConfig = { .clockRate = BOARD_APP_UART_CLK_FREQ,
.baudRate = BOARD_DEBUG_UART_BAUDRATE,
.parityMode = kSerialManager_UartParityDisabled,
.stopBitCount = kSerialManager_UartOneStopBit,
.enableRx = 1,
.enableTx = 1,
.enableRxRTS = 0,
.enableTxCTS = 0,
.instance = BOARD_APP_UART_INSTANCE,
#if STREAMER_UART_USE_DMA
.dma_instance = 0,
.rx_channel = 1,
.tx_channel = 0
.dma_instance = 0,
.rx_channel = 1,
.tx_channel = 0
#endif
};

Expand All @@ -125,16 +121,14 @@ static const serial_manager_config_t s_serialManagerConfig = {
.ringBuffer = &s_ringBuffer[0],
.ringBufferSize = STREAMER_UART_SERIAL_MANAGER_RING_BUFFER_SIZE,
#if STREAMER_UART_USE_DMA
.type = kSerialPort_UartDma,
.type = kSerialPort_UartDma,
#else
.type = BOARD_DEBUG_UART_TYPE,
.type = BOARD_DEBUG_UART_TYPE,
#endif
.blockType = kSerialManager_NonBlocking,
.portConfig = (serial_port_uart_config_t *)&uartConfig,
.blockType = kSerialManager_NonBlocking,
.portConfig = (serial_port_uart_config_t *) &uartConfig,
};

OSA_MUTEX_HANDLE_DEFINE(streamerMutex);

/* -------------------------------------------------------------------------- */
/* Public functions */
/* -------------------------------------------------------------------------- */
Expand All @@ -152,8 +146,6 @@ int streamer_nxp_init(streamer_t * streamer)
BOARD_CLIAttachClk();
#endif

uartConfig.clockRate = BOARD_APP_UART_CLK_FREQ;

#if STREAMER_UART_USE_DMA
dma_channel_mux_configure_t dma_channel_mux;
dma_channel_mux.dma_dmamux_configure.dma_tx_channel_mux = kDmaRequestLPUART1Tx;
Expand All @@ -169,61 +161,53 @@ int streamer_nxp_init(streamer_t * streamer)

do
{
if (SerialManager_Init((serial_handle_t)streamerSerialHandle, &s_serialManagerConfig) !=
kStatus_SerialManager_Success)
if (SerialManager_Init((serial_handle_t) streamerSerialHandle, &s_serialManagerConfig) != kStatus_SerialManager_Success)
break;
if (SerialManager_OpenWriteHandle((serial_handle_t)streamerSerialHandle,
(serial_write_handle_t)streamerSerialWriteHandle) !=
kStatus_SerialManager_Success)
if (SerialManager_OpenWriteHandle((serial_handle_t) streamerSerialHandle,
(serial_write_handle_t) streamerSerialWriteHandle) != kStatus_SerialManager_Success)
break;
if (SerialManager_OpenReadHandle((serial_handle_t)streamerSerialHandle,
(serial_read_handle_t)streamerSerialReadHandle) != kStatus_SerialManager_Success)
if (SerialManager_OpenReadHandle((serial_handle_t) streamerSerialHandle, (serial_read_handle_t) streamerSerialReadHandle) !=
kStatus_SerialManager_Success)
break;
if (SerialManager_InstallRxCallback((serial_read_handle_t)streamerSerialReadHandle, Uart_RxCallBack, NULL) !=
if (SerialManager_InstallRxCallback((serial_read_handle_t) streamerSerialReadHandle, Uart_RxCallBack, NULL) !=
kStatus_SerialManager_Success)
break;
if (SerialManager_InstallTxCallback((serial_write_handle_t)streamerSerialWriteHandle, Uart_TxCallBack, NULL) !=
if (SerialManager_InstallTxCallback((serial_write_handle_t) streamerSerialWriteHandle, Uart_TxCallBack, NULL) !=
kStatus_SerialManager_Success)
break;
status = kStatus_SerialManager_Success;
} while (0);

OSA_InterruptEnable();

osa_status_t status_osa = OSA_MutexCreate((osa_mutex_handle_t)streamerMutex);
assert(status_osa == KOSA_StatusSuccess);

return status;
}

ssize_t streamer_nxp_read(streamer_t * streamer, char * buffer, size_t length)
{
uint32_t bytesRead = 0;
uint32_t bytesRead = 0;
serial_manager_status_t status = kStatus_SerialManager_Success;

if (length != 0)
{
/**
* If the reading process is over,
/**
* If the reading process is over,
* let CLI Task enter blocked state until notification
**/
**/
if (readDone)
{
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
readDone = false;
}

status = SerialManager_TryRead((serial_read_handle_t)streamerSerialReadHandle, (uint8_t *)buffer, length, &bytesRead);
status = SerialManager_TryRead((serial_read_handle_t) streamerSerialReadHandle, (uint8_t *) buffer, length, &bytesRead);
assert(status != kStatus_SerialManager_Error);

/**
* In certain cases such as a copy-paste of multiple commands, we may encounter '\n' or '\r' caracters
* although the buffer is not empty yet, so the reading process should be considered done only when the
* bytesRead return null,
* this is to ensure that all commands are processed before blocking the CLI task
*
**/
if (bytesRead == 0)
* If we are at the end of the line or the buffer is empty,
* consider the reading process done
**/
if ((buffer[length - 1] == '\n') || (buffer[length - 1] == '\r') || (bytesRead == 0))
{
readDone = true;
}
Expand All @@ -234,35 +218,25 @@ ssize_t streamer_nxp_read(streamer_t * streamer, char * buffer, size_t length)

ssize_t streamer_nxp_write(streamer_t * streamer, const char * buffer, size_t length)
{
uint32_t intMask;
serial_manager_status_t status = kStatus_SerialManager_Success;
size_t len = 0;

/* Mutex lock to ensure the streamer write is accessed by only one task at a time */
osa_status_t status_osa = OSA_MutexLock(streamerMutex, osaWaitForever_c);

//If length is 0 there will be an assert in Serial Manager. Some OT functions output 0 bytes, for example
//in SrpServer::Process<Cmd("service")> -> OutputLine(hasSubType ? "" : "(null)");
if (length > 0)
uint32_t intMask;
serial_manager_status_t status = kStatus_SerialManager_Error;
size_t len = 0;

intMask = DisableGlobalIRQ();
txCount++;
status = SerialManager_WriteNonBlocking((serial_write_handle_t) streamerSerialWriteHandle,
(uint8_t *) (const_cast<char *>(buffer)), (uint32_t) length);
EnableGlobalIRQ(intMask);
if (status == kStatus_SerialManager_Success)
{
intMask = DisableGlobalIRQ();
txCount++;
status = SerialManager_WriteNonBlocking((serial_write_handle_t)streamerSerialWriteHandle, (uint8_t *)buffer, (uint32_t) length);
EnableGlobalIRQ(intMask);
if (status == kStatus_SerialManager_Success)
{
len = length;
}

/* Wait for the serial manager task to empty the TX buffer */
while (txCount)
{
OSA_TimeDelay(STREAMER_UART_FLUSH_DELAY_MS);
}
len = length;
}

status_osa = OSA_MutexUnlock(streamerMutex);
assert(status_osa == KOSA_StatusSuccess);
/* Wait for the serial manager task to empty the TX buffer */
while (txCount)
{
OSA_TimeDelay(STREAMER_UART_FLUSH_DELAY_MS);
}

return len;
}
Expand All @@ -286,7 +260,7 @@ streamer_t * streamer_get(void)
/* -------------------------------------------------------------------------- */
extern TaskHandle_t CONSUMER_TASK_HANDLE;

static void Uart_RxCallBack(void *pData, serial_manager_callback_message_t *message, serial_manager_status_t status)
static void Uart_RxCallBack(void * pData, serial_manager_callback_message_t * message, serial_manager_status_t status)
{
if (CONSUMER_TASK_HANDLE != NULL)
{
Expand All @@ -295,7 +269,7 @@ static void Uart_RxCallBack(void *pData, serial_manager_callback_message_t *mess
}
}

static void Uart_TxCallBack(void *pBuffer, serial_manager_callback_message_t *message, serial_manager_status_t status)
static void Uart_TxCallBack(void * pBuffer, serial_manager_callback_message_t * message, serial_manager_status_t status)
{
txCount--;
}
2 changes: 1 addition & 1 deletion src/messaging/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ chip_test_suite_using_nltest("tests") {
]

if (chip_device_platform != "esp32" && chip_device_platform != "mbed" &&
chip_device_platform != "nrfconnect" && chip_device_platform != "nxp") {
chip_device_platform != "nrfconnect") {
test_sources += [ "TestExchangeHolder.cpp" ]
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#endif // CHIP_CONFIG_ERROR_CLASS

#ifndef CHIP_CONFIG_SHA256_CONTEXT_SIZE
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE (sizeof(unsigned int) * 98)
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE (sizeof(unsigned int) * 76)
#endif // CHIP_CONFIG_SHA256_CONTEXT_SIZE

// ==================== Security Adaptations ====================
Expand Down
Loading

0 comments on commit e6d93ac

Please sign in to comment.