2015-06-05 01:46:25 +00:00
|
|
|
/* Some common compiler macros
|
2015-05-30 09:11:04 +00:00
|
|
|
*
|
2015-06-05 01:46:25 +00:00
|
|
|
* Not esp8266-specific.
|
2015-05-30 09:11:04 +00:00
|
|
|
*
|
2015-06-02 05:06:40 +00:00
|
|
|
* Part of esp-open-rtos
|
2015-06-05 01:46:25 +00:00
|
|
|
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
2015-05-30 09:11:04 +00:00
|
|
|
* BSD Licensed as described in the file LICENSE
|
|
|
|
*/
|
|
|
|
|
2015-06-05 01:46:25 +00:00
|
|
|
#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))
|
2015-06-05 01:46:25 +00:00
|
|
|
#endif
|
2015-05-30 09:11:04 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2015-08-26 00:07:06 +00:00
|
|
|
#define VAL2FIELD(fieldname, value) ((value) << fieldname##_S)
|
2015-08-19 00:38:31 +00:00
|
|
|
#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
|
|
|
|
2015-08-26 00:07:06 +00:00
|
|
|
/* VAL2FIELD/SET_FIELD do not normally check to make sure that the passed value
|
|
|
|
* will fit in the specified field (without clobbering other bits). This makes
|
|
|
|
* them faster and is usually fine. If you do need to make sure that the value
|
|
|
|
* will not overflow the field, use VAL2FIELD_M or SET_FIELD_M (which will
|
|
|
|
* first mask the supplied value to only the allowed number of bits) instead.
|
|
|
|
*/
|
|
|
|
#define VAL2FIELD_M(fieldname, value) (((value) & fieldname##_M) << fieldname##_S)
|
|
|
|
#define SET_FIELD_M(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD_M(fieldname, value))
|
|
|
|
|
2015-05-30 09:11:04 +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-07-30 17:34:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define IROM __attribute__((section(".irom0.literal")))
|
|
|
|
#else
|
|
|
|
#define IROM __attribute__((section(".irom0.literal"))) const
|
|
|
|
#endif
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-06-05 01:46:25 +00:00
|
|
|
#define INLINED inline static __attribute__((always_inline)) __attribute__((unused))
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-06-08 07:54:46 +00:00
|
|
|
#define IRAM __attribute__((section(".iram1.text")))
|
|
|
|
|
2015-05-30 09:11:04 +00:00
|
|
|
#endif
|