drivers: can: remove deprecated APIs
Remove the CAN APIs deprecated in Zephyr v3.0.0. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
da2a0befbb
commit
cf1879bfac
3 changed files with 1 additions and 345 deletions
|
@ -75,13 +75,6 @@ config CAN_INIT_PRIORITY
|
||||||
Note that the priority needs to be lower than the net stack
|
Note that the priority needs to be lower than the net stack
|
||||||
so that it can start before the networking sub-system.
|
so that it can start before the networking sub-system.
|
||||||
|
|
||||||
config CAN_WORKQ_FRAMES_BUF_CNT
|
|
||||||
int "Work queue buffer frame count (DEPRECATED)"
|
|
||||||
default 4
|
|
||||||
range 1 65534
|
|
||||||
help
|
|
||||||
Number of frames in the buffer of a zcan_work.
|
|
||||||
|
|
||||||
config CAN_RX_TIMESTAMP
|
config CAN_RX_TIMESTAMP
|
||||||
bool "Enable receiving timestamps"
|
bool "Enable receiving timestamps"
|
||||||
depends on CAN_HAS_RX_TIMESTAMP
|
depends on CAN_HAS_RX_TIMESTAMP
|
||||||
|
|
|
@ -11,21 +11,9 @@
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(can_common, CONFIG_CAN_LOG_LEVEL);
|
LOG_MODULE_REGISTER(can_common, CONFIG_CAN_LOG_LEVEL);
|
||||||
|
|
||||||
|
/* CAN sync segment is always one time quantum */
|
||||||
#define CAN_SYNC_SEG 1
|
#define CAN_SYNC_SEG 1
|
||||||
|
|
||||||
#define WORK_BUF_COUNT_IS_POWER_OF_2 !(CONFIG_CAN_WORKQ_FRAMES_BUF_CNT & \
|
|
||||||
(CONFIG_CAN_WORKQ_FRAMES_BUF_CNT - 1))
|
|
||||||
|
|
||||||
#define WORK_BUF_MOD_MASK (CONFIG_CAN_WORKQ_FRAMES_BUF_CNT - 1)
|
|
||||||
|
|
||||||
#if WORK_BUF_COUNT_IS_POWER_OF_2
|
|
||||||
#define WORK_BUF_MOD_SIZE(x) ((x) & WORK_BUF_MOD_MASK)
|
|
||||||
#else
|
|
||||||
#define WORK_BUF_MOD_SIZE(x) ((x) % CONFIG_CAN_WORKQ_FRAMES_BUF_CNT)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WORK_BUF_FULL 0xFFFF
|
|
||||||
|
|
||||||
static void can_msgq_put(struct zcan_frame *frame, void *arg)
|
static void can_msgq_put(struct zcan_frame *frame, void *arg)
|
||||||
{
|
{
|
||||||
struct k_msgq *msgq = (struct k_msgq *)arg;
|
struct k_msgq *msgq = (struct k_msgq *)arg;
|
||||||
|
@ -47,102 +35,6 @@ int z_impl_can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq,
|
||||||
return api->add_rx_filter(dev, can_msgq_put, msgq, filter);
|
return api->add_rx_filter(dev, can_msgq_put, msgq, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void can_work_buffer_init(struct can_frame_buffer *buffer)
|
|
||||||
{
|
|
||||||
buffer->head = 0;
|
|
||||||
buffer->tail = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int can_work_buffer_put(struct zcan_frame *frame,
|
|
||||||
struct can_frame_buffer *buffer)
|
|
||||||
{
|
|
||||||
uint16_t next_head = WORK_BUF_MOD_SIZE(buffer->head + 1);
|
|
||||||
|
|
||||||
if (buffer->head == WORK_BUF_FULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer->buf[buffer->head] = *frame;
|
|
||||||
|
|
||||||
/* Buffer is almost full */
|
|
||||||
if (next_head == buffer->tail) {
|
|
||||||
buffer->head = WORK_BUF_FULL;
|
|
||||||
} else {
|
|
||||||
buffer->head = next_head;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
struct zcan_frame *can_work_buffer_get_next(struct can_frame_buffer *buffer)
|
|
||||||
{
|
|
||||||
/* Buffer empty */
|
|
||||||
if (buffer->head == buffer->tail) {
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
return &buffer->buf[buffer->tail];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void can_work_buffer_free_next(struct can_frame_buffer *buffer)
|
|
||||||
{
|
|
||||||
uint16_t next_tail = WORK_BUF_MOD_SIZE(buffer->tail + 1);
|
|
||||||
|
|
||||||
if (buffer->head == buffer->tail) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer->head == WORK_BUF_FULL) {
|
|
||||||
buffer->head = buffer->tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer->tail = next_tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void can_work_handler(struct k_work *work)
|
|
||||||
{
|
|
||||||
struct zcan_work *can_work = CONTAINER_OF(work, struct zcan_work,
|
|
||||||
work_item);
|
|
||||||
struct zcan_frame *frame;
|
|
||||||
|
|
||||||
while ((frame = can_work_buffer_get_next(&can_work->buf))) {
|
|
||||||
can_work->cb(frame, can_work->cb_arg);
|
|
||||||
can_work_buffer_free_next(&can_work->buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void can_work_isr_put(struct zcan_frame *frame, void *arg)
|
|
||||||
{
|
|
||||||
struct zcan_work *work = (struct zcan_work *)arg;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = can_work_buffer_put(frame, &work->buf);
|
|
||||||
if (ret) {
|
|
||||||
LOG_ERR("Workq buffer overflow. Frame ID: 0x%x", frame->id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_work_submit_to_queue(work->work_queue, &work->work_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
|
||||||
struct zcan_work *work,
|
|
||||||
can_rx_callback_t callback, void *user_data,
|
|
||||||
const struct zcan_filter *filter)
|
|
||||||
{
|
|
||||||
const struct can_driver_api *api = dev->api;
|
|
||||||
|
|
||||||
k_work_init(&work->work_item, can_work_handler);
|
|
||||||
work->work_queue = work_q;
|
|
||||||
work->cb = callback;
|
|
||||||
work->cb_arg = user_data;
|
|
||||||
can_work_buffer_init(&work->buf);
|
|
||||||
|
|
||||||
return api->add_rx_filter(dev, can_work_isr_put, work, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res,
|
static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res,
|
||||||
const struct can_timing *max,
|
const struct can_timing *max,
|
||||||
const struct can_timing *min)
|
const struct can_timing *min)
|
||||||
|
|
|
@ -1226,235 +1226,6 @@ static inline void can_copy_zfilter_to_filter(const struct zcan_filter *zfilter,
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
|
||||||
* @cond INTERNAL_HIDDEN
|
|
||||||
* Deprecated APIs
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @name CAN specific error codes
|
|
||||||
*
|
|
||||||
* The `CAN_TX_*` error codes are used for CAN specific error return codes from
|
|
||||||
* @a can_send() and for `error_flags` values in @a can_tx_callback_t().
|
|
||||||
*
|
|
||||||
* `CAN_NO_FREE_FILTER` is returned by `can_add_rx_*()` if no free filters are
|
|
||||||
* available. `CAN_TIMEOUT` indicates that @a can_recover() timed out.
|
|
||||||
*
|
|
||||||
* @deprecated Use the corresponding errno definitions instead.
|
|
||||||
*
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Transmitted successfully. */
|
|
||||||
#define CAN_TX_OK (0) __DEPRECATED_MACRO
|
|
||||||
/** General transmit error. */
|
|
||||||
#define CAN_TX_ERR (-EIO) __DEPRECATED_MACRO
|
|
||||||
/** Bus arbitration lost during transmission. */
|
|
||||||
#define CAN_TX_ARB_LOST (-EBUSY) __DEPRECATED_MACRO
|
|
||||||
/** CAN controller is in bus off state. */
|
|
||||||
#define CAN_TX_BUS_OFF (-ENETDOWN) __DEPRECATED_MACRO
|
|
||||||
/** Unknown error. */
|
|
||||||
#define CAN_TX_UNKNOWN (CAN_TX_ERR) __DEPRECATED_MACRO
|
|
||||||
/** Invalid parameter. */
|
|
||||||
#define CAN_TX_EINVAL (-EINVAL) __DEPRECATED_MACRO
|
|
||||||
/** No free filters available. */
|
|
||||||
#define CAN_NO_FREE_FILTER (-ENOSPC) __DEPRECATED_MACRO
|
|
||||||
/** Operation timed out. */
|
|
||||||
#define CAN_TIMEOUT (-EAGAIN) __DEPRECATED_MACRO
|
|
||||||
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configure operation of a host controller.
|
|
||||||
*
|
|
||||||
* @deprecated Use @a can_set_bitrate() and @a can_set_mode() instead.
|
|
||||||
*
|
|
||||||
* @param dev Pointer to the device structure for the driver instance.
|
|
||||||
* @param mode Operation mode.
|
|
||||||
* @param bitrate bus-speed in Baud/s.
|
|
||||||
*
|
|
||||||
* @retval 0 If successful.
|
|
||||||
* @retval -EIO General input/output error, failed to configure device.
|
|
||||||
*/
|
|
||||||
__deprecated static inline int can_configure(const struct device *dev, enum can_mode mode,
|
|
||||||
uint32_t bitrate)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
if (bitrate > 0) {
|
|
||||||
err = can_set_bitrate(dev, bitrate, bitrate);
|
|
||||||
if (err != 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return can_set_mode(dev, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow including drivers/can.h even if CONFIG_CAN is not selected.
|
|
||||||
*/
|
|
||||||
#ifndef CONFIG_CAN_WORKQ_FRAMES_BUF_CNT
|
|
||||||
#define CONFIG_CAN_WORKQ_FRAMES_BUF_CNT 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CAN frame buffer structure
|
|
||||||
*
|
|
||||||
* Used internally by @a zcan_work struct
|
|
||||||
*/
|
|
||||||
struct can_frame_buffer {
|
|
||||||
struct zcan_frame buf[CONFIG_CAN_WORKQ_FRAMES_BUF_CNT];
|
|
||||||
uint16_t head;
|
|
||||||
uint16_t tail;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CAN work structure
|
|
||||||
*
|
|
||||||
* Used to attach a work queue to a filter.
|
|
||||||
*/
|
|
||||||
struct zcan_work {
|
|
||||||
struct k_work work_item;
|
|
||||||
struct k_work_q *work_queue;
|
|
||||||
struct can_frame_buffer buf;
|
|
||||||
can_rx_callback_t cb;
|
|
||||||
void *cb_arg;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Attach a CAN work queue with a given CAN filter
|
|
||||||
*
|
|
||||||
* Attach a work queue to CAN identifiers specified by a filter. Whenever a
|
|
||||||
* frame matching the filter is received by the CAN controller, the frame is
|
|
||||||
* pushed to the buffer of the @a zcan_work structure and the work element is
|
|
||||||
* put in the workqueue.
|
|
||||||
*
|
|
||||||
* If a frame matches more than one attached filter, the priority of the match
|
|
||||||
* is hardware dependent.
|
|
||||||
*
|
|
||||||
* The same CAN work queue can be attached to more than one filter.
|
|
||||||
*
|
|
||||||
* @see @a can_remove_rx_filter()
|
|
||||||
*
|
|
||||||
* @note The work queue must be initialized before and the caller must have
|
|
||||||
* appropriate permissions on it.
|
|
||||||
*
|
|
||||||
* @deprecated Use @a can_add_rx_filter_msgq() along with @a
|
|
||||||
* k_work_poll_submit() instead.
|
|
||||||
*
|
|
||||||
* @param dev Pointer to the device structure for the driver instance.
|
|
||||||
* @param work_q Pointer to the already initialized @a zcan_work queue.
|
|
||||||
* @param work Pointer to a @a zcan_work structure, which will be initialized.
|
|
||||||
* @param callback This function is called by the work queue whenever a frame
|
|
||||||
* matching the filter is received.
|
|
||||||
* @param user_data User data to pass to callback function.
|
|
||||||
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
|
||||||
*
|
|
||||||
* @retval filter_id on success.
|
|
||||||
* @retval -ENOSPC if there are no free filters.
|
|
||||||
*/
|
|
||||||
__deprecated int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
|
||||||
struct zcan_work *work, can_rx_callback_t callback,
|
|
||||||
void *user_data, const struct zcan_filter *filter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use can_add_rx_filter() instead.
|
|
||||||
*/
|
|
||||||
__deprecated static inline int can_attach_isr(const struct device *dev, can_rx_callback_t isr,
|
|
||||||
void *user_data, const struct zcan_filter *filter)
|
|
||||||
{
|
|
||||||
return can_add_rx_filter(dev, isr, user_data, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use CAN_MSGQ_DEFINE() instead.
|
|
||||||
*/
|
|
||||||
#define CAN_DEFINE_MSGQ(name, size) CAN_MSGQ_DEFINE(name, size) __DEPRECATED_MACRO
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use can_add_rx_filter_msgq() instead.
|
|
||||||
*/
|
|
||||||
__deprecated static inline int can_attach_msgq(const struct device *dev, struct k_msgq *msg_q,
|
|
||||||
const struct zcan_filter *filter)
|
|
||||||
{
|
|
||||||
return can_add_rx_filter_msgq(dev, msg_q, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use can_remove_rx_filter() instead.
|
|
||||||
*/
|
|
||||||
__deprecated static inline void can_detach(const struct device *dev, int filter_id)
|
|
||||||
{
|
|
||||||
can_remove_rx_filter(dev, filter_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use can_set_state_change_callback() instead.
|
|
||||||
*/
|
|
||||||
__deprecated static inline void can_register_state_change_isr(const struct device *dev,
|
|
||||||
can_state_change_callback_t isr)
|
|
||||||
{
|
|
||||||
can_set_state_change_callback(dev, isr, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Wrapper function for writing data to the CAN bus.
|
|
||||||
*
|
|
||||||
* Simple wrapper function for @a can_send() without the need for filling in a
|
|
||||||
* @a zcan_frame struct. This function blocks until the data is sent or a
|
|
||||||
* timeout occurs.
|
|
||||||
*
|
|
||||||
* By default, the CAN controller will automatically retry transmission in case
|
|
||||||
* of lost bus arbitration or missing acknowledge. Some CAN controllers support
|
|
||||||
* disabling automatic retransmissions ("one-shot" mode) via a devicetree
|
|
||||||
* property.
|
|
||||||
*
|
|
||||||
* @deprecated Use @a can_send() instead.
|
|
||||||
*
|
|
||||||
* @param dev Pointer to the device structure for the driver instance.
|
|
||||||
* @param data Pointer to the data to write.
|
|
||||||
* @param length Number of bytes to write (max. 8).
|
|
||||||
* @param id CAN identifier used for writing.
|
|
||||||
* @param rtr Write as data frame or Remote Transmission Request (RTR) frame.
|
|
||||||
* @param timeout Timeout waiting for an empty TX mailbox or ``K_FOREVER``.
|
|
||||||
*
|
|
||||||
* @retval 0 if successful.
|
|
||||||
* @retval -EINVAL if an invalid parameter was passed to the function.
|
|
||||||
* @retval -ENETDOWN if the CAN controller is in bus-off state.
|
|
||||||
* @retval -EBUSY if CAN bus arbitration was lost (only applicable if automatic
|
|
||||||
* retransmissions are disabled).
|
|
||||||
* @retval -EIO if a general transmit error occurred (e.g. missing ACK if
|
|
||||||
* automatic retransmissions are disabled).
|
|
||||||
* @retval -EAGAIN on timeout.
|
|
||||||
*/
|
|
||||||
__deprecated static inline int can_write(const struct device *dev, const uint8_t *data,
|
|
||||||
uint8_t length, uint32_t id, enum can_rtr rtr,
|
|
||||||
k_timeout_t timeout)
|
|
||||||
{
|
|
||||||
struct zcan_frame frame;
|
|
||||||
|
|
||||||
if (length > 8) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
frame.id = id;
|
|
||||||
|
|
||||||
if (id > CAN_MAX_STD_ID) {
|
|
||||||
frame.id_type = CAN_EXTENDED_IDENTIFIER;
|
|
||||||
} else {
|
|
||||||
frame.id_type = CAN_STANDARD_IDENTIFIER;
|
|
||||||
}
|
|
||||||
|
|
||||||
frame.dlc = length;
|
|
||||||
frame.rtr = rtr;
|
|
||||||
memcpy(frame.data, data, length);
|
|
||||||
|
|
||||||
return can_send(dev, &frame, timeout, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @endcond */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue