free start pointer
[RRG-proxmark3.git] / armsrc / lfsampling.h
blobd10f8279e1b3bdf79470b86d87e166cdef66bf97
1 #ifndef __LFSAMPLING_H
2 #define __LFSAMPLING_H
4 #include "common.h"
5 #include "pm3_cmd.h"
7 typedef struct {
8 uint8_t *buffer;
9 uint32_t numbits;
10 uint32_t position;
11 } BitstreamOut;
13 typedef struct {
14 int dec_counter;
15 uint32_t sum;
16 uint32_t counter;
17 uint32_t total_saved;
18 } sampling_t;
20 /**
21 * acquisition of Cotag LF signal. Similar to other LF, since the Cotag has such long datarate RF/384
22 * and is Manchester?, we directly gather the manchester data into bigbuff
23 **/
24 void doCotagAcquisition(void);
25 uint16_t doCotagAcquisitionManchester(uint8_t *dest, uint16_t destlen);
27 /**
28 * acquisition of T55x7 LF signal. Similar to other LF, but adjusted with @marshmellows thresholds
29 * the data is collected in BigBuf.
30 **/
31 void doT55x7Acquisition(size_t sample_size);
33 /**
34 * Initializes the FPGA for reader-mode (field on), and acquires the samples.
35 * @return number of bits sampled
36 **/
37 uint32_t SampleLF(bool verbose, uint32_t sample_size);
39 /**
40 * Initializes the FPGA for sniff-mode (field off), and acquires the samples.
41 * @return number of bits sampled
42 **/
43 uint32_t SniffLF(bool verbose, uint32_t sample_size);
45 uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, int16_t trigger_threshold,
46 bool verbose, uint32_t sample_size, uint32_t cancel_after, int32_t samples_to_skip);
48 // adds sample size to default options
49 uint32_t DoPartialAcquisition(int trigger_threshold, bool verbose, uint32_t sample_size, uint32_t cancel_after);
51 /**
52 * @brief Does sample acquisition, ignoring the config values set in the sample_config.
53 * This method is typically used by tag-specific readers who just wants to read the samples
54 * the normal way
55 * @param trigger_threshold
56 * @param verbose
57 * @return number of bits sampled
59 uint32_t DoAcquisition_default(int trigger_threshold, bool verbose);
60 /**
61 * @brief Does sample acquisition, using the config values set in the sample_config.
62 * @param trigger_threshold
63 * @param verbose
64 * @return number of bits sampled
67 uint32_t DoAcquisition_config(bool verbose, uint32_t sample_size);
69 /**
70 * Refactoring of lf sampling buffer
72 void initSampleBuffer(uint32_t *sample_size);
73 void initSampleBufferEx(uint32_t *sample_size, bool use_malloc);
74 void logSampleSimple(uint8_t sample);
75 void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool avg);
76 uint32_t getSampleCounter(void);
78 /**
79 * Setup the FPGA to listen for samples. This method downloads the FPGA bitstream
80 * if not already loaded, sets divisor and starts up the antenna.
81 * @param divisor : 1, 88> 255 or negative ==> 134.8 kHz
82 * 0 or 95 ==> 125 kHz
84 **/
85 void LFSetupFPGAForADC(int divisor, bool reader_field);
87 /**
88 * Called from the USB-handler to set the sampling configuration
89 * The sampling config is used for std reading and sniffing.
91 * Other functions may read samples and ignore the sampling config,
92 * such as functions to read the UID from a prox tag or similar.
94 * Values set to '0' implies no change (except for averaging)
95 * @brief setSamplingConfig
96 * @param sc
98 void setSamplingConfig(sample_config *sc);
100 sample_config *getSamplingConfig(void);
102 void printLFConfig(void);
103 void printSamples(void);
105 #endif // __LFSAMPLING_H