-
Notifications
You must be signed in to change notification settings - Fork 1
/
Common_Macros.h
37 lines (28 loc) · 1.17 KB
/
Common_Macros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/******************************************************************************
*
* Module: Common - Macros
*
* File Name: Common_Macros.h
*
* Description: Commonly used Macros
*
* Author: Mohamed Tarek
*
*******************************************************************************/
#ifndef COMMON_MACROS
#define COMMON_MACROS
/* Set a certain bit in any register */
#define SET_BIT(REG,BIT) (REG|=(1<<BIT))
/* Clear a certain bit in any register */
#define CLEAR_BIT(REG,BIT) (REG&=(~(1<<BIT)))
/* Toggle a certain bit in any register */
#define TOGGLE_BIT(REG,BIT) (REG^=(1<<BIT))
/* Rotate right the register value with specific number of rotates */
#define ROR(REG,num) ( REG = (REG>>num) | (REG << ((sizeof(REG) * 8)-num)) )
/* Rotate left the register value with specific number of rotates */
#define ROL(REG,num) ( REG = (REG<<num) | (REG >> ((sizeof(REG) * 8)-num)) )
/* Check if a specific bit is set in any register and return true if yes */
#define BIT_IS_SET(REG,BIT) ( REG & (1<<BIT) )
/* Check if a specific bit is cleared in any register and return true if yes */
#define BIT_IS_CLEAR(REG,BIT) ( !(REG & (1<<BIT)) )
#endif