5502879a5b
This is very much still work in progress and much more will change before the final 2.0.0 Some APIs have changed. New libraries have been added. LittleFS included. Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Mike Dunston <m_dunston@comcast.net> Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com> Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com> Co-authored-by: tobozo <tobozo@users.noreply.github.com> Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com> Co-authored-by: lorol <lorolouis@gmail.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net> Co-authored-by: Sweety <switi.mhaiske@espressif.com> Co-authored-by: Loick MAHIEUX <loick111@gmail.com> Co-authored-by: Larry Bernstone <lbernstone@gmail.com> Co-authored-by: Valerii Koval <valeros@users.noreply.github.com> Co-authored-by: 快乐的我531 <2302004040@qq.com> Co-authored-by: chegewara <imperiaonline4@gmail.com> Co-authored-by: Clemens Kirchgatterer <clemens@1541.org> Co-authored-by: Aron Rubin <aronrubin@gmail.com> Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
79 lines
2.0 KiB
C
79 lines
2.0 KiB
C
/*
|
|
* bits.h -- bit vector manipulation
|
|
*
|
|
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
|
*
|
|
* This file is part of the CoAP library libcoap. Please see README for terms
|
|
* of use.
|
|
*/
|
|
|
|
/**
|
|
* @file bits.h
|
|
* @brief Bit vector manipulation
|
|
*/
|
|
|
|
#ifndef COAP_BITS_H_
|
|
#define COAP_BITS_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
/**
|
|
* Sets the bit @p bit in bit-vector @p vec. This function returns @c 1 if bit
|
|
* was set or @c -1 on error (i.e. when the given bit does not fit in the
|
|
* vector).
|
|
*
|
|
* @param vec The bit-vector to change.
|
|
* @param size The size of @p vec in bytes.
|
|
* @param bit The bit to set in @p vec.
|
|
*
|
|
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
|
|
*/
|
|
COAP_STATIC_INLINE int
|
|
bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
|
|
if (size <= ((size_t)bit >> 3))
|
|
return -1;
|
|
|
|
*(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
* Clears the bit @p bit from bit-vector @p vec. This function returns @c 1 if
|
|
* bit was cleared or @c -1 on error (i.e. when the given bit does not fit in
|
|
* the vector).
|
|
*
|
|
* @param vec The bit-vector to change.
|
|
* @param size The size of @p vec in bytes.
|
|
* @param bit The bit to clear from @p vec.
|
|
*
|
|
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
|
|
*/
|
|
COAP_STATIC_INLINE int
|
|
bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
|
|
if (size <= ((size_t)bit >> 3))
|
|
return -1;
|
|
|
|
*(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
* Gets the status of bit @p bit from bit-vector @p vec. This function returns
|
|
* @c 1 if the bit is set, @c 0 otherwise (even in case of an error).
|
|
*
|
|
* @param vec The bit-vector to read from.
|
|
* @param size The size of @p vec in bytes.
|
|
* @param bit The bit to get from @p vec.
|
|
*
|
|
* @return @c 1 if the bit is set, @c 0 otherwise.
|
|
*/
|
|
COAP_STATIC_INLINE int
|
|
bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
|
|
if (size <= ((size_t)bit >> 3))
|
|
return -1;
|
|
|
|
return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
|
|
}
|
|
|
|
#endif /* COAP_BITS_H_ */
|