Changeset 64e6945d in mainline


Ignore:
Timestamp:
2011-07-03T10:27:37Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ec62681
Parents:
dcb74c0a
Message:

Factor out bit operations from usbmast to bitops.h.

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmast/inquiry.c

    rdcb74c0a r64e6945d  
    3434 * Main routines of USB mass storage driver.
    3535 */
     36#include <bitops.h>
    3637#include <usb/dev/driver.h>
    3738#include <usb/debug.h>
     
    4546#include "cmds.h"
    4647#include "mast.h"
    47 
    48 #define BITS_GET_MASK(type, bitcount) (((type)(1 << (bitcount)))-1)
    49 #define BITS_GET_MID_MASK(type, bitcount, offset) \
    50         ((type)( BITS_GET_MASK(type, (bitcount) + (offset)) - BITS_GET_MASK(type, bitcount) ))
    51 #define BITS_GET(type, number, hi_bit, lo_bit) \
    52         ((type)( (number) & (BITS_GET_MID_MASK(type, (hi_bit)-(lo_bit)+1, lo_bit)) ) >> (lo_bit))
    5348
    5449/** Get string representation for SCSI peripheral device type.
     
    107102        bzero(inquiry_result, sizeof(*inquiry_result));
    108103
    109         inquiry_result->device_type = BITS_GET(uint8_t, inq_data.pqual_devtype,
    110             SCSI_PQDT_DEV_TYPE_h, SCSI_PQDT_DEV_TYPE_l);
     104        inquiry_result->device_type = BIT_RANGE_EXTRACT(uint8_t,
     105            inq_data.pqual_devtype, SCSI_PQDT_DEV_TYPE_h, SCSI_PQDT_DEV_TYPE_l);
    111106
    112         inquiry_result->removable = BITS_GET(uint8_t, inq_data.rmb,
    113             SCSI_RMB_RMB, SCSI_RMB_RMB);
     107        inquiry_result->removable = BIT_RANGE_EXTRACT(uint8_t,
     108            inq_data.rmb, SCSI_RMB_RMB, SCSI_RMB_RMB);
    114109
    115110        spascii_to_str(inquiry_result->vendor, SCSI_INQ_VENDOR_STR_BUFSIZE,
  • uspace/lib/c/include/bitops.h

    rdcb74c0a r64e6945d  
    3838#include <sys/types.h>
    3939
     40/** Mask with bit @a n set. */
     41#define BIT_V(type, n) \
     42    ((type)1 << ((n) - 1))
     43
     44/** Mask with rightmost @a n bits set. */
     45#define BIT_RRANGE(type, n) \
     46    (BIT_V(type, (n) + 1) - 1)
     47
     48/** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */
     49#define BIT_RANGE(type, hi, lo) \
     50    (BIT_RRANGE(type, (hi) - (lo) + 1) << (lo))
     51
     52/** Extract range of bits @a hi .. @a lo from @a value. */
     53#define BIT_RANGE_EXTRACT(type, hi, lo, value) \
     54    (((value) >> (lo)) & BIT_RRANGE(type, (hi) - (lo) + 1))
    4055
    4156/** Return position of first non-zero bit from left (i.e. [log_2(arg)]).
Note: See TracChangeset for help on using the changeset viewer.