数据交换框图
借用网上的一张图,看下数据交互的方式:我们的sensor驱动先创建一个data stream, 然后填充request通过send_request后request挂入data steam的list里面,
目标sensor填充数据后通过send_event把数据给回我们。
平台的内建sensor,我们的sensor驱动要依赖于这些sensor,当要使用它们时要和其建立data stream
Typical platform feature-specific sensors
Registry sensor
Timer sensor
Interrupt sensor
Asynchronous COM port sensor
SUID lookup sensor
Test sensor
用HALL sensor研究数据流
接上图,bu52053nvx发送的request出去后就返回了,并不会一直等待,开启另外一个线程在sns_stream_servcie_process中处理
sns_stream_servcie_process线程结束,开启线程sns_event_service_process调用hall sensor的notify_event()将数据返回
以下为hall sensor使用timer sensor的代码片段
static void bu52053nvx_start_power_rail_timer(sns_sensor *const this,
sns_time timeout_ticks,
BU52053NVX_POWER_RAIL_PENDING_STATE pwr_rail_pend_state)
{
// 通信双方通过data stream交换数据
if (0 == state->timer_stream) {
sns_suid_lookup_get(&state->common.suid_lookup_data, "timer", &suid);
stream_svc->api->create_sensor_stream(stream_svc, this, suid, &state->timer_stream);
}
// 填充request
req_len = pb_encode_request(buffer, sizeof(buffer), &req_payload, sns_timer_sensor_config_fields, 0);
if ((req_len > 0U) && (0 != state->timer_stream)) {
sns_request timer_req = { .message_id = SNS_TIMER_MSGID_SNS_TIMER_SENSOR_CONFIG,
.request = buffer,
.request_len = req_len };
// 将request发送到data stream
state->timer_stream->api->send_request(state->timer_stream, &timer_req);
state->power_rail_pend_state = pwr_rail_pend_state;
}
return;
}
经过sensor framework这个黑盒后,request送达timer sensor,在设定的timer超时时间到期后,timer sensor的数据通过framework,
调用hall sensor的notify_event发送回来。所以在这里我们可以看到请求的数据可能很久才会回来,高通设计的时候采用了异步的方式,
有一点要吐槽的是,所有的数据接收都是在notify_event,这会导致notify_event又臭又长。
static sns_rc bu52053nvx_sensor_notify_event(sns_sensor *const this)
{
//----------------------Handle a Timer Sensor event.-------------------
// 数据挂在一个list中,不一定只有一个数据,下面还没处理的数据全部迭代出来
if (0 != state->timer_stream) {
event = state->timer_stream->api->peek_input(state->timer_stream);
while (0 != event) {
....
event = state->timer_stream->api->get_next_input(state->timer_stream);
}
}
}
到现在还剩 instance api的 set_client_config 和 notify_event
sns_sensor_instance_api bu52053nvx_sensor_instance_api = {
.set_client_config = &bu52053nvx_inst_set_client_config,
.notify_event = &bu52053nvx_inst_notify_event
};
- 每个sensor instance都使用特定的配置进行操作,instance的set_client_config是给sensor调用的
// sns_bu52053nvx_sensor.c
static void bu52053nvx_reval_instance_config(sns_sensor *this, sns_sensor_instance *instance, bool sequence)
{
BU52053NVX_INSTANCE_STATE *inst_state = (BU52053NVX_INSTANCE_STATE*)instance->state->state;
sns_request config;
bool sensor_hall_client_present = false;
// Start with a clean state
inst_state->enabled = 0U;
sensor_hall_client_present = bu52053nvx_get_hall_config(this, instance);
if (sensor_hall_client_present && BU52053NVX_ENABLE_SEQ == sequence) {
inst_state->enabled = (uint8_t)BU52053NVX_HALL;
}
// set instants config
config.message_id = (uint32_t)SNS_STD_SENSOR_MSGID_SNS_STD_SENSOR_CONFIG;
config.request_len = 0U;
this->instance_api->set_client_config(instance, &config);
return;
}
最后一个instance的notify_event,和senor的notify_event一样都是的,instance请求其他sensor的数据时,通过回调notify_event接收数据
// event service判断数据是发送给sensor的还是sensor instance的
sns_event_service_process(void *func_arg)
{
if(NULL != stream->dst_sensor)
process_pending_event_sensor(this, stream);
else
process_pending_event_instance(this, stream);
}
}
最后bu52053nvx为什么要搞个power_rail_timer,有没有大神知道,在评论区指导下?
记录之前看过的博客
SEE 中的数据结构及之间的关系_sensor see_shuai_wen的博客-CSDN博客
高通SDM845平台Sensor学习——3.SLPI(Physical Sensor)_qq964541543的博客-CSDN博客