-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.h
More file actions
62 lines (51 loc) · 1.62 KB
/
global.h
File metadata and controls
62 lines (51 loc) · 1.62 KB
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
/*==============================================================================
Useful macros and global flags to keep track of state
=============================================================================*/
#ifndef GLOBAL_H
#define GLOBAL_H
/* ---------------------*/
/* Stand-in for bools */
/* ---------------------*/
#define TRUE 1
#define FALSE 0
/* ---------------- */
/* Bit Ops Macros */
/* ---------------- */
#define flip_1bit(REG, BIT_POS) (REG ^= (1 << BIT_POS))
#define sethigh_1bit(REG, BIT_POS) (REG |= (1 << BIT_POS))
#define setlow_1bit(REG, BIT_POS) (REG &= ~ (1 << BIT_POS))
#define set_1bit(REG, BIT_POS, VAL) (\
VAL ? sethigh_1bit(REG, BIT_POS) : setlow_1bit(REG, BIT_POS) \
)
#define set_1bit_hex(REG, BIT_POS, HEX) (\
set_1bit(REG, BIT_POS, HEX & (1 << BIT_POS)) \
)
/* ---------------------------------- */
/* GLOBAL flags and state variables */
/* ---------------------------------- */
/* Global flags */
struct GLOBAL_FLAGS {
/* True when uart has received a string (ended with '/r') */
uint8_t cmd_check:1;
/* True when valid command is executing */
uint8_t cmd_executed:1;
/* True when RX interrupt received */
uint8_t rx_int:1;
/* True when escape character received */
uint8_t esc_char:1;
/* True when [ received */
uint8_t bracket:1;
/* Dummy bits to fill up a byte */
uint8_t dummy:3;
};
volatile struct GLOBAL_FLAGS status;
/* context */
#define N_CONTEXT_TYPES 3
enum context_types
{
context_cli, context_manual, context_game
};
volatile uint8_t context;
/* error number */
int err_no;
#endif