Cherry-pick CF/9f7f2f2
This commit is contained in:
parent
5bc79368be
commit
a4ee4102d7
2
Makefile
2
Makefile
|
@ -784,6 +784,8 @@ FC_SRC = \
|
|||
drivers/sonar_hcsr04.c \
|
||||
drivers/vtx_common.c \
|
||||
drivers/transponder_ir.c \
|
||||
drivers/transponder_ir_arcitimer.c \
|
||||
drivers/transponder_ir_ilap.c \
|
||||
flight/navigation.c \
|
||||
io/dashboard.c \
|
||||
io/displayport_max7456.c \
|
||||
|
|
|
@ -30,36 +30,8 @@
|
|||
#include "timer.h"
|
||||
|
||||
#include "transponder_ir.h"
|
||||
|
||||
#define TRANSPONDER_TIMER_MHZ 24
|
||||
#define TRANSPONDER_CARRIER_HZ 460750
|
||||
|
||||
static uint8_t bitToggleOne = 0;
|
||||
#define BIT_TOGGLE_0 0
|
||||
|
||||
#define TRANSPONDER_BITS_PER_BYTE 10 // start + 8 data + stop
|
||||
#define TRANSPONDER_DATA_LENGTH 6
|
||||
#define TRANSPONDER_TOGGLES_PER_BIT 11
|
||||
#define TRANSPONDER_GAP_TOGGLES 1
|
||||
#define TRANSPONDER_TOGGLES (TRANSPONDER_TOGGLES_PER_BIT + TRANSPONDER_GAP_TOGGLES)
|
||||
|
||||
#define TRANSPONDER_DMA_BUFFER_SIZE ((TRANSPONDER_TOGGLES_PER_BIT + 1) * TRANSPONDER_BITS_PER_BYTE * TRANSPONDER_DATA_LENGTH)
|
||||
|
||||
/*
|
||||
* Implementation note:
|
||||
* Using around over 700 bytes for a transponder DMA buffer is a little excessive, likely an alternative implementation that uses a fast
|
||||
* ISR to generate the output signal dynamically based on state would be more memory efficient and would likely be more appropriate for
|
||||
* other targets. However this approach requires very little CPU time and is just fire-and-forget.
|
||||
*
|
||||
* On an STM32F303CC 720 bytes is currently fine and that is the target for which this code was designed for.
|
||||
*/
|
||||
#if defined(STM32F3)
|
||||
uint8_t transponderIrDMABuffer[TRANSPONDER_DMA_BUFFER_SIZE];
|
||||
#elif defined(STM32F4)
|
||||
uint32_t transponderIrDMABuffer[TRANSPONDER_DMA_BUFFER_SIZE];
|
||||
#else
|
||||
#error "Transponder not supported on this MCU."
|
||||
#endif
|
||||
#include "drivers/transponder_ir_arcitimer.h"
|
||||
#include "drivers/transponder_ir_ilap.h"
|
||||
|
||||
volatile uint8_t transponderIrDataTransferInProgress = 0;
|
||||
|
||||
|
@ -74,6 +46,8 @@ static DMA_Stream_TypeDef *dmaRef = NULL;
|
|||
#error "Transponder not supported on this MCU."
|
||||
#endif
|
||||
|
||||
transponder_t transponder;
|
||||
|
||||
static void TRANSPONDER_DMA_IRQHandler(dmaChannelDescriptor_t* descriptor)
|
||||
{
|
||||
if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF)) {
|
||||
|
@ -84,7 +58,7 @@ static void TRANSPONDER_DMA_IRQHandler(dmaChannelDescriptor_t* descriptor)
|
|||
}
|
||||
}
|
||||
|
||||
void transponderIrHardwareInit(ioTag_t ioTag)
|
||||
void transponderIrHardwareInit(ioTag_t ioTag, transponder_t *transponder)
|
||||
{
|
||||
if (!ioTag) {
|
||||
return;
|
||||
|
@ -110,11 +84,10 @@ void transponderIrHardwareInit(ioTag_t ioTag)
|
|||
|
||||
RCC_ClockCmd(timerRCC(timer), ENABLE);
|
||||
|
||||
uint16_t prescaler = timerGetPrescalerByDesiredMhz(timer, TRANSPONDER_TIMER_MHZ);
|
||||
uint16_t period = timerGetPeriodByPrescaler(timer, prescaler, TRANSPONDER_CARRIER_HZ);
|
||||
uint16_t prescaler = timerGetPrescalerByDesiredMhz(timer, transponder->timer_hz);
|
||||
uint16_t period = timerGetPeriodByPrescaler(timer, prescaler, transponder->timer_carrier_hz);
|
||||
|
||||
bitToggleOne = period / 2;
|
||||
|
||||
transponder->bitToggleOne = period / 2;
|
||||
/* Time base configuration */
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = period;
|
||||
|
@ -149,15 +122,15 @@ void transponderIrHardwareInit(ioTag_t ioTag)
|
|||
DMA_StructInit(&DMA_InitStructure);
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)timerCCR(timer, timerHardware->channel);
|
||||
#if defined(STM32F3)
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)transponderIrDMABuffer;
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(transponder->transponderIrDMABuffer);
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
#elif defined(STM32F4)
|
||||
DMA_InitStructure.DMA_Channel = timerHardware->dmaChannel;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)transponderIrDMABuffer;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&(transponder->transponderIrDMABuffer);
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
|
||||
#endif
|
||||
DMA_InitStructure.DMA_BufferSize = TRANSPONDER_DMA_BUFFER_SIZE;
|
||||
DMA_InitStructure.DMA_BufferSize = transponder->dma_buffer_size;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
#if defined(STM32F3)
|
||||
|
@ -178,10 +151,8 @@ void transponderIrHardwareInit(ioTag_t ioTag)
|
|||
DMA_ITConfig(dmaRef, DMA_IT_TC, ENABLE);
|
||||
}
|
||||
|
||||
bool transponderIrInit(void)
|
||||
bool transponderIrInit(const TransponderProvider* transponderProvider)
|
||||
{
|
||||
memset(&transponderIrDMABuffer, 0, TRANSPONDER_DMA_BUFFER_SIZE);
|
||||
|
||||
ioTag_t ioTag = IO_TAG_NONE;
|
||||
for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) {
|
||||
if (timerHardware[i].usageFlags & TIM_USE_TRANSPONDER) {
|
||||
|
@ -194,8 +165,17 @@ bool transponderIrInit(void)
|
|||
return false;
|
||||
}
|
||||
|
||||
uint8_t transponderProviderLocal = *transponderProvider;
|
||||
switch(transponderProviderLocal){
|
||||
case ARCITIMER:
|
||||
transponderIrInitArcitimer(&transponder);
|
||||
break;
|
||||
case ILAP:
|
||||
transponderIrInitIlap(&transponder);
|
||||
break;
|
||||
}
|
||||
|
||||
transponderIrHardwareInit(ioTag);
|
||||
transponderIrHardwareInit(ioTag, &transponder);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -207,42 +187,6 @@ bool isTransponderIrReady(void)
|
|||
|
||||
static uint16_t dmaBufferOffset;
|
||||
|
||||
void updateTransponderDMABuffer(const uint8_t* transponderData)
|
||||
{
|
||||
uint8_t byteIndex;
|
||||
uint8_t bitIndex;
|
||||
uint8_t toggleIndex;
|
||||
|
||||
for (byteIndex = 0; byteIndex < TRANSPONDER_DATA_LENGTH; byteIndex++) {
|
||||
|
||||
uint8_t byteToSend = *transponderData;
|
||||
transponderData++;
|
||||
for (bitIndex = 0; bitIndex < TRANSPONDER_BITS_PER_BYTE; bitIndex++)
|
||||
{
|
||||
bool doToggles = false;
|
||||
if (bitIndex == 0) {
|
||||
doToggles = true;
|
||||
} else if (bitIndex == TRANSPONDER_BITS_PER_BYTE - 1) {
|
||||
doToggles = false;
|
||||
} else {
|
||||
doToggles = byteToSend & (1 << (bitIndex - 1));
|
||||
}
|
||||
|
||||
for (toggleIndex = 0; toggleIndex < TRANSPONDER_TOGGLES_PER_BIT; toggleIndex++)
|
||||
{
|
||||
if (doToggles) {
|
||||
transponderIrDMABuffer[dmaBufferOffset] = bitToggleOne;
|
||||
} else {
|
||||
transponderIrDMABuffer[dmaBufferOffset] = BIT_TOGGLE_0;
|
||||
}
|
||||
dmaBufferOffset++;
|
||||
}
|
||||
transponderIrDMABuffer[dmaBufferOffset] = BIT_TOGGLE_0;
|
||||
dmaBufferOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void transponderIrWaitForTransmitComplete(void)
|
||||
{
|
||||
static uint32_t waitCounter = 0;
|
||||
|
@ -254,14 +198,13 @@ void transponderIrWaitForTransmitComplete(void)
|
|||
|
||||
void transponderIrUpdateData(const uint8_t* transponderData)
|
||||
{
|
||||
transponderIrWaitForTransmitComplete();
|
||||
|
||||
updateTransponderDMABuffer(transponderData);
|
||||
transponderIrWaitForTransmitComplete();
|
||||
transponder.vTable->updateTransponderDMABuffer(&transponder, transponderData);
|
||||
}
|
||||
|
||||
void transponderIrDMAEnable(void)
|
||||
void transponderIrDMAEnable(transponder_t *transponder)
|
||||
{
|
||||
DMA_SetCurrDataCounter(dmaRef, TRANSPONDER_DMA_BUFFER_SIZE); // load number of bytes to be transferred
|
||||
DMA_SetCurrDataCounter(dmaRef, transponder->dma_buffer_size); // load number of bytes to be transferred
|
||||
TIM_SetCounter(timer, 0);
|
||||
TIM_Cmd(timer, ENABLE);
|
||||
DMA_Cmd(dmaRef, ENABLE);
|
||||
|
@ -289,6 +232,6 @@ void transponderIrTransmit(void)
|
|||
dmaBufferOffset = 0;
|
||||
|
||||
transponderIrDataTransferInProgress = 1;
|
||||
transponderIrDMAEnable();
|
||||
transponderIrDMAEnable(&transponder);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -19,11 +19,80 @@
|
|||
|
||||
#include "drivers/io_types.h"
|
||||
|
||||
bool transponderIrInit();
|
||||
/*** ARCITIMER ***/
|
||||
#define TRANSPONDER_BITS_PER_BYTE_ARCITIMER 8
|
||||
#define TRANSPONDER_DATA_LENGTH_ARCITIMER 9
|
||||
#define TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER 4
|
||||
#define TRANSPONDER_GAP_TOGGLES_ARCITIMER 0
|
||||
#define TRANSPONDER_TOGGLES_ARCITIMER (TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER + TRANSPONDER_GAP_TOGGLES_ARCITIMER)
|
||||
#define TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER 155 * TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER // 620
|
||||
#define TRANSPONDER_TIMER_MHZ_ARCITIMER 24
|
||||
#define TRANSPONDER_CARRIER_HZ_ARCITIMER 41886
|
||||
/*** ******** ***/
|
||||
|
||||
|
||||
/*** ILAP ***/
|
||||
#define TRANSPONDER_BITS_PER_BYTE_ILAP 10 // start + 8 data + stop
|
||||
#define TRANSPONDER_DATA_LENGTH_ILAP 6
|
||||
#define TRANSPONDER_TOGGLES_PER_BIT_ILAP 11
|
||||
#define TRANSPONDER_GAP_TOGGLES_ILAP 1
|
||||
#define TRANSPONDER_TOGGLES (TRANSPONDER_TOGGLES_PER_BIT_ILAP + TRANSPONDER_GAP_TOGGLES_ILAP)
|
||||
#define TRANSPONDER_DMA_BUFFER_SIZE_ILAP ((TRANSPONDER_TOGGLES_PER_BIT_ILAP + 1) * TRANSPONDER_BITS_PER_BYTE_ILAP * TRANSPONDER_DATA_LENGTH_ILAP) //720
|
||||
#define TRANSPONDER_TIMER_MHZ_ILAP 24
|
||||
#define TRANSPONDER_CARRIER_HZ_ILAP 460750
|
||||
/*** ******** ***/
|
||||
|
||||
/*
|
||||
* Implementation note:
|
||||
* Using around over 700 bytes for a transponder DMA buffer is a little excessive, likely an alternative implementation that uses a fast
|
||||
* ISR to generate the output signal dynamically based on state would be more memory efficient and would likely be more appropriate for
|
||||
* other targets. However this approach requires very little CPU time and is just fire-and-forget.
|
||||
*
|
||||
* On an STM32F303CC 720 bytes is currently fine and that is the target for which this code was designed for.
|
||||
*/
|
||||
#if defined(STM32F3) || defined(UNIT_TEST)
|
||||
|
||||
typedef union transponderIrDMABuffer_s {
|
||||
uint8_t arcitimer[TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER]; // 620
|
||||
uint8_t ilap[TRANSPONDER_DMA_BUFFER_SIZE_ILAP]; // 720
|
||||
} transponderIrDMABuffer_t;
|
||||
|
||||
#elif defined(STM32F4)
|
||||
|
||||
typedef union transponderIrDMABuffer_s {
|
||||
uint32_t arcitimer[TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER]; // 620
|
||||
uint32_t ilap[TRANSPONDER_DMA_BUFFER_SIZE_ILAP]; // 720
|
||||
} transponderIrDMABuffer_t;
|
||||
#endif
|
||||
|
||||
typedef struct transponder_s {
|
||||
uint8_t gap_toggles;
|
||||
uint32_t timer_hz;
|
||||
uint32_t timer_carrier_hz;
|
||||
uint16_t bitToggleOne;
|
||||
uint32_t dma_buffer_size;
|
||||
|
||||
#if defined(STM32F3) || defined(STM32F4)|| defined(UNIT_TEST)
|
||||
transponderIrDMABuffer_t transponderIrDMABuffer;
|
||||
#endif
|
||||
|
||||
const struct transponderVTable *vTable;
|
||||
} transponder_t;
|
||||
|
||||
typedef enum TransponderProvider{
|
||||
ARCITIMER,
|
||||
ILAP
|
||||
} TransponderProvider;
|
||||
|
||||
struct transponderVTable {
|
||||
void (*updateTransponderDMABuffer)(transponder_t *transponder, const uint8_t* transponderData);
|
||||
};
|
||||
|
||||
bool transponderIrInit(const TransponderProvider* transponderProvider);
|
||||
void transponderIrDisable(void);
|
||||
|
||||
void transponderIrHardwareInit(ioTag_t ioTag);
|
||||
void transponderIrDMAEnable(void);
|
||||
void transponderIrHardwareInit(ioTag_t ioTag, transponder_t *transponder);
|
||||
void transponderIrDMAEnable(transponder_t *transponder);
|
||||
|
||||
void transponderIrWaitForTransmitComplete(void);
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <platform.h>
|
||||
#include "drivers/transponder_ir.h"
|
||||
#include "drivers/transponder_ir_arcitimer.h"
|
||||
|
||||
#if defined(STM32F3) || defined(STM32F4) || defined(UNIT_TEST)
|
||||
|
||||
extern const struct transponderVTable arcitimerTansponderVTable;
|
||||
static uint16_t dmaBufferOffset;
|
||||
|
||||
void transponderIrInitArcitimer(transponder_t *transponder){
|
||||
// from drivers/transponder_ir.h
|
||||
transponder->gap_toggles = TRANSPONDER_GAP_TOGGLES_ARCITIMER;
|
||||
transponder->dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER;
|
||||
transponder->vTable = &arcitimerTansponderVTable;
|
||||
transponder->timer_hz = TRANSPONDER_TIMER_MHZ_ARCITIMER;
|
||||
transponder->timer_carrier_hz = TRANSPONDER_CARRIER_HZ_ARCITIMER;
|
||||
memset(&(transponder->transponderIrDMABuffer.arcitimer), 0, TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER);
|
||||
}
|
||||
|
||||
void updateTransponderDMABufferArcitimer(transponder_t *transponder, const uint8_t* transponderData)
|
||||
{
|
||||
uint8_t byteIndex;
|
||||
uint8_t bitIndex;
|
||||
uint8_t hightStateIndex;
|
||||
for (byteIndex = 0; byteIndex < TRANSPONDER_DATA_LENGTH_ARCITIMER; byteIndex++) {
|
||||
uint8_t byteToSend = *transponderData;
|
||||
transponderData++;
|
||||
for (bitIndex = 0; bitIndex < TRANSPONDER_BITS_PER_BYTE_ARCITIMER; bitIndex++)
|
||||
{
|
||||
bool isHightState = byteToSend & (1 << (bitIndex));
|
||||
for (hightStateIndex = 0; hightStateIndex < TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER; hightStateIndex++)
|
||||
{
|
||||
transponder->transponderIrDMABuffer.arcitimer[dmaBufferOffset] = isHightState ? transponder->bitToggleOne : 0;
|
||||
dmaBufferOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
dmaBufferOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const struct transponderVTable arcitimerTansponderVTable = {
|
||||
updateTransponderDMABufferArcitimer,
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// aRCiTimer transponder codes:
|
||||
//
|
||||
// ID1 0x1F, 0xFC, 0x8F, 0x3, 0xF0, 0x1, 0xF8, 0x1F, 0x0 // E00370FC0FFE07E0FF
|
||||
// ID2 0xFF, 0x83, 0xFF, 0xC1, 0x7, 0xFF, 0x3, 0xF0, 0x1 // 007C003EF800FC0FFE
|
||||
// ID3 0x7, 0x7E, 0xE0, 0x7, 0x7E, 0xE0, 0x0, 0x38, 0x0 // F8811FF8811FFFC7FF
|
||||
// ID4 0xFF, 0x83, 0xFF, 0xC1, 0x7, 0xE0, 0x7F, 0xF0, 0x1 // 007C003EF81F800FFE
|
||||
// ID5 0xF, 0xF0, 0x0, 0xFF, 0x0, 0xF, 0xF0, 0xF, 0x0 // F00FFF00FFF00FF0FF
|
||||
// ID6 0xFF, 0x83, 0xF, 0x3E, 0xF8, 0xE0, 0x83, 0xFF, 0xF // 007CF0C1071F7C00F0
|
||||
// ID7 0x1F, 0xFC, 0xF, 0xC0, 0xFF, 0x0, 0xFC, 0xF, 0x3E // E003F03F00FF03F0C1
|
||||
// ID8 0xFF, 0x3, 0xF0, 0x1, 0xF8, 0xE0, 0xC1, 0xFF, 0x1 // 00FC0FFE071F3E00FE
|
||||
// ID9 0x1F, 0x7C, 0x40, 0xF, 0xF0, 0x61, 0xC7, 0x3F, 0x0 // E083BFF00F9E38C0FF
|
||||
|
||||
|
||||
|
||||
void transponderIrInitArcitimer(transponder_t *transponder);
|
||||
void updateTransponderDMABufferArcitimer(transponder_t *transponder, const uint8_t* transponderData);
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <platform.h>
|
||||
#include "drivers/transponder_ir.h"
|
||||
#include "drivers/transponder_ir_ilap.h"
|
||||
|
||||
#if defined(STM32F3) || defined(STM32F4) || defined(UNIT_TEST)
|
||||
|
||||
static uint16_t dmaBufferOffset;
|
||||
extern const struct transponderVTable ilapTansponderVTable;
|
||||
|
||||
void transponderIrInitIlap(transponder_t *transponder){
|
||||
// from drivers/transponder_ir.h
|
||||
transponder->gap_toggles = TRANSPONDER_GAP_TOGGLES_ILAP;
|
||||
transponder->dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ILAP;
|
||||
transponder->vTable = &ilapTansponderVTable;
|
||||
transponder->timer_hz = TRANSPONDER_TIMER_MHZ_ILAP;
|
||||
transponder->timer_carrier_hz = TRANSPONDER_CARRIER_HZ_ILAP;
|
||||
memset(&(transponder->transponderIrDMABuffer.ilap), 0, TRANSPONDER_DMA_BUFFER_SIZE_ILAP);
|
||||
|
||||
}
|
||||
|
||||
void updateTransponderDMABufferIlap(transponder_t *transponder, const uint8_t* transponderData)
|
||||
{
|
||||
uint8_t byteIndex;
|
||||
uint8_t bitIndex;
|
||||
uint8_t toggleIndex;
|
||||
for (byteIndex = 0; byteIndex < TRANSPONDER_DATA_LENGTH_ILAP; byteIndex++) {
|
||||
uint8_t byteToSend = *transponderData;
|
||||
transponderData++;
|
||||
for (bitIndex = 0; bitIndex < TRANSPONDER_BITS_PER_BYTE_ILAP; bitIndex++)
|
||||
{
|
||||
bool doToggles = false;
|
||||
if (bitIndex == 0) {
|
||||
doToggles = true;
|
||||
}
|
||||
else if (bitIndex == TRANSPONDER_BITS_PER_BYTE_ILAP - 1) {
|
||||
doToggles = false;
|
||||
}
|
||||
else {
|
||||
doToggles = byteToSend & (1 << (bitIndex - 1));
|
||||
}
|
||||
for (toggleIndex = 0; toggleIndex < TRANSPONDER_TOGGLES_PER_BIT_ILAP; toggleIndex++)
|
||||
{
|
||||
if (doToggles) {
|
||||
transponder->transponderIrDMABuffer.ilap[dmaBufferOffset] = transponder->bitToggleOne;
|
||||
}
|
||||
else {
|
||||
transponder->transponderIrDMABuffer.ilap[dmaBufferOffset] = 0;
|
||||
}
|
||||
dmaBufferOffset++;
|
||||
}
|
||||
transponder->transponderIrDMABuffer.ilap[dmaBufferOffset] = 0;
|
||||
dmaBufferOffset++;
|
||||
}
|
||||
}
|
||||
dmaBufferOffset = 0;
|
||||
}
|
||||
|
||||
const struct transponderVTable ilapTansponderVTable = {
|
||||
updateTransponderDMABufferIlap,
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
void transponderIrInitIlap(transponder_t *transponder);
|
||||
void updateTransponderDMABufferIlap(transponder_t *transponder, const uint8_t* transponderData);
|
|
@ -40,6 +40,7 @@
|
|||
#include "drivers/serial.h"
|
||||
#include "drivers/stack_check.h"
|
||||
#include "drivers/vtx_common.h"
|
||||
#include "drivers/transponder_ir.h"
|
||||
|
||||
#include "fc/config.h"
|
||||
#include "fc/fc_msp.h"
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
PG_REGISTER_WITH_RESET_TEMPLATE(transponderConfig_t, transponderConfig, PG_TRANSPONDER_CONFIG, 0);
|
||||
|
||||
PG_RESET_TEMPLATE(transponderConfig_t, transponderConfig,
|
||||
.data = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC } // Note, this is NOT a valid transponder code, it's just for testing production hardware
|
||||
.data = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0x0, 0x0, 0x0 }, // Note, this is NOT a valid transponder code, it's just for testing production hardware
|
||||
.provider = ILAP
|
||||
);
|
||||
|
||||
static bool transponderInitialised = false;
|
||||
|
@ -84,7 +85,7 @@ void transponderUpdate(timeUs_t currentTimeUs)
|
|||
|
||||
void transponderInit(void)
|
||||
{
|
||||
transponderInitialised = transponderIrInit();
|
||||
transponderInitialised = transponderIrInit(&(transponderConfig()->provider));
|
||||
if (!transponderInitialised) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include "config/parameter_group.h"
|
||||
|
||||
typedef struct transponderConfig_s {
|
||||
uint8_t data[6];
|
||||
TransponderProvider provider;
|
||||
uint8_t data[9];
|
||||
} transponderConfig_t;
|
||||
|
||||
PG_DECLARE(transponderConfig_t, transponderConfig);
|
||||
|
|
|
@ -356,6 +356,42 @@ $(OBJECT_DIR)/$1/$1 : $$($$1_OBJS) \
|
|||
$(V1) mkdir -p $(dir $$@)
|
||||
$(V1) $(CXX) $(CXX_FLAGS) $(PG_FLAGS) $$^ -o $$@
|
||||
|
||||
$(OBJECT_DIR)/drivers/transponder_ir_arcitimer.o : \
|
||||
$(USER_DIR)/drivers/transponder_ir_arcitimer.c \
|
||||
$(USER_DIR)/drivers/transponder_ir.h \
|
||||
$(USER_DIR)/drivers/transponder_ir_arcitimer.h \
|
||||
$(GTEST_HEADERS)
|
||||
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/transponder_ir_arcitimer.c -o $@
|
||||
|
||||
$(OBJECT_DIR)/drivers/transponder_ir_ilap.o : \
|
||||
$(USER_DIR)/drivers/transponder_ir_ilap.c \
|
||||
$(USER_DIR)/drivers/transponder_ir.h \
|
||||
$(USER_DIR)/drivers/transponder_ir_ilap.h \
|
||||
$(GTEST_HEADERS)
|
||||
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/transponder_ir_ilap.c -o $@
|
||||
|
||||
$(OBJECT_DIR)/transponder_unittest.o : \
|
||||
$(TEST_DIR)/transponder_unittest.cc \
|
||||
$(USER_DIR)/drivers/transponder_ir.h \
|
||||
$(USER_DIR)/drivers/transponder_ir_arcitimer.h \
|
||||
$(USER_DIR)/drivers/transponder_ir_ilap.h \
|
||||
$(GTEST_HEADERS)
|
||||
|
||||
@mkdir -p $(dir $@)
|
||||
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/transponder_unittest.cc -o $@
|
||||
|
||||
$(OBJECT_DIR)/transponder_unittest : \
|
||||
$(OBJECT_DIR)/drivers/transponder_ir_arcitimer.o \
|
||||
$(OBJECT_DIR)/drivers/transponder_ir_ilap.o \
|
||||
$(OBJECT_DIR)/transponder_unittest.o \
|
||||
$(OBJECT_DIR)/gtest_main.a
|
||||
|
||||
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
||||
|
||||
|
||||
test_$1: $(OBJECT_DIR)/$1/$1
|
||||
$(V1) $$< $$(EXEC_OPTS) "$(STDOUT)" && echo "running $$@: PASS"
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
extern "C" {
|
||||
#include <platform.h>
|
||||
#include "build/build_config.h"
|
||||
#include "drivers/dma.h"
|
||||
#include "drivers/transponder_ir.h"
|
||||
#include "drivers/transponder_ir_arcitimer.h"
|
||||
#include "drivers/transponder_ir_ilap.h"
|
||||
}
|
||||
#include "unittest_macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
extern "C" {
|
||||
STATIC_UNIT_TESTED extern uint16_t dmaBufferOffset;
|
||||
}
|
||||
TEST(transponderTest, updateTransponderDMABufferArcitimer) {
|
||||
//input
|
||||
uint8_t data[9] = {0x1F, 0xFC, 0x8F, 0x3, 0xF0, 0x1, 0xF8, 0x1F, 0x0};
|
||||
//excepted
|
||||
uint8_t excepted[TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER] = {
|
||||
78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,
|
||||
78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,
|
||||
78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
uint8_t* transponderData = data;
|
||||
transponder_t transponder;
|
||||
transponder.dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER;
|
||||
transponder.bitToggleOne = 78;
|
||||
memset(&(transponder.transponderIrDMABuffer.arcitimer), 0, TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER);
|
||||
|
||||
updateTransponderDMABufferArcitimer(&transponder, transponderData);
|
||||
uint16_t i;
|
||||
for(i = 0; i < transponder.dma_buffer_size; i++) {
|
||||
EXPECT_EQ(transponder.transponderIrDMABuffer.arcitimer[i], excepted[i]);
|
||||
}
|
||||
}
|
||||
TEST(transponderTest, updateTransponderDMABufferIlap) {
|
||||
uint8_t data[9] = {0x1F, 0xFC, 0x8F, 0x3, 0xF0, 0x1, 0x0, 0x0, 0x0};
|
||||
|
||||
uint8_t excepted[TRANSPONDER_DMA_BUFFER_SIZE_ILAP] = {
|
||||
78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,
|
||||
78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,
|
||||
78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,
|
||||
78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,
|
||||
78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,
|
||||
78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,
|
||||
78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,
|
||||
78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,
|
||||
0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,
|
||||
78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
uint8_t* transponderData = data;
|
||||
transponder_t transponder;
|
||||
transponder.dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ILAP;
|
||||
transponder.bitToggleOne = 78;
|
||||
|
||||
updateTransponderDMABufferIlap(&transponder, transponderData);
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; i < transponder.dma_buffer_size; i++) {
|
||||
EXPECT_EQ(transponder.transponderIrDMABuffer.ilap[i], excepted[i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue