//-----------------------------------------------------------------------------
-// Utility functions used in many places, not specific to any piece of code.
// Jonathan Westhues, Sept 2005
+//
+// This code is licensed to you under the terms of the GNU GPL, version 2 or,
+// at your option, any later version. See the LICENSE.txt file for the text of
+// the license.
+//-----------------------------------------------------------------------------
+// Utility functions used in many places, not specific to any piece of code.
//-----------------------------------------------------------------------------
-#include "proxmark3.h"
-#include "apps.h"
-
-void *memcpy(void *dest, const void *src, int len)
-{
- BYTE *d = dest;
- const BYTE *s = src;
- while((len--) > 0) {
- *d = *s;
- d++;
- s++;
- }
- return dest;
-}
-
-void *memset(void *dest, int c, int len)
-{
- BYTE *d = dest;
- while((len--) > 0) {
- *d = c;
- d++;
- }
- return dest;
-}
-
-int memcmp(const void *av, const void *bv, int len)
-{
- const BYTE *a = av;
- const BYTE *b = bv;
-
- while((len--) > 0) {
- if(*a != *b) {
- return *a - *b;
- }
- a++;
- b++;
- }
- return 0;
-}
-
-int strlen(char *str)
-{
- int l = 0;
- while(*str) {
- l++;
- str++;
- }
- return l;
-}
-
-char* strncat(char *dest, const char *src, unsigned int n)
-{
- unsigned int dest_len = strlen(dest);
- unsigned int i;
-
- for (i = 0 ; i < n && src[i] != '\0' ; i++)
- dest[dest_len + i] = src[i];
- dest[dest_len + i] = '\0';
- return dest;
-}
+#include "proxmark3.h"
+#include "util.h"
+#include "string.h"
-void num_to_bytes(uint64_t n, size_t len, byte_t* dest)
+void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
{
while (len--) {
- dest[len] = (byte_t) n;
+ dest[len] = (uint8_t) n;
n >>= 8;
}
}
-uint64_t bytes_to_num(byte_t* src, size_t len)
+uint64_t bytes_to_num(uint8_t* src, size_t len)
{
uint64_t num = 0;
while (len--)
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff;
- WORD start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
int letoff = 0;
for(;;)
{
- WORD now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
// We haven't let off the button yet
if (!letoff)
// Still haven't let it off
else
// Have we held down a full second?
- if (now == (WORD)(start + ticks))
+ if (now == (uint16_t)(start + ticks))
return BUTTON_HOLD;
}
// Have we ran out of time to double click?
else
- if (now == (WORD)(start + ticks))
+ if (now == (uint16_t)(start + ticks))
// At least we did a single click
return BUTTON_SINGLE_CLICK;
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff;
- WORD start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
for(;;)
{
- WORD now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
// As soon as our button let go, we didn't hold long enough
if (!BUTTON_PRESS())
// Have we waited the full second?
else
- if (now == (WORD)(start + ticks))
+ if (now == (uint16_t)(start + ticks))
return BUTTON_HOLD;
WDT_HIT();
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff;
- WORD start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
for(;;) {
- WORD now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
- if (now == (WORD)(start + ticks))
+ uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ if (now == (uint16_t)(start + ticks))
return;
WDT_HIT();