| 1428 | ****************************************************************************/ |
| 1429 | |
| 1430 | int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower, |
| 1431 | FAR const char *path, size_t esize) |
| 1432 | { |
| 1433 | FAR struct sensor_upperhalf_s *upper; |
| 1434 | int ret = -EINVAL; |
| 1435 | |
| 1436 | DEBUGASSERT(lower != NULL); |
| 1437 | |
| 1438 | if (lower->type >= SENSOR_TYPE_COUNT || !esize) |
| 1439 | { |
| 1440 | snerr("ERROR: type is invalid\n"); |
| 1441 | return ret; |
| 1442 | } |
| 1443 | |
| 1444 | /* Allocate the upper-half data structure */ |
| 1445 | |
| 1446 | upper = kmm_zalloc(sizeof(struct sensor_upperhalf_s)); |
| 1447 | if (!upper) |
| 1448 | { |
| 1449 | snerr("ERROR: Allocation failed\n"); |
| 1450 | return -ENOMEM; |
| 1451 | } |
| 1452 | |
| 1453 | /* Initialize the upper-half data structure */ |
| 1454 | |
| 1455 | list_initialize(&upper->userlist); |
| 1456 | upper->state.esize = esize; |
| 1457 | upper->state.min_interval = UINT32_MAX; |
| 1458 | upper->state.nonwakeup = true; |
| 1459 | if (lower->ops->activate) |
| 1460 | { |
| 1461 | upper->state.nadvertisers = 1; |
| 1462 | } |
| 1463 | |
| 1464 | nxrmutex_init(&upper->lock); |
| 1465 | |
| 1466 | /* Bind the lower half data structure member */ |
| 1467 | |
| 1468 | lower->priv = upper; |
| 1469 | lower->sensor_lock = sensor_lock; |
| 1470 | lower->sensor_unlock = sensor_unlock; |
| 1471 | |
| 1472 | if (!lower->ops->fetch) |
| 1473 | { |
| 1474 | if (!lower->nbuffer) |
| 1475 | { |
| 1476 | lower->nbuffer = 1; |
| 1477 | } |
| 1478 | |
| 1479 | lower->push_event = sensor_push_event; |
| 1480 | } |
| 1481 | else |
| 1482 | { |
| 1483 | lower->notify_event = sensor_notify_event; |
| 1484 | lower->nbuffer = 0; |
| 1485 | } |
| 1486 | |
| 1487 | #ifdef CONFIG_SENSORS_RPMSG |
no test coverage detected