1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

can_trx: add CAN transceiver interface

This commit is contained in:
Vincent Dupont 2017-05-19 15:41:53 +02:00
parent 0a052f6b97
commit 8905199135
3 changed files with 162 additions and 0 deletions

1
drivers/can_trx/Makefile Normal file
View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

53
drivers/can_trx/can_trx.c Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2016 OTA keys S.A.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup drivers_can transceiver
* @ingroup drivers
* @brief generic transceiver interface
*
* @{
*
* @file
* @brief generic transceiver interface
*
* @author Vincent Dupont <vincent@otakeys.com>
*/
#include <errno.h>
#include <stdlib.h>
#include "can/can_trx.h"
int can_trx_init(can_trx_t *dev)
{
if (dev == NULL) {
return -ENODEV;
}
if (dev->driver->init) {
return dev->driver->init(dev);
}
else {
return -ENOTSUP;
}
}
int can_trx_set_mode(can_trx_t *dev, can_trx_mode_t mode)
{
if (dev == NULL) {
return -ENODEV;
}
if (dev->driver->set_mode) {
return dev->driver->set_mode(dev, mode);
}
else {
return -ENOTSUP;
}
}

View File

@ -0,0 +1,108 @@
/*
* Copyright (C) 2016 OTA keys S.A.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup trx_can CAN transceiver
* @ingroup can
* @ingroup drivers
* @brief generic transceiver interface
*
* @{
*
* @file
* @brief generic transceiver interface
*
* @author Aurelien Gonce <aurelien.gonce@altran.com>
* @author Vincent Dupont <vincent@otakeys.com>
*/
#ifndef CAN_CAN_TRX_H
#define CAN_CAN_TRX_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* trx transceiver mode
*/
typedef enum {
TRX_NORMAL_MODE = 0,
TRX_SILENT_MODE,
TRX_SLEEP_MODE,
/* single wire can modes */
TRX_HIGH_SPEED_MODE,
TRX_HIGH_VOLTAGE_WAKE_UP_MODE
} can_trx_mode_t;
/**
* @brief forward declaration of trx_driver
*/
typedef struct trx_driver trx_driver_t;
/**
* @brief Generic transceiver descriptor
*/
typedef struct can_trx {
const trx_driver_t *driver; /**< driver */
can_trx_mode_t mode; /**< current mode */
} can_trx_t;
/**
* @brief Generic transceiver driver
*/
struct trx_driver {
/**
* @brief initialize the trx device
*
* @param[in] dev Transceiver to initialize
*
* @return 0 on success
* @return < 0 on error
*/
int (*init)(can_trx_t *dev);
/**
* @brief set mode interface
*
* @param[in] dev Transceiver to set
* @param[in] mode Mode to set
*
* @return 0 on success
* @return < 0 on error
*/
int (*set_mode)(can_trx_t *dev, can_trx_mode_t mode);
};
/**
* @brief initialize a transceiver
*
* @param[in] dev Transceiver to initialize
*
* @return 0 on success
* @return < 0 on error
*/
int can_trx_init(can_trx_t *dev);
/**
* @brief transceiver set mode
*
* @param[in] dev Transceiver to set
* @param[in] mode Mode to set
*
* @return 0 on success
* @return < 0 on error
*/
int can_trx_set_mode(can_trx_t *dev, can_trx_mode_t mode);
#ifdef __cplusplus
}
#endif
#endif /* CAN_CAN_TRX_H */
/** @} */