ISIX-RTOS - small operating system for ARM microcontrollers 1.2

irqtimers.h

Go to the documentation of this file.
00001 /*
00002  * irq_timers.h
00003  *
00004  *  Created on: 05-03-2011
00005  *      Author: lucck
00006  */
00007 /*-----------------------------------------------------------------------*/
00008 
00009 #ifndef ISIX_IRQTIMERS_H_
00010 #define ISIX_IRQTIMERS_H_
00011 #ifdef ISIX_CONFIG_USE_TIMERS
00012 /*-----------------------------------------------------------------------*/
00013 #include <isix/config.h>
00014 #include <isix/types.h>
00015 #include <isix/semaphore.h>
00016 /*-----------------------------------------------------------------------*/
00017 #ifdef __cplusplus
00018 extern "C" {
00019 namespace isix {
00020 #endif /*__cplusplus*/
00021 
00022 /*-----------------------------------------------------------------------*/
00023 /* Structure definition for hidding the type */
00024 struct vtimer_struct;
00025 typedef struct vtimer_struct vtimer_t;
00026 
00027 /*-----------------------------------------------------------------------*/
00034 vtimer_t* isix_vtimer_create(void (*func)(void*),void *arg );
00035 /*-----------------------------------------------------------------------*/
00041 int isix_vtimer_start(vtimer_t* timer, tick_t timeout);
00042 /*-----------------------------------------------------------------------*/
00047 static inline int isix_vtimer_stop(vtimer_t* timer)
00048 {
00049         return isix_vtimer_start( timer, 0 );
00050 }
00051 /*-----------------------------------------------------------------------*/
00056 int isix_vtimer_destroy(vtimer_t* timer);
00057 /*-----------------------------------------------------------------------*/
00063 static inline int isix_vtimer_start_ms(vtimer_t* timer, tick_t timeout)
00064 {
00065         return isix_vtimer_start( timer, timeout>0?isix_ms2tick(timeout):0 );
00066 }
00067 
00068 /*-----------------------------------------------------------------------*/
00069 #ifdef __cplusplus
00070 }       //end namespace
00071 }       //end extern-C
00072 #endif /* __cplusplus */
00073 
00074 /*-----------------------------------------------------------------------*/
00075 /****************************** C++ API ***********************************/
00076 #ifdef __cplusplus
00077 #include <cstddef>
00078 
00079 namespace isix {
00080 /*-----------------------------------------------------------------------*/
00082 class virtual_timer
00083 {
00084 public:
00086         virtual_timer()
00087         {
00088                 timer = isix_vtimer_create( vtimer_func, this );
00089         }
00091         ~virtual_timer()
00092         {
00093                 isix_vtimer_destroy( timer );
00094         }
00096         bool is_valid() { return timer!=0; }
00098         int start(tick_t timeout) { return isix_vtimer_start( timer, timeout ); }
00100         int start_ms(tick_t timeout) { return isix_vtimer_start( timer, timeout ); }
00102         int stop() { return isix_vtimer_stop( timer ); }
00103 
00104 protected:
00106         virtual void handle_timer() = 0;
00107 private:
00108         static void vtimer_func(void *ptr)
00109         {
00110                 static_cast<virtual_timer*>(ptr)->handle_timer();
00111         }
00112 private:
00113         //Noncopyable
00114         virtual_timer(const virtual_timer&);
00115         virtual_timer& operator=(const virtual_timer&);
00116 private:
00117         vtimer_t *timer;
00118 };
00119 /*-----------------------------------------------------------------------*/
00120 }
00121 /*-----------------------------------------------------------------------*/
00122 #endif /*  __cplusplus */
00123 /*-----------------------------------------------------------------------*/
00124 
00125 #endif /*ISIX_CONFIG_USE_TIMERS */
00126 #endif /* IRQ_TIMERS_H_ */
00127 /*-----------------------------------------------------------------------*/
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines