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, ...) \ 158 _TN_BFA_STRUCT_TYPE(reg_name) o; \ 160 } lcur, lmask={}, lval={}; \ 162 lmask.o.field_name = -1; \ 164 ((comm) == TN_BFA_WR) \ 166 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 167 if (lmask.i & (lmask.i-1)){ \ 168 lval.o.field_name = v; \ 169 lcur.o = _TN_BFA_STRUCT_VAL(reg_name); \ 170 __asm__ __volatile__ \ 171 ("xor %0":"=U"(reg_name):"a"(lmask.i & (lval.i^lcur.i))); \ 175 _TN_BFA_STRUCT_VAL(reg_name).field_name = 1; \ 177 _TN_BFA_STRUCT_VAL(reg_name).field_name = 0; \ 182 :(((comm) == TN_BFA_INV) \ 184 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 185 lval.o.field_name = v; \ 186 __asm__ __volatile__(" xor %0" \ 187 :"=U"(reg_name):"a"(lmask.i & lval.i)); \ 190 :((((comm) == TN_BFA_SET) \ 192 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 193 if (lmask.i & (lmask.i-1)){ \ 194 lval.o.field_name = v; \ 195 __asm__ __volatile__ \ 196 ("ior %0":"=U"(reg_name):"a"(lmask.i & lval.i)); \ 199 _TN_BFA_STRUCT_VAL(reg_name).field_name = 1; \ 203 :(((((comm) == TN_BFA_CLR) \ 205 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 206 if (lmask.i & (lmask.i-1)){ \ 207 lval.o.field_name = v; \ 208 __asm__ __volatile__ \ 209 ("and %0":"=U"(reg_name):"a"(~(lmask.i & lval.i))); \ 212 _TN_BFA_STRUCT_VAL(reg_name).field_name = 0; \ 217 _TN_BFA_STRUCT_VAL(reg_name).field_name; \ 270 #define TN_BFAR(comm, reg_name, lower, upper, ...) \ 272 unsigned int lmask, lmaskl, lmasku; \ 273 lmaskl = (1 << (lower)); \ 274 lmasku = (1 << (upper)); \ 275 lmask = ((lmaskl-1) ^ (lmasku-1)) | lmaskl | lmasku; \ 276 ((comm) == TN_BFA_WR) \ 278 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 279 v = (v << (((lower) < (upper)) ? (lower) : (upper))) & lmask; \ 280 __asm__ __volatile__ \ 281 (" xor %0": "=T"(reg_name):"a"(lmask & (v ^ reg_name))); \ 283 :(((comm) == TN_BFA_INV) \ 285 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 286 if (lmask & (lmask-1)) \ 288 v = (v << (((lower) < (upper)) ? (lower) : (upper))) & lmask; \ 289 __asm__ __volatile__( \ 290 " xor %0":"=T"(reg_name):"a"(lmask & v)); \ 293 __asm__ __volatile__( \ 294 " btg %0, #%1" :"=T"(reg_name) :"i"(lower)); \ 298 :(((comm) == TN_BFA_SET) \ 300 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 301 if (lmask & (lmask-1)) \ 303 v = (v << (((lower) < (upper)) ? (lower) : (upper))) & lmask; \ 304 __asm__ __volatile__(" ior %0 " \ 309 __asm__ __volatile__( \ 310 " bset %0, #%1" :"=T"(reg_name) :"i"(lower)); \ 314 :((((comm) == TN_BFA_CLR) \ 316 _TN_BFA_COMM_GET(comm) v = __VA_ARGS__+0; \ 317 if (lmask & (lmask-1)) \ 319 v = (v << (((lower) < (upper)) ? (lower) : (upper))) & lmask; \ 320 __asm__ __volatile__(" and %0 " \ 322 :"a"(~(lmask & v))); \ 325 __asm__ __volatile__( \ 326 " bclr %0, #%1" :"=T"(reg_name) :"i"(lower)); \ 331 (reg_name & lmask) >> (((lower) < (upper)) ? (lower) : (upper)); \ 338 #ifndef DOXYGEN_SHOULD_SKIP_THIS 340 #define _TN_BFA_COMM_ERR(a) _TN_BFA_COMMAND_ERROR_##a 341 #define _TN_BFA_COMM_GET(a) _TN_BFA_COMM_ERR(a) 343 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_SET);
344 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_CLR);
345 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_INV);
347 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_WR);
348 typedef unsigned int _TN_BFA_COMM_GET(
TN_BFA_RD);
350 #define _TN_BFA_STRUCT_TYPE(a) a##BITS 351 #define _TN_BFA_STRUCT_VAL(a) a##bits 361 #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...