Skip to content

Commit

Permalink
squash can_stm32: adapt to new auto-init system
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Dupont committed Feb 6, 2017
1 parent 22a835c commit df1dce3
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 94 deletions.
4 changes: 4 additions & 0 deletions boards/nucleo-f091/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
ifneq (,$(filter can,$(USEMODULE)))
CFLAGS += -DCAN_DLL_NUMOF=1
endif

include $(RIOTBOARD)/nucleo-common/Makefile.dep
62 changes: 0 additions & 62 deletions boards/nucleo-f091/include/can_conf.h

This file was deleted.

4 changes: 4 additions & 0 deletions boards/nucleo-f207/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
ifneq (,$(filter can,$(USEMODULE)))
CFLAGS += -DCAN_DLL_NUMOF=2
endif

include $(RIOTBOARD)/nucleo-common/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
/*
* Copyright (C) 2016 OTA keys S.A.
* 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.
* 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 boards_nucleo-f207 Nucleo-F207
* @ingroup boards
* @brief Board specific files for the nucleo-f207 board
* @ingroup cpu_stm32_common
* @{
*
* @file
* @brief CAN specific definitions for the nucleo-f207 board
* @brief STM32 CAN controller driver (bxCAN) default parameters
*
* @author Vincent Dupont <vincent@otakeys.com>
* @}
*/

#ifndef CAN_CONF_H
#define CAN_CONF_H

#ifdef __cplusplus
extern "C" {
#endif

#include "can/config.h"
#ifndef CANDEV_STM32_PARAMS_H
#define CANDEV_STM32_PARAMS_H

#include "can/device.h"
#include "candev_stm32.h"

const static candev_stm32_conf_t can_config_candev_stm32[] = {
const static candev_stm32_conf_t candev_stm32_conf[] = {
{
.channel = CANDEV_STM32_CHANNEL_0,
#if defined(CPU_FAM_STM32F0)
.rx_pin = GPIO_PIN(PORT_A, 11),
.tx_pin = GPIO_PIN(PORT_A, 12),
.af = GPIO_AF4,
.irqn = CEC_CAN_IRQn,
#else
.rx_pin = GPIO_PIN(PORT_D, 0),
.tx_pin = GPIO_PIN(PORT_D, 1),
.af = GPIO_AF9,
.tx_irqn = CAN1_TX_IRQn,
.rx0_irqn = CAN1_RX0_IRQn,
.rx1_irqn = CAN1_RX1_IRQn,
.sce_irqn = CAN1_SCE_IRQn,
#endif
.ttcm = 0,
.abom = 1,
.awum = 1,
.nart = 0,
.rflm = 0,
.txfp = 0,
},
#if (defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)) \
&& (CAN_DLL_NUMOF >= 2)
{
.channel = CANDEV_STM32_CHANNEL_1,
.rx_pin = GPIO_PIN(PORT_B, 5),
Expand All @@ -61,22 +64,20 @@ const static candev_stm32_conf_t can_config_candev_stm32[] = {
.nart = 0,
.rflm = 0,
.txfp = 0,
}
};

#define CANDEV_STM32_NUMOF (sizeof(can_config_candev_stm32) / sizeof(candev_stm32_conf_t))
#define CAN_DLL_NUMOF CANDEV_STM32_NUMOF

const static can_iface_t candev_ifnum[] = {
{ CAN_DRIVER_STM32, 0 },
{ CAN_DRIVER_STM32, 1 },
},
#endif
};

#ifdef __cplusplus
}
const static candev_params_t candev_stm32_params[] = {
{
.name = "can_stm32_0",
},
#if (defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)) \
&& (CAN_DLL_NUMOF >= 2)
{
.name = "can_stm32_1",
}
#endif
};

#endif /* CAN_CONF_H */

/** @} */

#endif /* CANDEV_STM32_PARAMS_H */
5 changes: 5 additions & 0 deletions sys/auto_init/can/auto_init_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ void auto_init_candev(void)
extern void auto_init_can_native(void);
auto_init_can_native();
#endif

#ifdef MODULE_CAN_STM32
extern void auto_init_can_stm32(void);
auto_init_can_stm32();
#endif
}
57 changes: 57 additions & 0 deletions sys/auto_init/can/auto_init_can_stm32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/

/**
* @ingroup auto_init
* @{
* @file
* @brief initializes stm32 can device
*
* @author Vincent Dupont <vincent@otakeys.com>
* @}
*/

#ifdef MODULE_CAN_STM32
#include "can/device.h"
#include "candev_stm32_params.h"

#define CANDEV_STM32_NUMOF ((sizeof(candev_stm32_params) / sizeof(candev_params_t)))

#ifndef CANDEV_STM32_STACKSIZE
#define CANDEV_STM32_STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF)
#endif

#ifndef CANDEV_STM32_BASE_PRIORITY
#define CANDEV_STM32_BASE_PRIORITY (THREAD_PRIORITY_MAIN - CANDEV_STM32_NUMOF - 2)
#endif

static candev_dev_t candev_dev_stm32[CANDEV_STM32_NUMOF];
static char _can_stm32_stacks[CANDEV_STM32_NUMOF][CANDEV_STM32_STACKSIZE];
static candev_stm32_t candev_stm32[CANDEV_STM32_NUMOF];

void auto_init_can_stm32(void) {

for (size_t i = 0; i < CANDEV_STM32_NUMOF; i++) {
candev_stm32_init(&candev_stm32[i], &candev_stm32_conf[i]);
candev_dev_stm32[i].dev = (candev_t *)&candev_stm32[i];
candev_dev_stm32[i].name = candev_stm32_params[i].name;
#ifdef MODULE_CAN_TRX
candev_dev_stm32[i].trx = candev_stm32_params[i].trx;
#endif
#ifdef MODULE_CAN_PM
candev_dev_stm32[i].rx_inactivity_timeout = candev_stm32_params[i].rx_inactivity_timeout;
candev_dev_stm32[i].tx_wakeup_timeout = candev_stm32_params[i].tx_wakeup_timeout;
#endif

can_device_init(_can_stm32_stacks[i], CANDEV_STM32_STACKSIZE, CANDEV_STM32_BASE_PRIORITY + i,
candev_stm32_params[i].name, &candev_dev_stm32[i]);
}
}
#else
typedef int dont_be_pedantic;
#endif

0 comments on commit df1dce3

Please sign in to comment.