Skip to content

Commit

Permalink
Made UART2_LINK_COMM to a kbuild selection CONFIG_CRTP_OVER_UART. #1041
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbeanton committed Jun 9, 2022
1 parent 61e33e0 commit 0b0f345
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/drivers/interface/uart2.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

#include <stdbool.h>
#include "eprintf.h"
#include "autoconf.h"

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
#include "syslink.h"
#endif

Expand Down Expand Up @@ -95,7 +96,7 @@ void uart2SendDataDmaBlocking(uint32_t size, uint8_t* data);
*/
int uart2Putchar(int ch);

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2

/**
* Get data from rx queue. Blocks until data is available.
Expand Down
16 changes: 8 additions & 8 deletions src/drivers/src/uart2.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "nvicconf.h"
#include "static_mem.h"

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
#include "queuemonitor.h"
#endif

Expand All @@ -58,7 +58,7 @@ static uint8_t dmaBuffer[UART2_DMA_BUFFER_SIZE];
static bool isUartDmaInitialized;
static uint32_t initialDMACount;

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2

static xQueueHandle uart2PacketDelivery;
STATIC_MEM_QUEUE_ALLOC(uart2PacketDelivery, 8, sizeof(SyslinkPacket));
Expand Down Expand Up @@ -103,7 +103,7 @@ static void uart2DmaInit(void)
DMA_InitStructureShare.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructureShare.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;
DMA_InitStructureShare.DMA_Channel = UART2_DMA_CH;
#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
DMA_InitStructureShare.DMA_Priority = DMA_Priority_High;
#else
DMA_InitStructureShare.DMA_Priority = DMA_Priority_Low;
Expand All @@ -112,7 +112,7 @@ static void uart2DmaInit(void)
NVIC_InitStructure.NVIC_IRQChannel = UART2_DMA_IRQ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_HIGH_PRI;
#else
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_MID_PRI;
Expand Down Expand Up @@ -169,14 +169,14 @@ void uart2Init(const uint32_t baudrate)
NVIC_InitStructure.NVIC_IRQChannel = UART2_IRQ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_SYSLINK_PRI;
#else
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_MID_PRI;
#endif
NVIC_Init(&NVIC_InitStructure);

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
uart2PacketDelivery = STATIC_MEM_QUEUE_CREATE(uart2PacketDelivery);
DEBUG_QUEUE_MONITOR_REGISTER(uart2PacketDelivery);
#else
Expand Down Expand Up @@ -245,7 +245,7 @@ int uart2Putchar(int ch)
return (unsigned char)ch;
}

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2

void uart2GetPacketBlocking(SyslinkPacket* packet)
{
Expand Down Expand Up @@ -397,7 +397,7 @@ void __attribute__((used)) DMA1_Stream6_IRQHandler(void)
}
#endif

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2

void __attribute__((used)) USART2_IRQHandler(void)
{
Expand Down
21 changes: 21 additions & 0 deletions src/hal/src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,24 @@ config PM_AUTO_SHUTDOWN
occured.

endmenu

menu "Communication"

config CRTP_OVER_UART2
bool "Move CRTP communication to UART2 instead of over radio"
default n
help
The CRTP (Crazy Real Time Protocol) communication is normally
sent over the radio link (via Syslink). By enabling this the
communication will instead be sent over UART2 to communicate
with e.g. a companion computer instead.

config CRTP_OVER_UART2_BAUDRATE
int "CRTP over UART2 baudrate"
depends on CRTP_OVER_UART2
range 9600 2000000
default 512000
help
Uart baudrate to be used.

endmenu
11 changes: 6 additions & 5 deletions src/hal/src/syslink.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "semphr.h"

#include "config.h"
#include "autoconf.h"
#include "debug.h"
#include "syslink.h"
#include "radiolink.h"
Expand All @@ -45,7 +46,7 @@
#include "static_mem.h"
#include "system.h"

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
#include "uart2.h"
#endif

Expand All @@ -70,7 +71,7 @@ static void syslinkTask(void *param)
}
}

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2

STATIC_MEM_TASK_ALLOC(uart2Task, UART2_TASK_STACKSIZE);

Expand Down Expand Up @@ -126,8 +127,8 @@ void syslinkInit()

STATIC_MEM_TASK_CREATE(syslinkTask, syslinkTask, SYSLINK_TASK_NAME, NULL, SYSLINK_TASK_PRI);

#ifdef UART2_LINK_COMM
uart2Init(512000);
#ifdef CONFIG_CRTP_OVER_UART2
uart2Init(CONFIG_CRTP_OVER_UART2_BAUDRATE);
STATIC_MEM_TASK_CREATE(uart2Task, uart2Task, UART2_TASK_NAME, NULL, UART2_TASK_PRI);
#endif

Expand Down Expand Up @@ -171,7 +172,7 @@ int syslinkSendPacket(SyslinkPacket *slp)
sendBuffer[dataSize-2] = cksum[0];
sendBuffer[dataSize-1] = cksum[1];

#ifdef UART2_LINK_COMM
#ifdef CONFIG_CRTP_OVER_UART2
uint8_t groupType;
groupType = slp->type & SYSLINK_GROUP_MASK;
switch (groupType)
Expand Down
2 changes: 1 addition & 1 deletion test/deck/drivers/esp32/src/test_esp_slip.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// File under test esp_slip.crftq
#include "esp_slip.h"

#define UART2_LINK_COMM 1
#define CONFIG_CRTP_OVER_UART2 1

#include <string.h>

Expand Down

0 comments on commit 0b0f345

Please sign in to comment.