Release v4.15864 - Radium
[RRG-proxmark3.git] / armsrc / lfsampling.h
blob11c03ca74322dfac67aeeca099ff0ad4c0a50ea6
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 #ifndef __LFSAMPLING_H
17 #define __LFSAMPLING_H
19 #include "common.h"
20 #include "pm3_cmd.h"
22 typedef struct {
23 uint8_t *buffer;
24 uint32_t numbits;
25 uint32_t position;
26 } BitstreamOut_t;
28 typedef struct {
29 int dec_counter;
30 uint32_t sum;
31 uint32_t counter;
32 uint32_t total_saved;
33 } sampling_t;
35 /**
36 * acquisition of Cotag LF signal. Similar to other LF, since the Cotag has such long datarate RF/384
37 * and is Manchester?, we directly gather the manchester data into bigbuff
38 **/
39 void doCotagAcquisition(void);
40 uint16_t doCotagAcquisitionManchester(uint8_t *dest, uint16_t destlen);
42 /**
43 * acquisition of T55x7 LF signal. Similar to other LF, but adjusted with @marshmellows thresholds
44 * the data is collected in BigBuf.
45 **/
46 void doT55x7Acquisition(size_t sample_size, bool ledcontrol);
48 /**
49 * Initializes the FPGA for reader-mode (field on), and acquires the samples.
50 * @return number of bits sampled
51 **/
52 uint32_t SampleLF(bool verbose, uint32_t sample_size, bool ledcontrol);
54 /**
55 * Initializes the FPGA for sniff-mode (field off), and acquires the samples.
56 * @return number of bits sampled
57 **/
58 uint32_t SniffLF(bool verbose, uint32_t sample_size, bool ledcontrol);
60 uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, int16_t trigger_threshold,
61 bool verbose, uint32_t sample_size, uint32_t cancel_after, int32_t samples_to_skip, bool ledcontrol);
63 // adds sample size to default options
64 uint32_t DoPartialAcquisition(int trigger_threshold, bool verbose, uint32_t sample_size, uint32_t cancel_after, bool ledcontrol);
66 /**
67 * @brief Does sample acquisition, ignoring the config values set in the sample_config.
68 * This method is typically used by tag-specific readers who just wants to read the samples
69 * the normal way
70 * @param trigger_threshold
71 * @param verbose
72 * @return number of bits sampled
74 uint32_t DoAcquisition_default(int trigger_threshold, bool verbose, bool ledcontrol);
75 /**
76 * @brief Does sample acquisition, using the config values set in the sample_config.
77 * @param trigger_threshold
78 * @param verbose
79 * @return number of bits sampled
82 uint32_t DoAcquisition_config(bool verbose, uint32_t sample_size, bool ledcontrol);
84 /**
85 * Refactoring of lf sampling buffer
87 void initSampleBuffer(uint32_t *sample_size);
88 void initSampleBufferEx(uint32_t *sample_size, bool use_malloc);
89 void logSampleSimple(uint8_t sample);
90 void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool avg);
91 uint32_t getSampleCounter(void);
93 /**
94 * Setup the FPGA to listen for samples. This method downloads the FPGA bitstream
95 * if not already loaded, sets divisor and starts up the antenna.
96 * @param divisor : 1, 88> 255 or negative ==> 134.8 kHz
97 * 0 or 95 ==> 125 kHz
99 **/
100 void LFSetupFPGAForADC(int divisor, bool reader_field);
103 * Called from the USB-handler to set the sampling configuration
104 * The sampling config is used for std reading and sniffing.
106 * Other functions may read samples and ignore the sampling config,
107 * such as functions to read the UID from a prox tag or similar.
109 * Values set to '0' implies no change (except for averaging)
110 * @brief setSamplingConfig
111 * @param sc
113 void setSamplingConfig(sample_config *sc);
114 void setDefaultSamplingConfig(void);
115 sample_config *getSamplingConfig(void);
117 void printLFConfig(void);
118 void printSamples(void);
120 #endif // __LFSAMPLING_H