51 #ifndef _TN_ARCH_PIC24_BFA_H
52 #define _TN_ARCH_PIC24_BFA_H
76 #define TN_BFA_SET 0x1111
80 #define TN_BFA_CLR 0x2222
84 #define TN_BFA_INV 0x3333
88 #define TN_BFA_WR 0xAAAA
92 #define TN_BFA_RD 0xBBBB
154 #define TN_BFA(comm, reg_name, field_name, ...) \
156 ((comm) == TN_BFA_WR) \
158 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
159 if (_TN_BFA_FIELD_DEF(reg_name, field_name, LENGTH) == 1) { \
161 _TN_BFA_REG_DEF(reg_name, SET) = \
162 _TN_BFA_FIELD_DEF(reg_name, field_name, MASK); \
164 _TN_BFA_REG_DEF(reg_name, CLR) = \
165 _TN_BFA_FIELD_DEF(reg_name, field_name, MASK); \
168 _TN_BFA_REG_DEF(reg_name, INV) = \
169 _TN_BFA_FIELD_DEF(reg_name, field_name, MASK) \
172 ((v) << _TN_BFA_FIELD_DEF( \
173 reg_name, field_name, POSITION \
181 :(((comm) == TN_BFA_INV) \
183 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
184 _TN_BFA_REG_DEF(reg_name, INV) = \
186 _TN_BFA_FIELD_DEF(reg_name, field_name, MASK) \
188 ((v) << _TN_BFA_FIELD_DEF(reg_name, field_name, POSITION)) \
192 :((((comm) == TN_BFA_SET) \
194 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
195 _TN_BFA_REG_DEF(reg_name, SET) = \
197 _TN_BFA_FIELD_DEF(reg_name, field_name, MASK) \
199 ((v) << _TN_BFA_FIELD_DEF(reg_name, field_name, POSITION)) \
203 :(((((comm) == TN_BFA_CLR) \
205 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
206 _TN_BFA_REG_DEF(reg_name, CLR) = \
208 _TN_BFA_FIELD_DEF(reg_name, field_name, MASK) \
210 ((v) << _TN_BFA_FIELD_DEF(reg_name, field_name, POSITION)) \
215 _TN_BFA_STRUCT_VAL(reg_name).field_name; \
268 #define TN_BFAR(comm, reg_name, lower, upper, ...) \
270 unsigned int mask, maskl, masku; \
271 maskl = (1 << (lower)); \
272 masku = (1 << (upper)); \
273 mask = ((maskl-1) ^ (masku-1)) | maskl | masku; \
275 ((comm) == TN_BFA_WR) \
277 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
278 if ((lower) == (upper)) { \
280 _TN_BFA_REG_DEF(reg_name, SET) = mask; \
282 _TN_BFA_REG_DEF(reg_name, CLR) = mask; \
285 _TN_BFA_REG_DEF(reg_name, INV) = \
288 (((v) << _TN_BFA_MIN((lower), (upper))) ^ reg_name); \
292 :(((comm) == TN_BFA_INV) \
294 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
295 _TN_BFA_REG_DEF(reg_name, INV) = \
296 mask & ((v) << _TN_BFA_MIN((lower), (upper))); \
299 :((((comm) == TN_BFA_SET) \
301 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
302 _TN_BFA_REG_DEF(reg_name, SET) = \
303 mask & ((v) << _TN_BFA_MIN((lower), (upper))); \
306 :(((((comm) == TN_BFA_CLR) \
308 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \
309 _TN_BFA_REG_DEF(reg_name, CLR) = \
310 mask & ((v) << _TN_BFA_MIN((lower), (upper))); \
314 ((reg_name) & mask) >> _TN_BFA_MIN((lower), (upper)); \
321 #ifndef DOXYGEN_SHOULD_SKIP_THIS
323 #define _TN_BFA_COMM_ERR(a) _TN_BFA_COMMAND_ERROR_##a
324 #define _TN_BFA_COMM_GET(a) _TN_BFA_COMM_ERR(a)
326 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_SET);
327 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_CLR);
328 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_INV);
330 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_WR);
331 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_RD);
333 #define _TN_BFA_STRUCT_VAL(a) a##bits
334 #define _TN_BFA_FIELD_DEF(reg_name, field_name, def) \
335 _##reg_name##_##field_name##_##def
336 #define _TN_BFA_REG_DEF(reg_name, def) reg_name##def
337 #define _TN_BFA_MIN(a, b) ((a) < (b) ? (a) : (b))
348 #endif // _TN_ARCH_PIC24_BFA_H
#define TN_BFA_SET
Command for TN_BFA() macro: Set bits in the bit field by mask; ... macro param should be set to the b...
#define TN_BFA_INV
Command for TN_BFA() macro: Invert bits in the bit field by mask; ... macro param should be set to th...
#define TN_BFA_RD
Command for TN_BFA() macro: Read bit field; ... macro param ignored.
#define TN_BFA_CLR
Command for TN_BFA() macro: Clear bits in the bit field by mask; ... macro param should be set to the...
#define TN_BFA_WR
Command for TN_BFA() macro: Write bit field; ... macro param should be set to the value to write...