51
51
#define CELLULAR_COMM_PATH "\\\\.\\"CELLULAR_COMM_INTERFACE_PORT
52
52
53
53
/* Define the simulated UART interrupt number. */
54
- #define portINTERRUPT_UART ( 2UL )
54
+ #define portINTERRUPT_UART portINTERRUPT_USER_DEFINED_START
55
55
56
56
/* Define the read write buffer size. */
57
57
#define COMM_TX_BUFFER_SIZE ( 8192 )
@@ -91,7 +91,6 @@ typedef struct cellularCommContext
91
91
HANDLE commFileHandle ;
92
92
CellularCommInterface_t * pCommInterface ;
93
93
bool commTaskThreadStarted ;
94
- EventGroupHandle_t pCommTaskEvent ;
95
94
} cellularCommContext_t ;
96
95
97
96
/*-----------------------------------------------------------*/
@@ -126,14 +125,6 @@ static CellularCommInterfaceError_t prvCommIntfReceive( CellularCommInterfaceHan
126
125
*/
127
126
static CellularCommInterfaceError_t prvCommIntfClose ( CellularCommInterfaceHandle_t commInterfaceHandle );
128
127
129
- /**
130
- * @brief Get default comm interface context.
131
- *
132
- * @return On success, SOCKETS_ERROR_NONE is returned. If an error occurred, error code defined
133
- * in sockets_wrapper.h is returned.
134
- */
135
- static cellularCommContext_t * prvGetCellularCommContext ( void );
136
-
137
128
/**
138
129
* @brief UART interrupt handler.
139
130
*
@@ -170,33 +161,6 @@ static CellularCommInterfaceError_t prvSetupCommTimeout( HANDLE hComm );
170
161
*/
171
162
static CellularCommInterfaceError_t prvSetupCommSettings ( HANDLE hComm );
172
163
173
- /**
174
- * @brief Thread routine to generate simulated interrupt.
175
- *
176
- * @param[in] pUserData Pointer to cellularCommContext_t allocated in comm interface open.
177
- */
178
- static void prvCommTaskThread ( void * pUserData );
179
-
180
- /**
181
- * @brief Helper function to setup and create commTaskThread.
182
- *
183
- * @param[in] pCellularCommContext Cellular comm interface context allocated in open.
184
- *
185
- * @return On success, IOT_COMM_INTERFACE_SUCCESS is returned. If an error occurred, error code defined
186
- * in CellularCommInterfaceError_t is returned.
187
- */
188
- static CellularCommInterfaceError_t prvSetupCommTaskThread ( cellularCommContext_t * pCellularCommContext );
189
-
190
- /**
191
- * @brief Helper function to clean commTaskThread.
192
- *
193
- * @param[in] pCellularCommContext Cellular comm interface context allocated in open.
194
- *
195
- * @return On success, IOT_COMM_INTERFACE_SUCCESS is returned. If an error occurred, error code defined
196
- * in CellularCommInterfaceError_t is returned.
197
- */
198
- static CellularCommInterfaceError_t prvCleanCommTaskThread ( cellularCommContext_t * pCellularCommContext );
199
-
200
164
/*-----------------------------------------------------------*/
201
165
202
166
CellularCommInterface_t CellularCommInterface =
@@ -215,28 +179,14 @@ static cellularCommContext_t uxCellularCommContext =
215
179
.commFileHandle = NULL ,
216
180
.pUserData = NULL ,
217
181
.commStatus = 0U ,
218
- .commTaskThreadStarted = false,
219
- .pCommTaskEvent = NULL
182
+ .commTaskThreadStarted = false
220
183
};
221
184
222
- /* Mutex used to protect rxEvent variables that are accessed by multiple threads. */
223
- static void * pvRxEventMutex = NULL ;
224
-
225
- /* Indicate RX event is received in comm driver. */
226
- static bool rxEvent = false;
227
-
228
- /*-----------------------------------------------------------*/
229
-
230
- static cellularCommContext_t * prvGetCellularCommContext ( void )
231
- {
232
- return & uxCellularCommContext ;
233
- }
234
-
235
185
/*-----------------------------------------------------------*/
236
186
237
187
static uint32_t prvProcessUartInt ( void )
238
188
{
239
- cellularCommContext_t * pCellularCommContext = prvGetCellularCommContext () ;
189
+ cellularCommContext_t * pCellularCommContext = & uxCellularCommContext ;
240
190
CellularCommInterfaceError_t callbackRet = IOT_COMM_INTERFACE_FAILURE ;
241
191
uint32_t retUartInt = pdTRUE ;
242
192
@@ -280,9 +230,7 @@ static DWORD WINAPI prvCellularCommReceiveCBThreadFunc( LPVOID pArgument )
280
230
{
281
231
if ( ( dwCommStatus & EV_RXCHAR ) != 0 )
282
232
{
283
- WaitForSingleObject ( pvRxEventMutex , INFINITE );
284
- rxEvent = true;
285
- ReleaseMutex ( pvRxEventMutex );
233
+ vPortGenerateSimulatedInterruptFromNative ( portINTERRUPT_UART );
286
234
}
287
235
}
288
236
else
@@ -367,154 +315,14 @@ static CellularCommInterfaceError_t prvSetupCommSettings( HANDLE hComm )
367
315
368
316
/*-----------------------------------------------------------*/
369
317
370
- static void prvCommTaskThread ( void * pUserData )
371
- {
372
- cellularCommContext_t * pCellularCommContext = ( cellularCommContext_t * ) pUserData ;
373
- EventBits_t uxBits = 0 ;
374
-
375
- /* Inform thread ready. */
376
- LogInfo ( ( "Cellular commTaskThread started" ) );
377
-
378
- if ( pCellularCommContext != NULL )
379
- {
380
- ( void ) xEventGroupSetBits ( pCellularCommContext -> pCommTaskEvent ,
381
- COMMTASK_EVT_MASK_STARTED );
382
- }
383
-
384
- while ( true )
385
- {
386
- /* Wait for notification from eventqueue. */
387
- uxBits = xEventGroupWaitBits ( ( pCellularCommContext -> pCommTaskEvent ),
388
- ( ( EventBits_t ) COMMTASK_EVT_MASK_ABORT ),
389
- pdTRUE ,
390
- pdFALSE ,
391
- pdMS_TO_TICKS ( COMMTASK_POLLING_TIME_MS ) );
392
-
393
- if ( ( uxBits & ( EventBits_t ) COMMTASK_EVT_MASK_ABORT ) != 0U )
394
- {
395
- LogDebug ( ( "Abort received, cleaning up!" ) );
396
- break ;
397
- }
398
- else
399
- {
400
- /* Polling the global share variable to trigger the interrupt. */
401
- if ( rxEvent == true )
402
- {
403
- WaitForSingleObject ( pvRxEventMutex , INFINITE );
404
- rxEvent = false;
405
- ReleaseMutex ( pvRxEventMutex );
406
-
407
- vPortGenerateSimulatedInterrupt ( portINTERRUPT_UART );
408
- }
409
- }
410
- }
411
-
412
- /* Inform thread ready. */
413
- if ( pCellularCommContext != NULL )
414
- {
415
- ( void ) xEventGroupSetBits ( pCellularCommContext -> pCommTaskEvent , COMMTASK_EVT_MASK_ABORTED );
416
- }
417
-
418
- LogInfo ( ( "Cellular commTaskThread exit" ) );
419
- }
420
-
421
- /*-----------------------------------------------------------*/
422
-
423
- static CellularCommInterfaceError_t prvSetupCommTaskThread ( cellularCommContext_t * pCellularCommContext )
424
- {
425
- BOOL Status = TRUE;
426
- EventBits_t uxBits = 0 ;
427
- CellularCommInterfaceError_t commIntRet = IOT_COMM_INTERFACE_SUCCESS ;
428
-
429
- pCellularCommContext -> pCommTaskEvent = xEventGroupCreate ();
430
-
431
- if ( pCellularCommContext -> pCommTaskEvent != NULL )
432
- {
433
- /* Create the FreeRTOS thread to generate the simulated interrupt. */
434
- Status = Platform_CreateDetachedThread ( prvCommTaskThread ,
435
- ( void * ) pCellularCommContext ,
436
- COMM_IF_THREAD_DEFAULT_PRIORITY ,
437
- COMM_IF_THREAD_DEFAULT_STACK_SIZE );
438
-
439
- if ( Status != true )
440
- {
441
- commIntRet = IOT_COMM_INTERFACE_FAILURE ;
442
- }
443
- }
444
- else
445
- {
446
- commIntRet = IOT_COMM_INTERFACE_FAILURE ;
447
- }
448
-
449
- if ( commIntRet == IOT_COMM_INTERFACE_SUCCESS )
450
- {
451
- uxBits = xEventGroupWaitBits ( ( pCellularCommContext -> pCommTaskEvent ),
452
- ( ( EventBits_t ) COMMTASK_EVT_MASK_STARTED | ( EventBits_t ) COMMTASK_EVT_MASK_ABORTED ),
453
- pdTRUE ,
454
- pdFALSE ,
455
- portMAX_DELAY );
456
-
457
- if ( ( uxBits & ( EventBits_t ) COMMTASK_EVT_MASK_STARTED ) == COMMTASK_EVT_MASK_STARTED )
458
- {
459
- pCellularCommContext -> commTaskThreadStarted = true;
460
- }
461
- else
462
- {
463
- commIntRet = IOT_COMM_INTERFACE_FAILURE ;
464
- pCellularCommContext -> commTaskThreadStarted = false;
465
- }
466
- }
467
-
468
- return commIntRet ;
469
- }
470
-
471
- /*-----------------------------------------------------------*/
472
-
473
- static CellularCommInterfaceError_t prvCleanCommTaskThread ( cellularCommContext_t * pCellularCommContext )
474
- {
475
- EventBits_t uxBits = 0 ;
476
- CellularCommInterfaceError_t commIntRet = IOT_COMM_INTERFACE_SUCCESS ;
477
-
478
- /* Wait for the commTaskThreadStarted exit. */
479
- if ( ( pCellularCommContext -> commTaskThreadStarted == true ) && ( pCellularCommContext -> pCommTaskEvent != NULL ) )
480
- {
481
- ( void ) xEventGroupSetBits ( pCellularCommContext -> pCommTaskEvent ,
482
- COMMTASK_EVT_MASK_ABORT );
483
- uxBits = xEventGroupWaitBits ( ( pCellularCommContext -> pCommTaskEvent ),
484
- ( ( EventBits_t ) COMMTASK_EVT_MASK_ABORTED ),
485
- pdTRUE ,
486
- pdFALSE ,
487
- portMAX_DELAY );
488
-
489
- if ( ( uxBits & ( EventBits_t ) COMMTASK_EVT_MASK_ABORTED ) != COMMTASK_EVT_MASK_ABORTED )
490
- {
491
- LogDebug ( ( "Cellular close wait commTaskThread fail" ) );
492
- commIntRet = IOT_COMM_INTERFACE_FAILURE ;
493
- }
494
-
495
- pCellularCommContext -> commTaskThreadStarted = false;
496
- }
497
-
498
- /* Clean the event group. */
499
- if ( pCellularCommContext -> pCommTaskEvent != NULL )
500
- {
501
- vEventGroupDelete ( pCellularCommContext -> pCommTaskEvent );
502
- pCellularCommContext -> pCommTaskEvent = NULL ;
503
- }
504
-
505
- return commIntRet ;
506
- }
507
-
508
- /*-----------------------------------------------------------*/
509
-
510
318
static CellularCommInterfaceError_t prvCommIntfOpen ( CellularCommInterfaceReceiveCallback_t receiveCallback ,
511
319
void * pUserData ,
512
320
CellularCommInterfaceHandle_t * pCommInterfaceHandle )
513
321
{
514
322
CellularCommInterfaceError_t commIntRet = IOT_COMM_INTERFACE_SUCCESS ;
515
323
HANDLE hComm = ( HANDLE ) INVALID_HANDLE_VALUE ;
516
324
BOOL Status = TRUE;
517
- cellularCommContext_t * pCellularCommContext = prvGetCellularCommContext () ;
325
+ cellularCommContext_t * pCellularCommContext = & uxCellularCommContext ;
518
326
DWORD dwRes = 0 ;
519
327
520
328
if ( pCellularCommContext == NULL )
@@ -592,25 +400,10 @@ static CellularCommInterfaceError_t prvCommIntfOpen( CellularCommInterfaceReceiv
592
400
}
593
401
}
594
402
595
- /* Create RX event mutex to protect rxEvent. */
596
- if ( commIntRet == IOT_COMM_INTERFACE_SUCCESS )
597
- {
598
- pvRxEventMutex = CreateMutex ( NULL , FALSE, NULL );
599
-
600
- if ( pvRxEventMutex == NULL )
601
- {
602
- commIntRet = IOT_COMM_INTERFACE_FAILURE ;
603
- }
604
- }
605
-
606
403
if ( commIntRet == IOT_COMM_INTERFACE_SUCCESS )
607
404
{
608
405
pCellularCommContext -> commReceiveCallback = receiveCallback ;
609
- commIntRet = prvSetupCommTaskThread ( pCellularCommContext );
610
- }
611
406
612
- if ( commIntRet == IOT_COMM_INTERFACE_SUCCESS )
613
- {
614
407
vPortSetInterruptHandler ( portINTERRUPT_UART , prvProcessUartInt );
615
408
pCellularCommContext -> commReceiveCallbackThread =
616
409
CreateThread ( NULL , 0 , prvCellularCommReceiveCBThreadFunc , hComm , 0 , NULL );
@@ -653,16 +446,6 @@ static CellularCommInterfaceError_t prvCommIntfOpen( CellularCommInterfaceReceiv
653
446
}
654
447
655
448
pCellularCommContext -> commReceiveCallbackThread = NULL ;
656
-
657
- /* Wait for the commTaskThreadStarted exit. */
658
- ( void ) prvCleanCommTaskThread ( pCellularCommContext );
659
-
660
- /* Clean the rxEvent mutex. */
661
- if ( pvRxEventMutex != NULL )
662
- {
663
- CloseHandle ( pvRxEventMutex );
664
- pvRxEventMutex = NULL ;
665
- }
666
449
}
667
450
668
451
return commIntRet ;
@@ -731,16 +514,6 @@ static CellularCommInterfaceError_t prvCommIntfClose( CellularCommInterfaceHandl
731
514
732
515
pCellularCommContext -> commReceiveCallbackThread = NULL ;
733
516
734
- /* Clean the commTaskThread. */
735
- ( void ) prvCleanCommTaskThread ( pCellularCommContext );
736
-
737
- /* Clean the rxEvent mutex. */
738
- if ( pvRxEventMutex != NULL )
739
- {
740
- CloseHandle ( pvRxEventMutex );
741
- pvRxEventMutex = NULL ;
742
- }
743
-
744
517
/* clean the data structure. */
745
518
pCellularCommContext -> commStatus &= ~( CELLULAR_COMM_OPEN_BIT );
746
519
}
0 commit comments