@@ -535,23 +535,18 @@ rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size
535535
536536static rt_err_t at_client_getchar (at_client_t client , char * ch )
537537{
538- rt_err_t result = RT_EOK ;
539-
538+ rt_err_t result = RT_EOK ;
539+ rt_ssize_t recvLen = 0 ;
540540#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 )
542543 {
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 ;
550545 }
551546#else
552547 rt_int32_t rx_timeout = 0 ;
553548 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 );
555550 if (recvLen <= 0 )
556551 {
557552 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
593588 {
594589 rt_size_t read_len ;
595590
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 );
597592
598593 read_len = rt_device_read (client -> device , 0 , buf + read_idx , size );
599594 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
603598 }
604599 else
605600 {
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 )
607602 break ;
608603 }
609604 }
@@ -918,8 +913,26 @@ static void client_parser(at_client_t client)
918913
919914static rt_err_t at_client_rx_ind (rt_device_t dev , rt_size_t size )
920915{
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+
923936 return RT_EOK ;
924937}
925938
@@ -1042,7 +1055,6 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
10421055 rt_slist_append (& g_at_client_list , & client -> list );
10431056 rt_hw_interrupt_enable (level );
10441057
1045- client -> device -> user_data = client ;
10461058 rt_device_set_rx_indicate (client -> device , at_client_rx_ind );
10471059
10481060 client -> status = AT_STATUS_INITIALIZED ;
@@ -1090,8 +1102,7 @@ int at_client_deInit(const char *dev_name)
10901102 rt_event_detach (& client -> event );
10911103 rt_mutex_detach (& client -> lock );
10921104
1093- client -> device -> user_data = RT_NULL ;
1094- result = rt_device_close (client -> device );
1105+ result = rt_device_close (client -> device );
10951106
10961107 rt_free (client );
10971108 return result ;
0 commit comments