Skip to content

Commit

Permalink
Update platform header
Browse files Browse the repository at this point in the history
  • Loading branch information
chinglee-iot committed May 9, 2024
1 parent 71d6f60 commit 97b3628
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 41 deletions.
18 changes: 9 additions & 9 deletions source/cellular_pkthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static CellularPktStatus_t _convertAndQueueRespPacket( CellularContext_t * pCont
}

/* Notify calling thread, Not blocking immediately comes back if the queue is full. */
if( xQueueSend( pContext->pktRespQueue, ( void * ) &pktStatus, ( TickType_t ) 0 ) != pdPASS )
if( PlatformQueue_Send( pContext->pktRespQueue, ( void * ) &pktStatus, ( PlatformTickType_t ) 0 ) != platformPASS )
{
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
LogError( ( "_convertAndQueueRespPacket: Got a response when the Resp Q is full!!" ) );
Expand Down Expand Up @@ -203,7 +203,7 @@ static CellularPktStatus_t _Cellular_AtcmdRequestTimeoutWithCallbackRaw( Cellula
{
CellularPktStatus_t respCode = CELLULAR_PKT_STATUS_OK;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
BaseType_t qRet = pdFALSE;
PlatformBaseType_t qRet = platformFALSE;

if( atReq.pAtCmd == NULL )
{
Expand Down Expand Up @@ -231,9 +231,9 @@ static CellularPktStatus_t _Cellular_AtcmdRequestTimeoutWithCallbackRaw( Cellula
else
{
/* Wait for a response. */
qRet = xQueueReceive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMS ) );
qRet = PlatformQueue_Receive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMS ) );

if( qRet == pdTRUE )
if( qRet == platformTRUE )
{
pktStatus = ( CellularPktStatus_t ) respCode;

Expand Down Expand Up @@ -270,7 +270,7 @@ static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContex
{
CellularPktStatus_t respCode = CELLULAR_PKT_STATUS_OK;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
BaseType_t qStatus = pdFALSE;
PlatformBaseType_t qStatus = platformFALSE;
uint32_t sendEndPatternLen = 0U;

if( ( dataReq.pData == NULL ) || ( dataReq.pSentDataLength == NULL ) )
Expand Down Expand Up @@ -312,9 +312,9 @@ static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContex
/* Wait for a response. */
if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
qStatus = xQueueReceive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMs ) );
qStatus = PlatformQueue_Receive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMs ) );

if( qStatus == pdTRUE )
if( qStatus == platformTRUE )
{
pktStatus = ( CellularPktStatus_t ) respCode;

Expand Down Expand Up @@ -509,7 +509,7 @@ void _Cellular_PktHandlerCleanup( CellularContext_t * pContext )
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
/* This is platform dependent api. */

( void ) vQueueDelete( pContext->pktRespQueue );
( void ) PlatformQueue_Delete( pContext->pktRespQueue );
pContext->pktRespQueue = NULL;
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
Expand Down Expand Up @@ -782,7 +782,7 @@ CellularPktStatus_t _Cellular_PktHandlerInit( CellularContext_t * pContext )
if( pContext != NULL )
{
/* Create the response queue which is used to post responses to the sender. */
pContext->pktRespQueue = xQueueCreate( 1, ( uint32_t ) sizeof( CellularPktStatus_t ) );
pContext->pktRespQueue = PlatformQueue_Create( 1, ( uint32_t ) sizeof( CellularPktStatus_t ) );

if( pContext->pktRespQueue == NULL )
{
Expand Down
58 changes: 29 additions & 29 deletions source/cellular_pktio.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static CellularCommInterfaceError_t _Cellular_PktRxCallBack( void * pUserData,
CellularCommInterfaceHandle_t commInterfaceHandle )
{
const CellularContext_t * pContext = ( CellularContext_t * ) pUserData;
BaseType_t xHigherPriorityTaskWoken = pdFALSE, xResult = pdFALSE;
PlatformBaseType_t xHigherPriorityTaskWoken = platformFALSE, xResult = platformFALSE;
CellularCommInterfaceError_t retComm = IOT_COMM_INTERFACE_SUCCESS;

( void ) commInterfaceHandle; /* Comm if is not used in this function. */
Expand All @@ -532,13 +532,13 @@ static CellularCommInterfaceError_t _Cellular_PktRxCallBack( void * pUserData,
}
else
{
xResult = ( BaseType_t ) PlatformEventGroup_SetBitsFromISR( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( EventBits_t ) PKTIO_EVT_MASK_RX_DATA,
&xHigherPriorityTaskWoken );
xResult = PlatformEventGroup_SetBitsFromISR( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( PlatformEventBits_t ) PKTIO_EVT_MASK_RX_DATA,
&xHigherPriorityTaskWoken );

if( xResult == pdPASS )
if( xResult == platformPASS )
{
if( xHigherPriorityTaskWoken == pdTRUE )
if( xHigherPriorityTaskWoken == platformTRUE )
{
retComm = IOT_COMM_INTERFACE_SUCCESS;
}
Expand Down Expand Up @@ -1201,7 +1201,7 @@ static uint32_t _handleRxDataEvent( CellularContext_t * pContext )
static void _pktioReadThread( void * pUserData )
{
CellularContext_t * pContext = ( CellularContext_t * ) pUserData;
PlatformEventGroup_EventBits uxBits = 0;
PlatformEventBits_t uxBits = 0;
uint32_t bytesRead = 0U;

/* Open main communication port. */
Expand All @@ -1210,24 +1210,24 @@ static void _pktioReadThread( void * pUserData )
&( pContext->hPktioCommIntf ) ) == IOT_COMM_INTERFACE_SUCCESS ) )
{
/* Send thread started event. */
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( EventBits_t ) PKTIO_EVT_MASK_STARTED );
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( PlatformEventBits_t ) PKTIO_EVT_MASK_STARTED );

do
{
/* Wait events for abort thread or rx data available. */
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORT | ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_RX_DATA ),
pdTRUE,
pdFALSE,
portMAX_DELAY );
uxBits = PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORT | ( PlatformEventBits_t ) PKTIO_EVT_MASK_RX_DATA ),
platformTRUE,
platformFALSE,
platformMAX_DELAY );

if( ( uxBits & ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORT ) != 0U )
if( ( uxBits & ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORT ) != 0U )
{
LogDebug( ( "Abort received, cleaning up!" ) );
FREE_AT_RESPONSE_AND_SET_NULL( pContext->pAtCmdResp );
break;
}
else if( ( uxBits & ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_RX_DATA ) != 0U )
else if( ( uxBits & ( PlatformEventBits_t ) PKTIO_EVT_MASK_RX_DATA ) != 0U )
{
/* Keep Reading until there is no more bytes in comm interface. */
do
Expand All @@ -1250,7 +1250,7 @@ static void _pktioReadThread( void * pUserData )
LogError( ( "Comm port open failed" ) );
}

( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( EventBits_t ) PKTIO_EVT_MASK_ABORTED );
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED );

/* Call the shutdown callback if it is defined. */
if( pContext->pPktioShutdownCB != NULL )
Expand All @@ -1263,15 +1263,15 @@ static void _pktioReadThread( void * pUserData )

static void _PktioInitProcessReadThreadStatus( CellularContext_t * pContext )
{
PlatformEventGroup_EventBits uxBits = 0;
PlatformEventBits_t uxBits = 0;

uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_STARTED | ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORTED ),
pdTRUE,
pdFALSE,
( ( PlatformTickType ) ~( 0UL ) ) );
uxBits = ( PlatformEventBits_t ) PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_STARTED | ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED ),
platformTRUE,
platformFALSE,
( ( PlatformTickType_t ) ~( 0UL ) ) );

if( ( uxBits & ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORTED )
if( ( uxBits & ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED )
{
pContext->bPktioUp = true;
}
Expand Down Expand Up @@ -1367,7 +1367,7 @@ CellularPktStatus_t _Cellular_PktioInit( CellularContext_t * pContext,
{
pContext->pPktioHandlepktCB = handlePacketCb;
( void ) PlatformEventGroup_ClearBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
( ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ALL_EVENTS ) );
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_ALL_EVENTS ) );

/* Create the Read thread. */
status = Platform_CreateDetachedThread( _pktioReadThread,
Expand Down Expand Up @@ -1516,19 +1516,19 @@ uint32_t _Cellular_PktioSendData( CellularContext_t * pContext,

void _Cellular_PktioShutdown( CellularContext_t * pContext )
{
PlatformEventGroup_EventBits uxBits = 0;
PlatformEventBits_t uxBits = 0;

if( ( pContext != NULL ) && ( pContext->bPktioUp ) )
{
if( pContext->pPktioCommEvent != NULL )
{
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( EventBits_t ) PKTIO_EVT_MASK_ABORT );
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORT );
uxBits = ( PlatformEventBits_t ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );

while( ( PlatformEventGroup_EventBits ) ( uxBits & PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventGroup_EventBits ) ( PKTIO_EVT_MASK_ABORTED ) )
while( ( PlatformEventBits_t ) ( uxBits & PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventBits_t ) ( PKTIO_EVT_MASK_ABORTED ) )
{
Platform_Delay( PKTIO_SHUTDOWN_WAIT_INTERVAL_MS );
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
uxBits = ( PlatformEventBits_t ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
}

( void ) PlatformEventGroup_Delete( pContext->pPktioCommEvent );
Expand Down
29 changes: 29 additions & 0 deletions source/include/cellular_config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,35 @@
#define CELLULAR_CONFIG_USE_CCID_COMMAND 1
#endif

/**
* @brief Use FreeRTOS platform function for backward compatibility.<br>
*
* Define FreeRTOS platform function for cellular interface backward compatibility with versoin eariler
* than v1.4.0.
*
* <b>Possible values:</b>`0 or 1`<br>
* <b>Default value (if undefined):</b> 1
*/
#ifndef CELLULAR_CONFIG_PLATFORM_FREERTOS
#define CELLULAR_CONFIG_PLATFORM_FREERTOS 1
#endif

#if CELLULAR_CONFIG_PLATFORM_FREERTOS
#define PlatformQueueHandle_t QueueHandle_t
#define PlatformEventBits_t EventBits_t
#define PlatformBaseType_t BaseType_t
#define PlatformTickType_t TickType_t
#define platformTRUE pdTRUE
#define platformFALSE pdFALSE
#define platformPASS pdPASS
#define platformFAIL pdFAIL
#define platformMAX_DELAY portMAX_DELAY
#define PlatformQueue_Create xQueueCreate
#define PlatformQueue_Send xQueueSend
#define PlatformQueue_Receive xQueueReceive
#define PlatformQueue_Delete vQueueDelete
#endif /* if CELLULAR_CONFIG_PLATFORM_FREERTOS */

/**
* @brief Macro that is called in the cellular library for logging "Error" level
* messages.
Expand Down
4 changes: 3 additions & 1 deletion source/include/private/cellular_common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
/* *INDENT-ON* */

/* Cellular includes. */
#include "cellular_config_defaults.h"
#include "cellular_platform.h"

#include "cellular_pkthandler_internal.h"
#include "cellular_at_core.h"
#include "cellular_pktio_internal.h"
Expand Down Expand Up @@ -119,7 +121,7 @@ struct CellularContext
/* Packet handler. */
PlatformMutex_t pktRequestMutex; /**< The mutex for sending request. */
PlatformMutex_t PktRespMutex; /**< The mutex for parsing the response from modem. */
QueueHandle_t pktRespQueue; /**< Message queue to send/receive response. */
PlatformQueueHandle_t pktRespQueue; /**< Message queue to send/receive response. */
CellularATCommandResponseReceivedCallback_t pktRespCB; /**< Callback used to inform about the response of an AT command sent using Cellular_ATCommandRaw API. */
CellularATCommandDataPrefixCallback_t pktDataPrefixCB; /**< Data prefix callback function for socket receive function. */
void * pDataPrefixCBContext; /**< The pCallbackContext passed to CellularATCommandDataPrefixCallback_t. */
Expand Down
5 changes: 3 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set( CELLULAR_COMMON_INCLUDE_DIRS ${CELLULAR_INCLUDE_DIRS}/common )
set( CELLULAR_COMMON_INCLUDE_PRIVATE_DIRS ${CELLULAR_INCLUDE_DIRS}/private )
set( CELLULAR_INTERFACE_INCLUDE_DIRS ${CELLULAR_COMMON_SOURCE_DIRS}/interface )
set( CELLULAR_TEST_DIRS ${MODULE_ROOT_DIR}/test/unit-test )
set( CELLULAR_COVERITY_DIRS ${MODULE_ROOT_DIR}/test/coverity )

if( COV_ANALYSIS )
# Target for Coverity analysis that builds the library.
Expand All @@ -60,7 +61,7 @@ if( COV_ANALYSIS )
target_compile_definitions( coverity_analysis PUBLIC CELLULAR_DO_NOT_USE_CUSTOM_CONFIG=1 )

# Cellular include path.
target_include_directories( coverity_analysis PUBLIC ${CELLULAR_COMMON_INCLUDE_DIRS} ${CELLULAR_INCLUDE_DIRS} ${CELLULAR_INTERFACE_INCLUDE_DIRS} ${CELLULAR_TEST_DIRS} )
target_include_directories( coverity_analysis PUBLIC ${CELLULAR_COMMON_INCLUDE_DIRS} ${CELLULAR_INCLUDE_DIRS} ${CELLULAR_INTERFACE_INCLUDE_DIRS} ${CELLULAR_COVERITY_DIRS} )

# Cellular private include path.
target_include_directories( coverity_analysis PRIVATE ${CELLULAR_COMMON_INCLUDE_PRIVATE_DIRS} )
Expand All @@ -73,7 +74,7 @@ if( COV_ANALYSIS )
add_custom_target( fix_source ALL
COMMAND sed -i -b -e 's/pdFALSE/pdFAIL/g' -e 's/pdTRUE/pdPASS/g' ${CELLULAR_COMMON_SOURCE})

add_dependencies( coverity_analysis fix_source )
# add_dependencies( coverity_analysis fix_source )
endif()

# ==================================== Test Configuration ========================================
Expand Down
Loading

0 comments on commit 97b3628

Please sign in to comment.