MacLO/src/Common.h

38 lines
924 B
C
Raw Permalink Normal View History

2021-10-11 18:11:48 +00:00
// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
2021-12-07 19:07:28 +00:00
/**
* @file Common.h
*
* This file includes some common utility functions and macros.
*/
2021-10-11 18:11:48 +00:00
#ifndef COMMON_H
#define COMMON_H
#include "stdbool.h"
#include "stdint.h"
2021-12-07 19:07:28 +00:00
/** Get the minimum of a and b. */
2021-10-11 18:11:48 +00:00
#define min(a,b) ((a)<(b)?(a):(b))
2021-12-07 19:07:28 +00:00
/** Get the maximum of a and b. */
2021-10-11 18:11:48 +00:00
#define max(a,b) ((a)>(b)?(a):(b))
2021-12-07 19:07:28 +00:00
/** Gets the bit within value. */
2021-10-11 18:11:48 +00:00
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
2021-12-07 19:07:28 +00:00
/** Sets the bit within value. */
2021-10-11 18:11:48 +00:00
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
2021-12-07 19:07:28 +00:00
/** Clears the bit within value. */
2021-10-11 18:11:48 +00:00
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
2021-12-07 19:07:28 +00:00
/** Toggles the bit within value. */
2021-10-11 18:11:48 +00:00
#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
2021-12-07 19:07:28 +00:00
/** Sets the bit within value to bitValue. */
2021-12-08 22:35:06 +00:00
#define bitWrite(value, bit, bitValue) ((bitValue) ? bitSet(value, bit) : bitClear(value, bit))
2021-10-11 18:11:48 +00:00
#endif