Simple mbed library with macros

Dependents:   SimpleTimer SimpleUART SimpleTimer Stoppuhr1

Committer:
Alkorin
Date:
Sat Nov 13 23:20:15 2010 +0000
Revision:
14:23c6d41cb377
Parent:
10:0f79cde3f231
Child:
15:66150de7876b
Added website to license header

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alkorin 8:f8b47457fdcf 1 /*
Alkorin 8:f8b47457fdcf 2 * Copyright or © or Copr. 2010, Thomas SOETE
Alkorin 8:f8b47457fdcf 3 *
Alkorin 8:f8b47457fdcf 4 * Author e-mail: thomas@soete.org
Alkorin 14:23c6d41cb377 5 * Library website : http://mbed.org/users/Alkorin/libraries/SimpleLib/
Alkorin 8:f8b47457fdcf 6 *
Alkorin 8:f8b47457fdcf 7 * This software is governed by the CeCILL license under French law and
Alkorin 8:f8b47457fdcf 8 * abiding by the rules of distribution of free software. You can use,
Alkorin 8:f8b47457fdcf 9 * modify and/ or redistribute the software under the terms of the CeCILL
Alkorin 8:f8b47457fdcf 10 * license as circulated by CEA, CNRS and INRIA at the following URL
Alkorin 8:f8b47457fdcf 11 * "http://www.cecill.info".
Alkorin 8:f8b47457fdcf 12 *
Alkorin 8:f8b47457fdcf 13 * As a counterpart to the access to the source code and rights to copy,
Alkorin 8:f8b47457fdcf 14 * modify and redistribute granted by the license, users are provided only
Alkorin 8:f8b47457fdcf 15 * with a limited warranty and the software's author, the holder of the
Alkorin 8:f8b47457fdcf 16 * economic rights, and the successive licensors have only limited
Alkorin 8:f8b47457fdcf 17 * liability.
Alkorin 8:f8b47457fdcf 18 *
Alkorin 8:f8b47457fdcf 19 * In this respect, the user's attention is drawn to the risks associated
Alkorin 8:f8b47457fdcf 20 * with loading, using, modifying and/or developing or reproducing the
Alkorin 8:f8b47457fdcf 21 * software by the user in light of its specific status of free software,
Alkorin 8:f8b47457fdcf 22 * that may mean that it is complicated to manipulate, and that also
Alkorin 8:f8b47457fdcf 23 * therefore means that it is reserved for developers and experienced
Alkorin 8:f8b47457fdcf 24 * professionals having in-depth computer knowledge. Users are therefore
Alkorin 8:f8b47457fdcf 25 * encouraged to load and test the software's suitability as regards their
Alkorin 8:f8b47457fdcf 26 * requirements in conditions enabling the security of their systems and/or
Alkorin 8:f8b47457fdcf 27 * data to be ensured and, more generally, to use and operate it in the
Alkorin 8:f8b47457fdcf 28 * same conditions as regards security.
Alkorin 8:f8b47457fdcf 29 *
Alkorin 8:f8b47457fdcf 30 * The fact that you are presently reading this means that you have had
Alkorin 8:f8b47457fdcf 31 * knowledge of the CeCILL license and that you accept its terms.
Alkorin 8:f8b47457fdcf 32 */
Alkorin 8:f8b47457fdcf 33
Alkorin 5:b3aa0a49e21f 34 #ifndef __MBED_GLOBALS_H__
Alkorin 5:b3aa0a49e21f 35 #define __MBED_GLOBALS_H__
Alkorin 5:b3aa0a49e21f 36
Alkorin 5:b3aa0a49e21f 37 #include <LPC17xx.h>
Alkorin 5:b3aa0a49e21f 38
Alkorin 5:b3aa0a49e21f 39 /* GLOBALS MACRO */
Alkorin 5:b3aa0a49e21f 40 #define GET_REGISTER8(reg) *(volatile uint8_t *)(reg)
Alkorin 5:b3aa0a49e21f 41 #define GET_REGISTER16(reg) *(volatile uint16_t *)(reg)
Alkorin 5:b3aa0a49e21f 42 #define GET_REGISTER32(reg) *(volatile uint32_t *)(reg)
Alkorin 5:b3aa0a49e21f 43
Alkorin 5:b3aa0a49e21f 44 #define SET_REGISTER8(reg, val) *(uint8_t *)(reg)=(val)
Alkorin 5:b3aa0a49e21f 45 #define SET_REGISTER16(reg, val) *(uint16_t *)(reg)=(val)
Alkorin 5:b3aa0a49e21f 46 #define SET_REGISTER32(reg, val) *(uint32_t *)(reg)=(val)
Alkorin 5:b3aa0a49e21f 47
Alkorin 5:b3aa0a49e21f 48 // See 34.3.2.5 p740
Alkorin 5:b3aa0a49e21f 49 #define BIT_BANDING_ADDRESS(reg, bit) (((reg) & 0xF0000000) | (0x02000000) | (((reg) & 0x000FFFFF) << 5) | ((bit) << 2))
Alkorin 6:9e1310782abf 50 #define GET_BIT_ADDRESS(reg, bit) BIT_BANDING_ADDRESS(((uint32_t)&(reg)), (bit))
Alkorin 6:9e1310782abf 51 #define GET_BIT_VALUE(reg, bit) GET_REGISTER32(GET_BIT_ADDRESS((reg), (bit)))
Alkorin 6:9e1310782abf 52 #define SET_BIT_VALUE(reg, bit, value) SET_REGISTER32(GET_BIT_ADDRESS((reg), (bit)), (value))
Alkorin 5:b3aa0a49e21f 53
Alkorin 5:b3aa0a49e21f 54 // Macro tools
Alkorin 5:b3aa0a49e21f 55 #define TOKENPASTE(x, y) x ## y
Alkorin 5:b3aa0a49e21f 56 #define TOKENPASTE2(x, y) TOKENPASTE(x, y)
Alkorin 5:b3aa0a49e21f 57 #define TOKENPASTE3(x, y, z) TOKENPASTE(TOKENPASTE(x, y), z)
Alkorin 5:b3aa0a49e21f 58
Alkorin 10:0f79cde3f231 59 // Extern C
Alkorin 10:0f79cde3f231 60 #ifdef __cplusplus
Alkorin 10:0f79cde3f231 61 #define EXTERN_C extern "C"
Alkorin 10:0f79cde3f231 62 #else
Alkorin 10:0f79cde3f231 63 #define EXTERN_C
Alkorin 10:0f79cde3f231 64 #endif
Alkorin 10:0f79cde3f231 65
Alkorin 10:0f79cde3f231 66
Alkorin 0:aa3c3d1a5918 67 #endif