libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
common.h
Go to the documentation of this file.
1 /*
2  * This file is part of the libopencm3 project.
3  *
4  * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBOPENCM3_CM3_COMMON_H
21 #define LIBOPENCM3_CM3_COMMON_H
22 
23 #ifdef __cplusplus
24 /* Declarations need wrapping for C++ */
25 # define BEGIN_DECLS extern "C" {
26 # define END_DECLS }
27 #elif defined(__ASSEMBLER__)
28 /* skipping for assembly */
29 #define BEGIN_DECLS .if 0
30 #define END_DECLS .endif
31 #else
32 /* And nothing for C */
33 # define BEGIN_DECLS
34 # define END_DECLS
35 #endif
36 
37 /* Full-featured deprecation attribute with fallback for older compilers. */
38 
39 #ifdef __GNUC__
40 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)
41 # define LIBOPENCM3_DEPRECATED(x) __attribute__((deprecated(x)))
42 # else
43 # define LIBOPENCM3_DEPRECATED(x) __attribute__((deprecated))
44 # endif
45 #else
46 # define LIBOPENCM3_DEPRECATED(x)
47 #endif
48 
49 
50 #if defined (__ASSEMBLER__)
51 #define MMIO8(addr) (addr)
52 #define MMIO16(addr) (addr)
53 #define MMIO32(addr) (addr)
54 #define MMIO64(addr) (addr)
55 
56 #define BBIO_SRAM(addr, bit) \
57  (((addr) & 0x0FFFFF) * 32 + 0x22000000 + (bit) * 4)
58 
59 #define BBIO_PERIPH(addr, bit) \
60  (((addr) & 0x0FFFFF) * 32 + 0x42000000 + (bit) * 4)
61 #else
62 
63 #include <stdint.h>
64 #include <stdbool.h>
65 
66 /* Generic memory-mapped I/O accessor functions */
67 #define MMIO8(addr) (*(volatile uint8_t *)(addr))
68 #define MMIO16(addr) (*(volatile uint16_t *)(addr))
69 #define MMIO32(addr) (*(volatile uint32_t *)(addr))
70 #define MMIO64(addr) (*(volatile uint64_t *)(addr))
71 
72 /* Generic bit-band I/O accessor functions */
73 #define BBIO_SRAM(addr, bit) \
74  MMIO32((((uint32_t)addr) & 0x0FFFFF) * 32 + 0x22000000 + (bit) * 4)
75 
76 #define BBIO_PERIPH(addr, bit) \
77  MMIO32((((uint32_t)addr) & 0x0FFFFF) * 32 + 0x42000000 + (bit) * 4)
78 #endif
79 
80 /* Generic bit definition */
81 #define BIT0 (1<<0)
82 #define BIT1 (1<<1)
83 #define BIT2 (1<<2)
84 #define BIT3 (1<<3)
85 #define BIT4 (1<<4)
86 #define BIT5 (1<<5)
87 #define BIT6 (1<<6)
88 #define BIT7 (1<<7)
89 #define BIT8 (1<<8)
90 #define BIT9 (1<<9)
91 #define BIT10 (1<<10)
92 #define BIT11 (1<<11)
93 #define BIT12 (1<<12)
94 #define BIT13 (1<<13)
95 #define BIT14 (1<<14)
96 #define BIT15 (1<<15)
97 #define BIT16 (1<<16)
98 #define BIT17 (1<<17)
99 #define BIT18 (1<<18)
100 #define BIT19 (1<<19)
101 #define BIT20 (1<<20)
102 #define BIT21 (1<<21)
103 #define BIT22 (1<<22)
104 #define BIT23 (1<<23)
105 #define BIT24 (1<<24)
106 #define BIT25 (1<<25)
107 #define BIT26 (1<<26)
108 #define BIT27 (1<<27)
109 #define BIT28 (1<<28)
110 #define BIT29 (1<<29)
111 #define BIT30 (1<<30)
112 #define BIT31 (1<<31)
113 
114 #endif