riscv: integrated wcn code for rtos kernel into rtos sdk. [4/10]

PD#SWPL-154565

Problem:
integrated wcn code for rtos kernel into rtos sdk.

Solution:
integrated wcn code for rtos kernel into rtos sdk.

Verify:
N/A

Change-Id: I35de2185562fc387bdc8529bd36e2f4c8cecdfa1
Signed-off-by: xiaohu.huang <xiaohu.huang@amlogic.com>
diff --git a/common.h b/common.h
index b80d19b..ea30186 100644
--- a/common.h
+++ b/common.h
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier: MIT
  */
 
-#ifndef __COMMON_H
-#define __COMMON_H
+#ifndef __COMMON_H__
+#define __COMMON_H__
 
 #ifdef __cplusplus
 extern "C" {
@@ -22,15 +22,26 @@
 #define REG16(addr) (*REG16_ADDR(addr))
 #define REG8(addr) (*REG8_ADDR(addr))
 
-#define BIT(nr) (1UL << (nr))
-#define REG32_UPDATE_BITS(addr, mask, val)                \
-	do {                                              \
-		uint32_t _v = REG32((unsigned long)addr); \
-		_v &= (~(mask));                          \
-		_v |= ((val) & (mask));                   \
-		REG32((unsigned long)addr) = _v;          \
+#define REG32_SET_BITS(addr, bits)                  \
+    do {                                            \
+        REG32(addr) = REG32(addr) | (bits);         \
+    } while(0)
+
+#define REG32_CLR_BITS(addr, bits)                  \
+    do {                                            \
+        REG32(addr) = REG32(addr) & (~(bits));      \
+    } while(0)                                      \
+
+#define REG32_UPDATE_BITS(addr, mask, val)          \
+	do {                                            \
+		uint32_t _v = REG32((unsigned long)addr);   \
+		_v &= (~(mask));                            \
+		_v |= ((val) & (mask));                     \
+		REG32((unsigned long)addr) = _v;            \
 	} while (0)
 
+#define BIT(nr) (1UL << (nr))
+
 static inline int generic_ffs(int x)
 {
 	int r = 1;
@@ -72,19 +83,28 @@
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 #define BITS_PER_LONG (sizeof(unsigned long) == 8 ? 64 : 32)
+
 #define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
 #define IS_ALIGNED(x, a) (((unsigned long)(x) & ((unsigned long)(a)-1)) == 0)
+
 #define _RET_IP_ ((unsigned long)__builtin_return_address(0))
+
 #define _THIS_IP_                        \
 	({                               \
 		__label__ __here;        \
 __here:                          \
 		(unsigned long)&&__here; \
 	})
+
 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
 #define round_up(x, y) ((((x)-1) | __round_mask(x, y)) + 1)
 #define round_down(x, y) ((x) & ~__round_mask(x, y))
 
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
+
 typedef uint64_t u64;
 typedef uint32_t u32;
 typedef uint16_t u16;
@@ -104,10 +124,16 @@
 	uint32_t mepc;	   /* machine exception program counter */
 };
 
-#ifndef BIT
-#define BIT(x) (1 << (x))
+#ifdef __ASSEMBLER__
+#define _AC(X, Y) X
+#define _AT(T, X) X
+#else
+#define _AC(X, Y) (X##Y)
+#define _AT(T, X) ((T)(X))
 #endif
 
+#define UNUSED_PARAM(X)     ((void)X)
+
 #ifdef __cplusplus
 }
 #endif