-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon_Macros.h
More file actions
43 lines (30 loc) · 1.31 KB
/
Common_Macros.h
File metadata and controls
43 lines (30 loc) · 1.31 KB
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
38
39
40
41
42
43
/******************************************************************************
*
* 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) ((*((volatile uint32 *)(REG)))|=(1<<(BIT)))
/* Clear a certain bit in any register */
#define CLEAR_BIT(REG,BIT) ((*((volatile uint32 *)(REG)))&=(~(1<<(BIT))))
/* Toggle a certain bit in any register */
#define TOGGLE_BIT(REG,BIT) ((*((volatile uint32 *)(REG)))^=(1<<(BIT)))
/* Rotate right the register value with specific number of rotates */
#define ROR(REG,num) ( REG= (REG>>num) | (REG<<(8-num)) )
/* Rotate left the register value with specific number of rotates */
#define ROL(REG,num) ( REG= (REG<<num) | (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)) )
#define WRITE_REG_32BIT(REG,value) (*((volatile uint32 *)(REG)))=value
#define READ_REG_32BIT(REG) (*((volatile uint32 *)(REG)))
#endif