summaryrefslogtreecommitdiff
path: root/include/arch/msp430fr5994lp/driver/timed_resistive_load.h
blob: 4303636387348aa80ab4b4d761ae42a80855d513 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright 2020 Birte Kristina Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#ifndef TIMED_RESISTIVE_LOAD_H
#define TIMED_RESISTIVE_LOAD_H

/*
 * Resistance at 25°c
 * R1: 986R
 * R2: 3K25
 * R3: 46K3
 * R4: 9K86
 */

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

	public:
		TimedResistiveLoad() {}
		void setup();
		void switchToNone();
		void switchTo750(); // 576R (R1 || R2)
		void switchTo1K0(); // 986R (R1)
		void switchTo2K4(); // 2K44 (R2 || 4)
		void switchTo3K3(); // 3K25 (R2)
		void switchTo10K(); // 9K86 (R4)
		void switchTo47K(); // 46K3 (R3)

		/*
		 * These functions must be inline, as __delay_cycles only works with
		 * compile-time constants. So they must be part of the compilation unit
		 * which uses them and cannot easily be wrapped by a function without
		 * losing accuracy.
		 */

		inline void __attribute__((always_inline)) nop1K0(unsigned long long int const duration_us)
		{
			switchTo1K0();
			__delay_cycles(F_CPU / 1000000UL * duration_us);
			switchToNone();
		}

		inline void __attribute__((always_inline)) nop2K4(unsigned long long int const duration_us)
		{
			switchTo2K4();
			__delay_cycles(F_CPU / 1000000UL * duration_us);
			switchToNone();
		}

		inline void __attribute__((always_inline)) nop3K3(unsigned long long int const duration_us)
		{
			switchTo3K3();
			__delay_cycles(F_CPU / 1000000UL * duration_us);
			switchToNone();
		}

		inline void __attribute__((always_inline)) nop10K(unsigned long long int const duration_us)
		{
			switchTo10K();
			__delay_cycles(F_CPU / 1000000UL * duration_us);
			switchToNone();
		}

		inline void __attribute__((always_inline)) nop47K(unsigned long long int const duration_us)
		{
			switchTo47K();
			__delay_cycles(F_CPU / 1000000UL * duration_us);
			switchToNone();
		}
};

extern TimedResistiveLoad timedResistiveLoad;

#endif