subsys: canopen: Add a wrapper to avoid passing device to CO_init
Add a dedicated structure instead. Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
38809a44a8
commit
8d0a3f3b5c
3 changed files with 11 additions and 8 deletions
|
@ -38,6 +38,10 @@ enum canopen_storage {
|
|||
CANOPEN_STORAGE_EEPROM,
|
||||
};
|
||||
|
||||
struct canopen_context {
|
||||
const struct device *dev;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Attach CANopen object dictionary storage handlers.
|
||||
*
|
||||
|
|
|
@ -202,14 +202,14 @@ void main(void)
|
|||
{
|
||||
CO_NMT_reset_cmd_t reset = CO_RESET_NOT;
|
||||
CO_ReturnError_t err;
|
||||
const struct device *can;
|
||||
struct canopen_context can;
|
||||
uint16_t timeout;
|
||||
uint32_t elapsed;
|
||||
int64_t timestamp;
|
||||
int ret;
|
||||
|
||||
can = device_get_binding(CAN_INTERFACE);
|
||||
if (!can) {
|
||||
can.dev = device_get_binding(CAN_INTERFACE);
|
||||
if (!can.dev) {
|
||||
LOG_ERR("CAN interface not found");
|
||||
return;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ void main(void)
|
|||
while (reset != CO_RESET_APP) {
|
||||
elapsed = 0U; /* milliseconds */
|
||||
|
||||
err = CO_init(can, CONFIG_CANOPEN_NODE_ID, CAN_BITRATE);
|
||||
err = CO_init(&can, CONFIG_CANOPEN_NODE_ID, CAN_BITRATE);
|
||||
if (err != CO_ERROR_NO) {
|
||||
LOG_ERR("CO_init failed (err = %d)", err);
|
||||
return;
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
#include <init.h>
|
||||
#include <sys/util.h>
|
||||
|
||||
#include <CO_driver.h>
|
||||
#include <CO_Emergency.h>
|
||||
#include <CO_SDO.h>
|
||||
#include <canbus/canopen.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_CANOPEN_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
|
@ -169,6 +167,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
|
|||
CO_CANtx_t txArray[], uint16_t txSize,
|
||||
uint16_t CANbitRate)
|
||||
{
|
||||
struct canopen_context *ctx = (struct canopen_context *)CANdriverState;
|
||||
uint16_t i;
|
||||
int err;
|
||||
|
||||
|
@ -193,7 +192,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
|
|||
canopen_detach_all_rx_filters(CANmodule);
|
||||
canopen_tx_queue.CANmodule = CANmodule;
|
||||
|
||||
CANmodule->dev = CANdriverState;
|
||||
CANmodule->dev = ctx->dev;
|
||||
CANmodule->rx_array = rxArray;
|
||||
CANmodule->rx_size = rxSize;
|
||||
CANmodule->tx_array = txArray;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue