openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

generic.h (1212B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        generic.h
      8  * Purpose:     Generic defines, based only on C types.
      9  */
     10 
     11 #ifndef   _SAL_GENERIC_H_
     12 #define   _SAL_GENERIC_H_
     13 
     14 /*
     15  * Create a mask given the width and shift.
     16  * The width must be <= 32.
     17  * The mask is "in place", that is, is shifted accordingly.
     18  */
     19 #define SAL_MASK_MAKE(width, shift)  \
     20     ((((1 << (width)) - 1) | (1 << (width - 1))) << (shift))
     21 
     22 /*
     23  * Extract a field given the value, mask and shift.
     24  * The mask is assumed to be "in place" -- already shifted.
     25  * That is, it is from SAL_MASK_MAKE.
     26  */
     27 #define SAL_MASK_VAL_GET(val, mask, shift) (((val) & (mask)) >> (shift))
     28 
     29 /*
     30  * Set a field given the current value (val),
     31  * field value (fval) mask and shift.
     32  * The mask is assumed to be "in place" -- already shifted.
     33  * That is, it is from SAL_MASK_MAKE.
     34  */
     35 #define SAL_MASK_VAL_SET(val, fval, mask, shift) \
     36         do { \
     37             (val) &= (~(mask)); \
     38             (val) |= (((fval) << (shift)) & (mask)); \
     39         } while (0)
     40 
     41 #endif /* _SAL_GENERIC_H_ */