2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
23 #include "drivers/io_types.h"
26 #define TRANSPONDER_BITS_PER_BYTE_ARCITIMER 8
27 #define TRANSPONDER_DATA_LENGTH_ARCITIMER 9
28 #define TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER 4
29 #define TRANSPONDER_GAP_TOGGLES_ARCITIMER 0
30 #define TRANSPONDER_TOGGLES_ARCITIMER (TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER + TRANSPONDER_GAP_TOGGLES_ARCITIMER)
31 #define TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER 155 * TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER // 620
32 #define TRANSPONDER_TIMER_MHZ_ARCITIMER 24
33 #define TRANSPONDER_CARRIER_HZ_ARCITIMER 41886
34 #define TRANSPONDER_TRANSMIT_DELAY_ARCITIMER 4500
35 #define TRANSPONDER_TRANSMIT_JITTER_ARCITIMER 10000
40 #define TRANSPONDER_BITS_PER_BYTE_ILAP 10 // start + 8 data + stop
41 #define TRANSPONDER_DATA_LENGTH_ILAP 6
42 #define TRANSPONDER_TOGGLES_PER_BIT_ILAP 11
43 #define TRANSPONDER_GAP_TOGGLES_ILAP 1
44 #define TRANSPONDER_TOGGLES_ILAP (TRANSPONDER_TOGGLES_PER_BIT_ILAP + TRANSPONDER_GAP_TOGGLES_ILAP)
45 #define TRANSPONDER_DMA_BUFFER_SIZE_ILAP ((TRANSPONDER_TOGGLES_PER_BIT_ILAP + 1) * TRANSPONDER_BITS_PER_BYTE_ILAP * TRANSPONDER_DATA_LENGTH_ILAP) //720
46 #define TRANSPONDER_TIMER_MHZ_ILAP 24
47 #define TRANSPONDER_CARRIER_HZ_ILAP 460750
48 #define TRANSPONDER_TRANSMIT_DELAY_ILAP 4500
49 #define TRANSPONDER_TRANSMIT_JITTER_ILAP 10000
54 #define TRANSPONDER_DATA_LENGTH_ERLT 1
56 #define ERLTBitQuiet 0
57 #define ERLTCyclesForOneBit 25
58 #define ERLTCyclesForZeroBit 10
59 #define TRANSPONDER_DMA_BUFFER_SIZE_ERLT 200 // actually ERLT is variable length 91-196 depending on the ERLT id
60 #define TRANSPONDER_TIMER_MHZ_ERLT 18
61 #define TRANSPONDER_CARRIER_HZ_ERLT 38000
62 #define TRANSPONDER_TRANSMIT_DELAY_ERLT 22500
63 #define TRANSPONDER_TRANSMIT_JITTER_ERLT 5000
68 * Implementation note:
69 * Using around over 700 bytes for a transponder DMA buffer is a little excessive, likely an alternative implementation that uses a fast
70 * ISR to generate the output signal dynamically based on state would be more memory efficient and would likely be more appropriate for
71 * other targets. However this approach requires very little CPU time and is just fire-and-forget.
73 * On an STM32F303CC 720 bytes is currently fine and that is the target for which this code was designed for.
75 #if defined(STM32F3) || defined(UNIT_TEST)
77 typedef union transponderIrDMABuffer_s
{
78 uint8_t arcitimer
[TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER
]; // 620
79 uint8_t ilap
[TRANSPONDER_DMA_BUFFER_SIZE_ILAP
]; // 720
80 uint8_t erlt
[TRANSPONDER_DMA_BUFFER_SIZE_ERLT
]; // 91-200
81 } transponderIrDMABuffer_t
;
83 #elif defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
85 typedef union transponderIrDMABuffer_s
{
86 uint32_t arcitimer
[TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER
]; // 620
87 uint32_t ilap
[TRANSPONDER_DMA_BUFFER_SIZE_ILAP
]; // 720
88 uint32_t erlt
[TRANSPONDER_DMA_BUFFER_SIZE_ERLT
]; // 91-200
89 } transponderIrDMABuffer_t
;
92 typedef struct transponder_s
{
95 uint32_t timer_carrier_hz
;
96 uint16_t bitToggleOne
;
97 uint32_t dma_buffer_size
;
99 #if defined(STM32F3) || defined(STM32F4)|| defined(STM32F7) || defined(STM32H7) || defined(STM32G4) || defined(UNIT_TEST)
100 transponderIrDMABuffer_t transponderIrDMABuffer
;
103 const struct transponderVTable
*vTable
;
107 TRANSPONDER_NONE
= 0,
109 TRANSPONDER_ARCITIMER
,
111 } transponderProvider_e
;
113 #define TRANSPONDER_PROVIDER_COUNT 3
115 struct transponderVTable
{
116 void (*updateTransponderDMABuffer
)(transponder_t
*transponder
, const uint8_t* transponderData
);
119 bool transponderIrInit(const ioTag_t ioTag
, const transponderProvider_e provider
);
120 void transponderIrDisable(void);
122 void transponderIrHardwareInit(ioTag_t ioTag
, transponder_t
*transponder
);
123 void transponderIrDMAEnable(transponder_t
*transponder
);
125 void transponderIrWaitForTransmitComplete(void);
127 void transponderIrUpdateData(const uint8_t* transponderData
);
128 void transponderIrTransmit(void);
130 bool isTransponderIrReady(void);
132 extern volatile uint8_t transponderIrDataTransferInProgress
;