1
0
Fork 0

doxygen socketCAN + some simplifications.

This commit is contained in:
Janez 2020-02-28 16:37:41 +01:00
parent d52229917b
commit f21cde9ab0
10 changed files with 126 additions and 83 deletions

View file

@ -786,6 +786,7 @@ INPUT = README.md \
301 \
305 \
extra \
socketCAN
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

View file

@ -2,6 +2,7 @@
* Helper functions for implementing CANopen threads in Linux.
*
* @file CO_Linux_threads.h
* @ingroup CO_socketCAN
* @author Janez Paternoster
* @author Martin Wagner
* @copyright 2004 - 2015 Janez Paternoster
@ -32,10 +33,17 @@
extern "C" {
#endif
/*
/**
* @defgroup CO_socketCAN socketCAN
* @{
*
* Linux specific interface to CANopenNode
*
* CANopenNode runs in two threads: timer based realtime thread for CAN receive,
* SYNC and PDO and mainline thread for other processing.
*
* The "threads" specified here do not fork threads themselves, but require
* that two threads are provided by the calling application.
*
* It uses the global CO object and has one thread-local struct for variables.
*/
@ -79,8 +87,8 @@ extern void threadMain_process(CO_NMT_reset_cmd_t *reset);
* @remark If realtime is required, this thread must be registred as such in the Linux
* kernel.
*
* @param interval Interval of periodic timer in microseconds, recommended value
* for realtime response: 1000 us
* @param interval_us Interval of periodic timer in microseconds, recommended
* value for realtime response: 1000 us
*/
extern void CANrx_threadTmr_init(uint32_t interval_us);
@ -97,6 +105,8 @@ extern void CANrx_threadTmr_close(void);
*/
extern void CANrx_threadTmr_process();
/** @} */
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View file

@ -2,6 +2,7 @@
* CANopen Object Dictionary storage object for Linux SocketCAN.
*
* @file CO_OD_storage.h
* @ingroup CO_socketCAN
* @author Janez Paternoster
* @copyright 2015 - 2020 Janez Paternoster
*
@ -32,14 +33,27 @@
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/* For documentation see file drvTemplate/CO_OD_storage.h */
/**
* @defgroup CO_OD_storage OD_storage
* @ingroup CO_socketCAN
* @{
*
* Object Dictionary storage implementation for CANopenNode on Linux
*/
/**
* Callbacks for using inside @ref CO_OD_configure() function (for OD objects 1010 and 1011).
* Callback for use inside @ref CO_OD_configure() function for OD object 1010
*/
CO_SDO_abortCode_t CO_ODF_1010(CO_ODF_arg_t *ODF_arg);
/**
* Callback for use inside @ref CO_OD_configure() function for OD object 1011
*/
CO_SDO_abortCode_t CO_ODF_1011(CO_ODF_arg_t *ODF_arg);
@ -148,4 +162,10 @@ CO_ReturnError_t CO_OD_storage_autoSave(
*/
void CO_OD_storage_autoSaveClose(CO_OD_storage_t *odStor);
#endif
/** @} */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* CO_OD_STORAGE_H */

View file

@ -35,23 +35,14 @@
#include <sys/epoll.h>
#include "301/CO_driver.h"
#if defined CO_DRIVER_ERROR_REPORTING
#if __has_include("syslog1/log.h")
#include "syslog/log.h"
#include "msgs.h"
#else
#include "CO_msgs.h"
#endif
#else
#define log_printf(macropar_prio, macropar_message, ...)
#endif
#include "CO_error.h"
#if __has_include("301/CO_Emergency.h")
#include "301/CO_Emergency.h"
#define USE_EMERGENCY_OBJECT
#endif
pthread_mutex_t CO_EMCY_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t CO_OD_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -59,6 +50,7 @@ pthread_mutex_t CO_OD_mutex = PTHREAD_MUTEX_INITIALIZER;
static CO_ReturnError_t CO_CANmodule_addInterface(CO_CANmodule_t *CANmodule, const void *CANptr);
#endif
#ifdef CO_DRIVER_MULTI_INTERFACE
static const uint32_t CO_INVALID_COB_ID = 0xffffffff;
@ -106,10 +98,10 @@ static uint32_t CO_CANgetIndexFromIdent(
return lookup[ident];
}
#endif
#endif /* CO_DRIVER_MULTI_INTERFACE */
/** Disable socketCAN rx *****************************************************/
/** Disable socketCAN rx ******************************************************/
static CO_ReturnError_t disableRx(CO_CANmodule_t *CANmodule)
{
int ret;
@ -132,6 +124,7 @@ static CO_ReturnError_t disableRx(CO_CANmodule_t *CANmodule)
return retval;
}
/** Set up or update socketCAN rx filters *************************************/
static CO_ReturnError_t setRxFilters(CO_CANmodule_t *CANmodule)
{
@ -403,7 +396,7 @@ CO_ReturnError_t CO_CANmodule_addInterface(
log_printf(LOG_DEBUG, DBG_ERRNO, "setsockopt(can err)");
return CO_ERROR_SYSCALL;
}
#endif
#endif /* CO_DRIVER_ERROR_REPORTING */
/* Add socket to epoll */
ev.events = EPOLLIN;
@ -572,7 +565,7 @@ bool_t CO_CANrxBuffer_getInterface(
}
}
#endif
#endif /* CO_DRIVER_MULTI_INTERFACE */
/******************************************************************************/
@ -631,7 +624,7 @@ CO_ReturnError_t CO_CANtxBuffer_setInterface(
return CO_ERROR_PARAMETERS;
}
#endif
#endif /* CO_DRIVER_MULTI_INTERFACE */
/******************************************************************************/
static CO_ReturnError_t CO_CANCheckSendInterface(
@ -779,6 +772,7 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule)
* Therefore, error counter evaluation is included in rx function.*/
}
/******************************************************************************/
static CO_ReturnError_t CO_CANread(
CO_CANmodule_t *CANmodule,
@ -843,6 +837,7 @@ static CO_ReturnError_t CO_CANread(
return CO_ERROR_NO;
}
static int32_t CO_CANrxMsg(
CO_CANmodule_t *CANmodule,
struct can_frame *msg,
@ -887,6 +882,7 @@ static int32_t CO_CANrxMsg(
return retval;
}
/******************************************************************************/
int32_t CO_CANrxWait(CO_CANmodule_t *CANmodule, int fdTimer, CO_CANrxMsg_t *buffer)
{

View file

@ -149,9 +149,8 @@ typedef struct {
uint8_t padding[3]; /* ensure alignment */
uint8_t data[8];
volatile bool_t bufferFull; /* not used */
volatile bool_t syncFlag;
/* info about transmit message */
int32_t CANbaseAddress; /* CAN Interface identifier to use */
volatile bool_t syncFlag; /* info about transmit message */
const void *CANptr; /* CAN Interface identifier to use */
} CO_CANtx_t;
@ -160,7 +159,7 @@ typedef struct {
/* socketCAN interface object */
typedef struct {
int32_t CANbaseAddress; /* CAN Interface identifier */
const void *CANptr; /* CAN Interface identifier */
char ifName[IFNAMSIZ]; /* CAN Interface name */
int fd; /* socketCAN file descriptor */
#ifdef CO_DRIVER_ERROR_REPORTING

View file

@ -2,7 +2,6 @@
* CAN module object for Linux socketCAN Error handling.
*
* @file CO_error.c
* @ingroup CO_driver
* @author Martin Wagner
* @copyright 2018 - 2020 Neuberger Gebaeudeautomation GmbH
*
@ -32,17 +31,6 @@
#include "301/CO_driver.h"
#include "CO_error.h"
#if defined CO_DRIVER_ERROR_REPORTING
#if __has_include("syslog/log.h")
#include "syslog/log.h"
#include "msgs.h"
#else
#include "CO_msgs.h"
#endif
#else
#define log_printf(macropar_prio, macropar_message, ...)
#endif
/**
* Reset CAN interface and set to listen only mode

View file

@ -1,8 +1,8 @@
/**
* CAN module object for Linux socketCAN Error handling.
* CANopenNode Linux socketCAN Error handling.
*
* @file CO_error.h
* @ingroup CO_driver
* @ingroup CO_socketCAN
* @author Martin Wagner
* @copyright 2018 - 2020 Neuberger Gebaeudeautomation GmbH
*
@ -30,10 +30,46 @@
#include <stdint.h>
#if __has_include("CO_error_custom.h")
#include "CO_error_custom.h"
#else
#include "CO_error_msgs.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup CO_socketCAN_ERROR socketCAN_ERROR
* @ingroup CO_socketCAN
* @{
*
* CANopen Errors and logging of messages
*/
/**
* Message logging function.
*
* Default usage is to print messages into system log with syslog() call. By
* default system stores messages in /var/log/syslog file.
* Log can optionally be configured before, for example to filter out less
* critical errors than LOG_NOTICE, specify program name, print also process PID
* and print also to standard error, use:
* @code
* setlogmask (LOG_UPTO (LOG_NOTICE));
* openlog ("exampleprog", LOG_PID | LOG_PERROR);
* @endcode
*
* @param priority one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
* LOG_NOTICE, LOG_INFO, LOG_DEBUG
* @param format format string as in printf
*/
#ifdef CO_DOXYGEN
void log_printf(int priority, const char *format, ...);
#endif
/**
* driver interface state
*
@ -75,10 +111,11 @@ typedef struct {
uint32_t noackCounter;
volatile bool_t listenOnly; /**< set to listen only mode */
volatile unsigned char listenOnly; /**< set to listen only mode */
struct timespec timestamp; /**< listen only mode started at this time */
} CO_CANinterfaceErrorhandler_t;
/**
* Initialize CAN error handler
*
@ -93,6 +130,7 @@ void CO_CANerror_init(
int fd,
const char *ifname);
/**
* Reset CAN error handler
*
@ -101,6 +139,7 @@ void CO_CANerror_init(
void CO_CANerror_disable(
CO_CANinterfaceErrorhandler_t *CANerrorhandler);
/**
* Message received event
*
@ -123,6 +162,7 @@ void CO_CANerror_rxMsg(
CO_CANinterfaceState_t CO_CANerror_txMsg(
CO_CANinterfaceErrorhandler_t *CANerrorhandler);
/**
* Error message received event
*
@ -137,9 +177,10 @@ CO_CANinterfaceState_t CO_CANerror_rxMsgError(
const struct can_frame *msg);
/** @} */
#ifdef __cplusplus
}
#endif /*__cplusplus*/
/** @} */
#endif
#endif /* CO_ERROR_H */

View file

@ -1,10 +1,7 @@
/**
* CAN module object for Linux socketCAN.
/*
* Definitions for CANopenNode Linux socketCAN Error handling.
*
* This file is a template for other microcontrollers.
*
* @file CO_msgs.h
* @ingroup CO_driver
* @file CO_Error_msgs.h
* @author Martin Wagner
* @copyright 2020 Neuberger Gebaeudeautomation GmbH
*
@ -27,30 +24,23 @@
*/
#ifndef CO_MSGS_H
#define CO_MSGS_H
#include <stdio.h>
#include <syslog.h>
#include "CO_msgs.h"
#ifndef CO_ERROR_MSGS_H
#define CO_ERROR_MSGS_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif
/*
* message printing function
* Message logging function.
*/
#ifndef log_printf
#include <syslog.h>
#define log_printf(macropar_prio, macropar_message, ...) \
if (macropar_prio < LOG_DEBUG) { \
printf(macropar_message, ##__VA_ARGS__); \
}
/*
* message logging function. You need to open the log previous to this.
*/
//#define log_printf(macropar_prio, macropar_message, ...) syslog(macropar_prio, macropar_message, ##__VA_ARGS__);
syslog(macropar_prio, macropar_message, ##__VA_ARGS__)
#endif
/*
@ -74,8 +64,9 @@ extern "C" {
#define CAN_RX_LEVEL_WARNING "CAN Interface \"%s\" reached Rx Warning Level"
#define CAN_TX_LEVEL_WARNING "CAN Interface \"%s\" reached Tx Warning Level"
/*
* Debug
* Message definitions for debugging
*/
#define DBG_ERRNO "(%s) OS error \"%s\" in %s", __func__, strerror(errno)
#define DBG_CAN_TX_FAILED "(%s) Transmitting CAN msg OID 0x%08x failed(%s)", __func__
@ -91,5 +82,4 @@ extern "C" {
}
#endif /* __cplusplus */
/** @} */
#endif
#endif /* CO_ERROR_MSGS_H */

View file

@ -7,10 +7,6 @@
#include "CO_notify_pipe.h"
struct CO_NotifyPipe {
int m_receiveFd;
int m_sendFd;
};
CO_NotifyPipe_t *CO_NotifyPipeCreate(void)
{
@ -31,6 +27,7 @@ CO_NotifyPipe_t *CO_NotifyPipeCreate(void)
return p;
}
void CO_NotifyPipeFree(CO_NotifyPipe_t *p)
{
if (p == NULL) {

View file

@ -2,7 +2,7 @@
* Notify pipe for Linux threads.
*
* @file CO_notify_pipe.h
* @ingroup CO_driver
* @ingroup CO_socketCAN
* @author Martin Wagner
* @copyright 2017 - 2020 Neuberger Gebaeudeautomation GmbH
*
@ -33,21 +33,26 @@ extern "C" {
/**
* @defgroup CO_pipe Pipe
* @ingroup CO_driver
* @ingroup CO_socketCAN
* @{
*
* This is needed to wake up the can socket when blocking in select
*/
/**
* Object
* Notify pipe object
*/
typedef struct CO_NotifyPipe CO_NotifyPipe_t;
typedef struct {
int m_receiveFd; /**< File descriptor for receive */
int m_sendFd; /**< File descriptor for send */
} CO_NotifyPipe_t;
/**
* Create Pipe
*
* @return != null if successfully created
* @return pointer to CO_NotifyPipe_t object if successfully created or
* NULL on failure.
*/
CO_NotifyPipe_t *CO_NotifyPipeCreate(void);
@ -79,7 +84,3 @@ void CO_NotifyPipeSend(CO_NotifyPipe_t *p);
#endif /*__cplusplus*/
#endif /* CO_NOTIFY_PIPE_H_ */
/**
* @} @}
**/