source: mainline/uspace/drv/bus/usb/ohci/ohci_endpoint.c@ fb2ef35

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fb2ef35 was 57e06ef, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

ohci: Minor improvements.

Remove unused member.
Fix comments.
Add const qualifiers and asserts.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[2759c52]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvusbohci
29 * @{
30 */
31/** @file
32 * @brief OHCI driver
33 */
34#include "utils/malloc32.h"
[e20eaed]35#include "ohci_endpoint.h"
[620c710]36#include "hc.h"
[2759c52]37
[02cacce]38/** Callback to set toggle on ED.
39 *
40 * @param[in] hcd_ep hcd endpoint structure
41 * @param[in] toggle new value of toggle bit
42 */
[e20eaed]43static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
[545764b]44{
[e20eaed]45 ohci_endpoint_t *instance = ohci_ep;
[545764b]46 assert(instance);
47 assert(instance->ed);
48 ed_toggle_set(instance->ed, toggle);
49}
[02cacce]50/*----------------------------------------------------------------------------*/
51/** Callback to get value of toggle bit.
52 *
53 * @param[in] hcd_ep hcd endpoint structure
54 * @return Current value of toggle bit.
55 */
[e20eaed]56static int ohci_ep_toggle_get(void *ohci_ep)
[545764b]57{
[e20eaed]58 ohci_endpoint_t *instance = ohci_ep;
[545764b]59 assert(instance);
60 assert(instance->ed);
61 return ed_toggle_get(instance->ed);
62}
[02cacce]63/*----------------------------------------------------------------------------*/
64/** Creates new hcd endpoint representation.
65 *
66 * @param[in] ep USBD endpoint structure
[57e06ef]67 * @return Error code.
[02cacce]68 */
[620c710]69int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
[2759c52]70{
71 assert(ep);
[e20eaed]72 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
73 if (ohci_ep == NULL)
[b02308e]74 return ENOMEM;
[2759c52]75
[e20eaed]76 ohci_ep->ed = malloc32(sizeof(ed_t));
77 if (ohci_ep->ed == NULL) {
78 free(ohci_ep);
[b02308e]79 return ENOMEM;
[2759c52]80 }
81
[e20eaed]82 ohci_ep->td = malloc32(sizeof(td_t));
83 if (ohci_ep->td == NULL) {
84 free32(ohci_ep->ed);
85 free(ohci_ep);
[b02308e]86 return ENOMEM;
[2759c52]87 }
88
[9515f674]89 ed_init(ohci_ep->ed, ep, ohci_ep->td);
[32e093e]90 endpoint_set_hc_data(
[48ae3ef]91 ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
[620c710]92 hc_enqueue_endpoint(hcd->private_data, ep);
[b02308e]93 return EOK;
[2759c52]94}
[48ae3ef]95/*----------------------------------------------------------------------------*/
96/** Disposes hcd endpoint structure
97 *
[57e06ef]98 * @param[in] hcd driver using this instance.
99 * @param[in] ep endpoint structure.
[48ae3ef]100 */
101void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
102{
103 assert(hcd);
104 assert(ep);
105 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
106 hc_dequeue_endpoint(hcd->private_data, ep);
107 if (instance) {
108 free32(instance->ed);
109 free32(instance->td);
110 free(instance);
111 }
112 endpoint_clear_hc_data(ep);
113}
[2759c52]114/**
115 * @}
116 */
Note: See TracBrowser for help on using the repository browser.