]>
Commit | Line | Data |
---|---|---|
81dee67e SM |
1 | #ifndef LYNX_HELP_H__ |
2 | #define LYNX_HELP_H__ | |
3 | /*****************************************************************************\ | |
4 | * FIELD MACROS * | |
5 | \*****************************************************************************/ | |
6 | ||
7 | #define _LSB(f) (0 ? f) | |
8 | #define _MSB(f) (1 ? f) | |
9 | #define _COUNT(f) (_MSB(f) - _LSB(f) + 1) | |
10 | ||
11 | #define RAW_MASK(f) (0xFFFFFFFF >> (32 - _COUNT(f))) | |
12 | #define GET_MASK(f) (RAW_MASK(f) << _LSB(f)) | |
13 | #define GET_FIELD(d,f) (((d) >> _LSB(f)) & RAW_MASK(f)) | |
14 | #define TEST_FIELD(d,f,v) (GET_FIELD(d,f) == f ## _ ## v) | |
15 | #define SET_FIELD(d,f,v) (((d) & ~GET_MASK(f)) | \ | |
16 | (((f ## _ ## v) & RAW_MASK(f)) << _LSB(f))) | |
17 | #define SET_FIELDV(d,f,v) (((d) & ~GET_MASK(f)) | \ | |
18 | (((v) & RAW_MASK(f)) << _LSB(f))) | |
19 | ||
20 | ||
21 | //////////////////////////////////////////////////////////////////////////////// | |
22 | // // | |
23 | // Internal macros // | |
24 | // // | |
25 | //////////////////////////////////////////////////////////////////////////////// | |
26 | ||
27 | #define _F_START(f) (0 ? f) | |
28 | #define _F_END(f) (1 ? f) | |
29 | #define _F_SIZE(f) (1 + _F_END(f) - _F_START(f)) | |
30 | #define _F_MASK(f) (((1 << _F_SIZE(f)) - 1) << _F_START(f)) | |
31 | #define _F_NORMALIZE(v, f) (((v) & _F_MASK(f)) >> _F_START(f)) | |
32 | #define _F_DENORMALIZE(v, f) (((v) << _F_START(f)) & _F_MASK(f)) | |
33 | ||
34 | ||
35 | //////////////////////////////////////////////////////////////////////////////// | |
36 | // // | |
37 | // Global macros // | |
38 | // // | |
39 | //////////////////////////////////////////////////////////////////////////////// | |
40 | ||
41 | #define FIELD_GET(x, reg, field) \ | |
42 | ( \ | |
43 | _F_NORMALIZE((x), reg ## _ ## field) \ | |
44 | ) | |
45 | ||
46 | #define FIELD_SET(x, reg, field, value) \ | |
47 | ( \ | |
48 | (x & ~_F_MASK(reg ## _ ## field)) \ | |
49 | | _F_DENORMALIZE(reg ## _ ## field ## _ ## value, reg ## _ ## field) \ | |
50 | ) | |
51 | ||
52 | #define FIELD_VALUE(x, reg, field, value) \ | |
53 | ( \ | |
54 | (x & ~_F_MASK(reg ## _ ## field)) \ | |
55 | | _F_DENORMALIZE(value, reg ## _ ## field) \ | |
56 | ) | |
57 | ||
58 | #define FIELD_CLEAR(reg, field) \ | |
59 | ( \ | |
60 | ~ _F_MASK(reg ## _ ## field) \ | |
61 | ) | |
62 | ||
63 | ||
64 | //////////////////////////////////////////////////////////////////////////////// | |
65 | // // | |
66 | // Field Macros // | |
67 | // // | |
68 | //////////////////////////////////////////////////////////////////////////////// | |
69 | ||
70 | #define FIELD_START(field) (0 ? field) | |
71 | #define FIELD_END(field) (1 ? field) | |
72 | #define FIELD_SIZE(field) (1 + FIELD_END(field) - FIELD_START(field)) | |
73 | #define FIELD_MASK(field) (((1 << (FIELD_SIZE(field)-1)) | ((1 << (FIELD_SIZE(field)-1)) - 1)) << FIELD_START(field)) | |
74 | #define FIELD_NORMALIZE(reg, field) (((reg) & FIELD_MASK(field)) >> FIELD_START(field)) | |
75 | #define FIELD_DENORMALIZE(field, value) (((value) << FIELD_START(field)) & FIELD_MASK(field)) | |
76 | ||
77 | #define FIELD_INIT(reg, field, value) FIELD_DENORMALIZE(reg ## _ ## field, \ | |
78 | reg ## _ ## field ## _ ## value) | |
79 | #define FIELD_INIT_VAL(reg, field, value) \ | |
80 | (FIELD_DENORMALIZE(reg ## _ ## field, value)) | |
81 | #define FIELD_VAL_SET(x, r, f, v) x = x & ~FIELD_MASK(r ## _ ## f) \ | |
82 | | FIELD_DENORMALIZE(r ## _ ## f, r ## _ ## f ## _ ## v) | |
83 | ||
84 | #define RGB(r, g, b) \ | |
85 | ( \ | |
86 | (unsigned long) (((r) << 16) | ((g) << 8) | (b)) \ | |
87 | ) | |
88 | ||
89 | #define RGB16(r, g, b) \ | |
90 | ( \ | |
91 | (unsigned short) ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3)) \ | |
92 | ) | |
93 | ||
94 | static inline unsigned int absDiff(unsigned int a,unsigned int b) | |
95 | { | |
96 | if(a<b) | |
97 | return b-a; | |
98 | else | |
99 | return a-b; | |
100 | } | |
101 | ||
102 | /* n / d + 1 / 2 = (2n + d) / 2d */ | |
103 | #define roundedDiv(num,denom) ((2 * (num) + (denom)) / (2 * (denom))) | |
104 | #define MB(x) ((x)<<20) | |
105 | #define KB(x) ((x)<<10) | |
106 | #define MHz(x) ((x) * 1000000) | |
107 | ||
108 | ||
109 | ||
110 | ||
111 | #endif |