@@ -535,23 +535,18 @@ rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size
535
535
536
536
static rt_err_t at_client_getchar (at_client_t client , char * ch )
537
537
{
538
- rt_err_t result = RT_EOK ;
539
-
538
+ rt_err_t result = RT_EOK ;
539
+ rt_ssize_t recvLen = 0 ;
540
540
#if (!defined(RT_USING_SERIAL_V2 ))
541
- while (rt_device_read (client -> device , 0 , ch , 1 ) == 0 )
541
+ recvLen = rt_device_read (client -> device , 0 , ch , 1 );
542
+ if (recvLen <= 0 )
542
543
{
543
- result = rt_sem_take (client -> rx_notice , rt_tick_from_millisecond (timeout ));
544
- if (result != RT_EOK )
545
- {
546
- return result ;
547
- }
548
-
549
- rt_sem_control (client -> rx_notice , RT_IPC_CMD_RESET , RT_NULL );
544
+ result = - RT_ERROR ;
550
545
}
551
546
#else
552
547
rt_int32_t rx_timeout = 0 ;
553
548
rt_device_control (client -> device , RT_SERIAL_CTRL_SET_RX_TIMEOUT , (void * )& rx_timeout );
554
- rt_ssize_t recvLen = rt_device_read (client -> device , 0 , ch , 1 );
549
+ recvLen = rt_device_read (client -> device , 0 , ch , 1 );
555
550
if (recvLen <= 0 )
556
551
{
557
552
result = - RT_ERROR ;
@@ -593,7 +588,7 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
593
588
{
594
589
rt_size_t read_len ;
595
590
596
- rt_sem_control ( client -> rx_notice , RT_IPC_CMD_RESET , RT_NULL );
591
+ rt_event_recv ( & client -> event , at_client_rx_notice_event , RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR , 0 , NULL );
597
592
598
593
read_len = rt_device_read (client -> device , 0 , buf + read_idx , size );
599
594
if (read_len > 0 )
@@ -603,7 +598,7 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
603
598
}
604
599
else
605
600
{
606
- if (rt_sem_take ( client -> rx_notice , rt_tick_from_millisecond (timeout )) != RT_EOK )
601
+ if (rt_event_recv ( & client -> event , at_client_rx_notice_event , RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR , rt_tick_from_millisecond (timeout ), NULL ) != RT_EOK )
607
602
break ;
608
603
}
609
604
}
@@ -918,8 +913,26 @@ static void client_parser(at_client_t client)
918
913
919
914
static rt_err_t at_client_rx_ind (rt_device_t dev , rt_size_t size )
920
915
{
921
- at_client_t client = (at_client_t )dev -> user_data ;
922
- rt_event_send (& client -> event , at_client_rx_notice_event );
916
+ rt_slist_t * node ;
917
+ at_client_t client ;
918
+
919
+ if (size <= 0 )
920
+ {
921
+ return RT_EOK ;
922
+ }
923
+
924
+ rt_base_t level = rt_hw_interrupt_disable ();
925
+ rt_slist_for_each (node , & g_at_client_list )
926
+ {
927
+ client = rt_slist_entry (node , struct at_client , list );
928
+ if (client -> device == dev )
929
+ {
930
+ rt_event_send (& client -> event , at_client_rx_notice_event );
931
+ break ;
932
+ }
933
+ }
934
+ rt_hw_interrupt_enable (level );
935
+
923
936
return RT_EOK ;
924
937
}
925
938
@@ -1042,7 +1055,6 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
1042
1055
rt_slist_append (& g_at_client_list , & client -> list );
1043
1056
rt_hw_interrupt_enable (level );
1044
1057
1045
- client -> device -> user_data = client ;
1046
1058
rt_device_set_rx_indicate (client -> device , at_client_rx_ind );
1047
1059
1048
1060
client -> status = AT_STATUS_INITIALIZED ;
@@ -1090,8 +1102,7 @@ int at_client_deInit(const char *dev_name)
1090
1102
rt_event_detach (& client -> event );
1091
1103
rt_mutex_detach (& client -> lock );
1092
1104
1093
- client -> device -> user_data = RT_NULL ;
1094
- result = rt_device_close (client -> device );
1105
+ result = rt_device_close (client -> device );
1095
1106
1096
1107
rt_free (client );
1097
1108
return result ;
0 commit comments