ISIX-RTOS - small operating system for ARM microcontrollers 1.2

fifo.h

Go to the documentation of this file.
00001 /* Queue operations */
00002 #ifndef _ISIX_FIFO_H
00003 #define _ISIX_FIFO_H
00004 
00005 /*--------------------------------------------------------------*/
00006 #ifdef __cplusplus
00007 extern "C" {
00008 namespace isix {
00009 #endif /*__cplusplus*/
00010 
00011 /*--------------------------------------------------------------*/
00012 struct fifo_struct;
00013 typedef struct fifo_struct fifo_t;
00014 
00015 /*--------------------------------------------------------------*/
00021 fifo_t* isix_fifo_create(int n_elem, int elem_size);
00022 
00023 /*--------------------------------------------------------------*/
00029 int isix_fifo_write(fifo_t *fifo, const void *item, tick_t timeout);
00030 
00031 /*--------------------------------------------------------------*/
00036 int isix_fifo_write_isr(fifo_t *queue, const void *item);
00037 
00038 /*--------------------------------------------------------------*/
00041 int isix_fifo_destroy(fifo_t *fifo);
00042 
00043 /*--------------------------------------------------------------*/
00047 int isix_fifo_count(fifo_t *fifo);
00048 
00049 /*--------------------------------------------------------------*/
00055 int isix_fifo_read(fifo_t *fifo,void *item, tick_t timeout);
00056 
00057 /*--------------------------------------------------------------*/
00062 int isix_fifo_read_isr(fifo_t *queue, void *item);
00063 
00064 /*--------------------------------------------------------------*/
00065 #ifdef __cplusplus
00066 }       //end namespace
00067 }       //end extern-C
00068 #endif /* __cplusplus */
00069 /*--------------------------------------------------------------*/
00070 //****************************** C++ API ***********************************
00071 #ifdef __cplusplus
00072 #include <cstddef>
00073 
00074 namespace isix {
00075 /*--------------------------------------------------------------*/
00076 #ifdef ISIX_CONFIG_USE_MULTIOBJECTS
00077 union ihandle;
00078 #endif
00079 
00080 /*--------------------------------------------------------------*/
00082 class fifo_base
00083 {
00084 #ifdef ISIX_CONFIG_USE_MULTIOBJECTS
00085         friend union ihandle;
00086 #endif
00087 public:
00088         explicit fifo_base(fifo_t *hwnd_) : hwnd(hwnd_) {}
00089 protected:
00090         fifo_t *hwnd;
00091 private:
00092         fifo_base(const fifo_base&);
00093         fifo_base& operator=(const fifo_base&);
00094 };
00095 
00096 /*--------------------------------------------------------------*/
00098 template <typename T> class fifo : public fifo_base
00099 {
00100 public:
00104         explicit fifo(std::size_t n_elem)
00105                 : fifo_base(isix_fifo_create(n_elem,sizeof(T)))
00106         {
00107         }
00109         ~fifo()
00110         {
00111                 isix_fifo_destroy(hwnd);
00112         }
00116         bool is_valid() { return hwnd!=0; }
00117         /* Push data in the queue
00118          * @param[in] c Reference to the object
00119          * @param[in] timeout Wait time when queue is not empty
00120          * @return ISIX_EOK if success else return an error
00121          */
00122         int push(const T &c,tick_t timeout=0)
00123         {
00124                 return isix_fifo_write( hwnd, &c, timeout );
00125         }
00126         /* Push data in the queue from the ISR
00127          * @param[in] c Reference to the object
00128          * @param[in] timeout Wait time when queue is not empty
00129          * @return ISIX_EOK if success else return an error
00130          */
00131         int push_isr(const T &c)
00132         {
00133                 return isix_fifo_write_isr( hwnd, &c );
00134         }
00138         int size() const
00139         {
00140                 return isix_fifo_count( hwnd );
00141         }
00147         int pop(T &c, tick_t timeout=0)
00148         {
00149                 return isix_fifo_read( hwnd, &c, timeout );
00150         }
00156         int pop_isr(T &c)
00157         {
00158                 return isix_fifo_read_isr( hwnd, &c );
00159         }
00160 private:
00161         fifo(const fifo&);
00162         fifo& operator=(const fifo&);
00163 };
00164 
00165 /*--------------------------------------------------------------*/
00166 }
00167 #endif /* __cplusplus */
00168 /*--------------------------------------------------------------*/
00169 
00170 #endif /* __ISIX_FIFO_H */
00171 /*--------------------------------------------------------------*/
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines