diff --git a/Host/Source/LibOpenBLT/openblt.pas b/Host/Source/LibOpenBLT/openblt.pas index 5d517f40..d1a71194 100644 --- a/Host/Source/LibOpenBLT/openblt.pas +++ b/Host/Source/LibOpenBLT/openblt.pas @@ -93,7 +93,7 @@ type // Structure layout of the XCP version 1.0 CAN transport layer settings. tBltTransportSettingsXcpV10Can = record - deviceName: PAnsiChar; // Device name such as /dev/can0. + deviceName: PAnsiChar; // Device name such as can0, pcanusb, etc. deviceChannel: LongWord; // Channel on the device to use. baudrate: LongWord; // Communication speed in bits/sec. transmitId: LongWord; // Transmit CAN identifier. diff --git a/Host/Source/LibOpenBLT/xcptpcan.c b/Host/Source/LibOpenBLT/xcptpcan.c new file mode 100644 index 00000000..69e94ed2 --- /dev/null +++ b/Host/Source/LibOpenBLT/xcptpcan.c @@ -0,0 +1,170 @@ +/************************************************************************************//** +* \file xcptpcan.c +* \brief XCP CAN transport layer source file. +* \ingroup XcpTpCan +* \internal +*---------------------------------------------------------------------------------------- +* C O P Y R I G H T +*---------------------------------------------------------------------------------------- +* Copyright (c) 2017 by Feaser http://www.feaser.com All rights reserved +* +*---------------------------------------------------------------------------------------- +* L I C E N S E +*---------------------------------------------------------------------------------------- +* This file is part of OpenBLT. OpenBLT 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. +* +* OpenBLT 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 have received a copy of the GNU General Public License along with OpenBLT. It +* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy. +* +* \endinternal +****************************************************************************************/ + +/**************************************************************************************** +* Include files +****************************************************************************************/ +#include /* for assertions */ +#include /* for standard integer types */ +#include /* for NULL declaration */ +#include /* for boolean type */ +#include /* for standard library */ +#include /* for string library */ +#include "session.h" /* Communication session module */ +#include "xcploader.h" /* XCP loader module */ +#include "xcptpcan.h" /* XCP CAN transport layer */ +#include "util.h" /* Utility module */ +#include "candriver.h" /* Generic CAN driver module */ +#if defined(PLATFORM_WIN32) +#include "pcanusb.h" /* Peak PCAN-USB interface */ +#endif + + +/**************************************************************************************** +* Function prototypes +****************************************************************************************/ +static void XcpTpCanInit(void const * settings); +static void XcpTpCanTerminate(void); +static bool XcpTpCanConnect(void); +static void XcpTpCanDisconnect(void); +static bool XcpTpCanSendPacket(tXcpTransportPacket const * txPacket, + tXcpTransportPacket * rxPacket, uint16_t timeout); + + +/**************************************************************************************** +* Local constant declarations +****************************************************************************************/ +/** \brief XCP transport layer structure filled with CAN specifics. */ +static const tXcpTransport canTransport = +{ + XcpTpCanInit, + XcpTpCanTerminate, + XcpTpCanConnect, + XcpTpCanDisconnect, + XcpTpCanSendPacket +}; + + +/***********************************************************************************//** +** \brief Obtains a pointer to the transport layer structure, so that it can be +** linked to the XCP protocol module. +** \return Pointer to transport layer structure. +** +****************************************************************************************/ +tXcpTransport const * XcpTpCanGetTransport(void) +{ + return &canTransport; +} /*** end of XcpTpCanGetTransport ***/ + + +/************************************************************************************//** +** \brief Initializes the transport layer. +** \param settings Pointer to settings structure. +** \return None. +** +****************************************************************************************/ +static void XcpTpCanInit(void const * settings) +{ + /* Check parameters. */ + assert(settings != NULL); + + /* Only continue with valid parameters. */ + if (settings != NULL) /*lint !e774 */ + { + /* ##Vg TODO Extract and set the pointer to the CAN interface to link. */ + } + /* ##Vg TODO Implement CAN module initialization. */ +} /*** end of XcpTpCanInit ***/ + + +/************************************************************************************//** +** \brief Terminates the transport layer. +** +****************************************************************************************/ +static void XcpTpCanTerminate(void) +{ + /* ##Vg TODO Implement. */ +} /*** end of XcpTpCanTerminate ***/ + + +/************************************************************************************//** +** \brief Connects to the transport layer. +** \return True is connected, false otherwise. +** +****************************************************************************************/ +static bool XcpTpCanConnect(void) +{ + bool result = false; + + /* ##Vg TODO Implement. */ + + /* Give the result back to the caller. */ + return result; +} /*** end of XcpTpCanConnect ***/ + + +/************************************************************************************//** +** \brief Disconnects from the transport layer. +** +****************************************************************************************/ +static void XcpTpCanDisconnect(void) +{ + /* ##Vg TODO Disconnect from the CAN bus. */ +} /*** end of XcpTpCanDisconnect ***/ + + +/************************************************************************************//** +** \brief Transmits an XCP packet on the transport layer and attempts to receive the +** response packet within the specified timeout. +** \param txPacket Pointer to the packet to transmit. +** \param rxPacket Pointer where the received packet info is stored. +** \param timeout Maximum time in milliseconds to wait for the reception of the +** response packet. +** \return True is successful and a response packet was received, false otherwise. +** +****************************************************************************************/ +static bool XcpTpCanSendPacket(tXcpTransportPacket const * txPacket, + tXcpTransportPacket * rxPacket, uint16_t timeout) +{ + bool result = false; + + /* Check parameters. */ + assert(txPacket != NULL); + assert(rxPacket != NULL); + + /* Only continue with valid parameters. */ + if ( (txPacket != NULL) && (rxPacket != NULL) ) /*lint !e774 */ + { + /* ##Vg TODO Implement. */ + } + /* Give the result back to the caller. */ + return result; +} /*** end of XcpTpCanSendPacket ***/ + + +/*********************************** end of xcptpcan.c *********************************/ diff --git a/Host/Source/LibOpenBLT/xcptpcan.h b/Host/Source/LibOpenBLT/xcptpcan.h new file mode 100644 index 00000000..e43c6ad0 --- /dev/null +++ b/Host/Source/LibOpenBLT/xcptpcan.h @@ -0,0 +1,67 @@ +/************************************************************************************//** +* \file xcptpcan.h +* \brief XCP CAN transport layer header file. +* \ingroup XcpTpCan +* \internal +*---------------------------------------------------------------------------------------- +* C O P Y R I G H T +*---------------------------------------------------------------------------------------- +* Copyright (c) 2017 by Feaser http://www.feaser.com All rights reserved +* +*---------------------------------------------------------------------------------------- +* L I C E N S E +*---------------------------------------------------------------------------------------- +* This file is part of OpenBLT. OpenBLT 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. +* +* OpenBLT 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 have received a copy of the GNU General Public License along with OpenBLT. It +* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy. +* +* \endinternal +****************************************************************************************/ +/************************************************************************************//** +* \defgroup XcpTpCan XCP CAN transport layer +* \brief This module implements the XCP transport layer for CAN. +* \ingroup XcpLoader +****************************************************************************************/ +#ifndef XCPTPCAN_H +#define XCPTPCAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/**************************************************************************************** +* Type definitions +****************************************************************************************/ +/** \brief Layout of structure with settings specific to the XCP transport layer module + * for CAN. + */ +typedef struct t_xcp_tp_can_settings +{ + char const * device; /**< Device name such as can0, pcanusb, etc. */ + uint32_t channel; /**< Channel on the device to use. */ + uint32_t baudrate; /**< Communication speed in bits/sec. */ + uint32_t transmitId; /**< Transmit CAN identifier. */ + uint32_t receiveId; /**< Receive CAN identifier. */ + bool useExtended; /**< Boolean to configure 29-bit CAN identifiers. */ +} tXcpTpCanSettings; + + +/*************************************************************************************** +* Function prototypes +****************************************************************************************/ +tXcpTransport const * XcpTpCanGetTransport(void); + +#ifdef __cplusplus +} +#endif + +#endif /* XCPTPCAN_H */ +/*********************************** end of xcptpcan.h *********************************/ diff --git a/Host/Source/LibOpenBLT/xcptpuart.c b/Host/Source/LibOpenBLT/xcptpuart.c index 2806a8cb..d66ccffb 100644 --- a/Host/Source/LibOpenBLT/xcptpuart.c +++ b/Host/Source/LibOpenBLT/xcptpuart.c @@ -83,7 +83,7 @@ static tXcpTpUartSettings tpUartSettings; tXcpTransport const * XcpTpUartGetTransport(void) { return &uartTransport; -} /*** end of XcpLoaderGetProtocol ***/ +} /*** end of XcpTpUartGetTransport ***/ /************************************************************************************//** diff --git a/Host/libopenblt.dll b/Host/libopenblt.dll index e1ad8195..b3cca9dd 100644 Binary files a/Host/libopenblt.dll and b/Host/libopenblt.dll differ