This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
timer functions for non-kernel
- From: Jani Monoses <jani at iv dot ro>
- To: eCos Patches <ecos-patches at ecos dot sourceware dot org>
- Date: Fri, 26 Nov 2004 15:30:58 +0200
- Subject: timer functions for non-kernel
This adds cyg_thread_delay() and cyg_current_time() functions to the drv_api for
compatibility with the kernel config, so apps don't need to #ifdef on CYGPKG_KERNEL.
Does the idea and the code seem OK?
thanks
Jani
--- orig/packages/hal/common/current/include/drv_api.h
+++ mod/packages/hal/common/current/include/drv_api.h
@@ -130,6 +130,12 @@
typedef int cyg_bool_t;
typedef cyg_int32 cyg_code_t; /* type for various codes */
+typedef cyg_uint64 cyg_tick_count_t;
+
+externC cyg_tick_count_t cyg_current_time(void);
+externC void cyg_thread_delay(cyg_tick_count_t delay);
+void rtc_timer_init(void);
+
typedef cyg_uint32 cyg_ISR_t( cyg_vector_t vector, cyg_addrword_t data);
typedef void cyg_DSR_t(cyg_vector_t vector,
cyg_ucount32 count,
--- orig/packages/hal/common/current/src/drv_api.c
+++ mod/packages/hal/common/current/src/drv_api.c
@@ -937,6 +937,59 @@
CYG_FAIL(" !!! Exception !!! ");
}
+//
+// Real time clock and delay functions
+//
+
+static volatile cyg_tick_count_t rtc_ticks;
+static cyg_interrupt rtc_interrupt;
+static cyg_handle_t rtc_handle;
+
+static cyg_uint32
+rtc_isr(cyg_vector_t vector, cyg_addrword_t data)
+{
+ ++rtc_ticks;
+
+ HAL_CLOCK_RESET(CYGNUM_HAL_INTERRUPT_RTC, CYGNUM_HAL_RTC_PERIOD);
+
+ cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_RTC);
+
+ return CYG_ISR_HANDLED;
+}
+
+
+void rtc_timer_init(void)
+{
+ HAL_CLOCK_INITIALIZE(CYGNUM_HAL_RTC_PERIOD);
+
+ cyg_drv_interrupt_create(
+ CYGNUM_HAL_INTERRUPT_RTC,
+ 0, // Priority - unused
+ (CYG_ADDRWORD)0, // Data item passed to ISR & DSR
+ rtc_isr, // ISR
+ NULL, // no DSR
+ &rtc_handle, // handle to intr obj
+ &rtc_interrupt ); // space for int obj
+
+ cyg_drv_interrupt_attach(rtc_handle);
+
+ cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_RTC);
+}
+
+
+cyg_tick_count_t cyg_current_time(void)
+{
+ return rtc_ticks;
+}
+
+void cyg_thread_delay(cyg_tick_count_t delay)
+{
+ cyg_tick_count_t now = cyg_current_time();
+
+ while (cyg_current_time() < now + delay) {
+ HAL_IDLE_THREAD_ACTION(idle_thread_loops[CYG_KERNEL_CPU_THIS()]);
+ }
+}
#endif