From 954cd771fb2cca19ddf3f11f888931579470cc0c Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Wed, 18 Jan 2012 08:19:14 +0100 Subject: android/ypr0: Merge kernel-*.c to generic kernel-unix.c. Change-Id: Ife3fceb53829ef4e13bae73d8d2f10d7e56d484d --- firmware/SOURCES | 8 +- firmware/target/hosted/android/kernel-android.c | 117 ----------------- firmware/target/hosted/android/system-target.h | 11 +- firmware/target/hosted/kernel-unix.c | 168 ++++++++++++++++++++++++ firmware/target/hosted/kernel-unix.h | 34 +++++ firmware/target/hosted/ypr0/kernel-ypr0.c | 163 ----------------------- firmware/target/hosted/ypr0/system-target.h | 8 +- 7 files changed, 210 insertions(+), 299 deletions(-) delete mode 100644 firmware/target/hosted/android/kernel-android.c create mode 100644 firmware/target/hosted/kernel-unix.c create mode 100644 firmware/target/hosted/kernel-unix.h delete mode 100644 firmware/target/hosted/ypr0/kernel-ypr0.c diff --git a/firmware/SOURCES b/firmware/SOURCES index 18f877ba3d..19b0efd089 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -1,3 +1,6 @@ +#undef unix /* causes problems with some files */ +#undef linux + ata_idle_notify.c events.c backlight.c @@ -9,7 +12,6 @@ powermgmt.c #if (CONFIG_PLATFORM & PLATFORM_HOSTED) #ifdef __linux__ -#undef linux target/hosted/cpuinfo-linux.c #endif @@ -75,8 +77,8 @@ drivers/rtc/rtc_as3514.c #else target/hosted/rtc.c #endif +target/hosted/kernel-unix.c target/hosted/ypr0/button-ypr0.c -target/hosted/ypr0/kernel-ypr0.c target/hosted/ypr0/lcd-ypr0.c target/hosted/ypr0/system-ypr0.c target/hosted/ypr0/fs-ypr0.c @@ -1690,6 +1692,7 @@ target/arm/rk27xx/hm801/power-hm801.c #endif #if (CONFIG_PLATFORM & PLATFORM_ANDROID) +target/hosted/kernel-unix.c target/hosted/android/fs-android.c target/hosted/android/lcd-android.c target/hosted/android/lc-android.c @@ -1697,7 +1700,6 @@ target/hosted/android/button-android.c #ifdef DEBUG target/hosted/android/debug-android.c #endif -target/hosted/android/kernel-android.c target/hosted/android/pcm-android.c target/hosted/android/powermgmt-android.c target/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 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (c) 2010 Thomas Martitz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - - -#include -#include -#include -#include -#include -#include "config.h" -#include "system.h" -#include "button.h" -#include "audio.h" -#include "panic.h" - - -static pthread_cond_t wfi_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t wfi_mtx = PTHREAD_MUTEX_INITIALIZER; -/* - * call tick tasks and wake the scheduler up */ -void timer_signal(union sigval arg) -{ - (void)arg; - call_tick_tasks(); - interrupt(); -} - -/* - * wait on the sem which the signal handler posts to save cpu time (aka sleep) - * - * other mechanisms could use them as well */ -void wait_for_interrupt(void) -{ - pthread_cond_wait(&wfi_cond, &wfi_mtx); -} - -/* - * Wakeup the kernel, if sleeping (shall not be called from a signal handler) */ -void interrupt(void) -{ - pthread_cond_signal(&wfi_cond); -} - -/* - * setup a hrtimer to send a signal to our process every tick - * - * WARNING: JNI calls are not permitted from tick tasks, as the - * underlying thread is not attached to the Java VM - * - * Can be possibly be attached if it really needs to be. but let's - * keep this leightweight */ -void tick_start(unsigned int interval_in_ms) -{ - int ret = 0; - timer_t timerid; - struct itimerspec ts; - sigevent_t sigev; - - /* initializing in the declaration causes some weird warnings */ - memset(&sigev, 0, sizeof(sigevent_t)); - sigev.sigev_notify = SIGEV_THREAD, - sigev.sigev_notify_function = timer_signal, - - ts.it_value.tv_sec = ts.it_interval.tv_sec = 0; - ts.it_value.tv_nsec = ts.it_interval.tv_nsec = interval_in_ms*1000*1000; - - /* add the timer */ - ret |= timer_create(CLOCK_REALTIME, &sigev, &timerid); - ret |= timer_settime(timerid, 0, &ts, NULL); - - /* Grab the mutex already now and leave it to this thread. We don't - * care about race conditions when signaling the condition (because - * they are not critical), but a mutex is necessary due to the API */ - pthread_mutex_lock(&wfi_mtx); - - if (ret != 0) - panicf("%s(): %s\n", __func__, strerror(errno)); -} - - -bool timer_register(int reg_prio, void (*unregister_callback)(void), - long cycles, void (*timer_callback)(void)) -{ - (void)reg_prio; - (void)unregister_callback; - (void)cycles; - (void)timer_callback; - return false; -} - -bool timer_set_period(long cycles) -{ - (void)cycles; - return false; -} - -void timer_unregister(void) -{ -} 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 @@ * KIND, either express or implied. * ****************************************************************************/ + #ifndef __SYSTEM_TARGET_H__ #define __SYSTEM_TARGET_H__ -#define disable_irq() -#define enable_irq() -#define disable_irq_save() 0 -#define restore_irq(level) (void)level +#include "kernel-unix.h" static inline void commit_dcache(void) {} static inline void commit_discard_dcache(void) {} static inline void commit_discard_idcache(void) {} -void power_off(void); -void wait_for_interrupt(void); -void interrupt(void); - /* don't pull in jni.h for every user of this file, it should be only needed * within the target tree (if at all) * define this before #including system.h or system-target.h */ @@ -47,4 +41,3 @@ extern JNIEnv* getJavaEnvironment(void); #endif /* __SYSTEM_TARGET_H__ */ #define NEED_GENERIC_BYTESWAPS - diff --git a/firmware/target/hosted/kernel-unix.c b/firmware/target/hosted/kernel-unix.c new file mode 100644 index 0000000000..a0167d46c5 --- /dev/null +++ b/firmware/target/hosted/kernel-unix.c @@ -0,0 +1,168 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (c) 2010 Thomas Martitz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "system.h" +#include "button.h" +#include "audio.h" +#include "panic.h" +#include "timer.h" + + +static pthread_cond_t wfi_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t wfi_mtx = PTHREAD_MUTEX_INITIALIZER; +/* + * call tick tasks and wake the scheduler up */ +void timer_signal(union sigval arg) +{ + (void)arg; + call_tick_tasks(); + interrupt(); +} + +/* + * wait on the sem which the signal handler posts to save cpu time (aka sleep) + * + * other mechanisms could use them as well */ +void wait_for_interrupt(void) +{ + pthread_cond_wait(&wfi_cond, &wfi_mtx); +} + +/* + * Wakeup the kernel, if sleeping (shall not be called from a signal handler) */ +void interrupt(void) +{ + pthread_cond_signal(&wfi_cond); +} + + +/* + * setup a hrtimer to send a signal to our process every tick + * + * WARNING for Android: JNI calls are not permitted from tick tasks, as the + * underlying thread is not attached to the Java VM + * + * Can be possibly be attached if it really needs to be. but let's + * keep this leightweight + */ + +void tick_start(unsigned int interval_in_ms) +{ + int ret = 0; + timer_t timerid; + struct itimerspec ts; + sigevent_t sigev; + + /* initializing in the declaration causes some weird warnings */ + memset(&sigev, 0, sizeof(sigevent_t)); + sigev.sigev_notify = SIGEV_THREAD, + sigev.sigev_notify_function = timer_signal; + + ts.it_value.tv_sec = ts.it_interval.tv_sec = 0; + ts.it_value.tv_nsec = ts.it_interval.tv_nsec = interval_in_ms*1000*1000; + + /* add the timer */ + ret |= timer_create(CLOCK_REALTIME, &sigev, &timerid); + ret |= timer_settime(timerid, 0, &ts, NULL); + + /* Grab the mutex already now and leave it to this thread. We don't + * care about race conditions when signaling the condition (because + * they are not critical), but a mutex is necessary due to the API */ + pthread_mutex_lock(&wfi_mtx); + + if (ret != 0) + panicf("%s(): %s\n", __func__, strerror(errno)); +} + +#define cycles_to_microseconds(cycles) \ + ((int)((1000000*cycles)/TIMER_FREQ)) + + +static timer_t timer_tid; +static int timer_prio = -1; +void (*global_unreg_callback)(void); +void (*global_timer_callback)(void); + +static void timer_cb(union sigval arg) +{ + (void)arg; + if (global_timer_callback) + global_timer_callback(); +} + +bool timer_register(int reg_prio, void (*unregister_callback)(void), + long cycles, void (*timer_callback)(void)) +{ + int ret = 0; + struct itimerspec ts; + sigevent_t sigev; + long in_us = cycles_to_microseconds(cycles); + + if (reg_prio <= timer_prio || in_us <= 0) + return false; + + if (timer_prio >= 0 && global_unreg_callback) + global_unreg_callback(); + + memset(&sigev, 0, sizeof(sigevent_t)); + sigev.sigev_notify = SIGEV_THREAD, + sigev.sigev_notify_function = timer_cb; + + div_t q = div(in_us, 1000000); + ts.it_value.tv_sec = ts.it_interval.tv_sec = q.quot; + ts.it_value.tv_nsec = ts.it_interval.tv_nsec = q.rem*1000; + + /* add the timer */ + ret |= timer_create(CLOCK_REALTIME, &sigev, &timer_tid); + ret |= timer_settime(timer_tid, 0, &ts, NULL); + + global_timer_callback = timer_callback; + global_unreg_callback = unregister_callback; + timer_prio = reg_prio; + + return ret == 0; +} + +bool timer_set_period(long cycles) +{ + struct itimerspec ts; + long in_us = cycles_to_microseconds(cycles); + div_t q = div(in_us, 1000000); + ts.it_value.tv_sec = ts.it_interval.tv_sec = q.quot; + ts.it_value.tv_nsec = ts.it_interval.tv_nsec = q.rem*1000; + + return timer_settime(timer_tid, 0, &ts, NULL) == 0; +} + +void timer_unregister(void) +{ + timer_delete(timer_tid); + timer_prio = -1; +} + 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 by Thomas Martitz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef __KERNEL_UNIX_H__ +#define __KERNEL_UNIX_H__ + +/* interrupt emulation incomplete, doesn't seem needed so far */ +#define disable_irq() +#define enable_irq() +#define disable_irq_save() 0 +#define restore_irq(level) (void)level + +void wait_for_interrupt(void); +void interrupt(void); + +#endif /* __KERNEL_UNIX_H__ */ diff --git a/firmware/target/hosted/ypr0/kernel-ypr0.c b/firmware/target/hosted/ypr0/kernel-ypr0.c deleted file mode 100644 index bcf2cee583..0000000000 --- a/firmware/target/hosted/ypr0/kernel-ypr0.c +++ /dev/null @@ -1,163 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (c) 2010 Thomas Martitz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - - -#include -#include -#include -#include -#include -#include "config.h" -#include "system.h" -#include "button.h" -#include "audio.h" -#include "panic.h" -#include "timer.h" - - -static pthread_cond_t wfi_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t wfi_mtx = PTHREAD_MUTEX_INITIALIZER; -/* - * call tick tasks and wake the scheduler up */ -void timer_signal(union sigval arg) -{ - (void)arg; - call_tick_tasks(); - interrupt(); -} - -/* - * wait on the sem which the signal handler posts to save cpu time (aka sleep) - * - * other mechanisms could use them as well */ -void wait_for_interrupt(void) -{ - pthread_cond_wait(&wfi_cond, &wfi_mtx); -} - -/* - * Wakeup the kernel, if sleeping (shall not be called from a signal handler) */ -void interrupt(void) -{ - pthread_cond_signal(&wfi_cond); -} - - -/* - * setup a hrtimer to send a signal to our process every tick - */ -union sigval tick_arg = { - .sival_int = 0, -}; - -void tick_start(unsigned int interval_in_ms) -{ - int ret = 0; - timer_t timerid; - struct itimerspec ts; - sigevent_t sigev; - - /* initializing in the declaration causes some weird warnings */ - memset(&sigev, 0, sizeof(sigevent_t)); - sigev.sigev_notify = SIGEV_THREAD, - sigev.sigev_notify_function = timer_signal; - - ts.it_value.tv_sec = ts.it_interval.tv_sec = 0; - ts.it_value.tv_nsec = ts.it_interval.tv_nsec = interval_in_ms*1000*1000; - - /* add the timer */ - ret |= timer_create(CLOCK_REALTIME, &sigev, &timerid); - ret |= timer_settime(timerid, 0, &ts, NULL); - - /* Grab the mutex already now and leave it to this thread. We don't - * care about race conditions when signaling the condition (because - * they are not critical), but a mutex is necessary due to the API */ - pthread_mutex_lock(&wfi_mtx); - - if (ret != 0) - panicf("%s(): %s\n", __func__, strerror(errno)); -} - -#define cycles_to_microseconds(cycles) \ - ((int)((1000000*cycles)/TIMER_FREQ)) - - -static timer_t timer_tid; -static int timer_prio = -1; -void (*global_unreg_callback)(void); -void (*global_timer_callback)(void); - -static void timer_cb(union sigval arg) -{ - (void)arg; - if (global_timer_callback) - global_timer_callback(); -} - -bool timer_register(int reg_prio, void (*unregister_callback)(void), - long cycles, void (*timer_callback)(void)) -{ - int ret = 0; - struct itimerspec ts; - sigevent_t sigev; - long in_us = cycles_to_microseconds(cycles); - - if (reg_prio <= timer_prio || in_us <= 0) - return false; - - if (timer_prio >= 0 && global_unreg_callback) - global_unreg_callback(); - - /* initializing in the declaration causes some weird warnings */ - memset(&sigev, 0, sizeof(sigevent_t)); - sigev.sigev_notify = SIGEV_THREAD, - sigev.sigev_notify_function = timer_cb; - - ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000; - ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000; - - /* add the timer */ - ret |= timer_create(CLOCK_REALTIME, &sigev, &timer_tid); - ret |= timer_settime(timer_tid, 0, &ts, NULL); - - global_timer_callback = timer_callback; - global_unreg_callback = unregister_callback; - timer_prio = reg_prio; - - return ret == 0; -} - -bool timer_set_period(long cycles) -{ - struct itimerspec ts; - long in_us = cycles_to_microseconds(cycles); - ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000; - ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000; - - return timer_settime(timer_tid, 0, &ts, NULL) == 0; -} - -void timer_unregister(void) -{ - timer_delete(timer_tid); - timer_prio = -1; -} - 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 @@ #ifndef __SYSTEM_TARGET_H__ #define __SYSTEM_TARGET_H__ -#define disable_irq() -#define enable_irq() -#define disable_irq_save() 0 -#define restore_irq(level) (void)level - -void wait_for_interrupt(void); -void interrupt(void); +#include "kernel-unix.h" static inline void commit_dcache(void) {} static inline void commit_discard_dcache(void) {} -- cgit v1.2.3