- Supported NET communication module for future TCP/IP support.

- Implemented XCP connect hook function for the mode. Could be used as node id in a multi XCP slave network.
- Reworked communication module so that it builds even if no internally supported communication module is configured. This allows a custom communication module to be added that could even use XCP if desired.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@69 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
Frank Voorburg 2014-02-06 14:01:02 +00:00
parent e2d68890f6
commit 7c4819c3bd
5 changed files with 223 additions and 27 deletions

View File

@ -44,6 +44,9 @@
#if (BOOT_COM_USB_ENABLE > 0)
#include "usb.h" /* usb driver module */
#endif
#if (BOOT_COM_NET_ENABLE > 0)
#include "net.h" /* tcp/ip driver module */
#endif
#if (BOOT_COM_ENABLE > 0)
@ -115,6 +118,10 @@ void ComInit(void)
#if (BOOT_COM_USB_ENABLE > 0)
/* initialize the USB interface */
UsbInit();
#endif
#if (BOOT_COM_NET_ENABLE > 0)
/* initialize the TCP/IP interface */
NetInit();
#endif
/* simulate the reception of a CONNECT command if requested */
if (comEntryStateConnect == BLT_TRUE)
@ -142,6 +149,9 @@ void ComTask(void)
#if (BOOT_COM_USB_ENABLE > 0)
static unsigned char xcpCtoReqPacket[BOOT_COM_USB_RX_MAX_DATA];
#endif
#if (BOOT_COM_NET_ENABLE > 0)
static unsigned char xcpCtoReqPacket[BOOT_COM_NET_RX_MAX_DATA];
#endif
#if (BOOT_COM_CAN_ENABLE > 0)
if (CanReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE)
@ -164,6 +174,13 @@ void ComTask(void)
XcpPacketReceived(&xcpCtoReqPacket[0]);
}
#endif
#if (BOOT_COM_NET_ENABLE > 0)
if (NetReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE)
{
/* process packet */
XcpPacketReceived(&xcpCtoReqPacket[0]);
}
#endif
} /*** end of ComTask ***/
@ -206,6 +223,10 @@ void ComTransmitPacket(blt_int8u *data, blt_int16u len)
/* transmit the packet */
UsbTransmitPacket(data, len);
#endif
#if (BOOT_COM_NET_ENABLE > 0)
/* transmit the packet */
NetTransmitPacket(data, len);
#endif
/* send signal that the packet was transmitted */
XcpPacketTransmitted();

View File

@ -56,6 +56,12 @@
/** \brief Defines the maximum number of bytes for transport reception on USB. */
#define BOOT_COM_RX_MAX_DATA (BOOT_COM_USB_RX_MAX_DATA)
#endif
#if (BOOT_COM_NET_ENABLE > 0)
/** \brief Defines the maximum number of bytes for transport transmission on TCP/IP. */
#define BOOT_COM_TX_MAX_DATA (BOOT_COM_NET_TX_MAX_DATA)
/** \brief Defines the maximum number of bytes for transport reception on TCP/IP. */
#define BOOT_COM_RX_MAX_DATA (BOOT_COM_NET_RX_MAX_DATA)
#endif
/****************************************************************************************

View File

@ -181,6 +181,10 @@
#endif
#endif /* BOOT_COM_UART_ENABLE > 0 */
#ifndef BOOT_COM_USB_ENABLE
#define BOOT_COM_USB_ENABLE (0)
#endif
#if (BOOT_COM_USB_ENABLE > 0)
#ifndef BOOT_COM_USB_TX_MAX_DATA
#error "BOOT_COM_USB_TX_MAX_DATA is missing in blt_conf.h"
@ -199,6 +203,142 @@
#endif
#endif /* BOOT_COM_USB_ENABLE > 0 */
#ifndef BOOT_COM_NET_ENABLE
#define BOOT_COM_NET_ENABLE (0)
#endif
#if (BOOT_COM_NET_ENABLE > 0)
#ifndef BOOT_COM_NET_TX_MAX_DATA
#error "BOOT_COM_NET_TX_MAX_DATA is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_TX_MAX_DATA <= 0)
#error "BOOT_COM_NET_TX_MAX_DATA must be > 0"
#endif
#ifndef BOOT_COM_NET_RX_MAX_DATA
#error "BOOT_COM_NET_RX_MAX_DATA is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_RX_MAX_DATA <= 0)
#error "BOOT_COM_NET_RX_MAX_DATA must be > 0"
#endif
#ifndef BOOT_COM_NET_IPADDR0
#error "BOOT_COM_NET_IPADDR0 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_IPADDR0 < 0)
#error "BOOT_COM_NET_IPADDR0 must be >= 0"
#endif
#ifndef BOOT_COM_NET_IPADDR1
#error "BOOT_COM_NET_IPADDR1 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_IPADDR1 < 0)
#error "BOOT_COM_NET_IPADDR1 must be >= 0"
#endif
#ifndef BOOT_COM_NET_IPADDR2
#error "BOOT_COM_NET_IPADDR2 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_IPADDR2 < 0)
#error "BOOT_COM_NET_IPADDR2 must be >= 0"
#endif
#ifndef BOOT_COM_NET_IPADDR3
#error "BOOT_COM_NET_IPADDR3 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_IPADDR3 < 0)
#error "BOOT_COM_NET_IPADDR3 must be >= 0"
#endif
#ifndef BOOT_COM_NET_NETMASK0
#error "BOOT_COM_NET_NETMASK0 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_NETMASK0 < 0)
#error "BOOT_COM_NET_NETMASK0 must be >= 0"
#endif
#ifndef BOOT_COM_NET_NETMASK1
#error "BOOT_COM_NET_NETMASK1 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_NETMASK1 < 0)
#error "BOOT_COM_NET_NETMASK1 must be >= 0"
#endif
#ifndef BOOT_COM_NET_NETMASK2
#error "BOOT_COM_NET_NETMASK2 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_NETMASK2 < 0)
#error "BOOT_COM_NET_NETMASK2 must be >= 0"
#endif
#ifndef BOOT_COM_NET_NETMASK3
#error "BOOT_COM_NET_NETMASK3 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_NETMASK3 < 0)
#error "BOOT_COM_NET_NETMASK3 must be >= 0"
#endif
#ifndef BOOT_COM_NET_MACADDR0
#error "BOOT_COM_NET_MACADDR0 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_MACADDR0 < 0)
#error "BOOT_COM_NET_MACADDR0 must be >= 0"
#endif
#ifndef BOOT_COM_NET_MACADDR1
#error "BOOT_COM_NET_MACADDR1 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_MACADDR1 < 0)
#error "BOOT_COM_NET_MACADDR1 must be >= 0"
#endif
#ifndef BOOT_COM_NET_MACADDR2
#error "BOOT_COM_NET_MACADDR2 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_MACADDR2 < 0)
#error "BOOT_COM_NET_MACADDR2 must be >= 0"
#endif
#ifndef BOOT_COM_NET_MACADDR3
#error "BOOT_COM_NET_MACADDR3 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_MACADDR3 < 0)
#error "BOOT_COM_NET_MACADDR3 must be >= 0"
#endif
#ifndef BOOT_COM_NET_MACADDR4
#error "BOOT_COM_NET_MACADDR4 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_MACADDR4 < 0)
#error "BOOT_COM_NET_MACADDR4 must be >= 0"
#endif
#ifndef BOOT_COM_NET_MACADDR5
#error "BOOT_COM_NET_MACADDR5 is missing in blt_conf.h"
#endif
#if (BOOT_COM_NET_MACADDR5 < 0)
#error "BOOT_COM_NET_MACADDR5 must be >= 0"
#endif
#endif /* BOOT_COM_USB_ENABLE > 0 */
#ifndef BOOT_FILE_SYS_ENABLE
#define BOOT_FILE_SYS_ENABLE (0)
#endif
@ -241,20 +381,11 @@
#endif
#endif /* BOOT_FILE_SYS_ENABLE > 0 */
#if (BOOT_FILE_SYS_ENABLE == 0)
#if (BOOT_COM_CAN_ENABLE == 0) && \
(BOOT_COM_UART_ENABLE == 0) && \
(BOOT_COM_USB_ENABLE == 0)
#error "If not booting from file system (BOOT_FILE_SYS_ENABLE) then a communication interface must be enabled (BOOT_COM_XXX_ENABLE) in blt_conf.h"
#endif
#endif /* BOOT_FILE_SYS_ENABLE == 0 */
#if ((BOOT_COM_CAN_ENABLE + BOOT_COM_UART_ENABLE + BOOT_COM_USB_ENABLE) > 1)
#if ((BOOT_COM_CAN_ENABLE + BOOT_COM_UART_ENABLE + BOOT_COM_USB_ENABLE + BOOT_COM_NET_ENABLE) > 1)
#error "Too many communication interfaces enabled (BOOT_COM_XXX_ENABLE) in blt_conf.h"
#endif
#if (BOOT_COM_CAN_ENABLE == 1) || (BOOT_COM_UART_ENABLE == 1) || (BOOT_COM_USB_ENABLE == 1)
#if (BOOT_COM_CAN_ENABLE == 1) || (BOOT_COM_UART_ENABLE == 1) || (BOOT_COM_NET_ENABLE == 1) || (BOOT_COM_USB_ENABLE == 1)
#define BOOT_COM_ENABLE (1)
#else
#define BOOT_COM_ENABLE (0)

View File

@ -37,7 +37,6 @@
#include "boot.h" /* bootloader generic header */
#if (BOOT_COM_ENABLE > 0)
/****************************************************************************************
* Defines
****************************************************************************************/
@ -186,9 +185,26 @@ static void XcpCmdProgramPrepare(blt_int8u *data);
/****************************************************************************************
* Hook functions
****************************************************************************************/
#if F_CAL_RES_PAGING_EN == 1
blt_int8u AppCalSetPage(blt_int8u segment, blt_int8u page);
blt_int8u AppCalGetPage(blt_int8u segment);
#if (XCP_RES_PAGING_EN == 1)
extern blt_int8u XcpCalSetPageHook(blt_int8u segment, blt_int8u page);
extern blt_int8u XcpCalGetPageHook(blt_int8u segment);
#endif
#if (XCP_CONNECT_MODE_HOOK_EN == 1)
extern blt_bool XcpConnectModeHook(blt_int8u mode);
#endif
/****************************************************************************************
* External functions
****************************************************************************************/
#if (BOOT_COM_ENABLE == 0)
/* in case no internally supported communication interface is used, a custom
* communication module can be added. In order to use the XCP protocol in the custom
* communication module, this hook function needs to be implemented. In the XCP protocol
* is not needed, then simply remove the xcp.c source from the project.
*/
extern void XcpTransmitPacketHook(blt_int8u *data, blt_int16u len);
#endif
@ -356,11 +372,15 @@ void XcpPacketReceived(blt_int8u *data)
XcpSetCtoError(XCP_ERR_CMD_BUSY);
}
/* set cto packet transmission pending flag */
xcpInfo.ctoPending = 1;
/* send the response if it contains something */
if (xcpInfo.ctoLen > 0)
{
/* set cto packet transmission pending flag */
xcpInfo.ctoPending = 1;
/* transmit the cto response packet */
XcpTransmitPacket(xcpInfo.ctoData, xcpInfo.ctoLen);
/* transmit the cto response packet */
XcpTransmitPacket(xcpInfo.ctoData, xcpInfo.ctoLen);
}
} /*** end of XcpPacketReceived ***/
@ -374,7 +394,12 @@ void XcpPacketReceived(blt_int8u *data)
static void XcpTransmitPacket(blt_int8u *data, blt_int16s len)
{
/* submit packet to the communication interface for transmission */
#if (BOOT_COM_ENABLE == 0)
XcpTransmitPacketHook(data, len);
#else
ComTransmitPacket(data, len);
#endif
} /*** end of XcpTransmitPacket ***/
@ -545,7 +570,20 @@ static void XcpCmdConnect(blt_int8u *data)
return;
}
#endif
#if (XCP_CONNECT_MODE_HOOK_EN == 1)
/* pass on the mode to a application specific hook function. This function can determine
* is the mode is supported or not. A return value of BLT_FALSE causes the CONNECT command
* to be ignored. Note that this mode could potentially be used to specify a node ID in a
* multi XCP slave system.
*/
if (XcpConnectModeHook(data[1]) == BLT_FALSE)
{
/* set the response length to 0 to suppress it */
xcpInfo.ctoLen = 0;
return;
}
#endif
/* enable resource protection */
XcpProtectResources();
@ -603,6 +641,7 @@ static void XcpCmdConnect(blt_int8u *data)
/* set packet length */
xcpInfo.ctoLen = 8;
} /*** end of XcpCmdConnect ***/
@ -1045,7 +1084,7 @@ static void XcpCmdSetCalPage(blt_int8u *data)
#endif
/* select the page. note that the mode parameter is ignored */
if (AppCalSetPage(data[2], data[3]) == 0)
if (XcpCalSetPageHook(data[2], data[3]) == 0)
{
/* calibration page could not be selected */
XcpSetCtoError(XCP_ERR_PAGE_NOT_VALID);
@ -1087,7 +1126,7 @@ static void XcpCmdGetCalPage(blt_int8u *data)
xcpInfo.ctoData[2] = 0;
/* store the calibration page */
xcpInfo.ctoData[3] = AppCalGetPage(data[2]);
xcpInfo.ctoData[3] = XcpCalGetPageHook(data[2]);
/* set packet length */
xcpInfo.ctoLen = 4;
@ -1328,7 +1367,6 @@ static void XcpCmdProgramPrepare(blt_int8u *data)
} /*** end of XcpCmdProgramPrepare ***/
#endif /* XCP_RES_PROGRAMMING_EN == 1 */
#endif /* BOOT_COM_ENABLE > 0 */
/******************************** end of xcp.c *****************************************/

View File

@ -33,7 +33,6 @@
#ifndef XCP_H
#define XCP_H
#if (BOOT_COM_ENABLE > 0)
/****************************************************************************************
* Configuration
****************************************************************************************/
@ -157,7 +156,8 @@ void XcpPacketReceived(blt_int8u *data);
#endif
#if (XCP_CTO_PACKET_LEN < 1)
#error "XCP.H, XCP_CTO_PACKET_LEN must be at least 1."
#undef XCP_CTO_PACKET_LEN
#define XCP_CTO_PACKET_LEN (8)
#endif
#if (XCP_CTO_PACKET_LEN > 256)
@ -170,7 +170,8 @@ void XcpPacketReceived(blt_int8u *data);
#endif
#if (XCP_DTO_PACKET_LEN < 1)
#error "XCP.H, XCP_DTO_PACKET_LEN must be at least 1."
#undef XCP_DTO_PACKET_LEN
#define XCP_DTO_PACKET_LEN (8)
#endif
#if (XCP_DTO_PACKET_LEN > 65536)
@ -236,7 +237,6 @@ void XcpPacketReceived(blt_int8u *data);
#error "XCP.H, XCP_SEED_KEY_PROTECTION_EN must be 0 or 1."
#endif
#endif /* BOOT_COM_ENABLE > 0 */
#endif /* XCP_H */
/******************************** end of xcp.h *~~~~~***********************************/