]> git.zerfleddert.de Git - proxmark3-svn/blob - armsrc/BigBuf.c
987fee7d520b581a7909644fd62d37ee4c49d161
[proxmark3-svn] / armsrc / BigBuf.c
1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Aug 2005
3 // Gerhard de Koning Gans, April 2008, May 2011
4 //
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
7 // the license.
8 //-----------------------------------------------------------------------------
9 // BigBuf and functions to allocate/free parts of it.
10 //-----------------------------------------------------------------------------
11
12 #include <stdint.h>
13 #include "proxmark3.h"
14 #include "apps.h"
15 #include "string.h"
16
17 // The large multi-purpose buffer, typically used to hold A/D samples or traces,
18 // may be processed in some way. Also used to hold various smaller buffers.
19 static uint8_t BigBuf[BIGBUF_SIZE];
20
21 // High memory mark
22 static uint16_t BigBuf_hi = BIGBUF_SIZE;
23
24 // trace related global variables. Change to function calls?
25 //uint8_t *trace = BigBuf;
26 uint16_t traceLen;
27
28
29 // get the address of BigBuf
30 uint8_t *BigBuf_get_addr(void)
31 {
32 return BigBuf;
33 }
34
35
36 // clear ALL of BigBuf
37 void BigBuf_Clear(void)
38 {
39 memset(BigBuf,0,BIGBUF_SIZE);
40 Dbprintf("Buffer cleared (%i bytes)",BIGBUF_SIZE);
41 }
42
43
44 // allocate a chunk of memory from BigBuf. We allocate high memory first. Low memory
45 // is always for traces/samples
46 uint8_t *BigBuf_malloc(uint16_t chunksize)
47 {
48 if (BigBuf_hi - chunksize < 0) {
49 return NULL; // no memory left
50 } else {
51 BigBuf_hi -= chunksize; // aligned to 4 Byte boundary
52 return BigBuf + BigBuf_hi;
53 }
54 }
55
56
57 // free ALL allocated chunks. The whole BigBuf is available for traces again.
58 void BigBuf_free(void)
59 {
60 BigBuf_hi = BIGBUF_SIZE;
61 }
62
63
64 // return the maximum trace length (i.e. the unallocated size of BigBuf)
65 uint16_t BigBuf_max_trace_len(void)
66 {
67 return BigBuf_hi;
68 }
Impressum, Datenschutz