/** * @file GenMac.h * @brief Definition of general macros and bit manipulations. * @note * * ------------------------------------------------------------------ Copyright (c) 2023 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE. IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ */ #ifndef GENMAC_H_ #define GENMAC_H_ /** * @brief Defining TRUE */ #define TRUE 1 /** * @brief Defining true */ #ifndef true #define true TRUE #endif /** * @brief defining BUSY flag */ #define BUSY 1 /** * @brief Defining FALSE */ #define FALSE 0 /** * @brief Defining false */ #ifndef false #define false FALSE #endif /** * @brief Defining HIGH */ #define HIGH 1 /** * @brief Defining LOW */ #define LOW 0 /** * @brief Defining ENABLE */ #define ENABLE 1 /** * @brief Defining DISABLE */ #define DISABLE 0 /** * @brief Defining ON */ #define ON 1 /** * @brief Defining OFF */ #define OFF 0 /* a=target variable, b=bit number to act upon 0-n */ /** * @brief Set the bth bit of variable a */ #define BIT_SET(a,b) ((a) |= (1ULL<<(b))) /** * @brief Clear the bth bit of variabl a */ #define BIT_CLR(a,b) ((a) &= ~(1ULL<<(b))) /** * @brief Flip or toggle bth bit of variable a */ #define BIT_FLIP(a,b) ((a) ^= (1ULL<<(b))) /** * @brief Check for the bth bit of variable a */ #define BIT_CHECK(a,b) ((a) & (1ULL<<(b))) /* x=target variable, y=mask */ /** * @brief SET the mask y in the variable x */ #define BITMASK_SET(x,y) ((x) |= (y)) /** * @brief Clear the mask y in the variable x */ #define BITMASK_CLR(x,y) ((x) &= (~(y))) /** * @brief Flip or toggle the mask y from variable x */ #define BITMASK_FLIP(x,y) ((x) ^= (y)) /** * @brief Check for all the bits in mask y from variable x. * @warning, it evaluates the y twice. */ #define BITMASK_CHECK_ALL(x,y) (((x) & (y)) == (y)) /** * @brief Check for any bit in the mask y from variable x. */ #define BITMASK_CHECK_ANY(x,y) ((x) & (y)) /** * @brief Defining WEAK as attribute for weak functions. These functions can * be defined using normal definitions in application code. The normal * definition will override the definition from here. */ #ifndef WEAK #define WEAK __attribute__ ((weak)) #endif #endif /* GENMAC_H_ */