# SFBMacros.h

Go to the documentation of this file.

    00001 /*                                              -*- mode:C++; fill-column:100 -*-
    00002   SFBMacros.h - Standalone early macros requiring no constants.
    00003   Copyright (C) 2008 The Regents of the University of New Mexico.  All rights reserved.
    00004
    00005   This library is free software; you can redistribute it and/or
    00006   modify it under the terms of the GNU Lesser General Public
    00007   License as published by the Free Software Foundation; either
    00008   version 2.1 of the License, or (at your option) any later version.
    00009
    00010   This library is distributed in the hope that it will be useful,
    00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013   Lesser General Public License for more details.
    00014
    00015   You should have received a copy of the GNU General Public License
    00016   along with this library; if not, write to the Free Software
    00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00018   USA
    00019 */
    00020
    00027 #ifndef SFBMACROS_H_
    00028 #define SFBMACROS_H_
    00029
    00030 #include "SFBTypes.h"
    00031
    00032
    00037 #define CLOCKWISE_FACE(dir)        GET_MAP4BY2(MAP4BY2(EAST,WEST,SOUTH,NORTH),dir)
    00040 #define COUNTERCLOCKWISE_FACE(dir) GET_MAP4BY2(MAP4BY2(WEST,EAST,NORTH,SOUTH),dir)
    00043 #define ANTICLOCKWISE_FACE(dir) COUNTERCLOCKWISE_FACE(dir)
    00044 #define OPPOSITE_FACE(dir)         GET_MAP4BY2(MAP4BY2(SOUTH,NORTH,WEST,EAST),dir)
    00048 extern const char * const faceNames[];
    00049 #define FACE_NAME(face) (faceNames[face])
    00050 #define FACE_CODE(face) GET_MAP4BY8(MAP4BY8('N','S','E','W'),face)
    00052 #define FACE_NUMBER_FROM_CODE(code) (((((code)&~0x20)^(((code)&~0x20)>>1))-1)&0x3)
    00057 #define IS_FACE_CODE(code) ((((code)>>6)==1) && ((0x00884020>>((code)&0x1f))&1))
    00064
    00065
    00069
    00080 #define SET_BIT(value,bitNum) ((value) |= (1<<(bitNum)))
    00081
    00092 #define CLEAR_BIT(value,bitNum) ((value) &= ~(1<<(bitNum)))
    00093
    00105 #define GET_BIT(value,bitNum) (((value)>>(bitNum))&1)
    00106
    00119 #define TEST_BIT(value,bitNum) ((value)&(1<<(bitNum)))
    00120
    00136 #define BIT_PAIR_AT_POSITION(bits,newValue,position) \
    00137   ((bits) = ((bits)&(~(3<<(position))))|((newValue)<<(position)))
    00138
    00140 /****************** Structured H/W register access *****************/
    00141
    00146 #define REGISTER_OFFSET(baseAddress,byteOffset) \
    00147   (*((uv32 *) (((u32)(baseAddress))+(byteOffset))))
    00148
    00169 #define MAP4BY2(a, b, c, d) ((((((((u8) d)<<2)|(c))<<2)|(b))<<2)|(a))
    00170
    00185 #define GET_MAP4BY2(map, idx) (((map)>>((idx)<<1))&0x3)
    00186
    00203 #define MAP4BY4(a, b, c, d) ((((((((u16) d)<<4)|(c))<<4)|(b))<<4)|(a))
    00204
    00219 #define GET_MAP4BY4(map, idx) (((map)>>((idx)<<2))&0xf)
    00220
    00237 #define MAP4BY8(a, b, c, d) ((((((((u32) d)<<8)|(c))<<8)|(b))<<8)|(a))
    00238
    00252 #define GET_MAP4BY8(map, idx) (((map)>>((idx)<<3))&0xff)
    00253
    00282 #define MAP3BY3(a, b, c) ((((((u16) c)<<3)|(b))<<3)|(a))
    00283
    00297 #define GET_MAP3BY3(map, idx) (((map)>>((idx)*3))&0x7)
    00298
    00315 #define BLINK_MAP(red,green,blue) MAP3BY3(blue,green,red)
    00316
    00317
    00331 #define GET_BLINK_MAP_COLOR(code,color) GET_MAP3BY3(code,2-(color))
    00332
    00404 #define IS_EARLIER(a,b)          ((((u32)(a))-((u32)(b))) > 0x80000000UL)
    00406 #define IS_LATER_OR_EQUAL(a,b)   ((((u32)(a))-((u32)(b))) < 0x80000000UL)
    00409 #define IS_LATER(a,b)            ((((u32)(b))-((u32)(a))) > 0x80000000UL)
    00412 #define IS_EARLIER_OR_EQUAL(a,b) ((((u32)(b))-((u32)(a))) < 0x80000000UL)
    00417
    00418
    00421
    00439 #define STRUCT_MEMBER_OFFSET(structure,member) ((uptr) &(((structure *) 0)->member))
    00440
    00441 #define XSTR(arg) STR(arg)
    00444 #define STR(arg) #arg
    00448 #define MIN(a,b) (((a)<(b))?(a):(b))
    00454 #define MAX(a,b) (((a)>(b))?(a):(b))
    00461 #define FILEPOS __FILE__ ":" XSTR(__LINE__)
    00462
    00465 /****************** B36 constants macros ******************/
    00466
    00468 #define B36_CONST_0 0u
    00469 #define B36_CONST_1 1u
    00470 #define B36_CONST_2 2u
    00471 #define B36_CONST_3 3u
    00472 #define B36_CONST_4 4u
    00473 #define B36_CONST_5 5u
    00474 #define B36_CONST_6 6u
    00475 #define B36_CONST_7 7u
    00476 #define B36_CONST_8 8u
    00477 #define B36_CONST_9 9u
    00478 #define B36_CONST_A 10u
    00479 #define B36_CONST_a 10u
    00480 #define B36_CONST_B 11u
    00481 #define B36_CONST_b 11u
    00482 #define B36_CONST_C 12u
    00483 #define B36_CONST_c 12u
    00484 #define B36_CONST_D 13u
    00485 #define B36_CONST_d 13u
    00486 #define B36_CONST_E 14u
    00487 #define B36_CONST_e 14u
    00488 #define B36_CONST_F 15u
    00489 #define B36_CONST_f 15u
    00490 #define B36_CONST_G 16u
    00491 #define B36_CONST_g 16u
    00492 #define B36_CONST_H 17u
    00493 #define B36_CONST_h 17u
    00494 #define B36_CONST_I 18u
    00495 #define B36_CONST_i 18u
    00496 #define B36_CONST_J 19u
    00497 #define B36_CONST_j 19u
    00498 #define B36_CONST_K 20u
    00499 #define B36_CONST_k 20u
    00500 #define B36_CONST_L 21u
    00501 #define B36_CONST_l 21u
    00502 #define B36_CONST_M 22u
    00503 #define B36_CONST_m 22u
    00504 #define B36_CONST_N 23u
    00505 #define B36_CONST_n 23u
    00506 #define B36_CONST_O 24u
    00507 #define B36_CONST_o 24u
    00508 #define B36_CONST_P 25u
    00509 #define B36_CONST_p 25u
    00510 #define B36_CONST_Q 26u
    00511 #define B36_CONST_q 26u
    00512 #define B36_CONST_R 27u
    00513 #define B36_CONST_r 27u
    00514 #define B36_CONST_S 28u
    00515 #define B36_CONST_s 28u
    00516 #define B36_CONST_T 29u
    00517 #define B36_CONST_t 29u
    00518 #define B36_CONST_U 30u
    00519 #define B36_CONST_u 30u
    00520 #define B36_CONST_V 31u
    00521 #define B36_CONST_v 31u
    00522 #define B36_CONST_W 32u
    00523 #define B36_CONST_w 32u
    00524 #define B36_CONST_X 33u
    00525 #define B36_CONST_x 33u
    00526 #define B36_CONST_Y 34u
    00527 #define B36_CONST_y 34u
    00528 #define B36_CONST_Z 35u
    00529 #define B36_CONST_z 35u
    00530
    00532 #define B36_1(a) B36_CONST_##a
    00533 #define B36_2(a,b) (B36_1(a)*36u+B36_1(b))
    00534 #define B36_3(a,b,c) (B36_2(a,b)*36u+B36_1(c))
    00535 #define B36_4(a,b,c,d) (B36_3(a,b,c)*36u+B36_1(d))
    00536 #define B36_5(a,b,c,d,e) (B36_4(a,b,c,d)*36u+B36_1(e))
    00537 #define B36_6(a,b,c,d,e,f) (B36_5(a,b,c,d,e)*36u+B36_1(f))
    00538 #define B36_7(a,b,c,d,e,f,g) (B36_6(a,b,c,d,e,f)*36u+B36_1(g))
    00539
    00540 /****************** Memory placement macros ******************/
    00541
    00542 #ifndef HOST_MODE
    00543
    00544 #define IN_BODYRAM  __attribute__((section (".bodyram")))
    00545 #define IN_TALKRAM  __attribute__((section (".talkram")))
    00546 #define IN_FASTRAM  __attribute__((section (".fastram")))
    00547
    00548 #define IN_BODYRAM_BSS  __attribute__((section (".bss.bodyram")))
    00549 #define IN_TALKRAM_BSS  __attribute__((section (".bss.talkram")))
    00550 #define IN_FASTRAM_BSS  __attribute__((section (".bss.fastram")))
    00551
    00552 #else
    00553
    00554 #define IN_BODYRAM  /* in host mode */
    00555 #define IN_TALKRAM  /* no special ram regions */
    00556 #define IN_FASTRAM  /* are defined */
    00557
    00558 #define IN_BODYRAM_BSS  /* for */
    00559 #define IN_TALKRAM_BSS  /* any */
    00560 #define IN_FASTRAM_BSS  /* thing */
    00561
    00562 #endif
    00563
    00564 #endif /*SFBMACROS_H_*/