summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-01-18 08:19:14 +0100
committerThomas Martitz <kugel@rockbox.org>2012-01-21 18:39:19 +0100
commit954cd771fb2cca19ddf3f11f888931579470cc0c (patch)
tree809b628b1e290f26a08ba09d3bd7bb8a544e5c99
parenta0d54b09a6b33beb710ad4c9507d7b615eb7d1e8 (diff)
downloadrockbox-954cd771fb2cca19ddf3f11f888931579470cc0c.tar.gz
rockbox-954cd771fb2cca19ddf3f11f888931579470cc0c.zip
android/ypr0: Merge kernel-*.c to generic kernel-unix.c.
Change-Id: Ife3fceb53829ef4e13bae73d8d2f10d7e56d484d
-rw-r--r--firmware/SOURCES8
-rw-r--r--firmware/target/hosted/android/kernel-android.c117
-rw-r--r--firmware/target/hosted/android/system-target.h11
-rw-r--r--firmware/target/hosted/kernel-unix.c (renamed from firmware/target/hosted/ypr0/kernel-ypr0.c)21
-rw-r--r--firmware/target/hosted/kernel-unix.h34
-rw-r--r--firmware/target/hosted/ypr0/system-target.h8
6 files changed, 55 insertions, 144 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 18f877ba3d..19b0efd089 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1,3 +1,6 @@
1#undef unix /* causes problems with some files */
2#undef linux
3
1ata_idle_notify.c 4ata_idle_notify.c
2events.c 5events.c
3backlight.c 6backlight.c
@@ -9,7 +12,6 @@ powermgmt.c
9#if (CONFIG_PLATFORM & PLATFORM_HOSTED) 12#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
10 13
11#ifdef __linux__ 14#ifdef __linux__
12#undef linux
13target/hosted/cpuinfo-linux.c 15target/hosted/cpuinfo-linux.c
14#endif 16#endif
15 17
@@ -75,8 +77,8 @@ drivers/rtc/rtc_as3514.c
75#else 77#else
76target/hosted/rtc.c 78target/hosted/rtc.c
77#endif 79#endif
80target/hosted/kernel-unix.c
78target/hosted/ypr0/button-ypr0.c 81target/hosted/ypr0/button-ypr0.c
79target/hosted/ypr0/kernel-ypr0.c
80target/hosted/ypr0/lcd-ypr0.c 82target/hosted/ypr0/lcd-ypr0.c
81target/hosted/ypr0/system-ypr0.c 83target/hosted/ypr0/system-ypr0.c
82target/hosted/ypr0/fs-ypr0.c 84target/hosted/ypr0/fs-ypr0.c
@@ -1690,6 +1692,7 @@ target/arm/rk27xx/hm801/power-hm801.c
1690#endif 1692#endif
1691 1693
1692#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 1694#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
1695target/hosted/kernel-unix.c
1693target/hosted/android/fs-android.c 1696target/hosted/android/fs-android.c
1694target/hosted/android/lcd-android.c 1697target/hosted/android/lcd-android.c
1695target/hosted/android/lc-android.c 1698target/hosted/android/lc-android.c
@@ -1697,7 +1700,6 @@ target/hosted/android/button-android.c
1697#ifdef DEBUG 1700#ifdef DEBUG
1698target/hosted/android/debug-android.c 1701target/hosted/android/debug-android.c
1699#endif 1702#endif
1700target/hosted/android/kernel-android.c
1701target/hosted/android/pcm-android.c 1703target/hosted/android/pcm-android.c
1702target/hosted/android/powermgmt-android.c 1704target/hosted/android/powermgmt-android.c
1703target/hosted/android/system-android.c 1705target/hosted/android/system-android.c
diff --git a/firmware/target/hosted/android/kernel-android.c b/firmware/target/hosted/android/kernel-android.c
deleted file mode 100644
index e3522418fe..0000000000
--- a/firmware/target/hosted/android/kernel-android.c
+++ /dev/null
@@ -1,117 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
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
23#include <time.h>
24#include <signal.h>
25#include <errno.h>
26#include <unistd.h>
27#include <pthread.h>
28#include "config.h"
29#include "system.h"
30#include "button.h"
31#include "audio.h"
32#include "panic.h"
33
34
35static pthread_cond_t wfi_cond = PTHREAD_COND_INITIALIZER;
36static pthread_mutex_t wfi_mtx = PTHREAD_MUTEX_INITIALIZER;
37/*
38 * call tick tasks and wake the scheduler up */
39void timer_signal(union sigval arg)
40{
41 (void)arg;
42 call_tick_tasks();
43 interrupt();
44}
45
46/*
47 * wait on the sem which the signal handler posts to save cpu time (aka sleep)
48 *
49 * other mechanisms could use them as well */
50void wait_for_interrupt(void)
51{
52 pthread_cond_wait(&wfi_cond, &wfi_mtx);
53}
54
55/*
56 * Wakeup the kernel, if sleeping (shall not be called from a signal handler) */
57void interrupt(void)
58{
59 pthread_cond_signal(&wfi_cond);
60}
61
62/*
63 * setup a hrtimer to send a signal to our process every tick
64 *
65 * WARNING: JNI calls are not permitted from tick tasks, as the
66 * underlying thread is not attached to the Java VM
67 *
68 * Can be possibly be attached if it really needs to be. but let's
69 * keep this leightweight */
70void tick_start(unsigned int interval_in_ms)
71{
72 int ret = 0;
73 timer_t timerid;
74 struct itimerspec ts;
75 sigevent_t sigev;
76
77 /* initializing in the declaration causes some weird warnings */
78 memset(&sigev, 0, sizeof(sigevent_t));
79 sigev.sigev_notify = SIGEV_THREAD,
80 sigev.sigev_notify_function = timer_signal,
81
82 ts.it_value.tv_sec = ts.it_interval.tv_sec = 0;
83 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = interval_in_ms*1000*1000;
84
85 /* add the timer */
86 ret |= timer_create(CLOCK_REALTIME, &sigev, &timerid);
87 ret |= timer_settime(timerid, 0, &ts, NULL);
88
89 /* Grab the mutex already now and leave it to this thread. We don't
90 * care about race conditions when signaling the condition (because
91 * they are not critical), but a mutex is necessary due to the API */
92 pthread_mutex_lock(&wfi_mtx);
93
94 if (ret != 0)
95 panicf("%s(): %s\n", __func__, strerror(errno));
96}
97
98
99bool timer_register(int reg_prio, void (*unregister_callback)(void),
100 long cycles, void (*timer_callback)(void))
101{
102 (void)reg_prio;
103 (void)unregister_callback;
104 (void)cycles;
105 (void)timer_callback;
106 return false;
107}
108
109bool timer_set_period(long cycles)
110{
111 (void)cycles;
112 return false;
113}
114
115void timer_unregister(void)
116{
117}
diff --git a/firmware/target/hosted/android/system-target.h b/firmware/target/hosted/android/system-target.h
index 12610de42f..aba7e6d6c0 100644
--- a/firmware/target/hosted/android/system-target.h
+++ b/firmware/target/hosted/android/system-target.h
@@ -18,22 +18,16 @@
18 * KIND, either express or implied. 18 * KIND, either express or implied.
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21
21#ifndef __SYSTEM_TARGET_H__ 22#ifndef __SYSTEM_TARGET_H__
22#define __SYSTEM_TARGET_H__ 23#define __SYSTEM_TARGET_H__
23 24
24#define disable_irq() 25#include "kernel-unix.h"
25#define enable_irq()
26#define disable_irq_save() 0
27#define restore_irq(level) (void)level
28 26
29static inline void commit_dcache(void) {} 27static inline void commit_dcache(void) {}
30static inline void commit_discard_dcache(void) {} 28static inline void commit_discard_dcache(void) {}
31static inline void commit_discard_idcache(void) {} 29static inline void commit_discard_idcache(void) {}
32 30
33void power_off(void);
34void wait_for_interrupt(void);
35void interrupt(void);
36
37 /* don't pull in jni.h for every user of this file, it should be only needed 31 /* don't pull in jni.h for every user of this file, it should be only needed
38 * within the target tree (if at all) 32 * within the target tree (if at all)
39 * define this before #including system.h or system-target.h */ 33 * define this before #including system.h or system-target.h */
@@ -47,4 +41,3 @@ extern JNIEnv* getJavaEnvironment(void);
47#endif /* __SYSTEM_TARGET_H__ */ 41#endif /* __SYSTEM_TARGET_H__ */
48 42
49#define NEED_GENERIC_BYTESWAPS 43#define NEED_GENERIC_BYTESWAPS
50
diff --git a/firmware/target/hosted/ypr0/kernel-ypr0.c b/firmware/target/hosted/kernel-unix.c
index bcf2cee583..a0167d46c5 100644
--- a/firmware/target/hosted/ypr0/kernel-ypr0.c
+++ b/firmware/target/hosted/kernel-unix.c
@@ -20,6 +20,7 @@
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22 22
23#include <stdlib.h>
23#include <time.h> 24#include <time.h>
24#include <signal.h> 25#include <signal.h>
25#include <errno.h> 26#include <errno.h>
@@ -63,10 +64,13 @@ void interrupt(void)
63 64
64/* 65/*
65 * setup a hrtimer to send a signal to our process every tick 66 * setup a hrtimer to send a signal to our process every tick
67 *
68 * WARNING for Android: JNI calls are not permitted from tick tasks, as the
69 * underlying thread is not attached to the Java VM
70 *
71 * Can be possibly be attached if it really needs to be. but let's
72 * keep this leightweight
66 */ 73 */
67union sigval tick_arg = {
68 .sival_int = 0,
69};
70 74
71void tick_start(unsigned int interval_in_ms) 75void tick_start(unsigned int interval_in_ms)
72{ 76{
@@ -126,13 +130,13 @@ bool timer_register(int reg_prio, void (*unregister_callback)(void),
126 if (timer_prio >= 0 && global_unreg_callback) 130 if (timer_prio >= 0 && global_unreg_callback)
127 global_unreg_callback(); 131 global_unreg_callback();
128 132
129 /* initializing in the declaration causes some weird warnings */
130 memset(&sigev, 0, sizeof(sigevent_t)); 133 memset(&sigev, 0, sizeof(sigevent_t));
131 sigev.sigev_notify = SIGEV_THREAD, 134 sigev.sigev_notify = SIGEV_THREAD,
132 sigev.sigev_notify_function = timer_cb; 135 sigev.sigev_notify_function = timer_cb;
133 136
134 ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000; 137 div_t q = div(in_us, 1000000);
135 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000; 138 ts.it_value.tv_sec = ts.it_interval.tv_sec = q.quot;
139 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = q.rem*1000;
136 140
137 /* add the timer */ 141 /* add the timer */
138 ret |= timer_create(CLOCK_REALTIME, &sigev, &timer_tid); 142 ret |= timer_create(CLOCK_REALTIME, &sigev, &timer_tid);
@@ -149,8 +153,9 @@ bool timer_set_period(long cycles)
149{ 153{
150 struct itimerspec ts; 154 struct itimerspec ts;
151 long in_us = cycles_to_microseconds(cycles); 155 long in_us = cycles_to_microseconds(cycles);
152 ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000; 156 div_t q = div(in_us, 1000000);
153 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000; 157 ts.it_value.tv_sec = ts.it_interval.tv_sec = q.quot;
158 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = q.rem*1000;
154 159
155 return timer_settime(timer_tid, 0, &ts, NULL) == 0; 160 return timer_settime(timer_tid, 0, &ts, NULL) == 0;
156} 161}
diff --git a/firmware/target/hosted/kernel-unix.h b/firmware/target/hosted/kernel-unix.h
new file mode 100644
index 0000000000..f296668861
--- /dev/null
+++ b/firmware/target/hosted/kernel-unix.h
@@ -0,0 +1,34 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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 __KERNEL_UNIX_H__
23#define __KERNEL_UNIX_H__
24
25/* interrupt emulation incomplete, doesn't seem needed so far */
26#define disable_irq()
27#define enable_irq()
28#define disable_irq_save() 0
29#define restore_irq(level) (void)level
30
31void wait_for_interrupt(void);
32void interrupt(void);
33
34#endif /* __KERNEL_UNIX_H__ */
diff --git a/firmware/target/hosted/ypr0/system-target.h b/firmware/target/hosted/ypr0/system-target.h
index 07a3163ea9..efd235282e 100644
--- a/firmware/target/hosted/ypr0/system-target.h
+++ b/firmware/target/hosted/ypr0/system-target.h
@@ -21,13 +21,7 @@
21#ifndef __SYSTEM_TARGET_H__ 21#ifndef __SYSTEM_TARGET_H__
22#define __SYSTEM_TARGET_H__ 22#define __SYSTEM_TARGET_H__
23 23
24#define disable_irq() 24#include "kernel-unix.h"
25#define enable_irq()
26#define disable_irq_save() 0
27#define restore_irq(level) (void)level
28
29void wait_for_interrupt(void);
30void interrupt(void);
31 25
32static inline void commit_dcache(void) {} 26static inline void commit_dcache(void) {}
33static inline void commit_discard_dcache(void) {} 27static inline void commit_discard_dcache(void) {}