mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
can: add transceiver support in CAN stack
This commit is contained in:
parent
8905199135
commit
029a127eb3
@ -40,6 +40,9 @@ void auto_init_can_native(void) {
|
|||||||
candev_linux_init(&candev_linux[i], &candev_linux_conf[i]);
|
candev_linux_init(&candev_linux[i], &candev_linux_conf[i]);
|
||||||
candev_dev_linux[i].dev = (candev_t *)&candev_linux[i];
|
candev_dev_linux[i].dev = (candev_t *)&candev_linux[i];
|
||||||
candev_dev_linux[i].name = candev_linux_params[i].name;
|
candev_dev_linux[i].name = candev_linux_params[i].name;
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
candev_dev_linux[i].trx = candev_linux_params[i].trx;
|
||||||
|
#endif
|
||||||
#ifdef MODULE_CAN_PM
|
#ifdef MODULE_CAN_PM
|
||||||
candev_dev_linux[i].rx_inactivity_timeout = candev_linux_params[i].rx_inactivity_timeout;
|
candev_dev_linux[i].rx_inactivity_timeout = candev_linux_params[i].rx_inactivity_timeout;
|
||||||
candev_dev_linux[i].tx_wakeup_timeout = candev_linux_params[i].tx_wakeup_timeout;
|
candev_dev_linux[i].tx_wakeup_timeout = candev_linux_params[i].tx_wakeup_timeout;
|
||||||
|
@ -23,6 +23,10 @@
|
|||||||
#include "can/pkt.h"
|
#include "can/pkt.h"
|
||||||
#include "can/dll.h"
|
#include "can/dll.h"
|
||||||
|
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
#include "can/can_trx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@ -131,6 +135,9 @@ static int power_up(candev_dev_t *candev_dev)
|
|||||||
|
|
||||||
DEBUG("candev: power up\n");
|
DEBUG("candev: power up\n");
|
||||||
|
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
can_trx_set_mode(candev_dev->trx, TRX_NORMAL_MODE);
|
||||||
|
#endif
|
||||||
canopt_state_t state = CANOPT_STATE_ON;
|
canopt_state_t state = CANOPT_STATE_ON;
|
||||||
int res = dev->driver->set(dev, CANOPT_STATE, &state, sizeof(state));
|
int res = dev->driver->set(dev, CANOPT_STATE, &state, sizeof(state));
|
||||||
dev->state = CAN_STATE_ERROR_ACTIVE;
|
dev->state = CAN_STATE_ERROR_ACTIVE;
|
||||||
@ -144,6 +151,9 @@ static int power_down(candev_dev_t *candev_dev)
|
|||||||
|
|
||||||
DEBUG("candev: power down\n");
|
DEBUG("candev: power down\n");
|
||||||
|
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
can_trx_set_mode(candev_dev->trx, TRX_SLEEP_MODE);
|
||||||
|
#endif
|
||||||
canopt_state_t state = CANOPT_STATE_SLEEP;
|
canopt_state_t state = CANOPT_STATE_SLEEP;
|
||||||
int res = dev->driver->set(dev, CANOPT_STATE, &state, sizeof(state));
|
int res = dev->driver->set(dev, CANOPT_STATE, &state, sizeof(state));
|
||||||
dev->state = CAN_STATE_SLEEPING;
|
dev->state = CAN_STATE_SLEEPING;
|
||||||
@ -209,6 +219,9 @@ static void *_can_device_thread(void *args)
|
|||||||
candev_dev->pm_timer.arg = candev_dev;
|
candev_dev->pm_timer.arg = candev_dev;
|
||||||
pm_reset(candev_dev, candev_dev->rx_inactivity_timeout);
|
pm_reset(candev_dev, candev_dev->rx_inactivity_timeout);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
can_trx_init(candev_dev->trx);
|
||||||
|
#endif
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
can_pkt_t *pkt;
|
can_pkt_t *pkt;
|
||||||
@ -312,6 +325,20 @@ static void *_can_device_thread(void *args)
|
|||||||
reply.content.value = (uint32_t)res;
|
reply.content.value = (uint32_t)res;
|
||||||
msg_reply(&msg, &reply);
|
msg_reply(&msg, &reply);
|
||||||
break;
|
break;
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
case CAN_MSG_SET_TRX:
|
||||||
|
DEBUG("can device: CAN_MSG_SET_TRX received\n");
|
||||||
|
reply.type = CAN_MSG_ACK;
|
||||||
|
if (dev->state != CAN_STATE_SLEEPING) {
|
||||||
|
reply.content.value = -EBUSY;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
candev_dev->trx = msg.content.ptr;
|
||||||
|
reply.content.value = 0;
|
||||||
|
}
|
||||||
|
msg_reply(&msg, &reply);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#ifdef MODULE_CAN_PM
|
#ifdef MODULE_CAN_PM
|
||||||
case CAN_MSG_PM:
|
case CAN_MSG_PM:
|
||||||
DEBUG("can device: pm power down\n");
|
DEBUG("can device: pm power down\n");
|
||||||
|
@ -469,6 +469,23 @@ int raw_can_set_bitrate(int ifnum, uint32_t bitrate, uint32_t sample_point)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
int raw_can_set_trx(int ifnum, can_trx_t *trx)
|
||||||
|
{
|
||||||
|
msg_t msg, reply;
|
||||||
|
|
||||||
|
assert(ifnum < candev_nb);
|
||||||
|
|
||||||
|
msg.type = CAN_MSG_SET_TRX;
|
||||||
|
msg.content.ptr = trx;
|
||||||
|
if (msg_send_receive(&msg, &reply, candev_list[ifnum]->pid) != 1) {
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) reply.content.value;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int raw_can_get_ifnum_by_name(const char *name)
|
int raw_can_get_ifnum_by_name(const char *name)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < candev_nb; i++) {
|
for (int i = 0; i < candev_nb; i++) {
|
||||||
|
@ -91,6 +91,9 @@ enum can_msg {
|
|||||||
CAN_MSG_REMOVE_FILTER, /**< remove a filter */
|
CAN_MSG_REMOVE_FILTER, /**< remove a filter */
|
||||||
CAN_MSG_POWER_UP, /**< power up */
|
CAN_MSG_POWER_UP, /**< power up */
|
||||||
CAN_MSG_POWER_DOWN, /**< power down */
|
CAN_MSG_POWER_DOWN, /**< power down */
|
||||||
|
#if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
|
||||||
|
CAN_MSG_SET_TRX, /**< set a transceiver */
|
||||||
|
#endif
|
||||||
/* candev internal messages */
|
/* candev internal messages */
|
||||||
CAN_MSG_EVENT = 0x200, /**< driver event */
|
CAN_MSG_EVENT = 0x200, /**< driver event */
|
||||||
CAN_MSG_WAKE_UP, /**< driver has been woken up by bus */
|
CAN_MSG_WAKE_UP, /**< driver has been woken up by bus */
|
||||||
|
@ -31,6 +31,9 @@ extern "C" {
|
|||||||
#ifdef MODULE_CAN_PM
|
#ifdef MODULE_CAN_PM
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MODULE_CAN_TRX
|
||||||
|
#include "can/can_trx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CAN_MAX_RATE_ERROR
|
#ifndef CAN_MAX_RATE_ERROR
|
||||||
/**
|
/**
|
||||||
@ -52,6 +55,9 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef struct candev_params {
|
typedef struct candev_params {
|
||||||
const char *name; /**< candev name to set */
|
const char *name; /**< candev name to set */
|
||||||
|
#if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
|
||||||
|
can_trx_t *trx; /**< transceiver to set */
|
||||||
|
#endif
|
||||||
#if defined(MODULE_CAN_PM) || defined(DOXYGEN)
|
#if defined(MODULE_CAN_PM) || defined(DOXYGEN)
|
||||||
uint32_t rx_inactivity_timeout; /**< power management rx timeout value */
|
uint32_t rx_inactivity_timeout; /**< power management rx timeout value */
|
||||||
uint32_t tx_wakeup_timeout; /**< power management tx wake up value */
|
uint32_t tx_wakeup_timeout; /**< power management tx wake up value */
|
||||||
@ -66,6 +72,9 @@ typedef struct candev_dev {
|
|||||||
int ifnum; /**< interface number */
|
int ifnum; /**< interface number */
|
||||||
kernel_pid_t pid; /**< pid */
|
kernel_pid_t pid; /**< pid */
|
||||||
const char *name; /**< device name */
|
const char *name; /**< device name */
|
||||||
|
#if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
|
||||||
|
can_trx_t *trx; /**< transceiver attached to the device */
|
||||||
|
#endif
|
||||||
#if defined(MODULE_CAN_PM) || defined(DOXYGEN)
|
#if defined(MODULE_CAN_PM) || defined(DOXYGEN)
|
||||||
uint32_t rx_inactivity_timeout; /**< Min timeout loaded when a frame is received */
|
uint32_t rx_inactivity_timeout; /**< Min timeout loaded when a frame is received */
|
||||||
uint32_t tx_wakeup_timeout; /**< Min timeout loaded when a frame is sent */
|
uint32_t tx_wakeup_timeout; /**< Min timeout loaded when a frame is sent */
|
||||||
|
@ -37,6 +37,9 @@ extern "C" {
|
|||||||
#include "mbox.h"
|
#include "mbox.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULE_TRX
|
||||||
|
#include "can/can_trx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default value for undefined interface number
|
* @brief Default value for undefined interface number
|
||||||
@ -253,6 +256,21 @@ candev_dev_t *raw_can_get_dev_by_ifnum(int ifnum);
|
|||||||
*/
|
*/
|
||||||
int raw_can_set_bitrate(int ifnum, uint32_t bitrate, uint32_t sample_point);
|
int raw_can_set_bitrate(int ifnum, uint32_t bitrate, uint32_t sample_point);
|
||||||
|
|
||||||
|
#if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
|
||||||
|
/**
|
||||||
|
* @brief Set a transceiver for a given interface
|
||||||
|
*
|
||||||
|
* The interface must be powered down before changing the transceiver.
|
||||||
|
*
|
||||||
|
* @param[in] ifnum the interface number
|
||||||
|
* @param[in] trx the transceiver to set
|
||||||
|
*
|
||||||
|
* @return 0 on success
|
||||||
|
* @return < 0 on error (-EBUSY if device is not powered down)
|
||||||
|
*/
|
||||||
|
int raw_can_set_trx(int ifnum, can_trx_t *trx);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,5 +19,6 @@ USEMODULE += conn_can
|
|||||||
USEMODULE += can_isotp
|
USEMODULE += can_isotp
|
||||||
USEMODULE += conn_can_isotp_multi
|
USEMODULE += conn_can_isotp_multi
|
||||||
USEMODULE += can_pm
|
USEMODULE += can_pm
|
||||||
|
USEMODULE += can_trx
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
Loading…
Reference in New Issue
Block a user