-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmat91lib.h
67 lines (50 loc) · 1.27 KB
/
mat91lib.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
57
58
59
60
61
62
63
64
65
66
67
/** @file mat91lib.h
@author M. P. Hayes, UCECE
@date 23 March 2008
@brief Datatypes and macros required for mat91lib.
*/
#ifndef MAT91LIB_H
#define MAT91LIB_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#ifndef BIT
#define BIT(X) (1U << (X))
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(ARRAY) (sizeof(ARRAY) / sizeof (ARRAY[0]))
#endif
#ifndef __UNUSED__
#define __UNUSED__ __attribute__ ((unused))
#endif
#ifndef __unused__
#define __unused__ __attribute__ ((unused))
#endif
#ifndef __always_inline__
#define __always_inline__ inline __attribute__ ((always_inline))
#endif
#ifndef _DOXYGEN_
#define __packed__ __attribute__((packed))
#else
#define __packed__
#endif
#if defined (__SAM7__)
#include "sam7.h"
#elif defined (__SAM4S__)
#include "sam4s.h"
#else
#error "MCU family not defined"
#endif
#define F_CPU_UL ((unsigned long)F_CPU)
#define LOG2_1(n) (((n) >= 2) ? 1 : 0)
#define LOG2_2(n) (((n) >= 1 << 2) ? (2 + LOG2_1((n) >> 2)) : LOG2_1(n))
#define LOG2_4(n) (((n) >= 1 << 4) ? (4 + LOG2_2((n) >> 4)) : LOG2_2(n))
#define LOG2_8(n) (((n) >= 1 << 8) ? (8 + LOG2_4((n) >> 8)) : LOG2_4(n))
#define LOG2(n) (((n) >= 1 << 16) ? (16 + LOG2_8((n) >> 16)) : LOG2_8(n))
#ifdef __cplusplus
}
#endif
#endif