summaryrefslogtreecommitdiff
path: root/firmware/kernel/include/queue.h
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-12-04 17:06:17 +0100
committerThomas Martitz <kugel@rockbox.org>2014-03-03 18:11:57 +0100
commit382d1861af12741af4ff235b9d18f179c0adc4c5 (patch)
tree26166c130d2889bb1ae1082e8f7aba103534f49e /firmware/kernel/include/queue.h
parent8bae5f2644b5d5759499fbf1066b9c35c6f859ad (diff)
downloadrockbox-382d1861af12741af4ff235b9d18f179c0adc4c5.tar.gz
rockbox-382d1861af12741af4ff235b9d18f179c0adc4c5.zip
kernel: Break out kernel primitives into separate files and move to separate dir.
No code changed, just shuffling stuff around. This should make it easier to build only select parts kernel and use different implementations. Change-Id: Ie1f00f93008833ce38419d760afd70062c5e22b5
Diffstat (limited to 'firmware/kernel/include/queue.h')
-rw-r--r--firmware/kernel/include/queue.h157
1 files changed, 157 insertions, 0 deletions
diff --git a/firmware/kernel/include/queue.h b/firmware/kernel/include/queue.h
new file mode 100644
index 0000000000..1b404f8297
--- /dev/null
+++ b/firmware/kernel/include/queue.h
@@ -0,0 +1,157 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef QUEUE_H
23#define QUEUE_H
24
25#include <stdint.h>
26#include "config.h"
27#include "thread.h"
28
29/* System defined message ID's - |sign bit = 1|class|id| */
30/* Event class list */
31#define SYS_EVENT_CLS_QUEUE 0
32#define SYS_EVENT_CLS_USB 1
33#define SYS_EVENT_CLS_POWER 2
34#define SYS_EVENT_CLS_FILESYS 3
35#define SYS_EVENT_CLS_PLUG 4
36#define SYS_EVENT_CLS_MISC 5
37#define SYS_EVENT_CLS_PRIVATE 7 /* For use inside plugins */
38/* make sure SYS_EVENT_CLS_BITS has enough range */
39
40/* Bit 31->|S|c...c|i...i| */
41#define SYS_EVENT ((long)(int)(1 << 31))
42#define SYS_EVENT_CLS_BITS (3)
43#define SYS_EVENT_CLS_SHIFT (31-SYS_EVENT_CLS_BITS)
44#define SYS_EVENT_CLS_MASK (((1l << SYS_EVENT_CLS_BITS)-1) << SYS_EVENT_SHIFT)
45#define MAKE_SYS_EVENT(cls, id) (SYS_EVENT | ((long)(cls) << SYS_EVENT_CLS_SHIFT) | (long)(id))
46/* Macros for extracting codes */
47#define SYS_EVENT_CLS(e) (((e) & SYS_EVENT_CLS_MASK) >> SYS_EVENT_SHIFT)
48#define SYS_EVENT_ID(e) ((e) & ~(SYS_EVENT|SYS_EVENT_CLS_MASK))
49
50#define SYS_TIMEOUT MAKE_SYS_EVENT(SYS_EVENT_CLS_QUEUE, 0)
51#define SYS_USB_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 0)
52#define SYS_USB_CONNECTED_ACK MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 1)
53#define SYS_USB_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 2)
54#define SYS_USB_LUN_LOCKED MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 4)
55#define SYS_USB_READ_DATA MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 5)
56#define SYS_USB_WRITE_DATA MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 6)
57#define SYS_POWEROFF MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 0)
58#define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1)
59#define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2)
60#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3)
61#define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0)
62#define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0)
63#define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1)
64#define SYS_PHONE_PLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 2)
65#define SYS_PHONE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 3)
66#define SYS_REMOTE_PLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 4)
67#define SYS_REMOTE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 5)
68#define SYS_CAR_ADAPTER_RESUME MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 0)
69#define SYS_CALL_INCOMING MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 3)
70#define SYS_CALL_HUNG_UP MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 4)
71#define SYS_VOLUME_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 5)
72
73#define IS_SYSEVENT(ev) ((ev & SYS_EVENT) == SYS_EVENT)
74
75#define MAX_NUM_QUEUES 32
76#define QUEUE_LENGTH 16 /* MUST be a power of 2 */
77#define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1)
78
79struct queue_event
80{
81 long id;
82 intptr_t data;
83};
84
85#ifdef HAVE_EXTENDED_MESSAGING_AND_NAME
86struct queue_sender_list
87{
88 /* If non-NULL, there is a thread waiting for the corresponding event */
89 /* Must be statically allocated to put in non-cached ram. */
90 struct thread_entry *senders[QUEUE_LENGTH]; /* message->thread map */
91 struct thread_entry *list; /* list of senders in map */
92 /* Send info for last message dequeued or NULL if replied or not sent */
93 struct thread_entry * volatile curr_sender;
94#ifdef HAVE_PRIORITY_SCHEDULING
95 struct blocker blocker;
96#endif
97};
98#endif /* HAVE_EXTENDED_MESSAGING_AND_NAME */
99
100#ifdef HAVE_PRIORITY_SCHEDULING
101#define QUEUE_GET_THREAD(q) \
102 (((q)->send == NULL) ? NULL : (q)->send->blocker.thread)
103#else
104/* Queue without priority enabled have no owner provision _at this time_ */
105#define QUEUE_GET_THREAD(q) \
106 (NULL)
107#endif
108
109struct event_queue
110{
111 struct thread_entry *queue; /* waiter list */
112 struct queue_event events[QUEUE_LENGTH]; /* list of events */
113 unsigned int volatile read; /* head of queue */
114 unsigned int volatile write; /* tail of queue */
115#ifdef HAVE_EXTENDED_MESSAGING_AND_NAME
116 struct queue_sender_list * volatile send; /* list of threads waiting for
117 reply to an event */
118#ifdef HAVE_PRIORITY_SCHEDULING
119 struct blocker *blocker_p; /* priority inheritance info
120 for sync message senders */
121#endif
122#endif
123 IF_COP( struct corelock cl; ) /* multiprocessor sync */
124};
125
126extern void queue_init(struct event_queue *q, bool register_queue);
127extern void queue_delete(struct event_queue *q);
128extern void queue_wait(struct event_queue *q, struct queue_event *ev);
129extern void queue_wait_w_tmo(struct event_queue *q, struct queue_event *ev,
130 int ticks);
131extern void queue_post(struct event_queue *q, long id, intptr_t data);
132#ifdef HAVE_EXTENDED_MESSAGING_AND_NAME
133extern void queue_enable_queue_send(struct event_queue *q,
134 struct queue_sender_list *send,
135 unsigned int owner_id);
136extern intptr_t queue_send(struct event_queue *q, long id, intptr_t data);
137extern void queue_reply(struct event_queue *q, intptr_t retval);
138extern bool queue_in_queue_send(struct event_queue *q);
139#endif /* HAVE_EXTENDED_MESSAGING_AND_NAME */
140extern bool queue_empty(const struct event_queue* q);
141extern bool queue_peek(struct event_queue *q, struct queue_event *ev);
142
143#define QPEEK_FILTER_COUNT_MASK (0xffu) /* 0x00=1 filter, 0xff=256 filters */
144#define QPEEK_FILTER_HEAD_ONLY (1u << 8) /* Ignored if no filters */
145#define QPEEK_REMOVE_EVENTS (1u << 9) /* Remove or discard events */
146extern bool queue_peek_ex(struct event_queue *q,
147 struct queue_event *ev,
148 unsigned int flags,
149 const long (*filters)[2]);
150
151extern void queue_clear(struct event_queue* q);
152extern void queue_remove_from_head(struct event_queue *q, long id);
153extern int queue_count(const struct event_queue *q);
154extern int queue_broadcast(long id, intptr_t data);
155extern void init_queues(void);
156
157#endif /* QUEUE_H */