/******************************************************************************
 *
 * Copyright 2013, Silicon Image, Inc.  All rights reserved.
 * No part of this work may be reproduced, modified, distributed, transmitted,
 * transcribed, or translated into any language or computer format, in any form
 * or by any means without written permission of
 * Silicon Image, Inc., 1140 East Arques Avenue, Sunnyvale, California 94085
 *
 *****************************************************************************/
/**
 * @file si_system_api.h
 *
 * @brief Generic system library interface
 *
 *****************************************************************************/
#ifndef SI_SYSTEM_API_H
#define SI_SYSTEM_API_H

/***** #include statements ***************************************************/

#include "si_datatypes.h"
#include "si_sys_log_api.h"
#include "si_sys_malloc_api.h"
#include "si_sys_obj_api.h"
#include "si_sys_time_api.h"

/***** public macro definitions **********************************************/

/* Construct to stringify defines */
#define SII_STRINGIFY(x)                 #x
#define SII_DEF2STR(x)                   SII_STRINGIFY(x)

//#if 0
/*
#ifdef SII_DEBUG
  #if (0 < SII_DEBUG)
    #define SII_MODULE_NAME_SET(name)    static const char* sSiiModuleNameStr = SII_DEF2STR(name)
    #define SII_MODULE_NAME_GET()        sSiiModuleNameStr
  #else
    #define SII_MODULE_NAME_SET(name)
    #define SII_MODULE_NAME_GET()        (NULL)
  #endif // (0 < SII_DEBUG)
#else
  #define SII_MODULE_NAME_SET(name)
  #define SII_MODULE_NAME_GET()          (NULL)
#endif // SII_DEBUG
//#endif
*/
/* Bit manipulation macros */
#define SII_SET_BIT(p, bit)              ( *(p) |= (1<<(bit)) )
#define SII_CLR_BIT(p, bit)              ( *(p) &= (~(1<<(bit))) )
#define SII_PUT_BIT(p, bit, b)           ( *(p) = (b) ? (*(p)|(1<<(bit))) : (*(p)&(~(1<<(bit)))) )
#define SII_MOD_BIT(p, msk, val)         ( *(p) = ((*(p))&(~(msk))) | ((val)&(msk)) )

#define SII_ABS_DIFF(A, B)               (((A)>(B)) ? ((A)-(B)) : ((B)-(A)))
#define SII_UINT_FRAC(num, den)          ( ((((num)<<1) / (den)) + 1) >> 1 )
#define SII_INT_FRAC(num, den)           ( (0>(((int)num)*((int)den))) ? ((((((int)num)*2)/((int)den))-1)/2) : ((((((int)num)*2)/((int)den))+1)/2) )
#define SII_FLOAT2INT(flt)               ( (0.0 > flt) ? ((int_t)(flt-0.5)) : ((int_t)(flt+0.5)) )

#endif  // SI_SYSTEM_API_H
