source: mainline/uspace/lib/c/generic/irc.c@ 8610c2c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8610c2c was 39026d7c, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Replace fibril_usleep() with async_usleep().

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[869d936]1/*
2 * Copyright (c) 2014 Jiri Svoboda
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
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#include <assert.h>
[39026d7c]36#include <async.h>
[869d936]37#include <errno.h>
38#include <ipc/irc.h>
39#include <ipc/services.h>
40#include <irc.h>
[9a2eb14]41#include <loc.h>
42#include <stdlib.h>
[e5424e9]43#include <sysinfo.h>
[869d936]44
45static async_sess_t *irc_sess;
46
[e5424e9]47/** Connect to IRC service.
[869d936]48 *
[e5424e9]49 * @return EOK on success, EIO on failure
[869d936]50 */
[e5424e9]51static int irc_init(void)
[869d936]52{
[9a2eb14]53 category_id_t irc_cat;
54 service_id_t *svcs;
55 size_t count;
56 int rc;
57
[e5424e9]58 assert(irc_sess == NULL);
[9a2eb14]59 rc = loc_category_get_id("irc", &irc_cat, IPC_FLAG_BLOCKING);
60 if (rc != EOK)
61 return EIO;
62
63 while (true) {
64 rc = loc_category_get_svcs(irc_cat, &svcs, &count);
65 if (rc != EOK)
66 return EIO;
67
68 if (count > 0)
69 break;
70
71 free(svcs);
72
73 // XXX This is just a temporary hack
[39026d7c]74 async_usleep(500 * 1000);
[9a2eb14]75 }
[e5424e9]76
[9a2eb14]77 irc_sess = loc_service_connect(svcs[0], INTERFACE_IRC,
78 IPC_FLAG_BLOCKING);
79 free(svcs);
[e5424e9]80
81 if (irc_sess == NULL)
82 return EIO;
83
84 return EOK;
[869d936]85}
86
[e5424e9]87/** Enable interrupt.
[07cb0108]88 *
89 * Allow interrupt delivery.
[869d936]90 *
91 * @param irq IRQ number
92 */
[e5424e9]93int irc_enable_interrupt(int irq)
[869d936]94{
[e5424e9]95 int rc;
96
97 if (irc_sess == NULL) {
98 rc = irc_init();
99 if (rc != EOK)
100 return rc;
101 }
102
[869d936]103 async_exch_t *exch = async_exchange_begin(irc_sess);
[e5424e9]104 rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
[869d936]105 async_exchange_end(exch);
[e5424e9]106
107 return rc;
[869d936]108}
109
[e5424e9]110/** Disable interrupt.
[07cb0108]111 *
112 * Disallow interrupt delivery.
[869d936]113 *
[e5424e9]114 * @param irq IRQ number
[869d936]115 */
[e5424e9]116int irc_disable_interrupt(int irq)
[869d936]117{
[e5424e9]118 int rc;
[869d936]119
[e5424e9]120 if (irc_sess == NULL) {
121 rc = irc_init();
122 if (rc != EOK)
123 return rc;
124 }
[869d936]125
[07cb0108]126 async_exch_t *exch = async_exchange_begin(irc_sess);
127 rc = async_req_1_0(exch, IRC_DISABLE_INTERRUPT, irq);
128 async_exchange_end(exch);
129
130 return rc;
131}
132
133/** Clear interrupt.
134 *
135 * Clear/acknowledge interrupt in interrupt controller so that
136 * another interrupt can be delivered.
137 *
138 * @param irq IRQ number
139 */
140int irc_clear_interrupt(int irq)
141{
142 int rc;
143
144 if (irc_sess == NULL) {
145 rc = irc_init();
146 if (rc != EOK)
147 return rc;
148 }
149
[e5424e9]150 async_exch_t *exch = async_exchange_begin(irc_sess);
151 rc = async_req_1_0(exch, IRC_CLEAR_INTERRUPT, irq);
152 async_exchange_end(exch);
153
154 return rc;
[869d936]155}
156
157/** @}
158 */
Note: See TracBrowser for help on using the repository browser.