]>
Commit | Line | Data |
---|---|---|
bd20f8f4 | 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 | //----------------------------------------------------------------------------- | |
10 | ||
f7e3ed82 | 11 | #ifndef __UTIL_H |
12 | #define __UTIL_H | |
13 | ||
14 | #include <stddef.h> | |
15 | #include <stdint.h> | |
a631936e | 16 | #include "common.h" |
f7e3ed82 | 17 | |
20f9a2a1 M |
18 | #define BYTEx(x, n) (((x) >> (n * 8)) & 0xff ) |
19 | ||
f2dbf3d2 | 20 | #define LED_RED 1 |
f7e3ed82 | 21 | #define LED_ORANGE 2 |
f2dbf3d2 | 22 | #define LED_GREEN 4 |
23 | #define LED_RED2 8 | |
24 | ||
25 | #define BUTTON_HOLD 1 | |
26 | #define BUTTON_NO_CLICK 0 | |
27 | #define BUTTON_SINGLE_CLICK -1 | |
28 | #define BUTTON_DOUBLE_CLICK -2 | |
29 | #define BUTTON_ERROR -99 | |
30 | ||
31 | #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)) | |
32 | #define REV16(x) (REV8(x) | (REV8 (x >> 8) << 8)) | |
33 | #define REV32(x) (REV16(x) | (REV16(x >> 16) << 16)) | |
34 | #define REV64(x) (REV32(x) | (REV32(x >> 32) << 32)) | |
9ab7a6c7 | 35 | |
787b5bd8 | 36 | void print_result(char *name, uint8_t *buf, size_t len); |
195af472 | 37 | size_t nbytes(size_t nbits); |
81cd0474 | 38 | uint32_t SwapBits(uint32_t value, int nrbits); |
f7e3ed82 | 39 | void num_to_bytes(uint64_t n, size_t len, uint8_t* dest); |
40 | uint64_t bytes_to_num(uint8_t* src, size_t len); | |
787b5bd8 | 41 | void rol(uint8_t *data, const size_t len); |
42 | void lsl (uint8_t *data, size_t len); | |
f7e3ed82 | 43 | |
f7e3ed82 | 44 | void LED(int led, int ms); |
45 | void LEDsoff(); | |
3d057cfb SG |
46 | void LEDson(); |
47 | void LEDsinvert(); | |
f7e3ed82 | 48 | int BUTTON_CLICKED(int ms); |
49 | int BUTTON_HELD(int ms); | |
50 | void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information); | |
51 | ||
e04475c4 | 52 | //iceman's ticks.h |
53 | #ifndef GET_TICKS | |
8ff31e93 | 54 | # define GET_TICKS GetTicks() |
e04475c4 | 55 | #endif |
56 | ||
57 | void SpinDelay(int ms); | |
58 | void SpinDelayUs(int us); | |
59 | ||
9ca155ba M |
60 | void StartTickCount(); |
61 | uint32_t RAMFUNC GetTickCount(); | |
62 | ||
8f51ddb0 M |
63 | void StartCountUS(); |
64 | uint32_t RAMFUNC GetCountUS(); | |
65 | uint32_t RAMFUNC GetDeltaCountUS(); | |
66 | ||
7bc95e2e | 67 | void StartCountSspClk(); |
e04475c4 | 68 | void ResetSspClk(void); |
7bc95e2e | 69 | uint32_t RAMFUNC GetCountSspClk(); |
1c611bbd | 70 | |
e04475c4 | 71 | extern void StartTicks(void); |
8ff31e93 | 72 | extern uint32_t GetTicks(void); |
e04475c4 | 73 | extern void WaitTicks(uint32_t ticks); |
74 | extern void WaitUS(uint16_t us); | |
75 | extern void WaitMS(uint16_t ms); | |
76 | extern void ResetTicks(); | |
77 | extern void ResetTimer(AT91PS_TC timer); | |
78 | extern void StopTicks(void); | |
79 | // end iceman's ticks.h | |
80 | ||
f9c1dcd9 MF |
81 | uint32_t prand(); |
82 | ||
9e13f875 | 83 | #endif |