X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/e30c654b196a87a13ae7f7d4ced930b296c038ec..bd20f8f47847787e1f3e933043933272908c5beb:/armsrc/util.c diff --git a/armsrc/util.c b/armsrc/util.c index ae2e7247..5a8cfeec 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -1,78 +1,26 @@ //----------------------------------------------------------------------------- -// 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--) @@ -139,12 +87,12 @@ int BUTTON_CLICKED(int ms) 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) @@ -162,7 +110,7 @@ int BUTTON_CLICKED(int ms) // 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; } @@ -174,7 +122,7 @@ int BUTTON_CLICKED(int ms) // 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; @@ -202,11 +150,11 @@ int BUTTON_HELD(int ms) 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()) @@ -214,7 +162,7 @@ int BUTTON_HELD(int ms) // Have we waited the full second? else - if (now == (WORD)(start + ticks)) + if (now == (uint16_t)(start + ticks)) return BUTTON_HOLD; WDT_HIT(); @@ -237,11 +185,11 @@ void SpinDelayUs(int us) 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();