bsp.h
Go to the documentation of this file.
1 /********************************************************************************************************
2  * @file bsp.h
3  *
4  * @brief This is the header file for TLSR8258
5  *
6  * @author Driver Group
7  * @date May 8, 2018
8  *
9  * @par Copyright (c) 2018, Telink Semiconductor (Shanghai) Co., Ltd.
10  * All rights reserved.
11  *
12  * The information contained herein is confidential property of Telink
13  * Semiconductor (Shanghai) Co., Ltd. and is available under the terms
14  * of Commercial License Agreement between Telink Semiconductor (Shanghai)
15  * Co., Ltd. and the licensee or the terms described here-in. This heading
16  * MUST NOT be removed from this file.
17  *
18  * Licensees are granted free, non-transferable use of the information in this
19  * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
20  * @par History:
21  * 1.initial release(DEC. 26 2018)
22  *
23  * @version A001
24  *
25  *******************************************************************************************************/
26 #ifndef BSP_H_
27 #define BSP_H_
28 
29 #include "compiler.h"
33 #define BIT(n) ( 1<<(n) )
34 #define BIT_MASK_LEN(len) (BIT(len)-1)
35 #define BIT_RNG(s, e) (BIT_MASK_LEN((e)-(s)+1) << (s))
36 
37 #define BM_CLR_MASK_V(x, mask) ( (x) & ~(mask) )
38 
39 #define BM_SET(x, mask) ( (x) |= (mask) )
40 #define BM_CLR(x, mask) ( (x) &= ~(mask) )
41 #define BM_IS_SET(x, mask) ( (x) & (mask) )
42 #define BM_IS_CLR(x, mask) ( (~x) & (mask) )
43 #define BM_FLIP(x, mask) ( (x) ^= (mask) )
44 
49 // Return the bit index of the lowest 1 in y. ex: 0b00110111000 --> 3
50 #define BIT_LOW_BIT(y) (((y) & BIT(0))?0:(((y) & BIT(1))?1:(((y) & BIT(2))?2:(((y) & BIT(3))?3: \
51  (((y) & BIT(4))?4:(((y) & BIT(5))?5:(((y) & BIT(6))?6:(((y) & BIT(7))?7: \
52  (((y) & BIT(8))?8:(((y) & BIT(9))?9:(((y) & BIT(10))?10:(((y) & BIT(11))?11: \
53  (((y) & BIT(12))?12:(((y) & BIT(13))?13:(((y) & BIT(14))?14:(((y) & BIT(15))?15: \
54  (((y) & BIT(16))?16:(((y) & BIT(17))?17:(((y) & BIT(18))?18:(((y) & BIT(19))?19: \
55  (((y) & BIT(20))?20:(((y) & BIT(21))?21:(((y) & BIT(22))?22:(((y) & BIT(23))?23: \
56  (((y) & BIT(24))?24:(((y) & BIT(25))?25:(((y) & BIT(26))?26:(((y) & BIT(27))?27: \
57  (((y) & BIT(28))?28:(((y) & BIT(29))?29:(((y) & BIT(30))?30:(((y) & BIT(31))?31:32 \
58  ))))))))))))))))))))))))))))))))
59 
60 // Return the bit index of the highest 1 in (y). ex: 0b00110111000 --> 8
61 #define BIT_HIGH_BIT(y) (((y) & BIT(31))?31:(((y) & BIT(30))?30:(((y) & BIT(29))?29:(((y) & BIT(28))?28: \
62  (((y) & BIT(27))?27:(((y) & BIT(26))?26:(((y) & BIT(25))?25:(((y) & BIT(24))?24: \
63  (((y) & BIT(23))?23:(((y) & BIT(22))?22:(((y) & BIT(21))?21:(((y) & BIT(20))?20: \
64  (((y) & BIT(19))?19:(((y) & BIT(18))?18:(((y) & BIT(17))?17:(((y) & BIT(16))?16: \
65  (((y) & BIT(15))?15:(((y) & BIT(14))?14:(((y) & BIT(13))?13:(((y) & BIT(12))?12: \
66  (((y) & BIT(11))?11:(((y) & BIT(10))?10:(((y) & BIT(9))?9:(((y) & BIT(8))?8: \
67  (((y) & BIT(7))?7:(((y) & BIT(6))?6:(((y) & BIT(5))?5:(((y) & BIT(4))?4: \
68  (((y) & BIT(3))?3:(((y) & BIT(2))?2:(((y) & BIT(1))?1:(((y) & BIT(0))?0:32 \
69  ))))))))))))))))))))))))))))))))
70 
71 #define COUNT_ARGS_IMPL2(_1, _2, _3, _4, _5, _6, _7, _8 , _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, N, ...) N
72 #define COUNT_ARGS_IMPL(args) COUNT_ARGS_IMPL2 args
73 #define COUNT_ARGS(...) COUNT_ARGS_IMPL((__VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
74 
75 #define MACRO_CHOOSE_HELPER2(base, count) base##count
76 #define MACRO_CHOOSE_HELPER1(base, count) MACRO_CHOOSE_HELPER2(base, count)
77 #define MACRO_CHOOSE_HELPER(base, count) MACRO_CHOOSE_HELPER1(base, count)
78 
79 #define MACRO_GLUE(x, y) x y
80 #define VARARG(base, ...) MACRO_GLUE(MACRO_CHOOSE_HELPER(base, COUNT_ARGS(__VA_ARGS__)),(__VA_ARGS__))
81 
82 #define MV(m, v) (((v) << BIT_LOW_BIT(m)) & (m))
83 
84 // warning MASK_VALn are internal used macro, please use MASK_VAL instead
85 #define MASK_VAL2(m, v) (MV(m,v))
86 #define MASK_VAL4(m1,v1,m2,v2) (MV(m1,v1)|MV(m2,v2))
87 #define MASK_VAL6(m1,v1,m2,v2,m3,v3) (MV(m1,v1)|MV(m2,v2)|MV(m3,v3))
88 #define MASK_VAL8(m1,v1,m2,v2,m3,v3,m4,v4) (MV(m1,v1)|MV(m2,v2)|MV(m3,v3)|MV(m4,v4))
89 #define MASK_VAL10(m1,v1,m2,v2,m3,v3,m4,v4,m5,v5) (MV(m1,v1)|MV(m2,v2)|MV(m3,v3)|MV(m4,v4)|MV(m5,v5))
90 #define MASK_VAL12(m1,v1,m2,v2,m3,v3,m4,v4,m5,v5,m6,v6) (MV(m1,v1)|MV(m2,v2)|MV(m3,v3)|MV(m4,v4)|MV(m5,v5)|MV(m6,v6))
91 #define MASK_VAL14(m1,v1,m2,v2,m3,v3,m4,v4,m5,v5,m6,v6,m7,v7) (MV(m1,v1)|MV(m2,v2)|MV(m3,v3)|MV(m4,v4)|MV(m5,v5)|MV(m6,v6)|MV(m7,v7))
92 #define MASK_VAL16(m1,v1,m2,v2,m3,v3,m4,v4,m5,v5,m6,v6,m7,v7,m8,v8) (MV(m1,v1)|MV(m2,v2)|MV(m3,v3)|MV(m4,v4)|MV(m5,v5)|MV(m6,v6)|MV(m7,v7)|MV(m8,v8))
93 
94 #define MASK_VAL(...) VARARG(MASK_VAL, __VA_ARGS__)
95 
96 
100 #define REG_BASE_ADDR 0x800000
101 
102 #define REG_ADDR8(a) (*(volatile unsigned char*) (REG_BASE_ADDR + (a)))
103 #define REG_ADDR16(a) (*(volatile unsigned short*)(REG_BASE_ADDR + (a)))
104 #define REG_ADDR32(a) (*(volatile unsigned long*) (REG_BASE_ADDR + (a)))
105 
106 #define write_reg8(addr,v) (*(volatile unsigned char*) (REG_BASE_ADDR + (addr)) = (unsigned char)(v))
107 #define write_reg16(addr,v) (*(volatile unsigned short*) (REG_BASE_ADDR + (addr)) = (unsigned short)(v))
108 #define write_reg32(addr,v) (*(volatile unsigned long*) (REG_BASE_ADDR + (addr)) = (v))
109 
110 #define read_reg8(addr) (*(volatile unsigned char*) (REG_BASE_ADDR + (addr)))
111 #define read_reg16(addr) (*(volatile unsigned short*)(REG_BASE_ADDR + (addr)))
112 #define read_reg32(addr) (*(volatile unsigned long*) (REG_BASE_ADDR + (addr)))
113 
114 #define WRITE_REG8 write_reg8
115 #define WRITE_REG16 write_reg16
116 #define WRITE_REG32 write_reg32
117 
118 #define READ_REG8 read_reg8
119 #define READ_REG16 read_reg16
120 #define READ_REG32 read_reg32
121 
122 #define TCMD_UNDER_BOTH 0xc0
123 #define TCMD_UNDER_RD 0x80
124 #define TCMD_UNDER_WR 0x40
125 
126 #define TCMD_MASK 0x3f
127 
128 #define TCMD_WRITE 0x3
129 #define TCMD_WAIT 0x7
130 #define TCMD_WAREG 0x8
131 
132 
136 typedef struct TBLCMDSET {
137  unsigned short ADR;
138  unsigned char DAT;
139  unsigned char CMD;
140 } TBLCMDSET;
141 
150 extern int LoadTblCmdSet(const TBLCMDSET * pt, int size);
151 
152 
161 extern void sub_wr_ana(unsigned int addr, unsigned char value, unsigned char e, unsigned char s);
162 
171 extern void sub_wr(unsigned int addr, unsigned char value, unsigned char e, unsigned char s);
172 
173 #endif /* BSP_H_ */
174  //end of GP11
312 
unsigned char CMD
Definition: bsp.h:139
int LoadTblCmdSet(const TBLCMDSET *pt, int size)
This function performs a series of operations of writing digital or analog registers according to a c...
unsigned char DAT
Definition: bsp.h:138
Definition: bsp.h:136
unsigned short ADR
Definition: bsp.h:137
struct TBLCMDSET TBLCMDSET
void sub_wr_ana(unsigned int addr, unsigned char value, unsigned char e, unsigned char s)
This function writes a byte data to analog register.
void sub_wr(unsigned int addr, unsigned char value, unsigned char e, unsigned char s)
This function writes a byte data to a specified analog register.