Changeset 4e17d54 in mainline


Ignore:
Timestamp:
2018-01-31T17:12:13Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
da9d6ca
Parents:
50206e9
Message:

usbdev: pipe operations with dma buffers

Location:
uspace/lib/usbdev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r50206e9 r4e17d54  
    110110errno_t usb_pipe_write(usb_pipe_t *, const void *, size_t);
    111111
     112errno_t usb_pipe_read_dma(usb_pipe_t *, void *, size_t, size_t *);
     113errno_t usb_pipe_write_dma(usb_pipe_t *, void *, size_t);
     114
    112115errno_t usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
    113116    void *, size_t, size_t *);
  • uspace/lib/usbdev/src/pipes.c

    r50206e9 r4e17d54  
    258258}
    259259
     260/**
     261 * Request a read (in) transfer on an endpoint pipe, declaring that buffer
     262 * is pointing to a memory area previously allocated by usb_pipe_alloc_buffer.
     263 *
     264 * @param[in] pipe Pipe used for the transfer.
     265 * @param[in] buffer Buffer, previously allocated with usb_pipe_alloc_buffer.
     266 * @param[in] size Size of the buffer (in bytes).
     267 * @param[out] size_transferred Number of bytes that were actually transferred.
     268 * @return Error code.
     269 */
     270errno_t usb_pipe_read_dma(usb_pipe_t *pipe, void *buffer, size_t size,
     271    size_t *size_transferred)
     272{
     273        assert(pipe);
     274
     275        if (buffer == NULL || size == 0)
     276                return EINVAL;
     277
     278        if (pipe->desc.direction != USB_DIRECTION_IN
     279            || pipe->desc.transfer_type == USB_TRANSFER_CONTROL)
     280                return EBADF;
     281
     282        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     283        if (!exch)
     284                return ENOMEM;
     285
     286        const errno_t rc = usbhc_transfer(exch, pipe->desc.endpoint_no,
     287            USB_DIRECTION_IN, 0, buffer, size, size_transferred);
     288        async_exchange_end(exch);
     289        return rc;
     290}
     291
     292/**
     293 * Request a write (out) transfer on an endpoint pipe, declaring that buffer
     294 * is pointing to a memory area previously allocated by usb_pipe_alloc_buffer.
     295 *
     296 * @param[in] pipe Pipe used for the transfer.
     297 * @param[in] buffer Buffer, previously allocated with usb_pipe_alloc_buffer.
     298 * @param[in] size Size of the buffer (in bytes).
     299 * @return Error code.
     300 */
     301errno_t usb_pipe_write_dma(usb_pipe_t *pipe, void *buffer, size_t size)
     302{
     303        assert(pipe);
     304
     305        if (buffer == NULL || size == 0) {
     306                return EINVAL;
     307        }
     308
     309        if (pipe->desc.direction != USB_DIRECTION_OUT
     310            || pipe->desc.transfer_type == USB_TRANSFER_CONTROL)
     311                return EBADF;
     312
     313        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     314        if (!exch)
     315                return ENOMEM;
     316
     317        const errno_t rc = usbhc_transfer(exch, pipe->desc.endpoint_no, USB_DIRECTION_OUT, 0, buffer, size, NULL);
     318        async_exchange_end(exch);
     319        return rc;
     320}
     321
    260322/** Initialize USB endpoint pipe.
    261323 *
Note: See TracChangeset for help on using the changeset viewer.