MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_can_write

Function rt_can_write

components/drivers/can/dev_can.c:622–671  ·  view source on GitHub ↗

* @brief Write data to the CAN device. * * This function serves as the unified entry point for sending CAN messages. * It intelligently routes the request to either a blocking or non-blocking * transmission function based on: * 1. The calling context (thread or ISR). * 2. A user-specified flag (`nonblocking`) in the message structure. * * @param[in] dev A pointer to the device object.

Source from the content-addressed store, hash-verified

620 * the data was either sent directly or enqueued in the buffer.
621 */
622static rt_ssize_t rt_can_write(struct rt_device *dev,
623 rt_off_t pos,
624 const void *buffer,
625 rt_size_t size)
626{
627 struct rt_can_device *can;
628 const struct rt_can_msg *pmsg;
629
630 RT_ASSERT(dev != RT_NULL);
631 RT_ASSERT(buffer != RT_NULL);
632
633 if (size == 0) return -RT_EINVAL;
634
635 /* Ensure size is a multiple of the message size for buffer operations */
636 if (size % sizeof(struct rt_can_msg) != 0)
637 {
638 return -RT_EINVAL;
639 }
640
641 can = (struct rt_can_device *)dev;
642 pmsg = (const struct rt_can_msg *)buffer;
643
644 if(dev->ref_count == 0)
645 {
646 return -RT_ENOSYS;
647 }
648
649 /*
650 * Routing to the non-blocking send scenario:
651 * 1. Called from within an interrupt context.
652 * 2. Called from a thread, but the user explicitly set the nonblocking flag on the first message.
653 */
654 if (rt_interrupt_get_nest() > 0 || pmsg->nonblocking)
655 {
656 return _can_nonblocking_tx(can, pmsg, size);
657 }
658
659 if (dev->open_flag & RT_DEVICE_FLAG_INT_TX)
660 {
661 if (can->config.privmode)
662 {
663 return _can_int_tx_priv(can, buffer, size);
664 }
665 else
666 {
667 return _can_int_tx(can, buffer, size);
668 }
669 }
670 return -RT_ENOSYS;
671}
672
673static rt_err_t rt_can_control(struct rt_device *dev,
674 int cmd,

Callers

nothing calls this directly

Calls 4

rt_interrupt_get_nestFunction · 0.85
_can_nonblocking_txFunction · 0.85
_can_int_tx_privFunction · 0.85
_can_int_txFunction · 0.85

Tested by

no test coverage detected