summaryrefslogtreecommitdiff
path: root/include/arch/esp8266/driver/uptime.h
blob: f3e2f23ceb9cede68aedd2512a4508152bff8c97 (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
/*
 * Copyright 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#ifndef UPTIME_H
#define UPTIME_H

extern "C" {
#include "osapi.h"
#include "user_interface.h"
}
#include "c_types.h"

class Uptime {
	private:
		Uptime(const Uptime &copy);

	public:
		Uptime () {}
		inline uint32_t get_us() { return system_get_time(); }
		inline uint32_t get_s() { return system_get_time() / 1000000; }

		inline uint32_t get_cycles()
		{
			uint32_t ccount;
			asm volatile ("esync; rsr %0,ccount":"=a" (ccount));
			return ccount;
		}
};

extern Uptime uptime;

#endif