text
[RRG-proxmark3.git] / armsrc / util.h
blob1d8586c43a2095919ea120af29df1ef40d97945b
1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Aug 2005
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Utility functions used in many places, not specific to any piece of code.
9 //-----------------------------------------------------------------------------
11 #ifndef __UTIL_H
12 #define __UTIL_H
14 #include "common.h"
16 // PRIx64 definition missing with gcc-arm-none-eabi v8?
17 #ifndef PRIx64
18 #define PRIx64 "llx"
19 #endif
21 // Basic macros
23 #ifndef SHORT_COIL
24 #define SHORT_COIL() LOW(GPIO_SSC_DOUT)
25 #endif
27 #ifndef OPEN_COIL
28 #define OPEN_COIL() HIGH(GPIO_SSC_DOUT)
29 #endif
31 #ifndef BYTEx
32 #define BYTEx(x, n) (((x) >> (n * 8)) & 0xff )
33 #endif
35 // Proxmark3 RDV4.0 LEDs
36 #define LED_A 1
37 #define LED_B 2
38 #define LED_C 4
39 #define LED_D 8
41 // Proxmark3 historical LEDs
42 #define LED_ORANGE LED_A
43 #define LED_GREEN LED_B
44 #define LED_RED LED_C
45 #define LED_RED2 LED_D
47 #define BUTTON_HOLD 1
48 #define BUTTON_NO_CLICK 0
49 #define BUTTON_SINGLE_CLICK -1
50 #define BUTTON_DOUBLE_CLICK -2
51 #define BUTTON_ERROR -99
53 #ifndef REV8
54 #define REV8(x) ((((x)>>7)&1)+((((x)>>6)&1)<<1)+((((x)>>5)&1)<<2)+((((x)>>4)&1)<<3)+((((x)>>3)&1)<<4)+((((x)>>2)&1)<<5)+((((x)>>1)&1)<<6)+(((x)&1)<<7))
55 #endif
57 #ifndef REV16
58 #define REV16(x) (REV8(x) + (REV8 ((x) >> 8) << 8))
59 #endif
61 #ifndef REV32
62 #define REV32(x) (REV16(x) + (REV16((x) >> 16) << 16))
63 #endif
65 #ifndef REV64
66 #define REV64(x) (REV32(x) + ((uint64_t)(REV32((x) >> 32) << 32)))
67 #endif
69 #ifndef BIT32
70 #define BIT32(x,n) ((((x)[(n)>>5])>>((n)))&1)
71 #endif
73 #ifndef INV32
74 #define INV32(x,i,n) ((x)[(i)>>5]^=((uint32_t)(n))<<((i)&31))
75 #endif
77 #ifndef ROTL64
78 #define ROTL64(x, n) ((((uint64_t)(x))<<((n)&63))+(((uint64_t)(x))>>((0-(n))&63)))
79 #endif
81 size_t nbytes(size_t nbits);
83 uint8_t hex2int(char hexchar);
85 void LED(int led, int ms);
86 void LEDsoff(void);
87 void SpinOff(uint32_t pause);
88 void SpinErr(uint8_t led, uint32_t speed, uint8_t times);
89 void SpinDown(uint32_t speed);
90 void SpinUp(uint32_t speed);
92 int BUTTON_CLICKED(int ms);
93 int BUTTON_HELD(int ms);
94 bool data_available(void);
96 #endif