esp-open-rtos/core/include/common_macros.h

46 lines
1.4 KiB
C
Raw Normal View History

/* Some common compiler macros
*
* Not esp8266-specific.
*
* Part of esp-open-rtos
* Copyright (C) 2015 Superhouse Automation Pty Ltd
* BSD Licensed as described in the file LICENSE
*/
#ifndef _COMMON_MACROS_H
#define _COMMON_MACROS_H
#define UNUSED __attributed((unused))
#ifndef BIT
2015-06-17 23:00:02 +00:00
#define BIT(X) (1<<(X))
#endif
2015-08-19 00:38:31 +00:00
/* These macros convert values to/from bitfields specified by *_M and *_S (mask
* and shift) constants. Used primarily with ESP8266 register access.
*/
#define VAL2FIELD(fieldname, value) (((value) & fieldname##_M) << fieldname##_S)
#define FIELD2VAL(fieldname, regbits) (((regbits) >> fieldname##_S) & fieldname##_M)
2015-08-19 05:46:25 +00:00
#define FIELD_MASK(fieldname) (fieldname##_M << fieldname##_S)
#define SET_FIELD(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD(fieldname, value))
2015-08-19 00:38:31 +00:00
/* Use this macro to store constant values in IROM flash instead
of having them loaded into rodata (which resides in DRAM)
Unlike the ESP8266 SDK you don't need an attribute like this for
standard functions. They're stored in flash by default. But
variables need them.
Important to note: IROM flash can only be accessed via 32-bit word
aligned reads. It's up to the user of this attribute to ensure this.
*/
2015-06-08 07:58:10 +00:00
#define IROM __attribute__((section(".irom0.literal"))) const
#define INLINED inline static __attribute__((always_inline)) __attribute__((unused))
#define IRAM __attribute__((section(".iram1.text")))
#endif