aboutsummaryrefslogtreecommitdiff
path: root/include/zeta.h
blob: 291a2ff49099f2b19a20bd920285ca274b79b1c8 (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
#ifndef ZETA_H
#define ZETA_H

#include <stdint.h>
#include <stdbool.h>

typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))

// Corrent version, but the compiler does not recognize this as a constant
// expression
// #define ISR_ADDRESS(x) (((u16)&x) & 0xFF)
#define ISR_ADDRESS(x) ((u16)&x)

extern void *rx_isr_ptr;
extern void *ctc0_isr_ptr;
extern void *ctc1_isr_ptr;
extern void *ctc2_isr_ptr;
extern void *ctc3_isr_ptr;
extern void *port_a_isr_ptr;
extern void *port_b_isr_ptr;

void
bootloader(void);

uint16_t
crc16(const void *buf, size_t len);

void
_menu(void);

static inline int
max(int a, int b)
{
	return a > b ? a : b;
}

static inline int
min(int a, int b)
{
	return a < b ? a : b;
}

static inline int
clamp(int v, int low, int high)
{
	return min(max(v, low), high);
}

static inline uint8_t
bcd(uint8_t x)
{
	return ((x / 10) << 4) | (x % 10);
}

#endif // ZETA_H