高通ADSP和AP间的通讯过程

AP侧 :

sensor1_handle_s *hndl1;

//创建clients_mutex等互斥锁
sensor1_init()
/*
* 1. 首先获取Adsp的客户端;
* 2. 创建2个线程,一个线程waiting_thread首先等待获取Adsp的客户端,一个线程client_thread建立Adsp的Response的客户端处理线程;
*/
sensor1_open( hndl_ptr,notify_data_cb,(intptr_t)hndl_ptr );

 {
    sensor1_msg_header_s smgr_ver_req_hdr;
    sns_common_version_req_msg_v01 *smgr_version_req = NULL;
    //构造smgr_version_req的结构
    error = sensor1_alloc_msg_buf( hndl1,
                                 sizeof(sns_common_version_req_msg_v01),
                                 (void**)&smgr_version_req );
    //为smgr_ver_req_hdr 分配空间
    alloc_smgr_smgr_ver_req(&smgr_ver_req_hdr );
    //通过sensor1_write调用QMI接口Call到Adsp去
    send_req( hndl1, (void *)smgr_version_req, smgr_ver_req_hdr );
    
    while(1);
  }

Adsp构造的消息如下

  void alloc_smgr_smgr_ver_req(sensor1_msg_header_s *msg_hdr )
{
    msg_hdr->service_number = SNS_SMGR_SVC_ID_V01;
    msg_hdr->msg_id = SNS_SMGR_VERSION_REQ_V01;
    msg_hdr->msg_size = sizeof(sns_common_version_req_msg_v01);
    msg_hdr->txn_id = 0;
}

send_req函数实现如下:

void send_req( sensor1_handle_s *hndl, void *req, sensor1_msg_header_s msg_hdr )
{
  error = sensor1_write( hndl,
                         &msg_hdr,
                         req );

  if( SENSOR1_SUCCESS != error ) {
    printf("\nsensor1_write returned %d\n", error);
    if( SENSOR1_EWOULDBLOCK != error ) {
      exit(error);
    }
  }
  // Make sure we get a response
  error = 0;
  pthread_mutex_lock( &my_mutex );
  clock_gettime( CLOCK_REALTIME, &ts );
  while( (my_txn_id != msg_hdr.txn_id) && error == 0 ) {
    ts.tv_sec += 100000000; // wait 100msec
    error = pthread_cond_timedwait( &my_cond, &my_mutex, &ts );
  }
  my_txn_id = 0;
  pthread_mutex_unlock( &my_mutex );
  if( 0 != error ) {
    printf("\nError while waiting for response message %d\n", error);
    exit(error);
  } else {
    //printf("\nGot response to message\n");
  }
}
 

消息发送后,Adsp返回的信息会通过client_thread线程调用notify_data_cb的方式返回,如下:

void notify_data_cb( intptr_t data,
                     sensor1_msg_header_s *msg_hdr_ptr,
                     sensor1_msg_type_e msg_type,
                     void *msg_ptr )
{
  uint32_t smgr_version;
  sns_common_version_resp_msg_v01* respMsgPtr;

  if( NULL == msg_hdr_ptr ) {
    printf("\nreceived NULL msg_hdr_ptr!\n");
  } else {
    
    printf("hdr.service_number: %u\n\thdr.msg_id: %d\n\t"
           "hdr.msg_type: %d\n\thdr.msg_size: %d\n\thdr.txn_id: %d\n",
           msg_hdr_ptr->service_number,
           msg_hdr_ptr->msg_id,
           msg_type,
           msg_hdr_ptr->msg_size,
           msg_hdr_ptr->txn_id );
    
  }

  if( msg_type == SENSOR1_MSG_TYPE_RESP && NULL != msg_hdr_ptr ) {
    printf("received RESP\n");

    if( msg_hdr_ptr->service_number == SNS_SMGR_SVC_ID_V01 ) {
      switch (msg_hdr_ptr->msg_id) {
        case SNS_SMGR_VERSION_RESP_V01:     
            printf("received smgr version resp\n");
            respMsgPtr = (sns_common_version_resp_msg_v01 *)msg_ptr;
            if (respMsgPtr->resp.sns_result_t == 0) {
                smgr_version = respMsgPtr->interface_version_number;
                printf("%s: SMGR version=%d \n", __FUNCTION__, smgr_version);
            }else{
                printf("SMGR Get Response Failed\n");
            }

            break;          
        case SNS_SMGR_ALL_SENSOR_INFO_RESP_V01:
          handle_smgr_all_sensor_info_resp(msg_ptr );
          break;
        case SNS_SMGR_SINGLE_SENSOR_INFO_RESP_V01:
          handle_smgr_single_sensor_info_resp( msg_ptr );
          break;
        case SNS_SMGR_REPORT_RESP_V01:
          handle_smgr_report_resp();
          break;
        default:
          break;
      }
    }

    pthread_mutex_lock( &my_mutex );
    my_txn_id = msg_hdr_ptr->txn_id;
    pthread_cond_signal( &my_cond );
    pthread_mutex_unlock( &my_mutex );
  } else if( msg_type == SENSOR1_MSG_TYPE_IND ) {
    printf("*");
    fflush(NULL);
    pthread_mutex_lock( &my_mutex );
    num_indications++;
    pthread_cond_signal( &my_cond );
    pthread_mutex_unlock( &my_mutex );
  } else if( msg_type == SENSOR1_MSG_TYPE_BROKEN_PIPE ) {
    printf("\nreceived BROKEN_PIPE!!!\n");
  } else {
    printf( "\nreceived INVALID MSG type: %i!!!\n", msg_type );
  }
  if( NULL != msg_ptr ) {
    sensor1_free_msg_buf( *((sensor1_handle_s**)data), msg_ptr );
  }
}

Adsp的流程如下:

adsp_proc\sensors\smgr\src\sns_rh_main.c
SMGR_STATIC sns_err_code_e sns_rh_process_external_smgr_request(
  sns_rh_mr_req_q_item_s** msg_ptr_ptr)
{
    ...
  case SNS_SMGR_VERSION_REQ_V01:
    err_code = sns_rh_process_version_request(*msg_ptr_ptr);
    break;
    ...
}
————————————————

sns_rh_process_version_request调用如下:

adsp_proc\sensors\smgr\src\sns_rh_main.c
/*=========================================================================*/
SMGR_STATIC sns_err_code_e sns_rh_process_version_request(
  const sns_rh_mr_req_q_item_s* msg_ptr)
{
  sns_err_code_e err_code = SNS_ERR_NOMEM;
  sns_common_version_resp_msg_v01* resp_ptr =
    SMGR_ALLOC_STRUCT(sns_common_version_resp_msg_v01);
  /* -------------------------------------------------------------------- */

  if ( resp_ptr != NULL )
  {
    sns_rh_mr_header_s resp_msg_header = msg_ptr->header;

    resp_ptr->max_message_id = SNS_SMGR_SVC_V01_MAX_MESSAGE_ID;
    resp_ptr->interface_version_number = SNS_SMGR_SVC_V01_IDL_MINOR_VERS+1;
    resp_msg_header.msg_id   = SNS_SMGR_VERSION_RESP_V01;
    resp_msg_header.body_len = sizeof(sns_common_version_resp_msg_v01);
    resp_ptr->resp.sns_result_t = SNS_RESULT_SUCCESS_V01;
    resp_ptr->resp.sns_err_t    = SENSOR1_SUCCESS;
    sns_rh_mr_send_resp(&resp_msg_header, (void**)&resp_ptr);
    SNS_SMGR_PRINTF0(HIGH, "Jon smgr response");
    err_code = SNS_SUCCESS;
  }
  return err_code;
}
————————————————
 


————————————————
 

你可能感兴趣的:(高通ADSP和AP间的通讯过程)