mirror of https://github.com/rusefi/openblt.git
rs232: support several channels
This commit is contained in:
parent
dd0ba5104d
commit
a36636027e
|
@ -44,6 +44,8 @@
|
|||
#define RS232_CTO_RX_PACKET_TIMEOUT_MS (100u)
|
||||
/** \brief Timeout for transmitting a byte in milliseconds. */
|
||||
#define RS232_BYTE_TX_TIMEOUT_MS (10u)
|
||||
|
||||
#ifndef BOOT_COM_RS232_CHANNELS_N
|
||||
/* map the configured UART channel index to the STM32's USART peripheral */
|
||||
#if (BOOT_COM_RS232_CHANNEL_INDEX == 0)
|
||||
/** \brief Set UART base address to USART1. */
|
||||
|
@ -55,7 +57,13 @@
|
|||
/** \brief Set UART base address to USART3. */
|
||||
#define USART_CHANNEL USART3
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BOOT_COM_RS232_CHANNELS_N
|
||||
/* const */ USART_TypeDef *Rs232ChannelDevs[BOOT_COM_RS232_CHANNELS_N] = BOOT_COM_RS232_CHANNEL_DEVS;
|
||||
|
||||
USART_TypeDef *USART_CHANNEL = BOOT_COM_RS232_CHANNEL_DEFAULT_DEV; //(USART_TypeDef *)Rs232ChannelDevs[0];
|
||||
#endif
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
|
@ -63,6 +71,19 @@
|
|||
static blt_bool Rs232ReceiveByte(blt_int8u *data);
|
||||
static void Rs232TransmitByte(blt_int8u data);
|
||||
|
||||
#ifdef BOOT_COM_RS232_CHANNELS_N
|
||||
blt_bool Rs232Switch(blt_int8u channel)
|
||||
{
|
||||
if (channel >= BOOT_COM_RS232_CHANNELS_N)
|
||||
{
|
||||
return BLT_FALSE;
|
||||
}
|
||||
|
||||
USART_CHANNEL = Rs232ChannelDevs[channel];
|
||||
|
||||
return BLT_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Initializes the RS232 communication interface.
|
||||
|
@ -73,12 +94,14 @@ void Rs232Init(void)
|
|||
{
|
||||
LL_USART_InitTypeDef USART_InitStruct;
|
||||
|
||||
#ifndef BOOT_COM_RS232_CHANNELS_N
|
||||
/* the current implementation supports USART1 - USART5. throw an assertion error in
|
||||
* case a different UART channel is configured.
|
||||
*/
|
||||
ASSERT_CT((BOOT_COM_RS232_CHANNEL_INDEX == 0) ||
|
||||
(BOOT_COM_RS232_CHANNEL_INDEX == 1) ||
|
||||
(BOOT_COM_RS232_CHANNEL_INDEX == 2));
|
||||
#endif
|
||||
|
||||
/* disable the UART peripheral */
|
||||
LL_USART_Disable(USART_CHANNEL);
|
||||
|
|
|
@ -50,6 +50,9 @@
|
|||
****************************************************************************************/
|
||||
/** \brief Holds the communication interface of the currently active interface. */
|
||||
static tComInterfaceId comActiveInterface = COM_IF_OTHER;
|
||||
#ifdef BOOT_COM_RS232_CHANNELS_N
|
||||
static blt_int8s Rs232ActiveInterface = -1;
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
|
@ -69,8 +72,21 @@ void ComInit(void)
|
|||
comActiveInterface = COM_IF_CAN;
|
||||
#endif
|
||||
#if (BOOT_COM_RS232_ENABLE > 0)
|
||||
/* initialize the RS232 interface */
|
||||
/* initialize the RS232 interface(s) */
|
||||
#ifdef BOOT_COM_RS232_CHANNELS_N
|
||||
{
|
||||
blt_int8u i;
|
||||
for (i = 0; i < BOOT_COM_RS232_CHANNELS_N; i++)
|
||||
{
|
||||
if (Rs232Switch(i) == BLT_TRUE)
|
||||
{
|
||||
Rs232Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
Rs232Init();
|
||||
#endif
|
||||
/* set it as active */
|
||||
comActiveInterface = COM_IF_RS232;
|
||||
#endif
|
||||
|
@ -113,6 +129,34 @@ void ComTask(void)
|
|||
}
|
||||
#endif
|
||||
#if (BOOT_COM_RS232_ENABLE > 0)
|
||||
#ifdef BOOT_COM_RS232_CHANNELS_N
|
||||
if (Rs232ActiveInterface != -1) {
|
||||
if (Rs232ReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE)
|
||||
{
|
||||
/* make this the active interface */
|
||||
comActiveInterface = COM_IF_RS232;
|
||||
/* process packet */
|
||||
XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
blt_int8u i;
|
||||
for (i = 0; i < BOOT_COM_RS232_CHANNELS_N; i++)
|
||||
{
|
||||
if ((Rs232Switch(i) == BLT_TRUE) &&
|
||||
(Rs232ReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE))
|
||||
{
|
||||
/* make this the active interface */
|
||||
comActiveInterface = COM_IF_RS232;
|
||||
Rs232ActiveInterface = i;
|
||||
/* process packet */
|
||||
XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (Rs232ReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE)
|
||||
{
|
||||
/* make this the active interface */
|
||||
|
@ -121,6 +165,7 @@ void ComTask(void)
|
|||
XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if (BOOT_COM_USB_ENABLE > 0)
|
||||
if (UsbReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE)
|
||||
{
|
||||
|
|
|
@ -195,6 +195,7 @@
|
|||
#error "BOOT_COM_RS232_RX_MAX_DATA must be <= 255"
|
||||
#endif
|
||||
|
||||
#ifndef BOOT_COM_RS232_CHANNELS_N
|
||||
#ifndef BOOT_COM_RS232_CHANNEL_INDEX
|
||||
#error "BOOT_COM_RS232_CHANNEL_INDEX is missing in blt_conf.h"
|
||||
#endif
|
||||
|
@ -202,6 +203,7 @@
|
|||
#if (BOOT_COM_RS232_CHANNEL_INDEX < 0)
|
||||
#error "BOOT_COM_RS232_CHANNEL_INDEX must be >= 0"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* BOOT_COM_RS232_ENABLE > 0 */
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
#ifdef BOOT_COM_RS232_CHANNELS_N
|
||||
blt_bool Rs232Switch(blt_int8u channel);
|
||||
#endif
|
||||
void Rs232Init(void);
|
||||
void Rs232TransmitPacket(blt_int8u *data, blt_int8u len);
|
||||
blt_bool Rs232ReceivePacket(blt_int8u *data, blt_int8u *len);
|
||||
|
|
Loading…
Reference in New Issue