source: mainline/uspace/lib/c/generic/irc.c@ 28a5ebd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 28a5ebd was fec7ba0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Avoid including <fibril.h> from <async.h>

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