| 550 | } |
| 551 | |
| 552 | void rt_thermal_zone_device_update(struct rt_thermal_zone_device *zdev, rt_ubase_t msg) |
| 553 | { |
| 554 | rt_err_t err; |
| 555 | rt_bool_t passive = RT_FALSE, need_cool = RT_FALSE; |
| 556 | struct rt_thermal_notifier *notifier, *next_notifier; |
| 557 | |
| 558 | RT_ASSERT(zdev != RT_NULL); |
| 559 | |
| 560 | if (!rt_interrupt_get_nest()) |
| 561 | { |
| 562 | rt_mutex_take(&zdev->mutex, RT_WAITING_FOREVER); |
| 563 | } |
| 564 | |
| 565 | /* Check thermal zone status */ |
| 566 | if (msg == RT_THERMAL_MSG_DEVICE_DOWN) |
| 567 | { |
| 568 | zdev->enabled = RT_FALSE; |
| 569 | } |
| 570 | else if (msg == RT_THERMAL_MSG_DEVICE_UP) |
| 571 | { |
| 572 | zdev->enabled = RT_TRUE; |
| 573 | } |
| 574 | |
| 575 | /* Read temperature */ |
| 576 | zdev->last_temperature = zdev->temperature; |
| 577 | zdev->ops->get_temp(zdev, &zdev->temperature); |
| 578 | |
| 579 | for (int i = 0; i < zdev->trips_nr; ++i) |
| 580 | { |
| 581 | struct rt_thermal_trip *tmp_trip = &zdev->trips[i]; |
| 582 | |
| 583 | if (zdev->temperature <= tmp_trip->temperature) |
| 584 | { |
| 585 | continue; |
| 586 | } |
| 587 | |
| 588 | switch (tmp_trip->type) |
| 589 | { |
| 590 | case RT_THERMAL_TRIP_PASSIVE: |
| 591 | passive = RT_TRUE; |
| 592 | goto cooling; |
| 593 | |
| 594 | case RT_THERMAL_TRIP_CRITICAL: |
| 595 | if (zdev->ops->critical) |
| 596 | { |
| 597 | zdev->ops->critical(zdev); |
| 598 | } |
| 599 | else if (zdev->last_temperature > tmp_trip->temperature) |
| 600 | { |
| 601 | /* Tried to cool already, but failed */ |
| 602 | rt_hw_cpu_reset(); |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | goto cooling; |
| 607 | } |
| 608 | break; |
| 609 |
no test coverage detected