HelenOS sources
This source file includes following definitions.
- td_init
- td_status
- td_print_status
#include <assert.h>
#include <errno.h>
#include <usb/debug.h>
#include <usb/usb.h>
#include <usb/host/utils/malloc32.h>
#include "link_pointer.h"
#include "transfer_descriptor.h"
void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso,
bool low_speed, usb_target_t target, usb_packet_id pid, const void *buffer,
const td_t *next)
{
assert(instance);
assert(size < 1024);
assert((pid == USB_PID_SETUP) || (pid == USB_PID_IN) ||
(pid == USB_PID_OUT));
const uint32_t next_pa = addr_to_phys(next);
assert((next_pa & LINK_POINTER_ADDRESS_MASK) == next_pa);
instance->next = 0 |
LINK_POINTER_VERTICAL_FLAG |
(next_pa ? next_pa : LINK_POINTER_TERMINATE_FLAG);
instance->status = 0 |
((err_count & TD_STATUS_ERROR_COUNT_MASK) <<
TD_STATUS_ERROR_COUNT_POS) |
(low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0) |
(iso ? TD_STATUS_ISOCHRONOUS_FLAG : 0) |
TD_STATUS_ERROR_ACTIVE;
if (pid == USB_PID_IN && !iso) {
instance->status |= TD_STATUS_SPD_FLAG;
}
instance->device = 0 |
(((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS) |
(toggle ? TD_DEVICE_DATA_TOGGLE_ONE_FLAG : 0) |
((target.address & TD_DEVICE_ADDRESS_MASK) <<
TD_DEVICE_ADDRESS_POS) |
((target.endpoint & TD_DEVICE_ENDPOINT_MASK) <<
TD_DEVICE_ENDPOINT_POS) |
((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
instance->buffer_ptr = addr_to_phys(buffer);
usb_log_debug2("Created TD(%p): %X:%X:%X:%X(%p).",
instance, instance->next, instance->status, instance->device,
instance->buffer_ptr, buffer);
td_print_status(instance);
if (pid == USB_PID_SETUP) {
usb_log_debug2("SETUP BUFFER: %s",
usb_debug_str_buffer(buffer, 8, 8));
}
}
errno_t td_status(const td_t *instance)
{
assert(instance);
if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
return EIO;
if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
return EBADCHECKSUM;
if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
return EAGAIN;
if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
return ERANGE;
if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0)
return EIO;
if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
return ESTALL;
return EOK;
}
void td_print_status(const td_t *instance)
{
assert(instance);
const uint32_t s = instance->status;
usb_log_debug2("TD(%p) status(%#" PRIx32 "):%s %d,%s%s%s%s%s%s%s%s%s%s%s %zu.",
instance, instance->status,
(s & TD_STATUS_SPD_FLAG) ? " SPD," : "",
(s >> TD_STATUS_ERROR_COUNT_POS) & TD_STATUS_ERROR_COUNT_MASK,
(s & TD_STATUS_LOW_SPEED_FLAG) ? " LOW SPEED," : "",
(s & TD_STATUS_ISOCHRONOUS_FLAG) ? " ISOCHRONOUS," : "",
(s & TD_STATUS_IOC_FLAG) ? " IOC," : "",
(s & TD_STATUS_ERROR_ACTIVE) ? " ACTIVE," : "",
(s & TD_STATUS_ERROR_STALLED) ? " STALLED," : "",
(s & TD_STATUS_ERROR_BUFFER) ? " BUFFER," : "",
(s & TD_STATUS_ERROR_BABBLE) ? " BABBLE," : "",
(s & TD_STATUS_ERROR_NAK) ? " NAK," : "",
(s & TD_STATUS_ERROR_CRC) ? " CRC/TIMEOUT," : "",
(s & TD_STATUS_ERROR_BIT_STUFF) ? " BIT_STUFF," : "",
(s & TD_STATUS_ERROR_RESERVED) ? " RESERVED," : "",
td_act_size(instance));
}
HelenOS homepage, sources at GitHub