Skip to content

Commit aff376d

Browse files
authored
Update cellular platform header APIs (#166)
* Move the following FreeRTOS functions and data structure to platform and add CELLULAR_CONFIG_PLATFORM_FREERTOS for backward compatibility. Default to 1 for backward compatibility. * Add CELLULAR_CONFIG_ASSERT config. Default value is configASSERT * Remove critical section dependency. The common layer function is not thread safe. Thread safe should be handled by application.
1 parent 6486160 commit aff376d

9 files changed

Lines changed: 642 additions & 103 deletions

File tree

docs/doxygen/include/size_table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<tr>
3131
<td>cellular_common.c</td>
3232
<td><center>1.7K</center></td>
33-
<td><center>1.6K</center></td>
33+
<td><center>1.5K</center></td>
3434
</tr>
3535
<tr>
3636
<td>cellular_pkthandler.c</td>
@@ -45,6 +45,6 @@
4545
<tr>
4646
<td><b>Total estimates</b></td>
4747
<td><b><center>15.1K</center></b></td>
48-
<td><b><center>13.8K</center></b></td>
48+
<td><b><center>13.7K</center></b></td>
4949
</tr>
5050
</table>

source/cellular_3gpp_api.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ static CellularError_t queryNetworkStatus( CellularContext_t * pContext,
863863
CellularNetworkRegType_t recvRegType = regType;
864864
CellularAtReq_t atReqGetResult = { 0 };
865865

866-
configASSERT( pContext != NULL );
866+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
867867
atReqGetResult.pAtCmd = pCommand;
868868
atReqGetResult.atCmdType = CELLULAR_AT_MULTI_WITH_PREFIX;
869869
atReqGetResult.pAtRspPrefix = pPrefix;
@@ -1449,7 +1449,7 @@ static CellularError_t atcmdQueryRegStatus( CellularContext_t * pContext,
14491449
const cellularAtData_t * pLibAtData = NULL;
14501450
CellularNetworkRegistrationStatus_t psRegStatus = REGISTRATION_STATUS_UNKNOWN;
14511451

1452-
configASSERT( pContext != NULL );
1452+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
14531453

14541454
cellularStatus = queryNetworkStatus( pContext, "AT+CREG?", "+CREG", CELLULAR_REG_TYPE_CREG );
14551455

@@ -2078,7 +2078,7 @@ CellularError_t Cellular_CommonGetIPAddress( CellularHandle_t cellularHandle,
20782078

20792079
void _Cellular_DestroyAtDataMutex( CellularContext_t * pContext )
20802080
{
2081-
configASSERT( pContext != NULL );
2081+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
20822082

20832083
PlatformMutex_Destroy( &( pContext->libAtDataMutex ) );
20842084
}
@@ -2089,7 +2089,7 @@ bool _Cellular_CreateAtDataMutex( CellularContext_t * pContext )
20892089
{
20902090
bool status = false;
20912091

2092-
configASSERT( pContext != NULL );
2092+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
20932093

20942094
status = PlatformMutex_Create( &( pContext->libAtDataMutex ), false );
20952095

@@ -2100,7 +2100,7 @@ bool _Cellular_CreateAtDataMutex( CellularContext_t * pContext )
21002100

21012101
void _Cellular_LockAtDataMutex( CellularContext_t * pContext )
21022102
{
2103-
configASSERT( pContext != NULL );
2103+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
21042104

21052105
PlatformMutex_Lock( &( pContext->libAtDataMutex ) );
21062106
}
@@ -2109,7 +2109,7 @@ void _Cellular_LockAtDataMutex( CellularContext_t * pContext )
21092109

21102110
void _Cellular_UnlockAtDataMutex( CellularContext_t * pContext )
21112111
{
2112-
configASSERT( pContext != NULL );
2112+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
21132113

21142114
PlatformMutex_Unlock( &( pContext->libAtDataMutex ) );
21152115
}
@@ -2123,7 +2123,7 @@ void _Cellular_InitAtData( CellularContext_t * pContext,
21232123
{
21242124
cellularAtData_t * pLibAtData = NULL;
21252125

2126-
configASSERT( pContext != NULL );
2126+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
21272127

21282128
pLibAtData = &( pContext->libAtData );
21292129

source/cellular_common.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ static CellularContext_t * _Cellular_AllocContext( void )
118118
CellularContext_t * pContext = NULL;
119119
uint8_t i = 0;
120120

121-
taskENTER_CRITICAL();
122-
123121
for( i = 0; i < CELLULAR_CONTEXT_MAX; i++ )
124122
{
125123
if( cellularContextTable[ i ] == NULL )
@@ -144,8 +142,6 @@ static CellularContext_t * _Cellular_AllocContext( void )
144142
}
145143
}
146144

147-
taskEXIT_CRITICAL();
148-
149145
return pContext;
150146
}
151147

@@ -155,8 +151,6 @@ static void _Cellular_FreeContext( CellularContext_t * pContext )
155151
{
156152
uint8_t i = 0;
157153

158-
taskENTER_CRITICAL();
159-
160154
for( i = 0; i < CELLULAR_CONTEXT_MAX; i++ )
161155
{
162156
if( cellularContextTable[ i ] == pContext )
@@ -170,8 +164,6 @@ static void _Cellular_FreeContext( CellularContext_t * pContext )
170164
break;
171165
}
172166
}
173-
174-
taskEXIT_CRITICAL();
175167
}
176168

177169
/*-----------------------------------------------------------*/
@@ -188,7 +180,7 @@ static CellularError_t libOpen( CellularContext_t * pContext )
188180
CellularError_t cellularStatus = CELLULAR_SUCCESS;
189181
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
190182

191-
configASSERT( pContext != NULL );
183+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
192184

193185
PlatformMutex_Lock( &( pContext->libStatusMutex ) );
194186

@@ -235,7 +227,7 @@ static void libClose( CellularContext_t * pContext )
235227
bool bOpened = false;
236228
uint8_t i = 0;
237229

238-
configASSERT( pContext != NULL );
230+
CELLULAR_CONFIG_ASSERT( pContext != NULL );
239231

240232
PlatformMutex_Lock( &( pContext->libStatusMutex ) );
241233
bOpened = pContext->bLibOpened;
@@ -538,8 +530,6 @@ CellularError_t _Cellular_CreateSocketData( CellularContext_t * pContext,
538530
CellularSocketContext_t * pSocketData = NULL;
539531
uint8_t socketId = 0;
540532

541-
taskENTER_CRITICAL();
542-
543533
for( socketId = 0; socketId < CELLULAR_NUM_SOCKET_MAX; socketId++ )
544534
{
545535
if( pContext->pSocketData[ socketId ] == NULL )
@@ -570,8 +560,6 @@ CellularError_t _Cellular_CreateSocketData( CellularContext_t * pContext,
570560
}
571561
}
572562

573-
taskEXIT_CRITICAL();
574-
575563
if( cellularStatus == CELLULAR_NO_MEMORY )
576564
{
577565
LogError( ( "_Cellular_CreateSocket, Out of memory" ) );

source/cellular_pkthandler.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static CellularPktStatus_t _convertAndQueueRespPacket( CellularContext_t * pCont
107107
}
108108

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

208208
if( atReq.pAtCmd == NULL )
209209
{
@@ -231,9 +231,9 @@ static CellularPktStatus_t _Cellular_AtcmdRequestTimeoutWithCallbackRaw( Cellula
231231
else
232232
{
233233
/* Wait for a response. */
234-
qRet = xQueueReceive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMS ) );
234+
qRet = PlatformQueue_Receive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMS ) );
235235

236-
if( qRet == pdTRUE )
236+
if( qRet == platformTRUE )
237237
{
238238
pktStatus = ( CellularPktStatus_t ) respCode;
239239

@@ -270,7 +270,7 @@ static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContex
270270
{
271271
CellularPktStatus_t respCode = CELLULAR_PKT_STATUS_OK;
272272
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
273-
BaseType_t qStatus = pdFALSE;
273+
PlatformBaseType_t qStatus = platformFALSE;
274274
uint32_t sendEndPatternLen = 0U;
275275

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

317-
if( qStatus == pdTRUE )
317+
if( qStatus == platformTRUE )
318318
{
319319
pktStatus = ( CellularPktStatus_t ) respCode;
320320

@@ -509,7 +509,7 @@ void _Cellular_PktHandlerCleanup( CellularContext_t * pContext )
509509
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
510510
/* This is platform dependent api. */
511511

512-
( void ) vQueueDelete( pContext->pktRespQueue );
512+
( void ) PlatformQueue_Delete( pContext->pktRespQueue );
513513
pContext->pktRespQueue = NULL;
514514
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
515515
}
@@ -782,7 +782,7 @@ CellularPktStatus_t _Cellular_PktHandlerInit( CellularContext_t * pContext )
782782
if( pContext != NULL )
783783
{
784784
/* Create the response queue which is used to post responses to the sender. */
785-
pContext->pktRespQueue = xQueueCreate( 1, ( uint32_t ) sizeof( CellularPktStatus_t ) );
785+
pContext->pktRespQueue = PlatformQueue_Create( 1, ( uint32_t ) sizeof( CellularPktStatus_t ) );
786786

787787
if( pContext->pktRespQueue == NULL )
788788
{

source/cellular_pktio.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void _saveData( char * pLine,
151151
LogDebug( ( "_saveData : Save data %p with length %u", pLine, ( unsigned int ) dataLen ) );
152152

153153
pNew = ( CellularATCommandLine_t * ) Platform_Malloc( sizeof( CellularATCommandLine_t ) );
154-
configASSERT( ( pNew != NULL ) );
154+
CELLULAR_CONFIG_ASSERT( ( pNew != NULL ) );
155155

156156
/* Reuse the pktio buffer instead of allocate. */
157157
pNew->pLine = pLine;
@@ -287,7 +287,7 @@ static CellularATCommandResponse_t * _Cellular_AtResponseNew( void )
287287
CellularATCommandResponse_t * pNew = NULL;
288288

289289
pNew = ( CellularATCommandResponse_t * ) Platform_Malloc( sizeof( CellularATCommandResponse_t ) );
290-
configASSERT( ( pNew != NULL ) );
290+
CELLULAR_CONFIG_ASSERT( ( pNew != NULL ) );
291291

292292
( void ) memset( ( void * ) pNew, 0, sizeof( CellularATCommandResponse_t ) );
293293

@@ -520,7 +520,7 @@ static CellularCommInterfaceError_t _Cellular_PktRxCallBack( void * pUserData,
520520
CellularCommInterfaceHandle_t commInterfaceHandle )
521521
{
522522
const CellularContext_t * pContext = ( CellularContext_t * ) pUserData;
523-
BaseType_t xHigherPriorityTaskWoken = pdFALSE, xResult = pdFALSE;
523+
PlatformBaseType_t xHigherPriorityTaskWoken = platformFALSE, xResult = platformFALSE;
524524
CellularCommInterfaceError_t retComm = IOT_COMM_INTERFACE_SUCCESS;
525525

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

539-
if( xResult == pdPASS )
539+
if( xResult == platformPASS )
540540
{
541-
if( xHigherPriorityTaskWoken == pdTRUE )
541+
if( xHigherPriorityTaskWoken == platformTRUE )
542542
{
543543
retComm = IOT_COMM_INTERFACE_SUCCESS;
544544
}
@@ -1201,7 +1201,7 @@ static uint32_t _handleRxDataEvent( CellularContext_t * pContext )
12011201
static void _pktioReadThread( void * pUserData )
12021202
{
12031203
CellularContext_t * pContext = ( CellularContext_t * ) pUserData;
1204-
PlatformEventGroup_EventBits uxBits = 0;
1204+
PlatformEventBits_t uxBits = 0;
12051205
uint32_t bytesRead = 0U;
12061206

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

12151215
do
12161216
{
12171217
/* Wait events for abort thread or rx data available. */
1218-
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
1219-
( ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORT | ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_RX_DATA ),
1220-
pdTRUE,
1221-
pdFALSE,
1222-
portMAX_DELAY );
1218+
uxBits = PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
1219+
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORT | ( PlatformEventBits_t ) PKTIO_EVT_MASK_RX_DATA ),
1220+
platformTRUE,
1221+
platformFALSE,
1222+
platformMAX_DELAY );
12231223

1224-
if( ( uxBits & ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORT ) != 0U )
1224+
if( ( uxBits & ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORT ) != 0U )
12251225
{
12261226
LogDebug( ( "Abort received, cleaning up!" ) );
12271227
FREE_AT_RESPONSE_AND_SET_NULL( pContext->pAtCmdResp );
12281228
break;
12291229
}
1230-
else if( ( uxBits & ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_RX_DATA ) != 0U )
1230+
else if( ( uxBits & ( PlatformEventBits_t ) PKTIO_EVT_MASK_RX_DATA ) != 0U )
12311231
{
12321232
/* Keep Reading until there is no more bytes in comm interface. */
12331233
do
@@ -1250,7 +1250,7 @@ static void _pktioReadThread( void * pUserData )
12501250
LogError( ( "Comm port open failed" ) );
12511251
}
12521252

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

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

12641264
static void _PktioInitProcessReadThreadStatus( CellularContext_t * pContext )
12651265
{
1266-
PlatformEventGroup_EventBits uxBits = 0;
1266+
PlatformEventBits_t uxBits = 0;
12671267

1268-
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
1269-
( ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_STARTED | ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORTED ),
1270-
pdTRUE,
1271-
pdFALSE,
1272-
( ( PlatformTickType ) ~( 0UL ) ) );
1268+
uxBits = ( PlatformEventBits_t ) PlatformEventGroup_WaitBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
1269+
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_STARTED | ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED ),
1270+
platformTRUE,
1271+
platformFALSE,
1272+
( ( PlatformTickType_t ) ~( 0UL ) ) );
12731273

1274-
if( ( uxBits & ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ABORTED )
1274+
if( ( uxBits & ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORTED )
12751275
{
12761276
pContext->bPktioUp = true;
12771277
}
@@ -1367,7 +1367,7 @@ CellularPktStatus_t _Cellular_PktioInit( CellularContext_t * pContext,
13671367
{
13681368
pContext->pPktioHandlepktCB = handlePacketCb;
13691369
( void ) PlatformEventGroup_ClearBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent,
1370-
( ( PlatformEventGroup_EventBits ) PKTIO_EVT_MASK_ALL_EVENTS ) );
1370+
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_ALL_EVENTS ) );
13711371

13721372
/* Create the Read thread. */
13731373
status = Platform_CreateDetachedThread( _pktioReadThread,
@@ -1516,19 +1516,19 @@ uint32_t _Cellular_PktioSendData( CellularContext_t * pContext,
15161516

15171517
void _Cellular_PktioShutdown( CellularContext_t * pContext )
15181518
{
1519-
PlatformEventGroup_EventBits uxBits = 0;
1519+
PlatformEventBits_t uxBits = 0;
15201520

15211521
if( ( pContext != NULL ) && ( pContext->bPktioUp ) )
15221522
{
15231523
if( pContext->pPktioCommEvent != NULL )
15241524
{
1525-
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( EventBits_t ) PKTIO_EVT_MASK_ABORT );
1526-
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
1525+
( void ) PlatformEventGroup_SetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent, ( PlatformEventBits_t ) PKTIO_EVT_MASK_ABORT );
1526+
uxBits = ( PlatformEventBits_t ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
15271527

1528-
while( ( PlatformEventGroup_EventBits ) ( uxBits & PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventGroup_EventBits ) ( PKTIO_EVT_MASK_ABORTED ) )
1528+
while( ( PlatformEventBits_t ) ( uxBits & PKTIO_EVT_MASK_ABORTED ) != ( PlatformEventBits_t ) ( PKTIO_EVT_MASK_ABORTED ) )
15291529
{
15301530
Platform_Delay( PKTIO_SHUTDOWN_WAIT_INTERVAL_MS );
1531-
uxBits = ( PlatformEventGroup_EventBits ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
1531+
uxBits = ( PlatformEventBits_t ) PlatformEventGroup_GetBits( ( PlatformEventGroupHandle_t ) pContext->pPktioCommEvent );
15321532
}
15331533

15341534
( void ) PlatformEventGroup_Delete( pContext->pPktioCommEvent );

0 commit comments

Comments
 (0)