/************************************************************************* File name : util.h Module : common Author : Copyright : Version : 0.1 Created on : 2022-08-18 Creator : amir.liang Description : utils Modify History: 1. Date: Author: Modification: ***************************************************************************/ #ifndef __UTIL_H__ #define __UTIL_H__ #include #ifndef OK #define OK (uint8_t)(0) #endif #ifndef NG #define NG (uint8_t)(1) #endif #ifndef MAX_PATH #define MAX_PATH (256) #endif #ifndef MIN #define MIN(x,y) (((x)<(y))?(x):(y)) #endif #ifndef MAX #define MAX(x,y) (((x)>(y))?(x):(y)) #endif #define SET_BITS(value, bits) ((value) | (bits)) #define CLEAR_BITS(value, bits) ((value) & ~(bits)) #define CHECK_BITS(value, bits) ((value) & (bits)) #define TOGGLE_BITS(value, bits) ((value) ^ (bits)) // note: 'a' must be align 2 #define ROUNDUP(x, a) (((x) + (a)-1) & ~((a)-1)) // ALIGN(x, a) #define CHECK_SAME(a, b) ({\ if ( a != b ){\ hloge("%s [%d]!=[%d], fail.", __func__, a, b); \ }; a==b;}) #define CHECK_SAME_RETURN(a, b) ({if (!CHECK_SAME(a, b) ){ return NG;}}) #define CHECK_NULL(who, val) ({if(!val){hloge("%s %s is null param", __func__, who);}; val;}) #define CHECK_NULL_RETURN(who, val) if (!CHECK_NULL(who, val)){return NULL;} #define CHECK_LESS_RETURN(who, val) if(who