Chameleon-Mini
 All Classes Files Functions Variables Macros Pages
Codec.h
1 /* Copyright 2013 Timo Kasper, Simon Küppers, David Oswald ("ORIGINAL
2  * AUTHORS"). All rights reserved.
3  *
4  * DEFINITIONS:
5  *
6  * "WORK": The material covered by this license includes the schematic
7  * diagrams, designs, circuit or circuit board layouts, mechanical
8  * drawings, documentation (in electronic or printed form), source code,
9  * binary software, data files, assembled devices, and any additional
10  * material provided by the ORIGINAL AUTHORS in the ChameleonMini project
11  * (https://github.com/skuep/ChameleonMini).
12  *
13  * LICENSE TERMS:
14  *
15  * Redistributions and use of this WORK, with or without modification, or
16  * of substantial portions of this WORK are permitted provided that the
17  * following conditions are met:
18  *
19  * Redistributions and use of this WORK, with or without modification, or
20  * of substantial portions of this WORK must include the above copyright
21  * notice, this list of conditions, the below disclaimer, and the following
22  * attribution:
23  *
24  * "Based on ChameleonMini an open-source RFID emulator:
25  * https://github.com/skuep/ChameleonMini"
26  *
27  * The attribution must be clearly visible to a user, for example, by being
28  * printed on the circuit board and an enclosure, and by being displayed by
29  * software (both in binary and source code form).
30  *
31  * At any time, the majority of the ORIGINAL AUTHORS may decide to give
32  * written permission to an entity to use or redistribute the WORK (with or
33  * without modification) WITHOUT having to include the above copyright
34  * notice, this list of conditions, the below disclaimer, and the above
35  * attribution.
36  *
37  * DISCLAIMER:
38  *
39  * THIS PRODUCT IS PROVIDED BY THE ORIGINAL AUTHORS "AS IS" AND ANY EXPRESS
40  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE ORIGINAL AUTHORS OR CONTRIBUTORS BE
43  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS PRODUCT, EVEN IF ADVISED OF
49  * THE POSSIBILITY OF SUCH DAMAGE.
50  *
51  * The views and conclusions contained in the hardware, software, and
52  * documentation should not be interpreted as representing official
53  * policies, either expressed or implied, of the ORIGINAL AUTHORS.
54  */
55 
56 #ifndef CODEC_H_
57 #define CODEC_H_
58 
59 #include <avr/io.h>
60 #include <stdint.h>
61 #include <stdbool.h>
62 #include "../Common.h"
63 #include "../Configuration.h"
64 
65 #include "ISO14443-2A.h"
66 
67 #define CODEC_DEMOD_POWER_PORT PORTB
68 #define CODEC_DEMOD_POWER_MASK PIN1_bm
69 #define CODEC_DEMOD_IN_PORT PORTB
70 #define CODEC_DEMOD_IN_MASK (CODEC_DEMOD_IN_MASK0 | CODEC_DEMOD_IN_MASK1)
71 #define CODEC_DEMOD_IN_MASK0 PIN0_bm
72 #define CODEC_DEMOD_IN_MASK1 PIN2_bm
73 #define CODEC_DEMOD_IN_PINCTRL0 PIN0CTRL
74 #define CODEC_DEMOD_IN_PINCTRL1 PIN2CTRL
75 #define CODEC_DEMOD_IN_EVMUX0 EVSYS_CHMUX_PORTB_PIN0_gc
76 #define CODEC_DEMOD_IN_EVMUX1 EVSYS_CHMUX_PORTB_PIN2_gc
77 #define CODEC_DEMOD_IN_INT0_VECT PORTB_INT0_vect
78 #define CODEC_LOADMOD_PORT PORTC
79 #define CODEC_LOADMOD_MASK PIN6_bm
80 #define CODEC_CARRIER_IN_PORT PORTC
81 #define CODEC_CARRIER_IN_MASK PIN2_bm
82 #define CODEC_CARRIER_IN_PINCTRL PIN2CTRL
83 #define CODEC_CARRIER_IN_EVMUX EVSYS_CHMUX_PORTC_PIN2_gc
84 #define CODEC_SUBCARRIER_PORT PORTC
85 #define CODEC_SUBCARRIER_MASK_PSK PIN0_bm
86 #define CODEC_SUBCARRIER_MASK_OOK PIN1_bm
87 #define CODEC_SUBCARRIER_MASK (CODEC_SUBCARRIER_MASK_PSK | CODEC_SUBCARRIER_MASK_OOK)
88 #define CODEC_SUBCARRIER_TIMER TCC0
89 #define CODEC_SUBCARRIER_CC_PSK CCA
90 #define CODEC_SUBCARRIER_CC_OOK CCB
91 #define CODEC_SUBCARRIER_CCEN_PSK TC0_CCAEN_bm
92 #define CODEC_SUBCARRIER_CCEN_OOK TC0_CCBEN_bm
93 #define CODEC_TIMER_SAMPLING TCC1
94 #define CODEC_TIMER_SAMPLING_CCA_VECT TCC1_CCA_vect
95 #define CODEC_TIMER_LOADMOD TCD1
96 #define CODEC_TIMER_OVF_VECT TCD1_OVF_vect
97 
98 #define CODEC_BUFFER_SIZE 256 /* Byte */
99 
100 #define CODEC_CARRIER_FREQ 13560000
101 
102 extern uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
103 
104 INLINE void CodecInit(void) {
105  ActiveConfiguration.CodecInitFunc();
106 }
107 
108 INLINE void CodecTask(void) {
109  ActiveConfiguration.CodecTaskFunc();
110 }
111 
112 INLINE void CodecSetDemodPower(bool bOnOff) {
113  CODEC_DEMOD_POWER_PORT.DIRSET = CODEC_DEMOD_POWER_MASK;
114 
115  if (bOnOff) {
116  CODEC_DEMOD_POWER_PORT.OUTSET = CODEC_DEMOD_POWER_MASK;
117  } else {
118  CODEC_DEMOD_POWER_PORT.OUTCLR = CODEC_DEMOD_POWER_MASK;
119  }
120 }
121 
122 #endif /* CODEC_H_ */