]>
git.zerfleddert.de Git - proxmark3-svn/blob - armsrc/BigBuf.c
7f56e9a014290c1a4b60cbfbacfc49bc9b8da02d
1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Aug 2005
3 // Gerhard de Koning Gans, April 2008, May 2011
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // BigBuf and functions to allocate/free parts of it.
10 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
17 // BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces.
18 // Also used to hold various smaller buffers and the Mifare Emulator Memory.
20 // declare it as uint32_t to achieve alignment to 4 Byte boundary
21 static uint32_t BigBuf
[BIGBUF_SIZE
/sizeof(uint32_t)];
24 static uint16_t BigBuf_hi
= BIGBUF_SIZE
;
26 // pointer to the emulator memory.
27 static uint8_t *emulator_memory
= NULL
;
29 // trace related global variables
30 // (only one left). ToDo: make this static as well?
31 uint16_t traceLen
= 0;
34 // get the address of BigBuf
35 uint8_t *BigBuf_get_addr(void)
37 return (uint8_t *)BigBuf
;
41 // get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
42 uint8_t *BigBuf_get_EM_addr(void)
44 if (emulator_memory
== NULL
) { // not yet allocated
45 emulator_memory
= BigBuf_malloc(CARD_MEMORY_SIZE
);
48 return emulator_memory
;
52 // clear ALL of BigBuf
53 void BigBuf_Clear(void)
55 memset(BigBuf
,0,BIGBUF_SIZE
);
56 Dbprintf("Buffer cleared (%i bytes)",BIGBUF_SIZE
);
60 // allocate a chunk of memory from BigBuf. We allocate high memory first. The unallocated memory
61 // at the beginning of BigBuf is always for traces/samples
62 uint8_t *BigBuf_malloc(uint16_t chunksize
)
64 if (BigBuf_hi
- chunksize
< 0) {
65 return NULL
; // no memory left
67 chunksize
= (chunksize
+ 3) & 0xfffc; // round to next multiple of 4
68 BigBuf_hi
-= chunksize
; // aligned to 4 Byte boundary
69 return (uint8_t *)BigBuf
+ BigBuf_hi
;
74 // free ALL allocated chunks. The whole BigBuf is available for traces or samples again.
75 void BigBuf_free(void)
77 BigBuf_hi
= BIGBUF_SIZE
;
78 emulator_memory
= NULL
;
82 // free allocated chunks EXCEPT the emulator memory
83 void BigBuf_free_keep_EM(void)
85 if (emulator_memory
!= NULL
) {
86 BigBuf_hi
= emulator_memory
- (uint8_t *)BigBuf
;
88 BigBuf_hi
= BIGBUF_SIZE
;
93 // return the maximum trace length (i.e. the unallocated size of BigBuf)
94 uint16_t BigBuf_max_traceLen(void)