aboutsummaryrefslogtreecommitdiff
path: root/robot/hypervisor.h
blob: ad7d493f67d8ec70ca5f7d0d7fc1274e02c2fdb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

/** @file hypervisor.h */

#include <stdint.h>

#include "../shared/bool.h"
#include "../shared/protocol.h"

/** amount of parallel timers */
#define W2_HYPERVISOR_TIMER_COUNT 3

#define W2_TIMER_PING 0
#define W2_TIMER_OBJECT_DETECTION 1
#define W2_TIMER_BATTERY_MEASUREMENT 2

extern uint64_t g_w2_hypervisor_cycles;
extern uint64_t g_w2_hypervisor_uptime_qs;

extern unsigned long g_w2_hypervisor_ema_sercomm_qs;
extern unsigned long g_w2_hypervisor_ema_errcatch_qs;
extern unsigned long g_w2_hypervisor_ema_io_qs;
extern unsigned long g_w2_hypervisor_ema_mode_qs;

extern unsigned int g_w2_ping_ms;
extern uint8_t g_w2_ping_id;
extern bool g_w2_ping_received;
extern bool g_w2_ping_timeout;
extern bool g_w2_connected;

extern w2_e_target_area g_w2_target_area;

/**
 * backbone of all other modules
 *
 * stores global state and controls when other modules run
 */
void w2_hypervisor_main();

/**
 * pololu's `get_ms()` estimates run time by only adding the CPU time taken up
 * by pololu library functions. this function uses the `get_ticks()` function
 * to calculate elapsed microseconds, and should therefore be more accurate.
 */
uint64_t w2_get_qs();
/** return uptime in milliseconds (less accurate) */
uint64_t w2_get_ms();
/** reset time returned by `w2_get_qs()` */
void w2_time_reset();

/** start timer with label `label` */
void w2_hypervisor_time_start(uint8_t label);
/** stop timer with label `label` */
uint64_t w2_hypervisor_time_end(uint8_t label);