📄 bitset.h
字号:
/** * Copyright (c) 2006-2008 iWESUN (ShenZhen) Inf. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the AvrcX MTOS * * Author: Winter Hu <winter.hu@gmail.com> * Create: Nov 25, 2006 * */#ifndef __BITSET_H__#define __BITSET_H__#include "common.h"#ifndef __ASSEMBLER__/* These only work in C program */typedef struct BitSet { __volatile__ unsigned char bits; __volatile__ unsigned char bytes; unsigned char *data;} BitSet;/** * A macro to ease the declaration of BetSet definition. * USAGE: BITSET(flags, 16); * * @param name, The name of the BitSet * @param mxsize, The max capability of the BitSet */#define BITSET(name, mxsize) \ unsigned char name##_bits[((mxsize-1)>>3)+1]; \ BitSet name = { \ mxsize, \ ((mxsize-1)>>3)+1, \ &name##_bits[0] \ }/** * Set specified bit to 1 * * @param BitSet*, The pointer to the BitSet * @param unsigned char, The bit index */INTERFACE void set_bit(BitSet*, unsigned char);/** * Set specified bit to 0 * * @param BitSet*, The pointer to the BitSet * @param unsigned char, The bit index */INTERFACE void clr_bit(BitSet*, unsigned char);/** * Filp specified bit * * @param BitSet*, The pointer to the BitSet * @param unsigned char, The bit index */INTERFACE void filp_bit(BitSet*, unsigned char);/** * Clear all bits to 0 * * @param BitSet*, The pointer to the BitSet * @param unsigned char, The bit index */INTERFACE void clear_bits(BitSet*);/** * Get specified bit * * @param BitSet*, The pointer to the BitSet * @param unsigned char, The bit index * @return bool the bit value */INTERFACE bool get_bit(BitSet*, unsigned char);/** * Return the number of bits set to 1 * * @param BitSet*, The pointer to the BitSet * @return unsigned char, The number of bits set to 1 */INTERFACE unsigned char count_bits(BitSet*);#endif /* !__ASSEMBLER__ */#endif /* __BITSET_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -