• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybricks / pybricks-micropython / 14329424534

31 Mar 2025 01:50PM UTC coverage: 56.638% (+0.2%) from 56.477%
14329424534

push

github

laurensvalk
pbio/os: Move IRQ hooks to platform.

Proceed to make pbio more independent from MicroPython.

Also restore them as static inline as they used to be
prior to https://github.com/pybricks/pybricks-micropython/pull/298
which reduces build size.

0 of 6 new or added lines in 1 file covered. (0.0%)

204 existing lines in 11 files now uncovered.

3878 of 6847 relevant lines covered (56.64%)

20623019.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/lib/pbio/src/motor_process.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2018-2025 The Pybricks Authors
3

4
#include <pbdrv/clock.h>
5

6
#include <pbio/battery.h>
7
#include <pbio/control.h>
8
#include <pbio/drivebase.h>
9
#include <pbio/servo.h>
10

11
#include <pbio/os.h>
12

13
#if PBIO_CONFIG_MOTOR_PROCESS != 0
14

15
static pbio_os_process_t pbio_motor_process;
16

17
static pbio_error_t pbio_motor_process_thread(pbio_os_state_t *state, void *context) {
85,565✔
18

19
    static pbio_os_timer_t timer;
51,981✔
20

21
    PBIO_OS_ASYNC_BEGIN(state);
85,565✔
22

23
    timer.start = pbdrv_clock_get_ms() - PBIO_CONFIG_CONTROL_LOOP_TIME_MS;
33✔
24
    timer.duration = PBIO_CONFIG_CONTROL_LOOP_TIME_MS;
33✔
25

26
    // Initialize battery voltage.
27
    pbio_battery_init();
33✔
28

29
    for (;;) {
10,415✔
30
        // Update battery voltage.
31
        pbio_battery_update();
17,258✔
32

33
        // Update drivebase
34
        pbio_drivebase_update_all();
17,258✔
35

36
        // Update servos
37
        pbio_servo_update_all();
17,258✔
38

39
        // Increment start time instead waiting from here, making the
40
        // loop time closer to the target on average.
41
        timer.start += PBIO_CONFIG_CONTROL_LOOP_TIME_MS;
17,258✔
42

43
        // In the rare case that polling was delayed too long, we need to
44
        // ensure that the next poll is a minimum of 1ms in the future so we
45
        // don't have 0 time deltas in the control code.
46
        while (pbio_os_timer_is_expired(&timer)) {
17,258✔
UNCOV
47
            timer.start++;
×
48
        }
49

50
        PBIO_OS_AWAIT_UNTIL(state, pbio_os_timer_is_expired(&timer));
102,790✔
51
    }
52

53
    // Unreachable.
54
    PBIO_OS_ASYNC_END(PBIO_ERROR_FAILED);
51,981✔
55
}
56

57
void pbio_motor_process_start(void) {
33✔
58
    pbio_os_process_start(&pbio_motor_process, pbio_motor_process_thread, NULL);
33✔
59
}
33✔
60

61
#endif // PBIO_CONFIG_MOTOR_PROCESS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc