-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
56 lines (42 loc) · 1.28 KB
/
main.h
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
/**
* Copyright (c) 2018, Tiny Mesh AS - https://tiny-mesh.com
* All rights reserved.
*/
#ifndef MAIN_H_
#define MAIN_H_
#include "event-queue.h"
#include "debug.h"
#define PROCESS(name, _ev) void name(event _ev)
#define PROCESS_BEGIN() PRINT("PROCESS - start process\n")
#define PROCESS_YIELD(_cond) { \
if (1 == (_cond)) \
return; \
}
#define PROCESS_WAIT_FOR_EVENT(t) { \
if (0 == queue_peek().type || t != queue_peek().type) \
return; \
}
#define PROCESS_END() PRINT("PROCESS - end process\n")
#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int))
#define PROCESS_REGISTER(__name__, ...) void (*__name__[ NUMARGS(__VA_ARGS__) ])() = ##__VA_ARGS__
#define NUMTASKS(t) (sizeof(t) / sizeof(t[0]))
/**
* Called when byte is received on the UART
*
* Return 1 if data was successfully accepted, zero otherwise
*/
extern int recv_byte(unsigned char c);
/**
* Prepare to receive a packet
*/
extern void reset_input(void);
/**
* Write a single byte to UART, returns 1 if write was successful and 0
* if write failed.
*/
extern int write_byte(char c);
/**
* Enable raw mode for termios (read: linux) terminals
*/
extern void set_term_raw(void);
#endif /* MAIN_H_ */