]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/util.c
Bootloader cleanup (UNTESTED!)
[proxmark3-svn] / armsrc / util.c
index ae2e724738d64f470c966a58dd34322dcaf3f64b..5a8cfeec72ba0a063cee5ba87f12a6c4b1908431 100644 (file)
@@ -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();
Impressum, Datenschutz