mirror of https://github.com/rusefi/openblt.git
Refs #316. Refactoring to perform CAN interface linking inside the CAN driver module's CanInit() itself.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@321 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
ba70bb8ef4
commit
2b3f4b7f31
|
@ -33,7 +33,14 @@
|
|||
#include <stdint.h> /* for standard integer types */
|
||||
#include <stddef.h> /* for NULL declaration */
|
||||
#include <stdbool.h> /* for boolean type */
|
||||
#include <string.h> /* for string library */
|
||||
#include "candriver.h" /* Generic CAN driver module */
|
||||
#if defined(PLATFORM_WIN32)
|
||||
#include "pcanusb.h" /* Peak PCAN-USB interface */
|
||||
#endif
|
||||
#if defined(PLATFORM_LINUX)
|
||||
#include "socketcan.h" /* SocketCAN interface */
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
|
@ -49,10 +56,9 @@ static bool canConnected;
|
|||
/************************************************************************************//**
|
||||
** \brief Initializes the CAN module. Typically called once at program startup.
|
||||
** \param settings Pointer to the CAN module settings.
|
||||
** \param interface Pointer to the CAN interface to link.
|
||||
**
|
||||
****************************************************************************************/
|
||||
void CanInit(tCanSettings const * settings, tCanInterface const * const interface)
|
||||
void CanInit(tCanSettings const * settings)
|
||||
{
|
||||
/* Initialize locals. */
|
||||
canIfPtr = NULL;
|
||||
|
@ -60,15 +66,41 @@ void CanInit(tCanSettings const * settings, tCanInterface const * const interfac
|
|||
|
||||
/* Check parameters. */
|
||||
assert(settings != NULL);
|
||||
assert(interface != NULL);
|
||||
|
||||
/* Only continue with valid parameters. */
|
||||
if ( (settings != NULL) && (interface != NULL) ) /*lint !e774 */
|
||||
if (settings != NULL) /*lint !e774 */
|
||||
{
|
||||
/* Link the CAN interface. */
|
||||
canIfPtr = interface;
|
||||
/* Initialize the CAN interface. */
|
||||
canIfPtr->Init(settings);
|
||||
/* Check device name. */
|
||||
assert(settings->devicename != NULL);
|
||||
|
||||
/* Only continue with a valid device name. */
|
||||
if (settings->devicename != NULL) /*lint !e774 */
|
||||
{
|
||||
/* Determine the pointer to the correct CAN interface, based on the specified
|
||||
* device name.
|
||||
*/
|
||||
#if defined(PLATFORM_WIN32)
|
||||
if (strcmp(settings->devicename, "peak_pcanusb") == 0)
|
||||
{
|
||||
canIfPtr = PCanUsbGetInterface();
|
||||
}
|
||||
#endif
|
||||
#if defined(PLATFORM_LINUX)
|
||||
/* On Linux, the device name is the name of the SocketCAN link, so always link
|
||||
* the SocketCAN interface to the CAN driver.
|
||||
*/
|
||||
canIfPtr = SocketCanGetInterface();
|
||||
#endif
|
||||
/* Check validity of the interface. */
|
||||
assert(canIfPtr != NULL);
|
||||
|
||||
/* Only continue with a valid interface. */
|
||||
if (canIfPtr != NULL) /*lint !e774 */
|
||||
{
|
||||
/* Initialize the CAN interface. */
|
||||
canIfPtr->Init(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /*** end of CanInit ***/
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ typedef struct t_can_interface
|
|||
/***************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
void CanInit(tCanSettings const * settings, tCanInterface const * const interface);
|
||||
void CanInit(tCanSettings const * settings);
|
||||
void CanTerminate(void);
|
||||
bool CanConnect(void);
|
||||
void CanDisconnect(void);
|
||||
|
|
|
@ -40,12 +40,6 @@
|
|||
#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
|
||||
#if defined(PLATFORM_LINUX)
|
||||
#include "socketcan.h" /* SocketCAN interface */
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
|
@ -124,7 +118,6 @@ tXcpTransport const * XcpTpCanGetTransport(void)
|
|||
static void XcpTpCanInit(void const * settings)
|
||||
{
|
||||
char * canDeviceName;
|
||||
tCanInterface const * canInterface = NULL;
|
||||
tCanSettings canSettings;
|
||||
|
||||
/* Reset transport layer settings. */
|
||||
|
@ -158,25 +151,6 @@ static void XcpTpCanInit(void const * settings)
|
|||
{
|
||||
strcpy(canDeviceName, ((tXcpTpCanSettings *)settings)->device);
|
||||
tpCanSettings.device = canDeviceName;
|
||||
|
||||
/* ##Vg TODO Refactor such that the CAN driver does this interface linking
|
||||
* automatically.
|
||||
*/
|
||||
/* Determine the pointer to the correct CAN interface, based on the specified
|
||||
* device name.
|
||||
*/
|
||||
#if defined(PLATFORM_WIN32)
|
||||
if (strcmp(tpCanSettings.device, "peak_pcanusb") == 0)
|
||||
{
|
||||
canInterface = PCanUsbGetInterface();
|
||||
}
|
||||
#endif
|
||||
#if defined(PLATFORM_LINUX)
|
||||
/* On Linux, the device name is the name of the SocketCAN link, so always link
|
||||
* the SocketCAN interface to the CAN driver.
|
||||
*/
|
||||
canInterface = SocketCanGetInterface();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +200,7 @@ static void XcpTpCanInit(void const * settings)
|
|||
}
|
||||
canSettings.mask = 0x9fffffff;
|
||||
/* Initialize the CAN driver. */
|
||||
CanInit(&canSettings, canInterface);
|
||||
CanInit(&canSettings);
|
||||
/* Register CAN event functions. */
|
||||
CanRegisterEvents(&canEvents);
|
||||
} /*** end of XcpTpCanInit ***/
|
||||
|
|
Loading…
Reference in New Issue